diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2013-05-23 21:30:37 +0400 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2013-05-23 21:30:37 +0400 |
commit | 2a9676f4663a3332fd02ed05035cac1c47d181f3 (patch) | |
tree | 6416522bee89af2cdf7abcac26c72112746e1457 /accel-pppd/extra | |
parent | add08049bf0437e5b0821250127c2f36962aa60e (diff) | |
download | accel-ppp-2a9676f4663a3332fd02ed05035cac1c47d181f3.tar.gz accel-ppp-2a9676f4663a3332fd02ed05035cac1c47d181f3.zip |
chap-secrets: add netmask support
Diffstat (limited to 'accel-pppd/extra')
-rw-r--r-- | accel-pppd/extra/chap-secrets.c | 27 |
1 files changed, 26 insertions, 1 deletions
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) |