summaryrefslogtreecommitdiff
path: root/accel-pptpd/ctrl
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2010-11-11 17:10:19 +0300
committerKozlov Dmitry <dima@server>2010-11-11 17:10:19 +0300
commit8f5464b34e85d68c26e4cff16dfba2c00cf53adc (patch)
treeb62e30de01e125a2d26cb801eec8f6f4a0b3182d /accel-pptpd/ctrl
parent734a3d3e93271cbde8584b303a5e2d7afab70016 (diff)
downloadaccel-ppp-8f5464b34e85d68c26e4cff16dfba2c00cf53adc.tar.gz
accel-ppp-8f5464b34e85d68c26e4cff16dfba2c00cf53adc.zip
pppoe: implemented additional cli commands
Diffstat (limited to 'accel-pptpd/ctrl')
-rw-r--r--accel-pptpd/ctrl/pppoe/cli.c129
-rw-r--r--accel-pptpd/ctrl/pppoe/pppoe.c50
-rw-r--r--accel-pptpd/ctrl/pppoe/pppoe.h5
3 files changed, 169 insertions, 15 deletions
diff --git a/accel-pptpd/ctrl/pppoe/cli.c b/accel-pptpd/ctrl/pppoe/cli.c
index bb303ce..c3088aa 100644
--- a/accel-pptpd/ctrl/pppoe/cli.c
+++ b/accel-pptpd/ctrl/pppoe/cli.c
@@ -1,10 +1,12 @@
#include <string.h>
+#include <stdlib.h>
#include <netinet/in.h>
#include <net/ethernet.h>
#include "triton.h"
#include "cli.h"
#include "ppp.h"
+#include "memdebug.h"
#include "pppoe.h"
@@ -70,9 +72,136 @@ static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt,
return CLI_CMD_OK;
}
+//===================================
+
+static void set_verbose_help(char * const *f, int f_cnt, void *cli)
+{
+ cli_send(cli, "pppoe set verbose <n> - set verbosity of pppoe logging\r\n");
+ cli_send(cli, "pppoe set PADO-delay <delay> - set PADO delay (ms)\r\n");
+ cli_send(cli, "pppoe set Service-Name <name> - set Service-Name to respond\r\n");
+ cli_send(cli, "pppoe set Service-Name * - respond with client's Service-Name\r\n");
+ cli_send(cli, "pppoe set AC-Name <name> - set AC-Name tag value\r\n");
+ cli_send(cli, "pppoe show verbose - show current verbose value\r\n");
+ cli_send(cli, "pppoe show PADO-delay - show current PADO delay value\r\n");
+ cli_send(cli, "pppoe show Service-Name - show current Service-Name value\r\n");
+ cli_send(cli, "pppoe show AC-Name - show current AC-Name tag value\r\n");
+}
+
+static int show_verbose_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
+{
+ if (f_cnt != 3)
+ return CLI_CMD_SYNTAX;
+
+ cli_sendv(cli, "%i\r\n", conf_verbose);
+
+ return CLI_CMD_OK;
+}
+
+static int show_pado_delay_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
+{
+ if (f_cnt != 3)
+ return CLI_CMD_SYNTAX;
+
+ cli_sendv(cli, "%i\r\n", conf_pado_delay);
+
+ return CLI_CMD_OK;
+}
+
+static int show_service_name_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
+{
+ if (f_cnt != 3)
+ return CLI_CMD_SYNTAX;
+
+ if (conf_service_name)
+ cli_sendv(cli, "%s\r\n", conf_service_name);
+ else
+ cli_sendv(cli, "*\r\n", conf_service_name);
+
+ return CLI_CMD_OK;
+}
+
+static int show_ac_name_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
+{
+ if (f_cnt != 3)
+ return CLI_CMD_SYNTAX;
+
+ cli_sendv(cli, "%s\r\n", conf_ac_name);
+
+ return CLI_CMD_OK;
+}
+
+static int set_verbose_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
+{
+ if (f_cnt != 4)
+ return CLI_CMD_SYNTAX;
+
+ if (!strcmp(f[3], "0"))
+ conf_verbose = 0;
+ else if (!strcmp(f[3], "1"))
+ conf_verbose = 1;
+ else
+ return CLI_CMD_INVAL;
+
+ return CLI_CMD_OK;
+}
+
+static int set_pado_delay_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
+{
+ char *endptr;
+ int d;
+
+ if (f_cnt != 4)
+ return CLI_CMD_SYNTAX;
+
+ d = strtol(f[3], &endptr, 10);
+ if (*endptr || d < 0)
+ return CLI_CMD_INVAL;
+
+ conf_pado_delay = d;
+
+ return CLI_CMD_OK;
+}
+
+static int set_service_name_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
+{
+ if (f_cnt != 4)
+ return CLI_CMD_SYNTAX;
+
+ if (conf_service_name)
+ _free(conf_service_name);
+
+ if (!strcmp(f[3], "*"))
+ conf_service_name = NULL;
+ else
+ conf_service_name = _strdup(f[3]);
+
+ return CLI_CMD_OK;
+}
+
+static int set_ac_name_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
+{
+ if (f_cnt != 4)
+ return CLI_CMD_SYNTAX;
+
+ _free(conf_ac_name);
+ conf_ac_name = _strdup(f[3]);
+
+ return CLI_CMD_OK;
+}
+//===================================
+
+
static void __init init(void)
{
cli_register_simple_cmd2(show_stat_exec, NULL, 2, "show", "stat");
cli_register_simple_cmd2(intf_exec, intf_help, 2, "pppoe", "interface");
+ cli_register_simple_cmd2(set_verbose_exec, set_verbose_help, 3, "pppoe", "set", "verbose");
+ cli_register_simple_cmd2(set_pado_delay_exec, NULL, 3, "pppoe", "set", "PADO-delay");
+ cli_register_simple_cmd2(set_service_name_exec, NULL, 3, "pppoe", "set", "Service-Name");
+ cli_register_simple_cmd2(set_ac_name_exec, NULL, 3, "pppoe", "set", "AC-Name");
+ cli_register_simple_cmd2(show_verbose_exec, NULL, 3, "pppoe", "show", "verbose");
+ cli_register_simple_cmd2(show_pado_delay_exec, NULL, 3, "pppoe", "show", "PADO-delay");
+ cli_register_simple_cmd2(show_service_name_exec, NULL, 3, "pppoe", "show", "Service-Name");
+ cli_register_simple_cmd2(show_ac_name_exec, NULL, 3, "pppoe", "show", "AC-Name");
}
diff --git a/accel-pptpd/ctrl/pppoe/pppoe.c b/accel-pptpd/ctrl/pppoe/pppoe.c
index 4ce0862..f7737cf 100644
--- a/accel-pptpd/ctrl/pppoe/pppoe.c
+++ b/accel-pptpd/ctrl/pppoe/pppoe.c
@@ -54,10 +54,11 @@ struct delayed_pado_t
struct pppoe_tag *service_name;
};
-static int conf_verbose = 0;
-static const char *conf_service_name = NULL;
-static const char *conf_ac_name = "accel-pptp";
-static int conf_pado_delay = 0;
+int conf_verbose;
+char *conf_service_name;
+char *conf_ac_name;
+int conf_pado_delay;
+
static mempool_t conn_pool;
static mempool_t pado_pool;
@@ -529,13 +530,9 @@ static void pppoe_send_PADT(struct pppoe_conn_t *conn)
pppoe_send(conn->disc_sock, pack);
}
-static void pado_timer(struct triton_timer_t *t)
+static void free_delayed_pado(struct delayed_pado_t *pado)
{
- struct delayed_pado_t *pado = container_of(t, typeof(*pado), timer);
-
- triton_timer_del(t);
-
- pppoe_send_PADO(pado->serv, pado->addr, pado->host_uniq, pado->relay_sid, pado->service_name);
+ triton_timer_del(&pado->timer);
__sync_fetch_and_sub(&stat_delayed_pado, 1);
list_del(&pado->entry);
@@ -550,6 +547,15 @@ static void pado_timer(struct triton_timer_t *t)
mempool_free(pado);
}
+static void pado_timer(struct triton_timer_t *t)
+{
+ struct delayed_pado_t *pado = container_of(t, typeof(*pado), timer);
+
+ pppoe_send_PADO(pado->serv, pado->addr, pado->host_uniq, pado->relay_sid, pado->service_name);
+
+ free_delayed_pado(pado);
+}
+
static void pppoe_recv_PADI(struct pppoe_serv_t *serv, uint8_t *pack, int size)
{
struct ethhdr *ethhdr = (struct ethhdr *)pack;
@@ -846,7 +852,9 @@ static int pppoe_serv_read(struct triton_md_handler_t *h)
static void pppoe_serv_close(struct triton_context_t *ctx)
{
struct pppoe_serv_t *serv = container_of(ctx, typeof(*serv), ctx);
- _server_stop(serv);
+
+ triton_md_disable_handler(&serv->hnd, MD_MODE_READ | MD_MODE_WRITE);
+ serv->stopping = 1;
}
void pppoe_server_start(const char *ifname, void *cli)
@@ -976,6 +984,7 @@ static void _server_stop(struct pppoe_serv_t *serv)
return;
serv->stopping = 1;
+ triton_md_disable_handler(&serv->hnd, MD_MODE_READ | MD_MODE_WRITE);
pthread_mutex_lock(&serv->lock);
if (!serv->conn_cnt) {
@@ -990,10 +999,17 @@ static void _server_stop(struct pppoe_serv_t *serv)
void pppoe_server_free(struct pppoe_serv_t *serv)
{
+ struct delayed_pado_t *pado;
+
pthread_rwlock_wrlock(&serv_lock);
list_del(&serv->entry);
pthread_rwlock_unlock(&serv_lock);
+ while (!list_empty(&serv->pado_list)) {
+ pado = list_entry(serv->pado_list.next, typeof(*pado), entry);
+ free_delayed_pado(pado);
+ }
+
triton_md_unregister_handler(&serv->hnd);
close(serv->hnd.fd);
triton_context_unregister(&serv->ctx);
@@ -1061,15 +1077,19 @@ static void __init pppoe_init(void)
} else if (!strcmp(opt->name, "verbose")) {
if (atoi(opt->val) > 0)
conf_verbose = 1;
- } else if (!strcmp(opt->name, "ac-name") || !strcmp(opt->name, "AC-Name"))
- conf_ac_name = opt->val;
- else if (!strcmp(opt->name, "service-name") || !strcmp(opt->name, "Service-Name")) {
+ } else if (!strcmp(opt->name, "ac-name") || !strcmp(opt->name, "AC-Name")) {
if (opt->val && strlen(opt->val))
- conf_service_name = opt->val;
+ conf_ac_name = _strdup(opt->val);
+ } else if (!strcmp(opt->name, "service-name") || !strcmp(opt->name, "Service-Name")) {
+ if (opt->val && strlen(opt->val))
+ conf_service_name = _strdup(opt->val);
} else if (!strcmp(opt->name, "pado-delay") || !strcmp(opt->name, "PADO-delay")) {
if (opt->val && atoi(opt->val) > 0)
conf_pado_delay = atoi(opt->val);
}
}
+
+ if (!conf_ac_name)
+ conf_ac_name = _strdup("accel-pptp");
}
diff --git a/accel-pptpd/ctrl/pppoe/pppoe.h b/accel-pptpd/ctrl/pppoe/pppoe.h
index 9ef4475..91c8d30 100644
--- a/accel-pptpd/ctrl/pppoe/pppoe.h
+++ b/accel-pptpd/ctrl/pppoe/pppoe.h
@@ -74,6 +74,11 @@ struct pppoe_serv_t
struct list_head pado_list;
};
+extern int conf_verbose;
+extern char *conf_service_name;
+extern char *conf_ac_name;
+extern int conf_pado_delay;
+
extern uint32_t stat_active;
extern uint32_t stat_delayed_pado;