summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2016-12-07 14:11:28 +0100
committerOndrej Zajicek (work) <santiago@crfreenet.org>2016-12-07 14:20:52 +0100
commitd15b0b0a1b494c14b139d2d28706d82cd6e2f139 (patch)
treef704869689e1acab9a4f3417849ac5853188310d /lib
parent5df4073c81942ea119de90a81431bae71c87157b (diff)
BGP redesign
Integrated and extensible BGP with generalized AFI handling, support for IPv4+IPv6 AFI and unicast+multicast SAFI.
Diffstat (limited to 'lib')
-rw-r--r--lib/birdlib.h1
-rw-r--r--lib/ip.h1
-rw-r--r--lib/lists.c12
-rw-r--r--lib/lists.h1
-rw-r--r--lib/net.c18
-rw-r--r--lib/net.h2
-rw-r--r--lib/unaligned.h18
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); }
diff --git a/lib/ip.h b/lib/ip.h
index 6541ce1e..86750675 100644
--- a/lib/ip.h
+++ b/lib/ip.h
@@ -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
diff --git a/lib/net.c b/lib/net.c
index 55eec4b5..53991b4c 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -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)
{
diff --git a/lib/net.h b/lib/net.h
index d9137c4a..9b22c6be 100644
--- a/lib/net.h
+++ b/lib/net.h
@@ -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