Skip to content

Commit

Permalink
Match interface with longest prefix in IPv6
Browse files Browse the repository at this point in the history
- When several interfaces share the same prefix w/ distinct prefix length

  (e.g., in 6to4, 2002::/16 on WAN and 2002:<IPv4>:<subnet>::/64 on LAN),

  the interface with shorter prefix length might be matched instead of

  the longer one, if it appears later in the netlink message.

Signed-off-by: Lung-Pin Chang <changlp@cs.nctu.edu.tw>
  • Loading branch information
iamben committed Jul 2, 2014
1 parent cdb755c commit 4ee9751
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/dnsmasq.h
Expand Up @@ -640,6 +640,7 @@ struct dhcp_lease {
unsigned char *extradata;
unsigned int extradata_len, extradata_size;
int last_interface;
int last_prefixlen;
#ifdef HAVE_DHCP6
struct in6_addr addr6;
int iaid;
Expand Down
9 changes: 7 additions & 2 deletions src/lease.c
Expand Up @@ -379,8 +379,13 @@ static int find_interface_v6(struct in6_addr *local, int prefix,

for (lease = leases; lease; lease = lease->next)
if ((lease->flags & (LEASE_TA | LEASE_NA)))
if (is_same_net6(local, &lease->addr6, prefix))
lease_set_interface(lease, if_index, *((time_t *)vparam));
if (is_same_net6(local, &lease->addr6, prefix) && prefix > lease->last_prefixlen) {
/* save prefix length for comparison, as we might get shorter matching
* prefix in upcoming netlink GETADDR responses
* */
lease->last_prefixlen = prefix;
lease_set_interface(lease, if_index, *((time_t *)vparam));
}

return 1;
}
Expand Down

0 comments on commit 4ee9751

Please sign in to comment.