summaryrefslogtreecommitdiff
path: root/accel-pppd/cli
diff options
context:
space:
mode:
authorKozlov Dmitry <xeb@mail.ru>2012-06-19 19:06:06 +0400
committerKozlov Dmitry <xeb@mail.ru>2012-06-19 19:06:06 +0400
commit02b3fb2b24aacd90d535c2136a055f529d722974 (patch)
tree6243dd815869add07be2bad5846e7817b732ac59 /accel-pppd/cli
parentc553a7bbbc96d36ba4d0999bb172c7a926518eb1 (diff)
downloadaccel-ppp-02b3fb2b24aacd90d535c2136a055f529d722974.tar.gz
accel-ppp-02b3fb2b24aacd90d535c2136a055f529d722974.zip
general preparation for IPoE integration
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.c88
-rw-r--r--accel-pppd/cli/telnet.c6
4 files changed, 90 insertions, 82 deletions
diff --git a/accel-pppd/cli/cli.h b/accel-pppd/cli/cli.h
index cdceb2fa..3e31c5d8 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 c0fec580..746ce583 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 24e52283..0e1a7b21 100644
--- a/accel-pppd/cli/std_cmd.c
+++ b/accel-pppd/cli/std_cmd.c
@@ -69,9 +69,9 @@ static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt,
//===========
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_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 +94,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 +126,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 +144,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 +159,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 +225,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 +258,44 @@ 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 int shutdown_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
{
int hard = 0;
- struct ppp_t *ppp;
+ struct ap_session *ses;
if (f_cnt == 2) {
if (!strcmp(f[1], "soft")) {
- ppp_shutdown_soft();
+ ap_shutdown_soft();
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();
- 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_hard2, ppp);
+ triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_hard2, ses);
else
- triton_context_call(ppp->ctrl->ctx, (triton_event_func)ppp_terminate_soft2, ppp);
+ triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_soft2, ses);
}
- pthread_rwlock_unlock(&ppp_lock);
+ pthread_rwlock_unlock(&ses_lock);
return CLI_CMD_OK;
}
diff --git a/accel-pppd/cli/telnet.c b/accel-pppd/cli/telnet.c
index f7b43115..543e32cc 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;
}
@@ -600,7 +600,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;
}