summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>1998-06-01 23:36:58 +0200
committerMartin Mares <mj@ucw.cz>1998-06-01 23:36:58 +0200
commit0fe3b28b68f10a32f3fe43e8221559a72be5ca28 (patch)
tree3ad21f20008709e91afdd2c50420732c3f24fc31 /lib
parentaf847acc27978cf48721aafbacab70e48f42ede7 (diff)
downloadbird-0fe3b28b68f10a32f3fe43e8221559a72be5ca28.tar
bird-0fe3b28b68f10a32f3fe43e8221559a72be5ca28.zip
Added ipa_xor() and ipa_in_net().
Diffstat (limited to 'lib')
-rw-r--r--lib/ip.h2
-rw-r--r--lib/ipv4.h1
-rw-r--r--lib/ipv6.h4
3 files changed, 7 insertions, 0 deletions
diff --git a/lib/ip.h b/lib/ip.h
index 87cd3aa..5bf56fc 100644
--- a/lib/ip.h
+++ b/lib/ip.h
@@ -15,6 +15,8 @@
#include "ipv6.h"
#endif
+#define ipa_in_net(x,n,p) (!ipa_nonzero(ipa_and(ipa_xor((n),(x)),ipa_mkmask(p))))
+
/*
* ip_classify() returns either a negative number for invalid addresses
* or scope OR'ed together with address type.
diff --git a/lib/ipv4.h b/lib/ipv4.h
index add406b..af2194c 100644
--- a/lib/ipv4.h
+++ b/lib/ipv4.h
@@ -44,6 +44,7 @@ typedef u32 ip_addr;
#define ipa_nonzero(x) _I(x)
#define ipa_and(x,y) _MI(_I(x) & _I(y))
#define ipa_or(x,y) _MI(_I(x) | _I(y))
+#define ipa_xor(x,y) _MI(_I(x) ^ _I(y))
#define ipa_not(x) _MI(~_I(x))
#define ipa_mkmask(x) _MI(u32_mkmask(x))
#define ipa_mklen(x) u32_masklen(_I(x))
diff --git a/lib/ipv6.h b/lib/ipv6.h
index 08ed5f8..3f775d4 100644
--- a/lib/ipv6.h
+++ b/lib/ipv6.h
@@ -36,6 +36,10 @@ typedef struct ipv4_addr {
_I1(a) | _I1(b), \
_I2(a) | _I2(b), \
_I3(a) | _I3(b))
+#define ipa_xor(a,b) _MI(_I0(a) ^ _I0(b), \
+ _I1(a) ^ _I1(b), \
+ _I2(a) ^ _I2(b), \
+ _I3(a) ^ _I3(b))
#define ipa_not(a) _MI(~_I0(a),~_I1(a),~_I2(a),~_I3(a))
#define ipa_mkmask(x) ipv6_mkmask(x)
#define ipa_mklen(x) ipv6_mklen(&(x))