Set interface with longest prefix in DHCP & DHCPv6 lease

- With nested prefixes reside on different interfaces of single host

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

  current matching mechanism might return the interface with shorter prefix

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

Signed-off-by: Lung-Pin Chang <changlp@cs.nctu.edu.tw>
This commit is contained in:
Lung-Pin Chang
2014-07-02 10:48:05 +08:00
parent cdb755c5f1
commit dc8a1b1bcf
3 changed files with 47 additions and 9 deletions

View File

@@ -319,6 +319,18 @@ time_t dnsmasq_time(void)
#endif
}
int netmask_length(struct in_addr mask)
{
int zero_count = 0;
while (0x0 == (mask.s_addr & 0x1)) {
mask.s_addr >>= 1;
++zero_count;
}
return 32 - zero_count;
}
int is_same_net(struct in_addr a, struct in_addr b, struct in_addr mask)
{
return (a.s_addr & mask.s_addr) == (b.s_addr & mask.s_addr);