summaryrefslogtreecommitdiff
path: root/accel-pppd/cli
diff options
context:
space:
mode:
Diffstat (limited to 'accel-pppd/cli')
-rw-r--r--accel-pppd/cli/cli.h4
-rw-r--r--accel-pppd/cli/show_sessions.c74
-rw-r--r--accel-pppd/cli/std_cmd.c156
-rw-r--r--accel-pppd/cli/telnet.c8
4 files changed, 156 insertions, 86 deletions
diff --git a/accel-pppd/cli/cli.h b/accel-pppd/cli/cli.h
index cdceb2f..3e31c5d 100644
--- a/accel-pppd/cli/cli.h
+++ b/accel-pppd/cli/cli.h
@@ -29,7 +29,7 @@ struct cli_regexp_cmd_t
int (*help)(char * const *fields, int field_cnt, void *client);
};
-struct ppp_t;
+struct ap_session;
void cli_register_simple_cmd(struct cli_simple_cmd_t *cmd);
void cli_register_simple_cmd2(
@@ -39,7 +39,7 @@ void cli_register_simple_cmd2(
...
);
void cli_register_regexp_cmd(struct cli_regexp_cmd_t *cmd);
-void cli_show_ses_register(const char *name, const char *desc, void (*print)(const struct ppp_t *ppp, char *buf));
+void cli_show_ses_register(const char *name, const char *desc, void (*print)(const struct ap_session *ses, char *buf));
int cli_send(void *client, const char *data);
int cli_sendv(void *client, const char *fmt, ...);
diff --git a/accel-pppd/cli/show_sessions.c b/accel-pppd/cli/show_sessions.c
index c0fec58..746ce58 100644
--- a/accel-pppd/cli/show_sessions.c
+++ b/accel-pppd/cli/show_sessions.c
@@ -22,7 +22,7 @@ struct column_t
struct list_head entry;
const char *name;
const char *desc;
- void (*print)(const struct ppp_t *ppp, char *buf);
+ void (*print)(const struct ap_session *ses, char *buf);
};
struct col_t
@@ -50,7 +50,7 @@ struct cell_t
static LIST_HEAD(col_list);
-void __export cli_show_ses_register(const char *name, const char *desc, void (*print)(const struct ppp_t *ppp, char *buf))
+void __export cli_show_ses_register(const char *name, const char *desc, void (*print)(const struct ap_session *ses, char *buf))
{
struct column_t *c = malloc(sizeof(*c));
c->name = name;
@@ -131,7 +131,7 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
struct cell_t *cell;
char *ptr1, *ptr2;
int i, n, total_width, def_columns = 0;
- struct ppp_t *ppp;
+ struct ap_session *ses;
char *buf = NULL;
int match_key_f = 0, order_key_f = 0;
LIST_HEAD(c_list);
@@ -221,8 +221,8 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
list_add_tail(&col->entry, &c_list);
}
- pthread_rwlock_rdlock(&ppp_lock);
- list_for_each_entry(ppp, &ppp_list, entry) {
+ pthread_rwlock_rdlock(&ses_lock);
+ list_for_each_entry(ses, &ses_list, entry) {
row = _malloc(sizeof(*row));
if (!row)
goto oom;
@@ -238,7 +238,7 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
goto oom;
cell->col = col;
list_add_tail(&cell->entry, &row->cell_list);
- col->column->print(ppp, cell->buf);
+ col->column->print(ses, cell->buf);
n = strlen(cell->buf);
if (n > col->width)
col->width = n;
@@ -248,7 +248,7 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
row->match_key = cell->buf;
}
}
- pthread_rwlock_unlock(&ppp_lock);
+ pthread_rwlock_unlock(&ses_lock);
if (order_key || match_key) {
while(!list_empty(&t_list)) {
@@ -368,40 +368,40 @@ oom:
goto out;
}
-static void print_ifname(const struct ppp_t *ppp, char *buf)
+static void print_ifname(const struct ap_session *ses, char *buf)
{
- snprintf(buf, CELL_SIZE, "%s", ppp->ifname);
+ snprintf(buf, CELL_SIZE, "%s", ses->ifname);
}
-static void print_username(const struct ppp_t *ppp, char *buf)
+static void print_username(const struct ap_session *ses, char *buf)
{
- if (ppp->username)
- snprintf(buf, CELL_SIZE, "%s", ppp->username);
+ if (ses->username)
+ snprintf(buf, CELL_SIZE, "%s", ses->username);
else
*buf = 0;
}
-static void print_ip(const struct ppp_t *ppp, char *buf)
+static void print_ip(const struct ap_session *ses, char *buf)
{
- u_inet_ntoa(ppp->ipv4 ? ppp->ipv4->peer_addr : 0, buf);
+ u_inet_ntoa(ses->ipv4 ? ses->ipv4->peer_addr : 0, buf);
}
-static void print_type(const struct ppp_t *ppp, char *buf)
+static void print_type(const struct ap_session *ses, char *buf)
{
- snprintf(buf, CELL_SIZE, "%s", ppp->ctrl->name);
+ snprintf(buf, CELL_SIZE, "%s", ses->ctrl->name);
}
-static void print_state(const struct ppp_t *ppp, char *buf)
+static void print_state(const struct ap_session *ses, char *buf)
{
char *state;
- switch (ppp->state) {
- case PPP_STATE_STARTING:
+ switch (ses->state) {
+ case AP_STATE_STARTING:
state = "start";
break;
- case PPP_STATE_ACTIVE:
+ case AP_STATE_ACTIVE:
state = "active";
break;
- case PPP_STATE_FINISHING:
+ case AP_STATE_FINISHING:
state = "finish";
break;
default:
@@ -410,17 +410,17 @@ static void print_state(const struct ppp_t *ppp, char *buf)
sprintf(buf, "%s", state);
}
-static void print_uptime(const struct ppp_t *ppp, char *buf)
+static void print_uptime(const struct ap_session *ses, char *buf)
{
time_t uptime;
int day,hour,min,sec;
char time_str[14];
- if (ppp->stop_time)
- uptime = ppp->stop_time - ppp->start_time;
+ if (ses->stop_time)
+ uptime = ses->stop_time - ses->start_time;
else {
time(&uptime);
- uptime -= ppp->start_time;
+ uptime -= ses->start_time;
}
day = uptime/ (24*60*60); uptime %= (24*60*60);
@@ -435,24 +435,32 @@ static void print_uptime(const struct ppp_t *ppp, char *buf)
sprintf(buf, "%s", time_str);
}
-static void print_calling_sid(const struct ppp_t *ppp, char *buf)
+static void print_calling_sid(const struct ap_session *ses, char *buf)
{
- snprintf(buf, CELL_SIZE, "%s", ppp->ctrl->calling_station_id);
+ snprintf(buf, CELL_SIZE, "%s", ses->ctrl->calling_station_id);
}
-static void print_called_sid(const struct ppp_t *ppp, char *buf)
+static void print_called_sid(const struct ap_session *ses, char *buf)
{
- snprintf(buf, CELL_SIZE, "%s", ppp->ctrl->called_station_id);
+ snprintf(buf, CELL_SIZE, "%s", ses->ctrl->called_station_id);
}
-static void print_sid(const struct ppp_t *ppp, char *buf)
+static void print_sid(const struct ap_session *ses, char *buf)
{
- snprintf(buf, CELL_SIZE, "%s", ppp->sessionid);
+ snprintf(buf, CELL_SIZE, "%s", ses->sessionid);
}
-static void print_comp(const struct ppp_t *ppp, char *buf)
+static void print_comp(const struct ap_session *ses, char *buf)
{
- snprintf(buf, CELL_SIZE, "%s", ppp->comp ? ppp->comp : "");
+ struct ppp_t *ppp;
+
+ *buf = 0;
+
+ if (ses->ctrl->type != CTRL_TYPE_IPOE) {
+ ppp = container_of(ses, typeof(*ppp), ses);
+ if (ppp->comp)
+ snprintf(buf, CELL_SIZE, "%s", ppp->comp);
+ }
}
static void init(void)
diff --git a/accel-pppd/cli/std_cmd.c b/accel-pppd/cli/std_cmd.c
index 24e5228..01e0157 100644
--- a/accel-pppd/cli/std_cmd.c
+++ b/accel-pppd/cli/std_cmd.c
@@ -15,6 +15,8 @@
#include "log.h"
#include "memdebug.h"
+void core_restart(int);
+
static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt, void *client)
{
struct timespec ts;
@@ -68,10 +70,10 @@ static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt,
cli_sendv(client, " timer_pending: %u\r\n", triton_stat.timer_pending);
//===========
- cli_send(client, "ppp:\r\n");
- cli_sendv(client, " starting: %u\r\n", ppp_stat.starting);
- cli_sendv(client, " active: %u\r\n", ppp_stat.active);
- cli_sendv(client, " finishing: %u\r\n", ppp_stat.finishing);
+ cli_send(client, "sessions:\r\n");
+ cli_sendv(client, " starting: %u\r\n", ap_session_stat.starting);
+ cli_sendv(client, " active: %u\r\n", ap_session_stat.active);
+ cli_sendv(client, " finishing: %u\r\n", ap_session_stat.finishing);
return CLI_CMD_OK;
}
@@ -94,19 +96,19 @@ static void exit_help(char * const *fields, int fields_cnt, void *client)
//=============================
-static void ppp_terminate_soft(struct ppp_t *ppp)
+static void __terminate_soft(struct ap_session *ses)
{
- ppp_terminate(ppp, TERM_NAS_REQUEST, 0);
+ ap_session_terminate(ses, TERM_NAS_REQUEST, 0);
}
-static void ppp_terminate_hard(struct ppp_t *ppp)
+static void __terminate_hard(struct ap_session *ses)
{
- ppp_terminate(ppp, TERM_NAS_REQUEST, 1);
+ ap_session_terminate(ses, TERM_NAS_REQUEST, 1);
}
static int terminate_exec1(char * const *f, int f_cnt, void *cli)
{
- struct ppp_t *ppp;
+ struct ap_session *ses;
int hard = 0;
pcre *re;
const char *pcre_err;
@@ -126,16 +128,16 @@ static int terminate_exec1(char * const *f, int f_cnt, void *cli)
return CLI_CMD_OK;
}
- pthread_rwlock_rdlock(&ppp_lock);
- list_for_each_entry(ppp, &ppp_list, entry) {
- if (pcre_exec(re, NULL, ppp->username, strlen(ppp->username), 0, 0, NULL, 0) < 0)
+ pthread_rwlock_rdlock(&ses_lock);
+ list_for_each_entry(ses, &ses_list, entry) {
+ if (pcre_exec(re, NULL, ses->username, strlen(ses->username), 0, 0, NULL, 0) < 0)
continue;
if (hard)
- triton_context_call(ppp->ctrl->ctx, (triton_event_func)ppp_terminate_hard, ppp);
+ triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_hard, ses);
else
- triton_context_call(ppp->ctrl->ctx, (triton_event_func)ppp_terminate_soft, ppp);
+ triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_soft, ses);
}
- pthread_rwlock_unlock(&ppp_lock);
+ pthread_rwlock_unlock(&ses_lock);
pcre_free(re);
@@ -144,7 +146,7 @@ static int terminate_exec1(char * const *f, int f_cnt, void *cli)
static int terminate_exec2(int key, char * const *f, int f_cnt, void *cli)
{
- struct ppp_t *ppp;
+ struct ap_session *ses;
int hard = 0;
in_addr_t ipaddr = 0;
@@ -159,44 +161,44 @@ static int terminate_exec2(int key, char * const *f, int f_cnt, void *cli)
if (key == 1)
ipaddr = inet_addr(f[2]);
- pthread_rwlock_rdlock(&ppp_lock);
- list_for_each_entry(ppp, &ppp_list, entry) {
+ pthread_rwlock_rdlock(&ses_lock);
+ list_for_each_entry(ses, &ses_list, entry) {
switch (key) {
case 0:
- if (!ppp->username || strcmp(ppp->username, f[2]))
+ if (!ses->username || strcmp(ses->username, f[2]))
continue;
break;
case 1:
- if (ppp->ipv4 && ppp->ipv4->peer_addr != ipaddr)
+ if (ses->ipv4 && ses->ipv4->peer_addr != ipaddr)
continue;
break;
case 2:
- if (strcmp(ppp->ctrl->calling_station_id, f[2]))
+ if (strcmp(ses->ctrl->calling_station_id, f[2]))
continue;
break;
case 3:
- if (strcmp(ppp->sessionid, f[2]))
+ if (strcmp(ses->sessionid, f[2]))
continue;
break;
case 4:
- if (strcmp(ppp->ifname, f[2]))
+ if (strcmp(ses->ifname, f[2]))
continue;
break;
}
if (hard)
- triton_context_call(ppp->ctrl->ctx, (triton_event_func)ppp_terminate_hard, ppp);
+ triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_hard, ses);
else
- triton_context_call(ppp->ctrl->ctx, (triton_event_func)ppp_terminate_soft, ppp);
+ triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_soft, ses);
break;
}
- pthread_rwlock_unlock(&ppp_lock);
+ pthread_rwlock_unlock(&ses_lock);
return CLI_CMD_OK;
}
static int terminate_exec(const char *cmd, char * const *fields, int fields_cnt, void *client)
{
- struct ppp_t *ppp;
+ struct ap_session *ses;
int hard = 0;
if (fields_cnt == 1)
@@ -225,14 +227,14 @@ static int terminate_exec(const char *cmd, char * const *fields, int fields_cnt,
} else if (fields_cnt != 2)
return CLI_CMD_SYNTAX;
- pthread_rwlock_rdlock(&ppp_lock);
- list_for_each_entry(ppp, &ppp_list, entry) {
+ pthread_rwlock_rdlock(&ses_lock);
+ list_for_each_entry(ses, &ses_list, entry) {
if (hard)
- triton_context_call(ppp->ctrl->ctx, (triton_event_func)ppp_terminate_hard, ppp);
+ triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_hard, ses);
else
- triton_context_call(ppp->ctrl->ctx, (triton_event_func)ppp_terminate_soft, ppp);
+ triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_soft, ses);
}
- pthread_rwlock_unlock(&ppp_lock);
+ pthread_rwlock_unlock(&ses_lock);
return CLI_CMD_OK;
}
@@ -258,44 +260,50 @@ static void shutdown_help(char * const *fields, int fields_cnt, void *client)
cli_send(client, "\t\tcancel - cancel 'shutdown soft' and return to normal operation\r\n");
}
-static void ppp_terminate_soft2(struct ppp_t *ppp)
+static void __terminate_soft2(struct ap_session *ses)
{
- ppp_terminate(ppp, TERM_NAS_REBOOT, 0);
+ ap_session_terminate(ses, TERM_NAS_REBOOT, 0);
}
-static void ppp_terminate_hard2(struct ppp_t *ppp)
+static void __terminate_hard2(struct ap_session *ses)
{
- ppp_terminate(ppp, TERM_NAS_REBOOT, 1);
+ ap_session_terminate(ses, TERM_NAS_REBOOT, 1);
+}
+
+static void terminate_all_sessions(int hard)
+{
+ struct ap_session *ses;
+
+ pthread_rwlock_rdlock(&ses_lock);
+ list_for_each_entry(ses, &ses_list, entry) {
+ if (hard)
+ triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_hard2, ses);
+ else
+ triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_soft2, ses);
+ }
+ pthread_rwlock_unlock(&ses_lock);
}
static int shutdown_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
{
int hard = 0;
- struct ppp_t *ppp;
if (f_cnt == 2) {
if (!strcmp(f[1], "soft")) {
- ppp_shutdown_soft();
+ ap_shutdown_soft(NULL);
return CLI_CMD_OK;
} else if (!strcmp(f[1], "hard"))
hard = 1;
else if (!strcmp(f[1], "cancel")) {
- ppp_shutdown = 0;
+ ap_shutdown = 0;
return CLI_CMD_OK;
} else
return CLI_CMD_SYNTAX;
}
- ppp_shutdown_soft();
+ ap_shutdown_soft(NULL);
- pthread_rwlock_rdlock(&ppp_lock);
- list_for_each_entry(ppp, &ppp_list, entry) {
- if (hard)
- triton_context_call(ppp->ctrl->ctx, (triton_event_func)ppp_terminate_hard2, ppp);
- else
- triton_context_call(ppp->ctrl->ctx, (triton_event_func)ppp_terminate_soft2, ppp);
- }
- pthread_rwlock_unlock(&ppp_lock);
+ terminate_all_sessions(hard);
return CLI_CMD_OK;
}
@@ -328,11 +336,63 @@ static void reload_help(char * const *fields, int fields_cnt, void *client)
cli_send(client, "reload - reload config file\r\n");
}
+
+//==========================
+
+static void __do_restart(void)
+{
+ core_restart(0);
+ _exit(0);
+}
+
+static int restart_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
+{
+ int hard;
+
+ if (f_cnt == 2) {
+ if (strcmp(f[1], "soft") == 0)
+ hard = 0;
+ else if (strcmp(f[1], "gracefully") == 0)
+ hard = 1;
+ else if (strcmp(f[1], "hard") == 0)
+ __do_restart();
+ else
+ return CLI_CMD_SYNTAX;
+ } else if (f_cnt == 1)
+ hard = 0;
+ else
+ return CLI_CMD_SYNTAX;
+
+#ifndef USE_BACKUP
+ hard = 1;
+#endif
+
+ if (hard) {
+ ap_shutdown_soft(__do_restart);
+ terminate_all_sessions(0);
+ } else {
+ core_restart(1);
+ _exit(0);
+ }
+
+ return CLI_CMD_OK;
+}
+
+static void restart_help(char * const *fields, int fields_cnt, void *client)
+{
+ cli_send(client, "restart [soft|gracefully|hard] - restart daemon\r\n");
+ cli_send(client, "\t\tsoft - restart daemon softly, e.g. keep existing connections if session backup is enabled (default)\r\n");
+ cli_send(client, "\t\tgracefully - terminate all connections then restart\r\n");
+ cli_send(client, "\t\thard - restart immediatly\r\n");
+}
+
+
static void init(void)
{
cli_register_simple_cmd2(show_stat_exec, show_stat_help, 2, "show", "stat");
cli_register_simple_cmd2(terminate_exec, terminate_help, 1, "terminate");
cli_register_simple_cmd2(reload_exec, reload_help, 1, "reload");
+ cli_register_simple_cmd2(restart_exec, restart_help, 1, "restart");
cli_register_simple_cmd2(shutdown_exec, shutdown_help, 1, "shutdown");
cli_register_simple_cmd2(exit_exec, exit_help, 1, "exit");
}
diff --git a/accel-pppd/cli/telnet.c b/accel-pppd/cli/telnet.c
index 314ac9e..e9e886d 100644
--- a/accel-pppd/cli/telnet.c
+++ b/accel-pppd/cli/telnet.c
@@ -220,7 +220,7 @@ static int send_password_request(struct telnet_client_t *cln)
static int send_prompt(struct telnet_client_t *cln)
{
- sprintf((char *)temp_buf, "%s%s# ", conf_cli_prompt, ppp_shutdown ? "(shutdown)" : "");
+ sprintf((char *)temp_buf, "%s%s# ", conf_cli_prompt, ap_shutdown ? "(shutdown)" : "");
return telnet_send(cln, temp_buf, strlen((char *)temp_buf));
}
@@ -292,7 +292,7 @@ static int telnet_input_char(struct telnet_client_t *cln, uint8_t c)
return -1;
}
cln->auth = 1;
- if (ppp_shutdown) {
+ if (ap_shutdown) {
if (telnet_send(cln, MSG_SHUTDOWN_IN_PROGRESS, sizeof(MSG_SHUTDOWN_IN_PROGRESS)))
return -1;
}
@@ -555,6 +555,8 @@ static int serv_read(struct triton_md_handler_t *h)
continue;
}
+ fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC);
+
conn = _malloc(sizeof(*conn));
memset(conn, 0, sizeof(*conn));
conn->hnd.fd = sock;
@@ -600,7 +602,7 @@ static int serv_read(struct triton_md_handler_t *h)
send_password_request(conn);
else {
conn->auth = 1;
- if (ppp_shutdown) {
+ if (ap_shutdown) {
if (telnet_send(conn, MSG_SHUTDOWN_IN_PROGRESS, sizeof(MSG_SHUTDOWN_IN_PROGRESS)))
continue;
}