diff options
author | Kozlov Dmitry <xeb@mail.ru> | 2013-06-04 15:37:57 +0400 |
---|---|---|
committer | Kozlov Dmitry <xeb@mail.ru> | 2013-06-04 15:37:57 +0400 |
commit | 45156b684e0bd404215183d1368ad8694f29075e (patch) | |
tree | 28b2cb7abdebf9f1763968ddf0820647b894b2b2 /accel-pppd | |
parent | b267b9c39ed7177b466db6c8b5b3f8c3dc6d7758 (diff) | |
parent | cf27bf49df5243237acb15389fb5544f5a863685 (diff) | |
download | accel-ppp-45156b684e0bd404215183d1368ad8694f29075e.tar.gz accel-ppp-45156b684e0bd404215183d1368ad8694f29075e.zip |
Merge branch 'master' of ssh://git.code.sf.net/p/accel-ppp/code
Diffstat (limited to 'accel-pppd')
-rw-r--r-- | accel-pppd/accel-ppp.conf.5 | 4 | ||||
-rw-r--r-- | accel-pppd/cli/std_cmd.c | 16 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe.c | 35 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe.h | 1 | ||||
-rw-r--r-- | accel-pppd/ctrl/l2tp/l2tp.c | 6 | ||||
-rw-r--r-- | accel-pppd/extra/chap-secrets.c | 27 | ||||
-rw-r--r-- | accel-pppd/shaper/shaper.c | 3 |
7 files changed, 64 insertions, 28 deletions
diff --git a/accel-pppd/accel-ppp.conf.5 b/accel-pppd/accel-ppp.conf.5 index 9d29568a..a6c51897 100644 --- a/accel-pppd/accel-ppp.conf.5 +++ b/accel-pppd/accel-ppp.conf.5 @@ -602,8 +602,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/cli/std_cmd.c b/accel-pppd/cli/std_cmd.c index 7a890d1a..38198a2f 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 4c3c585c..a2991f42 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; @@ -564,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 { @@ -1414,6 +1417,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 +1470,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 +1527,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 +1545,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 +1851,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 96920a38..034092e1 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; }; diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index 0d27f50f..f109fbc9 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -1222,16 +1222,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; } diff --git a/accel-pppd/extra/chap-secrets.c b/accel-pppd/extra/chap-secrets.c index 47d59830..94e441de 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) diff --git a/accel-pppd/shaper/shaper.c b/accel-pppd/shaper/shaper.c index 5e6b576c..34a0988c 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; |