diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2017-12-25 17:55:52 +0300 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2017-12-25 17:55:52 +0300 |
commit | cd9bb5cfe3afec23ef62f2aa2ed82e6dd04a32f9 (patch) | |
tree | 2750ae03b9db866569571aa353fc4a699c64ed28 /accel-pppd/extra/ipv6pool.c | |
parent | 2369a4f0049e91dc62914693bea104b3fc54f557 (diff) | |
download | accel-ppp-cd9bb5cfe3afec23ef62f2aa2ed82e6dd04a32f9.tar.gz accel-ppp-cd9bb5cfe3afec23ef62f2aa2ed82e6dd04a32f9.zip |
ipv6pool: added gw-ip6-address option and special handling for /128 prefixes
If pool specified with /128 prefix length, then initialize intf_id by gw_ip6_address and peer_intf_id by generated pool address.
Diffstat (limited to 'accel-pppd/extra/ipv6pool.c')
-rw-r--r-- | accel-pppd/extra/ipv6pool.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/accel-pppd/extra/ipv6pool.c b/accel-pppd/extra/ipv6pool.c index 6887ea32..6fa5cc53 100644 --- a/accel-pppd/extra/ipv6pool.c +++ b/accel-pppd/extra/ipv6pool.c @@ -32,6 +32,7 @@ static LIST_HEAD(ippool); static LIST_HEAD(dppool); static spinlock_t pool_lock; static struct ipdb_t ipdb; +static struct in6_addr conf_gw_addr; static void in6_addr_add(struct in6_addr *res, const struct in6_addr *arg) { @@ -182,18 +183,30 @@ err: static struct ipv6db_item_t *get_ip(struct ap_session *ses) { struct ippool_item_t *it; + struct ipv6db_addr_t *a; spin_lock(&pool_lock); if (!list_empty(&ippool)) { it = list_entry(ippool.next, typeof(*it), entry); list_del(&it->entry); - it->it.intf_id = 0; - it->it.peer_intf_id = 0; } else it = NULL; spin_unlock(&pool_lock); - return it ? &it->it : NULL; + if (it) { + a = list_entry(it->it.addr_list.next, typeof(*a), entry); + if (a->prefix_len == 128) { + memcpy(&it->it.intf_id, conf_gw_addr.s6_addr + 8, 8); + memcpy(&it->it.peer_intf_id, a->addr.s6_addr + 8, 8); + } else { + it->it.intf_id = 0; + it->it.peer_intf_id = 0; + } + + return &it->it; + } + + return NULL; } static void put_ip(struct ap_session *ses, struct ipv6db_item_t *it) @@ -247,7 +260,10 @@ static void ippool_init(void) return; list_for_each_entry(opt, &s->items, entry) { - if (!strcmp(opt->name, "delegate")) + if (!strcmp(opt->name, "gw-ip6-address")) { + if (inet_pton(AF_INET6, opt->val, &conf_gw_addr) == 0) + log_error("ipv6_pool: failed to parse gw-ip6-address\n"); + } else if (!strcmp(opt->name, "delegate")) add_prefix(1, opt->val); else add_prefix(0, opt->name); |