diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2013-10-03 11:08:45 +0400 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2013-10-03 11:08:45 +0400 |
commit | 8c608ea9a5b6b73520c11e3974bb8cad3b7da914 (patch) | |
tree | d6ebed20aa2225da869983807dc655e8788b2ca2 | |
parent | a5f293d16c8b4a333fac31e187e0b5e55fd38335 (diff) | |
download | accel-ppp-8c608ea9a5b6b73520c11e3974bb8cad3b7da914.tar.gz accel-ppp-8c608ea9a5b6b73520c11e3974bb8cad3b7da914.zip |
Introduce per-ctrl 'ip-pool' option to be used as default IP pool name which may be overrided by radius
Signed-off-by: Dmitry Kozlov <xeb@mail.ru>
-rw-r--r-- | accel-pppd/accel-ppp.conf | 76 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe.c | 62 | ||||
-rw-r--r-- | accel-pppd/ctrl/l2tp/l2tp.c | 6 | ||||
-rw-r--r-- | accel-pppd/ctrl/pppoe/pppoe.c | 6 | ||||
-rw-r--r-- | accel-pppd/ctrl/pptp/pptp.c | 6 | ||||
-rw-r--r-- | accel-pppd/extra/ippool.c | 9 |
6 files changed, 83 insertions, 82 deletions
diff --git a/accel-pppd/accel-ppp.conf b/accel-pppd/accel-ppp.conf index 69f33b3..707287f 100644 --- a/accel-pppd/accel-ppp.conf +++ b/accel-pppd/accel-ppp.conf @@ -33,35 +33,10 @@ pppd_compat log-error=/var/log/accel-ppp/core.log thread-count=4 -[ipoe] -verbose=1 -username=ifname -#password=username -lease-time=600 -max-lease-time=3600 -#unit-cache=1000 -#l4-redirect-table=4 -#l4-redirect-ipset=l4 -#l4-redirect-on-reject=300 -shared=0 -ifcfg=1 -mode=L2 -start=dhcpv4 -#proxy-arp=0 -#nat=0 -#proto=100 -#relay=10.10.10.10 -#attr-dhcp-client-ip=DHCP-Client-IP-Address -#attr-dhcp-router-ip=DHCP-Router-IP-Address -#attr-dhcp-mask=DHCP-Mask -#attr-l4-redirect=L4-Redirect -#local-net=192.168.0.0/16 -#lua-file=/etc/accel-ppp.lua -#offer-delay=0,100:100,200:200,-1:1000 -#vlan-mon=eth0,10-200 -#vlan-timeout=60 -interface=eth0 - +[common] +#single-session=replace +#sid-case=upper +#sid-source=seq [ppp] verbose=1 @@ -69,9 +44,7 @@ min-mtu=1280 mtu=1400 mru=1400 #ccp=0 -#sid-case=upper #check-ip=0 -#single-session=replace #mppe=require ipv4=require ipv6=deny @@ -88,12 +61,11 @@ lcp-echo-timeout=120 #noauth=0 [pptp] -#echo-interval=30 verbose=1 +#echo-interval=30 [pppoe] -interface=eth0 -#interface=eth1,padi-limit=1000 +verbose=1 #ac-name=xxx #service-name=yyy #pado-delay=0 @@ -101,9 +73,12 @@ interface=eth0 #ifname-in-sid=called-sid #tr101=1 #padi-limit=0 -verbose=1 +#ip-pool=pppoe +#interface=eth1,padi-limit=1000 +interface=eth0 [l2tp] +verbose=1 #dictionary=/usr/local/share/accel-ppp/l2tp/dictionary #hello-interval=60 #timeout=60 @@ -114,7 +89,38 @@ verbose=1 #secret= #dataseq=allow #reorder-timeout=0 +#ip-pool=l2tp + +[ipoe] verbose=1 +username=ifname +#password=username +lease-time=600 +max-lease-time=3600 +#unit-cache=1000 +#l4-redirect-table=4 +#l4-redirect-ipset=l4 +#l4-redirect-on-reject=300 +shared=0 +ifcfg=1 +mode=L2 +start=dhcpv4 +#proxy-arp=0 +#nat=0 +#proto=100 +#relay=10.10.10.10 +#attr-dhcp-client-ip=DHCP-Client-IP-Address +#attr-dhcp-router-ip=DHCP-Router-IP-Address +#attr-dhcp-mask=DHCP-Mask +#attr-l4-redirect=L4-Redirect +#local-net=192.168.0.0/16 +#lua-file=/etc/accel-ppp.lua +#offer-delay=0,100:100,200:200,-1:1000 +#vlan-mon=eth0,10-200 +#vlan-timeout=60 +#ip-pool=ipoe +interface=eth0 + [dns] #dns1=172.16.0.1 diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index 7059e2a..6835fc6 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -98,7 +98,7 @@ static int conf_ifcfg = 1; static int conf_nat = 0; static int conf_arp = 0; static uint32_t conf_src; - +static const char *conf_ip_pool; //static int conf_dhcpv6; static int conf_username; static const char *conf_password; @@ -974,18 +974,11 @@ static struct ipoe_session *ipoe_session_create_dhcpv4(struct ipoe_serv *serv, s int dlen = 0; uint8_t *ptr = NULL; - ses = mempool_alloc(ses_pool); - if (!ses) { - log_emerg("out of memery\n"); + ses = ipoe_session_alloc(); + if (!ses) return NULL; - } - - memset(ses, 0, sizeof(*ses)); - - ap_session_init(&ses->ses); ses->serv = serv; - ses->ifindex = -1; ses->dhcpv4_request = pack; ses->xid = pack->hdr->xid; @@ -1027,14 +1020,6 @@ static struct ipoe_session *ipoe_session_create_dhcpv4(struct ipoe_serv *serv, s ses->relay_agent = NULL; } - ses->ctx.before_switch = log_switch; - ses->ctx.close = ipoe_session_close; - ses->ctrl.ctx = &ses->ctx; - ses->ctrl.started = ipoe_session_started; - ses->ctrl.finished = ipoe_session_finished; - ses->ctrl.terminate = ipoe_session_terminate; - ses->ctrl.type = CTRL_TYPE_IPOE; - ses->ctrl.name = "ipoe"; ses->ctrl.dont_ifcfg = 1; ses->ctrl.calling_station_id = _malloc(19); @@ -1047,6 +1032,9 @@ static struct ipoe_session *ipoe_session_create_dhcpv4(struct ipoe_serv *serv, s ses->ses.ctrl = &ses->ctrl; ses->ses.chan_name = ses->ctrl.calling_station_id; + if (conf_ip_pool) + ses->ses.ipv4_pool_name = _strdup(conf_ip_pool); + triton_context_register(&ses->ctx, &ses->ses); triton_context_wakeup(&ses->ctx); @@ -1497,44 +1485,27 @@ static struct ipoe_session *ipoe_session_create_up(struct ipoe_serv *serv, struc if (l4_redirect_list_check(iph->saddr)) return NULL; - ses = mempool_alloc(ses_pool); - if (!ses) { - log_emerg("out of memery\n"); + ses = ipoe_session_alloc(); + if (!ses) return NULL; - } - - memset(ses, 0, sizeof(*ses)); - - ap_session_init(&ses->ses); ses->serv = serv; - ses->ifindex = -1; - memcpy(ses->hwaddr, eth->h_source, 6); - - ses->ctx.before_switch = log_switch; - ses->ctx.close = ipoe_session_close; - ses->ctrl.ctx = &ses->ctx; - ses->ctrl.started = ipoe_session_started; - ses->ctrl.finished = ipoe_session_finished; - ses->ctrl.terminate = ipoe_session_terminate; - ses->ctrl.type = CTRL_TYPE_IPOE; - ses->ctrl.name = "ipoe"; - ses->yiaddr = iph->saddr; ses->ctrl.calling_station_id = _malloc(17); - ses->ctrl.called_station_id = _malloc(17); + ses->ctrl.called_station_id = _strdup(serv->ifname); u_inet_ntoa(iph->saddr, ses->ctrl.calling_station_id); - u_inet_ntoa(iph->daddr, ses->ctrl.called_station_id); + + ses->ses.chan_name = ses->ctrl.calling_station_id; if (conf_username == USERNAME_UNSET) ses->ses.username = _strdup(ses->ctrl.calling_station_id); - ses->ses.ctrl = &ses->ctrl; - ses->ses.chan_name = ses->ctrl.calling_station_id; - + if (conf_ip_pool) + ses->ses.ipv4_pool_name = _strdup(conf_ip_pool); + triton_context_register(&ses->ctx, &ses->ses); triton_context_wakeup(&ses->ctx); @@ -1577,8 +1548,7 @@ struct ipoe_session *ipoe_session_alloc(void) ses->ctrl.name = "ipoe"; ses->ses.ctrl = &ses->ctrl; - ses->ses.chan_name = ses->ctrl.calling_station_id; - + return ses; } @@ -2858,6 +2828,8 @@ static void load_config(void) else conf_offer_timeout = 10; + conf_ip_pool = conf_get_opt("ipoe", "ip-pool"); + #ifdef RADIUS if (triton_module_loaded("radius")) load_radius_attrs(); diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index e6fae4d..e14bab8 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -67,6 +67,7 @@ static size_t conf_secret_len = 0; static int conf_mppe = MPPE_UNSET; static int conf_dataseq = L2TP_DATASEQ_ALLOW; static int conf_reorder_timeout = 0; +static const char *conf_ip_pool; static unsigned int stat_active; static unsigned int stat_starting; @@ -905,6 +906,9 @@ static struct l2tp_sess_t *l2tp_tunnel_alloc_session(struct l2tp_conn_t *conn) sess->ppp.ses.ctrl = &sess->ctrl; sess->ppp.fd = -1; + if (conf_ip_pool) + sess->ppp.ses.ipv4_pool_name = _strdup(conf_ip_pool); + return sess; } @@ -3963,6 +3967,8 @@ static void load_config(void) else if (strcmp(opt, "require") == 0) conf_mppe = MPPE_REQUIRE; } + + conf_ip_pool = conf_get_opt("l2tp", "ip-pool"); } static void l2tp_init(void) diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c index 21051ed..c254c7a 100644 --- a/accel-pppd/ctrl/pppoe/pppoe.c +++ b/accel-pppd/ctrl/pppoe/pppoe.c @@ -89,6 +89,7 @@ char *conf_pado_delay; int conf_tr101 = 1; int conf_padi_limit = 0; int conf_mppe = MPPE_UNSET; +static const char *conf_ip_pool; static mempool_t conn_pool; static mempool_t pado_pool; @@ -299,6 +300,9 @@ static struct pppoe_conn_t *allocate_channel(struct pppoe_serv_t *serv, const ui conn->ppp.ses.ctrl = &conn->ctrl; conn->ppp.ses.chan_name = conn->ctrl.calling_station_id; + + if (conf_ip_pool) + conn->ppp.ses.ipv4_pool_name = _strdup(conf_ip_pool); triton_context_register(&conn->ctx, &conn->ppp.ses); triton_context_wakeup(&conn->ctx); @@ -1489,6 +1493,8 @@ static void load_config(void) else if (strcmp(opt, "require") == 0) conf_mppe = MPPE_REQUIRE; } + + conf_ip_pool = conf_get_opt("pppoe", "ip-pool"); } static void pppoe_init(void) diff --git a/accel-pppd/ctrl/pptp/pptp.c b/accel-pppd/ctrl/pptp/pptp.c index d5b96c1..31ffd00 100644 --- a/accel-pppd/ctrl/pptp/pptp.c +++ b/accel-pppd/ctrl/pptp/pptp.c @@ -60,6 +60,7 @@ static int conf_echo_interval = 0; static int conf_echo_failure = 3; static int conf_verbose = 0; static int conf_mppe = MPPE_UNSET; +static const char *conf_ip_pool; static mempool_t conn_pool; @@ -685,6 +686,9 @@ static int pptp_connect(struct triton_md_handler_t *h) ppp_init(&conn->ppp); conn->ppp.ses.ctrl = &conn->ctrl; + if (conf_ip_pool) + conn->ppp.ses.ipv4_pool_name = _strdup(conf_ip_pool); + triton_context_register(&conn->ctx, &conn->ppp.ses); triton_md_register_handler(&conn->ctx, &conn->hnd); triton_md_enable_handler(&conn->hnd,MD_MODE_READ); @@ -759,6 +763,8 @@ static void load_config(void) else if (strcmp(opt, "require") == 0) conf_mppe = MPPE_REQUIRE; } + + conf_ip_pool = conf_get_opt("pptp", "ip-pool"); } static void pptp_init(void) diff --git a/accel-pppd/extra/ippool.c b/accel-pppd/extra/ippool.c index 2f4b2e4..8dbf027 100644 --- a/accel-pppd/extra/ippool.c +++ b/accel-pppd/extra/ippool.c @@ -388,13 +388,18 @@ static struct backup_module backup_mod = { #ifdef RADIUS static int parse_attr(struct ap_session *ses, struct rad_attr_t *attr) { + if (ses->ipv4_pool_name) + _free(ses->ipv4_pool_name); + if (attr->len > sizeof("ip:addr-pool=") && memcmp(attr->val.string, "ip:addr-pool=", sizeof("ip:addr-pool=") - 1) == 0) ses->ipv4_pool_name = _strdup(attr->val.string + sizeof("ip:addr-pool=") - 1); else if (!attr->vendor) ses->ipv4_pool_name = _strdup(attr->val.string); - else + else { + ses->ipv4_pool_name = NULL; return -1; - + } + return 0; } |