summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Nault <g.nault@alphalink.fr>2014-02-06 17:23:32 +0100
committerDmitry Kozlov <xeb@mail.ru>2014-02-08 09:31:00 +0400
commitea57a3932621e89d7ca206dc8354fbb9f6596f3e (patch)
tree414ac20df8e8b17230db35ad6a7a9d0a87792ff7
parent7f4fb7016323b8f62e84085c62e6a80109dc0196 (diff)
downloadaccel-ppp-ea57a3932621e89d7ca206dc8354fbb9f6596f3e.tar.gz
accel-ppp-ea57a3932621e89d7ca206dc8354fbb9f6596f3e.zip
l2tp: add tunnel statistics
Report tunnel statistics with the "show stat" command. Statistics are updated upon tunnel state modifications. Setting the STATE_ESTB state is centralised in l2tp_tunnel_connect() to ensure the tunnel state remains synchronised with the statistics even when errors occur. While there, connect tunnels after sending SCCCN and stop tunnel establishment timer as soon as l2tp_tunnel_connect() is called (so that it'll be deleted even upon failure). Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
-rw-r--r--accel-pppd/ctrl/l2tp/l2tp.c53
1 files changed, 39 insertions, 14 deletions
diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c
index 36f41128..dd132a7b 100644
--- a/accel-pppd/ctrl/l2tp/l2tp.c
+++ b/accel-pppd/ctrl/l2tp/l2tp.c
@@ -74,6 +74,10 @@ static int conf_dataseq = L2TP_DATASEQ_ALLOW;
static int conf_reorder_timeout = 0;
static const char *conf_ip_pool;
+static unsigned int stat_conn_starting;
+static unsigned int stat_conn_active;
+static unsigned int stat_conn_finishing;
+
static unsigned int stat_active;
static unsigned int stat_starting;
static unsigned int stat_finishing;
@@ -566,7 +570,12 @@ static void l2tp_tunnel_disconnect(struct l2tp_conn_t *conn, int res, int err)
case STATE_INIT:
case STATE_WAIT_SCCRP:
case STATE_WAIT_SCCCN:
+ __sync_sub_and_fetch(&stat_conn_starting, 1);
+ __sync_add_and_fetch(&stat_conn_finishing, 1);
+ break;
case STATE_ESTB:
+ __sync_sub_and_fetch(&stat_conn_active, 1);
+ __sync_add_and_fetch(&stat_conn_finishing, 1);
break;
case STATE_FIN:
case STATE_CLOSE:
@@ -599,6 +608,8 @@ static void __tunnel_destroy(struct l2tp_conn_t *conn)
log_tunnel(log_info2, conn, "tunnel destroyed\n");
mempool_free(conn);
+
+ __sync_sub_and_fetch(&stat_conn_finishing, 1);
}
static void tunnel_put(struct l2tp_conn_t *conn)
@@ -745,7 +756,13 @@ static void l2tp_tunnel_free(struct l2tp_conn_t *conn)
case STATE_INIT:
case STATE_WAIT_SCCRP:
case STATE_WAIT_SCCCN:
+ __sync_sub_and_fetch(&stat_conn_starting, 1);
+ __sync_add_and_fetch(&stat_conn_finishing, 1);
+ break;
case STATE_ESTB:
+ __sync_sub_and_fetch(&stat_conn_active, 1);
+ __sync_add_and_fetch(&stat_conn_finishing, 1);
+ break;
case STATE_FIN:
break;
case STATE_CLOSE:
@@ -1287,6 +1304,8 @@ static struct l2tp_conn_t *l2tp_tunnel_alloc(const struct sockaddr_in *peer,
conn->hide_avps = hide_avps;
tunnel_hold(conn);
+ __sync_add_and_fetch(&stat_conn_starting, 1);
+
return conn;
out_err:
@@ -1529,6 +1548,9 @@ static int l2tp_tunnel_connect(struct l2tp_conn_t *conn)
int tunnel_fd;
int flg;
+ if (conn->timeout_timer.tpd)
+ triton_timer_del(&conn->timeout_timer);
+
memset(&pppox_addr, 0, sizeof(pppox_addr));
pppox_addr.sa_family = AF_PPPOX;
pppox_addr.sa_protocol = PX_PROTO_OL2TP;
@@ -1573,11 +1595,12 @@ static int l2tp_tunnel_connect(struct l2tp_conn_t *conn)
goto err_fd;
}
- if (conn->timeout_timer.tpd)
- triton_timer_del(&conn->timeout_timer);
-
close(tunnel_fd);
+ __sync_sub_and_fetch(&stat_conn_starting, 1);
+ __sync_add_and_fetch(&stat_conn_active, 1);
+ conn->state = STATE_ESTB;
+
return 0;
err_fd:
@@ -2490,16 +2513,16 @@ static int l2tp_recv_SCCRP(struct l2tp_conn_t *conn,
return -1;
}
- if (l2tp_tunnel_connect(conn) < 0) {
+ if (l2tp_send_SCCCN(conn) < 0) {
log_tunnel(log_error, conn, "impossible to handle SCCRP:"
- " connecting tunnel failed,"
+ " sending SCCCN failed,"
" disconnecting tunnel\n");
l2tp_tunnel_disconnect(conn, 2, 0);
return -1;
}
- if (l2tp_send_SCCCN(conn) < 0) {
+ if (l2tp_tunnel_connect(conn) < 0) {
log_tunnel(log_error, conn, "impossible to handle SCCRP:"
- " sending SCCCN failed,"
+ " connecting tunnel failed,"
" disconnecting tunnel\n");
l2tp_tunnel_disconnect(conn, 2, 0);
return -1;
@@ -2509,8 +2532,6 @@ static int l2tp_recv_SCCRP(struct l2tp_conn_t *conn,
log_tunnel(log_info1, conn, "established at %s:%hu\n",
host_addr, ntohs(conn->host_addr.sin_port));
- conn->state = STATE_ESTB;
-
return 0;
}
@@ -2579,8 +2600,6 @@ static int l2tp_recv_SCCCN(struct l2tp_conn_t *conn,
log_tunnel(log_info1, conn, "established at %s:%hu\n",
host_addr, ntohs(conn->host_addr.sin_port));
- conn->state = STATE_ESTB;
-
return 0;
}
@@ -3911,9 +3930,15 @@ err_fd:
static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt, void *client)
{
cli_send(client, "l2tp:\r\n");
- cli_sendv(client, " starting: %u\r\n", stat_starting);
- cli_sendv(client, " active: %u\r\n", stat_active);
- cli_sendv(client, " finishing: %u\r\n", stat_finishing);
+ cli_send(client, " tunnels:\r\n");
+ cli_sendv(client, " starting: %u\r\n", stat_conn_starting);
+ cli_sendv(client, " active: %u\r\n", stat_conn_active);
+ cli_sendv(client, " finishing: %u\r\n", stat_conn_finishing);
+
+ cli_send(client, " sessions (data channels):\r\n");
+ cli_sendv(client, " starting: %u\r\n", stat_starting);
+ cli_sendv(client, " active: %u\r\n", stat_active);
+ cli_sendv(client, " finishing: %u\r\n", stat_finishing);
return CLI_CMD_OK;
}