diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2014-05-18 01:04:19 +0000 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2014-05-18 02:15:25 +0000 |
commit | d5c3630d92b329735048b228878bb3ae137799cc (patch) | |
tree | 2e7ae38e67170ef8f7ce502e40e3d6fbecd06903 | |
parent | ec41e172a9da0de7cf5c28027928c698d0d1ebf8 (diff) | |
download | accel-ppp-d5c3630d92b329735048b228878bb3ae137799cc.tar.gz accel-ppp-d5c3630d92b329735048b228878bb3ae137799cc.zip |
improved single-session=replace handling
Wait for previous session completely terminated before continuing authorization new session.
-rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe.c | 5 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/lua.c | 6 | ||||
-rw-r--r-- | accel-pppd/include/ap_session.h | 4 | ||||
-rw-r--r-- | accel-pppd/ppp/ppp_auth.c | 6 | ||||
-rw-r--r-- | accel-pppd/session.c | 23 |
5 files changed, 31 insertions, 13 deletions
diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index 375e6c58..a7db155b 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -321,7 +321,8 @@ static void ipoe_session_set_username(struct ipoe_session *ses) ipoe_lua_set_username(ses, ses->serv->opt_lua_username_func ? : conf_lua_username_func); } else #endif - ses->ses.username = _strdup(ses->ses.ifname); + + ap_session_set_username(&ses->ses, _strdup(ses->ses.ifname)); } static void l4_redirect_list_add(in_addr_t addr, int ifindex) @@ -1547,7 +1548,7 @@ static struct ipoe_session *ipoe_session_create_up(struct ipoe_serv *serv, struc ses->ses.chan_name = ses->ctrl.calling_station_id; if (conf_username == USERNAME_UNSET) - ses->ses.username = _strdup(ses->ctrl.calling_station_id); + ap_session_set_username(&ses->ses, _strdup(ses->ctrl.calling_station_id)); if (conf_ip_pool) ses->ses.ipv4_pool_name = _strdup(conf_ip_pool); diff --git a/accel-pppd/ctrl/ipoe/lua.c b/accel-pppd/ctrl/ipoe/lua.c index 4fb6380a..b894aa3f 100644 --- a/accel-pppd/ctrl/ipoe/lua.c +++ b/accel-pppd/ctrl/ipoe/lua.c @@ -232,6 +232,8 @@ out_err: int ipoe_lua_set_username(struct ipoe_session *ses, const char *func) { + int r; + if (file_error && serial == __serial) return -1; @@ -257,11 +259,11 @@ int ipoe_lua_set_username(struct ipoe_session *ses, const char *func) goto out_err; } - ses->ses.username = _strdup(lua_tostring(L, -1)); + r = ap_session_set_username(&ses->ses, _strdup(lua_tostring(L, -1))); lua_settop(L, 0); - return 0; + return r; out_err: file_error = 1; diff --git a/accel-pppd/include/ap_session.h b/accel-pppd/include/ap_session.h index 86a777c2..cde8dc09 100644 --- a/accel-pppd/include/ap_session.h +++ b/accel-pppd/include/ap_session.h @@ -86,6 +86,8 @@ struct ap_session struct backup_data *backup; #endif + struct triton_context_t *wakeup; + int terminating:1; int terminated:1; int terminate_cause; @@ -124,7 +126,7 @@ 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); -int ap_session_check_single(const char *username); +int ap_session_set_username(struct ap_session *ses, char *username); void ap_session_ifup(struct ap_session *ses); void ap_session_ifdown(struct ap_session *ses); diff --git a/accel-pppd/ppp/ppp_auth.c b/accel-pppd/ppp/ppp_auth.c index 0510358c..b32400e2 100644 --- a/accel-pppd/ppp/ppp_auth.c +++ b/accel-pppd/ppp/ppp_auth.c @@ -336,10 +336,10 @@ int __export ppp_auth_succeeded(struct ppp_t *ppp, char *username) { struct auth_layer_data_t *ad = container_of(ppp_find_layer_data(ppp, &auth_layer), typeof(*ad), ld); - if (ap_session_check_single(username)) + if (ap_session_set_username(&ppp->ses, username)) { + _free(username); return -1; - - ppp->ses.username = username; + } triton_context_call(ppp->ses.ctrl->ctx, (triton_event_func)__ppp_auth_started, ppp); diff --git a/accel-pppd/session.c b/accel-pppd/session.c index c74de575..5d12635f 100644 --- a/accel-pppd/session.c +++ b/accel-pppd/session.c @@ -159,6 +159,9 @@ void __export ap_session_finished(struct ap_session *ses) triton_event_fire(EV_SES_FINISHED, ses); ses->ctrl->finished(ses); + if (ses->wakeup) + triton_context_wakeup(ses->wakeup); + if (ses->username) { _free(ses->username); ses->username = NULL; @@ -310,12 +313,13 @@ static void __terminate_sec(struct ap_session *ses) ap_session_terminate(ses, TERM_NAS_REQUEST, 0); } -int __export ap_session_check_single(const char *username) +int __export ap_session_set_username(struct ap_session *s, char *username) { struct ap_session *ses; + int wait = 0; + pthread_rwlock_wrlock(&ses_lock); if (conf_single_session >= 0) { - 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) { @@ -324,14 +328,23 @@ int __export ap_session_check_single(const char *username) return -1; } else { if (conf_single_session == 1) { - ap_session_ifdown(ses); + if (ses->wakeup) + continue; + //ap_session_ifdown(ses); + ses->wakeup = s->ctrl->ctx; + wait = 1; triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_sec, ses); } } } } - pthread_rwlock_unlock(&ses_lock); - } + s->username = username; + } else + s->username = username; + pthread_rwlock_unlock(&ses_lock); + + if (wait) + triton_context_schedule(); return 0; } |