Revision 04632fd7 nest/rt-table.c
nest/rt-table.c | ||
---|---|---|
68 | 68 |
return mta ? mta(rt, rte_update_pool) : NULL; |
69 | 69 |
} |
70 | 70 |
|
71 |
|
|
71 | 72 |
/* Like fib_route(), but skips empty net entries */ |
72 |
/* |
|
73 |
static net * |
|
74 |
net_route(rtable *tab, ip_addr a, int len) |
|
73 |
static inline void * |
|
74 |
net_route_ip4(struct fib *f, net_addr_ip4 *n) |
|
75 | 75 |
{ |
76 |
ip_addr a0; |
|
77 |
net *n; |
|
76 |
net *r; |
|
78 | 77 |
|
79 |
while (len >= 0) |
|
80 |
{ |
|
81 |
a0 = ipa_and(a, ipa_mkmask(len)); |
|
82 |
n = fib_find(&tab->fib, &a0, len); |
|
83 |
if (n && rte_is_valid(n->routes)) |
|
84 |
return n; |
|
85 |
len--; |
|
86 |
} |
|
87 |
return NULL; |
|
78 |
while (r = fib_find(f, (net_addr *) n), |
|
79 |
!(r && rte_is_valid(r->routes)) && (n->pxlen > 0)) |
|
80 |
{ |
|
81 |
n->pxlen--; |
|
82 |
ip4_clrbit(&n->prefix, n->pxlen); |
|
83 |
} |
|
84 |
|
|
85 |
return r; |
|
86 |
} |
|
87 |
|
|
88 |
static inline void * |
|
89 |
net_route_ip6(struct fib *f, net_addr_ip6 *n) |
|
90 |
{ |
|
91 |
net *r; |
|
92 |
|
|
93 |
while (r = fib_find(f, (net_addr *) n), |
|
94 |
!(r && rte_is_valid(r->routes)) && (n->pxlen > 0)) |
|
95 |
{ |
|
96 |
n->pxlen--; |
|
97 |
ip6_clrbit(&n->prefix, n->pxlen); |
|
98 |
} |
|
99 |
|
|
100 |
return r; |
|
101 |
} |
|
102 |
|
|
103 |
void * |
|
104 |
net_route(rtable *tab, const net_addr *n) |
|
105 |
{ |
|
106 |
ASSERT(f->addr_type == n->type); |
|
107 |
|
|
108 |
net_addr *n0 = alloca(n->length); |
|
109 |
net_copy(n0, n); |
|
110 |
|
|
111 |
switch (n->type) |
|
112 |
{ |
|
113 |
case NET_IP4: |
|
114 |
case NET_VPN4: |
|
115 |
return net_route_ip4(&tab->fib, (net_addr_ip4 *) n0); |
|
116 |
|
|
117 |
case NET_IP6: |
|
118 |
case NET_VPN6: |
|
119 |
return net_route_ip6(&tab->fib, (net_addr_ip6 *) n0); |
|
120 |
|
|
121 |
default: |
|
122 |
return NULL; |
|
123 |
} |
|
88 | 124 |
} |
89 |
*/ |
|
90 | 125 |
|
91 | 126 |
/** |
92 | 127 |
* rte_find - find a route |
... | ... | |
2040 | 2075 |
return p ^ (p << 8) ^ (p >> 16); |
2041 | 2076 |
} |
2042 | 2077 |
|
2043 |
static inline unsigned
|
|
2078 |
static inline u32
|
|
2044 | 2079 |
hc_hash(ip_addr a, rtable *dep) |
2045 | 2080 |
{ |
2046 |
return (ipa_hash(a) ^ ptr_hash(dep)) & 0xffff;
|
|
2081 |
return ipa_hash(a) ^ ptr_hash(dep);
|
|
2047 | 2082 |
} |
2048 | 2083 |
|
2049 | 2084 |
static inline void |
... | ... | |
2077 | 2112 |
{ |
2078 | 2113 |
unsigned hsize = 1 << order; |
2079 | 2114 |
hc->hash_order = order; |
2080 |
hc->hash_shift = 16 - order;
|
|
2115 |
hc->hash_shift = 32 - order;
|
|
2081 | 2116 |
hc->hash_max = (order >= HC_HI_ORDER) ? ~0 : (hsize HC_HI_MARK); |
2082 | 2117 |
hc->hash_min = (order <= HC_LO_ORDER) ? 0 : (hsize HC_LO_MARK); |
2083 | 2118 |
|
... | ... | |
2178 | 2213 |
static void |
2179 | 2214 |
rt_notify_hostcache(rtable *tab, net *net) |
2180 | 2215 |
{ |
2181 |
struct hostcache *hc = tab->hostcache; |
|
2182 |
|
|
2183 | 2216 |
if (tab->hcu_scheduled) |
2184 | 2217 |
return; |
2185 | 2218 |
|
2186 |
// XXXX |
|
2187 |
// if (trie_match_prefix(hc->trie, net->n.prefix, net->n.pxlen)) |
|
2188 |
// rt_schedule_hcu(tab); |
|
2219 |
if (trie_match_net(tab->hostcache->trie, net->n.addr)) |
|
2220 |
rt_schedule_hcu(tab); |
|
2189 | 2221 |
} |
2190 | 2222 |
|
2191 | 2223 |
static int |
... | ... | |
2235 | 2267 |
rta *old_src = he->src; |
2236 | 2268 |
int pxlen = 0; |
2237 | 2269 |
|
2238 |
/* Reset the hostentry */
|
|
2270 |
/* Reset the hostentry */ |
|
2239 | 2271 |
he->src = NULL; |
2240 | 2272 |
he->gw = IPA_NONE; |
2241 | 2273 |
he->dest = RTD_UNREACHABLE; |
2242 | 2274 |
he->igp_metric = 0; |
2243 | 2275 |
|
2244 |
// XXXX
|
|
2245 |
// net *n = net_route(tab, he->addr, MAX_PREFIX_LENGTH);
|
|
2246 |
net *n = NULL;
|
|
2276 |
net_addr he_addr;
|
|
2277 |
net_fill_ip_host(&he_addr, he->addr);
|
|
2278 |
net *n = net_route(tab, &he_addr);
|
|
2247 | 2279 |
if (n) |
2248 | 2280 |
{ |
2249 | 2281 |
rte *e = n->routes; |
... | ... | |
2285 | 2317 |
|
2286 | 2318 |
done: |
2287 | 2319 |
/* Add a prefix range to the trie */ |
2288 |
/* XXXX |
|
2289 |
if (ipa_is_ip4(he->addr)) |
|
2290 |
trie_add_prefix(tab->hostcache->trie, he->addr, IP4_MAX_PREFIX_LENGTH, pxlen, IP4_MAX_PREFIX_LENGTH); |
|
2291 |
else |
|
2292 |
trie_add_prefix(tab->hostcache->trie, he->addr, IP6_MAX_PREFIX_LENGTH, pxlen, IP6_MAX_PREFIX_LENGTH); |
|
2293 |
*/ |
|
2320 |
trie_add_prefix(tab->hostcache->trie, &he_addr, pxlen, he_addr.pxlen); |
|
2294 | 2321 |
|
2295 | 2322 |
rta_free(old_src); |
2296 | 2323 |
return old_src != he->src; |
... | ... | |
2331 | 2358 |
if (!tab->hostcache) |
2332 | 2359 |
rt_init_hostcache(tab); |
2333 | 2360 |
|
2334 |
uint k = hc_hash(a, dep);
|
|
2361 |
u32 k = hc_hash(a, dep);
|
|
2335 | 2362 |
struct hostcache *hc = tab->hostcache; |
2336 | 2363 |
for (he = hc->hash_table[k >> hc->hash_shift]; he != NULL; he = he->next) |
2337 | 2364 |
if (ipa_equal(he->addr, a) && (he->tab == dep)) |
... | ... | |
2575 | 2602 |
if (d->filtered && (d->export_mode || d->primary_only)) |
2576 | 2603 |
cli_msg(0, ""); |
2577 | 2604 |
|
2578 |
if (!d->prefix)
|
|
2605 |
if (!d->addr)
|
|
2579 | 2606 |
{ |
2580 | 2607 |
FIB_ITERATE_INIT(&d->fit, &d->table->fib); |
2581 | 2608 |
this_cli->cont = rt_show_cont; |
... | ... | |
2584 | 2611 |
} |
2585 | 2612 |
else |
2586 | 2613 |
{ |
2587 |
/* XXXX |
|
2588 | 2614 |
if (d->show_for) |
2589 |
n = net_route(d->table, d->prefix, d->pxlen);
|
|
2615 |
n = net_route(d->table, d->addr);
|
|
2590 | 2616 |
else |
2591 |
n = net_find(d->table, d->prefix, d->pxlen); |
|
2592 |
*/ |
|
2593 |
n = NULL; |
|
2617 |
n = net_find(d->table, d->addr); |
|
2594 | 2618 |
|
2595 | 2619 |
if (n) |
2596 | 2620 |
rt_show_net(this_cli, n, d); |
Also available in: Unified diff