Cleanup and add support for rule->table
This commit is contained in:
parent
abf0c56055
commit
7d8330b9be
43
src/addr.c
43
src/addr.c
@ -105,11 +105,11 @@ bool nd_addr_match(nd_addr_t *first, nd_addr_t *second, int pflen)
|
|||||||
|
|
||||||
static int ndL_count_bits(uint32_t n)
|
static int ndL_count_bits(uint32_t n)
|
||||||
{
|
{
|
||||||
n = (n & 0x55555555u) + ((n >> 1) & 0x55555555u);
|
n = (n & 0x55555555) + ((n >> 1) & 0x55555555);
|
||||||
n = (n & 0x33333333u) + ((n >> 2) & 0x33333333u);
|
n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
|
||||||
n = (n & 0x0f0f0f0fu) + ((n >> 4) & 0x0f0f0f0fu);
|
n = (n & 0x0f0f0f0f) + ((n >> 4) & 0x0f0f0f0f);
|
||||||
n = (n & 0x00ff00ffu) + ((n >> 8) & 0x00ff00ffu);
|
n = (n & 0x00ff00ff) + ((n >> 8) & 0x00ff00ff);
|
||||||
n = (n & 0x0000ffffu) + ((n >> 16) & 0x0000ffffu);
|
n = (n & 0x0000ffff) + ((n >> 16) & 0x0000ffff);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,38 +123,37 @@ void nd_addr_from_pflen(int pflen, nd_addr_t *netmask)
|
|||||||
{
|
{
|
||||||
if (pflen >= 97)
|
if (pflen >= 97)
|
||||||
{
|
{
|
||||||
netmask->s6_addr32[0] = 0xffffffffu;
|
netmask->s6_addr32[0] = 0xffffffff;
|
||||||
netmask->s6_addr32[1] = 0xffffffffu;
|
netmask->s6_addr32[1] = 0xffffffff;
|
||||||
netmask->s6_addr32[2] = 0xffffffffu;
|
netmask->s6_addr32[2] = 0xffffffff;
|
||||||
netmask->s6_addr32[3] = ndL_masks[pflen - 97];
|
netmask->s6_addr32[3] = ndL_masks[pflen - 97];
|
||||||
}
|
}
|
||||||
else if (pflen >= 65)
|
else if (pflen >= 65)
|
||||||
{
|
{
|
||||||
netmask->s6_addr32[0] = 0xffffffffu;
|
netmask->s6_addr32[0] = 0xffffffff;
|
||||||
netmask->s6_addr32[1] = 0xffffffffu;
|
netmask->s6_addr32[1] = 0xffffffff;
|
||||||
netmask->s6_addr32[2] = ndL_masks[pflen - 65];
|
netmask->s6_addr32[2] = ndL_masks[pflen - 65];
|
||||||
netmask->s6_addr32[3] = 0x00000000u;
|
netmask->s6_addr32[3] = 0x00000000;
|
||||||
}
|
}
|
||||||
else if (pflen >= 33)
|
else if (pflen >= 33)
|
||||||
{
|
{
|
||||||
netmask->s6_addr32[0] = 0xffffffffu;
|
netmask->s6_addr32[0] = 0xffffffff;
|
||||||
netmask->s6_addr32[1] = ndL_masks[pflen - 33];
|
netmask->s6_addr32[1] = ndL_masks[pflen - 33];
|
||||||
netmask->s6_addr32[2] = 0x00000000u;
|
netmask->s6_addr32[2] = 0x00000000;
|
||||||
netmask->s6_addr32[3] = 0x00000000u;
|
netmask->s6_addr32[3] = 0x00000000;
|
||||||
}
|
}
|
||||||
else if (pflen >= 1)
|
else if (pflen >= 1)
|
||||||
{
|
{
|
||||||
netmask->s6_addr32[0] = ndL_masks[pflen - 1];
|
netmask->s6_addr32[0] = ndL_masks[pflen - 1];
|
||||||
netmask->s6_addr32[1] = 0x00000000u;
|
netmask->s6_addr32[1] = 0x00000000;
|
||||||
netmask->s6_addr32[2] = 0x00000000u;
|
netmask->s6_addr32[2] = 0x00000000;
|
||||||
netmask->s6_addr32[3] = 0x00000000u;
|
netmask->s6_addr32[3] = 0x00000000;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
netmask->s6_addr32[0] = 0x00000000u;
|
netmask->s6_addr32[0] = 0x00000000;
|
||||||
netmask->s6_addr32[1] = 0x00000000u;
|
netmask->s6_addr32[1] = 0x00000000;
|
||||||
netmask->s6_addr32[2] = 0x00000000u;
|
netmask->s6_addr32[2] = 0x00000000;
|
||||||
netmask->s6_addr32[3] = 0x00000000u;
|
netmask->s6_addr32[3] = 0x00000000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
src/conf.c
16
src/conf.c
@ -73,7 +73,7 @@ enum
|
|||||||
{
|
{
|
||||||
NDL_DEFAULT,
|
NDL_DEFAULT,
|
||||||
NDL_PROXY,
|
NDL_PROXY,
|
||||||
NDL_ROUTE
|
NDL_RULE
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Configuration types. */
|
/* Configuration types. */
|
||||||
@ -111,8 +111,12 @@ static const ndL_cfinfo_t ndL_cfinfo_table[] = {
|
|||||||
{ "retrans-time", NDL_DEFAULT, NDL_INT, (uintptr_t)&nd_conf_retrans_time, 0, 60000, NULL },
|
{ "retrans-time", NDL_DEFAULT, NDL_INT, (uintptr_t)&nd_conf_retrans_time, 0, 60000, NULL },
|
||||||
{ "keepalive", NDL_DEFAULT, NDL_BOOL, (uintptr_t)&nd_conf_keepalive, 0, 0, NULL },
|
{ "keepalive", NDL_DEFAULT, NDL_BOOL, (uintptr_t)&nd_conf_keepalive, 0, 0, NULL },
|
||||||
{ "router", NDL_PROXY, NDL_BOOL, offsetof(nd_proxy_t, router), 0, 0, NULL },
|
{ "router", NDL_PROXY, NDL_BOOL, offsetof(nd_proxy_t, router), 0, 0, NULL },
|
||||||
{ "auto", NDL_ROUTE, NDL_BOOL, offsetof(nd_rule_t, is_auto), 0, 0, NULL },
|
{ "auto", NDL_RULE, NDL_BOOL, offsetof(nd_rule_t, is_auto), 0, 0, NULL },
|
||||||
|
{ "autowire", NDL_RULE, NDL_BOOL, offsetof(nd_rule_t, autowire), 0, 0, NULL },
|
||||||
{ "promisc", NDL_PROXY, NDL_BOOL, offsetof(nd_proxy_t, promisc), 0, 0, NULL },
|
{ "promisc", NDL_PROXY, NDL_BOOL, offsetof(nd_proxy_t, promisc), 0, 0, NULL },
|
||||||
|
#ifndef __FreeBSD__
|
||||||
|
{ "table", NDL_RULE, NDL_INT, offsetof(nd_rule_t, table), 0, 255, NULL },
|
||||||
|
#endif
|
||||||
{ NULL, 0, 0, 0, 0, 0, NULL },
|
{ NULL, 0, 0, 0, 0, 0, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -388,7 +392,13 @@ static bool ndL_parse_rule(ndL_state_t *state, nd_proxy_t *proxy)
|
|||||||
rule->prefix = 128;
|
rule->prefix = 128;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ndL_parse_block(state, NDL_ROUTE, rule);
|
#ifdef __linux__
|
||||||
|
rule->table = 254;
|
||||||
|
#else
|
||||||
|
rule->table = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ndL_parse_block(state, NDL_RULE, rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ndL_parse_proxy(ndL_state_t *state, __attribute__((unused)) void *unused)
|
static bool ndL_parse_proxy(ndL_state_t *state, __attribute__((unused)) void *unused)
|
||||||
|
@ -234,3 +234,5 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ void nd_proxy_handle_ns(nd_proxy_t *proxy, nd_addr_t *src, __attribute__((unused
|
|||||||
{
|
{
|
||||||
/* TODO: Loop through valid routes. */
|
/* TODO: Loop through valid routes. */
|
||||||
|
|
||||||
nd_rtnl_route_t *route = nd_rtnl_find_route(tgt, 254);
|
nd_rtnl_route_t *route = nd_rtnl_find_route(tgt, rule->table);
|
||||||
|
|
||||||
if (!route || route->oif == proxy->iface->index)
|
if (!route || route->oif == proxy->iface->index)
|
||||||
{
|
{
|
||||||
|
@ -34,6 +34,8 @@ struct nd_rule
|
|||||||
|
|
||||||
nd_iface_t *iface;
|
nd_iface_t *iface;
|
||||||
bool is_auto;
|
bool is_auto;
|
||||||
|
bool autowire;
|
||||||
|
int table;
|
||||||
};
|
};
|
||||||
|
|
||||||
nd_rule_t *nd_rule_create(nd_proxy_t *proxy);
|
nd_rule_t *nd_rule_create(nd_proxy_t *proxy);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user