summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--accel-pppd/include/ap_session.h1
-rw-r--r--accel-pppd/ppp/ppp.c10
-rw-r--r--accel-pppd/ppp/ppp.h1
-rw-r--r--accel-pppd/ppp/ppp_auth.c28
-rw-r--r--accel-pppd/session.c50
5 files changed, 49 insertions, 41 deletions
diff --git a/accel-pppd/include/ap_session.h b/accel-pppd/include/ap_session.h
index 6845ca90..9a8b1c73 100644
--- a/accel-pppd/include/ap_session.h
+++ b/accel-pppd/include/ap_session.h
@@ -123,6 +123,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);
void ap_session_ifup(struct ap_session *ses);
void ap_session_ifdown(struct ap_session *ses);
diff --git a/accel-pppd/ppp/ppp.c b/accel-pppd/ppp/ppp.c
index 116e1349..fee9334d 100644
--- a/accel-pppd/ppp/ppp.c
+++ b/accel-pppd/ppp/ppp.c
@@ -28,7 +28,6 @@
#include "memdebug.h"
int __export conf_ppp_verbose;
-int conf_single_session = -1;
int conf_unit_cache = 0;
static mempool_t buf_pool;
@@ -599,15 +598,6 @@ static void load_config(void)
if (opt && atoi(opt) > 0)
conf_ppp_verbose = 1;
- opt = conf_get_opt("ppp", "single-session");
- if (opt) {
- if (!strcmp(opt, "deny"))
- conf_single_session = 0;
- else if (!strcmp(opt, "replace"))
- conf_single_session = 1;
- } else
- conf_single_session = -1;
-
opt = conf_get_opt("ppp", "unit-cache");
if (opt && atoi(opt) > 0)
conf_unit_cache = atoi(opt);
diff --git a/accel-pppd/ppp/ppp.h b/accel-pppd/ppp/ppp.h
index f07e0282..e4030877 100644
--- a/accel-pppd/ppp/ppp.h
+++ b/accel-pppd/ppp/ppp.h
@@ -127,6 +127,5 @@ struct ppp_layer_data_t *ppp_find_layer_data(struct ppp_t *, struct ppp_layer_t
int ppp_ipv6_nd_start(struct ppp_t *ppp, uint64_t intf_id);
extern int conf_ppp_verbose;
-extern int conf_single_session;
#endif
diff --git a/accel-pppd/ppp/ppp_auth.c b/accel-pppd/ppp/ppp_auth.c
index 2b4aff9b..42bbbc6b 100644
--- a/accel-pppd/ppp/ppp_auth.c
+++ b/accel-pppd/ppp/ppp_auth.c
@@ -317,11 +317,6 @@ static void auth_layer_free(struct ppp_layer_data_t *ld)
_free(ad);
}
-static void __terminate_sec(struct ap_session *ses)
-{
- 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);
@@ -339,31 +334,12 @@ static void __ppp_auth_started(struct ppp_t *ppp)
int __export ppp_auth_succeeded(struct ppp_t *ppp, char *username)
{
- 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(&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(&ses_lock);
- log_ppp_info1("%s: second session denied\n", username);
- return -1;
- } else {
- if (conf_single_session == 1) {
- ap_session_ifdown(ses);
- triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_sec, ses);
- }
- }
- }
- }
- pthread_rwlock_unlock(&ses_lock);
- }
+ if (ap_session_check_single(username))
+ return -1;
- pthread_rwlock_wrlock(&ses_lock);
ppp->ses.username = username;
- pthread_rwlock_unlock(&ses_lock);
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 41c5d693..5c776832 100644
--- a/accel-pppd/session.c
+++ b/accel-pppd/session.c
@@ -23,7 +23,9 @@
#include "mempool.h"
#include "memdebug.h"
-int conf_sid_ucase;
+static int conf_sid_ucase;
+static int conf_single_session = -1;
+
pthread_rwlock_t __export ses_lock = PTHREAD_RWLOCK_INITIALIZER;
__export LIST_HEAD(ses_list);
@@ -261,10 +263,41 @@ int __export ap_session_read_stats(struct ap_session *ses, struct rtnl_link_stat
return 0;
}
+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)
+{
+ struct ap_session *ses;
+
+ 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) {
+ pthread_rwlock_unlock(&ses_lock);
+ log_ppp_info1("%s: second session denied\n", username);
+ return -1;
+ } else {
+ if (conf_single_session == 1) {
+ ap_session_ifdown(ses);
+ triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_sec, ses);
+ }
+ }
+ }
+ }
+ pthread_rwlock_unlock(&ses_lock);
+ }
+
+ return 0;
+}
+
static void save_seq(void)
{
FILE *f;
- char *opt = conf_get_opt("ppp", "seq-file");
+ char *opt = conf_get_opt("common", "seq-file");
if (!opt)
opt = "/var/run/accel-ppp/seq";
@@ -277,7 +310,7 @@ static void save_seq(void)
static void load_config(void)
{
- char *opt;
+ const char *opt;
opt = conf_get_opt("common", "sid-case");
if (opt) {
@@ -286,6 +319,15 @@ static void load_config(void)
else if (strcmp(opt, "lower"))
log_emerg("sid-case: invalid format\n");
}
+
+ opt = conf_get_opt("common", "single-session");
+ if (opt) {
+ if (!strcmp(opt, "deny"))
+ conf_single_session = 0;
+ else if (!strcmp(opt, "replace"))
+ conf_single_session = 1;
+ } else
+ conf_single_session = -1;
}
static void init(void)
@@ -315,7 +357,7 @@ static void init(void)
fcntl(urandom_fd, F_SETFD, fcntl(urandom_fd, F_GETFD) | FD_CLOEXEC);
- opt = conf_get_opt("session", "seq-file");
+ opt = conf_get_opt("common", "seq-file");
if (!opt)
opt = "/var/run/accel-ppp/seq";