diff options
65 files changed, 1489 insertions, 1170 deletions
diff --git a/accel-pppd/CMakeLists.txt b/accel-pppd/CMakeLists.txt index 30e6c910..a65f7fef 100644 --- a/accel-pppd/CMakeLists.txt +++ b/accel-pppd/CMakeLists.txt @@ -42,8 +42,10 @@ ADD_SUBDIRECTORY(ipv6) ADD_SUBDIRECTORY(shaper) ADD_EXECUTABLE(accel-pppd + session.c + ifcfg.c + ppp/ppp.c - ppp/ppp_ifcfg.c ppp/ppp_fsm.c ppp/ppp_lcp.c ppp/lcp_opt_mru.c diff --git a/accel-pppd/auth/auth_chap_md5.c b/accel-pppd/auth/auth_chap_md5.c index 4b8206b4..a43081d8 100644 --- a/accel-pppd/auth/auth_chap_md5.c +++ b/accel-pppd/auth/auth_chap_md5.c @@ -163,7 +163,7 @@ static void chap_timeout_timer(struct triton_timer_t *t) if (++d->failure == conf_max_failure) { if (d->started) - ppp_terminate(d->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&d->ppp->ses, TERM_USER_ERROR, 0); else ppp_auth_failed(d->ppp, NULL); } else { @@ -248,7 +248,7 @@ static void chap_send_challenge(struct chap_auth_data_t *ad, int new) ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); if (conf_timeout && !ad->timeout.tpd) - triton_timer_add(ad->ppp->ctrl->ctx, &ad->timeout, 0); + triton_timer_add(ad->ppp->ses.ctrl->ctx, &ad->timeout, 0); } static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *hdr) @@ -281,7 +281,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h log_ppp_error("chap-md5: incorrect value-size (%i)\n", msg->val_size); chap_send_failure(ad); if (ad->started) - ppp_terminate(ad->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&ad->ppp->ses, TERM_USER_ERROR, 0); else ppp_auth_failed(ad->ppp, NULL); return; @@ -292,7 +292,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (conf_any_login) { if (ppp_auth_successed(ad->ppp, name)) { chap_send_failure(ad); - ppp_terminate(ad->ppp, TERM_AUTH_ERROR, 0); + ap_session_terminate(&ad->ppp->ses, TERM_AUTH_ERROR, 0); _free(name); return; } @@ -301,10 +301,10 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h return; } - r = pwdb_check(ad->ppp, name, PPP_CHAP, CHAP_MD5, ad->id, ad->val, VALUE_SIZE, msg->val); + r = pwdb_check(&ad->ppp->ses, name, PPP_CHAP, CHAP_MD5, ad->id, ad->val, VALUE_SIZE, msg->val); if (r == PWDB_NO_IMPL) { - passwd = pwdb_get_passwd(ad->ppp,name); + passwd = pwdb_get_passwd(&ad->ppp->ses, name); if (!passwd) { _free(name); @@ -326,7 +326,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h log_ppp_warn("chap-md5: challenge response mismatch\n"); chap_send_failure(ad); if (ad->started) - ppp_terminate(ad->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&ad->ppp->ses, TERM_USER_ERROR, 0); else ppp_auth_failed(ad->ppp, name); _free(name); @@ -334,13 +334,13 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (!ad->started) { if (ppp_auth_successed(ad->ppp, name)) { chap_send_failure(ad); - ppp_terminate(ad->ppp, TERM_AUTH_ERROR, 0); + ap_session_terminate(&ad->ppp->ses, TERM_AUTH_ERROR, 0); _free(name); } else { chap_send_success(ad); ad->started = 1; if (conf_interval) - triton_timer_add(ad->ppp->ctrl->ctx, &ad->interval, 0); + triton_timer_add(ad->ppp->ses.ctrl->ctx, &ad->interval, 0); } } else _free(name); @@ -349,7 +349,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h } else if (r == PWDB_DENIED) { chap_send_failure(ad); if (ad->started) - ppp_terminate(ad->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&ad->ppp->ses, TERM_USER_ERROR, 0); else ppp_auth_failed(ad->ppp, name); _free(name); @@ -357,13 +357,13 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (!ad->started) { if (ppp_auth_successed(ad->ppp, name)) { chap_send_failure(ad); - ppp_terminate(ad->ppp, TERM_AUTH_ERROR, 0); + ap_session_terminate(&ad->ppp->ses, TERM_AUTH_ERROR, 0); _free(name); } else { chap_send_success(ad); ad->started = 1; if (conf_interval) - triton_timer_add(ad->ppp->ctrl->ctx, &ad->interval, 0); + triton_timer_add(ad->ppp->ses.ctrl->ctx, &ad->interval, 0); } } else { chap_send_success(ad); diff --git a/accel-pppd/auth/auth_mschap_v1.c b/accel-pppd/auth/auth_mschap_v1.c index f0b58f45..fd1a60a8 100644 --- a/accel-pppd/auth/auth_mschap_v1.c +++ b/accel-pppd/auth/auth_mschap_v1.c @@ -164,7 +164,7 @@ static void chap_timeout_timer(struct triton_timer_t *t) if (++d->failure == conf_max_failure) { if (d->started) - ppp_terminate(d->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&d->ppp->ses, TERM_USER_ERROR, 0); else ppp_auth_failed(d->ppp, NULL); } else { @@ -251,7 +251,7 @@ static void chap_send_challenge(struct chap_auth_data_t *ad, int new) ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); if (conf_timeout && !ad->timeout.tpd) - triton_timer_add(ad->ppp->ctrl->ctx, &ad->timeout, 0); + triton_timer_add(ad->ppp->ses.ctrl->ctx, &ad->timeout, 0); } static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *hdr) @@ -283,7 +283,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (msg->val_size != RESPONSE_VALUE_SIZE) { log_ppp_error("mschap-v1: incorrect value-size (%i)\n", msg->val_size); if (ad->started) - ppp_terminate(ad->ppp, TERM_AUTH_ERROR, 0); + ap_session_terminate(&ad->ppp->ses, TERM_AUTH_ERROR, 0); else ppp_auth_failed(ad->ppp, NULL); return; @@ -293,7 +293,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (!name) { log_emerg("mschap-v1: out of memory\n"); if (ad->started) - ppp_terminate(ad->ppp, TERM_NAS_ERROR, 0); + ap_session_terminate(&ad->ppp->ses, TERM_NAS_ERROR, 0); else ppp_auth_failed(ad->ppp, NULL); return; @@ -302,7 +302,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (conf_any_login) { if (ppp_auth_successed(ad->ppp, name)) { chap_send_failure(ad, mschap_error); - ppp_terminate(ad->ppp, TERM_AUTH_ERROR, 0); + ap_session_terminate(&ad->ppp->ses, TERM_AUTH_ERROR, 0); _free(name); return; } @@ -311,7 +311,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h return; } - r = pwdb_check(ad->ppp, name, PPP_CHAP, MSCHAP_V1, ad->id, ad->val, VALUE_SIZE, msg->lm_hash, msg->nt_hash, msg->flags, &mschap_error); + r = pwdb_check(&ad->ppp->ses, name, PPP_CHAP, MSCHAP_V1, ad->id, ad->val, VALUE_SIZE, msg->lm_hash, msg->nt_hash, msg->flags, &mschap_error); if (r == PWDB_NO_IMPL) if (chap_check_response(ad, msg, name)) r = PWDB_DENIED; @@ -319,7 +319,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (r == PWDB_DENIED) { chap_send_failure(ad, mschap_error); if (ad->started) - ppp_terminate(ad->ppp, TERM_AUTH_ERROR, 0); + ap_session_terminate(&ad->ppp->ses, TERM_AUTH_ERROR, 0); else ppp_auth_failed(ad->ppp, name); _free(name); @@ -327,13 +327,13 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (!ad->started) { if (ppp_auth_successed(ad->ppp, name)) { chap_send_failure(ad, mschap_error); - ppp_terminate(ad->ppp, TERM_AUTH_ERROR, 0); + ap_session_terminate(&ad->ppp->ses, TERM_AUTH_ERROR, 0); _free(name); } else { chap_send_success(ad); ad->started = 1; if (conf_interval) - triton_timer_add(ad->ppp->ctrl->ctx, &ad->interval, 0); + triton_timer_add(ad->ppp->ses.ctrl->ctx, &ad->interval, 0); } } else { chap_send_success(ad); @@ -380,7 +380,7 @@ static int chap_check_response(struct chap_auth_data_t *ad, struct chap_response char *u_passwd; int i; - passwd = pwdb_get_passwd(ad->ppp,name); + passwd = pwdb_get_passwd(&ad->ppp->ses, name); if (!passwd) { if (conf_ppp_verbose) log_ppp_warn("mschap-v1: user not found\n"); diff --git a/accel-pppd/auth/auth_mschap_v2.c b/accel-pppd/auth/auth_mschap_v2.c index aeb49077..ffb6fbf4 100644 --- a/accel-pppd/auth/auth_mschap_v2.c +++ b/accel-pppd/auth/auth_mschap_v2.c @@ -165,7 +165,7 @@ static void chap_timeout_timer(struct triton_timer_t *t) if (++d->failure == conf_max_failure) { if (d->started) - ppp_terminate(d->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&d->ppp->ses, TERM_USER_ERROR, 0); else ppp_auth_failed(d->ppp, NULL); } else { @@ -254,7 +254,7 @@ static int generate_response(struct chap_auth_data_t *ad, struct chap_response_t 0x6E}; - passwd = pwdb_get_passwd(ad->ppp,name); + passwd = pwdb_get_passwd(&ad->ppp->ses, name); if (!passwd) return -1; @@ -324,7 +324,7 @@ static void chap_send_challenge(struct chap_auth_data_t *ad, int new) ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); if (conf_timeout && !ad->timeout.tpd) - triton_timer_add(ad->ppp->ctrl->ctx, &ad->timeout, 0); + triton_timer_add(ad->ppp->ses.ctrl->ctx, &ad->timeout, 0); } static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *hdr) @@ -361,7 +361,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h log_ppp_error("mschap-v2: incorrect value-size (%i)\n", msg->val_size); chap_send_failure(ad, mschap_error, reply_msg); if (ad->started) - ppp_terminate(ad->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&ad->ppp->ses, TERM_USER_ERROR, 0); else ppp_auth_failed(ad->ppp, NULL); return; @@ -371,13 +371,13 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (!name) { log_emerg("mschap-v2: out of memory\n"); if (ad->started) - ppp_terminate(ad->ppp, TERM_NAS_ERROR, 0); + ap_session_terminate(&ad->ppp->ses, TERM_NAS_ERROR, 0); else ppp_auth_failed(ad->ppp, NULL); return; } - r = pwdb_check(ad->ppp, name, PPP_CHAP, MSCHAP_V2, ad->id, ad->val, msg->peer_challenge, msg->reserved, msg->nt_hash, msg->flags, authenticator, &mschap_error, &reply_msg); + r = pwdb_check(&ad->ppp->ses, name, PPP_CHAP, MSCHAP_V2, ad->id, ad->val, msg->peer_challenge, msg->reserved, msg->nt_hash, msg->flags, authenticator, &mschap_error, &reply_msg); if (r == PWDB_NO_IMPL) { r = chap_check_response(ad, msg, name); @@ -390,7 +390,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (r == PWDB_DENIED) { chap_send_failure(ad, mschap_error, reply_msg); if (ad->started) - ppp_terminate(ad->ppp, TERM_AUTH_ERROR, 0); + ap_session_terminate(&ad->ppp->ses, TERM_AUTH_ERROR, 0); else ppp_auth_failed(ad->ppp, name); _free(name); @@ -398,13 +398,13 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (!ad->started) { if (ppp_auth_successed(ad->ppp, name)) { chap_send_failure(ad, mschap_error, reply_msg); - ppp_terminate(ad->ppp, TERM_AUTH_ERROR, 0); + ap_session_terminate(&ad->ppp->ses, TERM_AUTH_ERROR, 0); _free(name); } else { chap_send_success(ad, msg, authenticator); ad->started = 1; if (conf_interval) - triton_timer_add(ad->ppp->ctrl->ctx, &ad->interval, 0); + triton_timer_add(ad->ppp->ses.ctrl->ctx, &ad->interval, 0); } } else { chap_send_success(ad, msg, authenticator); @@ -453,7 +453,7 @@ static int chap_check_response(struct chap_auth_data_t *ad, struct chap_response char *u_passwd; int i; - passwd = pwdb_get_passwd(ad->ppp, name); + passwd = pwdb_get_passwd(&ad->ppp->ses, name); if (!passwd) { if (conf_ppp_verbose) log_ppp_warn("mschap-v2: user not found\n"); diff --git a/accel-pppd/auth/auth_pap.c b/accel-pppd/auth/auth_pap.c index 4ab9bbbf..206ecde6 100644 --- a/accel-pppd/auth/auth_pap.c +++ b/accel-pppd/auth/auth_pap.c @@ -95,7 +95,7 @@ static int pap_start(struct ppp_t *ppp, struct auth_data_t *auth) d->timeout.expire = pap_timeout; d->timeout.period = conf_timeout * 1000; - triton_timer_add(ppp->ctrl->ctx, &d->timeout, 0); + triton_timer_add(ppp->ses.ctrl->ctx, &d->timeout, 0); ppp_register_chan_handler(ppp, &d->h); @@ -201,7 +201,7 @@ static int pap_recv_req(struct pap_auth_data_t *p, struct pap_hdr_t *hdr) if (conf_any_login) { if (ppp_auth_successed(p->ppp, peer_id)) { pap_send_nak(p, hdr->id); - ppp_terminate(p->ppp, TERM_AUTH_ERROR, 0); + ap_session_terminate(&p->ppp->ses, TERM_AUTH_ERROR, 0); _free(peer_id); return -1; } @@ -212,9 +212,9 @@ static int pap_recv_req(struct pap_auth_data_t *p, struct pap_hdr_t *hdr) passwd = _strndup((const char*)ptr, passwd_len); - r = pwdb_check(p->ppp, peer_id, PPP_PAP, passwd); + r = pwdb_check(&p->ppp->ses, peer_id, PPP_PAP, passwd); if (r == PWDB_NO_IMPL) { - passwd2 = pwdb_get_passwd(p->ppp, peer_id); + passwd2 = pwdb_get_passwd(&p->ppp->ses, peer_id); if (!passwd2 || strcmp(passwd2, passwd)) r = PWDB_DENIED; else @@ -226,7 +226,7 @@ static int pap_recv_req(struct pap_auth_data_t *p, struct pap_hdr_t *hdr) log_ppp_warn("PAP: authentication error\n"); pap_send_nak(p, hdr->id); if (p->started) - ppp_terminate(p->ppp, TERM_AUTH_ERROR, 0); + ap_session_terminate(&p->ppp->ses, TERM_AUTH_ERROR, 0); else ppp_auth_failed(p->ppp, peer_id); ret = -1; @@ -234,7 +234,7 @@ static int pap_recv_req(struct pap_auth_data_t *p, struct pap_hdr_t *hdr) } else { if (ppp_auth_successed(p->ppp, peer_id)) { pap_send_nak(p, hdr->id); - ppp_terminate(p->ppp, TERM_AUTH_ERROR, 0); + ap_session_terminate(&p->ppp->ses, TERM_AUTH_ERROR, 0); _free(peer_id); ret = -1; } else { 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; } diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index d8a98f8d..e3db614a 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -94,7 +94,7 @@ struct l2tp_conn_t int state1; int state2; - struct ppp_ctrl_t ctrl; + struct ap_ctrl ctrl; struct ppp_t ppp; }; @@ -130,7 +130,7 @@ static void l2tp_disconnect(struct l2tp_conn_t *conn) if (conn->state == STATE_PPP) { __sync_sub_and_fetch(&stat_active, 1); conn->state = STATE_FIN; - ppp_terminate(&conn->ppp, TERM_USER_REQUEST, 1); + ap_session_terminate(&conn->ppp.ses, TERM_USER_REQUEST, 1); } else if (conn->state != STATE_FIN) __sync_sub_and_fetch(&stat_starting, 1); @@ -156,8 +156,8 @@ static void l2tp_disconnect(struct l2tp_conn_t *conn) l2tp_packet_free(pack); } - if (conn->ppp.chan_name) - _free(conn->ppp.chan_name); + if (conn->ppp.ses.chan_name) + _free(conn->ppp.ses.chan_name); if (conn->challenge_len) _free(conn->challenge.octets); _free(conn->ctrl.calling_station_id); @@ -193,8 +193,9 @@ out_err: return -1; } -static void l2tp_ppp_started(struct ppp_t *ppp) +static void l2tp_ppp_started(struct ap_session *ses) { + struct ppp_t *ppp = container_of(ses, typeof(*ppp), ses); struct l2tp_conn_t *conn = container_of(ppp, typeof(*conn), ppp); log_ppp_debug("l2tp: ppp started\n"); @@ -203,8 +204,9 @@ static void l2tp_ppp_started(struct ppp_t *ppp) triton_timer_add(&conn->ctx, &conn->hello_timer, 0); } -static void l2tp_ppp_finished(struct ppp_t *ppp) +static void l2tp_ppp_finished(struct ap_session *ses) { + struct ppp_t *ppp = container_of(ses, typeof(*ppp), ses); struct l2tp_conn_t *conn = container_of(ppp, typeof(*conn), ppp); log_ppp_debug("l2tp: ppp finished\n"); @@ -223,7 +225,7 @@ static void l2tp_conn_close(struct triton_context_t *ctx) if (conn->state == STATE_PPP) { __sync_sub_and_fetch(&stat_active, 1); conn->state = STATE_FIN; - ppp_terminate(&conn->ppp, TERM_ADMIN_RESET, 1); + ap_session_terminate(&conn->ppp.ses, TERM_ADMIN_RESET, 1); } if (l2tp_terminate(conn, 0, 0)) @@ -343,11 +345,11 @@ static int l2tp_tunnel_alloc(struct l2tp_serv_t *serv, struct l2tp_packet_t *pac u_inet_ntoa(addr.sin_addr.s_addr, conn->ctrl.called_station_id); ppp_init(&conn->ppp); - conn->ppp.ctrl = &conn->ctrl; + conn->ppp.ses.ctrl = &conn->ctrl; conn->ppp.fd = -1; conn->tunnel_fd = -1; - triton_context_register(&conn->ctx, &conn->ppp); + triton_context_register(&conn->ctx, &conn->ppp.ses); triton_md_register_handler(&conn->ctx, &conn->hnd); triton_md_enable_handler(&conn->hnd, MD_MODE_READ); triton_context_wakeup(&conn->ctx); @@ -419,7 +421,7 @@ static int l2tp_connect(struct l2tp_conn_t *conn) return -1; } - conn->ppp.chan_name = _strdup(inet_ntoa(conn->addr.sin_addr)); + conn->ppp.ses.chan_name = _strdup(inet_ntoa(conn->addr.sin_addr)); triton_event_fire(EV_CTRL_STARTED, &conn->ppp); @@ -654,7 +656,7 @@ static int l2tp_recv_SCCRQ(struct l2tp_serv_t *serv, struct l2tp_packet_t *pack, struct l2tp_attr_t *router_id = NULL; struct l2tp_attr_t *challenge = NULL; - if (ppp_shutdown) + if (ap_shutdown) return 0; if (triton_module_loaded("connlimit") && connlimit_check(cl_key_from_ipv4(pack->addr.sin_addr.s_addr))) @@ -863,7 +865,7 @@ static int l2tp_recv_CDN(struct l2tp_conn_t *conn, struct l2tp_packet_t *pack) if (conn->state == STATE_PPP) { __sync_sub_and_fetch(&stat_active, 1); conn->state = STATE_FIN; - ppp_terminate(&conn->ppp, TERM_USER_REQUEST, 1); + ap_session_terminate(&conn->ppp.ses, TERM_USER_REQUEST, 1); } if (l2tp_terminate(conn, 0, 0)) diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c index f616ade4..7981eba1 100644 --- a/accel-pppd/ctrl/pppoe/pppoe.c +++ b/accel-pppd/ctrl/pppoe/pppoe.c @@ -48,7 +48,7 @@ struct pppoe_conn_t struct pppoe_tag *tr101; uint8_t cookie[COOKIE_LENGTH]; - struct ppp_ctrl_t ctrl; + struct ap_ctrl ctrl; struct ppp_t ppp; #ifdef RADIUS struct rad_plugin_t radius; @@ -112,7 +112,7 @@ static void disconnect(struct pppoe_conn_t *conn) if (conn->ppp_started) { dpado_check_prev(__sync_fetch_and_sub(&stat_active, 1)); conn->ppp_started = 0; - ppp_terminate(&conn->ppp, TERM_USER_REQUEST, 1); + ap_session_terminate(&conn->ppp.ses, TERM_USER_REQUEST, 1); } pppoe_send_PADT(conn); @@ -149,13 +149,14 @@ static void disconnect(struct pppoe_conn_t *conn) mempool_free(conn); } -static void ppp_started(struct ppp_t *ppp) +static void ppp_started(struct ap_session *ses) { log_ppp_debug("pppoe: ppp started\n"); } -static void ppp_finished(struct ppp_t *ppp) +static void ppp_finished(struct ap_session *ses) { + struct ppp_t *ppp = container_of(ses, typeof(*ppp), ses); struct pppoe_conn_t *conn = container_of(ppp, typeof(*conn), ppp); log_ppp_debug("pppoe: ppp finished\n"); @@ -172,7 +173,7 @@ static void pppoe_conn_close(struct triton_context_t *ctx) struct pppoe_conn_t *conn = container_of(ctx, typeof(*conn), ctx); if (conn->ppp_started) - ppp_terminate(&conn->ppp, TERM_ADMIN_RESET, 0); + ap_session_terminate(&conn->ppp.ses, TERM_ADMIN_RESET, 0); else disconnect(conn); } @@ -261,6 +262,7 @@ static struct pppoe_conn_t *allocate_channel(struct pppoe_serv_t *serv, const ui conn->ctrl.ctx = &conn->ctx; conn->ctrl.started = ppp_started; conn->ctrl.finished = ppp_finished; + conn->ctrl.terminate = ppp_terminate; conn->ctrl.max_mtu = MAX_PPPOE_MTU; conn->ctrl.type = CTRL_TYPE_PPPOE; conn->ctrl.name = "pppoe"; @@ -285,10 +287,10 @@ static struct pppoe_conn_t *allocate_channel(struct pppoe_serv_t *serv, const ui ppp_init(&conn->ppp); - conn->ppp.ctrl = &conn->ctrl; - conn->ppp.chan_name = conn->ctrl.calling_station_id; + conn->ppp.ses.ctrl = &conn->ctrl; + conn->ppp.ses.chan_name = conn->ctrl.calling_station_id; - triton_context_register(&conn->ctx, &conn->ppp); + triton_context_register(&conn->ctx, &conn->ppp.ses); triton_context_wakeup(&conn->ctx); triton_event_fire(EV_CTRL_STARTING, &conn->ppp); @@ -334,7 +336,7 @@ static void connect_channel(struct pppoe_conn_t *conn) if (conn->tr101 && triton_module_loaded("radius")) { conn->radius.send_access_request = pppoe_rad_send_access_request; conn->radius.send_accounting_request = pppoe_rad_send_accounting_request; - rad_register_plugin(&conn->ppp, &conn->radius); + rad_register_plugin(&conn->ppp.ses, &conn->radius); } #endif @@ -704,7 +706,7 @@ static void pado_timer(struct triton_timer_t *t) { struct delayed_pado_t *pado = container_of(t, typeof(*pado), timer); - if (!ppp_shutdown) + if (!ap_shutdown) pppoe_send_PADO(pado->serv, pado->addr, pado->host_uniq, pado->relay_sid, pado->service_name); free_delayed_pado(pado); @@ -774,7 +776,7 @@ static void pppoe_recv_PADI(struct pppoe_serv_t *serv, uint8_t *pack, int size) __sync_add_and_fetch(&stat_PADI_recv, 1); - if (ppp_shutdown || pado_delay == -1) + if (ap_shutdown || pado_delay == -1) return; if (check_padi_limit(serv, ethhdr->h_source)) { @@ -886,7 +888,7 @@ static void pppoe_recv_PADR(struct pppoe_serv_t *serv, uint8_t *pack, int size) __sync_add_and_fetch(&stat_PADR_recv, 1); - if (ppp_shutdown) + if (ap_shutdown) return; if (!memcmp(ethhdr->h_dest, bc_addr, ETH_ALEN)) { @@ -972,7 +974,7 @@ static void pppoe_recv_PADR(struct pppoe_serv_t *serv, uint8_t *pack, int size) pthread_mutex_lock(&serv->lock); conn = find_channel(serv, (uint8_t *)ac_cookie_tag->tag_data); - if (conn && !conn->ppp.username) { + if (conn && !conn->ppp.ses.username) { __sync_add_and_fetch(&stat_PADR_dup_recv, 1); pppoe_send_PADS(conn); } @@ -1277,7 +1279,7 @@ out_err: static void _conn_stop(struct pppoe_conn_t *conn) { - ppp_terminate(&conn->ppp, TERM_ADMIN_RESET, 0); + ap_session_terminate(&conn->ppp.ses, TERM_ADMIN_RESET, 0); } static void _server_stop(struct pppoe_serv_t *serv) diff --git a/accel-pppd/ctrl/pptp/pptp.c b/accel-pppd/ctrl/pptp/pptp.c index 2f0c5efd..59d50984 100644 --- a/accel-pppd/ctrl/pptp/pptp.c +++ b/accel-pppd/ctrl/pptp/pptp.c @@ -50,7 +50,7 @@ struct pptp_conn_t int out_size; int out_pos; - struct ppp_ctrl_t ctrl; + struct ap_ctrl ctrl; struct ppp_t ppp; }; @@ -68,8 +68,8 @@ static unsigned int 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 *); -static void ppp_started(struct ppp_t *); -static void ppp_finished(struct ppp_t *); +static void ppp_started(struct ap_session *); +static void ppp_finished(struct ap_session *); static void disconnect(struct pptp_conn_t *conn) { @@ -87,7 +87,7 @@ static void disconnect(struct pptp_conn_t *conn) if (conn->state == STATE_PPP) { __sync_sub_and_fetch(&stat_active, 1); conn->state = STATE_CLOSE; - ppp_terminate(&conn->ppp, TERM_LOST_CARRIER, 1); + ap_session_terminate(&conn->ppp.ses, TERM_LOST_CARRIER, 1); } else if (conn->state != STATE_CLOSE) __sync_sub_and_fetch(&stat_starting, 1); @@ -97,8 +97,8 @@ static void disconnect(struct pptp_conn_t *conn) triton_context_unregister(&conn->ctx); - if (conn->ppp.chan_name) - _free(conn->ppp.chan_name); + if (conn->ppp.ses.chan_name) + _free(conn->ppp.ses.chan_name); _free(conn->in_buf); _free(conn->out_buf); @@ -325,7 +325,7 @@ static int pptp_out_call_rqst(struct pptp_conn_t *conn) conn->call_id = src_addr.sa_addr.pptp.call_id; conn->peer_call_id = msg->call_id; conn->ppp.fd = pptp_sock; - conn->ppp.chan_name = _strdup(inet_ntoa(dst_addr.sa_addr.pptp.sin_addr)); + conn->ppp.ses.chan_name = _strdup(inet_ntoa(dst_addr.sa_addr.pptp.sin_addr)); triton_event_fire(EV_CTRL_STARTED, &conn->ppp); @@ -379,7 +379,7 @@ static int pptp_call_clear_rqst(struct pptp_conn_t *conn) if (conn->state == STATE_PPP) { __sync_sub_and_fetch(&stat_active, 1); conn->state = STATE_CLOSE; - ppp_terminate(&conn->ppp, TERM_USER_REQUEST, 1); + ap_session_terminate(&conn->ppp.ses, TERM_USER_REQUEST, 1); } return send_pptp_call_disconnect_notify(conn, 4); @@ -561,7 +561,7 @@ static void pptp_close(struct triton_context_t *ctx) if (conn->state == STATE_PPP) { __sync_sub_and_fetch(&stat_active, 1); conn->state = STATE_CLOSE; - ppp_terminate(&conn->ppp, TERM_ADMIN_RESET, 1); + ap_session_terminate(&conn->ppp.ses, TERM_ADMIN_RESET, 1); if (send_pptp_call_disconnect_notify(conn, 3)) { triton_context_call(&conn->ctx, (void (*)(void*))disconnect, conn); return; @@ -578,12 +578,13 @@ static void pptp_close(struct triton_context_t *ctx) else triton_timer_add(ctx, &conn->timeout_timer, 0); } -static void ppp_started(struct ppp_t *ppp) +static void ppp_started(struct ap_session *ses) { log_ppp_debug("pptp: ppp started\n"); } -static void ppp_finished(struct ppp_t *ppp) +static void ppp_finished(struct ap_session *ses) { + struct ppp_t *ppp = container_of(ses, typeof(*ppp), ses); struct pptp_conn_t *conn = container_of(ppp, typeof(*conn), ppp); if (conn->state != STATE_CLOSE) { @@ -628,7 +629,7 @@ static int pptp_connect(struct triton_md_handler_t *h) continue; } - if (ppp_shutdown) { + if (ap_shutdown) { close(sock); continue; } @@ -667,6 +668,7 @@ static int pptp_connect(struct triton_md_handler_t *h) conn->ctrl.ctx = &conn->ctx; conn->ctrl.started = ppp_started; conn->ctrl.finished = ppp_finished; + conn->ctrl.terminate = ppp_terminate; conn->ctrl.max_mtu = PPTP_MAX_MTU; conn->ctrl.type = CTRL_TYPE_PPTP; conn->ctrl.name = "pptp"; @@ -679,9 +681,9 @@ static int pptp_connect(struct triton_md_handler_t *h) u_inet_ntoa(addr.sin_addr.s_addr, conn->ctrl.called_station_id); ppp_init(&conn->ppp); - conn->ppp.ctrl = &conn->ctrl; + conn->ppp.ses.ctrl = &conn->ctrl; - triton_context_register(&conn->ctx, &conn->ppp); + triton_context_register(&conn->ctx, &conn->ppp.ses); triton_md_register_handler(&conn->ctx, &conn->hnd); triton_md_enable_handler(&conn->hnd,MD_MODE_READ); triton_timer_add(&conn->ctx, &conn->timeout_timer, 0); diff --git a/accel-pppd/extra/chap-secrets.c b/accel-pppd/extra/chap-secrets.c index db1bbb2f..c0e620b1 100644 --- a/accel-pppd/extra/chap-secrets.c +++ b/accel-pppd/extra/chap-secrets.c @@ -23,7 +23,7 @@ static struct ipdb_t ipdb; struct cs_pd_t { - struct ppp_pd_t pd; + struct ap_private pd; struct ipv4db_item_t ip; char *passwd; char *rate; @@ -93,7 +93,7 @@ static int split(char *buf, char **ptr) } -static struct cs_pd_t *create_pd(struct ppp_t *ppp, const char *username) +static struct cs_pd_t *create_pd(struct ap_session *ses, const char *username) { FILE *f; char *buf; @@ -161,7 +161,7 @@ found: if (n >= 4) pd->rate = _strdup(ptr[3]); - list_add_tail(&pd->pd.entry, &ppp->pd_list); + list_add_tail(&pd->pd.entry, &ses->pd_list); fclose(f); _free(buf); @@ -169,11 +169,11 @@ found: return pd; } -static struct cs_pd_t *find_pd(struct ppp_t *ppp) +static struct cs_pd_t *find_pd(struct ap_session *ses) { - struct ppp_pd_t *pd; + struct ap_private *pd; - list_for_each_entry(pd, &ppp->pd_list, entry) { + list_for_each_entry(pd, &ses->pd_list, entry) { if (pd->key == &pd_key) { return container_of(pd, typeof(struct cs_pd_t), pd); } @@ -182,9 +182,9 @@ static struct cs_pd_t *find_pd(struct ppp_t *ppp) return NULL; } -static void ev_ppp_finished(struct ppp_t *ppp) +static void ev_ses_finished(struct ap_session *ses) { - struct cs_pd_t *pd = find_pd(ppp); + struct cs_pd_t *pd = find_pd(ses); if (!pd) return; @@ -196,11 +196,11 @@ static void ev_ppp_finished(struct ppp_t *ppp) _free(pd); } -static void ev_ppp_pre_up(struct ppp_t *ppp) +static void ev_ses_pre_up(struct ap_session *ses) { - struct cs_pd_t *pd = find_pd(ppp); + struct cs_pd_t *pd = find_pd(ses); struct ev_shaper_t ev = { - .ppp = ppp, + .ses = ses, }; if (!pd) @@ -212,14 +212,14 @@ static void ev_ppp_pre_up(struct ppp_t *ppp) } } -static struct ipv4db_item_t *get_ip(struct ppp_t *ppp) +static struct ipv4db_item_t *get_ip(struct ap_session *ses) { struct cs_pd_t *pd; if (!conf_gw_ip_address) return NULL; - pd = find_pd(ppp); + pd = find_pd(ses); if (!pd) return NULL; @@ -230,12 +230,12 @@ static struct ipv4db_item_t *get_ip(struct ppp_t *ppp) return &pd->ip; } -static char* get_passwd(struct pwdb_t *pwdb, struct ppp_t *ppp, const char *username) +static char* get_passwd(struct pwdb_t *pwdb, struct ap_session *ses, const char *username) { - struct cs_pd_t *pd = find_pd(ppp); + struct cs_pd_t *pd = find_pd(ses); if (!pd) - pd = create_pd(ppp, username); + pd = create_pd(ses, username); if (!pd) return NULL; @@ -275,8 +275,8 @@ static void init(void) pwdb_register(&pwdb); ipdb_register(&ipdb); - triton_event_register_handler(EV_PPP_FINISHED, (triton_event_func)ev_ppp_finished); - triton_event_register_handler(EV_PPP_PRE_UP, (triton_event_func)ev_ppp_pre_up); + triton_event_register_handler(EV_SES_FINISHED, (triton_event_func)ev_ses_finished); + triton_event_register_handler(EV_SES_PRE_UP, (triton_event_func)ev_ses_pre_up); triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); } diff --git a/accel-pppd/extra/ippool.c b/accel-pppd/extra/ippool.c index fc4fd182..ab2dfb25 100644 --- a/accel-pppd/extra/ippool.c +++ b/accel-pppd/extra/ippool.c @@ -205,13 +205,13 @@ static void generate_pool(struct ippool_t *p) } } -static struct ipv4db_item_t *get_ip(struct ppp_t *ppp) +static struct ipv4db_item_t *get_ip(struct ap_session *ses) { struct ippool_item_t *it; struct ippool_t *p; - if (ppp->ipv4_pool_name) - p = find_pool(ppp->ipv4_pool_name, 0); + if (ses->ipv4_pool_name) + p = find_pool(ses->ipv4_pool_name, 0); else p = def_pool; @@ -229,7 +229,7 @@ static struct ipv4db_item_t *get_ip(struct ppp_t *ppp) return it ? &it->it : NULL; } -static void put_ip(struct ppp_t *ppp, struct ipv4db_item_t *it) +static void put_ip(struct ap_session *ses, struct ipv4db_item_t *it) { struct ippool_item_t *pit = container_of(it, typeof(*pit), it); @@ -244,12 +244,12 @@ static struct ipdb_t ipdb = { }; #ifdef RADIUS -static int parse_attr(struct ppp_t *ppp, struct rad_attr_t *attr) +static int parse_attr(struct ap_session *ses, struct rad_attr_t *attr) { if (attr->len > sizeof("ip:addr-pool=") && memcmp(attr->val.string, "ip:addr-pool=", sizeof("ip:addr-pool=") - 1) == 0) - ppp->ipv4_pool_name = _strdup(attr->val.string + sizeof("ip:addr-pool=") - 1); + ses->ipv4_pool_name = _strdup(attr->val.string + sizeof("ip:addr-pool=") - 1); else if (!attr->vendor) - ppp->ipv4_pool_name = _strdup(attr->val.string); + ses->ipv4_pool_name = _strdup(attr->val.string); else return -1; @@ -269,7 +269,7 @@ static void ev_radius_access_accept(struct ev_radius_t *ev) continue; if (attr->attr->id != conf_attr) continue; - if (parse_attr(ev->ppp, attr)) + if (parse_attr(ev->ses, attr)) continue; break; } diff --git a/accel-pppd/extra/ipv6pool.c b/accel-pppd/extra/ipv6pool.c index 59bda253..5a9dde96 100644 --- a/accel-pppd/extra/ipv6pool.c +++ b/accel-pppd/extra/ipv6pool.c @@ -129,7 +129,7 @@ err: _free(val); } -static struct ipv6db_item_t *get_ip(struct ppp_t *ppp) +static struct ipv6db_item_t *get_ip(struct ap_session *ses) { struct ippool_item_t *it; @@ -146,7 +146,7 @@ static struct ipv6db_item_t *get_ip(struct ppp_t *ppp) return it ? &it->it : NULL; } -static void put_ip(struct ppp_t *ppp, struct ipv6db_item_t *it) +static void put_ip(struct ap_session *ses, struct ipv6db_item_t *it) { struct ippool_item_t *pit = container_of(it, typeof(*pit), it); @@ -155,7 +155,7 @@ static void put_ip(struct ppp_t *ppp, struct ipv6db_item_t *it) spin_unlock(&pool_lock); } -static struct ipv6db_prefix_t *get_dp(struct ppp_t *ppp) +static struct ipv6db_prefix_t *get_dp(struct ap_session *ses) { struct dppool_item_t *it; @@ -170,7 +170,7 @@ static struct ipv6db_prefix_t *get_dp(struct ppp_t *ppp) return it ? &it->it : NULL; } -static void put_dp(struct ppp_t *ppp, struct ipv6db_prefix_t *it) +static void put_dp(struct ap_session *ses, struct ipv6db_prefix_t *it) { struct dppool_item_t *pit = container_of(it, typeof(*pit), it); diff --git a/accel-pppd/extra/logwtmp.c b/accel-pppd/extra/logwtmp.c index 5848102e..9f31d694 100644 --- a/accel-pppd/extra/logwtmp.c +++ b/accel-pppd/extra/logwtmp.c @@ -14,20 +14,20 @@ #include "memdebug.h" -static void ev_ppp_started(struct ppp_t *ppp) +static void ev_ses_started(struct ap_session *ses) { - logwtmp(ppp->ifname, ppp->username, ppp->ctrl->calling_station_id); + logwtmp(ses->ifname, ses->username, ses->ctrl->calling_station_id); } -static void ev_ppp_finished(struct ppp_t *ppp) +static void ev_ses_finished(struct ap_session *ses) { - logwtmp(ppp->ifname, "", ""); + logwtmp(ses->ifname, "", ""); } static void init(void) { - triton_event_register_handler(EV_PPP_STARTED, (triton_event_func)ev_ppp_started); - triton_event_register_handler(EV_PPP_FINISHED, (triton_event_func)ev_ppp_finished); + triton_event_register_handler(EV_SES_STARTED, (triton_event_func)ev_ses_started); + triton_event_register_handler(EV_SES_FINISHED, (triton_event_func)ev_ses_finished); } DEFINE_INIT(200, init); diff --git a/accel-pppd/extra/net-snmp/sessionTable.h b/accel-pppd/extra/net-snmp/sessionTable.h index f5619d98..645ddd35 100644 --- a/accel-pppd/extra/net-snmp/sessionTable.h +++ b/accel-pppd/extra/net-snmp/sessionTable.h @@ -75,7 +75,7 @@ typedef netsnmp_data_list sessionTable_registration; */ struct sessionTable_data_s { - char ifname[PPP_IFNAME_LEN]; + char ifname[AP_IFNAME_LEN]; char *username; in_addr_t peer_addr; int type; @@ -96,7 +96,7 @@ typedef struct sessionTable_mib_index_s { /* * sesSID(1)/OCTETSTR/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/h */ - char sesSID[PPP_SESSIONID_LEN]; + char sesSID[AP_SESSIONID_LEN]; size_t sesSID_len; @@ -111,7 +111,7 @@ typedef struct sessionTable_mib_index_s { * POSSIBLE LENGHT FOR EVERY VARIABLE LENGTH INDEX! * Guessing 128 - col/entry(2) - oid len(10) */ -#define MAX_sessionTable_IDX_LEN PPP_SESSIONID_LEN + 1 +#define MAX_sessionTable_IDX_LEN AP_SESSIONID_LEN + 1 /* ********************************************************************* diff --git a/accel-pppd/extra/net-snmp/sessionTable_data_access.c b/accel-pppd/extra/net-snmp/sessionTable_data_access.c index 0d38e5df..4821d38d 100644 --- a/accel-pppd/extra/net-snmp/sessionTable_data_access.c +++ b/accel-pppd/extra/net-snmp/sessionTable_data_access.c @@ -197,23 +197,23 @@ sessionTable_container_load(netsnmp_container *container) { sessionTable_rowreq_ctx *rowreq_ctx; size_t count = 0; - struct ppp_t *ppp; + struct ap_session *ses; time_t t; time(&t); DEBUGMSGTL(("verbose:sessionTable:sessionTable_container_load","called\n")); - 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) { rowreq_ctx = sessionTable_allocate_rowreq_ctx(NULL, NULL); if (NULL == rowreq_ctx) { - pthread_rwlock_unlock(&ppp_lock); + pthread_rwlock_unlock(&ses_lock); snmp_log(LOG_ERR, "memory allocation failed\n"); return MFD_RESOURCE_UNAVAILABLE; } if(MFD_SUCCESS != sessionTable_indexes_set(rowreq_ctx - , ppp->sessionid, PPP_SESSIONID_LEN + , ses->sessionid, AP_SESSIONID_LEN )) { snmp_log(LOG_ERR,"error setting index while loading " "sessionTable data->\n"); @@ -221,24 +221,24 @@ sessionTable_container_load(netsnmp_container *container) continue; } - strcpy(rowreq_ctx->data->ifname, ppp->ifname); + strcpy(rowreq_ctx->data->ifname, ses->ifname); - if (ppp->username) - rowreq_ctx->data->username = strdup(ppp->username); + if (ses->username) + rowreq_ctx->data->username = strdup(ses->username); else - ppp->username = strdup(""); + ses->username = strdup(""); - rowreq_ctx->data->peer_addr = ppp->ipv4 ? ppp->ipv4->peer_addr : 0; - rowreq_ctx->data->type = ppp->ctrl->type; - rowreq_ctx->data->state = ppp->state; - rowreq_ctx->data->uptime = (ppp->stop_time ? ppp->stop_time : t) - ppp->start_time; - rowreq_ctx->data->calling_sid = strdup(ppp->ctrl->calling_station_id); - rowreq_ctx->data->called_sid = strdup(ppp->ctrl->called_station_id); + rowreq_ctx->data->peer_addr = ses->ipv4 ? ses->ipv4->peer_addr : 0; + rowreq_ctx->data->type = ses->ctrl->type; + rowreq_ctx->data->state = ses->state; + rowreq_ctx->data->uptime = (ses->stop_time ? ses->stop_time : t) - ses->start_time; + rowreq_ctx->data->calling_sid = strdup(ses->ctrl->calling_station_id); + rowreq_ctx->data->called_sid = strdup(ses->ctrl->called_station_id); CONTAINER_INSERT(container, rowreq_ctx); ++count; } - pthread_rwlock_unlock(&ppp_lock); + pthread_rwlock_unlock(&ses_lock); DEBUGMSGT(("verbose:sessionTable:sessionTable_container_load", "inserted %d records\n", count)); diff --git a/accel-pppd/extra/net-snmp/statPPP.c b/accel-pppd/extra/net-snmp/statPPP.c index 7199b570..db8918b7 100644 --- a/accel-pppd/extra/net-snmp/statPPP.c +++ b/accel-pppd/extra/net-snmp/statPPP.c @@ -53,7 +53,7 @@ init_statPPP(void) statPPPStarting_oid, OID_LENGTH(statPPPStarting_oid), HANDLER_CAN_RONLY); winfo = netsnmp_create_watcher_info( - &ppp_stat.starting, sizeof(ppp_stat.starting), + &ap_session_stat.starting, sizeof(ap_session_stat.starting), ASN_INTEGER, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched statPPPStarting" ); @@ -67,7 +67,7 @@ init_statPPP(void) statPPPActive_oid, OID_LENGTH(statPPPActive_oid), HANDLER_CAN_RONLY); winfo = netsnmp_create_watcher_info( - &ppp_stat.active, sizeof(ppp_stat.active), + &ap_session_stat.active, sizeof(ap_session_stat.active), ASN_INTEGER, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched statPPPActive" ); @@ -81,7 +81,7 @@ init_statPPP(void) statPPPFinishing_oid, OID_LENGTH(statPPPFinishing_oid), HANDLER_CAN_RONLY); winfo = netsnmp_create_watcher_info( - &ppp_stat.finishing, sizeof(ppp_stat.finishing), + &ap_session_stat.finishing, sizeof(ap_session_stat.finishing), ASN_INTEGER, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched statPPPFinishing" ); diff --git a/accel-pppd/extra/net-snmp/terminate.c b/accel-pppd/extra/net-snmp/terminate.c index abe92df0..23d355a2 100644 --- a/accel-pppd/extra/net-snmp/terminate.c +++ b/accel-pppd/extra/net-snmp/terminate.c @@ -16,81 +16,81 @@ #include "terminate.h" -static void __terminate(struct ppp_t *ppp) +static void __terminate(struct ap_session *ses) { - ppp_terminate(ppp, TERM_ADMIN_RESET, 0); + ap_session_terminate(ses, TERM_ADMIN_RESET, 0); } static void terminate_by_sid(const char *val) { - struct ppp_t *ppp; + struct ap_session *ses; - pthread_rwlock_rdlock(&ppp_lock); - list_for_each_entry(ppp, &ppp_list, entry) { - if (strncmp(ppp->sessionid, val, PPP_SESSIONID_LEN)) + pthread_rwlock_rdlock(&ses_lock); + list_for_each_entry(ses, &ses_list, entry) { + if (strncmp(ses->sessionid, val, AP_SESSIONID_LEN)) continue; - triton_context_call(ppp->ctrl->ctx, (triton_event_func)__terminate, ppp); + triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate, ses); break; } - pthread_rwlock_unlock(&ppp_lock); + pthread_rwlock_unlock(&ses_lock); } static void terminate_by_ifname(const char *val, size_t len) { - struct ppp_t *ppp; + struct ap_session *ses; size_t n; - pthread_rwlock_rdlock(&ppp_lock); - list_for_each_entry(ppp, &ppp_list, entry) { - n = strlen(ppp->ifname); + pthread_rwlock_rdlock(&ses_lock); + list_for_each_entry(ses, &ses_list, entry) { + n = strlen(ses->ifname); if (n != len) continue; - if (strncmp(ppp->ifname, val, len)) + if (strncmp(ses->ifname, val, len)) continue; - triton_context_call(ppp->ctrl->ctx, (triton_event_func)__terminate, ppp); + triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate, ses); break; } - pthread_rwlock_unlock(&ppp_lock); + pthread_rwlock_unlock(&ses_lock); } static void terminate_by_ip(const char *val, size_t len) { char str[len + 1]; in_addr_t addr; - struct ppp_t *ppp; + struct ap_session *ses; strncpy(str, val, len); str[len] = 0; addr = inet_addr(str); - pthread_rwlock_rdlock(&ppp_lock); - list_for_each_entry(ppp, &ppp_list, entry) { - if (!ppp->ipv4 || ppp->ipv4->peer_addr != addr) + pthread_rwlock_rdlock(&ses_lock); + list_for_each_entry(ses, &ses_list, entry) { + if (!ses->ipv4 || ses->ipv4->peer_addr != addr) continue; - triton_context_call(ppp->ctrl->ctx, (triton_event_func)__terminate, ppp); + triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate, ses); break; } - pthread_rwlock_unlock(&ppp_lock); + pthread_rwlock_unlock(&ses_lock); } static void terminate_by_username(const char *val, size_t len) { - struct ppp_t *ppp; + struct ap_session *ses; size_t n; - pthread_rwlock_rdlock(&ppp_lock); - list_for_each_entry(ppp, &ppp_list, entry) { - if (!ppp->username) + pthread_rwlock_rdlock(&ses_lock); + list_for_each_entry(ses, &ses_list, entry) { + if (!ses->username) continue; - n = strlen(ppp->username); + n = strlen(ses->username); if (n != len) continue; - if (strncmp(ppp->username, val, len)) + if (strncmp(ses->username, val, len)) continue; - triton_context_call(ppp->ctrl->ctx, (triton_event_func)__terminate, ppp); + triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate, ses); } - pthread_rwlock_unlock(&ppp_lock); + pthread_rwlock_unlock(&ses_lock); } @@ -154,7 +154,7 @@ handle_termBySID(netsnmp_mib_handler *handler, */ case MODE_SET_RESERVE1: /* or you could use netsnmp_check_vb_type_and_size instead */ - ret = netsnmp_check_vb_type_and_size(requests->requestvb, ASN_OCTET_STR, PPP_SESSIONID_LEN); + ret = netsnmp_check_vb_type_and_size(requests->requestvb, ASN_OCTET_STR, AP_SESSIONID_LEN); if ( ret != SNMP_ERR_NOERROR ) { netsnmp_set_request_error(reqinfo, requests, ret ); } diff --git a/accel-pppd/extra/pppd_compat.c b/accel-pppd/extra/pppd_compat.c index d89a6a6a..4ed7824e 100644 --- a/accel-pppd/extra/pppd_compat.c +++ b/accel-pppd/extra/pppd_compat.c @@ -36,8 +36,8 @@ static void *pd_key; struct pppd_compat_pd_t { - struct ppp_pd_t pd; - struct ppp_t *ppp; + struct ap_private pd; + struct ap_session *ses; struct sigchld_handler_t ip_pre_up_hnd; struct sigchld_handler_t ip_up_hnd; struct sigchld_handler_t ip_change_hnd; @@ -53,31 +53,31 @@ struct pppd_compat_pd_t in_addr_t ipv4_peer_addr; }; -static struct pppd_compat_pd_t *find_pd(struct ppp_t *ppp); +static struct pppd_compat_pd_t *find_pd(struct ap_session *ses); static void fill_argv(char **argv, struct pppd_compat_pd_t *pd, char *path); static void fill_env(char **env, struct pppd_compat_pd_t *pd); #ifdef RADIUS -static void remove_radattr(struct ppp_t *ppp); -static void write_radattr(struct ppp_t *ppp, struct rad_packet_t *pack, int save_old); +static void remove_radattr(struct ap_session *ses); +static void write_radattr(struct ap_session *ses, struct rad_packet_t *pack, int save_old); #endif static void ip_pre_up_handler(struct sigchld_handler_t *h, int status) { struct pppd_compat_pd_t *pd = container_of(h, typeof(*pd), ip_pre_up_hnd); if (conf_verbose) { - log_switch(NULL, pd->ppp); + log_switch(NULL, pd->ses); log_ppp_info2("pppd_compat: ip-pre-up finished (%i)\n", status); } sched_yield(); pd->res = status; - triton_context_wakeup(pd->ppp->ctrl->ctx); + triton_context_wakeup(pd->ses->ctrl->ctx); } static void ip_up_handler(struct sigchld_handler_t *h, int status) { struct pppd_compat_pd_t *pd = container_of(h, typeof(*pd), ip_up_hnd); if (conf_verbose) { - log_switch(NULL, pd->ppp); + log_switch(NULL, pd->ses); log_ppp_info2("pppd_compat: ip-up finished (%i)\n", status); } } @@ -86,26 +86,26 @@ static void ip_down_handler(struct sigchld_handler_t *h, int status) { struct pppd_compat_pd_t *pd = container_of(h, typeof(*pd), ip_down_hnd); if (conf_verbose) { - log_switch(NULL, pd->ppp); + log_switch(NULL, pd->ses); log_ppp_info2("pppd_compat: ip-down finished (%i)\n", status); } sched_yield(); - triton_context_wakeup(pd->ppp->ctrl->ctx); + triton_context_wakeup(pd->ses->ctrl->ctx); } static void ip_change_handler(struct sigchld_handler_t *h, int status) { struct pppd_compat_pd_t *pd = container_of(h, typeof(*pd), ip_change_hnd); if (conf_verbose) { - log_switch(NULL, pd->ppp); + log_switch(NULL, pd->ses); log_ppp_info2("pppd_compat: ip-change finished (%i)\n", status); } sched_yield(); pd->res = status; - triton_context_wakeup(pd->ppp->ctrl->ctx); + triton_context_wakeup(pd->ses->ctrl->ctx); } -static void ev_ppp_starting(struct ppp_t *ppp) +static void ev_ses_starting(struct ap_session *ses) { struct pppd_compat_pd_t *pd = _malloc(sizeof(*pd)); @@ -116,15 +116,15 @@ static void ev_ppp_starting(struct ppp_t *ppp) memset(pd, 0, sizeof(*pd)); pd->pd.key = &pd_key; - pd->ppp = ppp; + pd->ses = ses; pd->ip_pre_up_hnd.handler = ip_pre_up_handler; pd->ip_up_hnd.handler = ip_up_handler; pd->ip_down_hnd.handler = ip_down_handler; pd->ip_change_hnd.handler = ip_change_handler; - list_add_tail(&pd->pd.entry, &ppp->pd_list); + list_add_tail(&pd->pd.entry, &ses->pd_list); } -static void ev_ppp_pre_up(struct ppp_t *ppp) +static void ev_ses_pre_up(struct ap_session *ses) { pid_t pid; char *argv[8]; @@ -132,14 +132,14 @@ static void ev_ppp_pre_up(struct ppp_t *ppp) char ipaddr[17]; char peer_ipaddr[17]; char peername[64]; - struct pppd_compat_pd_t *pd = find_pd(ppp); + struct pppd_compat_pd_t *pd = find_pd(ses); if (!pd) return; - if (ppp->ipv4) { - pd->ipv4_addr = ppp->ipv4->addr; - pd->ipv4_peer_addr = ppp->ipv4->peer_addr; + if (ses->ipv4) { + pd->ipv4_addr = ses->ipv4->addr; + pd->ipv4_peer_addr = ses->ipv4->peer_addr; } argv[4] = ipaddr; @@ -163,7 +163,7 @@ static void ev_ppp_pre_up(struct ppp_t *ppp) pthread_mutex_lock(&pd->ip_pre_up_hnd.lock); pthread_mutex_unlock(&pd->ip_pre_up_hnd.lock); if (pd->res != 0) { - ppp_terminate(ppp, pd->res > 127 ? TERM_NAS_ERROR : TERM_ADMIN_RESET, 0); + ap_session_terminate(ses, pd->res > 127 ? TERM_NAS_ERROR : TERM_ADMIN_RESET, 0); return; } } else if (pid == 0) { @@ -179,7 +179,7 @@ static void ev_ppp_pre_up(struct ppp_t *ppp) } } -static void ev_ppp_started(struct ppp_t *ppp) +static void ev_ses_started(struct ap_session *ses) { pid_t pid; char *argv[8]; @@ -187,7 +187,7 @@ static void ev_ppp_started(struct ppp_t *ppp) char ipaddr[17]; char peer_ipaddr[17]; char peername[64]; - struct pppd_compat_pd_t *pd = find_pd(ppp); + struct pppd_compat_pd_t *pd = find_pd(ses); if (!pd) return; @@ -224,17 +224,17 @@ static void ev_ppp_started(struct ppp_t *ppp) pd->started = 1; } -static void ev_ppp_finishing(struct ppp_t *ppp) +static void ev_ses_finishing(struct ap_session *ses) { struct ifpppstatsreq ifreq; - struct pppd_compat_pd_t *pd = find_pd(ppp); + struct pppd_compat_pd_t *pd = find_pd(ses); if (!pd) return; memset(&ifreq, 0, sizeof(ifreq)); ifreq.stats_ptr = (void *)&ifreq.stats; - strcpy(ifreq.ifr__name, ppp->ifname); + strcpy(ifreq.ifr__name, ses->ifname); if (ioctl(sock_fd, SIOCGPPPSTATS, &ifreq)) { log_ppp_error("pppd_compat: failed to get ppp statistics: %s\n", strerror(errno)); @@ -245,7 +245,7 @@ static void ev_ppp_finishing(struct ppp_t *ppp) pd->bytes_rcvd = ifreq.stats.p.ppp_ibytes; } -static void ev_ppp_finished(struct ppp_t *ppp) +static void ev_ses_finished(struct ap_session *ses) { pid_t pid; char *argv[8]; @@ -256,7 +256,7 @@ static void ev_ppp_finished(struct ppp_t *ppp) char connect_time[24]; char bytes_sent[24]; char bytes_rcvd[24]; - struct pppd_compat_pd_t *pd = find_pd(ppp); + struct pppd_compat_pd_t *pd = find_pd(ses); if (!pd) return; @@ -319,7 +319,7 @@ static void ev_ppp_finished(struct ppp_t *ppp) skip: #ifdef RADIUS if (pd->radattr_saved) - remove_radattr(ppp); + remove_radattr(ses); #endif list_del(&pd->pd.entry); @@ -329,9 +329,9 @@ skip: #ifdef RADIUS static void ev_radius_access_accept(struct ev_radius_t *ev) { - struct pppd_compat_pd_t *pd = find_pd(ev->ppp); + struct pppd_compat_pd_t *pd = find_pd(ev->ses); - write_radattr(ev->ppp, ev->reply, 0); + write_radattr(ev->ses, ev->reply, 0); pd->radattr_saved = 1; } @@ -344,12 +344,12 @@ static void ev_radius_coa(struct ev_radius_t *ev) char ipaddr[17]; char peer_ipaddr[17]; char peername[64]; - struct pppd_compat_pd_t *pd = find_pd(ev->ppp); + struct pppd_compat_pd_t *pd = find_pd(ev->ses); if (!pd) return; - write_radattr(ev->ppp, ev->request, 1); + write_radattr(ev->ses, ev->request, 1); argv[4] = ipaddr; argv[5] = peer_ipaddr; @@ -378,7 +378,7 @@ static void ev_radius_coa(struct ev_radius_t *ev) log_error("pppd_compat: fork: %s\n", strerror(errno)); } -static void remove_radattr(struct ppp_t *ppp) +static void remove_radattr(struct ap_session *ses) { char *fname; @@ -388,17 +388,17 @@ static void remove_radattr(struct ppp_t *ppp) return; } - sprintf(fname, "%s.%s", conf_radattr_prefix, ppp->ifname); + sprintf(fname, "%s.%s", conf_radattr_prefix, ses->ifname); if (unlink(fname)) { log_ppp_warn("pppd_compat: failed to remove '%s': %s\n", fname, strerror(errno)); } - sprintf(fname, "%s_old.%s", conf_radattr_prefix, ppp->ifname); + sprintf(fname, "%s_old.%s", conf_radattr_prefix, ses->ifname); unlink(fname); _free(fname); } -static void write_radattr(struct ppp_t *ppp, struct rad_packet_t *pack, int save_old) +static void write_radattr(struct ap_session *ses, struct rad_packet_t *pack, int save_old) { struct rad_attr_t *attr; struct rad_dict_value_t *val; @@ -421,9 +421,9 @@ static void write_radattr(struct ppp_t *ppp, struct rad_packet_t *pack, int save } } - sprintf(fname1, "%s.%s", conf_radattr_prefix, ppp->ifname); + sprintf(fname1, "%s.%s", conf_radattr_prefix, ses->ifname); if (save_old) { - sprintf(fname2, "%s_old.%s", conf_radattr_prefix, ppp->ifname); + sprintf(fname2, "%s_old.%s", conf_radattr_prefix, ses->ifname); if (rename(fname1, fname2)) { log_ppp_warn("pppd_compat: rename: %s\n", strerror(errno)); } @@ -467,12 +467,12 @@ static void write_radattr(struct ppp_t *ppp, struct rad_packet_t *pack, int save } #endif -static struct pppd_compat_pd_t *find_pd(struct ppp_t *ppp) +static struct pppd_compat_pd_t *find_pd(struct ap_session *ses) { - struct ppp_pd_t *pd; + struct ap_private *pd; struct pppd_compat_pd_t *cpd; - list_for_each_entry(pd, &ppp->pd_list, entry) { + list_for_each_entry(pd, &ses->pd_list, entry) { if (pd->key == &pd_key) { cpd = container_of(pd, typeof(*cpd), pd); return cpd; @@ -486,21 +486,21 @@ static struct pppd_compat_pd_t *find_pd(struct ppp_t *ppp) static void fill_argv(char **argv, struct pppd_compat_pd_t *pd, char *path) { argv[0] = path; - argv[1] = pd->ppp->ifname; + argv[1] = pd->ses->ifname; argv[2] = "none"; argv[3] = "0"; u_inet_ntoa(pd->ipv4_addr, argv[4]); u_inet_ntoa(pd->ipv4_peer_addr, argv[5]); - argv[6] = pd->ppp->ctrl->calling_station_id; + argv[6] = pd->ses->ctrl->calling_station_id; argv[7] = NULL; } static void fill_env(char **env, struct pppd_compat_pd_t *pd) { - snprintf(env[0], 64, "PEERNAME=%s", pd->ppp->username); + snprintf(env[0], 64, "PEERNAME=%s", pd->ses->username); - if (pd->ppp->stop_time && env[1]) { - snprintf(env[1], 24, "CONNECT_TIME=%lu", pd->ppp->stop_time - pd->ppp->start_time); + if (pd->ses->stop_time && env[1]) { + snprintf(env[1], 24, "CONNECT_TIME=%lu", pd->ses->stop_time - pd->ses->start_time); snprintf(env[2], 24, "BYTES_SENT=%u", pd->bytes_sent); snprintf(env[3], 24, "BYTES_RCVD=%u", pd->bytes_rcvd); } @@ -534,11 +534,11 @@ static void init(void) if (opt && atoi(opt) > 0) conf_verbose = 1; - triton_event_register_handler(EV_PPP_STARTING, (triton_event_func)ev_ppp_starting); - triton_event_register_handler(EV_PPP_PRE_UP, (triton_event_func)ev_ppp_pre_up); - triton_event_register_handler(EV_PPP_STARTED, (triton_event_func)ev_ppp_started); - triton_event_register_handler(EV_PPP_FINISHING, (triton_event_func)ev_ppp_finishing); - triton_event_register_handler(EV_PPP_PRE_FINISHED, (triton_event_func)ev_ppp_finished); + triton_event_register_handler(EV_SES_STARTING, (triton_event_func)ev_ses_starting); + triton_event_register_handler(EV_SES_PRE_UP, (triton_event_func)ev_ses_pre_up); + triton_event_register_handler(EV_SES_STARTED, (triton_event_func)ev_ses_started); + triton_event_register_handler(EV_SES_FINISHING, (triton_event_func)ev_ses_finishing); + triton_event_register_handler(EV_SES_PRE_FINISHED, (triton_event_func)ev_ses_finished); #ifdef RADIUS if (triton_module_loaded("radius")) { triton_event_register_handler(EV_RADIUS_ACCESS_ACCEPT, (triton_event_func)ev_radius_access_accept); diff --git a/accel-pppd/extra/shaper_tbf.c b/accel-pppd/extra/shaper_tbf.c index 718a5c58..7c16475d 100644 --- a/accel-pppd/extra/shaper_tbf.c +++ b/accel-pppd/extra/shaper_tbf.c @@ -58,7 +58,7 @@ struct shaper_pd_t { struct list_head entry; struct ppp_t *ppp; - struct ppp_pd_t pd; + struct ap_private pd; int temp_down_speed; int temp_up_speed; int down_speed; @@ -427,7 +427,7 @@ out: static struct shaper_pd_t *find_pd(struct ppp_t *ppp, int create) { - struct ppp_pd_t *pd; + struct ap_private *pd; struct shaper_pd_t *spd; list_for_each_entry(pd, &ppp->pd_list, entry) { @@ -732,7 +732,7 @@ static void ev_radius_access_accept(struct ev_radius_t *ev) } if (down_speed > 0 && up_speed > 0) { - if (!install_shaper(ev->ppp->ifname, down_speed, down_burst, up_speed, up_burst)) { + if (!install_shaper(ev->ppp->ses.ifname, down_speed, down_burst, up_speed, up_burst)) { if (conf_verbose) log_ppp_info2("tbf: installed shaper %i/%i (Kbit)\n", down_speed, up_speed); } @@ -760,7 +760,7 @@ static void ev_radius_coa(struct ev_radius_t *ev) pd->up_speed = 0; if (conf_verbose) log_ppp_info2("tbf: removed shaper\n"); - remove_shaper(ev->ppp->ifname); + remove_shaper(ev->ppp->ses.ifname); } return; } @@ -769,13 +769,13 @@ static void ev_radius_coa(struct ev_radius_t *ev) pd->down_speed = pd->cur_tr->down_speed; pd->up_speed = pd->cur_tr->up_speed; - if (remove_shaper(ev->ppp->ifname)) { + if (remove_shaper(ev->ppp->ses.ifname)) { ev->res = -1; return; } if (pd->down_speed > 0 || pd->up_speed > 0) { - if (install_shaper(ev->ppp->ifname, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst)) { + if (install_shaper(ev->ppp->ses.ifname, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst)) { ev->res= -1; return; } else { @@ -827,7 +827,7 @@ static void ev_shaper(struct ev_shaper_t *ev) } if (pd->down_speed > 0 && pd->up_speed > 0) { - if (!install_shaper(ev->ppp->ifname, down_speed, down_burst, up_speed, up_burst)) { + if (!install_shaper(ev->ppp->ses.ifname, down_speed, down_burst, up_speed, up_burst)) { if (conf_verbose) log_ppp_info2("tbf: installed shaper %i/%i (Kbit)\n", down_speed, up_speed); } @@ -845,7 +845,7 @@ static void ev_ppp_pre_up(struct ppp_t *ppp) pd->temp_up_speed = temp_up_speed; pd->down_speed = temp_down_speed; pd->up_speed = temp_up_speed; - if (!install_shaper(ppp->ifname, temp_down_speed, 0, temp_up_speed, 0)) { + if (!install_shaper(ppp->ses.ifname, temp_down_speed, 0, temp_up_speed, 0)) { if (conf_verbose) log_ppp_info2("tbf: installed shaper %i/%i (Kbit)\n", temp_down_speed, temp_up_speed); } @@ -875,16 +875,16 @@ static void shaper_change_help(char * const *f, int f_cnt, void *cli) static void shaper_change(struct shaper_pd_t *pd) { if (pd->down_speed || pd->up_speed) - remove_shaper(pd->ppp->ifname); + remove_shaper(pd->ppp->ses.ifname); if (pd->temp_down_speed || pd->temp_up_speed) { pd->down_speed = pd->temp_down_speed; pd->up_speed = pd->temp_up_speed; - install_shaper(pd->ppp->ifname, pd->temp_down_speed, 0, pd->temp_up_speed, 0); + install_shaper(pd->ppp->ses.ifname, pd->temp_down_speed, 0, pd->temp_up_speed, 0); } else if (pd->cur_tr->down_speed || pd->cur_tr->up_speed) { pd->down_speed = pd->cur_tr->down_speed; pd->up_speed = pd->cur_tr->up_speed; - install_shaper(pd->ppp->ifname, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst); + install_shaper(pd->ppp->ses.ifname, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst); } } @@ -921,7 +921,7 @@ static int shaper_change_exec(const char *cmd, char * const *f, int f_cnt, void pthread_rwlock_rdlock(&shaper_lock); list_for_each_entry(pd, &shaper_list, entry) { - if (all || !strcmp(f[2], pd->ppp->ifname)) { + if (all || !strcmp(f[2], pd->ppp->ses.ifname)) { if (temp) { pd->temp_down_speed = down_speed; pd->temp_up_speed = up_speed; @@ -935,7 +935,7 @@ static int shaper_change_exec(const char *cmd, char * const *f, int f_cnt, void pd->cur_tr->up_speed = up_speed; pd->cur_tr->up_burst = up_burst; } - triton_context_call(pd->ppp->ctrl->ctx, (triton_event_func)shaper_change, pd); + triton_context_call(pd->ppp->ses.ctrl->ctx, (triton_event_func)shaper_change, pd); if (!all) { found = 1; break; @@ -958,12 +958,12 @@ static void shaper_restore_help(char * const *f, int f_cnt, void *cli) static void shaper_restore(struct shaper_pd_t *pd) { - remove_shaper(pd->ppp->ifname); + remove_shaper(pd->ppp->ses.ifname); if (pd->cur_tr) { pd->down_speed = pd->cur_tr->down_speed; pd->up_speed = pd->cur_tr->up_speed; - install_shaper(pd->ppp->ifname, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst); + install_shaper(pd->ppp->ses.ifname, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst); } else { pd->down_speed = 0; pd->up_speed = 0; @@ -991,10 +991,10 @@ static int shaper_restore_exec(const char *cmd, char * const *f, int f_cnt, void list_for_each_entry(pd, &shaper_list, entry) { if (!pd->temp_down_speed) continue; - if (all || !strcmp(f[2], pd->ppp->ifname)) { + if (all || !strcmp(f[2], pd->ppp->ses.ifname)) { pd->temp_down_speed = 0; pd->temp_up_speed = 0; - triton_context_call(pd->ppp->ctrl->ctx, (triton_event_func)shaper_restore, pd); + triton_context_call(pd->ppp->ses.ctrl->ctx, (triton_event_func)shaper_restore, pd); if (!all) { found = 1; break; @@ -1056,13 +1056,13 @@ static void update_shaper_tr(struct shaper_pd_t *pd) if (pd->down_speed || pd->up_speed) { if (pd->cur_tr && pd->down_speed == pd->cur_tr->down_speed && pd->up_speed == pd->cur_tr->up_speed) return; - remove_shaper(pd->ppp->ifname); + remove_shaper(pd->ppp->ses.ifname); } if (pd->cur_tr && (pd->cur_tr->down_speed || pd->cur_tr->up_speed)) { pd->down_speed = pd->cur_tr->down_speed; pd->up_speed = pd->cur_tr->up_speed; - if (!install_shaper(pd->ppp->ifname, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst)) { + if (!install_shaper(pd->ppp->ses.ifname, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst)) { if (conf_verbose) log_ppp_info2("tbf: changed shaper %i/%i (Kbit)\n", pd->cur_tr->down_speed, pd->cur_tr->up_speed); } @@ -1082,7 +1082,7 @@ static void time_range_begin_timer(struct triton_timer_t *t) pthread_rwlock_rdlock(&shaper_lock); list_for_each_entry(pd, &shaper_list, entry) - triton_context_call(pd->ppp->ctrl->ctx, (triton_event_func)update_shaper_tr, pd); + triton_context_call(pd->ppp->ses.ctrl->ctx, (triton_event_func)update_shaper_tr, pd); pthread_rwlock_unlock(&shaper_lock); } @@ -1096,7 +1096,7 @@ static void time_range_end_timer(struct triton_timer_t *t) pthread_rwlock_rdlock(&shaper_lock); list_for_each_entry(pd, &shaper_list, entry) - triton_context_call(pd->ppp->ctrl->ctx, (triton_event_func)update_shaper_tr, pd); + triton_context_call(pd->ppp->ses.ctrl->ctx, (triton_event_func)update_shaper_tr, pd); pthread_rwlock_unlock(&shaper_lock); } @@ -1336,7 +1336,7 @@ static void init(void) triton_event_register_handler(EV_RADIUS_COA, (triton_event_func)ev_radius_coa); } #endif - triton_event_register_handler(EV_PPP_PRE_UP, (triton_event_func)ev_ppp_pre_up); + triton_event_register_handler(EV_SES_PRE_UP, (triton_event_func)ev_ppp_pre_up); triton_event_register_handler(EV_CTRL_FINISHED, (triton_event_func)ev_ctrl_finished); triton_event_register_handler(EV_SHAPER, (triton_event_func)ev_shaper); triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); diff --git a/accel-pppd/ifcfg.c b/accel-pppd/ifcfg.c new file mode 100644 index 00000000..a1bb2e34 --- /dev/null +++ b/accel-pppd/ifcfg.c @@ -0,0 +1,186 @@ +#include <unistd.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> +#include <errno.h> +#include <limits.h> +#include <arpa/inet.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include "linux_ppp.h" + +#include "triton.h" +#include "events.h" +#include "ppp.h" +#include "ipdb.h" +#include "log.h" + +// from /usr/include/linux/ipv6.h +struct in6_ifreq { + struct in6_addr ifr6_addr; + __u32 ifr6_prefixlen; + int ifr6_ifindex; +}; + +static void devconf(struct ap_session *ses, const char *attr, const char *val) +{ + int fd; + char fname[PATH_MAX]; + + sprintf(fname, "/proc/sys/net/ipv6/conf/%s/%s", ses->ifname, attr); + fd = open(fname, O_WRONLY); + if (!fd) { + log_ppp_error("failed to open '%s': %s\n", fname, strerror(errno)); + return; + } + + write(fd, val, strlen(val)); + + close(fd); +} + +static void build_addr(struct ipv6db_addr_t *a, uint64_t intf_id, struct in6_addr *addr) +{ + memcpy(addr, &a->addr, sizeof(*addr)); + + if (a->prefix_len <= 64) + *(uint64_t *)(addr->s6_addr + 8) = intf_id; + else + *(uint64_t *)(addr->s6_addr + 8) |= intf_id & ((1 << (128 - a->prefix_len)) - 1); +} + +void ap_session_ifup(struct ap_session *ses) +{ + struct ipv6db_addr_t *a; + struct ifreq ifr; + struct in6_ifreq ifr6; + struct npioctl np; + struct sockaddr_in addr; + struct ppp_t *ppp; + + triton_event_fire(EV_SES_ACCT_START, ses); + if (ses->stop_time) + return; + + triton_event_fire(EV_SES_PRE_UP, ses); + if (ses->stop_time) + return; + + memset(&ifr, 0, sizeof(ifr)); + strcpy(ifr.ifr_name, ses->ifname); + + if (ses->ipv4) { + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = ses->ipv4->addr; + memcpy(&ifr.ifr_addr,&addr,sizeof(addr)); + + if (ioctl(sock_fd, SIOCSIFADDR, &ifr)) + log_ppp_error("failed to set IPv4 address: %s\n", strerror(errno)); + + addr.sin_addr.s_addr = ses->ipv4->peer_addr; + memcpy(&ifr.ifr_dstaddr,&addr,sizeof(addr)); + + if (ioctl(sock_fd, SIOCSIFDSTADDR, &ifr)) + log_ppp_error("failed to set peer IPv4 address: %s\n", strerror(errno)); + } + + if (ses->ipv6) { + devconf(ses, "accept_ra", "0"); + devconf(ses, "autoconf", "0"); + devconf(ses, "forwarding", "1"); + + memset(&ifr6, 0, sizeof(ifr6)); + ifr6.ifr6_addr.s6_addr32[0] = htons(0xfe80); + *(uint64_t *)(ifr6.ifr6_addr.s6_addr + 8) = ses->ipv6->intf_id; + ifr6.ifr6_prefixlen = 64; + ifr6.ifr6_ifindex = ses->ifindex; + + if (ioctl(sock6_fd, SIOCSIFADDR, &ifr6)) + log_ppp_error("faild to set LL IPv6 address: %s\n", strerror(errno)); + + list_for_each_entry(a, &ses->ipv6->addr_list, entry) { + if (a->prefix_len == 128) + continue; + + build_addr(a, ses->ipv6->intf_id, &ifr6.ifr6_addr); + ifr6.ifr6_prefixlen = a->prefix_len; + + if (ioctl(sock6_fd, SIOCSIFADDR, &ifr6)) + log_ppp_error("failed to add IPv6 address: %s\n", strerror(errno)); + } + } + + if (ioctl(sock_fd, SIOCGIFFLAGS, &ifr)) + log_ppp_error("failed to get interface flags: %s\n", strerror(errno)); + + ifr.ifr_flags |= IFF_UP; + + if (ioctl(sock_fd, SIOCSIFFLAGS, &ifr)) + log_ppp_error("failed to set interface flags: %s\n", strerror(errno)); + + if (ses->ctrl->type != CTRL_TYPE_IPOE) { + ppp = container_of(ses, typeof(*ppp), ses); + if (ses->ipv4) { + np.protocol = PPP_IP; + np.mode = NPMODE_PASS; + + if (ioctl(ppp->unit_fd, PPPIOCSNPMODE, &np)) + log_ppp_error("failed to set NP (IPv4) mode: %s\n", strerror(errno)); + } + + if (ses->ipv6) { + np.protocol = PPP_IPV6; + np.mode = NPMODE_PASS; + + if (ioctl(ppp->unit_fd, PPPIOCSNPMODE, &np)) + log_ppp_error("failed to set NP (IPv6) mode: %s\n", strerror(errno)); + } + } + + ses->ctrl->started(ses); + + triton_event_fire(EV_SES_STARTED, ses); +} + +void __export ap_session_ifdown(struct ap_session *ses) +{ + struct ifreq ifr; + struct sockaddr_in addr; + struct in6_ifreq ifr6; + struct ipv6db_addr_t *a; + + memset(&ifr, 0, sizeof(ifr)); + strcpy(ifr.ifr_name, ses->ifname); + ioctl(sock_fd, SIOCSIFFLAGS, &ifr); + + if (ses->ipv4) { + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + memcpy(&ifr.ifr_addr,&addr,sizeof(addr)); + ioctl(sock_fd, SIOCSIFADDR, &ifr); + } + + if (ses->ipv6) { + memset(&ifr6, 0, sizeof(ifr6)); + ifr6.ifr6_addr.s6_addr32[0] = htons(0xfe80); + *(uint64_t *)(ifr6.ifr6_addr.s6_addr + 8) = ses->ipv6->intf_id; + ifr6.ifr6_prefixlen = 64; + ifr6.ifr6_ifindex = ses->ifindex; + + ioctl(sock6_fd, SIOCDIFADDR, &ifr6); + + list_for_each_entry(a, &ses->ipv6->addr_list, entry) { + if (a->prefix_len == 128) + continue; + + build_addr(a, ses->ipv6->intf_id, &ifr6.ifr6_addr); + ifr6.ifr6_prefixlen = a->prefix_len; + + ioctl(sock6_fd, SIOCDIFADDR, &ifr6); + } + } +} + diff --git a/accel-pppd/include/ap_session.h b/accel-pppd/include/ap_session.h new file mode 100644 index 00000000..681d05fb --- /dev/null +++ b/accel-pppd/include/ap_session.h @@ -0,0 +1,108 @@ +#ifndef __AP_SESSION_H__ +#define __AP_SESSION_H__ + +#define AP_SESSIONID_LEN 16 +#define AP_IFNAME_LEN 10 + +#define AP_STATE_STARTING 1 +#define AP_STATE_ACTIVE 2 +#define AP_STATE_FINISHING 3 + +#define TERM_USER_REQUEST 1 +#define TERM_SESSION_TIMEOUT 2 +#define TERM_ADMIN_RESET 3 +#define TERM_USER_ERROR 4 +#define TERM_NAS_ERROR 5 +#define TERM_NAS_REQUEST 6 +#define TERM_NAS_REBOOT 7 +#define TERM_AUTH_ERROR 8 +#define TERM_LOST_CARRIER 9 + +#define CTRL_TYPE_PPTP 1 +#define CTRL_TYPE_L2TP 2 +#define CTRL_TYPE_PPPOE 3 +#define CTRL_TYPE_IPOE 4 + +#define MPPE_UNSET -2 +#define MPPE_ALLOW -1 +#define MPPE_DENY 0 +#define MPPE_PREFER 1 +#define MPPE_REQUIRE 2 + +struct ap_session; + +struct ap_ctrl +{ + struct triton_context_t *ctx; + int type; + const char *name; + int max_mtu; + int mppe; + char *calling_station_id; + char *called_station_id; + void (*started)(struct ap_session*); + void (*finished)(struct ap_session *); + void (*terminate)(struct ap_session *, int hard); +}; + +struct ap_private +{ + struct list_head entry; + void *key; +}; + +struct ap_session +{ + struct list_head entry; + + int state; + char *chan_name; + char ifname[AP_IFNAME_LEN]; + int unit_idx; + int ifindex; + char sessionid[AP_SESSIONID_LEN+1]; + time_t start_time; + time_t stop_time; + char *username; + struct ipv4db_item_t *ipv4; + struct ipv6db_item_t *ipv6; + char *ipv4_pool_name; + char *ipv6_pool_name; + + struct ap_ctrl *ctrl; + + int terminating:1; + int terminated:1; + int terminate_cause; + + struct list_head pd_list; +}; + +struct ap_session_stat +{ + unsigned int active; + unsigned int starting; + unsigned int finishing; +}; + + +extern pthread_rwlock_t ses_lock; +extern struct list_head ses_list; +extern int ap_shutdown; +extern int sock_fd; // internet socket for ioctls +extern int sock6_fd; // internet socket for ioctls +extern int urandom_fd; +extern struct ap_session_stat ap_session_stat; + +void ap_session_init(struct ap_session *ses); +int ap_session_starting(struct ap_session *ses); +void ap_session_finished(struct ap_session *ses); +void ap_session_terminate(struct ap_session *ses, int cause, int hard); +void ap_session_activate(struct ap_session *ses); + +void ap_session_ifup(struct ap_session *ses); +void ap_session_ifdown(struct ap_session *ses); + +void ap_shutdown_soft(void); + +#endif diff --git a/accel-pppd/include/events.h b/accel-pppd/include/events.h index 5d6fea7e..ca04d757 100644 --- a/accel-pppd/include/events.h +++ b/accel-pppd/include/events.h @@ -4,19 +4,19 @@ #include <stdint.h> #include <netinet/in.h> -#define EV_PPP_STARTING 1 -#define EV_PPP_STARTED 2 -#define EV_PPP_FINISHING 3 -#define EV_PPP_FINISHED 4 -#define EV_PPP_AUTHORIZED 5 +#define EV_SES_STARTING 1 +#define EV_SES_STARTED 2 +#define EV_SES_FINISHING 3 +#define EV_SES_FINISHED 4 +#define EV_SES_AUTHORIZED 5 #define EV_CTRL_STARTING 6 #define EV_CTRL_STARTED 7 #define EV_CTRL_FINISHED 8 -#define EV_PPP_PRE_UP 9 -#define EV_PPP_ACCT_START 10 +#define EV_SES_PRE_UP 9 +#define EV_SES_ACCT_START 10 #define EV_CONFIG_RELOAD 11 -#define EV_PPP_AUTH_FAILED 12 -#define EV_PPP_PRE_FINISHED 13 +#define EV_SES_AUTH_FAILED 12 +#define EV_SES_PRE_FINISHED 13 #define EV_IP_CHANGED 100 #define EV_SHAPER 101 #define EV_MPPE_KEYS 102 @@ -24,11 +24,12 @@ #define EV_RADIUS_ACCESS_ACCEPT 200 #define EV_RADIUS_COA 201 +struct ap_session; struct ppp_t; struct rad_packet_t; struct ev_radius_t { - struct ppp_t *ppp; + struct ap_session *ses; struct rad_packet_t *request; struct rad_packet_t *reply; int res; @@ -45,13 +46,13 @@ struct ev_mppe_keys_t struct ev_shaper_t { - struct ppp_t *ppp; + struct ap_session *ses; const char *val; }; struct ev_dns_t { - struct ppp_t *ppp; + struct ap_session *ses; in_addr_t dns1; in_addr_t dns2; }; diff --git a/accel-pppd/ipdb.c b/accel-pppd/ipdb.c index f87d4788..7c3ebb82 100644 --- a/accel-pppd/ipdb.c +++ b/accel-pppd/ipdb.c @@ -5,7 +5,7 @@ static LIST_HEAD(ipdb_handlers); -struct ipv4db_item_t __export *ipdb_get_ipv4(struct ppp_t *ppp) +struct ipv4db_item_t __export *ipdb_get_ipv4(struct ap_session *ses) { struct ipdb_t *ipdb; struct ipv4db_item_t *it; @@ -13,7 +13,7 @@ struct ipv4db_item_t __export *ipdb_get_ipv4(struct ppp_t *ppp) list_for_each_entry(ipdb, &ipdb_handlers, entry) { if (!ipdb->get_ipv4) continue; - it = ipdb->get_ipv4(ppp); + it = ipdb->get_ipv4(ses); if (it) return it; } @@ -21,13 +21,13 @@ struct ipv4db_item_t __export *ipdb_get_ipv4(struct ppp_t *ppp) return NULL; } -void __export ipdb_put_ipv4(struct ppp_t *ppp, struct ipv4db_item_t *it) +void __export ipdb_put_ipv4(struct ap_session *ses, struct ipv4db_item_t *it) { if (it->owner->put_ipv4) - it->owner->put_ipv4(ppp, it); + it->owner->put_ipv4(ses, it); } -struct ipv6db_item_t __export *ipdb_get_ipv6(struct ppp_t *ppp) +struct ipv6db_item_t __export *ipdb_get_ipv6(struct ap_session *ses) { struct ipdb_t *ipdb; struct ipv6db_item_t *it; @@ -35,7 +35,7 @@ struct ipv6db_item_t __export *ipdb_get_ipv6(struct ppp_t *ppp) list_for_each_entry(ipdb, &ipdb_handlers, entry) { if (!ipdb->get_ipv6) continue; - it = ipdb->get_ipv6(ppp); + it = ipdb->get_ipv6(ses); if (it) return it; } @@ -43,13 +43,13 @@ struct ipv6db_item_t __export *ipdb_get_ipv6(struct ppp_t *ppp) return NULL; } -void __export ipdb_put_ipv6(struct ppp_t *ppp, struct ipv6db_item_t *it) +void __export ipdb_put_ipv6(struct ap_session *ses, struct ipv6db_item_t *it) { if (it->owner->put_ipv6) - it->owner->put_ipv6(ppp, it); + it->owner->put_ipv6(ses, it); } -struct ipv6db_prefix_t __export *ipdb_get_ipv6_prefix(struct ppp_t *ppp) +struct ipv6db_prefix_t __export *ipdb_get_ipv6_prefix(struct ap_session *ses) { struct ipdb_t *ipdb; struct ipv6db_prefix_t *it; @@ -57,7 +57,7 @@ struct ipv6db_prefix_t __export *ipdb_get_ipv6_prefix(struct ppp_t *ppp) list_for_each_entry(ipdb, &ipdb_handlers, entry) { if (!ipdb->get_ipv6_prefix) continue; - it = ipdb->get_ipv6_prefix(ppp); + it = ipdb->get_ipv6_prefix(ses); if (it) return it; } @@ -65,10 +65,10 @@ struct ipv6db_prefix_t __export *ipdb_get_ipv6_prefix(struct ppp_t *ppp) return NULL; } -void __export ipdb_put_ipv6_prefix(struct ppp_t *ppp, struct ipv6db_prefix_t *it) +void __export ipdb_put_ipv6_prefix(struct ap_session *ses, struct ipv6db_prefix_t *it) { if (it->owner->put_ipv6_prefix) - it->owner->put_ipv6_prefix(ppp, it); + it->owner->put_ipv6_prefix(ses, it); } diff --git a/accel-pppd/ipdb.h b/accel-pppd/ipdb.h index 2781bd08..0d13b76e 100644 --- a/accel-pppd/ipdb.h +++ b/accel-pppd/ipdb.h @@ -40,24 +40,24 @@ struct ipdb_t { struct list_head entry; - struct ipv4db_item_t *(*get_ipv4)(struct ppp_t *ppp); - void (*put_ipv4)(struct ppp_t *ppp, struct ipv4db_item_t *); + struct ipv4db_item_t *(*get_ipv4)(struct ap_session *ses); + void (*put_ipv4)(struct ap_session *ses, struct ipv4db_item_t *); - struct ipv6db_item_t *(*get_ipv6)(struct ppp_t *ppp); - void (*put_ipv6)(struct ppp_t *ppp, struct ipv6db_item_t *); + struct ipv6db_item_t *(*get_ipv6)(struct ap_session *ses); + void (*put_ipv6)(struct ap_session *ses, struct ipv6db_item_t *); - struct ipv6db_prefix_t *(*get_ipv6_prefix)(struct ppp_t *ppp); - void (*put_ipv6_prefix)(struct ppp_t *ppp, struct ipv6db_prefix_t *); + struct ipv6db_prefix_t *(*get_ipv6_prefix)(struct ap_session *ses); + void (*put_ipv6_prefix)(struct ap_session *ses, struct ipv6db_prefix_t *); }; -struct ipv4db_item_t *ipdb_get_ipv4(struct ppp_t *ppp); -void ipdb_put_ipv4(struct ppp_t *ppp, struct ipv4db_item_t *); +struct ipv4db_item_t *ipdb_get_ipv4(struct ap_session *ses); +void ipdb_put_ipv4(struct ap_session *ses, struct ipv4db_item_t *); -struct ipv6db_item_t *ipdb_get_ipv6(struct ppp_t *ppp); -void ipdb_put_ipv6(struct ppp_t *ppp, struct ipv6db_item_t *); +struct ipv6db_item_t *ipdb_get_ipv6(struct ap_session *ses); +void ipdb_put_ipv6(struct ap_session *ses, struct ipv6db_item_t *); -struct ipv6db_prefix_t __export *ipdb_get_ipv6_prefix(struct ppp_t *ppp); -void __export ipdb_put_ipv6_prefix(struct ppp_t *ppp, struct ipv6db_prefix_t *it); +struct ipv6db_prefix_t __export *ipdb_get_ipv6_prefix(struct ap_session *ses); +void __export ipdb_put_ipv6_prefix(struct ap_session *ses, struct ipv6db_prefix_t *it); void ipdb_register(struct ipdb_t *); diff --git a/accel-pppd/ipv6/dhcpv6.c b/accel-pppd/ipv6/dhcpv6.c index ddc977ba..93888245 100644 --- a/accel-pppd/ipv6/dhcpv6.c +++ b/accel-pppd/ipv6/dhcpv6.c @@ -42,7 +42,7 @@ static int conf_dnssl_size; struct dhcpv6_pd { - struct ppp_pd_t pd; + struct ap_private pd; struct dhcpv6_opt_clientid *clientid; uint32_t addr_iaid; uint32_t dp_iaid; @@ -56,22 +56,22 @@ static struct triton_context_t dhcpv6_ctx; static uint8_t *buf; static void *pd_key; -static void ev_ppp_started(struct ppp_t *ppp) +static void ev_ppp_started(struct ap_session *ses) { struct ipv6_mreq mreq; struct dhcpv6_pd *pd; - if (!ppp->ipv6) + if (!ses->ipv6) return; pd = _malloc(sizeof(*pd)); memset(pd, 0, sizeof(*pd)); pd->pd.key = &pd_key; - list_add_tail(&pd->pd.entry, &ppp->pd_list); + list_add_tail(&pd->pd.entry, &ses->pd_list); memset(&mreq, 0, sizeof(mreq)); - mreq.ipv6mr_interface = ppp->ifindex; + mreq.ipv6mr_interface = ses->ifindex; mreq.ipv6mr_multiaddr.s6_addr32[0] = htonl(0xff020000); mreq.ipv6mr_multiaddr.s6_addr32[3] = htonl(0x010002); @@ -81,11 +81,11 @@ static void ev_ppp_started(struct ppp_t *ppp) } } -static struct dhcpv6_pd *find_pd(struct ppp_t *ppp) +static struct dhcpv6_pd *find_pd(struct ap_session *ses) { - struct ppp_pd_t *pd; + struct ap_private *pd; - list_for_each_entry(pd, &ppp->pd_list, entry) { + list_for_each_entry(pd, &ses->pd_list, entry) { if (pd->key == &pd_key) return container_of(pd, struct dhcpv6_pd, pd); } @@ -93,9 +93,9 @@ static struct dhcpv6_pd *find_pd(struct ppp_t *ppp) return NULL; } -static void ev_ppp_finished(struct ppp_t *ppp) +static void ev_ppp_finished(struct ap_session *ses) { - struct dhcpv6_pd *pd = find_pd(ppp); + struct dhcpv6_pd *pd = find_pd(ses); if (!pd) return; @@ -106,7 +106,7 @@ static void ev_ppp_finished(struct ppp_t *ppp) _free(pd->clientid); if (pd->ipv6_dp) - ipdb_put_ipv6_prefix(ppp, pd->ipv6_dp); + ipdb_put_ipv6_prefix(ses, pd->ipv6_dp); _free(pd); } @@ -119,8 +119,8 @@ static void dhcpv6_send(struct dhcpv6_packet *reply) addr.sin6_family = AF_INET6; addr.sin6_port = htons(DHCPV6_CLIENT_PORT); addr.sin6_addr.s6_addr32[0] = htons(0xfe80); - *(uint64_t *)(addr.sin6_addr.s6_addr + 8) = reply->ppp->ipv6->peer_intf_id; - addr.sin6_scope_id = reply->ppp->ifindex; + *(uint64_t *)(addr.sin6_addr.s6_addr + 8) = reply->ses->ipv6->peer_intf_id; + addr.sin6_scope_id = reply->ses->ifindex; sendto(dhcpv6_hnd.fd, reply->hdr, reply->endptr - (void *)reply->hdr, 0, (struct sockaddr *)&addr, sizeof(addr)); } @@ -135,7 +135,7 @@ static void build_addr(struct ipv6db_addr_t *a, uint64_t intf_id, struct in6_add *(uint64_t *)(addr->s6_addr + 8) |= intf_id & ((1 << (128 - a->prefix_len)) - 1); } -static void insert_dp_routes(struct ppp_t *ppp, struct dhcpv6_pd *pd) +static void insert_dp_routes(struct ap_session *ses, struct dhcpv6_pd *pd) { struct ipv6db_addr_t *a; struct ipv6db_addr_t *p; @@ -145,7 +145,7 @@ static void insert_dp_routes(struct ppp_t *ppp, struct dhcpv6_pd *pd) int err; memset(&rt6, 0, sizeof(rt6)); - rt6.rtmsg_ifindex = ppp->ifindex; + rt6.rtmsg_ifindex = ses->ifindex; rt6.rtmsg_flags = RTF_UP; list_for_each_entry(p, &pd->ipv6_dp->prefix_list, entry) { @@ -155,8 +155,8 @@ static void insert_dp_routes(struct ppp_t *ppp, struct dhcpv6_pd *pd) if (conf_route_via_gw) { rt6.rtmsg_flags |= RTF_GATEWAY; - list_for_each_entry(a, &ppp->ipv6->addr_list, entry) { - build_addr(a, ppp->ipv6->peer_intf_id, &rt6.rtmsg_gateway); + list_for_each_entry(a, &ses->ipv6->addr_list, entry) { + build_addr(a, ses->ipv6->peer_intf_id, &rt6.rtmsg_gateway); if (ioctl(sock6_fd, SIOCADDRT, &rt6)) { err = errno; inet_ntop(AF_INET6, &p->addr, str1, sizeof(str1)); @@ -252,7 +252,7 @@ static void dhcpv6_send_reply(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, i if (req->hdr->type == D6_RENEW && pd->addr_iaid != ia_na->iaid) { insert_status(reply, opt1, D6_STATUS_NoBinding); - } else if (list_empty(&req->ppp->ipv6->addr_list) || f) { + } else if (list_empty(&req->ses->ipv6->addr_list) || f) { insert_status(reply, opt1, D6_STATUS_NoAddrsAvail); } else { @@ -261,11 +261,11 @@ static void dhcpv6_send_reply(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, i f = 1; - list_for_each_entry(a, &req->ppp->ipv6->addr_list, entry) { + list_for_each_entry(a, &req->ses->ipv6->addr_list, entry) { opt2 = dhcpv6_nested_option_alloc(reply, opt1, D6_OPTION_IAADDR, sizeof(*ia_addr) - sizeof(struct dhcpv6_opt_hdr)); ia_addr = (struct dhcpv6_opt_ia_addr *)opt2->hdr; - build_addr(a, req->ppp->ipv6->peer_intf_id, &ia_addr->addr); + build_addr(a, req->ses->ipv6->peer_intf_id, &ia_addr->addr); ia_addr->pref_lifetime = htonl(conf_pref_lifetime); ia_addr->valid_lifetime = htonl(conf_valid_lifetime); @@ -279,8 +279,8 @@ static void dhcpv6_send_reply(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, i continue; f1 = 0; - list_for_each_entry(a, &req->ppp->ipv6->addr_list, entry) { - build_addr(a, req->ppp->ipv6->peer_intf_id, &addr); + list_for_each_entry(a, &req->ses->ipv6->addr_list, entry) { + build_addr(a, req->ses->ipv6->peer_intf_id, &addr); if (memcmp(&addr, &ia_addr->addr, sizeof(addr))) continue; f1 = 1; @@ -316,7 +316,7 @@ static void dhcpv6_send_reply(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, i ia_na->T2 = conf_pref_lifetime == -1 ? -1 : htonl((conf_pref_lifetime * 4) / 5); if (!pd->ipv6_dp) - pd->ipv6_dp = ipdb_get_ipv6_prefix(req->ppp); + pd->ipv6_dp = ipdb_get_ipv6_prefix(req->ses); if ((req->hdr->type == D6_RENEW) && pd->dp_iaid != ia_na->iaid) { insert_status(reply, opt1, D6_STATUS_NoBinding); @@ -327,7 +327,7 @@ static void dhcpv6_send_reply(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, i if (req->hdr->type == D6_REQUEST || req->rapid_commit) { pd->dp_iaid = ia_na->iaid; if (!pd->dp_active) - insert_dp_routes(req->ppp, pd); + insert_dp_routes(req->ses, pd); } f2 = 1; @@ -447,8 +447,8 @@ static void dhcpv6_send_reply2(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, f1 = 0; if (!f) { - list_for_each_entry(a, &req->ppp->ipv6->addr_list, entry) { - build_addr(a, req->ppp->ipv6->peer_intf_id, &addr); + list_for_each_entry(a, &req->ses->ipv6->addr_list, entry) { + build_addr(a, req->ses->ipv6->peer_intf_id, &addr); if (memcmp(&addr, &ia_addr->addr, sizeof(addr))) continue; f1 = 1; @@ -489,7 +489,7 @@ static void dhcpv6_send_reply2(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, ia_na->T2 = conf_pref_lifetime == -1 ? -1 : htonl((conf_pref_lifetime * 4) / 5); if (!pd->ipv6_dp) - pd->ipv6_dp = ipdb_get_ipv6_prefix(req->ppp); + pd->ipv6_dp = ipdb_get_ipv6_prefix(req->ses); f3 = 0; @@ -558,7 +558,7 @@ static void dhcpv6_send_reply2(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, static void dhcpv6_recv_solicit(struct dhcpv6_packet *req) { - struct dhcpv6_pd *pd = find_pd(req->ppp); + struct dhcpv6_pd *pd = find_pd(req->ses); if (!pd) return; @@ -590,7 +590,7 @@ static void dhcpv6_recv_solicit(struct dhcpv6_packet *req) static void dhcpv6_recv_request(struct dhcpv6_packet *req) { - struct dhcpv6_pd *pd = find_pd(req->ppp); + struct dhcpv6_pd *pd = find_pd(req->ses); if (!pd) return; @@ -618,7 +618,7 @@ static void dhcpv6_recv_request(struct dhcpv6_packet *req) static void dhcpv6_recv_renew(struct dhcpv6_packet *req) { - struct dhcpv6_pd *pd = find_pd(req->ppp); + struct dhcpv6_pd *pd = find_pd(req->ses); if (!pd) return; @@ -655,7 +655,7 @@ static void dhcpv6_recv_renew(struct dhcpv6_packet *req) static void dhcpv6_recv_information_request(struct dhcpv6_packet *req) { - struct dhcpv6_pd *pd = find_pd(req->ppp); + struct dhcpv6_pd *pd = find_pd(req->ses); if (req->rapid_commit) { log_ppp_error("dhcpv6: unexpected Rapid-Commit option\n"); @@ -669,7 +669,7 @@ static void dhcpv6_recv_information_request(struct dhcpv6_packet *req) static void dhcpv6_recv_rebind(struct dhcpv6_packet *req) { - struct dhcpv6_pd *pd = find_pd(req->ppp); + struct dhcpv6_pd *pd = find_pd(req->ses); if (!pd) return; @@ -747,7 +747,7 @@ static int dhcpv6_read(struct triton_md_handler_t *h) struct sockaddr_in6 addr; socklen_t len = sizeof(addr); struct dhcpv6_packet *pkt; - struct ppp_t *ppp; + struct ap_session *ses; while (1) { n = recvfrom(h->fd, buf, BUF_SIZE, 0, &addr, &len); @@ -768,26 +768,26 @@ static int dhcpv6_read(struct triton_md_handler_t *h) continue; } - pthread_rwlock_rdlock(&ppp_lock); - list_for_each_entry(ppp, &ppp_list, entry) { - if (ppp->state != PPP_STATE_ACTIVE) + pthread_rwlock_rdlock(&ses_lock); + list_for_each_entry(ses, &ses_list, entry) { + if (ses->state != AP_STATE_ACTIVE) continue; - if (!ppp->ipv6) + if (!ses->ipv6) continue; - if (ppp->ifindex != addr.sin6_scope_id) + if (ses->ifindex != addr.sin6_scope_id) continue; - if (ppp->ipv6->peer_intf_id != *(uint64_t *)(addr.sin6_addr.s6_addr + 8)) + if (ses->ipv6->peer_intf_id != *(uint64_t *)(addr.sin6_addr.s6_addr + 8)) continue; - pkt->ppp = ppp; + pkt->ses = ses; - triton_context_call(ppp->ctrl->ctx, (triton_event_func)dhcpv6_recv_packet, pkt); + triton_context_call(ses->ctrl->ctx, (triton_event_func)dhcpv6_recv_packet, pkt); break; } - pthread_rwlock_unlock(&ppp_lock); + pthread_rwlock_unlock(&ses_lock); } return 0; @@ -991,8 +991,8 @@ static void init(void) triton_context_wakeup(&dhcpv6_ctx); triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); - triton_event_register_handler(EV_PPP_STARTED, (triton_event_func)ev_ppp_started); - triton_event_register_handler(EV_PPP_FINISHED, (triton_event_func)ev_ppp_finished); + triton_event_register_handler(EV_SES_STARTED, (triton_event_func)ev_ppp_started); + triton_event_register_handler(EV_SES_FINISHED, (triton_event_func)ev_ppp_finished); } DEFINE_INIT(10, init); diff --git a/accel-pppd/ipv6/dhcpv6.h b/accel-pppd/ipv6/dhcpv6.h index d1c0267c..4afb5fa6 100644 --- a/accel-pppd/ipv6/dhcpv6.h +++ b/accel-pppd/ipv6/dhcpv6.h @@ -167,7 +167,7 @@ struct dhcpv6_option struct ppp_t; struct dhcpv6_packet { - struct ppp_t *ppp; + struct ap_session *ses; struct dhcpv6_msg_hdr *hdr; struct dhcpv6_opt_clientid *clientid; diff --git a/accel-pppd/ipv6/dhcpv6_packet.c b/accel-pppd/ipv6/dhcpv6_packet.c index 026b6afd..71184911 100644 --- a/accel-pppd/ipv6/dhcpv6_packet.c +++ b/accel-pppd/ipv6/dhcpv6_packet.c @@ -212,7 +212,7 @@ struct dhcpv6_packet *dhcpv6_packet_alloc_reply(struct dhcpv6_packet *req, int t memset(pkt, 0, sizeof(*pkt)); INIT_LIST_HEAD(&pkt->opt_list); - pkt->ppp = req->ppp; + pkt->ses = req->ses; pkt->hdr = _malloc(BUF_SIZE); if (!pkt->hdr) { diff --git a/accel-pppd/ipv6/nd.c b/accel-pppd/ipv6/nd.c index e6040a07..79a228cb 100644 --- a/accel-pppd/ipv6/nd.c +++ b/accel-pppd/ipv6/nd.c @@ -79,8 +79,8 @@ struct nd_opt_dnssl_info_local struct ipv6_nd_handler_t { - struct ppp_t *ppp; - struct ppp_pd_t pd; + struct ap_session *ses; + struct ap_private pd; struct triton_md_handler_t hnd; struct triton_timer_t timer; int ra_sent; @@ -120,7 +120,7 @@ static void ipv6_nd_send_ra(struct ipv6_nd_handler_t *h, struct sockaddr_in6 *ad adv->nd_ra_retransmit = htonl(conf_AdvRetransTimer); pinfo = (struct nd_opt_prefix_info *)(adv + 1); - list_for_each_entry(a, &h->ppp->ipv6->addr_list, entry) { + list_for_each_entry(a, &h->ses->ipv6->addr_list, entry) { if (a->prefix_len > 64) continue; @@ -136,7 +136,7 @@ static void ipv6_nd_send_ra(struct ipv6_nd_handler_t *h, struct sockaddr_in6 *ad } /*rinfo = (struct nd_opt_route_info_local *)pinfo; - list_for_each_entry(a, &h->ppp->ipv6->route_list, entry) { + list_for_each_entry(a, &h->ses->ipv6->route_list, entry) { memset(rinfo, 0, sizeof(*rinfo)); rinfo->nd_opt_ri_type = ND_OPT_ROUTE_INFORMATION; rinfo->nd_opt_ri_len = 3; @@ -186,7 +186,7 @@ static void send_ra_timer(struct triton_timer_t *t) addr.sin6_family = AF_INET6; addr.sin6_addr.s6_addr32[0] = htonl(0xff020000); addr.sin6_addr.s6_addr32[3] = htonl(0x1); - addr.sin6_scope_id = h->ppp->ifindex; + addr.sin6_scope_id = h->ses->ifindex; if (h->ra_sent++ == conf_init_ra) { h->timer.period = conf_MaxRtrAdvInterval * 1000; @@ -233,7 +233,7 @@ static int ipv6_nd_read(struct triton_md_handler_t *_h) continue; } - /*if (*(uint64_t *)(addr.sin6_addr.s6_addr + 8) != *(uint64_t *)(h->ppp->ipv6_addr.s6_addr + 8)) { + /*if (*(uint64_t *)(addr.sin6_addr.s6_addr + 8) != *(uint64_t *)(h->ses->ipv6_addr.s6_addr + 8)) { log_ppp_warn("ipv6_nd: received icmp packet from unknown address\n"); continue; }*/ @@ -246,7 +246,7 @@ static int ipv6_nd_read(struct triton_md_handler_t *_h) return 0; } -static int ipv6_nd_start(struct ppp_t *ppp) +static int ipv6_nd_start(struct ap_session *ses) { int sock; struct icmp6_filter filter; @@ -267,8 +267,8 @@ static int ipv6_nd_start(struct ppp_t *ppp) memset(&addr, 0, sizeof(addr)); addr.sin6_family = AF_INET6; addr.sin6_addr.s6_addr32[0] = htons(0xfe80); - *(uint64_t *)(addr.sin6_addr.s6_addr + 8) = ppp->ipv6->intf_id; - addr.sin6_scope_id = ppp->ifindex; + *(uint64_t *)(addr.sin6_addr.s6_addr + 8) = ses->ipv6->intf_id; + addr.sin6_scope_id = ses->ifindex; if (bind(sock, (struct sockaddr *)&addr, sizeof(addr))) { log_ppp_error("ipv6_nd: bind: %s %i\n", strerror(errno), errno); @@ -307,7 +307,7 @@ static int ipv6_nd_start(struct ppp_t *ppp) } memset(&mreq, 0, sizeof(mreq)); - mreq.ipv6mr_interface = ppp->ifindex; + mreq.ipv6mr_interface = ses->ifindex; mreq.ipv6mr_multiaddr.s6_addr32[0] = htonl(0xff020000); mreq.ipv6mr_multiaddr.s6_addr32[3] = htonl(0x2); @@ -320,18 +320,18 @@ static int ipv6_nd_start(struct ppp_t *ppp) h = _malloc(sizeof(*h)); memset(h, 0, sizeof(*h)); - h->ppp = ppp; + h->ses = ses; h->pd.key = &pd_key; h->hnd.fd = sock; h->hnd.read = ipv6_nd_read; h->timer.expire = send_ra_timer; h->timer.period = conf_init_ra_interval * 1000; - list_add_tail(&h->pd.entry, &ppp->pd_list); + list_add_tail(&h->pd.entry, &ses->pd_list); - triton_md_register_handler(ppp->ctrl->ctx, &h->hnd); + triton_md_register_handler(ses->ctrl->ctx, &h->hnd); triton_md_enable_handler(&h->hnd, MD_MODE_READ); - triton_timer_add(ppp->ctrl->ctx, &h->timer, 0); + triton_timer_add(ses->ctrl->ctx, &h->timer, 0); return 0; @@ -340,11 +340,11 @@ out_err: return -1; } -static struct ipv6_nd_handler_t *find_pd(struct ppp_t *ppp) +static struct ipv6_nd_handler_t *find_pd(struct ap_session *ses) { - struct ppp_pd_t *pd; + struct ap_private *pd; - list_for_each_entry(pd, &ppp->pd_list, entry) { + list_for_each_entry(pd, &ses->pd_list, entry) { if (pd->key == &pd_key) return container_of(pd, typeof(struct ipv6_nd_handler_t), pd); } @@ -352,17 +352,17 @@ static struct ipv6_nd_handler_t *find_pd(struct ppp_t *ppp) return NULL; } -static void ev_ppp_started(struct ppp_t *ppp) +static void ev_ses_started(struct ap_session *ses) { - if (!ppp->ipv6) + if (!ses->ipv6) return; - ipv6_nd_start(ppp); + ipv6_nd_start(ses); } -static void ev_ppp_finishing(struct ppp_t *ppp) +static void ev_ses_finishing(struct ap_session *ses) { - struct ipv6_nd_handler_t *h = find_pd(ppp); + struct ipv6_nd_handler_t *h = find_pd(ses); if (!h) return; @@ -531,8 +531,8 @@ static void init(void) load_config(); triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); - triton_event_register_handler(EV_PPP_STARTED, (triton_event_func)ev_ppp_started); - triton_event_register_handler(EV_PPP_FINISHING, (triton_event_func)ev_ppp_finishing); + triton_event_register_handler(EV_SES_STARTED, (triton_event_func)ev_ses_started); + triton_event_register_handler(EV_SES_FINISHING, (triton_event_func)ev_ses_finishing); } DEFINE_INIT(5, init); diff --git a/accel-pppd/log.c b/accel-pppd/log.c index 43e98a97..b19f64b4 100644 --- a/accel-pppd/log.c +++ b/accel-pppd/log.c @@ -25,8 +25,8 @@ struct log_pd_t { - struct ppp_pd_t pd; - struct ppp_t *ppp; + struct ap_private pd; + struct ap_session *ses; struct list_head msgs; struct log_msg_t *msg; int authorized:1; @@ -48,7 +48,7 @@ static mempool_t msg_pool; static mempool_t _msg_pool; static mempool_t chunk_pool; -static __thread struct ppp_t *cur_ppp; +static __thread struct ap_session *cur_ses; static __thread struct _log_msg_t *cur_msg; static __thread char *stat_buf; static pthread_key_t stat_buf_key; @@ -59,15 +59,15 @@ static FILE *debug_file; static void _log_free_msg(struct _log_msg_t *msg); static struct log_msg_t *clone_msg(struct _log_msg_t *msg); static int add_msg(struct _log_msg_t *msg, const char *buf); -//static struct log_pd_t *find_pd(struct ppp_t *ppp); -static void write_msg(FILE *f, struct _log_msg_t *msg, struct ppp_t *ppp); +//static struct log_pd_t *find_pd(struct ap_session *ses); +static void write_msg(FILE *f, struct _log_msg_t *msg, struct ap_session *ses); static void stat_buf_free(void *ptr) { _free(ptr); } -static void do_log(int level, const char *fmt, va_list ap, struct ppp_t *ppp) +static void do_log(int level, const char *fmt, va_list ap, struct ap_session *ses) { struct log_target_t *t; struct log_msg_t *m; @@ -96,13 +96,13 @@ static void do_log(int level, const char *fmt, va_list ap, struct ppp_t *ppp) return; if (debug_file) - write_msg(debug_file, cur_msg, ppp); + write_msg(debug_file, cur_msg, ses); list_for_each_entry(t, &targets, entry) { m = clone_msg(cur_msg); if (!m) break; - t->log(t, m, ppp); + t->log(t, m, ses); } out: @@ -183,7 +183,7 @@ void __export log_ppp_error(const char *fmt,...) if (log_level >= LOG_ERROR) { va_list ap; va_start(ap, fmt); - do_log(LOG_ERROR, fmt, ap, cur_ppp); + do_log(LOG_ERROR, fmt, ap, cur_ses); va_end(ap); } } @@ -193,7 +193,7 @@ void __export log_ppp_warn(const char *fmt,...) if (log_level >= LOG_WARN) { va_list ap; va_start(ap, fmt); - do_log(LOG_WARN, fmt, ap, cur_ppp); + do_log(LOG_WARN, fmt, ap, cur_ses); va_end(ap); } } @@ -203,7 +203,7 @@ void __export log_ppp_info1(const char *fmt,...) if (log_level >= LOG_INFO1) { va_list ap; va_start(ap, fmt); - do_log(LOG_INFO1, fmt, ap, cur_ppp); + do_log(LOG_INFO1, fmt, ap, cur_ses); va_end(ap); } } @@ -213,7 +213,7 @@ void __export log_ppp_info2(const char *fmt,...) if (log_level >= LOG_INFO2) { va_list ap; va_start(ap, fmt); - do_log(LOG_INFO2, fmt, ap, cur_ppp); + do_log(LOG_INFO2, fmt, ap, cur_ses); va_end(ap); } } @@ -223,7 +223,7 @@ void __export log_ppp_debug(const char *fmt,...) if (log_level >= LOG_DEBUG) { va_list ap; va_start(ap, fmt); - do_log(LOG_DEBUG, fmt, ap, cur_ppp); + do_log(LOG_DEBUG, fmt, ap, cur_ses); va_end(ap); } } @@ -232,7 +232,7 @@ void __export log_ppp_msg(const char *fmt,...) { va_list ap; va_start(ap, fmt); - do_log(LOG_MSG, fmt, ap, cur_ppp); + do_log(LOG_MSG, fmt, ap, cur_ses); va_end(ap); } @@ -326,12 +326,12 @@ static int add_msg(struct _log_msg_t *msg, const char *buf) return 0; } -static void write_msg(FILE *f, struct _log_msg_t *msg, struct ppp_t *ppp) +static void write_msg(FILE *f, struct _log_msg_t *msg, struct ap_session *ses) { struct log_chunk_t *chunk; - if (ppp) - sprintf(stat_buf,"%s: %s: ", ppp->ifname, ppp->sessionid); + if (ses) + sprintf(stat_buf,"%s: %s: ", ses->ifname, ses->sessionid); else stat_buf[0] = 0; @@ -342,12 +342,12 @@ static void write_msg(FILE *f, struct _log_msg_t *msg, struct ppp_t *ppp) fflush(f); } -/*static struct log_pd_t *find_pd(struct ppp_t *ppp) +/*static struct log_pd_t *find_pd(struct ap_session *ses) { - struct ppp_pd_t *pd; + struct ap_private *pd; struct log_pd_t *lpd; - list_for_each_entry(pd, &ppp->pd_list, entry) { + list_for_each_entry(pd, &ses->pd_list, entry) { if (pd->key == &pd_key) { lpd = container_of(pd, typeof(*lpd), pd); return lpd; @@ -357,7 +357,7 @@ static void write_msg(FILE *f, struct _log_msg_t *msg, struct ppp_t *ppp) abort(); } -static void ev_ctrl_starting(struct ppp_t *ppp) +static void ev_ctrl_starting(struct ap_session *ses) { struct log_pd_t *lpd = _malloc(sizeof(*lpd)); if (!lpd) { @@ -369,10 +369,10 @@ static void ev_ctrl_starting(struct ppp_t *ppp) lpd->pd.key = &pd_key; lpd->ppp = ppp; INIT_LIST_HEAD(&lpd->msgs); - list_add_tail(&lpd->pd.entry, &ppp->pd_list); + list_add_tail(&lpd->pd.entry, &ses->pd_list); } -static void ev_ctrl_finished(struct ppp_t *ppp) +static void ev_ctrl_finished(struct ap_session *ses) { struct log_pd_t *lpd = find_pd(ppp); struct _log_msg_t *msg; @@ -414,7 +414,7 @@ static void ev_ctrl_finished(struct ppp_t *ppp) _free(lpd); } -static void ev_ppp_authorized(struct ppp_t *ppp) +static void ev_ppp_authorized(struct ap_session *ses) { struct log_pd_t *lpd = find_pd(ppp); struct _log_msg_t *msg; @@ -446,7 +446,7 @@ static void ev_ppp_authorized(struct ppp_t *ppp) void __export log_switch(struct triton_context_t *ctx, void *arg) { - cur_ppp = (struct ppp_t *)arg; + cur_ses = (struct ap_session *)arg; } diff --git a/accel-pppd/log.h b/accel-pppd/log.h index 58461465..2ff2ac80 100644 --- a/accel-pppd/log.h +++ b/accel-pppd/log.h @@ -8,7 +8,7 @@ #define LOG_MAX_SIZE 4096 #define LOG_CHUNK_SIZE 128 -struct ppp_t; +struct ap_session; struct triton_context_t; struct log_msg_t @@ -33,7 +33,7 @@ struct log_target_t { struct list_head entry; - void (*log)(struct log_target_t *, struct log_msg_t *, struct ppp_t *ppp); + void (*log)(struct log_target_t *, struct log_msg_t *, struct ap_session *ses); void (*reopen)(void); }; diff --git a/accel-pppd/logs/log_file.c b/accel-pppd/logs/log_file.c index 48f43510..1da3ee3f 100644 --- a/accel-pppd/logs/log_file.c +++ b/accel-pppd/logs/log_file.c @@ -42,14 +42,14 @@ struct log_file_t struct log_file_pd_t { - struct ppp_pd_t pd; + struct ap_private pd; struct log_file_t lf; unsigned long tmp; }; struct fail_log_pd_t { - struct ppp_pd_t pd; + struct ap_private pd; struct list_head msgs; }; @@ -285,7 +285,7 @@ static void queue_log_list(struct log_file_t *lf, struct list_head *l) } -static void set_hdr(struct log_msg_t *msg, struct ppp_t *ppp) +static void set_hdr(struct log_msg_t *msg, struct ap_session *ses) { struct tm tm; char timestamp[32]; @@ -295,28 +295,28 @@ static void set_hdr(struct log_msg_t *msg, struct ppp_t *ppp) strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", &tm); sprintf(msg->hdr->msg, "%s[%s]: %s: %s%s%s", conf_color ? level_color[msg->level] : "", timestamp, level_name[msg->level], - ppp ? ppp->ifname : "", - ppp ? ": " : "", + ses ? ses->ifname : "", + ses ? ": " : "", conf_color ? NORMAL_COLOR : ""); msg->hdr->len = strlen(msg->hdr->msg); } -static void general_log(struct log_target_t *t, struct log_msg_t *msg, struct ppp_t *ppp) +static void general_log(struct log_target_t *t, struct log_msg_t *msg, struct ap_session *ses) { - if (ppp && !conf_copy) { + if (ses && !conf_copy) { log_free_msg(msg); return; } - set_hdr(msg, ppp); + set_hdr(msg, ses); queue_log(log_file, msg); } -static struct ppp_pd_t *find_pd(struct ppp_t *ppp, void *pd_key) +static struct ap_private *find_pd(struct ap_session *ses, void *pd_key) { - struct ppp_pd_t *pd; + struct ap_private *pd; - list_for_each_entry(pd, &ppp->pd_list, entry) { + list_for_each_entry(pd, &ses->pd_list, entry) { if (pd->key == pd_key) { return pd; } @@ -325,9 +325,9 @@ static struct ppp_pd_t *find_pd(struct ppp_t *ppp, void *pd_key) return NULL; } -static struct log_file_pd_t *find_lpd(struct ppp_t *ppp, void *pd_key) +static struct log_file_pd_t *find_lpd(struct ap_session *ses, void *pd_key) { - struct ppp_pd_t *pd = find_pd(ppp, pd_key); + struct ap_private *pd = find_pd(ses, pd_key); if (!pd) return NULL; @@ -335,9 +335,9 @@ static struct log_file_pd_t *find_lpd(struct ppp_t *ppp, void *pd_key) return container_of(pd, struct log_file_pd_t, pd); } -static struct fail_log_pd_t *find_fpd(struct ppp_t *ppp, void *pd_key) +static struct fail_log_pd_t *find_fpd(struct ap_session *ses, void *pd_key) { - struct ppp_pd_t *pd = find_pd(ppp, pd_key); + struct ap_private *pd = find_pd(ses, pd_key); if (!pd) return NULL; @@ -346,63 +346,63 @@ static struct fail_log_pd_t *find_fpd(struct ppp_t *ppp, void *pd_key) } -static void per_user_log(struct log_target_t *t, struct log_msg_t *msg, struct ppp_t *ppp) +static void per_user_log(struct log_target_t *t, struct log_msg_t *msg, struct ap_session *ses) { struct log_file_pd_t *lpd; - if (!ppp) { + if (!ses) { log_free_msg(msg); return; } - lpd = find_lpd(ppp, &pd_key1); + lpd = find_lpd(ses, &pd_key1); if (!lpd) { log_free_msg(msg); return; } - set_hdr(msg, ppp); + set_hdr(msg, ses); queue_log(&lpd->lf, msg); } -static void per_session_log(struct log_target_t *t, struct log_msg_t *msg, struct ppp_t *ppp) +static void per_session_log(struct log_target_t *t, struct log_msg_t *msg, struct ap_session *ses) { struct log_file_pd_t *lpd; - if (!ppp) { + if (!ses) { log_free_msg(msg); return; } - lpd = find_lpd(ppp, &pd_key2); + lpd = find_lpd(ses, &pd_key2); if (!lpd) { log_free_msg(msg); return; } - set_hdr(msg, ppp); + set_hdr(msg, ses); queue_log(&lpd->lf, msg); } -static void fail_log(struct log_target_t *t, struct log_msg_t *msg, struct ppp_t *ppp) +static void fail_log(struct log_target_t *t, struct log_msg_t *msg, struct ap_session *ses) { struct fail_log_pd_t *fpd; - if (!ppp || !conf_fail_log) { + if (!ses || !conf_fail_log) { log_free_msg(msg); return; } - fpd = find_fpd(ppp, &pd_key3); + fpd = find_fpd(ses, &pd_key3); if (!fpd) { log_free_msg(msg); return; } - set_hdr(msg, ppp); + set_hdr(msg, ses); list_add_tail(&msg->entry, &fpd->msgs); } @@ -453,12 +453,12 @@ static void free_lpd(struct log_file_pd_t *lpd) } } -static void ev_ppp_authorized2(struct ppp_t *ppp) +static void ev_ses_authorized2(struct ap_session *ses) { struct fail_log_pd_t *fpd; struct log_msg_t *msg; - fpd = find_fpd(ppp, &pd_key3); + fpd = find_fpd(ses, &pd_key3); if (!fpd) return; @@ -472,12 +472,12 @@ static void ev_ppp_authorized2(struct ppp_t *ppp) mempool_free(fpd); } -static void ev_ppp_authorized1(struct ppp_t *ppp) +static void ev_ses_authorized1(struct ap_session *ses) { struct log_file_pd_t *lpd; char *fname; - lpd = find_lpd(ppp, &pd_key1); + lpd = find_lpd(ses, &pd_key1); if (!lpd) return; @@ -489,14 +489,14 @@ static void ev_ppp_authorized1(struct ppp_t *ppp) strcpy(fname, conf_per_user_dir); strcat(fname, "/"); - strcat(fname, ppp->username); + strcat(fname, ses->username); if (conf_per_session) { if (mkdir(fname, S_IRWXU) && errno != EEXIST) { log_emerg("log_file: mkdir '%s': %s'\n", fname, strerror(errno)); goto out_err; } strcat(fname, "/"); - strcat(fname, ppp->sessionid); + strcat(fname, ses->sessionid); } strcat(fname, ".log"); @@ -518,7 +518,7 @@ out_err: free_lpd(lpd); } -static void ev_ctrl_started(struct ppp_t *ppp) +static void ev_ctrl_started(struct ap_session *ses) { struct log_file_pd_t *lpd; struct fail_log_pd_t *fpd; @@ -534,7 +534,7 @@ static void ev_ctrl_started(struct ppp_t *ppp) lpd->pd.key = &pd_key1; log_file_init(&lpd->lf); lpd->lf.lpd = lpd; - list_add_tail(&lpd->pd.entry, &ppp->pd_list); + list_add_tail(&lpd->pd.entry, &ses->pd_list); } if (conf_per_session_dir) { @@ -568,7 +568,7 @@ static void ev_ctrl_started(struct ppp_t *ppp) _free(fname); - list_add_tail(&lpd->pd.entry, &ppp->pd_list); + list_add_tail(&lpd->pd.entry, &ses->pd_list); } if (conf_fail_log) { @@ -579,29 +579,29 @@ static void ev_ctrl_started(struct ppp_t *ppp) } memset(fpd, 0, sizeof(*fpd)); fpd->pd.key = &pd_key3; - list_add_tail(&fpd->pd.entry, &ppp->pd_list); + list_add_tail(&fpd->pd.entry, &ses->pd_list); INIT_LIST_HEAD(&fpd->msgs); } } -static void ev_ctrl_finished(struct ppp_t *ppp) +static void ev_ctrl_finished(struct ap_session *ses) { struct log_file_pd_t *lpd; struct fail_log_pd_t *fpd; char *fname; - fpd = find_fpd(ppp, &pd_key3); + fpd = find_fpd(ses, &pd_key3); if (fpd) { queue_log_list(fail_log_file, &fpd->msgs); list_del(&fpd->pd.entry); mempool_free(fpd); } - lpd = find_lpd(ppp, &pd_key1); + lpd = find_lpd(ses, &pd_key1); if (lpd) free_lpd(lpd); - lpd = find_lpd(ppp, &pd_key2); + lpd = find_lpd(ses, &pd_key2); if (lpd) { if (lpd->tmp) { fname = _malloc(PATH_MAX); @@ -619,12 +619,12 @@ static void ev_ctrl_finished(struct ppp_t *ppp) } } -static void ev_ppp_starting(struct ppp_t *ppp) +static void ev_ses_starting(struct ap_session *ses) { struct log_file_pd_t *lpd; char *fname1, *fname2; - lpd = find_lpd(ppp, &pd_key2); + lpd = find_lpd(ses, &pd_key2); if (!lpd) return; @@ -647,7 +647,7 @@ static void ev_ppp_starting(struct ppp_t *ppp) strcpy(fname2, conf_per_session_dir); strcat(fname2, "/"); - strcat(fname2, ppp->sessionid); + strcat(fname2, ses->sessionid); strcat(fname2, ".log"); if (rename(fname1, fname2)) @@ -753,17 +753,17 @@ static void init(void) if (conf_per_user_dir) { log_register_target(&per_user_target); - triton_event_register_handler(EV_PPP_AUTHORIZED, (triton_event_func)ev_ppp_authorized1); + triton_event_register_handler(EV_SES_AUTHORIZED, (triton_event_func)ev_ses_authorized1); } if (conf_per_session_dir) { log_register_target(&per_session_target); - triton_event_register_handler(EV_PPP_STARTING, (triton_event_func)ev_ppp_starting); + triton_event_register_handler(EV_SES_STARTING, (triton_event_func)ev_ses_starting); } if (conf_fail_log) { log_register_target(&fail_log_target); - triton_event_register_handler(EV_PPP_AUTHORIZED, (triton_event_func)ev_ppp_authorized2); + triton_event_register_handler(EV_SES_AUTHORIZED, (triton_event_func)ev_ses_authorized2); } triton_event_register_handler(EV_CTRL_STARTED, (triton_event_func)ev_ctrl_started); diff --git a/accel-pppd/logs/log_syslog.c b/accel-pppd/logs/log_syslog.c index 5a922f57..cbab5252 100644 --- a/accel-pppd/logs/log_syslog.c +++ b/accel-pppd/logs/log_syslog.c @@ -50,10 +50,10 @@ static void unpack_msg(struct log_msg_t *msg) log_buf[0] = 0; } -static void set_hdr(struct log_msg_t *msg, struct ppp_t *ppp) +static void set_hdr(struct log_msg_t *msg, struct ap_session *ses) { - if (ppp) { - if (snprintf(msg->hdr->msg, LOG_CHUNK_SIZE, "%s:%s: ", ppp->ifname, ppp->username ? ppp->username : "")) + if (ses) { + if (snprintf(msg->hdr->msg, LOG_CHUNK_SIZE, "%s:%s: ", ses->ifname, ses->username ? ses->username : "")) strcpy(msg->hdr->msg + LOG_CHUNK_SIZE - 3, ": "); } else msg->hdr->msg[0] = 0; @@ -104,9 +104,9 @@ static void queue_log(struct log_msg_t *msg) } -static void general_log(struct log_target_t *t, struct log_msg_t *msg, struct ppp_t *ppp) +static void general_log(struct log_target_t *t, struct log_msg_t *msg, struct ap_session *ses) { - set_hdr(msg, ppp); + set_hdr(msg, ses); if (syslog_ctx.tpd) queue_log(msg); diff --git a/accel-pppd/logs/log_tcp.c b/accel-pppd/logs/log_tcp.c index 3f76ff8a..b89b7d65 100644 --- a/accel-pppd/logs/log_tcp.c +++ b/accel-pppd/logs/log_tcp.c @@ -130,7 +130,7 @@ static void queue_log(struct tcp_target_t *t, struct log_msg_t *msg) } } -static void set_hdr(struct log_msg_t *msg, struct ppp_t *ppp) +static void set_hdr(struct log_msg_t *msg, struct ap_session *ses) { struct tm tm; char timestamp[32]; @@ -138,15 +138,15 @@ static void set_hdr(struct log_msg_t *msg, struct ppp_t *ppp) localtime_r(&msg->timestamp.tv_sec, &tm); strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", &tm); - sprintf(msg->hdr->msg, "[%s]: %s: %s: ", timestamp, level_name[msg->level], ppp ? ppp->ifname : ""); + sprintf(msg->hdr->msg, "[%s]: %s: %s: ", timestamp, level_name[msg->level], ses ? ses->ifname : ""); msg->hdr->len = strlen(msg->hdr->msg); } -static void general_log(struct log_target_t *lt, struct log_msg_t *msg, struct ppp_t *ppp) +static void general_log(struct log_target_t *lt, struct log_msg_t *msg, struct ap_session *ses) { struct tcp_target_t *t = container_of(lt, typeof(*t), target); - set_hdr(msg, ppp); + set_hdr(msg, ses); queue_log(t, msg); } diff --git a/accel-pppd/ppp/ccp_mppe.c b/accel-pppd/ppp/ccp_mppe.c index 388e2f6c..ae2b2cae 100644 --- a/accel-pppd/ppp/ccp_mppe.c +++ b/accel-pppd/ppp/ccp_mppe.c @@ -61,10 +61,10 @@ static struct ccp_option_t *mppe_init(struct ppp_ccp_t *ccp) memset(mppe_opt, 0, sizeof(*mppe_opt)); int mppe; - if (ccp->ppp->ctrl->mppe == MPPE_UNSET) + if (ccp->ppp->ses.ctrl->mppe == MPPE_UNSET) mppe = conf_mppe; else - mppe = ccp->ppp->ctrl->mppe; + mppe = ccp->ppp->ses.ctrl->mppe; if (mppe != MPPE_ALLOW) mppe_opt->policy = mppe; @@ -78,6 +78,9 @@ static struct ccp_option_t *mppe_init(struct ppp_ccp_t *ccp) if (mppe == MPPE_REQUIRE || mppe == MPPE_PREFER) ccp->ld.passive = 0; + + if (mppe == MPPE_REQUIRE) + ccp->ld.optional = 0; mppe_opt->opt.id = CI_MPPE; mppe_opt->opt.len = 6; @@ -121,7 +124,7 @@ static int decrease_mtu(struct ppp_t *ppp) { struct ifreq ifr; - strcpy(ifr.ifr_name, ppp->ifname); + strcpy(ifr.ifr_name, ppp->ses.ifname); if (ioctl(sock_fd, SIOCGIFMTU, &ifr)) { log_ppp_error("mppe: failed to get MTU: %s\n", strerror(errno)); @@ -173,10 +176,10 @@ static int mppe_recv_conf_req(struct ppp_ccp_t *ccp, struct ccp_option_t *opt, u struct ccp_opt32_t *opt32 = (struct ccp_opt32_t *)ptr; int mppe; - if (ccp->ppp->ctrl->mppe == MPPE_UNSET) + if (ccp->ppp->ses.ctrl->mppe == MPPE_UNSET) mppe = conf_mppe; else - mppe = ccp->ppp->ctrl->mppe; + mppe = ccp->ppp->ses.ctrl->mppe; if (!ptr) { if (mppe_opt->policy == 2) @@ -299,12 +302,12 @@ static void ev_mppe_keys(struct ev_mppe_keys_t *ev) return; } - if (ccp->ppp->ctrl->mppe == MPPE_UNSET) + if (ccp->ppp->ses.ctrl->mppe == MPPE_UNSET) mppe = conf_mppe; else - mppe = ev->ppp->ctrl->mppe; + mppe = ev->ppp->ses.ctrl->mppe; - if (ev->ppp->ctrl->mppe == MPPE_UNSET) { + if (ev->ppp->ses.ctrl->mppe == MPPE_UNSET) { mppe_opt->policy = ev->policy; if (ev->policy == 2) { diff --git a/accel-pppd/ppp/ipcp_opt_dns.c b/accel-pppd/ppp/ipcp_opt_dns.c index 19183eb7..1ca8723b 100644 --- a/accel-pppd/ppp/ipcp_opt_dns.c +++ b/accel-pppd/ppp/ipcp_opt_dns.c @@ -143,11 +143,17 @@ static void dns2_print(void (*print)(const char *fmt,...),struct ipcp_option_t * static void ev_dns(struct ev_dns_t *ev) { struct dns_option_t *dns_opt; + struct ppp_t *ppp; - dns_opt = container_of(ipcp_find_option(ev->ppp, &dns1_opt_hnd), typeof(*dns_opt), opt); + if (ev->ses->ctrl->type == CTRL_TYPE_IPOE) + return; + + ppp = container_of(ev->ses, typeof(*ppp), ses); + + dns_opt = container_of(ipcp_find_option(ppp, &dns1_opt_hnd), typeof(*dns_opt), opt); dns_opt->addr = ev->dns1; - dns_opt = container_of(ipcp_find_option(ev->ppp, &dns2_opt_hnd), typeof(*dns_opt), opt); + dns_opt = container_of(ipcp_find_option(ppp, &dns2_opt_hnd), typeof(*dns_opt), opt); dns_opt->addr = ev->dns2; } diff --git a/accel-pppd/ppp/ipcp_opt_ipaddr.c b/accel-pppd/ppp/ipcp_opt_ipaddr.c index e965f5c2..44dd3ddd 100644 --- a/accel-pppd/ppp/ipcp_opt_ipaddr.c +++ b/accel-pppd/ppp/ipcp_opt_ipaddr.c @@ -58,9 +58,9 @@ static void ipaddr_free(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt) { struct ipaddr_option_t *ipaddr_opt = container_of(opt, typeof(*ipaddr_opt), opt); - if (ipcp->ppp->ipv4) { - ipdb_put_ipv4(ipcp->ppp, ipcp->ppp->ipv4); - ipcp->ppp->ipv4 = NULL; + if (ipcp->ppp->ses.ipv4) { + ipdb_put_ipv4(&ipcp->ppp->ses, ipcp->ppp->ses.ipv4); + ipcp->ppp->ses.ipv4 = NULL; } _free(ipaddr_opt); @@ -68,40 +68,40 @@ static void ipaddr_free(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *opt) static int check_exists(struct ppp_t *self_ppp, in_addr_t addr) { - struct ppp_t *ppp; + struct ap_session *ses; int r = 0; - pthread_rwlock_rdlock(&ppp_lock); - list_for_each_entry(ppp, &ppp_list, entry) { - if (!ppp->terminating && ppp->ipv4 && ppp->ipv4->peer_addr == addr && ppp != self_ppp) { - log_ppp_warn("ppp: requested IPv4 address already assigned to %s\n", ppp->ifname); + pthread_rwlock_rdlock(&ses_lock); + list_for_each_entry(ses, &ses_list, entry) { + if (!ses->terminating && ses->ipv4 && ses->ipv4->peer_addr == addr && ses != &self_ppp->ses) { + log_ppp_warn("ppp: requested IPv4 address already assigned to %s\n", ses->ifname); r = 1; break; } } - pthread_rwlock_unlock(&ppp_lock); + pthread_rwlock_unlock(&ses_lock); return r; } static int alloc_ip(struct ppp_t *ppp) { - ppp->ipv4 = ipdb_get_ipv4(ppp); - if (!ppp->ipv4) { + ppp->ses.ipv4 = ipdb_get_ipv4(&ppp->ses); + if (!ppp->ses.ipv4) { log_ppp_warn("ppp: no free IPv4 address\n"); return IPCP_OPT_CLOSE; } - if (iprange_tunnel_check(ppp->ipv4->peer_addr)) { + if (iprange_tunnel_check(ppp->ses.ipv4->peer_addr)) { log_ppp_warn("ppp:ipcp: to avoid kernel soft lockup requested IP cannot be assigned (%i.%i.%i.%i)\n", - ppp->ipv4->peer_addr&0xff, - (ppp->ipv4->peer_addr >> 8)&0xff, - (ppp->ipv4->peer_addr >> 16)&0xff, - (ppp->ipv4->peer_addr >> 24)&0xff); + ppp->ses.ipv4->peer_addr&0xff, + (ppp->ses.ipv4->peer_addr >> 8)&0xff, + (ppp->ses.ipv4->peer_addr >> 16)&0xff, + (ppp->ses.ipv4->peer_addr >> 24)&0xff); return IPCP_OPT_FAIL; } - if (conf_check_exists && check_exists(ppp, ppp->ipv4->peer_addr)) + if (conf_check_exists && check_exists(ppp, ppp->ses.ipv4->peer_addr)) return IPCP_OPT_FAIL; return 0; @@ -113,7 +113,7 @@ static int ipaddr_send_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *o struct ipcp_opt32_t *opt32 = (struct ipcp_opt32_t *)ptr; int r; - if (!ipcp->ppp->ipv4) { + if (!ipcp->ppp->ses.ipv4) { r = alloc_ip(ipcp->ppp); if (r) return r; @@ -121,7 +121,7 @@ static int ipaddr_send_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *o opt32->hdr.id = CI_ADDR; opt32->hdr.len = 6; - opt32->val = ipcp->ppp->ipv4->addr; + opt32->val = ipcp->ppp->ses.ipv4->addr; return 6; } @@ -131,7 +131,7 @@ static int ipaddr_send_conf_nak(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *o struct ipcp_opt32_t *opt32 = (struct ipcp_opt32_t *)ptr; opt32->hdr.id = CI_ADDR; opt32->hdr.len = 6; - opt32->val = ipcp->ppp->ipv4->peer_addr; + opt32->val = ipcp->ppp->ses.ipv4->peer_addr; return 6; } @@ -141,7 +141,7 @@ static int ipaddr_recv_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *o struct ipcp_opt32_t *opt32 = (struct ipcp_opt32_t *)ptr; int r; - if (!ipcp->ppp->ipv4) { + if (!ipcp->ppp->ses.ipv4) { r = alloc_ip(ipcp->ppp); if (r) return r; @@ -150,7 +150,7 @@ static int ipaddr_recv_conf_req(struct ppp_ipcp_t *ipcp, struct ipcp_option_t *o if (opt32->hdr.len != 6) return IPCP_OPT_REJ; - if (ipcp->ppp->ipv4->peer_addr == opt32->val) { + if (ipcp->ppp->ses.ipv4->peer_addr == opt32->val) { ipcp->delay_ack = ccp_ipcp_started(ipcp->ppp); return IPCP_OPT_ACK; } @@ -166,8 +166,8 @@ static void ipaddr_print(void (*print)(const char *fmt,...),struct ipcp_option_t if (ptr) in.s_addr = opt32->val; - else if (ipaddr_opt->ppp->ipv4) - in.s_addr = ipaddr_opt->ppp->ipv4->addr; + else if (ipaddr_opt->ppp->ses.ipv4) + in.s_addr = ipaddr_opt->ppp->ses.ipv4->addr; print("<addr %s>",inet_ntoa(in)); } diff --git a/accel-pppd/ppp/ipv6cp_opt_intfid.c b/accel-pppd/ppp/ipv6cp_opt_intfid.c index 9a2ddee0..21f0b931 100644 --- a/accel-pppd/ppp/ipv6cp_opt_intfid.c +++ b/accel-pppd/ppp/ipv6cp_opt_intfid.c @@ -72,9 +72,9 @@ static void ipaddr_free(struct ppp_ipv6cp_t *ipv6cp, struct ipv6cp_option_t *opt { struct ipaddr_option_t *ipaddr_opt=container_of(opt,typeof(*ipaddr_opt),opt); - if (ipv6cp->ppp->ipv6) { - ipdb_put_ipv6(ipv6cp->ppp, ipv6cp->ppp->ipv6); - ipv6cp->ppp->ipv6 = NULL; + if (ipv6cp->ppp->ses.ipv6) { + ipdb_put_ipv6(&ipv6cp->ppp->ses, ipv6cp->ppp->ses.ipv6); + ipv6cp->ppp->ses.ipv6 = NULL; } _free(ipaddr_opt); @@ -82,24 +82,24 @@ static void ipaddr_free(struct ppp_ipv6cp_t *ipv6cp, struct ipv6cp_option_t *opt static int check_exists(struct ppp_t *self_ppp) { - struct ppp_t *ppp; + struct ap_session *ses; struct ipv6db_addr_t *a1, *a2; int r = 0; - pthread_rwlock_rdlock(&ppp_lock); - list_for_each_entry(ppp, &ppp_list, entry) { - if (ppp->terminating) + pthread_rwlock_rdlock(&ses_lock); + list_for_each_entry(ses, &ses_list, entry) { + if (ses->terminating) continue; - if (!ppp->ipv6) + if (!ses->ipv6) continue; - if (ppp == self_ppp) + if (ses == &self_ppp->ses) continue; - list_for_each_entry(a1, &ppp->ipv6->addr_list, entry) { - list_for_each_entry(a2, &self_ppp->ipv6->addr_list, entry) { + list_for_each_entry(a1, &ses->ipv6->addr_list, entry) { + list_for_each_entry(a2, &ses->ipv6->addr_list, entry) { if (a1->addr.s6_addr32[0] == a2->addr.s6_addr32[0] && a1->addr.s6_addr32[1] == a2->addr.s6_addr32[1]) { - log_ppp_warn("ppp: requested IPv6 address already assigned to %s\n", ppp->ifname); + log_ppp_warn("ppp: requested IPv6 address already assigned to %s\n", ses->ifname); r = 1; goto out; } @@ -107,7 +107,7 @@ static int check_exists(struct ppp_t *self_ppp) } } out: - pthread_rwlock_unlock(&ppp_lock); + pthread_rwlock_unlock(&ses_lock); return r; } @@ -148,9 +148,9 @@ static uint64_t generate_peer_intf_id(struct ppp_t *ppp) case INTF_ID_CSID: break; case INTF_ID_IPV4: - if (ppp->ipv4) { + if (ppp->ses.ipv4) { for (i = 0; i < 4; i++) { - sprintf(str, "%i", (ppp->ipv4->peer_addr >> (i*8)) & 0xff); + sprintf(str, "%i", (ppp->ses.ipv4->peer_addr >> (i*8)) & 0xff); sscanf(str, "%x", &n); u.addr16[i] = htons(n); } @@ -163,14 +163,14 @@ static uint64_t generate_peer_intf_id(struct ppp_t *ppp) static int alloc_ip(struct ppp_t *ppp) { - ppp->ipv6 = ipdb_get_ipv6(ppp); - if (!ppp->ipv6) { + ppp->ses.ipv6 = ipdb_get_ipv6(&ppp->ses); + if (!ppp->ses.ipv6) { log_ppp_warn("ppp: no free IPv6 address\n"); return IPV6CP_OPT_CLOSE; } - if (!ppp->ipv6->intf_id) - ppp->ipv6->intf_id = generate_intf_id(ppp); + if (!ppp->ses.ipv6->intf_id) + ppp->ses.ipv6->intf_id = generate_intf_id(ppp); if (conf_check_exists && check_exists(ppp)) return IPV6CP_OPT_FAIL; @@ -184,7 +184,7 @@ static int ipaddr_send_conf_req(struct ppp_ipv6cp_t *ipv6cp, struct ipv6cp_optio struct ipv6cp_opt64_t *opt64 = (struct ipv6cp_opt64_t *)ptr; int r; - if (!ipv6cp->ppp->ipv6) { + if (!ipv6cp->ppp->ses.ipv6) { r = alloc_ip(ipv6cp->ppp); if (r) return r; @@ -192,7 +192,7 @@ static int ipaddr_send_conf_req(struct ppp_ipv6cp_t *ipv6cp, struct ipv6cp_optio opt64->hdr.id = CI_INTFID; opt64->hdr.len = 10; - opt64->val = ipv6cp->ppp->ipv6->intf_id; + opt64->val = ipv6cp->ppp->ses.ipv6->intf_id; return 10; } @@ -202,7 +202,7 @@ static int ipaddr_send_conf_nak(struct ppp_ipv6cp_t *ipv6cp, struct ipv6cp_optio struct ipv6cp_opt64_t *opt64 = (struct ipv6cp_opt64_t *)ptr; opt64->hdr.id = CI_INTFID; opt64->hdr.len = 10; - opt64->val = ipv6cp->ppp->ipv6->peer_intf_id; + opt64->val = ipv6cp->ppp->ses.ipv6->peer_intf_id; return 10; } @@ -215,21 +215,21 @@ static int ipaddr_recv_conf_req(struct ppp_ipv6cp_t *ipv6cp, struct ipv6cp_optio if (opt64->hdr.len != 10) return IPV6CP_OPT_REJ; - if (!ipv6cp->ppp->ipv6) { + if (!ipv6cp->ppp->ses.ipv6) { r = alloc_ip(ipv6cp->ppp); if (r) return r; } if (conf_accept_peer_intf_id && opt64->val) - ipv6cp->ppp->ipv6->peer_intf_id = opt64->val; - else if (!ipv6cp->ppp->ipv6->peer_intf_id) { - ipv6cp->ppp->ipv6->peer_intf_id = generate_peer_intf_id(ipv6cp->ppp); - if (!ipv6cp->ppp->ipv6->peer_intf_id) + ipv6cp->ppp->ses.ipv6->peer_intf_id = opt64->val; + else if (!ipv6cp->ppp->ses.ipv6->peer_intf_id) { + ipv6cp->ppp->ses.ipv6->peer_intf_id = generate_peer_intf_id(ipv6cp->ppp); + if (!ipv6cp->ppp->ses.ipv6->peer_intf_id) return IPV6CP_OPT_TERMACK; } - if (opt64->val && ipv6cp->ppp->ipv6->peer_intf_id == opt64->val && opt64->val != ipv6cp->ppp->ipv6->intf_id) { + if (opt64->val && ipv6cp->ppp->ses.ipv6->peer_intf_id == opt64->val && opt64->val != ipv6cp->ppp->ses.ipv6->intf_id) { ipv6cp->delay_ack = ccp_ipcp_started(ipv6cp->ppp); ipaddr_opt->started = 1; return IPV6CP_OPT_ACK; @@ -247,7 +247,7 @@ static void ipaddr_print(void (*print)(const char *fmt,...), struct ipv6cp_optio if (ptr) *(uint64_t *)(a.s6_addr + 8) = opt64->val; else - *(uint64_t *)(a.s6_addr + 8) = ipaddr_opt->ppp->ipv6->intf_id; + *(uint64_t *)(a.s6_addr + 8) = ipaddr_opt->ppp->ses.ipv6->intf_id; print("<addr %x:%x:%x:%x>", ntohs(a.s6_addr16[4]), ntohs(a.s6_addr16[5]), ntohs(a.s6_addr16[6]), ntohs(a.s6_addr16[7])); } diff --git a/accel-pppd/ppp/lcp_opt_mru.c b/accel-pppd/ppp/lcp_opt_mru.c index 577e0191..10dc54e7 100644 --- a/accel-pppd/ppp/lcp_opt_mru.c +++ b/accel-pppd/ppp/lcp_opt_mru.c @@ -53,10 +53,10 @@ static struct lcp_option_t *mru_init(struct ppp_lcp_t *lcp) { struct mru_option_t *mru_opt=_malloc(sizeof(*mru_opt)); memset(mru_opt, 0, sizeof(*mru_opt)); - mru_opt->mru = (conf_mru && conf_mru <= lcp->ppp->ctrl->max_mtu) ? conf_mru : lcp->ppp->ctrl->max_mtu; + mru_opt->mru = (conf_mru && conf_mru <= lcp->ppp->ses.ctrl->max_mtu) ? conf_mru : lcp->ppp->ses.ctrl->max_mtu; if (mru_opt->mru > conf_max_mtu) mru_opt->mru = conf_max_mtu; - mru_opt->mtu = (conf_mtu && conf_mtu <= lcp->ppp->ctrl->max_mtu) ? conf_mtu : lcp->ppp->ctrl->max_mtu; + mru_opt->mtu = (conf_mtu && conf_mtu <= lcp->ppp->ses.ctrl->max_mtu) ? conf_mtu : lcp->ppp->ses.ctrl->max_mtu; if (mru_opt->mtu > conf_max_mtu) mru_opt->mtu = conf_max_mtu; mru_opt->opt.id = CI_MRU; @@ -107,7 +107,7 @@ static int mru_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, ui if (opt16->hdr.len != 4) return LCP_OPT_REJ; - if (ntohs(opt16->val) < conf_min_mtu || ntohs(opt16->val) > lcp->ppp->ctrl->max_mtu || ntohs(opt16->val) > conf_max_mtu) + if (ntohs(opt16->val) < conf_min_mtu || ntohs(opt16->val) > lcp->ppp->ses.ctrl->max_mtu || ntohs(opt16->val) > conf_max_mtu) return LCP_OPT_NAK; mru_opt->mtu = ntohs(opt16->val); @@ -121,7 +121,7 @@ static int mru_recv_conf_ack(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, ui .ifr_mtu = mru_opt->mtu, }; - strcpy(ifr.ifr_name, lcp->ppp->ifname); + strcpy(ifr.ifr_name, lcp->ppp->ses.ifname); if (ioctl(lcp->ppp->unit_fd, PPPIOCSMRU, &mru_opt->mru)) log_ppp_error("lcp:mru: failed to set MRU: %s\n", strerror(errno)); diff --git a/accel-pppd/ppp/ppp.c b/accel-pppd/ppp/ppp.c index 814240cd..9a006676 100644 --- a/accel-pppd/ppp/ppp.c +++ b/accel-pppd/ppp/ppp.c @@ -16,6 +16,7 @@ #include "triton.h" +#include "ap_session.h" #include "events.h" #include "ppp.h" #include "ppp_fsm.h" @@ -27,30 +28,13 @@ #include "memdebug.h" int __export conf_ppp_verbose; -int conf_sid_ucase; int conf_single_session = -1; int conf_unit_cache = 0; -pthread_rwlock_t __export ppp_lock = PTHREAD_RWLOCK_INITIALIZER; -__export LIST_HEAD(ppp_list); - -int __export sock_fd; -int __export sock6_fd; -int __export urandom_fd; - -int __export ppp_shutdown; - static mempool_t buf_pool; static LIST_HEAD(layers); -static unsigned long long seq; -#if __WORDSIZE == 32 -static spinlock_t seq_lock; -#endif - -__export struct ppp_stat_t ppp_stat; - struct layer_node_t { struct list_head entry; @@ -78,37 +62,19 @@ static void start_first_layer(struct ppp_t *); void __export ppp_init(struct ppp_t *ppp) { - memset(ppp,0,sizeof(*ppp)); + memset(ppp, 0, sizeof(*ppp)); INIT_LIST_HEAD(&ppp->layers); INIT_LIST_HEAD(&ppp->chan_handlers); INIT_LIST_HEAD(&ppp->unit_handlers); - INIT_LIST_HEAD(&ppp->pd_list); ppp->fd = -1; ppp->chan_fd = -1; ppp->unit_fd = -1; -} -static void generate_sessionid(struct ppp_t *ppp) -{ - unsigned long long sid; - -#if __WORDSIZE == 32 - spin_lock(&seq_lock); - sid = ++seq; - spin_unlock(&seq_lock); -#else - sid = __sync_add_and_fetch(&seq, 1); -#endif - - if (conf_sid_ucase) - sprintf(ppp->sessionid, "%016llX", sid); - else - sprintf(ppp->sessionid, "%016llx", sid); + ap_session_init(&ppp->ses); } int __export establish_ppp(struct ppp_t *ppp) { - struct ifreq ifr; struct pppunit_cache *uc = NULL; /* Open an instance of /dev/ppp and connect the channel to it */ @@ -142,7 +108,7 @@ int __export establish_ppp(struct ppp_t *ppp) if (uc) { ppp->unit_fd = uc->fd; - ppp->unit_idx = uc->unit_idx; + ppp->ses.unit_idx = uc->unit_idx; mempool_free(uc); } else { ppp->unit_fd = open("/dev/ppp", O_RDWR); @@ -153,8 +119,8 @@ int __export establish_ppp(struct ppp_t *ppp) fcntl(ppp->unit_fd, F_SETFD, fcntl(ppp->unit_fd, F_GETFD) | FD_CLOEXEC); - ppp->unit_idx = -1; - if (ioctl(ppp->unit_fd, PPPIOCNEWUNIT, &ppp->unit_idx) < 0) { + ppp->ses.unit_idx = -1; + if (ioctl(ppp->unit_fd, PPPIOCNEWUNIT, &ppp->ses.unit_idx) < 0) { log_ppp_error("ioctl(PPPIOCNEWUNIT): %s\n", strerror(errno)); goto exit_close_unit; } @@ -165,7 +131,7 @@ int __export establish_ppp(struct ppp_t *ppp) } } - if (ioctl(ppp->chan_fd, PPPIOCCONNECT, &ppp->unit_idx) < 0) { + if (ioctl(ppp->chan_fd, PPPIOCCONNECT, &ppp->ses.unit_idx) < 0) { log_ppp_error("ioctl(PPPIOCCONNECT): %s\n", strerror(errno)); goto exit_close_unit; } @@ -175,20 +141,9 @@ int __export establish_ppp(struct ppp_t *ppp) goto exit_close_unit; } - ppp->start_time = time(NULL); - generate_sessionid(ppp); - sprintf(ppp->ifname, "ppp%i", ppp->unit_idx); - - memset(&ifr, 0, sizeof(ifr)); - strcpy(ifr.ifr_name, ppp->ifname); - - if (ioctl(sock_fd, SIOCGIFINDEX, &ifr)) { - log_ppp_error("ppp: ioctl(SIOCGIFINDEX): %s\n", strerror(errno)); - goto exit_close_unit; - } - ppp->ifindex = ifr.ifr_ifindex; - - log_ppp_info1("connect: %s <--> %s(%s)\n", ppp->ifname, ppp->ctrl->name, ppp->chan_name); + sprintf(ppp->ses.ifname, "ppp%i", ppp->ses.unit_idx); + + log_ppp_info1("connect: %s <--> %s(%s)\n", ppp->ses.ifname, ppp->ses.ctrl->name, ppp->ses.chan_name); init_layers(ppp); @@ -203,22 +158,15 @@ int __export establish_ppp(struct ppp_t *ppp) ppp->chan_hnd.read = ppp_chan_read; ppp->unit_hnd.fd = ppp->unit_fd; ppp->unit_hnd.read = ppp_unit_read; - triton_md_register_handler(ppp->ctrl->ctx, &ppp->chan_hnd); - triton_md_register_handler(ppp->ctrl->ctx, &ppp->unit_hnd); + triton_md_register_handler(ppp->ses.ctrl->ctx, &ppp->chan_hnd); + triton_md_register_handler(ppp->ses.ctrl->ctx, &ppp->unit_hnd); triton_md_enable_handler(&ppp->chan_hnd, MD_MODE_READ); triton_md_enable_handler(&ppp->unit_hnd, MD_MODE_READ); - ppp->state = PPP_STATE_STARTING; - __sync_add_and_fetch(&ppp_stat.starting, 1); - - pthread_rwlock_wrlock(&ppp_lock); - list_add_tail(&ppp->entry, &ppp_list); - pthread_rwlock_unlock(&ppp_lock); - log_ppp_debug("ppp established\n"); - triton_event_fire(EV_PPP_STARTING, ppp); + ap_session_starting(&ppp->ses); start_first_layer(ppp); @@ -239,23 +187,7 @@ static void destablish_ppp(struct ppp_t *ppp) { struct pppunit_cache *uc; - triton_event_fire(EV_PPP_PRE_FINISHED, ppp); - - pthread_rwlock_wrlock(&ppp_lock); - list_del(&ppp->entry); - pthread_rwlock_unlock(&ppp_lock); - - switch (ppp->state) { - case PPP_STATE_ACTIVE: - __sync_sub_and_fetch(&ppp_stat.active, 1); - break; - case PPP_STATE_STARTING: - __sync_sub_and_fetch(&ppp_stat.starting, 1); - break; - case PPP_STATE_FINISHING: - __sync_sub_and_fetch(&ppp_stat.finishing, 1); - break; - } + triton_event_fire(EV_SES_PRE_FINISHED, ppp); triton_md_unregister_handler(&ppp->chan_hnd); triton_md_unregister_handler(&ppp->unit_hnd); @@ -263,7 +195,7 @@ static void destablish_ppp(struct ppp_t *ppp) if (uc_size < conf_unit_cache) { uc = mempool_alloc(uc_pool); uc->fd = ppp->unit_fd; - uc->unit_idx = ppp->unit_idx; + uc->unit_idx = ppp->ses.unit_idx; pthread_mutex_lock(&uc_lock); list_add_tail(&uc->entry, &uc_list); @@ -281,32 +213,11 @@ static void destablish_ppp(struct ppp_t *ppp) _free_layers(ppp); - ppp->terminated = 1; - log_ppp_debug("ppp destablished\n"); - triton_event_fire(EV_PPP_FINISHED, ppp); - ppp->ctrl->finished(ppp); - mempool_free(ppp->buf); - if (ppp->username) { - _free(ppp->username); - ppp->username = NULL; - } - - if (ppp->ipv4_pool_name) { - _free(ppp->ipv4_pool_name); - ppp->ipv4_pool_name = NULL; - } - - if (ppp->ipv6_pool_name) { - _free(ppp->ipv6_pool_name); - ppp->ipv6_pool_name = NULL; - } - - if (ppp_shutdown && !ppp_stat.starting && !ppp_stat.active && !ppp_stat.finishing) - kill(getpid(), SIGTERM); + ap_session_finished(&ppp->ses); } /*void print_buf(uint8_t *buf, int size) @@ -362,7 +273,7 @@ cont: //printf("ppp_chan_read: "); //print_buf(ppp->buf,ppp->buf_size); if (ppp->buf_size == 0) { - ppp_terminate(ppp, TERM_NAS_ERROR, 1); + ap_session_terminate(&ppp->ses, TERM_NAS_ERROR, 1); return 1; } @@ -376,7 +287,7 @@ cont: if (ppp_h->proto == proto) { ppp_h->recv(ppp_h); if (ppp->chan_fd == -1) { - //ppp->ctrl->finished(ppp); + //ppp->ses.ctrl->finished(ppp); return 1; } goto cont; @@ -410,7 +321,7 @@ cont: //print_buf(ppp->buf,ppp->buf_size); /*if (ppp->buf_size == 0) { - ppp_terminate(ppp, TERM_NAS_ERROR, 1); + ap_session_terminate(ppp, TERM_NAS_ERROR, 1); return 1; }*/ @@ -424,7 +335,7 @@ cont: if (ppp_h->proto == proto) { ppp_h->recv(ppp_h); if (ppp->unit_fd == -1) { - //ppp->ctrl->finished(ppp); + //ppp->ses.ctrl->finished(ppp); return 1; } goto cont; @@ -472,18 +383,15 @@ static void __ppp_layer_started(struct ppp_t *ppp, struct ppp_layer_data_t *d) if (n->entry.next == &ppp->layers) { - if (ppp->state == PPP_STATE_STARTING) { - ppp->state = PPP_STATE_ACTIVE; - __sync_sub_and_fetch(&ppp_stat.starting, 1); - __sync_add_and_fetch(&ppp_stat.active, 1); - ppp_ifup(ppp); + if (ppp->ses.state == AP_STATE_STARTING) { + ap_session_activate(&ppp->ses); } } else { n = list_entry(n->entry.next, typeof(*n), entry); list_for_each_entry(d, &n->items, entry) { d->starting = 1; if (d->layer->start(d)) { - ppp_terminate(ppp, TERM_NAS_ERROR, 0); + ap_session_terminate(&ppp->ses, TERM_NAS_ERROR, 0); return; } } @@ -527,41 +435,13 @@ void __export ppp_layer_finished(struct ppp_t *ppp, struct ppp_layer_data_t *d) destablish_ppp(ppp); } -void __export ppp_terminate(struct ppp_t *ppp, int cause, int hard) +void __export ppp_terminate(struct ap_session *ses, int hard) { + struct ppp_t *ppp = container_of(ses, typeof(*ppp), ses); struct layer_node_t *n; struct ppp_layer_data_t *d; int s = 0; - if (ppp->terminated) - return; - - if (!ppp->stop_time) - time(&ppp->stop_time); - - if (!ppp->terminate_cause) - ppp->terminate_cause = cause; - - if (ppp->terminating) { - if (hard) - destablish_ppp(ppp); - return; - } - - ppp->terminating = 1; - if (ppp->state == PPP_STATE_ACTIVE) - __sync_sub_and_fetch(&ppp_stat.active, 1); - else - __sync_sub_and_fetch(&ppp_stat.starting, 1); - __sync_add_and_fetch(&ppp_stat.finishing, 1); - ppp->state = PPP_STATE_FINISHING; - - log_ppp_debug("ppp_terminate\n"); - - ppp_ifdown(ppp); - - triton_event_fire(EV_PPP_FINISHING, ppp); - if (hard) { destablish_ppp(ppp); return; @@ -577,6 +457,7 @@ void __export ppp_terminate(struct ppp_t *ppp, int cause, int hard) } if (s) return; + destablish_ppp(ppp); } @@ -689,7 +570,7 @@ static void start_first_layer(struct ppp_t *ppp) list_for_each_entry(d, &n->items, entry) { d->starting = 1; if (d->layer->start(d)) { - ppp_terminate(ppp, TERM_NAS_ERROR, 0); + ap_session_terminate(&ppp->ses, TERM_NAS_ERROR, 0); return; } } @@ -710,44 +591,14 @@ struct ppp_layer_data_t *ppp_find_layer_data(struct ppp_t *ppp, struct ppp_layer return NULL; } -void ppp_shutdown_soft(void) -{ - ppp_shutdown = 1; - - if (!ppp_stat.starting && !ppp_stat.active && !ppp_stat.finishing) - kill(getpid(), SIGTERM); -} - -static void save_seq(void) -{ - FILE *f; - char *opt = conf_get_opt("ppp", "seq-file"); - if (!opt) - opt = "/var/run/accel-ppp/seq"; - - f = fopen(opt, "w"); - if (f) { - fprintf(f, "%llu", seq); - fclose(f); - } -} - static void load_config(void) { - char *opt; + const char *opt; opt = conf_get_opt("ppp", "verbose"); if (opt && atoi(opt) > 0) conf_ppp_verbose = 1; - opt = conf_get_opt("ppp", "sid-case"); - if (opt) { - if (!strcmp(opt, "upper")) - conf_sid_ucase = 1; - else if (strcmp(opt, "lower")) - log_emerg("ppp: sid-case: invalid format\n"); - } - opt = conf_get_opt("ppp", "single-session"); if (opt) { if (!strcmp(opt, "deny")) @@ -766,49 +617,11 @@ static void load_config(void) static void init(void) { - char *opt; - FILE *f; - buf_pool = mempool_create(PPP_MRU); uc_pool = mempool_create(sizeof(struct pppunit_cache)); - sock_fd = socket(AF_INET, SOCK_DGRAM, 0); - if (sock_fd < 0) { - perror("socket"); - _exit(EXIT_FAILURE); - } - - fcntl(sock_fd, F_SETFD, fcntl(sock_fd, F_GETFD) | FD_CLOEXEC); - - sock6_fd = socket(AF_INET6, SOCK_DGRAM, 0); - if (sock6_fd < 0) - log_warn("ppp: kernel doesn't support ipv6\n"); - else - fcntl(sock6_fd, F_SETFD, fcntl(sock6_fd, F_GETFD) | FD_CLOEXEC); - - urandom_fd = open("/dev/urandom", O_RDONLY); - if (urandom_fd < 0) { - log_emerg("failed to open /dev/urandom: %s\n", strerror(errno)); - return; - } - - fcntl(urandom_fd, F_SETFD, fcntl(urandom_fd, F_GETFD) | FD_CLOEXEC); - - opt = conf_get_opt("ppp", "seq-file"); - if (!opt) - opt = "/var/run/accel-ppp/seq"; - - f = fopen(opt, "r"); - if (f) { - fscanf(f, "%llu", &seq); - fclose(f); - } else - seq = (unsigned long long)random() * (unsigned long long)random(); - load_config(); triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); - - atexit(save_seq); } DEFINE_INIT(2, init); diff --git a/accel-pppd/ppp/ppp.h b/accel-pppd/ppp/ppp.h index e37c75d3..f5e0922a 100644 --- a/accel-pppd/ppp/ppp.h +++ b/accel-pppd/ppp/ppp.h @@ -8,6 +8,7 @@ #include "triton.h" #include "list.h" +#include "ap_session.h" /* * Packet header = Code, id, length. @@ -15,7 +16,6 @@ #define PPP_HEADERLEN 4 #define PPP_MTU 1500 - /* * Protocol field values. */ @@ -39,60 +39,15 @@ #define PPP_CBCP 0xc029 /* Callback Control Protocol */ #define PPP_EAP 0xc227 /* Extensible Authentication Protocol */ -#define PPP_SESSIONID_LEN 16 -#define PPP_IFNAME_LEN 10 - -#define PPP_STATE_STARTING 1 -#define PPP_STATE_ACTIVE 2 -#define PPP_STATE_FINISHING 3 - -#define TERM_USER_REQUEST 1 -#define TERM_SESSION_TIMEOUT 2 -#define TERM_ADMIN_RESET 3 -#define TERM_USER_ERROR 4 -#define TERM_NAS_ERROR 5 -#define TERM_NAS_REQUEST 6 -#define TERM_NAS_REBOOT 7 -#define TERM_AUTH_ERROR 8 -#define TERM_LOST_CARRIER 9 - -#define CTRL_TYPE_PPTP 1 -#define CTRL_TYPE_L2TP 2 -#define CTRL_TYPE_PPPOE 3 - -#define MPPE_UNSET -2 -#define MPPE_ALLOW -1 -#define MPPE_DENY 0 -#define MPPE_PREFER 1 -#define MPPE_REQUIRE 2 - struct ppp_t; struct ipv4db_item_t; struct ipv6db_item_t; -struct ppp_ctrl_t -{ - struct triton_context_t *ctx; - int type; - const char *name; - int max_mtu; - int mppe; - char *calling_station_id; - char *called_station_id; - void (*started)(struct ppp_t*); - void (*finished)(struct ppp_t*); -}; - -struct ppp_pd_t -{ - struct list_head entry; - void *key; -}; - struct ppp_t { - struct list_head entry; + struct ap_session ses; + struct triton_md_handler_t chan_hnd; struct triton_md_handler_t unit_hnd; int fd; @@ -100,27 +55,6 @@ struct ppp_t int unit_fd; int chan_idx; - int unit_idx; - - int state; - char *chan_name; - char ifname[PPP_IFNAME_LEN]; - int ifindex; - char sessionid[PPP_SESSIONID_LEN+1]; - time_t start_time; - time_t stop_time; - char *username; - struct ipv4db_item_t *ipv4; - struct ipv6db_item_t *ipv6; - char *ipv4_pool_name; - char *ipv6_pool_name; - const char *comp; - - struct ppp_ctrl_t *ctrl; - - int terminating:1; - int terminated:1; - int terminate_cause; void *buf; int buf_size; @@ -130,9 +64,8 @@ struct ppp_t struct list_head layers; + const char *comp; struct ppp_lcp_t *lcp; - - struct list_head pd_list; }; struct ppp_layer_t; @@ -166,13 +99,6 @@ struct ppp_handler_t void (*recv_proto_rej)(struct ppp_handler_t *h); }; -struct ppp_stat_t -{ - unsigned int active; - unsigned int starting; - unsigned int finishing; -}; - struct ppp_t *alloc_ppp(void); void ppp_init(struct ppp_t *ppp); int establish_ppp(struct ppp_t *ppp); @@ -189,7 +115,7 @@ void ppp_layer_started(struct ppp_t *ppp,struct ppp_layer_data_t*); void ppp_layer_finished(struct ppp_t *ppp,struct ppp_layer_data_t*); void ppp_layer_passive(struct ppp_t *ppp,struct ppp_layer_data_t*); -void ppp_terminate(struct ppp_t *ppp, int hard, int cause); +void ppp_terminate(struct ap_session *ses, int hard); void ppp_register_chan_handler(struct ppp_t *, struct ppp_handler_t *); void ppp_register_unit_handler(struct ppp_t * ,struct ppp_handler_t *); @@ -199,20 +125,9 @@ int ppp_register_layer(const char *name, struct ppp_layer_t *); void ppp_unregister_layer(struct ppp_layer_t *); struct ppp_layer_data_t *ppp_find_layer_data(struct ppp_t *, struct ppp_layer_t *); -extern int ppp_shutdown; -void ppp_shutdown_soft(void); - int ppp_ipv6_nd_start(struct ppp_t *ppp, uint64_t intf_id); extern int conf_ppp_verbose; extern int conf_single_session; -extern pthread_rwlock_t ppp_lock; -extern struct list_head ppp_list; - -extern struct ppp_stat_t ppp_stat; - -extern int sock_fd; // internet socket for ioctls -extern int sock6_fd; // internet socket for ioctls -extern int urandom_fd; #endif diff --git a/accel-pppd/ppp/ppp_auth.c b/accel-pppd/ppp/ppp_auth.c index 7603d8cf..805bf741 100644 --- a/accel-pppd/ppp/ppp_auth.c +++ b/accel-pppd/ppp/ppp_auth.c @@ -312,60 +312,60 @@ static void auth_layer_free(struct ppp_layer_data_t *ld) log_ppp_debug("auth_layer_free\n"); - triton_cancel_call(ad->ppp->ctrl->ctx, (triton_event_func)__ppp_auth_started); + triton_cancel_call(ad->ppp->ses.ctrl->ctx, (triton_event_func)__ppp_auth_started); _free(ad); } -static void ppp_terminate_sec(struct ppp_t *ppp) +static void __terminate_sec(struct ap_session *ses) { - ppp_terminate(ppp, TERM_NAS_REQUEST, 0); + ap_session_terminate(ses, TERM_NAS_REQUEST, 0); } static void __ppp_auth_started(struct ppp_t *ppp) { struct auth_layer_data_t *ad = container_of(ppp_find_layer_data(ppp, &auth_layer), typeof(*ad), ld); - if (ppp->terminating) + if (ppp->ses.terminating) return; log_ppp_debug("auth_layer_started\n"); ppp_layer_started(ppp, &ad->ld); - log_ppp_info1("%s: authentication successed\n", ppp->username); - triton_event_fire(EV_PPP_AUTHORIZED, ppp); + log_ppp_info1("%s: authentication successed\n", ppp->ses.username); + triton_event_fire(EV_SES_AUTHORIZED, ppp); } int __export ppp_auth_successed(struct ppp_t *ppp, char *username) { - struct ppp_t *p; + struct ap_session *ses; struct auth_layer_data_t *ad = container_of(ppp_find_layer_data(ppp, &auth_layer), typeof(*ad), ld); if (conf_single_session >= 0) { - pthread_rwlock_rdlock(&ppp_lock); - list_for_each_entry(p, &ppp_list, entry) { - if (p->username && !strcmp(p->username, username)) { + pthread_rwlock_rdlock(&ses_lock); + list_for_each_entry(ses, &ses_list, entry) { + if (ses->username && !strcmp(ses->username, username)) { if (conf_single_session == 0) { - pthread_rwlock_unlock(&ppp_lock); + pthread_rwlock_unlock(&ses_lock); log_ppp_info1("%s: second session denied\n", username); return -1; } else { if (conf_single_session == 1) { - ppp_ifdown(p); - triton_context_call(p->ctrl->ctx, (triton_event_func)ppp_terminate_sec, p); + ap_session_ifdown(ses); + triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_sec, ses); } } } } - pthread_rwlock_unlock(&ppp_lock); + pthread_rwlock_unlock(&ses_lock); } - pthread_rwlock_wrlock(&ppp_lock); - ppp->username = username; - pthread_rwlock_unlock(&ppp_lock); + pthread_rwlock_wrlock(&ses_lock); + ppp->ses.username = username; + pthread_rwlock_unlock(&ses_lock); - triton_context_call(ppp->ctrl->ctx, (triton_event_func)__ppp_auth_started, ppp); + triton_context_call(ppp->ses.ctrl->ctx, (triton_event_func)__ppp_auth_started, ppp); return 0; } @@ -373,16 +373,16 @@ int __export ppp_auth_successed(struct ppp_t *ppp, char *username) void __export ppp_auth_failed(struct ppp_t *ppp, char *username) { if (username) { - pthread_rwlock_wrlock(&ppp_lock); - if (!ppp->username) - ppp->username = _strdup(username); - pthread_rwlock_unlock(&ppp_lock); + pthread_rwlock_wrlock(&ses_lock); + if (!ppp->ses.username) + ppp->ses.username = _strdup(username); + pthread_rwlock_unlock(&ses_lock); log_ppp_info1("%s: authentication failed\n", username); log_info1("%s: authentication failed\n", username); - triton_event_fire(EV_PPP_AUTH_FAILED, ppp); + triton_event_fire(EV_SES_AUTH_FAILED, ppp); } else log_ppp_info1("authentication failed\n"); - ppp_terminate(ppp, TERM_AUTH_ERROR, 0); + ap_session_terminate(&ppp->ses, TERM_AUTH_ERROR, 0); } int __export ppp_auth_register_handler(struct ppp_auth_handler_t *h) diff --git a/accel-pppd/ppp/ppp_auth.h b/accel-pppd/ppp/ppp_auth.h index 6f86d260..b6a7b145 100644 --- a/accel-pppd/ppp/ppp_auth.h +++ b/accel-pppd/ppp/ppp_auth.h @@ -31,7 +31,7 @@ int ppp_auth_register_handler(struct ppp_auth_handler_t*); int ppp_auth_successed(struct ppp_t *ppp, char *username); void ppp_auth_failed(struct ppp_t *ppp, char *username); -int ppp_auth_restart(struct ppp_t *ppp); +int ppp_auth_restart(struct ppp_t *ppp); #endif diff --git a/accel-pppd/ppp/ppp_ccp.c b/accel-pppd/ppp/ppp_ccp.c index 297d9bc7..058e7b38 100644 --- a/accel-pppd/ppp/ppp_ccp.c +++ b/accel-pppd/ppp/ppp_ccp.c @@ -180,7 +180,10 @@ void ccp_layer_free(struct ppp_layer_data_t *ld) struct ppp_ccp_t *ccp = container_of(ld, typeof(*ccp), ld); log_ppp_debug("ccp_layer_free\n"); - + + if (ccp->ppp->unit_fd != -1) + ccp_set_flags(ccp->ppp->unit_fd, 0, 0); + ppp_unregister_handler(ccp->ppp, &ccp->hnd); ccp_options_free(ccp); ppp_fsm_free(&ccp->fsm); @@ -196,7 +199,7 @@ static void ccp_layer_up(struct ppp_fsm_t *fsm) log_ppp_debug("ccp_layer_started\n"); ccp->started = 1; if (ccp_set_flags(ccp->ppp->unit_fd, 1, 1)) { - ppp_terminate(ccp->ppp, TERM_NAS_ERROR, 0); + ap_session_terminate(&ccp->ppp->ses, TERM_NAS_ERROR, 0); return; } ppp_layer_started(ccp->ppp, &ccp->ld); @@ -211,8 +214,8 @@ static void ccp_layer_finished(struct ppp_fsm_t *fsm) if (!ccp->started) ppp_layer_passive(ccp->ppp, &ccp->ld); - else if (!ccp->ppp->terminating) - ppp_terminate(ccp->ppp, TERM_USER_ERROR, 0); + else if (!ccp->ppp->ses.terminating) + ap_session_terminate(&ccp->ppp->ses, TERM_USER_ERROR, 0); fsm->fsm_state = FSM_Closed; } @@ -631,10 +634,10 @@ static void ccp_recv(struct ppp_handler_t*h) struct ppp_ccp_t *ccp = container_of(h, typeof(*ccp), hnd); int r; - if (!ccp->starting || ccp->fsm.fsm_state == FSM_Closed || ccp->ppp->terminating || ccp->ppp->state == PPP_STATE_ACTIVE) { + if (!ccp->starting || ccp->fsm.fsm_state == FSM_Closed || ccp->ppp->ses.terminating || ccp->ppp->ses.state == AP_STATE_ACTIVE) { if (conf_ppp_verbose) log_ppp_warn("CCP: discarding packet\n"); - if (ccp->fsm.fsm_state == FSM_Closed || !conf_ccp || ccp->ppp->state == PPP_STATE_ACTIVE) + if (ccp->fsm.fsm_state == FSM_Closed || !conf_ccp || ccp->ppp->ses.state == AP_STATE_ACTIVE) lcp_send_proto_rej(ccp->ppp, PPP_CCP); return; } @@ -684,11 +687,11 @@ static void ccp_recv(struct ppp_handler_t*h) ccp_free_conf_req(ccp); if (r == CCP_OPT_FAIL) - ppp_terminate(ccp->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&ccp->ppp->ses, TERM_USER_ERROR, 0); break; case CONFACK: if (ccp_recv_conf_ack(ccp, (uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN)) - ppp_terminate(ccp->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&ccp->ppp->ses, TERM_USER_ERROR, 0); else ppp_fsm_recv_conf_ack(&ccp->fsm); break; @@ -698,7 +701,7 @@ static void ccp_recv(struct ppp_handler_t*h) break; case CONFREJ: if (ccp_recv_conf_rej(ccp, (uint8_t*)(hdr + 1),ntohs(hdr->len) - PPP_HDRLEN)) - ppp_terminate(ccp->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&ccp->ppp->ses, TERM_USER_ERROR, 0); else ppp_fsm_recv_conf_rej(&ccp->fsm); break; @@ -729,8 +732,8 @@ static void ccp_recv_proto_rej(struct ppp_handler_t *h) { struct ppp_ccp_t *ccp = container_of(h, typeof(*ccp), hnd); - if (!ccp->ld.passive) { - ppp_terminate(ccp->ppp, TERM_USER_ERROR, 0); + if (!ccp->ld.optional) { + ap_session_terminate(&ccp->ppp->ses, TERM_USER_ERROR, 0); return; } diff --git a/accel-pppd/ppp/ppp_fsm.c b/accel-pppd/ppp/ppp_fsm.c index 27021d18..babaf667 100644 --- a/accel-pppd/ppp/ppp_fsm.c +++ b/accel-pppd/ppp/ppp_fsm.c @@ -505,14 +505,14 @@ static void init_req_counter(struct ppp_fsm_t *layer,int timeout) layer->restart_counter = timeout; if (!layer->restart_timer.tpd) - triton_timer_add(layer->ppp->ctrl->ctx, &layer->restart_timer, 0); + triton_timer_add(layer->ppp->ses.ctrl->ctx, &layer->restart_timer, 0); } static void zero_req_counter(struct ppp_fsm_t *layer) { layer->restart_counter=0; if (!layer->restart_timer.tpd) - triton_timer_add(layer->ppp->ctrl->ctx, &layer->restart_timer, 0); + triton_timer_add(layer->ppp->ses.ctrl->ctx, &layer->restart_timer, 0); } static void restart_timer_func(struct triton_timer_t *t) diff --git a/accel-pppd/ppp/ppp_ifcfg.c b/accel-pppd/ppp/ppp_ifcfg.c index f916251d..bcad3f4b 100644 --- a/accel-pppd/ppp/ppp_ifcfg.c +++ b/accel-pppd/ppp/ppp_ifcfg.c @@ -59,52 +59,52 @@ void ppp_ifup(struct ppp_t *ppp) struct npioctl np; struct sockaddr_in addr; - triton_event_fire(EV_PPP_ACCT_START, ppp); + triton_event_fire(EV_SES_ACCT_START, ppp); if (ppp->stop_time) return; - triton_event_fire(EV_PPP_PRE_UP, ppp); + triton_event_fire(EV_SES_PRE_UP, ppp); if (ppp->stop_time) return; memset(&ifr, 0, sizeof(ifr)); strcpy(ifr.ifr_name, ppp->ifname); - if (ppp->ipv4) { + if (ppp->ses.ipv4) { memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; - addr.sin_addr.s_addr = ppp->ipv4->addr; + addr.sin_addr.s_addr = ppp->ses.ipv4->addr; memcpy(&ifr.ifr_addr,&addr,sizeof(addr)); if (ioctl(sock_fd, SIOCSIFADDR, &ifr)) log_ppp_error("ppp: failed to set IPv4 address: %s\n", strerror(errno)); - addr.sin_addr.s_addr = ppp->ipv4->peer_addr; + addr.sin_addr.s_addr = ppp->ses.ipv4->peer_addr; memcpy(&ifr.ifr_dstaddr,&addr,sizeof(addr)); if (ioctl(sock_fd, SIOCSIFDSTADDR, &ifr)) log_ppp_error("ppp: failed to set peer IPv4 address: %s\n", strerror(errno)); } - if (ppp->ipv6) { + if (ppp->ses.ipv6) { devconf(ppp, "accept_ra", "0"); devconf(ppp, "autoconf", "0"); devconf(ppp, "forwarding", "1"); memset(&ifr6, 0, sizeof(ifr6)); ifr6.ifr6_addr.s6_addr32[0] = htons(0xfe80); - *(uint64_t *)(ifr6.ifr6_addr.s6_addr + 8) = ppp->ipv6->intf_id; + *(uint64_t *)(ifr6.ifr6_addr.s6_addr + 8) = ppp->ses.ipv6->intf_id; ifr6.ifr6_prefixlen = 64; ifr6.ifr6_ifindex = ppp->ifindex; if (ioctl(sock6_fd, SIOCSIFADDR, &ifr6)) log_ppp_error("ppp: faild to set LL IPv6 address: %s\n", strerror(errno)); - list_for_each_entry(a, &ppp->ipv6->addr_list, entry) { + list_for_each_entry(a, &ppp->ses.ipv6->addr_list, entry) { if (a->prefix_len == 128) continue; - build_addr(a, ppp->ipv6->intf_id, &ifr6.ifr6_addr); + build_addr(a, ppp->ses.ipv6->intf_id, &ifr6.ifr6_addr); ifr6.ifr6_prefixlen = a->prefix_len; if (ioctl(sock6_fd, SIOCSIFADDR, &ifr6)) @@ -120,7 +120,7 @@ void ppp_ifup(struct ppp_t *ppp) if (ioctl(sock_fd, SIOCSIFFLAGS, &ifr)) log_ppp_error("ppp: failed to set interface flags: %s\n", strerror(errno)); - if (ppp->ipv4) { + if (ppp->ses.ipv4) { np.protocol = PPP_IP; np.mode = NPMODE_PASS; @@ -128,7 +128,7 @@ void ppp_ifup(struct ppp_t *ppp) log_ppp_error("ppp: failed to set NP (IPv4) mode: %s\n", strerror(errno)); } - if (ppp->ipv6) { + if (ppp->ses.ipv6) { np.protocol = PPP_IPV6; np.mode = NPMODE_PASS; @@ -136,9 +136,9 @@ void ppp_ifup(struct ppp_t *ppp) log_ppp_error("ppp: failed to set NP (IPv6) mode: %s\n", strerror(errno)); } - ppp->ctrl->started(ppp); + ppp->ses.ctrl->started(ppp); - triton_event_fire(EV_PPP_STARTED, ppp); + triton_event_fire(EV_SES_STARTED, ppp); } void __export ppp_ifdown(struct ppp_t *ppp) @@ -152,27 +152,27 @@ void __export ppp_ifdown(struct ppp_t *ppp) strcpy(ifr.ifr_name, ppp->ifname); ioctl(sock_fd, SIOCSIFFLAGS, &ifr); - if (ppp->ipv4) { + if (ppp->ses.ipv4) { memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; memcpy(&ifr.ifr_addr,&addr,sizeof(addr)); ioctl(sock_fd, SIOCSIFADDR, &ifr); } - if (ppp->ipv6) { + if (ppp->ses.ipv6) { memset(&ifr6, 0, sizeof(ifr6)); ifr6.ifr6_addr.s6_addr32[0] = htons(0xfe80); - *(uint64_t *)(ifr6.ifr6_addr.s6_addr + 8) = ppp->ipv6->intf_id; + *(uint64_t *)(ifr6.ifr6_addr.s6_addr + 8) = ppp->ses.ipv6->intf_id; ifr6.ifr6_prefixlen = 64; ifr6.ifr6_ifindex = ppp->ifindex; ioctl(sock6_fd, SIOCDIFADDR, &ifr6); - list_for_each_entry(a, &ppp->ipv6->addr_list, entry) { + list_for_each_entry(a, &ppp->ses.ipv6->addr_list, entry) { if (a->prefix_len == 128) continue; - build_addr(a, ppp->ipv6->intf_id, &ifr6.ifr6_addr); + build_addr(a, ppp->ses.ipv6->intf_id, &ifr6.ifr6_addr); ifr6.ifr6_prefixlen = a->prefix_len; ioctl(sock6_fd, SIOCDIFADDR, &ifr6); diff --git a/accel-pppd/ppp/ppp_ipcp.c b/accel-pppd/ppp/ppp_ipcp.c index 9ec92d49..c05e20b1 100644 --- a/accel-pppd/ppp/ppp_ipcp.c +++ b/accel-pppd/ppp/ppp_ipcp.c @@ -121,8 +121,8 @@ static void ipcp_start_timeout(struct triton_timer_t *t) triton_timer_del(t); - if (ipcp->ppp->state == PPP_STATE_STARTING) - ppp_terminate(ipcp->ppp, TERM_USER_ERROR, 0); + if (ipcp->ppp->ses.state == AP_STATE_STARTING) + ap_session_terminate(&ipcp->ppp->ses, TERM_USER_ERROR, 0); } int ipcp_layer_start(struct ppp_layer_data_t *ld) @@ -137,7 +137,7 @@ int ipcp_layer_start(struct ppp_layer_data_t *ld) if (ipcp->ld.passive) { ipcp->timeout.expire = ipcp_start_timeout; ipcp->timeout.expire_tv.tv_sec = START_TIMEOUT; - triton_timer_add(ipcp->ppp->ctrl->ctx, &ipcp->timeout, 0); + triton_timer_add(ipcp->ppp->ses.ctrl->ctx, &ipcp->timeout, 0); } else { ppp_fsm_lower_up(&ipcp->fsm); if (ppp_fsm_open(&ipcp->fsm)) @@ -202,17 +202,17 @@ static void ipcp_layer_finished(struct ppp_fsm_t *fsm) if (!ipcp->started) { if (conf_ipv4 == IPV4_REQUIRE) - ppp_terminate(ipcp->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&ipcp->ppp->ses, TERM_USER_ERROR, 0); else ppp_layer_passive(ipcp->ppp, &ipcp->ld); - } else if (!ipcp->ppp->terminating) - ppp_terminate(ipcp->ppp, TERM_USER_ERROR, 0); + } else if (!ipcp->ppp->ses.terminating) + ap_session_terminate(&ipcp->ppp->ses, TERM_USER_ERROR, 0); fsm->fsm_state = FSM_Closed; - if (ipcp->ppp->ipv4) { - ipdb_put_ipv4(ipcp->ppp, ipcp->ppp->ipv4); - ipcp->ppp->ipv4 = NULL; + if (ipcp->ppp->ses.ipv4) { + ipdb_put_ipv4(&ipcp->ppp->ses, ipcp->ppp->ses.ipv4); + ipcp->ppp->ses.ipv4 = NULL; } } @@ -446,12 +446,12 @@ static int ipcp_recv_conf_req(struct ppp_ipcp_t *ipcp, uint8_t *data, int size) } if (r == IPCP_OPT_CLOSE) { if (conf_ipv4 == IPV4_REQUIRE) - ppp_terminate(ipcp->ppp, TERM_NAS_ERROR, 0); + ap_session_terminate(&ipcp->ppp->ses, TERM_NAS_ERROR, 0); else lcp_send_proto_rej(ipcp->ppp, PPP_IPCP); return 0; } - if (ipcp->ppp->stop_time) + if (ipcp->ppp->ses.stop_time) return -1; lopt->state = r; ropt->state = r; @@ -660,10 +660,10 @@ static void ipcp_recv(struct ppp_handler_t*h) int r; int delay_ack = ipcp->delay_ack; - if (!ipcp->starting || ipcp->fsm.fsm_state == FSM_Closed || ipcp->ppp->terminating || conf_ipv4 == IPV4_DENY) { + if (!ipcp->starting || ipcp->fsm.fsm_state == FSM_Closed || ipcp->ppp->ses.terminating || conf_ipv4 == IPV4_DENY) { if (conf_ppp_verbose) log_ppp_warn("IPCP: discarding packet\n"); - if (ipcp->ppp->terminating) + if (ipcp->ppp->ses.terminating) return; if (ipcp->fsm.fsm_state == FSM_Closed || conf_ipv4 == IPV4_DENY) lcp_send_proto_rej(ipcp->ppp, PPP_IPCP); @@ -689,7 +689,7 @@ static void ipcp_recv(struct ppp_handler_t*h) switch(hdr->code) { case CONFREQ: r = ipcp_recv_conf_req(ipcp,(uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN); - if (ipcp->ppp->stop_time) { + if (ipcp->ppp->ses.stop_time) { ipcp_free_conf_req(ipcp); return; } @@ -721,11 +721,11 @@ static void ipcp_recv(struct ppp_handler_t*h) } ipcp_free_conf_req(ipcp); if (r == IPCP_OPT_FAIL) - ppp_terminate(ipcp->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&ipcp->ppp->ses, TERM_USER_ERROR, 0); break; case CONFACK: if (ipcp_recv_conf_ack(ipcp,(uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN)) - ppp_terminate(ipcp->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&ipcp->ppp->ses, TERM_USER_ERROR, 0); else ppp_fsm_recv_conf_ack(&ipcp->fsm); break; @@ -735,7 +735,7 @@ static void ipcp_recv(struct ppp_handler_t*h) break; case CONFREJ: if (ipcp_recv_conf_rej(ipcp, (uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN)) - ppp_terminate(ipcp->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&ipcp->ppp->ses, TERM_USER_ERROR, 0); else ppp_fsm_recv_conf_rej(&ipcp->fsm); break; @@ -743,13 +743,13 @@ static void ipcp_recv(struct ppp_handler_t*h) if (conf_ppp_verbose) log_ppp_info2("recv [IPCP TermReq id=%x]\n", hdr->id); ppp_fsm_recv_term_req(&ipcp->fsm); - ppp_terminate(ipcp->ppp, TERM_USER_REQUEST, 0); + ap_session_terminate(&ipcp->ppp->ses, TERM_USER_REQUEST, 0); break; case TERMACK: if (conf_ppp_verbose) log_ppp_info2("recv [IPCP TermAck id=%x]\n", hdr->id); //ppp_fsm_recv_term_ack(&ipcp->fsm); - //ppp_terminate(ipcp->ppp, 0); + //ap_session_terminate(&ipcp->ppp->ses, 0); break; case CODEREJ: if (conf_ppp_verbose) diff --git a/accel-pppd/ppp/ppp_ipv6cp.c b/accel-pppd/ppp/ppp_ipv6cp.c index 9e7bf784..ee666267 100644 --- a/accel-pppd/ppp/ppp_ipv6cp.c +++ b/accel-pppd/ppp/ppp_ipv6cp.c @@ -119,8 +119,8 @@ static void ipv6cp_start_timeout(struct triton_timer_t *t) triton_timer_del(t); - if (ipv6cp->ppp->state == PPP_STATE_STARTING) - ppp_terminate(ipv6cp->ppp, TERM_USER_ERROR, 0); + if (ipv6cp->ppp->ses.state == AP_STATE_STARTING) + ap_session_terminate(&ipv6cp->ppp->ses, TERM_USER_ERROR, 0); } int ipv6cp_layer_start(struct ppp_layer_data_t *ld) @@ -137,7 +137,7 @@ int ipv6cp_layer_start(struct ppp_layer_data_t *ld) if (ipv6cp->ld.passive) { ipv6cp->timeout.expire = ipv6cp_start_timeout; ipv6cp->timeout.expire_tv.tv_sec = START_TIMEOUT; - triton_timer_add(ipv6cp->ppp->ctrl->ctx, &ipv6cp->timeout, 0); + triton_timer_add(ipv6cp->ppp->ses.ctrl->ctx, &ipv6cp->timeout, 0); } else { ppp_fsm_lower_up(&ipv6cp->fsm); if (ppp_fsm_open(&ipv6cp->fsm)) @@ -202,17 +202,17 @@ static void ipv6cp_layer_finished(struct ppp_fsm_t *fsm) if (!ipv6cp->started) { if (conf_ipv6 == IPV6_REQUIRE) - ppp_terminate(ipv6cp->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&ipv6cp->ppp->ses, TERM_USER_ERROR, 0); else ppp_layer_passive(ipv6cp->ppp, &ipv6cp->ld); - } else if (!ipv6cp->ppp->terminating) - ppp_terminate(ipv6cp->ppp, TERM_USER_ERROR, 0); + } else if (!ipv6cp->ppp->ses.terminating) + ap_session_terminate(&ipv6cp->ppp->ses, TERM_USER_ERROR, 0); fsm->fsm_state = FSM_Closed; - if (ipv6cp->ppp->ipv6) { - ipdb_put_ipv6(ipv6cp->ppp, ipv6cp->ppp->ipv6); - ipv6cp->ppp->ipv6 = NULL; + if (ipv6cp->ppp->ses.ipv6) { + ipdb_put_ipv6(&ipv6cp->ppp->ses, ipv6cp->ppp->ses.ipv6); + ipv6cp->ppp->ses.ipv6 = NULL; } } @@ -446,12 +446,12 @@ static int ipv6cp_recv_conf_req(struct ppp_ipv6cp_t *ipv6cp, uint8_t *data, int } if (r == IPV6CP_OPT_CLOSE) { if (conf_ipv6 == IPV6_REQUIRE) - ppp_terminate(ipv6cp->ppp, TERM_NAS_ERROR, 0); + ap_session_terminate(&ipv6cp->ppp->ses, TERM_NAS_ERROR, 0); else lcp_send_proto_rej(ipv6cp->ppp, PPP_IPV6CP); return 0; } - if (ipv6cp->ppp->stop_time) + if (ipv6cp->ppp->ses.stop_time) return -1; lopt->state = r; ropt->state = r; @@ -660,10 +660,10 @@ static void ipv6cp_recv(struct ppp_handler_t*h) int r; int delay_ack = ipv6cp->delay_ack; - if (!ipv6cp->starting || ipv6cp->fsm.fsm_state == FSM_Closed || ipv6cp->ppp->terminating || conf_ipv6 == IPV6_DENY) { + if (!ipv6cp->starting || ipv6cp->fsm.fsm_state == FSM_Closed || ipv6cp->ppp->ses.terminating || conf_ipv6 == IPV6_DENY) { if (conf_ppp_verbose) log_ppp_warn("IPV6CP: discarding packet\n"); - if (ipv6cp->ppp->terminating) + if (ipv6cp->ppp->ses.terminating) return; if (ipv6cp->fsm.fsm_state == FSM_Closed || conf_ipv6 == IPV6_DENY) lcp_send_proto_rej(ipv6cp->ppp, PPP_IPV6CP); @@ -689,7 +689,7 @@ static void ipv6cp_recv(struct ppp_handler_t*h) switch(hdr->code) { case CONFREQ: r = ipv6cp_recv_conf_req(ipv6cp,(uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN); - if (ipv6cp->ppp->stop_time) { + if (ipv6cp->ppp->ses.stop_time) { ipv6cp_free_conf_req(ipv6cp); return; } @@ -721,11 +721,11 @@ static void ipv6cp_recv(struct ppp_handler_t*h) } ipv6cp_free_conf_req(ipv6cp); if (r == IPV6CP_OPT_FAIL) - ppp_terminate(ipv6cp->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&ipv6cp->ppp->ses, TERM_USER_ERROR, 0); break; case CONFACK: if (ipv6cp_recv_conf_ack(ipv6cp,(uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN)) - ppp_terminate(ipv6cp->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&ipv6cp->ppp->ses, TERM_USER_ERROR, 0); else ppp_fsm_recv_conf_ack(&ipv6cp->fsm); break; @@ -735,7 +735,7 @@ static void ipv6cp_recv(struct ppp_handler_t*h) break; case CONFREJ: if (ipv6cp_recv_conf_rej(ipv6cp, (uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN)) - ppp_terminate(ipv6cp->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&ipv6cp->ppp->ses, TERM_USER_ERROR, 0); else ppp_fsm_recv_conf_rej(&ipv6cp->fsm); break; @@ -743,13 +743,13 @@ static void ipv6cp_recv(struct ppp_handler_t*h) if (conf_ppp_verbose) log_ppp_info2("recv [IPV6CP TermReq id=%x]\n", hdr->id); ppp_fsm_recv_term_req(&ipv6cp->fsm); - ppp_terminate(ipv6cp->ppp, TERM_USER_REQUEST, 0); + ap_session_terminate(&ipv6cp->ppp->ses, TERM_USER_REQUEST, 0); break; case TERMACK: if (conf_ppp_verbose) log_ppp_info2("recv [IPV6CP TermAck id=%x]\n", hdr->id); //ppp_fsm_recv_term_ack(&ipv6cp->fsm); - //ppp_terminate(ipv6cp->ppp, 0); + //ap_session_terminate(&ipv6cp->ppp->ses, 0); break; case CODEREJ: if (conf_ppp_verbose) diff --git a/accel-pppd/ppp/ppp_lcp.c b/accel-pppd/ppp/ppp_lcp.c index 5813517a..b081e875 100644 --- a/accel-pppd/ppp/ppp_lcp.c +++ b/accel-pppd/ppp/ppp_lcp.c @@ -138,7 +138,7 @@ void lcp_layer_finish(struct ppp_layer_data_t *ld) stop_echo(lcp); ppp_fsm_close(&lcp->fsm); } else - triton_context_call(lcp->ppp->ctrl->ctx, (triton_event_func)_lcp_layer_finished, lcp); + triton_context_call(lcp->ppp->ses.ctrl->ctx, (triton_event_func)_lcp_layer_finished, lcp); } void lcp_layer_free(struct ppp_layer_data_t *ld) @@ -151,7 +151,7 @@ void lcp_layer_free(struct ppp_layer_data_t *ld) ppp_unregister_handler(lcp->ppp, &lcp->hnd); lcp_options_free(lcp); ppp_fsm_free(&lcp->fsm); - triton_cancel_call(lcp->ppp->ctrl->ctx, (triton_event_func)_lcp_layer_finished); + triton_cancel_call(lcp->ppp->ses.ctrl->ctx, (triton_event_func)_lcp_layer_finished); _free(lcp); } @@ -186,12 +186,12 @@ static void lcp_layer_finished(struct ppp_fsm_t *fsm) stop_echo(lcp); if (lcp->started) { lcp->started = 0; - if (lcp->ppp->terminating) + if (lcp->ppp->ses.terminating) ppp_layer_finished(lcp->ppp, &lcp->ld); else - ppp_terminate(lcp->ppp, TERM_NAS_ERROR, 0); + ap_session_terminate(&lcp->ppp->ses, TERM_NAS_ERROR, 0); } else - ppp_terminate(lcp->ppp, TERM_NAS_ERROR, 0); + ap_session_terminate(&lcp->ppp->ses, TERM_NAS_ERROR, 0); } static void print_ropt(struct recv_opt_t *ropt) @@ -587,7 +587,7 @@ static void lcp_update_echo_timer(struct ppp_lcp_t *lcp) if (lcp->echo_timer.tpd) triton_timer_mod(&lcp->echo_timer, 0); else - triton_timer_add(lcp->ppp->ctrl->ctx, &lcp->echo_timer, 0); + triton_timer_add(lcp->ppp->ses.ctrl->ctx, &lcp->echo_timer, 0); } } } @@ -607,7 +607,7 @@ static void lcp_recv_echo_repl(struct ppp_lcp_t *lcp, uint8_t *data, int size) if (magic == lcp->magic) { log_ppp_error("lcp: echo: loop-back detected\n"); - ppp_terminate(lcp->ppp, TERM_NAS_ERROR, 0); + ap_session_terminate(&lcp->ppp->ses, TERM_NAS_ERROR, 0); } } @@ -656,7 +656,7 @@ static void send_echo_request(struct triton_timer_t *t) if (lcp->echo_sent == 2) { memset(&ifreq, 0, sizeof(ifreq)); ifreq.stats_ptr = (void *)&ifreq.stats; - strcpy(ifreq.ifr__name, lcp->ppp->ifname); + strcpy(ifreq.ifr__name, lcp->ppp->ses.ifname); if (ioctl(sock_fd, SIOCGPPPSTATS, &ifreq) == 0) lcp->last_ipackets = ifreq.stats.p.ppp_ipackets; @@ -666,7 +666,7 @@ static void send_echo_request(struct triton_timer_t *t) time(&ts); memset(&ifreq, 0, sizeof(ifreq)); ifreq.stats_ptr = (void *)&ifreq.stats; - strcpy(ifreq.ifr__name, lcp->ppp->ifname); + strcpy(ifreq.ifr__name, lcp->ppp->ses.ifname); if (ioctl(sock_fd, SIOCGPPPSTATS, &ifreq) == 0 && lcp->last_ipackets != ifreq.stats.p.ppp_ipackets) { lcp->echo_sent = 1; lcp_update_echo_timer(lcp); @@ -682,7 +682,7 @@ static void send_echo_request(struct triton_timer_t *t) if (f) { log_ppp_warn("lcp: no echo reply\n"); - ppp_terminate(lcp->ppp, TERM_LOST_CARRIER, 1); + ap_session_terminate(&lcp->ppp->ses, TERM_LOST_CARRIER, 1); return; } @@ -697,7 +697,7 @@ static void start_echo(struct ppp_lcp_t *lcp) lcp->echo_timer.period = conf_echo_interval * 1000; lcp->echo_timer.expire = send_echo_request; if (lcp->echo_timer.period && !lcp->echo_timer.tpd) - triton_timer_add(lcp->ppp->ctrl->ctx, &lcp->echo_timer, 0); + triton_timer_add(lcp->ppp->ses.ctrl->ctx, &lcp->echo_timer, 0); } static void stop_echo(struct ppp_lcp_t *lcp) { @@ -782,7 +782,7 @@ static void lcp_recv(struct ppp_handler_t*h) if ((hdr->code == CONFACK || hdr->code == CONFNAK || hdr->code == CONFREJ) && lcp->started) return; - if (lcp->fsm.fsm_state == FSM_Initial || lcp->fsm.fsm_state == FSM_Closed || (lcp->ppp->terminating && (hdr->code != TERMACK && hdr->code != TERMREQ))) { + if (lcp->fsm.fsm_state == FSM_Initial || lcp->fsm.fsm_state == FSM_Closed || (lcp->ppp->ses.terminating && (hdr->code != TERMACK && hdr->code != TERMREQ))) { /*if (conf_ppp_verbose) log_ppp_warn("LCP: discaring packet\n"); lcp_send_proto_rej(ccp->ppp, htons(PPP_CCP));*/ @@ -813,11 +813,11 @@ static void lcp_recv(struct ppp_handler_t*h) } lcp_free_conf_req(lcp); if (r == LCP_OPT_FAIL) - ppp_terminate(lcp->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&lcp->ppp->ses, TERM_USER_ERROR, 0); break; case CONFACK: if (lcp_recv_conf_ack(lcp,(uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN)) - ppp_terminate(lcp->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&lcp->ppp->ses, TERM_USER_ERROR, 0); else if (lcp->fsm.recv_id != lcp->fsm.id) break; @@ -831,7 +831,7 @@ static void lcp_recv(struct ppp_handler_t*h) break; case CONFREJ: if (lcp_recv_conf_rej(lcp,(uint8_t*)(hdr + 1), ntohs(hdr->len) - PPP_HDRLEN)) - ppp_terminate(lcp->ppp, TERM_USER_ERROR, 0); + ap_session_terminate(&lcp->ppp->ses, TERM_USER_ERROR, 0); else if (lcp->fsm.recv_id != lcp->fsm.id) break; @@ -841,7 +841,7 @@ static void lcp_recv(struct ppp_handler_t*h) if (conf_ppp_verbose) log_ppp_info2("recv [LCP TermReq id=%x]\n", hdr->id); ppp_fsm_recv_term_req(&lcp->fsm); - ppp_terminate(lcp->ppp, TERM_USER_REQUEST, 0); + ap_session_terminate(&lcp->ppp->ses, TERM_USER_REQUEST, 0); break; case TERMACK: if (conf_ppp_verbose) diff --git a/accel-pppd/pwdb.c b/accel-pppd/pwdb.c index 4c0ab02e..f4440b8f 100644 --- a/accel-pppd/pwdb.c +++ b/accel-pppd/pwdb.c @@ -8,7 +8,7 @@ static LIST_HEAD(pwdb_handlers); -int __export pwdb_check(struct ppp_t *ppp, const char *username, int type, ...) +int __export pwdb_check(struct ap_session *ses, const char *username, int type, ...) { struct pwdb_t *pwdb; int r, res = PWDB_NO_IMPL; @@ -19,7 +19,7 @@ int __export pwdb_check(struct ppp_t *ppp, const char *username, int type, ...) list_for_each_entry(pwdb, &pwdb_handlers, entry) { if (!pwdb->check) continue; - r = pwdb->check(pwdb, ppp, username, type, args); + r = pwdb->check(pwdb, ses, username, type, args); if (r == PWDB_NO_IMPL) continue; if (r == PWDB_SUCCESS) @@ -29,7 +29,7 @@ int __export pwdb_check(struct ppp_t *ppp, const char *username, int type, ...) return res; } -__export char *pwdb_get_passwd(struct ppp_t *ppp, const char *username) +__export char *pwdb_get_passwd(struct ap_session *ses, const char *username) { struct pwdb_t *pwdb; char *r = NULL; @@ -37,7 +37,7 @@ __export char *pwdb_get_passwd(struct ppp_t *ppp, const char *username) list_for_each_entry(pwdb, &pwdb_handlers, entry) { if (!pwdb->get_passwd) continue; - r = pwdb->get_passwd(pwdb, ppp, username); + r = pwdb->get_passwd(pwdb, ses, username); if (r) break; } diff --git a/accel-pppd/pwdb.h b/accel-pppd/pwdb.h index a1c2cedb..8d8ab408 100644 --- a/accel-pppd/pwdb.h +++ b/accel-pppd/pwdb.h @@ -4,7 +4,7 @@ #include <stdarg.h> #include "list.h" -struct ppp_t; +struct ap_session; #define PWDB_SUCCESS 0 #define PWDB_DENIED 1 @@ -13,12 +13,12 @@ struct ppp_t; struct pwdb_t { struct list_head entry; - int (*check)(struct pwdb_t *, struct ppp_t *, const char *username, int type, va_list args); - char* (*get_passwd)(struct pwdb_t *, struct ppp_t *, const char *username); + int (*check)(struct pwdb_t *, struct ap_session *, const char *username, int type, va_list args); + char* (*get_passwd)(struct pwdb_t *, struct ap_session *, const char *username); }; -int pwdb_check(struct ppp_t *, const char *username, int type, ...); -char *pwdb_get_passwd(struct ppp_t *, const char *username); +int pwdb_check(struct ap_session *, const char *username, int type, ...); +char *pwdb_get_passwd(struct ap_session *, const char *username); void pwdb_register(struct pwdb_t *); void pwdb_unregister(struct pwdb_t *); diff --git a/accel-pppd/radius/acct.c b/accel-pppd/radius/acct.c index 76ad3299..dfc982d4 100644 --- a/accel-pppd/radius/acct.c +++ b/accel-pppd/radius/acct.c @@ -32,40 +32,42 @@ static int req_set_RA(struct rad_req_t *req, const char *secret) return 0; } -static void req_set_stat(struct rad_req_t *req, struct ppp_t *ppp) +static void req_set_stat(struct rad_req_t *req, struct ap_session *ses) { struct ifpppstatsreq ifreq; time_t stop_time; - if (ppp->stop_time) - stop_time = ppp->stop_time; + if (ses->stop_time) + stop_time = ses->stop_time; else time(&stop_time); memset(&ifreq, 0, sizeof(ifreq)); ifreq.stats_ptr = (void *)&ifreq.stats; - strcpy(ifreq.ifr__name, ppp->ifname); + strcpy(ifreq.ifr__name, ses->ifname); - if (ioctl(sock_fd, SIOCGPPPSTATS, &ifreq)) { - log_ppp_error("radius: failed to get ppp statistics: %s\n", strerror(errno)); - return; - } + if (ses->ctrl->type != CTRL_TYPE_IPOE) { + if (ioctl(sock_fd, SIOCGPPPSTATS, &ifreq)) { + log_ppp_error("radius: failed to get ppp statistics: %s\n", strerror(errno)); + return; + } - if (ifreq.stats.p.ppp_ibytes < req->rpd->acct_input_octets) - req->rpd->acct_input_gigawords++; - req->rpd->acct_input_octets = ifreq.stats.p.ppp_ibytes; - - if (ifreq.stats.p.ppp_obytes < req->rpd->acct_output_octets) - req->rpd->acct_output_gigawords++; - req->rpd->acct_output_octets = ifreq.stats.p.ppp_obytes; - - rad_packet_change_int(req->pack, NULL, "Acct-Input-Octets", ifreq.stats.p.ppp_ibytes); - rad_packet_change_int(req->pack, NULL, "Acct-Output-Octets", ifreq.stats.p.ppp_obytes); - rad_packet_change_int(req->pack, NULL, "Acct-Input-Packets", ifreq.stats.p.ppp_ipackets); - rad_packet_change_int(req->pack, NULL, "Acct-Output-Packets", ifreq.stats.p.ppp_opackets); - rad_packet_change_int(req->pack, NULL, "Acct-Input-Gigawords", req->rpd->acct_input_gigawords); - rad_packet_change_int(req->pack, NULL, "Acct-Output-Gigawords", req->rpd->acct_output_gigawords); - rad_packet_change_int(req->pack, NULL, "Acct-Session-Time", stop_time - ppp->start_time); + if (ifreq.stats.p.ppp_ibytes < req->rpd->acct_input_octets) + req->rpd->acct_input_gigawords++; + req->rpd->acct_input_octets = ifreq.stats.p.ppp_ibytes; + + if (ifreq.stats.p.ppp_obytes < req->rpd->acct_output_octets) + req->rpd->acct_output_gigawords++; + req->rpd->acct_output_octets = ifreq.stats.p.ppp_obytes; + + rad_packet_change_int(req->pack, NULL, "Acct-Input-Octets", ifreq.stats.p.ppp_ibytes); + rad_packet_change_int(req->pack, NULL, "Acct-Output-Octets", ifreq.stats.p.ppp_obytes); + rad_packet_change_int(req->pack, NULL, "Acct-Input-Packets", ifreq.stats.p.ppp_ipackets); + rad_packet_change_int(req->pack, NULL, "Acct-Output-Packets", ifreq.stats.p.ppp_opackets); + rad_packet_change_int(req->pack, NULL, "Acct-Input-Gigawords", req->rpd->acct_input_gigawords); + rad_packet_change_int(req->pack, NULL, "Acct-Output-Gigawords", req->rpd->acct_output_gigawords); + } + rad_packet_change_int(req->pack, NULL, "Acct-Session-Time", stop_time - ses->start_time); } static int rad_acct_read(struct triton_md_handler_t *h) @@ -125,7 +127,7 @@ static void __rad_req_send(struct rad_req_t *req) if (rad_server_realloc(req)) { if (conf_acct_timeout) { log_ppp_warn("radius:acct: no servers available, terminating session...\n"); - ppp_terminate(req->rpd->ppp, TERM_NAS_ERROR, 0); + ap_session_terminate(req->rpd->ses, TERM_NAS_ERROR, 0); } break; } @@ -134,7 +136,7 @@ static void __rad_req_send(struct rad_req_t *req) rad_req_send(req, conf_interim_verbose); if (!req->hnd.tpd) { - triton_md_register_handler(req->rpd->ppp->ctrl->ctx, &req->hnd); + triton_md_register_handler(req->rpd->ses->ctrl->ctx, &req->hnd); triton_md_enable_handler(&req->hnd, MD_MODE_READ); } @@ -167,7 +169,7 @@ static void rad_acct_timeout(struct triton_timer_t *t) rad_server_fail(req->serv); if (rad_server_realloc(req)) { log_ppp_warn("radius:acct: no servers available, terminating session...\n"); - ppp_terminate(req->rpd->ppp, TERM_NAS_ERROR, 0); + ap_session_terminate(req->rpd->ses, TERM_NAS_ERROR, 0); return; } time(&req->rpd->acct_timestamp); @@ -201,10 +203,10 @@ static void rad_acct_interim_update(struct triton_timer_t *t) return; if (rpd->session_timeout.expire_tv.tv_sec && - rpd->session_timeout.expire_tv.tv_sec - (time(NULL) - rpd->ppp->start_time) < INTERIM_SAFE_TIME) + rpd->session_timeout.expire_tv.tv_sec - (time(NULL) - rpd->ses->start_time) < INTERIM_SAFE_TIME) return; - req_set_stat(rpd->acct_req, rpd->ppp); + req_set_stat(rpd->acct_req, rpd->ses); if (!rpd->acct_interim_interval) return; @@ -221,7 +223,7 @@ static void rad_acct_interim_update(struct triton_timer_t *t) __sync_add_and_fetch(&rpd->acct_req->serv->stat_interim_sent, 1); rpd->acct_req->timeout.period = conf_timeout * 1000; - triton_timer_add(rpd->ppp->ctrl->ctx, &rpd->acct_req->timeout, 0); + triton_timer_add(rpd->ses->ctrl->ctx, &rpd->acct_req->timeout, 0); } int rad_acct_start(struct radius_pd_t *rpd) @@ -233,7 +235,7 @@ int rad_acct_start(struct radius_pd_t *rpd) if (!conf_accounting) return 0; - rpd->acct_req = rad_req_alloc(rpd, CODE_ACCOUNTING_REQUEST, rpd->ppp->username); + rpd->acct_req = rad_req_alloc(rpd, CODE_ACCOUNTING_REQUEST, rpd->ses->username); if (!rpd->acct_req) return -1; @@ -244,7 +246,7 @@ int rad_acct_start(struct radius_pd_t *rpd) //if (rad_req_add_val(rpd->acct_req, "Acct-Status-Type", "Start", 4)) // goto out_err; - //if (rad_req_add_str(rpd->acct_req, "Acct-Session-Id", rpd->ppp->sessionid, PPP_SESSIONID_LEN, 1)) + //if (rad_req_add_str(rpd->acct_req, "Acct-Session-Id", rpd->ses->ionid, PPP_SESSIONID_LEN, 1)) // goto out_err; if (rpd->acct_req->reply) { @@ -325,7 +327,7 @@ int rad_acct_start(struct radius_pd_t *rpd) rpd->acct_req->hnd.read = rad_acct_read; - triton_md_register_handler(rpd->ppp->ctrl->ctx, &rpd->acct_req->hnd); + triton_md_register_handler(rpd->ses->ctrl->ctx, &rpd->acct_req->hnd); if (triton_md_enable_handler(&rpd->acct_req->hnd, MD_MODE_READ)) goto out_err; @@ -334,7 +336,7 @@ int rad_acct_start(struct radius_pd_t *rpd) rpd->acct_interim_timer.expire = rad_acct_interim_update; rpd->acct_interim_timer.period = rpd->acct_interim_interval ? rpd->acct_interim_interval * 1000 : STAT_UPDATE_INTERVAL; - if (rpd->acct_interim_interval && triton_timer_add(rpd->ppp->ctrl->ctx, &rpd->acct_interim_timer, 0)) { + if (rpd->acct_interim_interval && triton_timer_add(rpd->ses->ctrl->ctx, &rpd->acct_interim_timer, 0)) { triton_md_unregister_handler(&rpd->acct_req->hnd); triton_timer_del(&rpd->acct_req->timeout); goto out_err; @@ -364,7 +366,7 @@ void rad_acct_stop(struct radius_pd_t *rpd) if (rpd->acct_req->timeout.tpd) triton_timer_del(&rpd->acct_req->timeout); - switch (rpd->ppp->terminate_cause) { + switch (rpd->ses->terminate_cause) { case TERM_USER_REQUEST: rad_packet_add_val(rpd->acct_req->pack, NULL, "Acct-Terminate-Cause", "User-Request"); break; @@ -392,7 +394,7 @@ void rad_acct_stop(struct radius_pd_t *rpd) break; } rad_packet_change_val(rpd->acct_req->pack, NULL, "Acct-Status-Type", "Stop"); - req_set_stat(rpd->acct_req, rpd->ppp); + req_set_stat(rpd->acct_req, rpd->ses); req_set_RA(rpd->acct_req, rpd->acct_req->serv->secret); /// !!! rad_req_add_val(rpd->acct_req, "Acct-Terminate-Cause", ""); diff --git a/accel-pppd/radius/auth.c b/accel-pppd/radius/auth.c index 3e5d281d..6a0b3a96 100644 --- a/accel-pppd/radius/auth.c +++ b/accel-pppd/radius/auth.c @@ -243,13 +243,13 @@ int rad_auth_pap(struct radius_pd_t *rpd, const char *username, va_list args) _free(epasswd); if (conf_sid_in_auth) - if (rad_packet_add_str(req->pack, NULL, "Acct-Session-Id", rpd->ppp->sessionid)) + if (rad_packet_add_str(req->pack, NULL, "Acct-Session-Id", rpd->ses->sessionid)) return -1; r = rad_auth_send(req); if (r == PWDB_SUCCESS) { struct ev_radius_t ev = { - .ppp = rpd->ppp, + .ses = rpd->ses, .request = req->pack, .reply = req->reply, }; @@ -311,13 +311,13 @@ int rad_auth_chap_md5(struct radius_pd_t *rpd, const char *username, va_list arg } if (conf_sid_in_auth) - if (rad_packet_add_str(rpd->auth_req->pack, NULL, "Acct-Session-Id", rpd->ppp->sessionid)) + if (rad_packet_add_str(rpd->auth_req->pack, NULL, "Acct-Session-Id", rpd->ses->sessionid)) goto out; r = rad_auth_send(rpd->auth_req); if (r == PWDB_SUCCESS) { struct ev_radius_t ev = { - .ppp = rpd->ppp, + .ses = rpd->ses, .request = rpd->auth_req->pack, .reply = rpd->auth_req->reply, }; @@ -339,9 +339,12 @@ static void setup_mppe(struct rad_req_t *req, const uint8_t *challenge) uint8_t mppe_recv_key[16]; uint8_t mppe_send_key[16]; struct ev_mppe_keys_t ev_mppe = { - .ppp = req->rpd->ppp, + .ppp = container_of(req->rpd->ses, typeof(struct ppp_t), ses), }; + if (req->rpd->ses->ctrl->type == CTRL_TYPE_IPOE) + return; + list_for_each_entry(attr, &req->reply->attrs, entry) { if (attr->vendor && attr->vendor->id == Vendor_Microsoft) { switch (attr->attr->id) { @@ -426,14 +429,14 @@ int rad_auth_mschap_v1(struct radius_pd_t *rpd, const char *username, va_list ar } if (conf_sid_in_auth) - if (rad_packet_add_str(rpd->auth_req->pack, NULL, "Acct-Session-Id", rpd->ppp->sessionid)) + if (rad_packet_add_str(rpd->auth_req->pack, NULL, "Acct-Session-Id", rpd->ses->sessionid)) goto out; r = rad_auth_send(rpd->auth_req); if (r == PWDB_SUCCESS) { struct ev_radius_t ev = { - .ppp = rpd->ppp, + .ses = rpd->ses, .request = rpd->auth_req->pack, .reply = rpd->auth_req->reply, }; @@ -508,7 +511,7 @@ int rad_auth_mschap_v2(struct radius_pd_t *rpd, const char *username, va_list ar } if (conf_sid_in_auth) - if (rad_packet_add_str(rpd->auth_req->pack, NULL, "Acct-Session-Id", rpd->ppp->sessionid)) + if (rad_packet_add_str(rpd->auth_req->pack, NULL, "Acct-Session-Id", rpd->ses->sessionid)) goto out; r = rad_auth_send(rpd->auth_req); @@ -522,7 +525,7 @@ int rad_auth_mschap_v2(struct radius_pd_t *rpd, const char *username, va_list ar } if (r == PWDB_SUCCESS) { struct ev_radius_t ev = { - .ppp = rpd->ppp, + .ses = rpd->ses, .request = rpd->auth_req->pack, .reply = rpd->auth_req->reply, }; diff --git a/accel-pppd/radius/dm_coa.c b/accel-pppd/radius/dm_coa.c index f6197e7c..a2757362 100644 --- a/accel-pppd/radius/dm_coa.c +++ b/accel-pppd/radius/dm_coa.c @@ -140,13 +140,13 @@ static void disconnect_request(struct radius_pd_t *rpd) rpd->dm_coa_req = NULL; pthread_mutex_unlock(&rpd->lock); - ppp_terminate(rpd->ppp, TERM_ADMIN_RESET, 0); + ap_session_terminate(rpd->ses, TERM_ADMIN_RESET, 0); } static void coa_request(struct radius_pd_t *rpd) { struct ev_radius_t ev = { - .ppp = rpd->ppp, + .ses = rpd->ses, .request = rpd->dm_coa_req, }; @@ -171,8 +171,8 @@ static void coa_request(struct radius_pd_t *rpd) void dm_coa_cancel(struct radius_pd_t *rpd) { - triton_cancel_call(rpd->ppp->ctrl->ctx, (triton_event_func)disconnect_request); - triton_cancel_call(rpd->ppp->ctrl->ctx, (triton_event_func)coa_request); + triton_cancel_call(rpd->ses->ctrl->ctx, (triton_event_func)disconnect_request); + triton_cancel_call(rpd->ses->ctrl->ctx, (triton_event_func)coa_request); rad_packet_free(rpd->dm_coa_req); } @@ -227,9 +227,9 @@ static int dm_coa_read(struct triton_md_handler_t *h) memcpy(&rpd->dm_coa_addr, &addr, sizeof(addr)); if (pack->code == CODE_DISCONNECT_REQUEST) - triton_context_call(rpd->ppp->ctrl->ctx, (triton_event_func)disconnect_request, rpd); + triton_context_call(rpd->ses->ctrl->ctx, (triton_event_func)disconnect_request, rpd); else - triton_context_call(rpd->ppp->ctrl->ctx, (triton_event_func)coa_request, rpd); + triton_context_call(rpd->ses->ctrl->ctx, (triton_event_func)coa_request, rpd); pthread_mutex_unlock(&rpd->lock); diff --git a/accel-pppd/radius/radius.c b/accel-pppd/radius/radius.c index 8f17fcc9..b654f29c 100644 --- a/accel-pppd/radius/radius.c +++ b/accel-pppd/radius/radius.c @@ -60,18 +60,18 @@ int rad_proc_attrs(struct rad_req_t *req) struct ev_dns_t dns; int res = 0; - dns.ppp = NULL; + dns.ses = NULL; req->rpd->acct_interim_interval = conf_acct_interim_interval; list_for_each_entry(attr, &req->reply->attrs, entry) { if (attr->vendor && attr->vendor->id == Vendor_Microsoft) { switch (attr->attr->id) { case MS_Primary_DNS_Server: - dns.ppp = req->rpd->ppp; + dns.ses = req->rpd->ses; dns.dns1 = attr->val.ipaddr; break; case MS_Secondary_DNS_Server: - dns.ppp = req->rpd->ppp; + dns.ses = req->rpd->ses; dns.dns2 = attr->val.ipaddr; break; } @@ -132,18 +132,18 @@ int rad_proc_attrs(struct rad_req_t *req) } } - if (dns.ppp) + if (dns.ses) triton_event_fire(EV_DNS, &dns); return res; } -static int check(struct pwdb_t *pwdb, struct ppp_t *ppp, const char *username, int type, va_list _args) +static int check(struct pwdb_t *pwdb, struct ap_session *ses, const char *username, int type, va_list _args) { int r = PWDB_NO_IMPL; va_list args; int chap_type; - struct radius_pd_t *rpd = find_pd(ppp); + struct radius_pd_t *rpd = find_pd(ses); va_copy(args, _args); @@ -175,18 +175,18 @@ static int check(struct pwdb_t *pwdb, struct ppp_t *ppp, const char *username, i return r; } -static struct ipv4db_item_t *get_ipv4(struct ppp_t *ppp) +static struct ipv4db_item_t *get_ipv4(struct ap_session *ses) { - struct radius_pd_t *rpd = find_pd(ppp); + struct radius_pd_t *rpd = find_pd(ses); if (rpd->ipv4_addr.peer_addr) return &rpd->ipv4_addr; return NULL; } -static struct ipv6db_item_t *get_ipv6(struct ppp_t *ppp) +static struct ipv6db_item_t *get_ipv6(struct ap_session *ses) { - struct radius_pd_t *rpd = find_pd(ppp); + struct radius_pd_t *rpd = find_pd(ses); rpd->ipv6_addr.owner = &ipdb; rpd->ipv6_addr.intf_id = 0; @@ -197,9 +197,9 @@ static struct ipv6db_item_t *get_ipv6(struct ppp_t *ppp) return NULL; } -static struct ipv6db_prefix_t *get_ipv6_prefix(struct ppp_t *ppp) +static struct ipv6db_prefix_t *get_ipv6_prefix(struct ap_session *ses) { - struct radius_pd_t *rpd = find_pd(ppp); + struct radius_pd_t *rpd = find_pd(ses); rpd->ipv6_dp.owner = &ipdb; @@ -214,66 +214,67 @@ static struct ipv6db_prefix_t *get_ipv6_prefix(struct ppp_t *ppp) static void session_timeout(struct triton_timer_t *t) { struct radius_pd_t *rpd = container_of(t, typeof(*rpd), session_timeout); + log_ppp_msg("radius: session timed out\n"); - if (rpd->ppp->stop_time) + if (rpd->ses->stop_time) return; - if (rpd->termination_action == Termination_Action_RADIUS_Request) { - if (ppp_auth_restart(rpd->ppp)) - ppp_terminate(rpd->ppp, TERM_SESSION_TIMEOUT, 0); + if (rpd->termination_action == Termination_Action_RADIUS_Request && rpd->ses->ctrl->type != CTRL_TYPE_IPOE) { + if (ppp_auth_restart(container_of(rpd->ses, struct ppp_t, ses))) + ap_session_terminate(rpd->ses, TERM_SESSION_TIMEOUT, 0); } else - ppp_terminate(rpd->ppp, TERM_SESSION_TIMEOUT, 0); + ap_session_terminate(rpd->ses, TERM_SESSION_TIMEOUT, 0); } -static void ppp_starting(struct ppp_t *ppp) +static void ses_starting(struct ap_session *ses) { struct radius_pd_t *rpd = mempool_alloc(rpd_pool); memset(rpd, 0, sizeof(*rpd)); rpd->pd.key = &pd_key; - rpd->ppp = ppp; + rpd->ses = ses; pthread_mutex_init(&rpd->lock, NULL); INIT_LIST_HEAD(&rpd->plugin_list); INIT_LIST_HEAD(&rpd->ipv6_addr.addr_list); INIT_LIST_HEAD(&rpd->ipv6_dp.prefix_list); - list_add_tail(&rpd->pd.entry, &ppp->pd_list); + list_add_tail(&rpd->pd.entry, &ses->pd_list); pthread_rwlock_wrlock(&sessions_lock); list_add_tail(&rpd->entry, &sessions); pthread_rwlock_unlock(&sessions_lock); } -static void ppp_acct_start(struct ppp_t *ppp) +static void ses_acct_start(struct ap_session *ses) { - struct radius_pd_t *rpd = find_pd(ppp); + struct radius_pd_t *rpd = find_pd(ses); if (!rpd->authenticated) return; if (rad_acct_start(rpd)) { - ppp_terminate(rpd->ppp, TERM_NAS_ERROR, 0); + ap_session_terminate(rpd->ses, TERM_NAS_ERROR, 0); return; } if (rpd->session_timeout.expire_tv.tv_sec) { rpd->session_timeout.expire = session_timeout; - triton_timer_add(ppp->ctrl->ctx, &rpd->session_timeout, 0); + triton_timer_add(ses->ctrl->ctx, &rpd->session_timeout, 0); } } -static void ppp_finishing(struct ppp_t *ppp) +static void ses_finishing(struct ap_session *ses) { - struct radius_pd_t *rpd = find_pd(ppp); + struct radius_pd_t *rpd = find_pd(ses); if (!rpd->authenticated) return; rad_acct_stop(rpd); } -static void ppp_finished(struct ppp_t *ppp) +static void ses_finished(struct ap_session *ses) { - struct radius_pd_t *rpd = find_pd(ppp); + struct radius_pd_t *rpd = find_pd(ses); struct ipv6db_addr_t *a; pthread_rwlock_wrlock(&sessions_lock); @@ -317,12 +318,12 @@ static void ppp_finished(struct ppp_t *ppp) mempool_free(rpd); } -struct radius_pd_t *find_pd(struct ppp_t *ppp) +struct radius_pd_t *find_pd(struct ap_session *ses) { - struct ppp_pd_t *pd; + struct ap_private *pd; struct radius_pd_t *rpd; - list_for_each_entry(pd, &ppp->pd_list, entry) { + list_for_each_entry(pd, &ses->pd_list, entry) { if (pd->key == &pd_key) { rpd = container_of(pd, typeof(*rpd), pd); return rpd; @@ -339,17 +340,17 @@ struct radius_pd_t *rad_find_session(const char *sessionid, const char *username pthread_rwlock_rdlock(&sessions_lock); list_for_each_entry(rpd, &sessions, entry) { - if (!rpd->ppp->username) + if (!rpd->ses->username) continue; - if (sessionid && strcmp(sessionid, rpd->ppp->sessionid)) + if (sessionid && strcmp(sessionid, rpd->ses->sessionid)) continue; - if (username && strcmp(username, rpd->ppp->username)) + if (username && strcmp(username, rpd->ses->username)) continue; - if (port_id >= 0 && port_id != rpd->ppp->unit_idx) + if (port_id >= 0 && port_id != rpd->ses->unit_idx) continue; - if (ipaddr && rpd->ppp->ipv4 && ipaddr != rpd->ppp->ipv4->peer_addr) + if (ipaddr && rpd->ses->ipv4 && ipaddr != rpd->ses->ipv4->peer_addr) continue; - if (csid && rpd->ppp->ctrl->calling_station_id && strcmp(csid, rpd->ppp->ctrl->calling_station_id)) + if (csid && rpd->ses->ctrl->calling_station_id && strcmp(csid, rpd->ses->ctrl->calling_station_id)) continue; pthread_mutex_lock(&rpd->lock); pthread_rwlock_unlock(&sessions_lock); @@ -422,9 +423,9 @@ int rad_check_nas_pack(struct rad_packet_t *pack) return 0; } -void __export rad_register_plugin(struct ppp_t *ppp, struct rad_plugin_t *plugin) +void __export rad_register_plugin(struct ap_session *ses, struct rad_plugin_t *plugin) { - struct radius_pd_t *rpd = find_pd(ppp); + struct radius_pd_t *rpd = find_pd(ses); if (!rpd) return; @@ -575,10 +576,10 @@ static void radius_init(void) pwdb_register(&pwdb); ipdb_register(&ipdb); - triton_event_register_handler(EV_PPP_STARTING, (triton_event_func)ppp_starting); - triton_event_register_handler(EV_PPP_ACCT_START, (triton_event_func)ppp_acct_start); - triton_event_register_handler(EV_PPP_FINISHING, (triton_event_func)ppp_finishing); - triton_event_register_handler(EV_PPP_FINISHED, (triton_event_func)ppp_finished); + triton_event_register_handler(EV_SES_STARTING, (triton_event_func)ses_starting); + triton_event_register_handler(EV_SES_ACCT_START, (triton_event_func)ses_acct_start); + triton_event_register_handler(EV_SES_FINISHING, (triton_event_func)ses_finishing); + triton_event_register_handler(EV_SES_FINISHED, (triton_event_func)ses_finished); triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); } diff --git a/accel-pppd/radius/radius.h b/accel-pppd/radius/radius.h index 296fd133..ad27b898 100644 --- a/accel-pppd/radius/radius.h +++ b/accel-pppd/radius/radius.h @@ -102,9 +102,9 @@ struct rad_plugin_t int (*send_accounting_request)(struct rad_plugin_t *, struct rad_packet_t *pack); }; -struct ppp_t; +struct ap_session; -void rad_register_plugin(struct ppp_t *, struct rad_plugin_t *); +void rad_register_plugin(struct ap_session *, struct rad_plugin_t *); struct rad_dict_attr_t *rad_dict_find_attr(const char *name); struct rad_dict_attr_t *rad_dict_find_attr_id(struct rad_dict_vendor_t *vendor, int type); diff --git a/accel-pppd/radius/radius_p.h b/accel-pppd/radius/radius_p.h index 7422bbf3..e2c48bf9 100644 --- a/accel-pppd/radius/radius_p.h +++ b/accel-pppd/radius/radius_p.h @@ -15,8 +15,8 @@ struct rad_server_t; struct radius_pd_t { struct list_head entry; - struct ppp_pd_t pd; - struct ppp_t *ppp; + struct ap_private pd; + struct ap_session *ses; pthread_mutex_t lock; int authenticated:1; @@ -147,7 +147,7 @@ void rad_req_free(struct rad_req_t *); int rad_req_send(struct rad_req_t *, int verbose); int rad_req_wait(struct rad_req_t *, int); -struct radius_pd_t *find_pd(struct ppp_t *ppp); +struct radius_pd_t *find_pd(struct ap_session *ses); int rad_proc_attrs(struct rad_req_t *req); int rad_auth_pap(struct radius_pd_t *rpd, const char *username, va_list args); diff --git a/accel-pppd/radius/req.c b/accel-pppd/radius/req.c index cc0b261a..33273b43 100644 --- a/accel-pppd/radius/req.c +++ b/accel-pppd/radius/req.c @@ -20,6 +20,7 @@ static void rad_req_timeout(struct triton_timer_t *t); struct rad_req_t *rad_req_alloc(struct radius_pd_t *rpd, int code, const char *username) { struct rad_plugin_t *plugin; + struct ppp_t *ppp = NULL; struct rad_req_t *req = _malloc(sizeof(*req)); if (!req) { @@ -27,6 +28,9 @@ struct rad_req_t *rad_req_alloc(struct radius_pd_t *rpd, int code, const char *u return NULL; } + if (rpd->ses->ctrl->type != CTRL_TYPE_IPOE) + ppp = container_of(rpd->ses, typeof(*ppp), ses); + memset(req, 0, sizeof(*req)); req->rpd = rpd; req->hnd.fd = -1; @@ -63,19 +67,21 @@ struct rad_req_t *rad_req_alloc(struct radius_pd_t *rpd, int code, const char *u if (conf_nas_ip_address) if (rad_packet_add_ipaddr(req->pack, NULL, "NAS-IP-Address", conf_nas_ip_address)) goto out_err; - if (rad_packet_add_int(req->pack, NULL, "NAS-Port", rpd->ppp->unit_idx)) - goto out_err; + if (ppp) { + if (rad_packet_add_int(req->pack, NULL, "NAS-Port", ppp->ses.unit_idx)) + goto out_err; + } if (rad_packet_add_val(req->pack, NULL, "NAS-Port-Type", "Virtual")) goto out_err; if (rad_packet_add_val(req->pack, NULL, "Service-Type", "Framed-User")) goto out_err; if (rad_packet_add_val(req->pack, NULL, "Framed-Protocol", "PPP")) goto out_err; - if (rpd->ppp->ctrl->calling_station_id) - if (rad_packet_add_str(req->pack, NULL, "Calling-Station-Id", rpd->ppp->ctrl->calling_station_id)) + if (rpd->ses->ctrl->calling_station_id) + if (rad_packet_add_str(req->pack, NULL, "Calling-Station-Id", rpd->ses->ctrl->calling_station_id)) goto out_err; - if (rpd->ppp->ctrl->called_station_id) - if (rad_packet_add_str(req->pack, NULL, "Called-Station-Id", rpd->ppp->ctrl->called_station_id)) + if (rpd->ses->ctrl->called_station_id) + if (rad_packet_add_str(req->pack, NULL, "Called-Station-Id", rpd->ses->ctrl->called_station_id)) goto out_err; if (rpd->attr_class) if (rad_packet_add_octets(req->pack, NULL, "Class", rpd->attr_class, rpd->attr_class_len)) @@ -117,7 +123,7 @@ int rad_req_acct_fill(struct rad_req_t *req) return -1; if (rad_packet_add_val(req->pack, NULL, "Acct-Authentic", "RADIUS")) return -1; - if (rad_packet_add_str(req->pack, NULL, "Acct-Session-Id", req->rpd->ppp->sessionid)) + if (rad_packet_add_str(req->pack, NULL, "Acct-Session-Id", req->rpd->ses->sessionid)) return -1; if (rad_packet_add_int(req->pack, NULL, "Acct-Session-Time", 0)) return -1; @@ -137,14 +143,14 @@ int rad_req_acct_fill(struct rad_req_t *req) if (rad_packet_add_int(req->pack, NULL, "Acct-Delay-Time", 0)) return -1; } - if (req->rpd->ppp->ipv4) { - if (rad_packet_add_ipaddr(req->pack, NULL, "Framed-IP-Address", req->rpd->ppp->ipv4->peer_addr)) + if (req->rpd->ses->ipv4) { + if (rad_packet_add_ipaddr(req->pack, NULL, "Framed-IP-Address", req->rpd->ses->ipv4->peer_addr)) return -1; } - if (req->rpd->ppp->ipv6) { - if (rad_packet_add_ifid(req->pack, NULL, "Framed-Interface-Id", req->rpd->ppp->ipv6->peer_intf_id)) + if (req->rpd->ses->ipv6) { + if (rad_packet_add_ifid(req->pack, NULL, "Framed-Interface-Id", req->rpd->ses->ipv6->peer_intf_id)) return -1; - list_for_each_entry(a, &req->rpd->ppp->ipv6->addr_list, entry) { + list_for_each_entry(a, &req->rpd->ses->ipv6->addr_list, entry) { if (rad_packet_add_ipv6prefix(req->pack, NULL, "Framed-IPv6-Prefix", &a->addr, a->prefix_len)) return -1; } @@ -235,7 +241,7 @@ out_err: static void req_wakeup(struct rad_req_t *req) { - struct triton_context_t *ctx = req->rpd->ppp->ctrl->ctx; + struct triton_context_t *ctx = req->rpd->ses->ctrl->ctx; if (req->timeout.tpd) triton_timer_del(&req->timeout); triton_md_unregister_handler(&req->hnd); @@ -277,7 +283,7 @@ int rad_req_wait(struct rad_req_t *req, int timeout) req->hnd.read = rad_req_read; req->timeout.expire = rad_req_timeout; - triton_context_register(&req->ctx, req->rpd->ppp); + triton_context_register(&req->ctx, req->rpd->ses); triton_context_set_priority(&req->ctx, 1); triton_md_register_handler(&req->ctx, &req->hnd); triton_md_enable_handler(&req->hnd, MD_MODE_READ); diff --git a/accel-pppd/radius/serv.c b/accel-pppd/radius/serv.c index 30219f75..4de6ad1e 100644 --- a/accel-pppd/radius/serv.c +++ b/accel-pppd/radius/serv.c @@ -132,7 +132,7 @@ void rad_server_req_exit(struct rad_req_t *req) pthread_mutex_unlock(&req->serv->lock); if (r) - triton_context_wakeup(r->rpd->ppp->ctrl->ctx); + triton_context_wakeup(r->rpd->ses->ctrl->ctx); } int rad_server_realloc(struct rad_req_t *req) @@ -182,7 +182,7 @@ void rad_server_fail(struct rad_server_t *s) while (!list_empty(&s->req_queue)) { r = list_entry(s->req_queue.next, typeof(*r), entry); list_del(&r->entry); - triton_context_wakeup(r->rpd->ppp->ctrl->ctx); + triton_context_wakeup(r->rpd->ses->ctrl->ctx); } } @@ -559,7 +559,7 @@ static void load_config(void) while (!list_empty(&s->req_queue)) { r = list_entry(s->req_queue.next, typeof(*r), entry); list_del(&r->entry); - triton_context_wakeup(r->rpd->ppp->ctrl->ctx); + triton_context_wakeup(r->rpd->ses->ctrl->ctx); } if (!s->client_cnt[0] && !s->client_cnt[1]) diff --git a/accel-pppd/session.c b/accel-pppd/session.c new file mode 100644 index 00000000..0064f54f --- /dev/null +++ b/accel-pppd/session.c @@ -0,0 +1,256 @@ +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> +#include <errno.h> +#include <signal.h> +#include <fcntl.h> +#include <pthread.h> +#include <arpa/inet.h> +#include <features.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <linux/if.h> + +#include "triton.h" +#include "log.h" +#include "events.h" +#include "ap_session.h" +#include "mempool.h" +#include "memdebug.h" + +int conf_sid_ucase; +pthread_rwlock_t __export ses_lock = PTHREAD_RWLOCK_INITIALIZER; +__export LIST_HEAD(ses_list); + +int __export sock_fd; +int __export sock6_fd; +int __export urandom_fd; +int __export ap_shutdown; + +static long long unsigned seq; + +struct ap_session_stat __export ap_session_stat; + +static void generate_sessionid(struct ap_session *ses); + +void __export ap_session_init(struct ap_session *ses) +{ + memset(ses, 0, sizeof(*ses)); + INIT_LIST_HEAD(&ses->pd_list); +} + +int __export ap_session_starting(struct ap_session *ses) +{ + struct ifreq ifr; + + ses->start_time = time(NULL); + + memset(&ifr, 0, sizeof(ifr)); + strcpy(ifr.ifr_name, ses->ifname); + + if (ioctl(sock_fd, SIOCGIFINDEX, &ifr)) { + log_ppp_error("ioctl(SIOCGIFINDEX): %s\n", strerror(errno)); + return -1; + } + ses->ifindex = ifr.ifr_ifindex; + + generate_sessionid(ses); + + ses->state = AP_STATE_STARTING; + __sync_add_and_fetch(&ap_session_stat.starting, 1); + + pthread_rwlock_wrlock(&ses_lock); + list_add_tail(&ses->entry, &ses_list); + pthread_rwlock_unlock(&ses_lock); + + triton_event_fire(EV_SES_STARTING, ses); + + return 0; +} + +void __export ap_session_activate(struct ap_session *ses) +{ + ses->state = AP_STATE_ACTIVE; + __sync_sub_and_fetch(&ap_session_stat.starting, 1); + __sync_add_and_fetch(&ap_session_stat.active, 1); + ap_session_ifup(ses); +} + +void __export ap_session_finished(struct ap_session *ses) +{ + ses->terminated = 1; + + pthread_rwlock_wrlock(&ses_lock); + list_del(&ses->entry); + pthread_rwlock_unlock(&ses_lock); + + switch (ses->state) { + case AP_STATE_ACTIVE: + __sync_sub_and_fetch(&ap_session_stat.active, 1); + break; + case AP_STATE_STARTING: + __sync_sub_and_fetch(&ap_session_stat.starting, 1); + break; + case AP_STATE_FINISHING: + __sync_sub_and_fetch(&ap_session_stat.finishing, 1); + break; + } + + triton_event_fire(EV_SES_FINISHED, ses); + ses->ctrl->finished(ses); + + if (ses->username) { + _free(ses->username); + ses->username = NULL; + } + + if (ses->ipv4_pool_name) { + _free(ses->ipv4_pool_name); + ses->ipv4_pool_name = NULL; + } + + if (ses->ipv6_pool_name) { + _free(ses->ipv6_pool_name); + ses->ipv6_pool_name = NULL; + } + + if (ap_shutdown && !ap_session_stat.starting && !ap_session_stat.active && !ap_session_stat.finishing) + kill(getpid(), SIGTERM); +} + +void __export ap_session_terminate(struct ap_session *ses, int cause, int hard) +{ + if (ses->terminated) + return; + + if (!ses->stop_time) + time(&ses->stop_time); + + if (!ses->terminate_cause) + ses->terminate_cause = cause; + + if (ses->terminating) { + if (hard) + ses->ctrl->terminate(ses, hard); + return; + } + + ses->terminating = 1; + ses->state = AP_STATE_FINISHING; + + if (ses->state == AP_STATE_ACTIVE) + __sync_sub_and_fetch(&ap_session_stat.active, 1); + else + __sync_sub_and_fetch(&ap_session_stat.starting, 1); + __sync_add_and_fetch(&ap_session_stat.finishing, 1); + + log_ppp_debug("terminate\n"); + + ap_session_ifdown(ses); + + triton_event_fire(EV_SES_FINISHING, ses); + + ses->ctrl->terminate(ses, hard); +} + +void ap_shutdown_soft(void) +{ + ap_shutdown = 1; + + if (!ap_session_stat.starting && !ap_session_stat.active && !ap_session_stat.finishing) + kill(getpid(), SIGTERM); +} + +static void generate_sessionid(struct ap_session *ses) +{ + unsigned long long sid; + +#if __WORDSIZE == 32 + spin_lock(&seq_lock); + sid = ++seq; + spin_unlock(&seq_lock); +#else + sid = __sync_add_and_fetch(&seq, 1); +#endif + + if (conf_sid_ucase) + sprintf(ses->sessionid, "%016llX", sid); + else + sprintf(ses->sessionid, "%016llx", sid); +} + +static void save_seq(void) +{ + FILE *f; + char *opt = conf_get_opt("ppp", "seq-file"); + if (!opt) + opt = "/var/run/accel-ppp/seq"; + + f = fopen(opt, "w"); + if (f) { + fprintf(f, "%llu", seq); + fclose(f); + } +} + +static void load_config(void) +{ + char *opt; + + opt = conf_get_opt("common", "sid-case"); + if (opt) { + if (!strcmp(opt, "upper")) + conf_sid_ucase = 1; + else if (strcmp(opt, "lower")) + log_emerg("sid-case: invalid format\n"); + } +} + +static void init(void) +{ + const char *opt; + FILE *f; + + sock_fd = socket(AF_INET, SOCK_DGRAM, 0); + if (sock_fd < 0) { + perror("socket"); + _exit(EXIT_FAILURE); + } + + fcntl(sock_fd, F_SETFD, fcntl(sock_fd, F_GETFD) | FD_CLOEXEC); + + sock6_fd = socket(AF_INET6, SOCK_DGRAM, 0); + if (sock6_fd < 0) + log_warn("ppp: kernel doesn't support ipv6\n"); + else + fcntl(sock6_fd, F_SETFD, fcntl(sock6_fd, F_GETFD) | FD_CLOEXEC); + + urandom_fd = open("/dev/urandom", O_RDONLY); + if (urandom_fd < 0) { + log_emerg("failed to open /dev/urandom: %s\n", strerror(errno)); + return; + } + + fcntl(urandom_fd, F_SETFD, fcntl(urandom_fd, F_GETFD) | FD_CLOEXEC); + + opt = conf_get_opt("session", "seq-file"); + if (!opt) + opt = "/var/run/accel-ppp/seq"; + + f = fopen(opt, "r"); + if (f) { + fscanf(f, "%llu", &seq); + fclose(f); + } else + seq = (unsigned long long)random() * (unsigned long long)random(); + + load_config(); + triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); + + atexit(save_seq); +} + +DEFINE_INIT(2, init); + diff --git a/accel-pppd/shaper/limiter.c b/accel-pppd/shaper/limiter.c index 5a3142bd..15eef19a 100644 --- a/accel-pppd/shaper/limiter.c +++ b/accel-pppd/shaper/limiter.c @@ -413,7 +413,7 @@ static int remove_htb_ifb(struct rtnl_handle *rth, int ifindex, int priority) return tc_qdisc_modify(rth, conf_ifb_ifindex, RTM_DELTCLASS, 0, &opt); } -int install_limiter(struct ppp_t *ppp, int down_speed, int down_burst, int up_speed, int up_burst) +int install_limiter(struct ap_session *ses, int down_speed, int down_burst, int up_speed, int up_burst) { struct rtnl_handle rth; int r; @@ -429,19 +429,19 @@ int install_limiter(struct ppp_t *ppp, int down_speed, int down_burst, int up_sp up_burst = up_burst ? up_burst : conf_up_burst_factor * up_speed; if (conf_down_limiter == LIM_TBF) - r = install_tbf(&rth, ppp->ifindex, down_speed, down_burst); + r = install_tbf(&rth, ses->ifindex, down_speed, down_burst); else { - r = install_htb(&rth, ppp->ifindex, down_speed, down_burst); + r = install_htb(&rth, ses->ifindex, down_speed, down_burst); if (r == 0) - r = install_leaf_qdisc(&rth, ppp->ifindex, 0x00010001, 0x00020000); + r = install_leaf_qdisc(&rth, ses->ifindex, 0x00010001, 0x00020000); } if (conf_up_limiter == LIM_POLICE) - r = install_police(&rth, ppp->ifindex, up_speed, up_burst); + r = install_police(&rth, ses->ifindex, up_speed, up_burst); else { - r = install_htb_ifb(&rth, ppp->ifindex, ppp->unit_idx + 1, up_speed, up_burst); + r = install_htb_ifb(&rth, ses->ifindex, ses->unit_idx + 1, up_speed, up_burst); if (r == 0) - r = install_leaf_qdisc(&rth, conf_ifb_ifindex, 0x00010001 + ppp->unit_idx + 1, (1 + ppp->unit_idx + 1) << 16); + r = install_leaf_qdisc(&rth, conf_ifb_ifindex, 0x00010001 + ses->unit_idx + 1, (1 + ses->unit_idx + 1) << 16); } rtnl_close(&rth); @@ -449,7 +449,7 @@ int install_limiter(struct ppp_t *ppp, int down_speed, int down_burst, int up_sp return r; } -int remove_limiter(struct ppp_t *ppp) +int remove_limiter(struct ap_session *ses) { struct rtnl_handle rth; @@ -458,11 +458,11 @@ int remove_limiter(struct ppp_t *ppp) return -1; } - remove_root(&rth, ppp->ifindex); - remove_ingress(&rth, ppp->ifindex); + remove_root(&rth, ses->ifindex); + remove_ingress(&rth, ses->ifindex); if (conf_up_limiter == LIM_HTB) - remove_htb_ifb(&rth, ppp->ifindex, ppp->unit_idx + 1); + remove_htb_ifb(&rth, ses->ifindex, ses->unit_idx + 1); return 0; } diff --git a/accel-pppd/shaper/shaper.c b/accel-pppd/shaper/shaper.c index 8ae2630a..2b749c9b 100644 --- a/accel-pppd/shaper/shaper.c +++ b/accel-pppd/shaper/shaper.c @@ -59,8 +59,8 @@ struct time_range_pd_t; struct shaper_pd_t { struct list_head entry; - struct ppp_t *ppp; - struct ppp_pd_t pd; + struct ap_session *ses; + struct ap_private pd; int temp_down_speed; int temp_up_speed; int down_speed; @@ -98,12 +98,12 @@ static struct triton_context_t shaper_ctx = { .before_switch = log_switch, }; -static struct shaper_pd_t *find_pd(struct ppp_t *ppp, int create) +static struct shaper_pd_t *find_pd(struct ap_session *ses, int create) { - struct ppp_pd_t *pd; + struct ap_private *pd; struct shaper_pd_t *spd; - list_for_each_entry(pd, &ppp->pd_list, entry) { + list_for_each_entry(pd, &ses->pd_list, entry) { if (pd->key == &pd_key) { spd = container_of(pd, typeof(*spd), pd); return spd; @@ -118,8 +118,8 @@ static struct shaper_pd_t *find_pd(struct ppp_t *ppp, int create) } memset(spd, 0, sizeof(*spd)); - spd->ppp = ppp; - list_add_tail(&spd->pd.entry, &ppp->pd_list); + spd->ses = ses; + list_add_tail(&spd->pd.entry, &ses->pd_list); spd->pd.key = &pd_key; INIT_LIST_HEAD(&spd->tr_list); @@ -279,7 +279,7 @@ static void ev_radius_access_accept(struct ev_radius_t *ev) { int down_speed, down_burst; int up_speed, up_burst; - struct shaper_pd_t *pd = find_pd(ev->ppp, 1); + struct shaper_pd_t *pd = find_pd(ev->ses, 1); if (!pd) return; @@ -307,7 +307,7 @@ static void ev_radius_access_accept(struct ev_radius_t *ev) } if (down_speed > 0 && up_speed > 0) { - if (!install_limiter(ev->ppp, down_speed, down_burst, up_speed, up_burst)) { + if (!install_limiter(ev->ses, down_speed, down_burst, up_speed, up_burst)) { if (conf_verbose) log_ppp_info2("shaper: installed shaper %i/%i (Kbit)\n", down_speed, up_speed); } @@ -316,7 +316,7 @@ static void ev_radius_access_accept(struct ev_radius_t *ev) static void ev_radius_coa(struct ev_radius_t *ev) { - struct shaper_pd_t *pd = find_pd(ev->ppp, 0); + struct shaper_pd_t *pd = find_pd(ev->ses, 0); if (!pd) { ev->res = -1; @@ -335,7 +335,7 @@ static void ev_radius_coa(struct ev_radius_t *ev) pd->up_speed = 0; if (conf_verbose) log_ppp_info2("shaper: removed shaper\n"); - remove_limiter(ev->ppp); + remove_limiter(ev->ses); } return; } @@ -344,13 +344,13 @@ static void ev_radius_coa(struct ev_radius_t *ev) pd->down_speed = pd->cur_tr->down_speed; pd->up_speed = pd->cur_tr->up_speed; - if (remove_limiter(ev->ppp)) { + if (remove_limiter(ev->ses)) { ev->res = -1; return; } if (pd->down_speed > 0 || pd->up_speed > 0) { - if (install_limiter(ev->ppp, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst)) { + if (install_limiter(ev->ses, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst)) { ev->res= -1; return; } else { @@ -367,7 +367,7 @@ static void ev_radius_coa(struct ev_radius_t *ev) static void ev_shaper(struct ev_shaper_t *ev) { - struct shaper_pd_t *pd = find_pd(ev->ppp, 1); + struct shaper_pd_t *pd = find_pd(ev->ses, 1); int down_speed = 0, down_burst = 0; int up_speed = 0, up_burst = 0; int tr_id = 0; @@ -402,16 +402,16 @@ static void ev_shaper(struct ev_shaper_t *ev) } if (pd->down_speed > 0 && pd->up_speed > 0) { - if (!install_limiter(ev->ppp, down_speed, down_burst, up_speed, up_burst)) { + if (!install_limiter(ev->ses, down_speed, down_burst, up_speed, up_burst)) { if (conf_verbose) log_ppp_info2("shaper: installed shaper %i/%i (Kbit)\n", down_speed, up_speed); } } } -static void ev_ppp_pre_up(struct ppp_t *ppp) +static void ev_ppp_pre_up(struct ap_session *ses) { - struct shaper_pd_t *pd = find_pd(ppp, 1); + struct shaper_pd_t *pd = find_pd(ses, 1); if (!pd) return; @@ -420,16 +420,16 @@ static void ev_ppp_pre_up(struct ppp_t *ppp) pd->temp_up_speed = temp_up_speed; pd->down_speed = temp_down_speed; pd->up_speed = temp_up_speed; - if (!install_limiter(ppp, temp_down_speed, 0, temp_up_speed, 0)) { + if (!install_limiter(ses, temp_down_speed, 0, temp_up_speed, 0)) { if (conf_verbose) log_ppp_info2("shaper: installed shaper %i/%i (Kbit)\n", temp_down_speed, temp_up_speed); } } } -static void ev_ppp_finishing(struct ppp_t *ppp) +static void ev_ppp_finishing(struct ap_session *ses) { - struct shaper_pd_t *pd = find_pd(ppp, 0); + struct shaper_pd_t *pd = find_pd(ses, 0); if (pd) { clear_tr_pd(pd); @@ -439,7 +439,7 @@ static void ev_ppp_finishing(struct ppp_t *ppp) list_del(&pd->pd.entry); if (pd->down_speed || pd->up_speed) - remove_limiter(ppp); + remove_limiter(ses); _free(pd); } @@ -454,16 +454,16 @@ static void shaper_change_help(char * const *f, int f_cnt, void *cli) static void shaper_change(struct shaper_pd_t *pd) { if (pd->down_speed || pd->up_speed) - remove_limiter(pd->ppp); + remove_limiter(pd->ses); if (pd->temp_down_speed || pd->temp_up_speed) { pd->down_speed = pd->temp_down_speed; pd->up_speed = pd->temp_up_speed; - install_limiter(pd->ppp, pd->temp_down_speed, 0, pd->temp_up_speed, 0); + install_limiter(pd->ses, pd->temp_down_speed, 0, pd->temp_up_speed, 0); } else if (pd->cur_tr->down_speed || pd->cur_tr->up_speed) { pd->down_speed = pd->cur_tr->down_speed; pd->up_speed = pd->cur_tr->up_speed; - install_limiter(pd->ppp, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst); + install_limiter(pd->ses, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst); } else { pd->down_speed = 0; pd->up_speed = 0; @@ -503,7 +503,7 @@ static int shaper_change_exec(const char *cmd, char * const *f, int f_cnt, void pthread_rwlock_rdlock(&shaper_lock); list_for_each_entry(pd, &shaper_list, entry) { - if (all || !strcmp(f[2], pd->ppp->ifname)) { + if (all || !strcmp(f[2], pd->ses->ifname)) { if (temp) { pd->temp_down_speed = down_speed; pd->temp_up_speed = up_speed; @@ -517,7 +517,7 @@ static int shaper_change_exec(const char *cmd, char * const *f, int f_cnt, void pd->cur_tr->up_speed = up_speed; pd->cur_tr->up_burst = up_burst; } - triton_context_call(pd->ppp->ctrl->ctx, (triton_event_func)shaper_change, pd); + triton_context_call(pd->ses->ctrl->ctx, (triton_event_func)shaper_change, pd); if (!all) { found = 1; break; @@ -540,12 +540,12 @@ static void shaper_restore_help(char * const *f, int f_cnt, void *cli) static void shaper_restore(struct shaper_pd_t *pd) { - remove_limiter(pd->ppp); + remove_limiter(pd->ses); if (pd->cur_tr) { pd->down_speed = pd->cur_tr->down_speed; pd->up_speed = pd->cur_tr->up_speed; - install_limiter(pd->ppp, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst); + install_limiter(pd->ses, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst); } else { pd->down_speed = 0; pd->up_speed = 0; @@ -576,10 +576,10 @@ static int shaper_restore_exec(const char *cmd, char * const *f, int f_cnt, void list_for_each_entry(pd, &shaper_list, entry) { if (!pd->temp_down_speed) continue; - if (all || !strcmp(f[2], pd->ppp->ifname)) { + if (all || !strcmp(f[2], pd->ses->ifname)) { pd->temp_down_speed = 0; pd->temp_up_speed = 0; - triton_context_call(pd->ppp->ctrl->ctx, (triton_event_func)shaper_restore, pd); + triton_context_call(pd->ses->ctrl->ctx, (triton_event_func)shaper_restore, pd); if (!all) { found = 1; break; @@ -594,9 +594,9 @@ static int shaper_restore_exec(const char *cmd, char * const *f, int f_cnt, void return CLI_CMD_OK; } -static void print_rate(const struct ppp_t *ppp, char *buf) +static void print_rate(const struct ap_session *ses, char *buf) { - struct shaper_pd_t *pd = find_pd((struct ppp_t *)ppp, 0); + struct shaper_pd_t *pd = find_pd((struct ap_session *)ses, 0); if (pd && (pd->down_speed || pd->up_speed)) sprintf(buf, "%i/%i", pd->down_speed, pd->up_speed); @@ -625,7 +625,7 @@ static void update_shaper_tr(struct shaper_pd_t *pd) { struct time_range_pd_t *tr; - if (pd->ppp->terminating) + if (pd->ses->terminating) return; list_for_each_entry(tr, &pd->tr_list, entry) { @@ -641,13 +641,13 @@ static void update_shaper_tr(struct shaper_pd_t *pd) if (pd->down_speed || pd->up_speed) { if (pd->cur_tr && pd->down_speed == pd->cur_tr->down_speed && pd->up_speed == pd->cur_tr->up_speed) return; - remove_limiter(pd->ppp); + remove_limiter(pd->ses); } if (pd->cur_tr && (pd->cur_tr->down_speed || pd->cur_tr->up_speed)) { pd->down_speed = pd->cur_tr->down_speed; pd->up_speed = pd->cur_tr->up_speed; - if (!install_limiter(pd->ppp, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst)) { + if (!install_limiter(pd->ses, pd->cur_tr->down_speed, pd->cur_tr->down_burst, pd->cur_tr->up_speed, pd->cur_tr->up_burst)) { if (conf_verbose) log_ppp_info2("shaper: changed shaper %i/%i (Kbit)\n", pd->cur_tr->down_speed, pd->cur_tr->up_speed); } @@ -667,7 +667,7 @@ static void time_range_begin_timer(struct triton_timer_t *t) pthread_rwlock_rdlock(&shaper_lock); list_for_each_entry(pd, &shaper_list, entry) - triton_context_call(pd->ppp->ctrl->ctx, (triton_event_func)update_shaper_tr, pd); + triton_context_call(pd->ses->ctrl->ctx, (triton_event_func)update_shaper_tr, pd); pthread_rwlock_unlock(&shaper_lock); } @@ -681,7 +681,7 @@ static void time_range_end_timer(struct triton_timer_t *t) pthread_rwlock_rdlock(&shaper_lock); list_for_each_entry(pd, &shaper_list, entry) - triton_context_call(pd->ppp->ctrl->ctx, (triton_event_func)update_shaper_tr, pd); + triton_context_call(pd->ses->ctrl->ctx, (triton_event_func)update_shaper_tr, pd); pthread_rwlock_unlock(&shaper_lock); } @@ -935,8 +935,8 @@ static void init(void) triton_event_register_handler(EV_RADIUS_COA, (triton_event_func)ev_radius_coa); } #endif - triton_event_register_handler(EV_PPP_PRE_UP, (triton_event_func)ev_ppp_pre_up); - triton_event_register_handler(EV_PPP_FINISHING, (triton_event_func)ev_ppp_finishing); + triton_event_register_handler(EV_SES_PRE_UP, (triton_event_func)ev_ppp_pre_up); + triton_event_register_handler(EV_SES_FINISHING, (triton_event_func)ev_ppp_finishing); //triton_event_register_handler(EV_CTRL_FINISHED, (triton_event_func)ev_ctrl_finished); triton_event_register_handler(EV_SHAPER, (triton_event_func)ev_shaper); triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); diff --git a/accel-pppd/shaper/shaper.h b/accel-pppd/shaper/shaper.h index 41e6e437..6322a6ba 100644 --- a/accel-pppd/shaper/shaper.h +++ b/accel-pppd/shaper/shaper.h @@ -39,8 +39,8 @@ extern int conf_lq_arg1; extern int conf_lq_arg2; extern int conf_lq_arg3; -int install_limiter(struct ppp_t *ppp, int down_speed, int down_burst, int up_speed, int up_burst); -int remove_limiter(struct ppp_t *ppp); +int install_limiter(struct ap_session *ses, int down_speed, int down_burst, int up_speed, int up_burst); +int remove_limiter(struct ap_session *ses); int install_leaf_qdisc(struct rtnl_handle *rth, int ifindex, int parent, int handle); int init_ifb(const char *); |