summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/birdlib.h1
-rw-r--r--lib/lists.h5
-rw-r--r--lib/net.c7
-rw-r--r--lib/net.h17
4 files changed, 29 insertions, 1 deletions
diff --git a/lib/birdlib.h b/lib/birdlib.h
index 9ffe0070..ece50dc2 100644
--- a/lib/birdlib.h
+++ b/lib/birdlib.h
@@ -34,6 +34,7 @@
#define ABS(a) ((a)>=0 ? (a) : -(a))
#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); })
static inline int uint_cmp(uint i1, uint i2)
{ return (int)(i1 > i2) - (int)(i1 < i2); }
diff --git a/lib/lists.h b/lib/lists.h
index 80a4dc93..d75f033d 100644
--- a/lib/lists.h
+++ b/lib/lists.h
@@ -39,7 +39,10 @@ typedef struct list { /* In fact two overlayed nodes */
#define WALK_LIST2(n,nn,list,pos) \
for(nn=(list).head; NODE_VALID(nn) && (n=SKIP_BACK(typeof(*n),pos,nn)); nn=nn->next)
#define WALK_LIST_DELSAFE(n,nxt,list) \
- for(n=HEAD(list); nxt=NODE_NEXT(n); n=(void *) nxt)
+ for(n=HEAD(list); nxt=NODE_NEXT(n); n=(void *) nxt)
+#define WALK_LIST2_DELSAFE(n,nn,nxt,list,pos) \
+ for(nn=HEAD(list); (nxt=nn->next) && (n=SKIP_BACK(typeof(*n),pos,nn)); nn=nxt)
+
/* WALK_LIST_FIRST supposes that called code removes each processed node */
#define WALK_LIST_FIRST(n,list) \
while(n=HEAD(list), (NODE (n))->next)
diff --git a/lib/net.c b/lib/net.c
index d03a03b7..71fbe6ff 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -4,6 +4,13 @@
#include "lib/net.h"
+const char * const net_label[] = {
+ [NET_IP4] = "ipv4",
+ [NET_IP6] = "ipv6",
+ [NET_VPN4] = "vpn4",
+ [NET_VPN6] = "vpn6"
+};
+
const u16 net_addr_length[] = {
[NET_IP4] = sizeof(net_addr_ip4),
[NET_IP6] = sizeof(net_addr_ip6),
diff --git a/lib/net.h b/lib/net.h
index dd6e597a..fbce2811 100644
--- a/lib/net.h
+++ b/lib/net.h
@@ -21,6 +21,15 @@
#define NET_ROA6 6
#define NET_MAX 7
+#define NB_IP4 (1 << NET_IP4)
+#define NB_IP6 (1 << NET_IP6)
+#define NB_VPN4 (1 << NET_VPN4)
+#define NB_VPN6 (1 << NET_VPN6)
+
+#define NB_IP (NB_IP4 | NB_IP6)
+#define NB_ANY 0xffffffff
+
+
typedef struct net_addr {
u8 type;
u8 pxlen;
@@ -88,6 +97,7 @@ typedef union net_addr_union {
} net_addr_union;
+extern const char * const net_label[];
extern const u16 net_addr_length[];
extern const u8 net_max_prefix_length[];
extern const u16 net_max_text_length[];
@@ -149,6 +159,13 @@ static inline void net_fill_ip_host(net_addr *a, ip_addr prefix)
net_fill_ip6(a, ipa_to_ip6(prefix), IP6_MAX_PREFIX_LENGTH);
}
+
+static inline int net_val_match(u8 type, u32 mask)
+{ return !!((1 << type) & mask); }
+
+static inline int net_type_match(const net_addr *a, u32 mask)
+{ return net_val_match(a->type, mask); }
+
static inline int net_is_ip(const net_addr *a)
{ return (a->type == NET_IP4) || (a->type == NET_IP6); }