summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ip.c2
-rw-r--r--lib/ip.h24
-rw-r--r--lib/net.h21
3 files changed, 22 insertions, 25 deletions
diff --git a/lib/ip.c b/lib/ip.c
index 6205915a..5e039c12 100644
--- a/lib/ip.c
+++ b/lib/ip.c
@@ -67,7 +67,7 @@ ip6_masklen(ip6_addr *a)
if (a->addr[i] != ~0U)
{
j = u32_masklen(a->addr[i]);
- if (j < 0)
+ if (j == 255)
return j;
n += j;
while (++i < 4)
diff --git a/lib/ip.h b/lib/ip.h
index 60a9a7b2..3191e307 100644
--- a/lib/ip.h
+++ b/lib/ip.h
@@ -91,6 +91,9 @@ typedef ip6_addr ip_addr;
#define ipa_is_ip4(a) ip6_is_v4mapped(a)
+#define IPA_NONE4 ipa_from_ip4(IP4_NONE)
+#define IPA_NONE6 ipa_from_ip6(IP6_NONE)
+
/*
* Public constructors
@@ -180,16 +183,7 @@ static inline int ipa_nonzero2(ip_addr a)
* Hash and compare functions
*/
-static inline uint ip4_hash(ip4_addr a)
-{
- /* Returns a 16-bit value */
- u32 x = _I(a);
- x ^= x >> 16;
- x ^= x << 10;
- return x & 0xffff;
-}
-
-static inline u32 ip4_hash32(ip4_addr a)
+static inline u32 ip4_hash(ip4_addr a)
{
/* Returns a 32-bit value, although low-order bits are not mixed */
u32 x = _I(a);
@@ -198,14 +192,7 @@ static inline u32 ip4_hash32(ip4_addr a)
return x;
}
-static inline uint ip6_hash(ip6_addr a)
-{
- /* Returns a 16-bit hash key */
- u32 x = _I0(a) ^ _I1(a) ^ _I2(a) ^ _I3(a);
- return (x ^ (x >> 16) ^ (x >> 8)) & 0xffff;
-}
-
-static inline u32 ip6_hash32(ip6_addr a)
+static inline u32 ip6_hash(ip6_addr a)
{
/* Returns a 32-bit hash key, although low-order bits are not mixed */
u32 x = _I0(a) ^ _I1(a) ^ _I2(a) ^ _I3(a);
@@ -218,7 +205,6 @@ static inline int ip4_compare(ip4_addr a, ip4_addr b)
int ip6_compare(ip6_addr a, ip6_addr b);
#define ipa_hash(x) ip6_hash(x)
-#define ipa_hash32(x) ip6_hash32(x)
#define ipa_compare(x,y) ip6_compare(x,y)
diff --git a/lib/net.h b/lib/net.h
index 9439c6db..b0ab2153 100644
--- a/lib/net.h
+++ b/lib/net.h
@@ -107,6 +107,17 @@ static inline void net_fill_ipa(net_addr *a, ip_addr prefix, uint pxlen)
net_fill_ip6(a, ipa_to_ip6(prefix), pxlen);
}
+static inline void net_fill_ip_host(net_addr *a, ip_addr prefix)
+{
+ if (ipa_is_ip4(prefix))
+ net_fill_ip4(a, ipa_to_ip4(prefix), IP4_MAX_PREFIX_LENGTH);
+ else
+ net_fill_ip6(a, ipa_to_ip6(prefix), IP6_MAX_PREFIX_LENGTH);
+}
+
+static inline int net_is_ip(const net_addr *a)
+{ return (a->type == NET_IP4) || (a->type == NET_IP6); }
+
static inline ip4_addr net4_prefix(const net_addr *a)
{ return ((net_addr_ip4 *) a)->prefix; }
@@ -199,20 +210,20 @@ static inline void net_copy_vpn6(net_addr_vpn6 *dst, const net_addr_vpn6 *src)
static inline u32 net_hash_ip4(const net_addr_ip4 *n)
-{ return ip4_hash32(n->prefix) ^ ((u32) n->pxlen << 26); }
+{ return ip4_hash(n->prefix) ^ ((u32) n->pxlen << 26); }
static inline u32 net_hash_ip6(const net_addr_ip6 *n)
-{ return ip6_hash32(n->prefix) ^ ((u32) n->pxlen << 26); }
+{ return ip6_hash(n->prefix) ^ ((u32) n->pxlen << 26); }
/* XXXX */
-static inline u32 u64_hash(u32 a)
+static inline u32 u64_hash(u64 a)
{ return u32_hash(a); }
static inline u32 net_hash_vpn4(const net_addr_vpn4 *n)
-{ return ip4_hash32(n->prefix) ^ ((u32) n->pxlen << 26) ^ u64_hash(n->rd); }
+{ return ip4_hash(n->prefix) ^ ((u32) n->pxlen << 26) ^ u64_hash(n->rd); }
static inline u32 net_hash_vpn6(const net_addr_vpn6 *n)
-{ return ip6_hash32(n->prefix) ^ ((u32) n->pxlen << 26) ^ u64_hash(n->rd); }
+{ return ip6_hash(n->prefix) ^ ((u32) n->pxlen << 26) ^ u64_hash(n->rd); }
static inline int net_validate_ip4(const net_addr_ip4 *n)