mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-11-08 12:18:42 +00:00
Refactoring of net_route
This commit is contained in:
parent
3b48dc9bce
commit
9a91ea52db
178
nest/rt-table.c
178
nest/rt-table.c
@ -145,66 +145,6 @@ net_init_with_trie(struct fib *f, void *N)
|
||||
trie_add_prefix(tab->trie_new, n->n.addr, n->n.addr->pxlen, n->n.addr->pxlen);
|
||||
}
|
||||
|
||||
static inline net *
|
||||
net_route_ip4_trie(rtable *t, const net_addr_ip4 *n0)
|
||||
{
|
||||
TRIE_WALK_TO_ROOT_IP4(t->trie, n0, n)
|
||||
{
|
||||
net *r;
|
||||
if (r = net_find_valid(t, (net_addr *) &n))
|
||||
return r;
|
||||
}
|
||||
TRIE_WALK_TO_ROOT_END;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline net *
|
||||
net_route_vpn4_trie(rtable *t, const net_addr_vpn4 *n0)
|
||||
{
|
||||
TRIE_WALK_TO_ROOT_IP4(t->trie, (const net_addr_ip4 *) n0, px)
|
||||
{
|
||||
net_addr_vpn4 n = NET_ADDR_VPN4(px.prefix, px.pxlen, n0->rd);
|
||||
|
||||
net *r;
|
||||
if (r = net_find_valid(t, (net_addr *) &n))
|
||||
return r;
|
||||
}
|
||||
TRIE_WALK_TO_ROOT_END;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline net *
|
||||
net_route_ip6_trie(rtable *t, const net_addr_ip6 *n0)
|
||||
{
|
||||
TRIE_WALK_TO_ROOT_IP6(t->trie, n0, n)
|
||||
{
|
||||
net *r;
|
||||
if (r = net_find_valid(t, (net_addr *) &n))
|
||||
return r;
|
||||
}
|
||||
TRIE_WALK_TO_ROOT_END;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline net *
|
||||
net_route_vpn6_trie(rtable *t, const net_addr_vpn6 *n0)
|
||||
{
|
||||
TRIE_WALK_TO_ROOT_IP6(t->trie, (const net_addr_ip6 *) n0, px)
|
||||
{
|
||||
net_addr_vpn6 n = NET_ADDR_VPN6(px.prefix, px.pxlen, n0->rd);
|
||||
|
||||
net *r;
|
||||
if (r = net_find_valid(t, (net_addr *) &n))
|
||||
return r;
|
||||
}
|
||||
TRIE_WALK_TO_ROOT_END;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline void *
|
||||
net_route_ip6_sadr_trie(rtable *t, const net_addr_ip6_sadr *n0)
|
||||
{
|
||||
@ -238,69 +178,6 @@ net_route_ip6_sadr_trie(rtable *t, const net_addr_ip6_sadr *n0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline net *
|
||||
net_route_ip4_fib(rtable *t, const net_addr_ip4 *n0)
|
||||
{
|
||||
net_addr_ip4 n;
|
||||
net_copy_ip4(&n, n0);
|
||||
|
||||
net *r;
|
||||
while (r = net_find_valid(t, (net_addr *) &n), (!r) && (n.pxlen > 0))
|
||||
{
|
||||
n.pxlen--;
|
||||
ip4_clrbit(&n.prefix, n.pxlen);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline net *
|
||||
net_route_vpn4_fib(rtable *t, const net_addr_vpn4 *n0)
|
||||
{
|
||||
net_addr_vpn4 n;
|
||||
net_copy_vpn4(&n, n0);
|
||||
|
||||
net *r;
|
||||
while (r = net_find_valid(t, (net_addr *) &n), (!r) && (n.pxlen > 0))
|
||||
{
|
||||
n.pxlen--;
|
||||
ip4_clrbit(&n.prefix, n.pxlen);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline net *
|
||||
net_route_ip6_fib(rtable *t, const net_addr_ip6 *n0)
|
||||
{
|
||||
net_addr_ip6 n;
|
||||
net_copy_ip6(&n, n0);
|
||||
|
||||
net *r;
|
||||
while (r = net_find_valid(t, (net_addr *) &n), (!r) && (n.pxlen > 0))
|
||||
{
|
||||
n.pxlen--;
|
||||
ip6_clrbit(&n.prefix, n.pxlen);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline net *
|
||||
net_route_vpn6_fib(rtable *t, const net_addr_vpn6 *n0)
|
||||
{
|
||||
net_addr_vpn6 n;
|
||||
net_copy_vpn6(&n, n0);
|
||||
|
||||
net *r;
|
||||
while (r = net_find_valid(t, (net_addr *) &n), (!r) && (n.pxlen > 0))
|
||||
{
|
||||
n.pxlen--;
|
||||
ip6_clrbit(&n.prefix, n.pxlen);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline void *
|
||||
net_route_ip6_sadr_fib(rtable *t, const net_addr_ip6_sadr *n0)
|
||||
@ -346,39 +223,48 @@ net *
|
||||
net_route(rtable *tab, const net_addr *n)
|
||||
{
|
||||
ASSERT(tab->addr_type == n->type);
|
||||
net_addr_union *nu = SKIP_BACK(net_addr_union, n, n);
|
||||
|
||||
switch (n->type)
|
||||
{
|
||||
case NET_IP4:
|
||||
if (tab->trie)
|
||||
return net_route_ip4_trie(tab, (net_addr_ip4 *) n);
|
||||
else
|
||||
return net_route_ip4_fib (tab, (net_addr_ip4 *) n);
|
||||
#define TW(ipv, what) \
|
||||
TRIE_WALK_TO_ROOT_IP##ipv(tab->trie, &(nu->ip##ipv), var) \
|
||||
{ what(ipv, var); } \
|
||||
TRIE_WALK_TO_ROOT_END; return NULL;
|
||||
|
||||
case NET_VPN4:
|
||||
if (tab->trie)
|
||||
return net_route_vpn4_trie(tab, (net_addr_vpn4 *) n);
|
||||
else
|
||||
return net_route_vpn4_fib (tab, (net_addr_vpn4 *) n);
|
||||
#define FW(ipv, what) do { \
|
||||
net_addr_union nuc; net_copy(&nuc.n, n); \
|
||||
while (1) { \
|
||||
what(ipv, nuc.ip##ipv); if (!nuc.n.pxlen) return NULL; \
|
||||
nuc.n.pxlen--; ip##ipv##_clrbit(&nuc.ip##ipv.prefix, nuc.ip##ipv.pxlen); \
|
||||
} \
|
||||
} while(0); return NULL;
|
||||
|
||||
case NET_IP6:
|
||||
if (tab->trie)
|
||||
return net_route_ip6_trie(tab, (net_addr_ip6 *) n);
|
||||
else
|
||||
return net_route_ip6_fib (tab, (net_addr_ip6 *) n);
|
||||
#define FVR_IP(ipv, var) \
|
||||
net *r; if (r = net_find_valid(tab, (net_addr *) &var)) return r;
|
||||
|
||||
#define FVR_VPN(ipv, var) \
|
||||
net_addr_vpn##ipv _var0 = NET_ADDR_VPN##ipv(var.prefix, var.pxlen, nu->vpn##ipv.rd); FVR_IP(ipv, _var0);
|
||||
|
||||
case NET_VPN6:
|
||||
if (tab->trie)
|
||||
return net_route_vpn6_trie(tab, (net_addr_vpn6 *) n);
|
||||
else
|
||||
return net_route_vpn6_fib (tab, (net_addr_vpn6 *) n);
|
||||
switch (n->type) {
|
||||
case NET_IP4: TW(4, FVR_IP);
|
||||
case NET_VPN4: TW(4, FVR_VPN);
|
||||
case NET_IP6: TW(6, FVR_IP);
|
||||
case NET_VPN6: TW(6, FVR_VPN);
|
||||
|
||||
case NET_IP6_SADR:
|
||||
if (tab->trie)
|
||||
return net_route_ip6_sadr_trie(tab, (net_addr_ip6_sadr *) n);
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
return net_route_ip6_sadr_fib (tab, (net_addr_ip6_sadr *) n);
|
||||
switch (n->type) {
|
||||
case NET_IP4: FW(4, FVR_IP);
|
||||
case NET_VPN4: FW(4, FVR_VPN);
|
||||
case NET_IP6: FW(6, FVR_IP);
|
||||
case NET_VPN6: FW(6, FVR_VPN);
|
||||
|
||||
case NET_IP6_SADR:
|
||||
return net_route_ip6_sadr_fib (tab, (net_addr_ip6_sadr *) n);
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user