diff options
author | xebd <xeb@mail.ru> | 2020-03-10 13:35:47 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-10 13:35:47 +0300 |
commit | 7afe0f075676219ab4b9e8dbfed294992e9f360b (patch) | |
tree | 4a7349449ac2072e52b441c813df42be4fec0ae1 /accel-pppd | |
parent | 5db4429c75352b636cb8bb441216c4816ee8421f (diff) | |
parent | 58b41703427284ca849bed7d11087b76ef16a46f (diff) | |
download | accel-ppp-7afe0f075676219ab4b9e8dbfed294992e9f360b.tar.gz accel-ppp-7afe0f075676219ab4b9e8dbfed294992e9f360b.zip |
Merge pull request #121 from themiron/max-starting-cleanup
Add global [common]max-starting option
Diffstat (limited to 'accel-pppd')
-rw-r--r-- | accel-pppd/accel-ppp.conf | 4 | ||||
-rw-r--r-- | accel-pppd/accel-ppp.conf.5 | 5 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe.c | 24 | ||||
-rw-r--r-- | accel-pppd/ctrl/l2tp/l2tp.c | 9 | ||||
-rw-r--r-- | accel-pppd/ctrl/pppoe/pppoe.c | 20 | ||||
-rw-r--r-- | accel-pppd/ctrl/pptp/pptp.c | 12 | ||||
-rw-r--r-- | accel-pppd/ctrl/sstp/sstp.c | 12 | ||||
-rw-r--r-- | accel-pppd/include/ap_session.h | 1 | ||||
-rw-r--r-- | accel-pppd/session.c | 7 |
9 files changed, 51 insertions, 43 deletions
diff --git a/accel-pppd/accel-ppp.conf b/accel-pppd/accel-ppp.conf index 7e9bb40d..290a19c8 100644 --- a/accel-pppd/accel-ppp.conf +++ b/accel-pppd/accel-ppp.conf @@ -41,6 +41,7 @@ thread-count=4 #sid-case=upper #sid-source=seq #max-sessions=1000 +#max-starting=0 #check-ip=0 [ppp] @@ -68,7 +69,6 @@ unit-cache=1 #noauth=0 [pptp] -#max-starting=0 verbose=1 #echo-interval=30 #ip-pool=pptp @@ -78,7 +78,6 @@ verbose=1 [pppoe] verbose=1 -#max-starting=0 #ac-name=xxx #service-name=yyy #pado-delay=0 @@ -140,7 +139,6 @@ verbose=1 #ifname=sstp%d [ipoe] -#max-starting=0 verbose=1 username=ifname #password=username diff --git a/accel-pppd/accel-ppp.conf.5 b/accel-pppd/accel-ppp.conf.5 index 41ee09c5..af85d04d 100644 --- a/accel-pppd/accel-ppp.conf.5 +++ b/accel-pppd/accel-ppp.conf.5 @@ -124,7 +124,10 @@ Assign session id by sequence method Path to file for sessions sequence number. Start sequence number may be set there (default /var/lib/accel-ppp/seq). .TP .BI "max-sessions=" n -Specifies maximum sessions which server may processed (default 0, disabled) +Specifies maximum concurrent sessions which server may processed (default 0, disabled) +.TP +.BI "max-starting=" n +Specifies maximum concurrent session attempts which server may processed (default 0, disabled) .TP .BI "check-ip=" 0|1 Specifies whether accel-ppp should check if IP already assigned to other client interface (default 0). diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index b1504a2f..87261cb3 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -127,7 +127,6 @@ static int conf_username; static const char *conf_password; static int conf_unit_cache; static int conf_noauth; -static int conf_max_starting; #ifdef RADIUS static int conf_vendor; static const char *conf_vendor_str; @@ -1303,6 +1302,9 @@ static struct ipoe_session *ipoe_session_create_dhcpv4(struct ipoe_serv *serv, s if (ap_shutdown) return NULL; + if (conf_max_starting && ap_session_stat.starting >= conf_max_starting) + return NULL; + if (conf_max_sessions && ap_session_stat.active + ap_session_stat.starting >= conf_max_sessions) return NULL; @@ -1772,10 +1774,7 @@ static void __ipoe_recv_dhcpv4(struct dhcpv4_serv *dhcpv4, struct dhcpv4_packet if (connlimit_loaded && pack->msg_type == DHCPDISCOVER && connlimit_check(serv->opt_shared ? cl_key_from_mac(pack->hdr->chaddr) : serv->ifindex)) return; - if (conf_max_starting > 0 && pack->msg_type == DHCPDISCOVER && stat_starting > conf_max_starting) { - log_warn("ipoe: Count of starting sessions > conf_max_starting, droping connection...\n"); - return; - } + pthread_mutex_lock(&serv->lock); if (pack->msg_type == DHCPDISCOVER) { if (check_notify(serv, pack)) @@ -2029,15 +2028,15 @@ static struct ipoe_session *ipoe_session_create_up(struct ipoe_serv *serv, struc if (ap_shutdown) return NULL; - if (connlimit_loaded && connlimit_check(cl_key_from_ipv4(saddr))) - return NULL; - if (conf_max_starting > 0 && stat_starting > conf_max_starting) { - log_warn("ipoe: Count of starting sessions > conf_max_starting, droping connection...\n"); + if (conf_max_starting && ap_session_stat.starting >= conf_max_starting) return NULL; - } + if (conf_max_sessions && ap_session_stat.active + ap_session_stat.starting >= conf_max_sessions) return NULL; + if (connlimit_loaded && connlimit_check(cl_key_from_ipv4(saddr))) + return NULL; + if (l4_redirect_list_check(saddr)) return NULL; @@ -3745,11 +3744,6 @@ static void load_config(void) conf_password = opt; } else conf_password = NULL; - opt = conf_get_opt("ipoe", "max-starting"); - if (opt) - conf_max_starting = atoi(opt); - else - conf_max_starting = 0; opt = conf_get_opt("ipoe", "netmask"); if (opt) { diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index 0d1ca21a..2467189f 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -2761,6 +2761,9 @@ static int l2tp_recv_SCCRQ(const struct l2tp_serv_t *serv, return 0; } + if (conf_max_starting && ap_session_stat.starting >= conf_max_starting) + return 0; + if (conf_max_sessions && ap_session_stat.active + ap_session_stat.starting >= conf_max_sessions) return 0; @@ -3300,6 +3303,9 @@ static int l2tp_recv_ICRQ(struct l2tp_conn_t *conn, return 0; } + if (conf_max_starting && ap_session_stat.starting >= conf_max_starting) + return 0; + if (conf_max_sessions && ap_session_stat.active + ap_session_stat.starting >= conf_max_sessions) return 0; @@ -3603,6 +3609,9 @@ static int l2tp_recv_OCRQ(struct l2tp_conn_t *conn, return 0; } + if (conf_max_starting && ap_session_stat.starting >= conf_max_starting) + return 0; + if (conf_max_sessions && ap_session_stat.active + ap_session_stat.starting >= conf_max_sessions) return 0; diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c index 32dee77a..718ebc51 100644 --- a/accel-pppd/ctrl/pppoe/pppoe.c +++ b/accel-pppd/ctrl/pppoe/pppoe.c @@ -87,7 +87,6 @@ struct iplink_arg { long *arg1; }; -static int conf_max_starting; int conf_verbose; char *conf_service_name[255]; int conf_accept_any_service; @@ -967,15 +966,11 @@ 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 (conf_max_starting > 0 && stat_starting >= conf_max_starting) { - log_warn("pppoe: Count of starting sessions > conf_max_starting, droping connection...\n"); + if (conf_max_starting && ap_session_stat.starting >= conf_max_starting) 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); @@ -1101,6 +1096,9 @@ static void pppoe_recv_PADR(struct pppoe_serv_t *serv, uint8_t *pack, int size) if (ap_shutdown) return; + if (conf_max_starting && ap_session_stat.starting >= conf_max_starting) + return; + if (conf_max_sessions && ap_session_stat.active + ap_session_stat.starting >= conf_max_sessions) return; @@ -1936,12 +1934,6 @@ static void load_config(void) char *opt; struct conf_sect_t *s = conf_get_section("pppoe"); - opt = conf_get_opt("pppoe", "max-starting"); - if (opt) - conf_max_starting = atoi(opt); - else - conf_max_starting = 0; - opt = conf_get_opt("pppoe", "verbose"); if (opt) conf_verbose = atoi(opt); diff --git a/accel-pppd/ctrl/pptp/pptp.c b/accel-pppd/ctrl/pptp/pptp.c index 1161da5a..3b90139f 100644 --- a/accel-pppd/ctrl/pptp/pptp.c +++ b/accel-pppd/ctrl/pptp/pptp.c @@ -55,7 +55,6 @@ struct pptp_conn_t struct ppp_t ppp; }; -static int conf_max_starting; static int conf_ppp_max_mtu = PPTP_MAX_MTU; static int conf_timeout = 5; static int conf_echo_interval = 0; @@ -652,13 +651,13 @@ 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) { + if (conf_max_starting && ap_session_stat.starting >= conf_max_starting) { close(sock); continue; } - if (conf_max_starting > 0 && stat_starting >= conf_max_starting) { + + if (conf_max_sessions && ap_session_stat.active + ap_session_stat.starting >= conf_max_sessions) { close(sock); - log_warn("pptp: Count of starting sessions > conf_max_starting, droping connection...\n"); continue; } @@ -789,11 +788,6 @@ static void load_config(void) else conf_ppp_max_mtu = PPTP_MAX_MTU; - opt = conf_get_opt("pptp", "max-starting"); - if (opt) - conf_max_starting = atoi(opt); - else - conf_max_starting = 0; conf_mppe = MPPE_UNSET; opt = conf_get_opt("pptp", "mppe"); if (opt) { diff --git a/accel-pppd/ctrl/sstp/sstp.c b/accel-pppd/ctrl/sstp/sstp.c index 5bf8fd82..7574a789 100644 --- a/accel-pppd/ctrl/sstp/sstp.c +++ b/accel-pppd/ctrl/sstp/sstp.c @@ -2196,10 +2196,20 @@ static int sstp_connect(struct triton_md_handler_t *h) continue; } + if (conf_max_starting && ap_session_stat.starting >= conf_max_starting) { + close(sock); + continue; + } + + if (conf_max_sessions && ap_session_stat.active + ap_session_stat.starting >= conf_max_sessions) { + close(sock); + continue; + } + ip = conf_proxyproto ? INADDR_ANY : sockaddr_ipv4(&addr); if (ip && triton_module_loaded("connlimit") && connlimit_check(cl_key_from_ipv4(ip))) { close(sock); - return 0; + continue; } sockaddr_ntop(&addr, addr_buf, sizeof(addr_buf), 0); diff --git a/accel-pppd/include/ap_session.h b/accel-pppd/include/ap_session.h index 6a6b9504..8c79d31d 100644 --- a/accel-pppd/include/ap_session.h +++ b/accel-pppd/include/ap_session.h @@ -135,6 +135,7 @@ extern int sock6_fd; extern int urandom_fd; extern struct ap_session_stat ap_session_stat; extern int conf_max_sessions; +extern int conf_max_starting; void ap_session_init(struct ap_session *ses); void ap_session_set_ifindex(struct ap_session *ses); diff --git a/accel-pppd/session.c b/accel-pppd/session.c index 81247d18..8ef569e6 100644 --- a/accel-pppd/session.c +++ b/accel-pppd/session.c @@ -36,6 +36,7 @@ static int conf_sid_source; static int conf_seq_save_timeout = 10; static const char *conf_seq_file; int __export conf_max_sessions; +int __export conf_max_starting; pthread_rwlock_t __export ses_lock = PTHREAD_RWLOCK_INITIALIZER; __export LIST_HEAD(ses_list); @@ -542,6 +543,12 @@ static void load_config(void) conf_max_sessions = atoi(opt); else conf_max_sessions = 0; + + opt = conf_get_opt("common", "max-starting"); + if (opt) + conf_max_starting = atoi(opt); + else + conf_max_starting = 0; } static void init(void) |