From c91a2babe00212d73b4d972bd337ae5b9273d5ed Mon Sep 17 00:00:00 2001 From: Guillaume Nault Date: Fri, 26 Apr 2013 10:22:09 +0200 Subject: initscript: Fix LSB runlevels and ACCEL_PPPD_OPTS check * Stop daemon upon halt and reboot * Protect the ACCEL_PPPD_OPTS variable in the existence check to allow space charaters. Signed-off-by: Guillaume Nault --- contrib/debian/accel-ppp-init | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/debian/accel-ppp-init b/contrib/debian/accel-ppp-init index 08120cd..cc62525 100755 --- a/contrib/debian/accel-ppp-init +++ b/contrib/debian/accel-ppp-init @@ -5,7 +5,7 @@ # Required-Start: $networking # Required-Stop: $networking # Default-Start: 2 3 4 5 -# Default-Stop: 1 +# Default-Stop: 0 1 6 ### END INIT INFO set -e @@ -18,7 +18,7 @@ if test -f /etc/default/accel-ppp; then . /etc/default/accel-ppp fi -if [ -z $ACCEL_PPPD_OPTS ]; then +if [ -z "$ACCEL_PPPD_OPTS" ]; then ACCEL_PPPD_OPTS="-c /etc/accel-ppp.conf" fi -- cgit v1.2.3 From e08cd5d552a80a2d3166ee1be9d49179322a553c Mon Sep 17 00:00:00 2001 From: Guillaume Nault Date: Fri, 26 Apr 2013 10:22:18 +0200 Subject: l2tp: Fix PPP channel name Allocate space for the terminationg null byte, to avoid truncating PPP channel name. Signed-off-by: Guillaume Nault --- accel-pppd/ctrl/l2tp/l2tp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index 79d003e..ffcbb8a 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -1221,16 +1221,16 @@ static int l2tp_session_connect(struct l2tp_sess_t *sess) " snprintf() failed: %s\n", strerror(errno)); goto out_err; } - sess->ppp.ses.chan_name = _malloc(chan_sz); + sess->ppp.ses.chan_name = _malloc(chan_sz + 1); if (sess->ppp.ses.chan_name == NULL) { log_session(log_error, sess, "impossible to connect session:" " memory allocation failed\n"); goto out_err; } - if (snprintf(sess->ppp.ses.chan_name, chan_sz, "%s:%i session %i", + if (snprintf(sess->ppp.ses.chan_name, chan_sz + 1, "%s:%i session %i", addr, peer_port, sess->peer_sid) < 0) { log_session(log_error, sess, "impossible to connect session:" - " snprintf(%i) failed\n", chan_sz); + " snprintf(%i) failed\n", chan_sz + 1); goto out_err; } -- cgit v1.2.3 From add08049bf0437e5b0821250127c2f36962aa60e Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Thu, 23 May 2013 21:29:09 +0400 Subject: ipoe: implemented nat option (default 0) --- accel-pppd/ctrl/ipoe/ipoe.c | 32 ++++++++++++++++++++++++-------- accel-pppd/ctrl/ipoe/ipoe.h | 1 + 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index 64bc02a..65b526f 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -49,6 +49,7 @@ static int conf_up = 0; static int conf_mode = 0; static int conf_shared = 1; static int conf_ifcfg = 1; +static int conf_nat = 0; //static int conf_dhcpv6; static int conf_username; static int conf_unit_cache; @@ -372,8 +373,9 @@ static void ipoe_session_start(struct ipoe_session *ses) return; } } - - ses->ses.ipv4 = ipdb_get_ipv4(&ses->ses); + + if (ses->serv->opt_nat) + ses->ses.ipv4 = ipdb_get_ipv4(&ses->ses); if (ses->serv->opt_shared == 0 && (!ses->ses.ipv4 || ses->ses.ipv4->peer_addr == ses->yiaddr)) { strncpy(ses->ses.ifname, ses->serv->ifname, AP_IFNAME_LEN); @@ -432,14 +434,18 @@ static void __ipoe_session_start(struct ipoe_session *ses) ses->dhcp_addr = 1; } + if (!ses->yiaddr && !ses->serv->opt_nat) + ses->ses.ipv4 = ipdb_get_ipv4(&ses->ses); + + if (!ses->mask) + ses->mask = conf_netmask; + if (ses->ses.ipv4) { if (conf_gw_address) ses->ses.ipv4->addr = conf_gw_address; - if (conf_netmask) - ses->ses.ipv4->mask = conf_netmask; - else if (!ses->ses.ipv4->mask) - ses->ses.ipv4->mask = 24; + if (!ses->mask) + ses->mask = ses->ses.ipv4->mask; if (!ses->yiaddr) ses->yiaddr = ses->ses.ipv4->peer_addr; @@ -550,7 +556,7 @@ static void ipoe_ifcfg_add(struct ipoe_session *ses) } if (iproute_add(serv->ifindex, ses->siaddr, ses->yiaddr)) log_ppp_warn("ipoe: failed to add route to interface '%s'\n", serv->ifname); - } else if (iproute_add(serv->ifindex, 0, ses->yiaddr)) + } else if (iproute_add(serv->ifindex, ses->siaddr, ses->yiaddr)) log_ppp_warn("ipoe: failed to add route to interface '%s'\n", serv->ifname); ses->ifcfg = 1; @@ -1414,6 +1420,7 @@ static void add_interface(const char *ifname, int ifindex, const char *opt) int opt_up = 0; int opt_mode = conf_mode; int opt_ifcfg = conf_ifcfg; + int opt_nat = conf_nat; const char *opt_relay = conf_relay; const char *opt_giaddr = NULL; in_addr_t relay_addr = 0; @@ -1466,6 +1473,8 @@ static void add_interface(const char *ifname, int ifindex, const char *opt) } else if (strcmp(str, "giaddr") == 0) { opt_giaddr = ptr1; giaddr = inet_addr(ptr1); + } else if (strcmp(str, "nat") == 0) { + opt_nat = atoi(ptr1); } if (end) @@ -1521,7 +1530,7 @@ static void add_interface(const char *ifname, int ifindex, const char *opt) serv->opt_up = opt_up; serv->opt_mode = opt_mode; serv->opt_ifcfg = opt_ifcfg; - + serv->opt_nat = opt_nat; if (str0) _free(str0); @@ -1539,6 +1548,7 @@ static void add_interface(const char *ifname, int ifindex, const char *opt) serv->opt_up = opt_up; serv->opt_mode = opt_mode; serv->opt_ifcfg = opt_ifcfg; + serv->opt_nat = opt_nat; serv->active = 1; INIT_LIST_HEAD(&serv->sessions); INIT_LIST_HEAD(&serv->addr_list); @@ -1844,6 +1854,12 @@ static void load_config(void) else conf_ifcfg = 1; + opt = conf_get_opt("ipoe", "nat"); + if (opt) + conf_nat = atoi(opt); + else + conf_nat = 0; + opt = conf_get_opt("ipoe", "mode"); if (opt) { if (!strcmp(opt, "L2")) diff --git a/accel-pppd/ctrl/ipoe/ipoe.h b/accel-pppd/ctrl/ipoe/ipoe.h index 96920a3..034092e 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.h +++ b/accel-pppd/ctrl/ipoe/ipoe.h @@ -26,6 +26,7 @@ struct ipoe_serv int opt_dhcpv4:1; int opt_up:1; int opt_ifcfg:1; + int opt_nat:1; int need_close:1; }; -- cgit v1.2.3 From 2a9676f4663a3332fd02ed05035cac1c47d181f3 Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Thu, 23 May 2013 21:30:37 +0400 Subject: chap-secrets: add netmask support --- accel-pppd/extra/chap-secrets.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/accel-pppd/extra/chap-secrets.c b/accel-pppd/extra/chap-secrets.c index 47d5983..94e441d 100644 --- a/accel-pppd/extra/chap-secrets.c +++ b/accel-pppd/extra/chap-secrets.c @@ -25,6 +25,7 @@ static char *def_chap_secrets = "/etc/ppp/chap-secrets"; static char *conf_chap_secrets; static int conf_encrypted; static in_addr_t conf_gw_ip_address = 0; +static int conf_netmask; static void *pd_key; static struct ipdb_t ipdb; @@ -225,6 +226,7 @@ found: pd->ip.addr = conf_gw_ip_address; if (n >= 3 && ptr[2][0] != '*') pd->ip.peer_addr = inet_addr(ptr[2]); + pd->ip.mask = conf_netmask; pd->ip.owner = &ipdb; if (n >= 4) @@ -701,6 +703,26 @@ static void parse_hash_chain(const char *opt) } #endif +static void parse_gw_ip_address(const char *opt) +{ + char addr[17]; + const char *ptr = strchr(opt, '/'); + + if (ptr) { + memcpy(addr, opt, ptr - opt); + addr[ptr - opt] = 0; + conf_gw_ip_address = inet_addr(addr); + conf_netmask = atoi(ptr + 1); + if (conf_netmask < 0 || conf_netmask > 32) { + log_error("chap-secrets: invalid netmask %i\n", conf_netmask); + conf_netmask = 32; + } + } else { + conf_gw_ip_address = inet_addr(opt); + conf_netmask = 32; + } +} + static void load_config(void) { const char *opt; @@ -715,7 +737,10 @@ static void load_config(void) opt = conf_get_opt("chap-secrets", "gw-ip-address"); if (opt) - conf_gw_ip_address = inet_addr(opt); + parse_gw_ip_address(opt); + else { + conf_gw_ip_address = 0; + } opt = conf_get_opt("chap-secrets", "encrypted"); if (opt) -- cgit v1.2.3 From de677ffd0e12f966c6d871e1343ccd5c517ad44c Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Thu, 23 May 2013 21:48:42 +0400 Subject: shaper: fixed 'shaper restore' command --- accel-pppd/accel-ppp.conf.5 | 4 ++-- accel-pppd/shaper/shaper.c | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/accel-pppd/accel-ppp.conf.5 b/accel-pppd/accel-ppp.conf.5 index 0518042..dd0d255 100644 --- a/accel-pppd/accel-ppp.conf.5 +++ b/accel-pppd/accel-ppp.conf.5 @@ -596,8 +596,8 @@ If specified and greated then zero pppd_module will produce verbose logging. .br Configuration of chap-secrets module. .TP -.BI "gw-ip-address=" x.x.x.x -Specifies address to use as local address of ppp interfaces if chap-secrets is used for IP address assignment. +.BI "gw-ip-address=" x.x.x.x[/mask] +Specifies address to use as local address of ppp interfaces if chap-secrets is used for IP address assignment. Mask is used for IPoE. .TP .BI "chap-secrets=" file Specifies alternate chap-secrets file location (default is /etc/ppp/chap-secrets). diff --git a/accel-pppd/shaper/shaper.c b/accel-pppd/shaper/shaper.c index 5e6b576..34a0988 100644 --- a/accel-pppd/shaper/shaper.c +++ b/accel-pppd/shaper/shaper.c @@ -546,9 +546,6 @@ static int shaper_restore_exec(const char *cmd, char * const *f, int f_cnt, void { struct shaper_pd_t *pd; int all, found = 0;; - int *ptr = 0; - - *ptr = 1; if (f_cnt != 3) return CLI_CMD_SYNTAX; -- cgit v1.2.3 From cf27bf49df5243237acb15389fb5544f5a863685 Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Thu, 23 May 2013 21:57:16 +0400 Subject: cli: fixed 'restart' command (do soft restart, i.e. terminate sessions by default) --- accel-pppd/cli/std_cmd.c | 16 ++++++++-------- accel-pppd/ctrl/ipoe/ipoe.c | 3 --- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/accel-pppd/cli/std_cmd.c b/accel-pppd/cli/std_cmd.c index 7a890d1..38198a2 100644 --- a/accel-pppd/cli/std_cmd.c +++ b/accel-pppd/cli/std_cmd.c @@ -343,13 +343,17 @@ static void reload_help(char * const *fields, int fields_cnt, void *client) static void __do_restart(void) { +#ifdef USE_BACKUP core_restart(0); +#else + core_restart(1); +#endif _exit(0); } static int restart_exec(const char *cmd, char * const *f, int f_cnt, void *cli) { - int hard; + int hard = 0; if (f_cnt == 2) { if (strcmp(f[1], "soft") == 0) @@ -365,16 +369,12 @@ static int restart_exec(const char *cmd, char * const *f, int f_cnt, void *cli) else return CLI_CMD_SYNTAX; -#ifndef USE_BACKUP - hard = 1; -#endif - if (hard) { - ap_shutdown_soft(__do_restart); - terminate_all_sessions(0); - } else { core_restart(1); _exit(0); + } else { + ap_shutdown_soft(__do_restart); + terminate_all_sessions(0); } return CLI_CMD_OK; diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index 65b526f..7fcfa26 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -570,9 +570,6 @@ static void ipoe_ifcfg_del(struct ipoe_session *ses) log_ppp_warn("ipoe: failed to delete route from interface '%s'\n", serv->ifname); if (ses->serv->opt_ifcfg) { - if (iproute_del(serv->ifindex, ses->yiaddr)) - log_ppp_warn("ipoe: failed to delete route from interface '%s'\n", serv->ifname); - if (ses->serv->opt_shared) { ipoe_serv_del_addr(ses->serv, ses->siaddr); } else { -- cgit v1.2.3