From cd9bb5cfe3afec23ef62f2aa2ed82e6dd04a32f9 Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Mon, 25 Dec 2017 17:55:52 +0300 Subject: 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. --- accel-pppd/extra/ipv6pool.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'accel-pppd/extra') 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); -- cgit v1.2.3