summaryrefslogtreecommitdiff
path: root/accel-pppd
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2012-12-10 00:30:09 +0400
committerKozlov Dmitry <xeb@mail.ru>2013-01-24 23:55:37 +0400
commit48502707eb16f0ed0d4aa46bac7c18fba953c7bc (patch)
treef18e5568b93ec951d6bbd593d53df64433eba5c6 /accel-pppd
parent433d988f0d81b833bf5654dc10d55722b426f8ec (diff)
downloadaccel-ppp-48502707eb16f0ed0d4aa46bac7c18fba953c7bc.tar.gz
accel-ppp-48502707eb16f0ed0d4aa46bac7c18fba953c7bc.zip
implemented different sessionid length and urandom source
Diffstat (limited to 'accel-pppd')
-rw-r--r--accel-pppd/CMakeLists.txt7
-rw-r--r--accel-pppd/include/ap_session.h2
-rw-r--r--accel-pppd/session.c46
3 files changed, 44 insertions, 11 deletions
diff --git a/accel-pppd/CMakeLists.txt b/accel-pppd/CMakeLists.txt
index 3f4e27a5..141b493d 100644
--- a/accel-pppd/CMakeLists.txt
+++ b/accel-pppd/CMakeLists.txt
@@ -24,6 +24,12 @@ IF (MEMDEBUG)
ENDIF (VALGRIND)
ENDIF (MEMDEBUG)
+IF (SESSIONID_LEN)
+ ADD_DEFINITIONS(-DAP_SESSIONID_LEN=${SESSIONID_LEN})
+ELSE (SESSIONID_LEN)
+ ADD_DEFINITIONS(-DAP_SESSIONID_LEN=16)
+ENDIF (SESSIONID_LEN)
+
IF (BACKUP)
ADD_DEFINITIONS(-DUSE_BACKUP)
ADD_SUBDIRECTORY(backup)
@@ -38,6 +44,7 @@ IF (RADIUS)
ADD_SUBDIRECTORY(radius)
ENDIF (RADIUS)
+
ADD_SUBDIRECTORY(triton)
ADD_SUBDIRECTORY(ctrl)
ADD_SUBDIRECTORY(auth)
diff --git a/accel-pppd/include/ap_session.h b/accel-pppd/include/ap_session.h
index 9a8b1c73..a44c9899 100644
--- a/accel-pppd/include/ap_session.h
+++ b/accel-pppd/include/ap_session.h
@@ -1,7 +1,7 @@
#ifndef __AP_SESSION_H__
#define __AP_SESSION_H__
-#define AP_SESSIONID_LEN 16
+//#define AP_SESSIONID_LEN 16
#define AP_IFNAME_LEN 16
#define AP_STATE_STARTING 1
diff --git a/accel-pppd/session.c b/accel-pppd/session.c
index 5c776832..fece0893 100644
--- a/accel-pppd/session.c
+++ b/accel-pppd/session.c
@@ -23,8 +23,12 @@
#include "mempool.h"
#include "memdebug.h"
+#define SID_SOURCE_SEQ 0
+#define SID_SOURCE_URANDOM 1
+
static int conf_sid_ucase;
static int conf_single_session = -1;
+static int conf_sid_source;
pthread_rwlock_t __export ses_lock = PTHREAD_RWLOCK_INITIALIZER;
__export LIST_HEAD(ses_list);
@@ -213,20 +217,31 @@ void ap_shutdown_soft(void (*cb)(void))
static void generate_sessionid(struct ap_session *ses)
{
- unsigned long long sid;
-
+ if (conf_sid_source == SID_SOURCE_SEQ) {
+ unsigned long long sid;
#if __WORDSIZE == 32
- spin_lock(&seq_lock);
- sid = ++seq;
- spin_unlock(&seq_lock);
+ spin_lock(&seq_lock);
+ sid = ++seq;
+ spin_unlock(&seq_lock);
#else
- sid = __sync_add_and_fetch(&seq, 1);
+ sid = __sync_add_and_fetch(&seq, 1);
#endif
- if (conf_sid_ucase)
- sprintf(ses->sessionid, "%016llX", sid);
- else
- sprintf(ses->sessionid, "%016llx", sid);
+ if (conf_sid_ucase)
+ sprintf(ses->sessionid, "%016llX", sid);
+ else
+ sprintf(ses->sessionid, "%016llx", sid);
+ } else {
+ uint8_t sid[AP_SESSIONID_LEN/2];
+ int i;
+ read(urandom_fd, sid, AP_SESSIONID_LEN/2);
+ for (i = 0; i < AP_SESSIONID_LEN/2; i++) {
+ if (conf_sid_ucase)
+ sprintf(ses->sessionid + i*2, "%02X", sid[i]);
+ else
+ sprintf(ses->sessionid + i*2, "%02x", sid[i]);
+ }
+ }
}
int __export ap_session_read_stats(struct ap_session *ses, struct rtnl_link_stats *stats)
@@ -328,6 +343,17 @@ static void load_config(void)
conf_single_session = 1;
} else
conf_single_session = -1;
+
+ opt = conf_get_opt("common", "sid-source");
+ if (opt) {
+ if (strcmp(opt, "seq") == 0)
+ conf_sid_source = SID_SOURCE_SEQ;
+ else if (strcmp(opt, "urandom") == 0)
+ conf_sid_source = SID_SOURCE_URANDOM;
+ else
+ log_error("unknown sid-source\n");
+ } else
+ conf_sid_source = SID_SOURCE_SEQ;
}
static void init(void)