summaryrefslogtreecommitdiff
path: root/lib/net.c
diff options
context:
space:
mode:
authorJan Moskyto Matejka <mq@ucw.cz>2015-12-16 10:25:12 +0100
committerOndrej Zajicek (work) <santiago@crfreenet.org>2015-12-19 23:49:47 +0100
commit5e173e9f631913f68cf38d57a69c3ce6faf60d1e (patch)
treeaa873aa790686a108cab830c63cae1f946f61e96 /lib/net.c
parentd7661fbe9dea980c61daa01a11a9aa59fa7be426 (diff)
Stop perusing f_prefix for non-prefix-set uses
Multiple changes by Ondrej Santiago Zajicek
Diffstat (limited to 'lib/net.c')
-rw-r--r--lib/net.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/net.c b/lib/net.c
index 21486a9b..e2765995 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -58,23 +58,30 @@ net_pxmask(const net_addr *a)
}
}
-
-static inline int net_validate_ip4(const net_addr_ip4 *n)
+int
+net_compare(const net_addr *a, const net_addr *b)
{
- return (n->pxlen <= IP4_MAX_PREFIX_LENGTH) &&
- ip4_zero(ip4_and(n->prefix, ip4_not(ip4_mkmask(n->pxlen))));
-}
+ if (a->type != b->type)
+ return uint_cmp(a->type, b->type);
-static inline int net_validate_ip6(const net_addr_ip6 *n)
-{
- return (n->pxlen <= IP6_MAX_PREFIX_LENGTH) &&
- ip6_zero(ip6_and(n->prefix, ip6_not(ip6_mkmask(n->pxlen))));
+ switch (a->type)
+ {
+ case NET_IP4:
+ return net_compare_ip4((const net_addr_ip4 *) a, (const net_addr_ip4 *) b);
+ case NET_IP6:
+ return net_compare_ip6((const net_addr_ip6 *) a, (const net_addr_ip6 *) b);
+ case NET_VPN4:
+ return net_compare_vpn4((const net_addr_vpn4 *) a, (const net_addr_vpn4 *) b);
+ case NET_VPN6:
+ return net_compare_vpn6((const net_addr_vpn6 *) a, (const net_addr_vpn6 *) b);
+ }
+ return 0;
}
int
net_validate(const net_addr *N)
{
- switch (a->type)
+ switch (N->type)
{
case NET_IP4:
case NET_VPN4: