summaryrefslogtreecommitdiff
path: root/accel-pppd
diff options
context:
space:
mode:
authorKozlov Dmitry <xeb@mail.ru>2013-01-24 23:53:53 +0400
committerKozlov Dmitry <xeb@mail.ru>2013-01-24 23:53:53 +0400
commit1845b7ce4ea0c717401936ba8157c90f431d7932 (patch)
tree0920a94a42d87a141d100a75ed10600736e727e4 /accel-pppd
parent4c7ad9a5f8839d2e13c6f012c7cd3653e04b98b7 (diff)
downloadaccel-ppp-xebd-1845b7ce4ea0c717401936ba8157c90f431d7932.tar.gz
accel-ppp-xebd-1845b7ce4ea0c717401936ba8157c90f431d7932.zip
generalize single-session checking
Diffstat (limited to 'accel-pppd')
-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 6845ca9..9a8b1c7 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 116e134..fee9334 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 f07e028..e403087 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 2b4aff9..42bbbc6 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 41c5d69..5c77683 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";