summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2017-04-18 20:47:53 +0300
committerDmitry Kozlov <xeb@mail.ru>2017-04-18 21:17:54 +0300
commit3ec0e18a9636924736cd5759ad53a41924363533 (patch)
tree2a42a6bb8ce13e7fad686245d82fea217640c940
parentf22c441fa712c110afb17cdb7476fe3bfdaf3538 (diff)
downloadaccel-ppp-3ec0e18a9636924736cd5759ad53a41924363533.tar.gz
accel-ppp-3ec0e18a9636924736cd5759ad53a41924363533.zip
implemented session count limiting
new config option: [common] max-sessions=N If set then accel-pppd stops reply to new connection requests if total number of sessions (active and starting) is reached specified limit.
-rw-r--r--accel-pppd/accel-ppp.conf1
-rw-r--r--accel-pppd/ctrl/ipoe/ipoe.c9
-rw-r--r--accel-pppd/ctrl/l2tp/l2tp.c9
-rw-r--r--accel-pppd/ctrl/pppoe/pppoe.c6
-rw-r--r--accel-pppd/ctrl/pptp/pptp.c7
-rw-r--r--accel-pppd/include/ap_session.h1
-rw-r--r--accel-pppd/session.c11
7 files changed, 43 insertions, 1 deletions
diff --git a/accel-pppd/accel-ppp.conf b/accel-pppd/accel-ppp.conf
index 98ca885..49466b1 100644
--- a/accel-pppd/accel-ppp.conf
+++ b/accel-pppd/accel-ppp.conf
@@ -40,6 +40,7 @@ thread-count=4
#single-session=replace
#sid-case=upper
#sid-source=seq
+#max-sessions=1000
[ppp]
verbose=1
diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c
index 4a04fcb..31724ad 100644
--- a/accel-pppd/ctrl/ipoe/ipoe.c
+++ b/accel-pppd/ctrl/ipoe/ipoe.c
@@ -1190,6 +1190,12 @@ static struct ipoe_session *ipoe_session_create_dhcpv4(struct ipoe_serv *serv, s
int dlen = 0;
uint8_t *ptr = NULL;
+ if (ap_shutdown)
+ return NULL;
+
+ if (conf_max_sessions && ap_session_stat.active + ap_session_stat.starting >= conf_max_sessions)
+ return NULL;
+
ses = ipoe_session_alloc(serv->ifname);
if (!ses)
return NULL;
@@ -1790,6 +1796,9 @@ static struct ipoe_session *ipoe_session_create_up(struct ipoe_serv *serv, struc
if (ap_shutdown)
return NULL;
+ if (conf_max_sessions && ap_session_stat.active + ap_session_stat.starting >= conf_max_sessions)
+ return NULL;
+
if (l4_redirect_list_check(saddr))
return NULL;
diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c
index 76c679c..81e3ad5 100644
--- a/accel-pppd/ctrl/l2tp/l2tp.c
+++ b/accel-pppd/ctrl/l2tp/l2tp.c
@@ -2731,6 +2731,9 @@ static int l2tp_recv_SCCRQ(const struct l2tp_serv_t *serv,
return 0;
}
+ if (conf_max_sessions && ap_session_stat.active + ap_session_stat.starting >= conf_max_sessions)
+ return 0;
+
if (triton_module_loaded("connlimit")
&& connlimit_check(cl_key_from_ipv4(pack->addr.sin_addr.s_addr))) {
log_warn("l2tp: connection limits reached,"
@@ -3257,6 +3260,9 @@ static int l2tp_recv_ICRQ(struct l2tp_conn_t *conn,
return 0;
}
+ if (conf_max_sessions && ap_session_stat.active + ap_session_stat.starting >= conf_max_sessions)
+ return 0;
+
if (triton_module_loaded("connlimit")
&& connlimit_check(cl_key_from_ipv4(conn->peer_addr.sin_addr.s_addr))) {
log_tunnel(log_warn, conn, "connection limits reached,"
@@ -3557,6 +3563,9 @@ static int l2tp_recv_OCRQ(struct l2tp_conn_t *conn,
return 0;
}
+ if (conf_max_sessions && ap_session_stat.active + ap_session_stat.starting >= conf_max_sessions)
+ return 0;
+
if (triton_module_loaded("connlimit")
&& connlimit_check(cl_key_from_ipv4(conn->peer_addr.sin_addr.s_addr))) {
log_tunnel(log_warn, conn, "connection limits reached,"
diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c
index 242f7e0..7fbf038 100644
--- a/accel-pppd/ctrl/pppoe/pppoe.c
+++ b/accel-pppd/ctrl/pppoe/pppoe.c
@@ -949,6 +949,9 @@ static void pppoe_recv_PADI(struct pppoe_serv_t *serv, uint8_t *pack, int size)
if (ap_shutdown || pado_delay == -1)
return;
+ if (conf_max_sessions && ap_session_stat.active + ap_session_stat.starting >= conf_max_sessions)
+ return;
+
if (check_padi_limit(serv, ethhdr->h_source)) {
__sync_add_and_fetch(&stat_PADI_drop, 1);
if (conf_verbose) {
@@ -1068,6 +1071,9 @@ static void pppoe_recv_PADR(struct pppoe_serv_t *serv, uint8_t *pack, int size)
if (ap_shutdown)
return;
+ if (conf_max_sessions && ap_session_stat.active + ap_session_stat.starting >= conf_max_sessions)
+ return;
+
if (!memcmp(ethhdr->h_dest, bc_addr, ETH_ALEN)) {
if (conf_verbose)
log_warn("pppoe: discard PADR (destination address is broadcast)\n");
diff --git a/accel-pppd/ctrl/pptp/pptp.c b/accel-pppd/ctrl/pptp/pptp.c
index ec20586..d878b08 100644
--- a/accel-pppd/ctrl/pptp/pptp.c
+++ b/accel-pppd/ctrl/pptp/pptp.c
@@ -644,9 +644,14 @@ static int pptp_connect(struct triton_md_handler_t *h)
continue;
}
+ if (conf_max_sessions && ap_session_stat.active + ap_session_stat.starting >= conf_max_sessions) {
+ close(sock);
+ continue;
+ }
+
if (triton_module_loaded("connlimit") && connlimit_check(cl_key_from_ipv4(addr.sin_addr.s_addr))) {
close(sock);
- return 0;
+ continue;
}
log_info2("pptp: new connection from %s\n", inet_ntoa(addr.sin_addr));
diff --git a/accel-pppd/include/ap_session.h b/accel-pppd/include/ap_session.h
index 0baaab2..cc827fe 100644
--- a/accel-pppd/include/ap_session.h
+++ b/accel-pppd/include/ap_session.h
@@ -129,6 +129,7 @@ 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;
+extern int conf_max_sessions;
extern __thread const struct ap_net *net;
extern const struct ap_net def_net;
diff --git a/accel-pppd/session.c b/accel-pppd/session.c
index ad164f3..aa05a87 100644
--- a/accel-pppd/session.c
+++ b/accel-pppd/session.c
@@ -34,6 +34,7 @@ static int conf_single_session = -1;
static int conf_sid_source;
static int conf_seq_save_timeout = 10;
static const char *conf_seq_file;
+int __export conf_max_sessions;
pthread_rwlock_t __export ses_lock = PTHREAD_RWLOCK_INITIALIZER;
__export LIST_HEAD(ses_list);
@@ -75,6 +76,10 @@ void __export ap_session_set_ifindex(struct ap_session *ses)
ses->acct_tx_packets_i = stats.tx_packets;
ses->acct_rx_bytes_i = stats.rx_bytes;
ses->acct_tx_bytes_i = stats.tx_bytes;
+ ses->acct_rx_bytes = 0;
+ ses->acct_tx_bytes = 0;
+ ses->acct_input_gigawords = 0;
+ ses->acct_output_gigawords = 0;
}
}
@@ -507,6 +512,12 @@ static void load_config(void)
conf_seq_file = conf_get_opt("common", "seq-file");
if (!conf_seq_file)
conf_seq_file = "/var/lib/accel-ppp/seq";
+
+ opt = conf_get_opt("common", "max-sessions");
+ if (opt)
+ conf_max_sessions = atoi(opt);
+ else
+ conf_max_sessions = 0;
}
static void init(void)