]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* BGP nexthop scan |
2 | Copyright (C) 2000 Kunihiro Ishiguro | |
3 | ||
4 | This file is part of GNU Zebra. | |
5 | ||
6 | GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU General Public License as published by the | |
8 | Free Software Foundation; either version 2, or (at your option) any | |
9 | later version. | |
10 | ||
11 | GNU Zebra is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU Zebra; see the file COPYING. If not, write to the Free | |
18 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
19 | 02111-1307, USA. */ | |
20 | ||
21 | #include <zebra.h> | |
22 | ||
23 | #include "command.h" | |
24 | #include "thread.h" | |
25 | #include "prefix.h" | |
26 | #include "zclient.h" | |
27 | #include "stream.h" | |
28 | #include "network.h" | |
29 | #include "log.h" | |
30 | #include "memory.h" | |
10f9bf3f JBD |
31 | #include "hash.h" |
32 | #include "jhash.h" | |
fb018d25 | 33 | #include "nexthop.h" |
718e3744 | 34 | |
35 | #include "bgpd/bgpd.h" | |
36 | #include "bgpd/bgp_table.h" | |
37 | #include "bgpd/bgp_route.h" | |
38 | #include "bgpd/bgp_attr.h" | |
39 | #include "bgpd/bgp_nexthop.h" | |
fb018d25 | 40 | #include "bgpd/bgp_nht.h" |
718e3744 | 41 | #include "bgpd/bgp_debug.h" |
42 | #include "bgpd/bgp_damp.h" | |
43 | #include "zebra/rib.h" | |
44 | #include "zebra/zserv.h" /* For ZEBRA_SERV_PATH. */ | |
45 | ||
fb018d25 DS |
46 | extern struct zclient *zclient; |
47 | ||
718e3744 | 48 | struct bgp_nexthop_cache *zlookup_query (struct in_addr); |
49 | #ifdef HAVE_IPV6 | |
50 | struct bgp_nexthop_cache *zlookup_query_ipv6 (struct in6_addr *); | |
51 | #endif /* HAVE_IPV6 */ | |
6b0655a2 | 52 | |
718e3744 | 53 | /* Only one BGP scan thread are activated at the same time. */ |
00d252cb | 54 | static struct thread *bgp_scan_thread = NULL; |
718e3744 | 55 | |
56 | /* BGP import thread */ | |
00d252cb | 57 | static struct thread *bgp_import_thread = NULL; |
718e3744 | 58 | |
59 | /* BGP scan interval. */ | |
00d252cb | 60 | static int bgp_scan_interval; |
718e3744 | 61 | |
62 | /* BGP import interval. */ | |
00d252cb | 63 | static int bgp_import_interval; |
718e3744 | 64 | |
65 | /* Route table for next-hop lookup cache. */ | |
fb018d25 | 66 | struct bgp_table *bgp_nexthop_cache_table[AFI_MAX]; |
00d252cb | 67 | static struct bgp_table *cache1_table[AFI_MAX]; |
68 | static struct bgp_table *cache2_table[AFI_MAX]; | |
718e3744 | 69 | |
70 | /* Route table for connected route. */ | |
00d252cb | 71 | static struct bgp_table *bgp_connected_table[AFI_MAX]; |
718e3744 | 72 | |
73 | /* BGP nexthop lookup query client. */ | |
228da428 | 74 | struct zclient *zlookup = NULL; |
6b0655a2 | 75 | |
fb018d25 DS |
76 | char * |
77 | bnc_str (struct bgp_nexthop_cache *bnc, char *buf, int size) | |
78 | { | |
79 | prefix2str(&(bnc->node->p), buf, size); | |
80 | return buf; | |
81 | } | |
82 | ||
718e3744 | 83 | /* Add nexthop to the end of the list. */ |
94f2b392 | 84 | static void |
718e3744 | 85 | bnc_nexthop_add (struct bgp_nexthop_cache *bnc, struct nexthop *nexthop) |
86 | { | |
87 | struct nexthop *last; | |
88 | ||
89 | for (last = bnc->nexthop; last && last->next; last = last->next) | |
90 | ; | |
91 | if (last) | |
92 | last->next = nexthop; | |
93 | else | |
94 | bnc->nexthop = nexthop; | |
95 | nexthop->prev = last; | |
96 | } | |
97 | ||
fb018d25 | 98 | void |
718e3744 | 99 | bnc_nexthop_free (struct bgp_nexthop_cache *bnc) |
100 | { | |
101 | struct nexthop *nexthop; | |
102 | struct nexthop *next = NULL; | |
103 | ||
104 | for (nexthop = bnc->nexthop; nexthop; nexthop = next) | |
105 | { | |
106 | next = nexthop->next; | |
107 | XFREE (MTYPE_NEXTHOP, nexthop); | |
108 | } | |
109 | } | |
110 | ||
fb018d25 DS |
111 | struct bgp_nexthop_cache * |
112 | bnc_new () | |
718e3744 | 113 | { |
fb018d25 DS |
114 | struct bgp_nexthop_cache *bnc; |
115 | ||
116 | bnc = XCALLOC (MTYPE_BGP_NEXTHOP_CACHE, sizeof (struct bgp_nexthop_cache)); | |
117 | LIST_INIT(&(bnc->paths)); | |
118 | return bnc; | |
718e3744 | 119 | } |
120 | ||
fb018d25 | 121 | void |
718e3744 | 122 | bnc_free (struct bgp_nexthop_cache *bnc) |
123 | { | |
124 | bnc_nexthop_free (bnc); | |
125 | XFREE (MTYPE_BGP_NEXTHOP_CACHE, bnc); | |
126 | } | |
6b0655a2 | 127 | |
94f2b392 | 128 | static int |
8e80bdf2 | 129 | bgp_nexthop_cache_different (struct bgp_nexthop_cache *bnc1, |
718e3744 | 130 | struct bgp_nexthop_cache *bnc2) |
131 | { | |
132 | int i; | |
133 | struct nexthop *next1, *next2; | |
134 | ||
135 | if (bnc1->nexthop_num != bnc2->nexthop_num) | |
136 | return 1; | |
137 | ||
138 | next1 = bnc1->nexthop; | |
139 | next2 = bnc2->nexthop; | |
140 | ||
141 | for (i = 0; i < bnc1->nexthop_num; i++) | |
142 | { | |
fb018d25 | 143 | if (! nexthop_same_no_recurse (next1, next2)) |
718e3744 | 144 | return 1; |
145 | ||
146 | next1 = next1->next; | |
147 | next2 = next2->next; | |
148 | } | |
149 | return 0; | |
150 | } | |
151 | ||
152 | /* If nexthop exists on connected network return 1. */ | |
153 | int | |
8e80bdf2 | 154 | bgp_nexthop_onlink (afi_t afi, struct attr *attr) |
718e3744 | 155 | { |
156 | struct bgp_node *rn; | |
fc98d16e PJ |
157 | |
158 | /* If zebra is not enabled return */ | |
159 | if (zlookup->sock < 0) | |
160 | return 1; | |
161 | ||
718e3744 | 162 | /* Lookup the address is onlink or not. */ |
163 | if (afi == AFI_IP) | |
164 | { | |
5932020b | 165 | rn = bgp_node_match_ipv4 (bgp_connected_table[AFI_IP], &attr->nexthop); |
718e3744 | 166 | if (rn) |
167 | { | |
168 | bgp_unlock_node (rn); | |
169 | return 1; | |
170 | } | |
171 | } | |
172 | #ifdef HAVE_IPV6 | |
173 | else if (afi == AFI_IP6) | |
174 | { | |
fb982c25 | 175 | if (attr->extra->mp_nexthop_len == 32) |
718e3744 | 176 | return 1; |
fb982c25 | 177 | else if (attr->extra->mp_nexthop_len == 16) |
718e3744 | 178 | { |
fb982c25 | 179 | if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global)) |
718e3744 | 180 | return 1; |
181 | ||
5932020b | 182 | rn = bgp_node_match_ipv6 (bgp_connected_table[AFI_IP6], |
fb982c25 | 183 | &attr->extra->mp_nexthop_global); |
718e3744 | 184 | if (rn) |
185 | { | |
186 | bgp_unlock_node (rn); | |
187 | return 1; | |
188 | } | |
189 | } | |
190 | } | |
191 | #endif /* HAVE_IPV6 */ | |
192 | return 0; | |
193 | } | |
194 | ||
195 | #ifdef HAVE_IPV6 | |
196 | /* Check specified next-hop is reachable or not. */ | |
94f2b392 | 197 | static int |
718e3744 | 198 | bgp_nexthop_lookup_ipv6 (struct peer *peer, struct bgp_info *ri, int *changed, |
199 | int *metricchanged) | |
200 | { | |
201 | struct bgp_node *rn; | |
202 | struct prefix p; | |
203 | struct bgp_nexthop_cache *bnc; | |
204 | struct attr *attr; | |
fc98d16e PJ |
205 | |
206 | /* If lookup is not enabled, return valid. */ | |
207 | if (zlookup->sock < 0) | |
208 | { | |
209 | if (ri->extra) | |
210 | ri->extra->igpmetric = 0; | |
211 | return 1; | |
212 | } | |
213 | ||
718e3744 | 214 | /* Only check IPv6 global address only nexthop. */ |
215 | attr = ri->attr; | |
216 | ||
fb982c25 PJ |
217 | if (attr->extra->mp_nexthop_len != 16 |
218 | || IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global)) | |
718e3744 | 219 | return 1; |
220 | ||
221 | memset (&p, 0, sizeof (struct prefix)); | |
222 | p.family = AF_INET6; | |
223 | p.prefixlen = IPV6_MAX_BITLEN; | |
fb982c25 | 224 | p.u.prefix6 = attr->extra->mp_nexthop_global; |
718e3744 | 225 | |
226 | /* IBGP or ebgp-multihop */ | |
5932020b | 227 | rn = bgp_node_get (bgp_nexthop_cache_table[AFI_IP6], &p); |
718e3744 | 228 | |
229 | if (rn->info) | |
230 | { | |
231 | bnc = rn->info; | |
232 | bgp_unlock_node (rn); | |
233 | } | |
234 | else | |
235 | { | |
b64bfc1c DO |
236 | if (NULL == (bnc = zlookup_query_ipv6 (&attr->extra->mp_nexthop_global))) |
237 | bnc = bnc_new (); | |
238 | else | |
718e3744 | 239 | { |
718e3744 | 240 | if (changed) |
241 | { | |
8e80bdf2 DO |
242 | struct bgp_table *old; |
243 | struct bgp_node *oldrn; | |
244 | ||
5932020b | 245 | if (bgp_nexthop_cache_table[AFI_IP6] == cache1_table[AFI_IP6]) |
246 | old = cache2_table[AFI_IP6]; | |
718e3744 | 247 | else |
5932020b | 248 | old = cache1_table[AFI_IP6]; |
718e3744 | 249 | |
250 | oldrn = bgp_node_lookup (old, &p); | |
251 | if (oldrn) | |
252 | { | |
8e80bdf2 | 253 | struct bgp_nexthop_cache *oldbnc = oldrn->info; |
718e3744 | 254 | |
8e80bdf2 | 255 | bnc->changed = bgp_nexthop_cache_different (bnc, oldbnc); |
718e3744 | 256 | |
257 | if (bnc->metric != oldbnc->metric) | |
258 | bnc->metricchanged = 1; | |
6c88b44d CC |
259 | |
260 | bgp_unlock_node (oldrn); | |
718e3744 | 261 | } |
262 | } | |
263 | } | |
718e3744 | 264 | rn->info = bnc; |
265 | } | |
266 | ||
267 | if (changed) | |
268 | *changed = bnc->changed; | |
269 | ||
270 | if (metricchanged) | |
271 | *metricchanged = bnc->metricchanged; | |
272 | ||
fb982c25 PJ |
273 | if (bnc->valid && bnc->metric) |
274 | (bgp_info_extra_get (ri))->igpmetric = bnc->metric; | |
275 | else if (ri->extra) | |
276 | ri->extra->igpmetric = 0; | |
718e3744 | 277 | |
278 | return bnc->valid; | |
279 | } | |
280 | #endif /* HAVE_IPV6 */ | |
281 | ||
282 | /* Check specified next-hop is reachable or not. */ | |
283 | int | |
284 | bgp_nexthop_lookup (afi_t afi, struct peer *peer, struct bgp_info *ri, | |
285 | int *changed, int *metricchanged) | |
286 | { | |
287 | struct bgp_node *rn; | |
288 | struct prefix p; | |
289 | struct bgp_nexthop_cache *bnc; | |
290 | struct in_addr addr; | |
fc98d16e PJ |
291 | |
292 | /* If lookup is not enabled, return valid. */ | |
293 | if (zlookup->sock < 0) | |
294 | { | |
295 | if (ri->extra) | |
296 | ri->extra->igpmetric = 0; | |
297 | return 1; | |
298 | } | |
299 | ||
718e3744 | 300 | #ifdef HAVE_IPV6 |
301 | if (afi == AFI_IP6) | |
302 | return bgp_nexthop_lookup_ipv6 (peer, ri, changed, metricchanged); | |
303 | #endif /* HAVE_IPV6 */ | |
304 | ||
305 | addr = ri->attr->nexthop; | |
306 | ||
307 | memset (&p, 0, sizeof (struct prefix)); | |
308 | p.family = AF_INET; | |
309 | p.prefixlen = IPV4_MAX_BITLEN; | |
310 | p.u.prefix4 = addr; | |
311 | ||
312 | /* IBGP or ebgp-multihop */ | |
5932020b | 313 | rn = bgp_node_get (bgp_nexthop_cache_table[AFI_IP], &p); |
718e3744 | 314 | |
315 | if (rn->info) | |
316 | { | |
317 | bnc = rn->info; | |
318 | bgp_unlock_node (rn); | |
319 | } | |
320 | else | |
321 | { | |
b64bfc1c DO |
322 | if (NULL == (bnc = zlookup_query (addr))) |
323 | bnc = bnc_new (); | |
324 | else | |
718e3744 | 325 | { |
718e3744 | 326 | if (changed) |
327 | { | |
8e80bdf2 DO |
328 | struct bgp_table *old; |
329 | struct bgp_node *oldrn; | |
330 | ||
5932020b | 331 | if (bgp_nexthop_cache_table[AFI_IP] == cache1_table[AFI_IP]) |
332 | old = cache2_table[AFI_IP]; | |
718e3744 | 333 | else |
5932020b | 334 | old = cache1_table[AFI_IP]; |
718e3744 | 335 | |
336 | oldrn = bgp_node_lookup (old, &p); | |
337 | if (oldrn) | |
338 | { | |
8e80bdf2 | 339 | struct bgp_nexthop_cache *oldbnc = oldrn->info; |
718e3744 | 340 | |
8e80bdf2 | 341 | bnc->changed = bgp_nexthop_cache_different (bnc, oldbnc); |
718e3744 | 342 | |
343 | if (bnc->metric != oldbnc->metric) | |
344 | bnc->metricchanged = 1; | |
6c88b44d CC |
345 | |
346 | bgp_unlock_node (oldrn); | |
718e3744 | 347 | } |
348 | } | |
349 | } | |
718e3744 | 350 | rn->info = bnc; |
351 | } | |
352 | ||
353 | if (changed) | |
354 | *changed = bnc->changed; | |
355 | ||
356 | if (metricchanged) | |
357 | *metricchanged = bnc->metricchanged; | |
358 | ||
fb982c25 PJ |
359 | if (bnc->valid && bnc->metric) |
360 | (bgp_info_extra_get(ri))->igpmetric = bnc->metric; | |
361 | else if (ri->extra) | |
362 | ri->extra->igpmetric = 0; | |
718e3744 | 363 | |
364 | return bnc->valid; | |
365 | } | |
366 | ||
367 | /* Reset and free all BGP nexthop cache. */ | |
94f2b392 | 368 | static void |
718e3744 | 369 | bgp_nexthop_cache_reset (struct bgp_table *table) |
370 | { | |
371 | struct bgp_node *rn; | |
372 | struct bgp_nexthop_cache *bnc; | |
373 | ||
374 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) | |
375 | if ((bnc = rn->info) != NULL) | |
376 | { | |
377 | bnc_free (bnc); | |
378 | rn->info = NULL; | |
379 | bgp_unlock_node (rn); | |
380 | } | |
381 | } | |
382 | ||
94f2b392 | 383 | static void |
5932020b | 384 | bgp_scan (afi_t afi, safi_t safi) |
718e3744 | 385 | { |
386 | struct bgp_node *rn; | |
387 | struct bgp *bgp; | |
388 | struct bgp_info *bi; | |
389 | struct bgp_info *next; | |
390 | struct peer *peer; | |
1eb8ef25 | 391 | struct listnode *node, *nnode; |
fb018d25 | 392 | #if BGP_SCAN_NEXTHOP |
718e3744 | 393 | int valid; |
394 | int current; | |
395 | int changed; | |
396 | int metricchanged; | |
397 | ||
398 | /* Change cache. */ | |
5932020b | 399 | if (bgp_nexthop_cache_table[afi] == cache1_table[afi]) |
400 | bgp_nexthop_cache_table[afi] = cache2_table[afi]; | |
718e3744 | 401 | else |
5932020b | 402 | bgp_nexthop_cache_table[afi] = cache1_table[afi]; |
fb018d25 | 403 | #endif |
718e3744 | 404 | |
405 | /* Get default bgp. */ | |
406 | bgp = bgp_get_default (); | |
407 | if (bgp == NULL) | |
408 | return; | |
409 | ||
410 | /* Maximum prefix check */ | |
1eb8ef25 | 411 | for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) |
718e3744 | 412 | { |
413 | if (peer->status != Established) | |
414 | continue; | |
415 | ||
5932020b | 416 | if (peer->afc[afi][SAFI_UNICAST]) |
417 | bgp_maximum_prefix_overflow (peer, afi, SAFI_UNICAST, 1); | |
418 | if (peer->afc[afi][SAFI_MULTICAST]) | |
419 | bgp_maximum_prefix_overflow (peer, afi, SAFI_MULTICAST, 1); | |
420 | if (peer->afc[afi][SAFI_MPLS_VPN]) | |
421 | bgp_maximum_prefix_overflow (peer, afi, SAFI_MPLS_VPN, 1); | |
718e3744 | 422 | } |
423 | ||
5932020b | 424 | for (rn = bgp_table_top (bgp->rib[afi][SAFI_UNICAST]); rn; |
718e3744 | 425 | rn = bgp_route_next (rn)) |
426 | { | |
427 | for (bi = rn->info; bi; bi = next) | |
428 | { | |
429 | next = bi->next; | |
430 | ||
431 | if (bi->type == ZEBRA_ROUTE_BGP && bi->sub_type == BGP_ROUTE_NORMAL) | |
432 | { | |
fb018d25 | 433 | #if BGP_SCAN_NEXTHOP |
718e3744 | 434 | changed = 0; |
435 | metricchanged = 0; | |
436 | ||
a0f6ce5b CF |
437 | if (bi->peer->sort == BGP_PEER_EBGP && bi->peer->ttl == 1 |
438 | && !CHECK_FLAG(bi->peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)) | |
8e80bdf2 | 439 | valid = bgp_nexthop_onlink (afi, bi->attr); |
718e3744 | 440 | else |
5932020b | 441 | valid = bgp_nexthop_lookup (afi, bi->peer, bi, |
718e3744 | 442 | &changed, &metricchanged); |
443 | ||
444 | current = CHECK_FLAG (bi->flags, BGP_INFO_VALID) ? 1 : 0; | |
445 | ||
446 | if (changed) | |
447 | SET_FLAG (bi->flags, BGP_INFO_IGP_CHANGED); | |
448 | else | |
449 | UNSET_FLAG (bi->flags, BGP_INFO_IGP_CHANGED); | |
450 | ||
451 | if (valid != current) | |
452 | { | |
453 | if (CHECK_FLAG (bi->flags, BGP_INFO_VALID)) | |
454 | { | |
455 | bgp_aggregate_decrement (bgp, &rn->p, bi, | |
5932020b | 456 | afi, SAFI_UNICAST); |
1a392d46 | 457 | bgp_info_unset_flag (rn, bi, BGP_INFO_VALID); |
718e3744 | 458 | } |
459 | else | |
460 | { | |
1a392d46 | 461 | bgp_info_set_flag (rn, bi, BGP_INFO_VALID); |
718e3744 | 462 | bgp_aggregate_increment (bgp, &rn->p, bi, |
5932020b | 463 | afi, SAFI_UNICAST); |
718e3744 | 464 | } |
465 | } | |
fb018d25 | 466 | #endif |
718e3744 | 467 | |
5932020b | 468 | if (CHECK_FLAG (bgp->af_flags[afi][SAFI_UNICAST], |
718e3744 | 469 | BGP_CONFIG_DAMPENING) |
fb982c25 | 470 | && bi->extra && bi->extra->damp_info ) |
5932020b | 471 | if (bgp_damp_scan (bi, afi, SAFI_UNICAST)) |
718e3744 | 472 | bgp_aggregate_increment (bgp, &rn->p, bi, |
5932020b | 473 | afi, SAFI_UNICAST); |
718e3744 | 474 | } |
475 | } | |
5932020b | 476 | bgp_process (bgp, rn, afi, SAFI_UNICAST); |
718e3744 | 477 | } |
478 | ||
fb018d25 | 479 | #if BGP_SCAN_NEXTHOP |
718e3744 | 480 | /* Flash old cache. */ |
5932020b | 481 | if (bgp_nexthop_cache_table[afi] == cache1_table[afi]) |
482 | bgp_nexthop_cache_reset (cache2_table[afi]); | |
718e3744 | 483 | else |
5932020b | 484 | bgp_nexthop_cache_reset (cache1_table[afi]); |
fb018d25 | 485 | #endif |
f418446b | 486 | |
487 | if (BGP_DEBUG (events, EVENTS)) | |
488 | { | |
489 | if (afi == AFI_IP) | |
490 | zlog_debug ("scanning IPv4 Unicast routing tables"); | |
491 | else if (afi == AFI_IP6) | |
492 | zlog_debug ("scanning IPv6 Unicast routing tables"); | |
493 | } | |
dcab1bb8 CF |
494 | |
495 | /* Reevaluate default-originate route-maps and announce/withdraw | |
496 | * default route if neccesary. */ | |
497 | for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) | |
498 | { | |
499 | if (peer->status == Established | |
500 | && CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE) | |
501 | && peer->default_rmap[afi][safi].name) | |
502 | bgp_default_originate (peer, afi, safi, 0); | |
503 | } | |
718e3744 | 504 | } |
718e3744 | 505 | |
506 | /* BGP scan thread. This thread check nexthop reachability. */ | |
94f2b392 | 507 | static int |
5932020b | 508 | bgp_scan_timer (struct thread *t) |
718e3744 | 509 | { |
510 | bgp_scan_thread = | |
5932020b | 511 | thread_add_timer (master, bgp_scan_timer, NULL, bgp_scan_interval); |
718e3744 | 512 | |
f418446b | 513 | if (BGP_DEBUG (events, EVENTS)) |
478ba054 | 514 | zlog_debug ("Performing BGP general scanning"); |
718e3744 | 515 | |
5932020b | 516 | bgp_scan (AFI_IP, SAFI_UNICAST); |
718e3744 | 517 | |
518 | #ifdef HAVE_IPV6 | |
5932020b | 519 | bgp_scan (AFI_IP6, SAFI_UNICAST); |
718e3744 | 520 | #endif /* HAVE_IPV6 */ |
521 | ||
522 | return 0; | |
523 | } | |
10f9bf3f JBD |
524 | |
525 | /* BGP own address structure */ | |
526 | struct bgp_addr | |
527 | { | |
528 | struct in_addr addr; | |
529 | int refcnt; | |
530 | }; | |
531 | ||
532 | static struct hash *bgp_address_hash; | |
533 | ||
534 | static void * | |
535 | bgp_address_hash_alloc (void *p) | |
536 | { | |
537 | struct in_addr *val = p; | |
538 | struct bgp_addr *addr; | |
539 | ||
540 | addr = XMALLOC (MTYPE_BGP_ADDR, sizeof (struct bgp_addr)); | |
541 | addr->refcnt = 0; | |
542 | addr->addr.s_addr = val->s_addr; | |
543 | ||
544 | return addr; | |
545 | } | |
546 | ||
547 | static unsigned int | |
548 | bgp_address_hash_key_make (void *p) | |
549 | { | |
550 | const struct bgp_addr *addr = p; | |
551 | ||
552 | return jhash_1word(addr->addr.s_addr, 0); | |
553 | } | |
554 | ||
555 | static int | |
556 | bgp_address_hash_cmp (const void *p1, const void *p2) | |
557 | { | |
558 | const struct bgp_addr *addr1 = p1; | |
559 | const struct bgp_addr *addr2 = p2; | |
560 | ||
561 | return addr1->addr.s_addr == addr2->addr.s_addr; | |
562 | } | |
563 | ||
564 | void | |
565 | bgp_address_init (void) | |
566 | { | |
567 | bgp_address_hash = hash_create (bgp_address_hash_key_make, | |
568 | bgp_address_hash_cmp); | |
569 | } | |
570 | ||
571 | static void | |
572 | bgp_address_add (struct prefix *p) | |
573 | { | |
574 | struct bgp_addr tmp; | |
575 | struct bgp_addr *addr; | |
576 | ||
577 | tmp.addr = p->u.prefix4; | |
578 | ||
579 | addr = hash_get (bgp_address_hash, &tmp, bgp_address_hash_alloc); | |
5ce10e92 DS |
580 | if (!addr) |
581 | return; | |
582 | ||
10f9bf3f JBD |
583 | addr->refcnt++; |
584 | } | |
585 | ||
586 | static void | |
587 | bgp_address_del (struct prefix *p) | |
588 | { | |
589 | struct bgp_addr tmp; | |
590 | struct bgp_addr *addr; | |
591 | ||
592 | tmp.addr = p->u.prefix4; | |
593 | ||
594 | addr = hash_lookup (bgp_address_hash, &tmp); | |
9e47abd8 RG |
595 | /* may have been deleted earlier by bgp_interface_down() */ |
596 | if (addr == NULL) | |
597 | return; | |
598 | ||
10f9bf3f JBD |
599 | addr->refcnt--; |
600 | ||
601 | if (addr->refcnt == 0) | |
602 | { | |
603 | hash_release (bgp_address_hash, addr); | |
604 | XFREE (MTYPE_BGP_ADDR, addr); | |
605 | } | |
606 | } | |
607 | ||
6b0655a2 | 608 | |
5932020b | 609 | struct bgp_connected_ref |
718e3744 | 610 | { |
611 | unsigned int refcnt; | |
612 | }; | |
613 | ||
614 | void | |
615 | bgp_connected_add (struct connected *ifc) | |
616 | { | |
617 | struct prefix p; | |
618 | struct prefix *addr; | |
718e3744 | 619 | struct interface *ifp; |
620 | struct bgp_node *rn; | |
5932020b | 621 | struct bgp_connected_ref *bc; |
718e3744 | 622 | |
623 | ifp = ifc->ifp; | |
624 | ||
625 | if (! ifp) | |
626 | return; | |
627 | ||
628 | if (if_is_loopback (ifp)) | |
629 | return; | |
630 | ||
631 | addr = ifc->address; | |
718e3744 | 632 | |
633 | if (addr->family == AF_INET) | |
634 | { | |
e4529636 | 635 | PREFIX_COPY_IPV4(&p, CONNECTED_PREFIX(ifc)); |
718e3744 | 636 | apply_mask_ipv4 ((struct prefix_ipv4 *) &p); |
637 | ||
638 | if (prefix_ipv4_any ((struct prefix_ipv4 *) &p)) | |
639 | return; | |
640 | ||
10f9bf3f JBD |
641 | bgp_address_add (addr); |
642 | ||
5932020b | 643 | rn = bgp_node_get (bgp_connected_table[AFI_IP], (struct prefix *) &p); |
718e3744 | 644 | if (rn->info) |
645 | { | |
646 | bc = rn->info; | |
647 | bc->refcnt++; | |
648 | } | |
649 | else | |
650 | { | |
6c88b44d | 651 | bc = XCALLOC (MTYPE_BGP_CONN, sizeof (struct bgp_connected_ref)); |
718e3744 | 652 | bc->refcnt = 1; |
653 | rn->info = bc; | |
654 | } | |
655 | } | |
656 | #ifdef HAVE_IPV6 | |
e4529636 | 657 | else if (addr->family == AF_INET6) |
718e3744 | 658 | { |
e4529636 | 659 | PREFIX_COPY_IPV6(&p, CONNECTED_PREFIX(ifc)); |
718e3744 | 660 | apply_mask_ipv6 ((struct prefix_ipv6 *) &p); |
661 | ||
662 | if (IN6_IS_ADDR_UNSPECIFIED (&p.u.prefix6)) | |
663 | return; | |
664 | ||
665 | if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6)) | |
666 | return; | |
667 | ||
5932020b | 668 | rn = bgp_node_get (bgp_connected_table[AFI_IP6], (struct prefix *) &p); |
718e3744 | 669 | if (rn->info) |
670 | { | |
671 | bc = rn->info; | |
672 | bc->refcnt++; | |
673 | } | |
674 | else | |
675 | { | |
6c88b44d | 676 | bc = XCALLOC (MTYPE_BGP_CONN, sizeof (struct bgp_connected_ref)); |
718e3744 | 677 | bc->refcnt = 1; |
678 | rn->info = bc; | |
679 | } | |
680 | } | |
681 | #endif /* HAVE_IPV6 */ | |
682 | } | |
683 | ||
684 | void | |
685 | bgp_connected_delete (struct connected *ifc) | |
686 | { | |
687 | struct prefix p; | |
688 | struct prefix *addr; | |
718e3744 | 689 | struct interface *ifp; |
690 | struct bgp_node *rn; | |
5932020b | 691 | struct bgp_connected_ref *bc; |
718e3744 | 692 | |
693 | ifp = ifc->ifp; | |
694 | ||
695 | if (if_is_loopback (ifp)) | |
696 | return; | |
697 | ||
698 | addr = ifc->address; | |
718e3744 | 699 | |
700 | if (addr->family == AF_INET) | |
701 | { | |
e4529636 | 702 | PREFIX_COPY_IPV4(&p, CONNECTED_PREFIX(ifc)); |
718e3744 | 703 | apply_mask_ipv4 ((struct prefix_ipv4 *) &p); |
704 | ||
705 | if (prefix_ipv4_any ((struct prefix_ipv4 *) &p)) | |
706 | return; | |
707 | ||
10f9bf3f JBD |
708 | bgp_address_del (addr); |
709 | ||
5932020b | 710 | rn = bgp_node_lookup (bgp_connected_table[AFI_IP], &p); |
718e3744 | 711 | if (! rn) |
712 | return; | |
713 | ||
714 | bc = rn->info; | |
715 | bc->refcnt--; | |
716 | if (bc->refcnt == 0) | |
717 | { | |
6c88b44d | 718 | XFREE (MTYPE_BGP_CONN, bc); |
718e3744 | 719 | rn->info = NULL; |
720 | } | |
721 | bgp_unlock_node (rn); | |
722 | bgp_unlock_node (rn); | |
723 | } | |
724 | #ifdef HAVE_IPV6 | |
725 | else if (addr->family == AF_INET6) | |
726 | { | |
e4529636 | 727 | PREFIX_COPY_IPV6(&p, CONNECTED_PREFIX(ifc)); |
718e3744 | 728 | apply_mask_ipv6 ((struct prefix_ipv6 *) &p); |
729 | ||
730 | if (IN6_IS_ADDR_UNSPECIFIED (&p.u.prefix6)) | |
731 | return; | |
732 | ||
733 | if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6)) | |
734 | return; | |
735 | ||
5932020b | 736 | rn = bgp_node_lookup (bgp_connected_table[AFI_IP6], (struct prefix *) &p); |
718e3744 | 737 | if (! rn) |
738 | return; | |
739 | ||
740 | bc = rn->info; | |
741 | bc->refcnt--; | |
742 | if (bc->refcnt == 0) | |
743 | { | |
6c88b44d | 744 | XFREE (MTYPE_BGP_CONN, bc); |
718e3744 | 745 | rn->info = NULL; |
746 | } | |
747 | bgp_unlock_node (rn); | |
748 | bgp_unlock_node (rn); | |
749 | } | |
750 | #endif /* HAVE_IPV6 */ | |
751 | } | |
752 | ||
753 | int | |
10f9bf3f | 754 | bgp_nexthop_self (struct attr *attr) |
718e3744 | 755 | { |
10f9bf3f | 756 | struct bgp_addr tmp, *addr; |
718e3744 | 757 | |
10f9bf3f JBD |
758 | tmp.addr = attr->nexthop; |
759 | ||
760 | addr = hash_lookup (bgp_address_hash, &tmp); | |
761 | if (addr) | |
762 | return 1; | |
718e3744 | 763 | |
718e3744 | 764 | return 0; |
765 | } | |
6b0655a2 | 766 | |
94f2b392 | 767 | static struct bgp_nexthop_cache * |
66e5cd87 | 768 | zlookup_read (void) |
718e3744 | 769 | { |
770 | struct stream *s; | |
d3092e7f | 771 | uint16_t length; |
772 | u_char marker; | |
773 | u_char version; | |
774 | uint16_t command; | |
718e3744 | 775 | int nbytes; |
776 | struct in_addr raddr; | |
d3092e7f | 777 | uint32_t metric; |
718e3744 | 778 | int i; |
779 | u_char nexthop_num; | |
780 | struct nexthop *nexthop; | |
781 | struct bgp_nexthop_cache *bnc; | |
782 | ||
783 | s = zlookup->ibuf; | |
784 | stream_reset (s); | |
785 | ||
786 | nbytes = stream_read (s, zlookup->sock, 2); | |
787 | length = stream_getw (s); | |
788 | ||
789 | nbytes = stream_read (s, zlookup->sock, length - 2); | |
d3092e7f | 790 | marker = stream_getc (s); |
791 | version = stream_getc (s); | |
792 | ||
793 | if (version != ZSERV_VERSION || marker != ZEBRA_HEADER_MARKER) | |
794 | { | |
795 | zlog_err("%s: socket %d version mismatch, marker %d, version %d", | |
796 | __func__, zlookup->sock, marker, version); | |
797 | return NULL; | |
798 | } | |
799 | ||
800 | command = stream_getw (s); | |
801 | ||
718e3744 | 802 | raddr.s_addr = stream_get_ipv4 (s); |
803 | metric = stream_getl (s); | |
804 | nexthop_num = stream_getc (s); | |
805 | ||
806 | if (nexthop_num) | |
807 | { | |
808 | bnc = bnc_new (); | |
809 | bnc->valid = 1; | |
810 | bnc->metric = metric; | |
811 | bnc->nexthop_num = nexthop_num; | |
812 | ||
813 | for (i = 0; i < nexthop_num; i++) | |
814 | { | |
393deb9b | 815 | nexthop = XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop)); |
718e3744 | 816 | nexthop->type = stream_getc (s); |
817 | switch (nexthop->type) | |
818 | { | |
819 | case ZEBRA_NEXTHOP_IPV4: | |
820 | nexthop->gate.ipv4.s_addr = stream_get_ipv4 (s); | |
821 | break; | |
bb97e462 CF |
822 | case ZEBRA_NEXTHOP_IPV4_IFINDEX: |
823 | nexthop->gate.ipv4.s_addr = stream_get_ipv4 (s); | |
824 | nexthop->ifindex = stream_getl (s); | |
825 | break; | |
718e3744 | 826 | case ZEBRA_NEXTHOP_IFINDEX: |
827 | case ZEBRA_NEXTHOP_IFNAME: | |
828 | nexthop->ifindex = stream_getl (s); | |
829 | break; | |
fa2b17e3 | 830 | default: |
831 | /* do nothing */ | |
832 | break; | |
718e3744 | 833 | } |
834 | bnc_nexthop_add (bnc, nexthop); | |
835 | } | |
836 | } | |
837 | else | |
838 | return NULL; | |
839 | ||
840 | return bnc; | |
841 | } | |
842 | ||
843 | struct bgp_nexthop_cache * | |
844 | zlookup_query (struct in_addr addr) | |
845 | { | |
846 | int ret; | |
847 | struct stream *s; | |
848 | ||
849 | /* Check socket. */ | |
850 | if (zlookup->sock < 0) | |
851 | return NULL; | |
852 | ||
853 | s = zlookup->obuf; | |
854 | stream_reset (s); | |
d3092e7f | 855 | zclient_create_header (s, ZEBRA_IPV4_NEXTHOP_LOOKUP); |
718e3744 | 856 | stream_put_in_addr (s, &addr); |
d3092e7f | 857 | |
858 | stream_putw_at (s, 0, stream_get_endp (s)); | |
859 | ||
860 | ret = writen (zlookup->sock, s->data, stream_get_endp (s)); | |
718e3744 | 861 | if (ret < 0) |
862 | { | |
863 | zlog_err ("can't write to zlookup->sock"); | |
864 | close (zlookup->sock); | |
865 | zlookup->sock = -1; | |
866 | return NULL; | |
867 | } | |
868 | if (ret == 0) | |
869 | { | |
870 | zlog_err ("zlookup->sock connection closed"); | |
871 | close (zlookup->sock); | |
872 | zlookup->sock = -1; | |
873 | return NULL; | |
874 | } | |
875 | ||
876 | return zlookup_read (); | |
877 | } | |
878 | ||
879 | #ifdef HAVE_IPV6 | |
94f2b392 | 880 | static struct bgp_nexthop_cache * |
66e5cd87 | 881 | zlookup_read_ipv6 (void) |
718e3744 | 882 | { |
883 | struct stream *s; | |
d3092e7f | 884 | uint16_t length; |
885 | u_char version, marker; | |
886 | uint16_t command; | |
718e3744 | 887 | int nbytes; |
888 | struct in6_addr raddr; | |
d3092e7f | 889 | uint32_t metric; |
718e3744 | 890 | int i; |
891 | u_char nexthop_num; | |
892 | struct nexthop *nexthop; | |
893 | struct bgp_nexthop_cache *bnc; | |
894 | ||
895 | s = zlookup->ibuf; | |
896 | stream_reset (s); | |
897 | ||
898 | nbytes = stream_read (s, zlookup->sock, 2); | |
899 | length = stream_getw (s); | |
900 | ||
901 | nbytes = stream_read (s, zlookup->sock, length - 2); | |
d3092e7f | 902 | marker = stream_getc (s); |
903 | version = stream_getc (s); | |
904 | ||
905 | if (version != ZSERV_VERSION || marker != ZEBRA_HEADER_MARKER) | |
906 | { | |
907 | zlog_err("%s: socket %d version mismatch, marker %d, version %d", | |
908 | __func__, zlookup->sock, marker, version); | |
909 | return NULL; | |
910 | } | |
911 | ||
912 | command = stream_getw (s); | |
913 | ||
718e3744 | 914 | stream_get (&raddr, s, 16); |
915 | ||
916 | metric = stream_getl (s); | |
917 | nexthop_num = stream_getc (s); | |
918 | ||
919 | if (nexthop_num) | |
920 | { | |
921 | bnc = bnc_new (); | |
922 | bnc->valid = 1; | |
923 | bnc->metric = metric; | |
924 | bnc->nexthop_num = nexthop_num; | |
925 | ||
926 | for (i = 0; i < nexthop_num; i++) | |
927 | { | |
393deb9b | 928 | nexthop = XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop)); |
718e3744 | 929 | nexthop->type = stream_getc (s); |
930 | switch (nexthop->type) | |
931 | { | |
932 | case ZEBRA_NEXTHOP_IPV6: | |
933 | stream_get (&nexthop->gate.ipv6, s, 16); | |
934 | break; | |
935 | case ZEBRA_NEXTHOP_IPV6_IFINDEX: | |
936 | case ZEBRA_NEXTHOP_IPV6_IFNAME: | |
937 | stream_get (&nexthop->gate.ipv6, s, 16); | |
938 | nexthop->ifindex = stream_getl (s); | |
939 | break; | |
940 | case ZEBRA_NEXTHOP_IFINDEX: | |
941 | case ZEBRA_NEXTHOP_IFNAME: | |
942 | nexthop->ifindex = stream_getl (s); | |
943 | break; | |
fa2b17e3 | 944 | default: |
945 | /* do nothing */ | |
946 | break; | |
718e3744 | 947 | } |
948 | bnc_nexthop_add (bnc, nexthop); | |
949 | } | |
950 | } | |
951 | else | |
952 | return NULL; | |
953 | ||
954 | return bnc; | |
955 | } | |
956 | ||
957 | struct bgp_nexthop_cache * | |
958 | zlookup_query_ipv6 (struct in6_addr *addr) | |
959 | { | |
960 | int ret; | |
961 | struct stream *s; | |
962 | ||
963 | /* Check socket. */ | |
964 | if (zlookup->sock < 0) | |
965 | return NULL; | |
966 | ||
967 | s = zlookup->obuf; | |
968 | stream_reset (s); | |
d3092e7f | 969 | zclient_create_header (s, ZEBRA_IPV6_NEXTHOP_LOOKUP); |
718e3744 | 970 | stream_put (s, addr, 16); |
d3092e7f | 971 | stream_putw_at (s, 0, stream_get_endp (s)); |
972 | ||
973 | ret = writen (zlookup->sock, s->data, stream_get_endp (s)); | |
718e3744 | 974 | if (ret < 0) |
975 | { | |
976 | zlog_err ("can't write to zlookup->sock"); | |
977 | close (zlookup->sock); | |
978 | zlookup->sock = -1; | |
979 | return NULL; | |
980 | } | |
981 | if (ret == 0) | |
982 | { | |
983 | zlog_err ("zlookup->sock connection closed"); | |
984 | close (zlookup->sock); | |
985 | zlookup->sock = -1; | |
986 | return NULL; | |
987 | } | |
988 | ||
989 | return zlookup_read_ipv6 (); | |
990 | } | |
991 | #endif /* HAVE_IPV6 */ | |
992 | ||
94f2b392 | 993 | static int |
994 | bgp_import_check (struct prefix *p, u_int32_t *igpmetric, | |
995 | struct in_addr *igpnexthop) | |
718e3744 | 996 | { |
997 | struct stream *s; | |
998 | int ret; | |
d3092e7f | 999 | u_int16_t length, command; |
1000 | u_char version, marker; | |
718e3744 | 1001 | int nbytes; |
1002 | struct in_addr addr; | |
1003 | struct in_addr nexthop; | |
1004 | u_int32_t metric = 0; | |
1005 | u_char nexthop_num; | |
1006 | u_char nexthop_type; | |
1007 | ||
1008 | /* If lookup connection is not available return valid. */ | |
1009 | if (zlookup->sock < 0) | |
1010 | { | |
1011 | if (igpmetric) | |
1012 | *igpmetric = 0; | |
1013 | return 1; | |
1014 | } | |
1015 | ||
1016 | /* Send query to the lookup connection */ | |
1017 | s = zlookup->obuf; | |
1018 | stream_reset (s); | |
d3092e7f | 1019 | zclient_create_header (s, ZEBRA_IPV4_IMPORT_LOOKUP); |
1020 | ||
718e3744 | 1021 | stream_putc (s, p->prefixlen); |
1022 | stream_put_in_addr (s, &p->u.prefix4); | |
d3092e7f | 1023 | |
1024 | stream_putw_at (s, 0, stream_get_endp (s)); | |
1025 | ||
718e3744 | 1026 | /* Write the packet. */ |
d3092e7f | 1027 | ret = writen (zlookup->sock, s->data, stream_get_endp (s)); |
718e3744 | 1028 | |
1029 | if (ret < 0) | |
1030 | { | |
1031 | zlog_err ("can't write to zlookup->sock"); | |
1032 | close (zlookup->sock); | |
1033 | zlookup->sock = -1; | |
1034 | return 1; | |
1035 | } | |
1036 | if (ret == 0) | |
1037 | { | |
1038 | zlog_err ("zlookup->sock connection closed"); | |
1039 | close (zlookup->sock); | |
1040 | zlookup->sock = -1; | |
1041 | return 1; | |
1042 | } | |
1043 | ||
1044 | /* Get result. */ | |
1045 | stream_reset (s); | |
1046 | ||
1047 | /* Fetch length. */ | |
1048 | nbytes = stream_read (s, zlookup->sock, 2); | |
1049 | length = stream_getw (s); | |
1050 | ||
1051 | /* Fetch whole data. */ | |
1052 | nbytes = stream_read (s, zlookup->sock, length - 2); | |
d3092e7f | 1053 | marker = stream_getc (s); |
1054 | version = stream_getc (s); | |
1055 | ||
1056 | if (version != ZSERV_VERSION || marker != ZEBRA_HEADER_MARKER) | |
1057 | { | |
1058 | zlog_err("%s: socket %d version mismatch, marker %d, version %d", | |
1059 | __func__, zlookup->sock, marker, version); | |
1060 | return 0; | |
1061 | } | |
1062 | ||
1063 | command = stream_getw (s); | |
1064 | ||
718e3744 | 1065 | addr.s_addr = stream_get_ipv4 (s); |
1066 | metric = stream_getl (s); | |
1067 | nexthop_num = stream_getc (s); | |
1068 | ||
1069 | /* Set IGP metric value. */ | |
1070 | if (igpmetric) | |
1071 | *igpmetric = metric; | |
1072 | ||
1073 | /* If there is nexthop then this is active route. */ | |
1074 | if (nexthop_num) | |
1075 | { | |
1076 | nexthop.s_addr = 0; | |
1077 | nexthop_type = stream_getc (s); | |
a12afd5e | 1078 | switch (nexthop_type) |
718e3744 | 1079 | { |
a12afd5e | 1080 | case ZEBRA_NEXTHOP_IPV4: |
718e3744 | 1081 | nexthop.s_addr = stream_get_ipv4 (s); |
a12afd5e CF |
1082 | break; |
1083 | case ZEBRA_NEXTHOP_IPV4_IFINDEX: | |
1084 | nexthop.s_addr = stream_get_ipv4 (s); | |
1085 | /* ifindex */ (void)stream_getl (s); | |
1086 | break; | |
1087 | default: | |
1088 | /* do nothing */ | |
1089 | break; | |
718e3744 | 1090 | } |
a12afd5e | 1091 | *igpnexthop = nexthop; |
718e3744 | 1092 | |
1093 | return 1; | |
1094 | } | |
1095 | else | |
1096 | return 0; | |
1097 | } | |
1098 | ||
1099 | /* Scan all configured BGP route then check the route exists in IGP or | |
1100 | not. */ | |
94f2b392 | 1101 | static int |
718e3744 | 1102 | bgp_import (struct thread *t) |
1103 | { | |
1104 | struct bgp *bgp; | |
1105 | struct bgp_node *rn; | |
1106 | struct bgp_static *bgp_static; | |
1eb8ef25 | 1107 | struct listnode *node, *nnode; |
718e3744 | 1108 | int valid; |
1109 | u_int32_t metric; | |
1110 | struct in_addr nexthop; | |
1111 | afi_t afi; | |
1112 | safi_t safi; | |
1113 | ||
1114 | bgp_import_thread = | |
1115 | thread_add_timer (master, bgp_import, NULL, bgp_import_interval); | |
1116 | ||
f418446b | 1117 | if (BGP_DEBUG (events, EVENTS)) |
1118 | zlog_debug ("Import timer expired."); | |
718e3744 | 1119 | |
1eb8ef25 | 1120 | for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) |
6cbbc3cc | 1121 | { |
1122 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
1123 | for (safi = SAFI_UNICAST; safi < SAFI_MPLS_VPN; safi++) | |
1124 | for (rn = bgp_table_top (bgp->route[afi][safi]); rn; | |
1125 | rn = bgp_route_next (rn)) | |
1126 | if ((bgp_static = rn->info) != NULL) | |
718e3744 | 1127 | { |
6cbbc3cc | 1128 | if (bgp_static->backdoor) |
1129 | continue; | |
718e3744 | 1130 | |
6cbbc3cc | 1131 | valid = bgp_static->valid; |
1132 | metric = bgp_static->igpmetric; | |
1133 | nexthop = bgp_static->igpnexthop; | |
1134 | ||
1135 | if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK) | |
1136 | && afi == AFI_IP && safi == SAFI_UNICAST) | |
1137 | bgp_static->valid = bgp_import_check (&rn->p, &bgp_static->igpmetric, | |
1138 | &bgp_static->igpnexthop); | |
718e3744 | 1139 | else |
6cbbc3cc | 1140 | { |
1141 | bgp_static->valid = 1; | |
1142 | bgp_static->igpmetric = 0; | |
1143 | bgp_static->igpnexthop.s_addr = 0; | |
1144 | } | |
1145 | ||
1146 | if (bgp_static->valid != valid) | |
1147 | { | |
1148 | if (bgp_static->valid) | |
1149 | bgp_static_update (bgp, &rn->p, bgp_static, afi, safi); | |
1150 | else | |
1151 | bgp_static_withdraw (bgp, &rn->p, afi, safi); | |
1152 | } | |
1153 | else if (bgp_static->valid) | |
1154 | { | |
1155 | if (bgp_static->igpmetric != metric | |
1156 | || bgp_static->igpnexthop.s_addr != nexthop.s_addr | |
1157 | || bgp_static->rmap.name) | |
1158 | bgp_static_update (bgp, &rn->p, bgp_static, afi, safi); | |
1159 | } | |
718e3744 | 1160 | } |
6cbbc3cc | 1161 | } |
718e3744 | 1162 | return 0; |
1163 | } | |
1164 | ||
1165 | /* Connect to zebra for nexthop lookup. */ | |
94f2b392 | 1166 | static int |
718e3744 | 1167 | zlookup_connect (struct thread *t) |
1168 | { | |
1169 | struct zclient *zlookup; | |
1170 | ||
1171 | zlookup = THREAD_ARG (t); | |
1172 | zlookup->t_connect = NULL; | |
1173 | ||
1174 | if (zlookup->sock != -1) | |
1175 | return 0; | |
1176 | ||
b5114685 | 1177 | if (zclient_socket_connect (zlookup) < 0) |
718e3744 | 1178 | return -1; |
1179 | ||
718e3744 | 1180 | return 0; |
1181 | } | |
1182 | ||
1183 | /* Check specified multiaccess next-hop. */ | |
1184 | int | |
1185 | bgp_multiaccess_check_v4 (struct in_addr nexthop, char *peer) | |
1186 | { | |
1187 | struct bgp_node *rn1; | |
1188 | struct bgp_node *rn2; | |
1189 | struct prefix p1; | |
1190 | struct prefix p2; | |
1191 | struct in_addr addr; | |
1192 | int ret; | |
1193 | ||
1194 | ret = inet_aton (peer, &addr); | |
1195 | if (! ret) | |
1196 | return 0; | |
1197 | ||
1198 | memset (&p1, 0, sizeof (struct prefix)); | |
1199 | p1.family = AF_INET; | |
1200 | p1.prefixlen = IPV4_MAX_BITLEN; | |
1201 | p1.u.prefix4 = nexthop; | |
1202 | memset (&p2, 0, sizeof (struct prefix)); | |
1203 | p2.family = AF_INET; | |
1204 | p2.prefixlen = IPV4_MAX_BITLEN; | |
1205 | p2.u.prefix4 = addr; | |
1206 | ||
1207 | /* If bgp scan is not enabled, return invalid. */ | |
1208 | if (zlookup->sock < 0) | |
1209 | return 0; | |
1210 | ||
5932020b | 1211 | rn1 = bgp_node_match (bgp_connected_table[AFI_IP], &p1); |
718e3744 | 1212 | if (! rn1) |
1213 | return 0; | |
6c88b44d | 1214 | bgp_unlock_node (rn1); |
718e3744 | 1215 | |
5932020b | 1216 | rn2 = bgp_node_match (bgp_connected_table[AFI_IP], &p2); |
718e3744 | 1217 | if (! rn2) |
1218 | return 0; | |
6c88b44d | 1219 | bgp_unlock_node (rn2); |
718e3744 | 1220 | |
6c88b44d CC |
1221 | /* This is safe, even with above unlocks, since we are just |
1222 | comparing pointers to the objects, not the objects themselves. */ | |
718e3744 | 1223 | if (rn1 == rn2) |
1224 | return 1; | |
1225 | ||
1226 | return 0; | |
1227 | } | |
6b0655a2 | 1228 | |
718e3744 | 1229 | DEFUN (bgp_scan_time, |
1230 | bgp_scan_time_cmd, | |
1231 | "bgp scan-time <5-60>", | |
1232 | "BGP specific commands\n" | |
1233 | "Configure background scanner interval\n" | |
1234 | "Scanner interval (seconds)\n") | |
1235 | { | |
1236 | bgp_scan_interval = atoi (argv[0]); | |
1237 | ||
1238 | if (bgp_scan_thread) | |
1239 | { | |
1240 | thread_cancel (bgp_scan_thread); | |
1241 | bgp_scan_thread = | |
5932020b | 1242 | thread_add_timer (master, bgp_scan_timer, NULL, bgp_scan_interval); |
718e3744 | 1243 | } |
1244 | ||
1245 | return CMD_SUCCESS; | |
1246 | } | |
1247 | ||
1248 | DEFUN (no_bgp_scan_time, | |
1249 | no_bgp_scan_time_cmd, | |
1250 | "no bgp scan-time", | |
1251 | NO_STR | |
1252 | "BGP specific commands\n" | |
1253 | "Configure background scanner interval\n") | |
1254 | { | |
1255 | bgp_scan_interval = BGP_SCAN_INTERVAL_DEFAULT; | |
1256 | ||
1257 | if (bgp_scan_thread) | |
1258 | { | |
1259 | thread_cancel (bgp_scan_thread); | |
1260 | bgp_scan_thread = | |
5932020b | 1261 | thread_add_timer (master, bgp_scan_timer, NULL, bgp_scan_interval); |
718e3744 | 1262 | } |
1263 | ||
1264 | return CMD_SUCCESS; | |
1265 | } | |
1266 | ||
1267 | ALIAS (no_bgp_scan_time, | |
1268 | no_bgp_scan_time_val_cmd, | |
1269 | "no bgp scan-time <5-60>", | |
1270 | NO_STR | |
1271 | "BGP specific commands\n" | |
1272 | "Configure background scanner interval\n" | |
1273 | "Scanner interval (seconds)\n") | |
1274 | ||
318f0d8a DO |
1275 | static int |
1276 | show_ip_bgp_scan_tables (struct vty *vty, const char detail) | |
718e3744 | 1277 | { |
1278 | struct bgp_node *rn; | |
318f0d8a | 1279 | char buf[INET6_ADDRSTRLEN]; |
718e3744 | 1280 | |
1281 | if (bgp_scan_thread) | |
1282 | vty_out (vty, "BGP scan is running%s", VTY_NEWLINE); | |
1283 | else | |
1284 | vty_out (vty, "BGP scan is not running%s", VTY_NEWLINE); | |
1285 | vty_out (vty, "BGP scan interval is %d%s", bgp_scan_interval, VTY_NEWLINE); | |
1286 | ||
fb018d25 | 1287 | #if BGP_SCAN_NEXTHOP |
718e3744 | 1288 | vty_out (vty, "Current BGP nexthop cache:%s", VTY_NEWLINE); |
5932020b | 1289 | for (rn = bgp_table_top (bgp_nexthop_cache_table[AFI_IP]); rn; rn = bgp_route_next (rn)) |
718e3744 | 1290 | if ((bnc = rn->info) != NULL) |
1291 | { | |
1292 | if (bnc->valid) | |
318f0d8a | 1293 | { |
718e3744 | 1294 | vty_out (vty, " %s valid [IGP metric %d]%s", |
318f0d8a DO |
1295 | inet_ntop (AF_INET, &rn->p.u.prefix4, buf, INET6_ADDRSTRLEN), bnc->metric, VTY_NEWLINE); |
1296 | if (detail) | |
1297 | for (i = 0; i < bnc->nexthop_num; i++) | |
0e8032d6 DO |
1298 | switch (bnc->nexthop[i].type) |
1299 | { | |
1300 | case NEXTHOP_TYPE_IPV4: | |
1301 | vty_out (vty, " gate %s%s", inet_ntop (AF_INET, &bnc->nexthop[i].gate.ipv4, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); | |
1302 | break; | |
bb97e462 CF |
1303 | case NEXTHOP_TYPE_IPV4_IFINDEX: |
1304 | vty_out (vty, " gate %s", inet_ntop (AF_INET, &bnc->nexthop[i].gate.ipv4, buf, INET6_ADDRSTRLEN)); | |
1305 | vty_out (vty, " ifidx %u%s", bnc->nexthop[i].ifindex, VTY_NEWLINE); | |
1306 | break; | |
0e8032d6 DO |
1307 | case NEXTHOP_TYPE_IFINDEX: |
1308 | vty_out (vty, " ifidx %u%s", bnc->nexthop[i].ifindex, VTY_NEWLINE); | |
1309 | break; | |
1310 | default: | |
1311 | vty_out (vty, " invalid nexthop type %u%s", bnc->nexthop[i].type, VTY_NEWLINE); | |
1312 | } | |
318f0d8a | 1313 | } |
718e3744 | 1314 | else |
1315 | vty_out (vty, " %s invalid%s", | |
318f0d8a | 1316 | inet_ntop (AF_INET, &rn->p.u.prefix4, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); |
718e3744 | 1317 | } |
1318 | ||
1319 | #ifdef HAVE_IPV6 | |
1320 | { | |
5932020b | 1321 | for (rn = bgp_table_top (bgp_nexthop_cache_table[AFI_IP6]); |
1322 | rn; | |
1323 | rn = bgp_route_next (rn)) | |
718e3744 | 1324 | if ((bnc = rn->info) != NULL) |
1325 | { | |
1326 | if (bnc->valid) | |
318f0d8a | 1327 | { |
718e3744 | 1328 | vty_out (vty, " %s valid [IGP metric %d]%s", |
318f0d8a | 1329 | inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, INET6_ADDRSTRLEN), |
718e3744 | 1330 | bnc->metric, VTY_NEWLINE); |
318f0d8a DO |
1331 | if (detail) |
1332 | for (i = 0; i < bnc->nexthop_num; i++) | |
0e8032d6 DO |
1333 | switch (bnc->nexthop[i].type) |
1334 | { | |
1335 | case NEXTHOP_TYPE_IPV6: | |
1336 | vty_out (vty, " gate %s%s", inet_ntop (AF_INET6, &bnc->nexthop[i].gate.ipv6, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); | |
1337 | break; | |
1338 | case NEXTHOP_TYPE_IFINDEX: | |
1339 | vty_out (vty, " ifidx %u%s", bnc->nexthop[i].ifindex, VTY_NEWLINE); | |
1340 | break; | |
1341 | default: | |
1342 | vty_out (vty, " invalid nexthop type %u%s", bnc->nexthop[i].type, VTY_NEWLINE); | |
1343 | } | |
318f0d8a | 1344 | } |
718e3744 | 1345 | else |
1346 | vty_out (vty, " %s invalid%s", | |
318f0d8a | 1347 | inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, INET6_ADDRSTRLEN), |
718e3744 | 1348 | VTY_NEWLINE); |
1349 | } | |
1350 | } | |
1351 | #endif /* HAVE_IPV6 */ | |
fb018d25 DS |
1352 | #else |
1353 | vty_out (vty, "BGP next-hop tracking is on%s", VTY_NEWLINE); | |
1354 | #endif | |
718e3744 | 1355 | vty_out (vty, "BGP connected route:%s", VTY_NEWLINE); |
5932020b | 1356 | for (rn = bgp_table_top (bgp_connected_table[AFI_IP]); |
1357 | rn; | |
1358 | rn = bgp_route_next (rn)) | |
718e3744 | 1359 | if (rn->info != NULL) |
1360 | vty_out (vty, " %s/%d%s", inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen, | |
1361 | VTY_NEWLINE); | |
1362 | ||
1363 | #ifdef HAVE_IPV6 | |
1364 | { | |
5932020b | 1365 | for (rn = bgp_table_top (bgp_connected_table[AFI_IP6]); |
1366 | rn; | |
1367 | rn = bgp_route_next (rn)) | |
718e3744 | 1368 | if (rn->info != NULL) |
1369 | vty_out (vty, " %s/%d%s", | |
318f0d8a | 1370 | inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, INET6_ADDRSTRLEN), |
718e3744 | 1371 | rn->p.prefixlen, |
1372 | VTY_NEWLINE); | |
1373 | } | |
1374 | #endif /* HAVE_IPV6 */ | |
1375 | ||
1376 | return CMD_SUCCESS; | |
1377 | } | |
1378 | ||
fb018d25 DS |
1379 | static int |
1380 | show_ip_bgp_nexthop_table (struct vty *vty, int detail) | |
1381 | { | |
1382 | struct bgp_node *rn; | |
1383 | struct bgp_nexthop_cache *bnc; | |
1384 | char buf[INET6_ADDRSTRLEN]; | |
1385 | time_t tbuf; | |
1386 | u_char i; | |
1387 | ||
1388 | vty_out (vty, "Current BGP nexthop cache:%s", VTY_NEWLINE); | |
1389 | for (rn = bgp_table_top (bgp_nexthop_cache_table[AFI_IP]); rn; rn = bgp_route_next (rn)) | |
1390 | if ((bnc = rn->info) != NULL) | |
1391 | { | |
1392 | if (CHECK_FLAG(bnc->flags, BGP_NEXTHOP_VALID)) | |
1393 | { | |
1394 | vty_out (vty, " %s valid [IGP metric %d], #paths %d%s", | |
1395 | inet_ntop (AF_INET, &rn->p.u.prefix4, buf, INET6_ADDRSTRLEN), | |
1396 | bnc->metric, bnc->path_count, VTY_NEWLINE); | |
1397 | if (detail) | |
1398 | for (i = 0; i < bnc->nexthop_num; i++) | |
1399 | switch (bnc->nexthop[i].type) | |
1400 | { | |
1401 | case NEXTHOP_TYPE_IPV4: | |
1402 | vty_out (vty, " gate %s%s", | |
1403 | inet_ntop (AF_INET, &bnc->nexthop[i].gate.ipv4, buf, | |
1404 | INET6_ADDRSTRLEN), VTY_NEWLINE); | |
1405 | break; | |
1406 | case NEXTHOP_TYPE_IFINDEX: | |
1407 | vty_out (vty, " if %s%s", | |
1408 | ifindex2ifname(bnc->nexthop[i].ifindex), VTY_NEWLINE); | |
1409 | break; | |
1410 | case NEXTHOP_TYPE_IPV4_IFINDEX: | |
1411 | vty_out (vty, " gate %s, if %s%s", | |
1412 | inet_ntop(AF_INET, &bnc->nexthop[i].gate.ipv4, buf, | |
1413 | INET6_ADDRSTRLEN), | |
1414 | ifindex2ifname(bnc->nexthop[i].ifindex), VTY_NEWLINE); | |
1415 | break; | |
1416 | default: | |
1417 | vty_out (vty, " invalid nexthop type %u%s", | |
1418 | bnc->nexthop[i].type, VTY_NEWLINE); | |
1419 | } | |
1420 | } | |
1421 | else | |
1422 | vty_out (vty, " %s invalid%s", | |
1423 | inet_ntop (AF_INET, &rn->p.u.prefix4, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); | |
1424 | #ifdef HAVE_CLOCK_MONOTONIC | |
1425 | tbuf = time(NULL) - (bgp_clock() - bnc->last_update); | |
1426 | vty_out (vty, " Last update: %s", ctime(&tbuf)); | |
1427 | #else | |
1428 | vty_out (vty, " Last update: %s", ctime(&bnc->uptime)); | |
1429 | #endif /* HAVE_CLOCK_MONOTONIC */ | |
1430 | ||
1431 | vty_out(vty, "%s", VTY_NEWLINE); | |
1432 | } | |
1433 | ||
1434 | #ifdef HAVE_IPV6 | |
1435 | { | |
1436 | for (rn = bgp_table_top (bgp_nexthop_cache_table[AFI_IP6]); | |
1437 | rn; | |
1438 | rn = bgp_route_next (rn)) | |
1439 | if ((bnc = rn->info) != NULL) | |
1440 | { | |
1441 | if (CHECK_FLAG(bnc->flags, BGP_NEXTHOP_VALID)) | |
1442 | { | |
1443 | vty_out (vty, " %s valid [IGP metric %d]%s", | |
1444 | inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, | |
1445 | INET6_ADDRSTRLEN), | |
1446 | bnc->metric, VTY_NEWLINE); | |
1447 | if (detail) | |
1448 | for (i = 0; i < bnc->nexthop_num; i++) | |
1449 | switch (bnc->nexthop[i].type) | |
1450 | { | |
1451 | case NEXTHOP_TYPE_IPV6: | |
1452 | vty_out (vty, " gate %s%s", | |
1453 | inet_ntop (AF_INET6, &bnc->nexthop[i].gate.ipv6, | |
1454 | buf, INET6_ADDRSTRLEN), VTY_NEWLINE); | |
1455 | break; | |
1456 | case NEXTHOP_TYPE_IPV6_IFINDEX: | |
1457 | vty_out(vty, " gate %s, if %s%s", | |
1458 | inet_ntop(AF_INET6, &bnc->nexthop[i].gate.ipv6, buf, | |
1459 | INET6_ADDRSTRLEN), | |
1460 | ifindex2ifname(bnc->nexthop[i].ifindex), | |
1461 | VTY_NEWLINE); | |
1462 | break; | |
1463 | case NEXTHOP_TYPE_IFINDEX: | |
1464 | vty_out (vty, " ifidx %u%s", bnc->nexthop[i].ifindex, | |
1465 | VTY_NEWLINE); | |
1466 | break; | |
1467 | default: | |
1468 | vty_out (vty, " invalid nexthop type %u%s", | |
1469 | bnc->nexthop[i].type, VTY_NEWLINE); | |
1470 | } | |
1471 | } | |
1472 | else | |
1473 | vty_out (vty, " %s invalid%s", | |
1474 | inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, INET6_ADDRSTRLEN), | |
1475 | VTY_NEWLINE); | |
1476 | #ifdef HAVE_CLOCK_MONOTONIC | |
1477 | tbuf = time(NULL) - (bgp_clock() - bnc->last_update); | |
1478 | vty_out (vty, " Last update: %s", ctime(&tbuf)); | |
1479 | #else | |
1480 | vty_out (vty, " Last update: %s", ctime(&bnc->uptime)); | |
1481 | #endif /* HAVE_CLOCK_MONOTONIC */ | |
1482 | ||
1483 | vty_out(vty, "%s", VTY_NEWLINE); | |
1484 | } | |
1485 | } | |
1486 | #endif /* HAVE_IPV6 */ | |
1487 | return CMD_SUCCESS; | |
1488 | } | |
1489 | ||
318f0d8a DO |
1490 | DEFUN (show_ip_bgp_scan, |
1491 | show_ip_bgp_scan_cmd, | |
1492 | "show ip bgp scan", | |
1493 | SHOW_STR | |
1494 | IP_STR | |
1495 | BGP_STR | |
1496 | "BGP scan status\n") | |
1497 | { | |
1498 | return show_ip_bgp_scan_tables (vty, 0); | |
1499 | } | |
1500 | ||
1501 | DEFUN (show_ip_bgp_scan_detail, | |
1502 | show_ip_bgp_scan_detail_cmd, | |
1503 | "show ip bgp scan detail", | |
1504 | SHOW_STR | |
1505 | IP_STR | |
1506 | BGP_STR | |
1507 | "BGP scan status\n" | |
1508 | "More detailed output\n") | |
1509 | { | |
1510 | return show_ip_bgp_scan_tables (vty, 1); | |
1511 | } | |
1512 | ||
fb018d25 DS |
1513 | DEFUN (show_ip_bgp_nexthop, |
1514 | show_ip_bgp_nexthop_cmd, | |
1515 | "show ip bgp nexthop", | |
1516 | SHOW_STR | |
1517 | IP_STR | |
1518 | BGP_STR | |
1519 | "BGP nexthop table\n") | |
1520 | { | |
1521 | return show_ip_bgp_nexthop_table (vty, 0); | |
1522 | } | |
1523 | ||
1524 | DEFUN (show_ip_bgp_nexthop_detail, | |
1525 | show_ip_bgp_nexthop_detail_cmd, | |
1526 | "show ip bgp nexthop detail", | |
1527 | SHOW_STR | |
1528 | IP_STR | |
1529 | BGP_STR | |
1530 | "BGP nexthop table\n") | |
1531 | { | |
1532 | return show_ip_bgp_nexthop_table (vty, 1); | |
1533 | } | |
1534 | ||
718e3744 | 1535 | int |
1536 | bgp_config_write_scan_time (struct vty *vty) | |
1537 | { | |
1538 | if (bgp_scan_interval != BGP_SCAN_INTERVAL_DEFAULT) | |
1539 | vty_out (vty, " bgp scan-time %d%s", bgp_scan_interval, VTY_NEWLINE); | |
1540 | return CMD_SUCCESS; | |
1541 | } | |
1542 | ||
1543 | void | |
66e5cd87 | 1544 | bgp_scan_init (void) |
718e3744 | 1545 | { |
1546 | zlookup = zclient_new (); | |
1547 | zlookup->sock = -1; | |
718e3744 | 1548 | zlookup->t_connect = thread_add_event (master, zlookup_connect, zlookup, 0); |
1549 | ||
1550 | bgp_scan_interval = BGP_SCAN_INTERVAL_DEFAULT; | |
1551 | bgp_import_interval = BGP_IMPORT_INTERVAL_DEFAULT; | |
1552 | ||
64e580a7 PJ |
1553 | cache1_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST); |
1554 | cache2_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST); | |
5932020b | 1555 | bgp_nexthop_cache_table[AFI_IP] = cache1_table[AFI_IP]; |
718e3744 | 1556 | |
64e580a7 | 1557 | bgp_connected_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST); |
718e3744 | 1558 | |
1559 | #ifdef HAVE_IPV6 | |
64e580a7 PJ |
1560 | cache1_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST); |
1561 | cache2_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST); | |
5932020b | 1562 | bgp_nexthop_cache_table[AFI_IP6] = cache1_table[AFI_IP6]; |
64e580a7 | 1563 | bgp_connected_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST); |
718e3744 | 1564 | #endif /* HAVE_IPV6 */ |
1565 | ||
1566 | /* Make BGP scan thread. */ | |
5932020b | 1567 | bgp_scan_thread = thread_add_timer (master, bgp_scan_timer, |
1568 | NULL, bgp_scan_interval); | |
6cbbc3cc | 1569 | /* Make BGP import there. */ |
1570 | bgp_import_thread = thread_add_timer (master, bgp_import, NULL, 0); | |
718e3744 | 1571 | |
1572 | install_element (BGP_NODE, &bgp_scan_time_cmd); | |
1573 | install_element (BGP_NODE, &no_bgp_scan_time_cmd); | |
1574 | install_element (BGP_NODE, &no_bgp_scan_time_val_cmd); | |
1575 | install_element (VIEW_NODE, &show_ip_bgp_scan_cmd); | |
318f0d8a | 1576 | install_element (VIEW_NODE, &show_ip_bgp_scan_detail_cmd); |
fb018d25 DS |
1577 | install_element (VIEW_NODE, &show_ip_bgp_nexthop_cmd); |
1578 | install_element (VIEW_NODE, &show_ip_bgp_nexthop_detail_cmd); | |
62687ff1 | 1579 | install_element (RESTRICTED_NODE, &show_ip_bgp_scan_cmd); |
718e3744 | 1580 | install_element (ENABLE_NODE, &show_ip_bgp_scan_cmd); |
fb018d25 DS |
1581 | install_element (ENABLE_NODE, &show_ip_bgp_nexthop_cmd); |
1582 | install_element (ENABLE_NODE, &show_ip_bgp_nexthop_detail_cmd); | |
318f0d8a | 1583 | install_element (ENABLE_NODE, &show_ip_bgp_scan_detail_cmd); |
718e3744 | 1584 | } |
228da428 CC |
1585 | |
1586 | void | |
1587 | bgp_scan_finish (void) | |
1588 | { | |
6c88b44d CC |
1589 | /* Only the current one needs to be reset. */ |
1590 | bgp_nexthop_cache_reset (bgp_nexthop_cache_table[AFI_IP]); | |
1591 | ||
228da428 CC |
1592 | bgp_table_unlock (cache1_table[AFI_IP]); |
1593 | cache1_table[AFI_IP] = NULL; | |
1594 | ||
1595 | bgp_table_unlock (cache2_table[AFI_IP]); | |
1596 | cache2_table[AFI_IP] = NULL; | |
1597 | ||
1598 | bgp_table_unlock (bgp_connected_table[AFI_IP]); | |
1599 | bgp_connected_table[AFI_IP] = NULL; | |
1600 | ||
1601 | #ifdef HAVE_IPV6 | |
6c88b44d CC |
1602 | /* Only the current one needs to be reset. */ |
1603 | bgp_nexthop_cache_reset (bgp_nexthop_cache_table[AFI_IP6]); | |
1604 | ||
228da428 CC |
1605 | bgp_table_unlock (cache1_table[AFI_IP6]); |
1606 | cache1_table[AFI_IP6] = NULL; | |
1607 | ||
1608 | bgp_table_unlock (cache2_table[AFI_IP6]); | |
1609 | cache2_table[AFI_IP6] = NULL; | |
1610 | ||
1611 | bgp_table_unlock (bgp_connected_table[AFI_IP6]); | |
1612 | bgp_connected_table[AFI_IP6] = NULL; | |
1613 | #endif /* HAVE_IPV6 */ | |
1614 | } |