summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2017-12-07 17:41:09 +0100
committerOndrej Zajicek (work) <santiago@crfreenet.org>2017-12-07 17:41:09 +0100
commit4ff15a75c56531fa2d3858d8250dcef1af4e75b6 (patch)
tree8410799a1bf43210ac4fe600595488a2907149e2 /lib
parentcd80c9b0700ef9533a19ab19d66c38a1722c4e08 (diff)
parent98bb80a243b58c43453e9be69d19d0350286549c (diff)
Merge commit '98bb80a243b58c43453e9be69d19d0350286549c' into int-new
Diffstat (limited to 'lib')
-rw-r--r--lib/net.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/net.h b/lib/net.h
index 332f4c9a..cae3a749 100644
--- a/lib/net.h
+++ b/lib/net.h
@@ -526,6 +526,18 @@ int net_classify(const net_addr *N);
int net_format(const net_addr *N, char *buf, int buflen);
int rd_format(const u64 rd, char *buf, int buflen);
+static inline int ipa_in_net_ip4(ip4_addr a, const net_addr_ip4 *n)
+{ return ip4_zero(ip4_and(ip4_xor(a, n->prefix), ip4_mkmask(n->pxlen))); }
+
+static inline int net_in_net_ip4(const net_addr_ip4 *a, const net_addr_ip4 *b)
+{ return (a->pxlen >= b->pxlen) && ipa_in_net_ip4(a->prefix, b); }
+
+static inline int ipa_in_net_ip6(ip6_addr a, const net_addr_ip6 *n)
+{ return ip6_zero(ip6_and(ip6_xor(a, n->prefix), ip6_mkmask(n->pxlen))); }
+
+static inline int net_in_net_ip6(const net_addr_ip6 *a, const net_addr_ip6 *b)
+{ return (a->pxlen >= b->pxlen) && ipa_in_net_ip6(a->prefix, b); }
+
int ipa_in_netX(const ip_addr A, const net_addr *N);
int net_in_netX(const net_addr *A, const net_addr *N);