diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/birdlib.h | 1 | ||||
-rw-r--r-- | lib/ip.h | 1 | ||||
-rw-r--r-- | lib/lists.c | 12 | ||||
-rw-r--r-- | lib/lists.h | 1 | ||||
-rw-r--r-- | lib/net.c | 18 | ||||
-rw-r--r-- | lib/net.h | 2 | ||||
-rw-r--r-- | lib/unaligned.h | 18 |
7 files changed, 53 insertions, 0 deletions
diff --git a/lib/birdlib.h b/lib/birdlib.h index c352b7f6..bb19df54 100644 --- a/lib/birdlib.h +++ b/lib/birdlib.h @@ -35,6 +35,7 @@ #define DELTA(a,b) (((a)>=(b))?(a)-(b):(b)-(a)) #define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a))) #define CALL(fn, args...) ({ if (fn) fn(args); }) +#define ADVANCE(w, r, l) ({ r -= l; w += l; }) static inline int uint_cmp(uint i1, uint i2) { return (int)(i1 > i2) - (int)(i1 < i2); } @@ -91,6 +91,7 @@ typedef ip6_addr ip_addr; #define ipa_to_u32(x) ip4_to_u32(ipa_to_ip4(x)) #define ipa_is_ip4(a) ip6_is_v4mapped(a) +#define ipa_is_ip6(a) (! ip6_is_v4mapped(a)) #define IPA_NONE4 ipa_from_ip4(IP4_NONE) #define IPA_NONE6 ipa_from_ip6(IP6_NONE) diff --git a/lib/lists.c b/lib/lists.c index 12ef3cc6..4a48d3b7 100644 --- a/lib/lists.c +++ b/lib/lists.c @@ -158,3 +158,15 @@ add_tail_list(list *to, list *l) q->next = &to->tail_node; to->tail = q; } + +LIST_INLINE uint +list_length(list *l) +{ + uint len = 0; + node *n; + + WALK_LIST(n, *l) + len++; + + return len; +} diff --git a/lib/lists.h b/lib/lists.h index 46b33446..066eafbb 100644 --- a/lib/lists.h +++ b/lib/lists.h @@ -80,6 +80,7 @@ void rem_node(node *); void add_tail_list(list *, list *); void init_list(list *); void insert_node(node *, node *); +uint list_length(list *); #endif #endif @@ -109,6 +109,24 @@ net_compare(const net_addr *a, const net_addr *b) return 0; } +#define NET_HASH(a,t) net_hash_##t((const net_addr_##t *) a) + +u32 +net_hash(const net_addr *n) +{ + switch (n->type) + { + case NET_IP4: return NET_HASH(n, ip4); + case NET_IP6: return NET_HASH(n, ip6); + case NET_VPN4: return NET_HASH(n, vpn4); + case NET_VPN6: return NET_HASH(n, vpn6); + case NET_ROA4: return NET_HASH(n, roa4); + case NET_ROA6: return NET_HASH(n, roa6); + default: bug("invalid type"); + } +} + + int net_validate(const net_addr *N) { @@ -321,6 +321,8 @@ static inline u32 net_hash_roa4(const net_addr_roa4 *n) static inline u32 net_hash_roa6(const net_addr_roa6 *n) { return ip6_hash(n->prefix) ^ ((u32) n->pxlen << 26); } +u32 net_hash(const net_addr *a); + static inline int net_validate_ip4(const net_addr_ip4 *n) { diff --git a/lib/unaligned.h b/lib/unaligned.h index ad5811ab..4e841f3a 100644 --- a/lib/unaligned.h +++ b/lib/unaligned.h @@ -69,4 +69,22 @@ put_u64(void *p, u64 x) memcpy(p+4, &xl, 4); } +static inline void +get_u32s(const void *p, u32 *x, int n) +{ + int i; + memcpy(x, p, 4*n); + for (i = 0; i < n; i++) + x[i] = ntohl(x[i]); +} + +static inline void +put_u32s(void *p, const u32 *x, int n) +{ + int i; + for (i = 0; i < n; i++) + put_u32((byte *) p + 4*i, x[i]); +} + + #endif |