summaryrefslogtreecommitdiff
path: root/accel-pptpd/ctrl
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2010-11-10 18:33:36 +0300
committerKozlov Dmitry <dima@server>2010-11-10 18:33:36 +0300
commit058e7ff66b8fbb1f9494ae5077e5294db288fb1c (patch)
treee5d4c535539681843efb80bb1f06a643cee88904 /accel-pptpd/ctrl
parent4d826710d0d30606da88ff3543a4b43521e404df (diff)
downloadaccel-ppp-xebd-058e7ff66b8fbb1f9494ae5077e5294db288fb1c.tar.gz
accel-ppp-xebd-058e7ff66b8fbb1f9494ae5077e5294db288fb1c.zip
cli: implemented following command list: show stat, show sessions, terminate (sessison)
Diffstat (limited to 'accel-pptpd/ctrl')
-rw-r--r--accel-pptpd/ctrl/l2tp/l2tp.c40
-rw-r--r--accel-pptpd/ctrl/pppoe/pppoe.c40
-rw-r--r--accel-pptpd/ctrl/pptp/pptp.c45
3 files changed, 121 insertions, 4 deletions
diff --git a/accel-pptpd/ctrl/l2tp/l2tp.c b/accel-pptpd/ctrl/l2tp/l2tp.c
index c9af912..899ac6a 100644
--- a/accel-pptpd/ctrl/l2tp/l2tp.c
+++ b/accel-pptpd/ctrl/l2tp/l2tp.c
@@ -22,6 +22,7 @@
#include "events.h"
#include "utils.h"
#include "iprange.h"
+#include "cli.h"
#include "memdebug.h"
@@ -49,6 +50,9 @@ int conf_retransmit = 5;
int conf_hello_interval = 60;
const char *conf_host_name = "accel-pptp";
+static uint32_t stat_active;
+static uint32_t stat_starting;
+
struct l2tp_serv_t
{
struct triton_context_t ctx;
@@ -115,9 +119,11 @@ static void l2tp_disconnect(struct l2tp_conn_t *conn)
triton_timer_del(&conn->hello_timer);
if (conn->state == STATE_PPP) {
+ __sync_fetch_and_sub(&stat_active, 1);
conn->state = STATE_FIN;
ppp_terminate(&conn->ppp, TERM_USER_REQUEST, 1);
- }
+ } else if (conn->state != STATE_FIN)
+ __sync_fetch_and_sub(&stat_starting, 1);
pthread_mutex_lock(&l2tp_lock);
l2tp_conn[conn->tid] = NULL;
@@ -324,6 +330,8 @@ static int l2tp_tunnel_alloc(struct l2tp_serv_t *serv, struct l2tp_packet_t *pac
triton_context_call(&conn->ctx, (triton_event_func)l2tp_send_SCCRP, conn);
+ __sync_fetch_and_add(&stat_starting, 1);
+
return 0;
out_err:
@@ -384,6 +392,9 @@ static int l2tp_connect(struct l2tp_conn_t *conn)
if (establish_ppp(&conn->ppp))
return -1;
+ __sync_fetch_and_sub(&stat_starting, 1);
+ __sync_fetch_and_add(&stat_active, 1);
+
conn->state = STATE_PPP;
return 0;
@@ -1049,6 +1060,31 @@ static void start_udp_server(void)
triton_context_wakeup(&udp_serv.ctx);
}
+static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt, void *client)
+{
+ char buf[128];
+
+ if (cli_send(client, "l2tp:\r\n"))
+ return CLI_CMD_FAILED;
+
+ sprintf(buf, " starting: %u\r\n", stat_starting);
+ if (cli_send(client, buf))
+ return CLI_CMD_FAILED;
+
+ sprintf(buf, " active: %u\r\n", stat_active);
+ if (cli_send(client, buf))
+ return CLI_CMD_FAILED;
+
+ return CLI_CMD_OK;
+}
+
+static const char *show_stat_hdr[] = {"show","stat"};
+static struct cli_simple_cmd_t show_stat_cmd = {
+ .hdr_len = 2,
+ .hdr = show_stat_hdr,
+ .exec = show_stat_exec,
+};
+
static void __init l2tp_init(void)
{
char *opt;
@@ -1083,5 +1119,7 @@ static void __init l2tp_init(void)
conf_host_name = opt;
start_udp_server();
+
+ cli_register_simple_cmd(&show_stat_cmd);
}
diff --git a/accel-pptpd/ctrl/pppoe/pppoe.c b/accel-pptpd/ctrl/pppoe/pppoe.c
index cba2631..ef661bc 100644
--- a/accel-pptpd/ctrl/pppoe/pppoe.c
+++ b/accel-pptpd/ctrl/pppoe/pppoe.c
@@ -19,6 +19,7 @@
#include "log.h"
#include "ppp.h"
#include "mempool.h"
+#include "cli.h"
#include "pppoe.h"
@@ -74,6 +75,9 @@ static int conf_pado_delay = 0;
static mempool_t conn_pool;
static mempool_t pado_pool;
+static uint32_t stat_active;
+static uint32_t stat_delayed_pado;
+
#define SECRET_SIZE 16
static uint8_t *secret;
@@ -84,6 +88,7 @@ static void pppoe_send_PADT(struct pppoe_conn_t *conn);
static void disconnect(struct pppoe_conn_t *conn)
{
if (conn->ppp_started) {
+ __sync_fetch_and_sub(&stat_active, 1);
conn->ppp_started = 0;
ppp_terminate(&conn->ppp, TERM_USER_REQUEST, 1);
}
@@ -92,6 +97,7 @@ static void disconnect(struct pppoe_conn_t *conn)
close(conn->disc_sock);
+
triton_event_fire(EV_CTRL_FINISHED, &conn->ppp);
if (conf_verbose)
@@ -126,6 +132,7 @@ static void ppp_finished(struct ppp_t *ppp)
log_ppp_debug("pppoe: ppp finished\n");
if (conn->ppp_started) {
+ __sync_fetch_and_sub(&stat_active, 1);
conn->ppp_started = 0;
disconnect(conn);
}
@@ -531,6 +538,7 @@ static void pado_timer(struct triton_timer_t *t)
pppoe_send_PADO(pado->serv, pado->addr, pado->host_uniq, pado->relay_sid, pado->service_name);
+ __sync_fetch_and_sub(&stat_delayed_pado, 1);
list_del(&pado->entry);
if (pado->host_uniq)
@@ -632,6 +640,7 @@ static void pppoe_recv_PADI(struct pppoe_serv_t *serv, uint8_t *pack, int size)
triton_timer_add(&serv->ctx, &pado->timer, 0);
list_add_tail(&pado->entry, &serv->pado_list);
+ __sync_fetch_and_add(&stat_delayed_pado, 1);
} else
pppoe_send_PADO(serv, ethhdr->h_source, host_uniq_tag, relay_sid_tag, service_name_tag);
}
@@ -731,8 +740,10 @@ static void pppoe_recv_PADR(struct pppoe_serv_t *serv, uint8_t *pack, int size)
pppoe_send_PADS(conn);
if (connect_channel(conn))
disconnect(conn);
- else
+ else {
+ __sync_fetch_and_add(&stat_active, 1);
conn->ppp_started = 1;
+ }
}
}
@@ -929,6 +940,31 @@ out_err:
_free(serv);
}
+static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt, void *client)
+{
+ char buf[128];
+
+ if (cli_send(client, "pppoe:\r\n"))
+ return CLI_CMD_FAILED;
+
+ sprintf(buf, " active: %u\r\n", stat_active);
+ if (cli_send(client, buf))
+ return CLI_CMD_FAILED;
+
+ sprintf(buf, " delayed PADO: %u\r\n", stat_delayed_pado);
+ if (cli_send(client, buf))
+ return CLI_CMD_FAILED;
+
+ return CLI_CMD_OK;
+}
+
+static const char *show_stat_hdr[] = {"show","stat"};
+static struct cli_simple_cmd_t show_stat_cmd = {
+ .hdr_len = 2,
+ .hdr = show_stat_hdr,
+ .exec = show_stat_exec,
+};
+
static int init_secret(void)
{
int fd;
@@ -985,5 +1021,7 @@ static void __init pppoe_init(void)
conf_pado_delay = atoi(opt->val);
}
}
+
+ cli_register_simple_cmd(&show_stat_cmd);
}
diff --git a/accel-pptpd/ctrl/pptp/pptp.c b/accel-pptpd/ctrl/pptp/pptp.c
index 4a705d5..433292f 100644
--- a/accel-pptpd/ctrl/pptp/pptp.c
+++ b/accel-pptpd/ctrl/pptp/pptp.c
@@ -21,6 +21,7 @@
#include "mempool.h"
#include "iprange.h"
#include "utils.h"
+#include "cli.h"
#include "memdebug.h"
@@ -58,6 +59,9 @@ static int conf_verbose = 0;
static mempool_t conn_pool;
+static uint32_t stat_starting;
+static uint32_t stat_active;
+
static int pptp_read(struct triton_md_handler_t *h);
static int pptp_write(struct triton_md_handler_t *h);
static void pptp_timeout(struct triton_timer_t *);
@@ -78,9 +82,11 @@ static void disconnect(struct pptp_conn_t *conn)
triton_timer_del(&conn->echo_timer);
if (conn->state == STATE_PPP) {
+ __sync_fetch_and_sub(&stat_active, 1);
conn->state = STATE_CLOSE;
ppp_terminate(&conn->ppp, TERM_USER_REQUEST, 1);
- }
+ } else if (conn->state != STATE_CLOSE)
+ __sync_fetch_and_sub(&stat_starting, 1);
triton_event_fire(EV_CTRL_FINISHED, &conn->ppp);
@@ -323,6 +329,8 @@ static int pptp_out_call_rqst(struct pptp_conn_t *conn)
return -1;
}
conn->state = STATE_PPP;
+ __sync_fetch_and_sub(&stat_starting, 1);
+ __sync_fetch_and_add(&stat_active, 1);
if (conn->timeout_timer.tpd)
triton_timer_del(&conn->timeout_timer);
@@ -359,9 +367,11 @@ static int pptp_call_clear_rqst(struct pptp_conn_t *conn)
log_ppp_info("recv [PPTP Call-Clear-Request <Call-ID %x>]\n", ntohs(rqst->call_id));
if (conn->state == STATE_PPP) {
+ __sync_fetch_and_sub(&stat_active, 1);
conn->state = STATE_CLOSE;
ppp_terminate(&conn->ppp, TERM_USER_REQUEST, 1);
- }
+ } else
+ __sync_fetch_and_sub(&stat_starting, 1);
return send_pptp_call_disconnect_notify(conn, 4);
}
@@ -540,6 +550,7 @@ static void pptp_close(struct triton_context_t *ctx)
{
struct pptp_conn_t *conn = container_of(ctx, typeof(*conn), ctx);
if (conn->state == STATE_PPP) {
+ __sync_fetch_and_sub(&stat_active, 1);
conn->state = STATE_CLOSE;
ppp_terminate(&conn->ppp, TERM_ADMIN_RESET, 1);
if (send_pptp_call_disconnect_notify(conn, 3)) {
@@ -569,6 +580,7 @@ static void ppp_finished(struct ppp_t *ppp)
if (conn->state != STATE_CLOSE) {
log_ppp_debug("pptp: ppp finished\n");
conn->state = STATE_CLOSE;
+ __sync_fetch_and_sub(&stat_active, 1);
if (send_pptp_call_disconnect_notify(conn, 3))
triton_context_call(&conn->ctx, (void (*)(void*))disconnect, conn);
@@ -655,6 +667,8 @@ static int pptp_connect(struct triton_md_handler_t *h)
triton_context_wakeup(&conn->ctx);
triton_event_fire(EV_CTRL_STARTING, &conn->ppp);
+
+ __sync_fetch_and_add(&stat_starting, 1);
}
return 0;
}
@@ -672,6 +686,31 @@ static struct pptp_serv_t serv=
.ctx.close=pptp_serv_close,
};
+static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt, void *client)
+{
+ char buf[128];
+
+ if (cli_send(client, "pptp:\r\n"))
+ return CLI_CMD_FAILED;
+
+ sprintf(buf, " starting: %u\r\n", stat_starting);
+ if (cli_send(client, buf))
+ return CLI_CMD_FAILED;
+
+ sprintf(buf, " active: %u\r\n", stat_active);
+ if (cli_send(client, buf))
+ return CLI_CMD_FAILED;
+
+ return CLI_CMD_OK;
+}
+
+static const char *show_stat_hdr[] = {"show","stat"};
+static struct cli_simple_cmd_t show_stat_cmd = {
+ .hdr_len = 2,
+ .hdr = show_stat_hdr,
+ .exec = show_stat_exec,
+};
+
static void __init pptp_init(void)
{
struct sockaddr_in addr;
@@ -732,5 +771,7 @@ static void __init pptp_init(void)
triton_md_register_handler(&serv.ctx, &serv.hnd);
triton_md_enable_handler(&serv.hnd, MD_MODE_READ);
triton_context_wakeup(&serv.ctx);
+
+ cli_register_simple_cmd(&show_stat_cmd);
}