diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2016-01-26 11:48:58 +0100 |
---|---|---|
committer | Jan Moskyto Matejka <mq@ucw.cz> | 2016-02-01 10:28:50 +0100 |
commit | f4a60a9bc429c28cb397402331dc01a789197450 (patch) | |
tree | e8cead76aa1c2aedfb76d7e3ceade2fc4a7214cf /lib | |
parent | 9f5782d9691f23296c4b1a68ef66630d9cc3a6cd (diff) |
Channels - explicit links between protocols and tables
The patch adds support for channels, structures connecting protocols and
tables and handling most interactions between them. The documentation is
missing yet.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/birdlib.h | 1 | ||||
-rw-r--r-- | lib/lists.h | 5 | ||||
-rw-r--r-- | lib/net.c | 7 | ||||
-rw-r--r-- | lib/net.h | 17 |
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) @@ -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), @@ -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); } |