blob: 479ef949388b543ad61470ea03a922271feefda9 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP nexthop scan
2 Copyright (C) 2000 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-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"
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +000031#include "hash.h"
32#include "jhash.h"
Donald Sharp04907292016-01-07 10:03:01 -050033#include "filter.h"
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050034#include "nexthop.h"
paul718e3742002-12-13 20:15:29 +000035
36#include "bgpd/bgpd.h"
37#include "bgpd/bgp_table.h"
38#include "bgpd/bgp_route.h"
39#include "bgpd/bgp_attr.h"
40#include "bgpd/bgp_nexthop.h"
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050041#include "bgpd/bgp_nht.h"
paul718e3742002-12-13 20:15:29 +000042#include "bgpd/bgp_debug.h"
43#include "bgpd/bgp_damp.h"
44#include "zebra/rib.h"
45#include "zebra/zserv.h" /* For ZEBRA_SERV_PATH. */
46
paul718e3742002-12-13 20:15:29 +000047
48/* Route table for next-hop lookup cache. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050049struct bgp_table *bgp_nexthop_cache_table[AFI_MAX];
paul00d252c2005-05-23 14:19:54 +000050static struct bgp_table *cache1_table[AFI_MAX];
paul718e3742002-12-13 20:15:29 +000051
52/* Route table for connected route. */
paul00d252c2005-05-23 14:19:54 +000053static struct bgp_table *bgp_connected_table[AFI_MAX];
paul718e3742002-12-13 20:15:29 +000054
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050055char *
56bnc_str (struct bgp_nexthop_cache *bnc, char *buf, int size)
57{
58 prefix2str(&(bnc->node->p), buf, size);
59 return buf;
60}
61
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050062void
paul718e3742002-12-13 20:15:29 +000063bnc_nexthop_free (struct bgp_nexthop_cache *bnc)
64{
65 struct nexthop *nexthop;
66 struct nexthop *next = NULL;
67
68 for (nexthop = bnc->nexthop; nexthop; nexthop = next)
69 {
70 next = nexthop->next;
71 XFREE (MTYPE_NEXTHOP, nexthop);
72 }
73}
74
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050075struct bgp_nexthop_cache *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080076bnc_new (void)
paul718e3742002-12-13 20:15:29 +000077{
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050078 struct bgp_nexthop_cache *bnc;
79
80 bnc = XCALLOC (MTYPE_BGP_NEXTHOP_CACHE, sizeof (struct bgp_nexthop_cache));
81 LIST_INIT(&(bnc->paths));
82 return bnc;
paul718e3742002-12-13 20:15:29 +000083}
84
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050085void
paul718e3742002-12-13 20:15:29 +000086bnc_free (struct bgp_nexthop_cache *bnc)
87{
88 bnc_nexthop_free (bnc);
89 XFREE (MTYPE_BGP_NEXTHOP_CACHE, bnc);
90}
David Lamparter6b0655a2014-06-04 06:53:35 +020091
paul718e3742002-12-13 20:15:29 +000092/* If nexthop exists on connected network return 1. */
93int
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +040094bgp_nexthop_onlink (afi_t afi, struct attr *attr)
paul718e3742002-12-13 20:15:29 +000095{
96 struct bgp_node *rn;
Paul Jakmafc98d162012-01-09 11:36:23 +000097
paul718e3742002-12-13 20:15:29 +000098 /* Lookup the address is onlink or not. */
99 if (afi == AFI_IP)
100 {
paul59320202004-11-09 01:54:03 +0000101 rn = bgp_node_match_ipv4 (bgp_connected_table[AFI_IP], &attr->nexthop);
paul718e3742002-12-13 20:15:29 +0000102 if (rn)
103 {
104 bgp_unlock_node (rn);
105 return 1;
106 }
107 }
paul718e3742002-12-13 20:15:29 +0000108 else if (afi == AFI_IP6)
109 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000110 if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +0000111 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000112 else if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +0000113 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000114 if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000115 return 1;
116
paul59320202004-11-09 01:54:03 +0000117 rn = bgp_node_match_ipv6 (bgp_connected_table[AFI_IP6],
Paul Jakmafb982c22007-05-04 20:15:47 +0000118 &attr->extra->mp_nexthop_global);
paul718e3742002-12-13 20:15:29 +0000119 if (rn)
120 {
121 bgp_unlock_node (rn);
122 return 1;
123 }
124 }
125 }
paul718e3742002-12-13 20:15:29 +0000126 return 0;
127}
128
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +0000129/* BGP own address structure */
130struct bgp_addr
131{
132 struct in_addr addr;
133 int refcnt;
134};
135
136static struct hash *bgp_address_hash;
137
138static void *
139bgp_address_hash_alloc (void *p)
140{
141 struct in_addr *val = p;
142 struct bgp_addr *addr;
143
144 addr = XMALLOC (MTYPE_BGP_ADDR, sizeof (struct bgp_addr));
145 addr->refcnt = 0;
146 addr->addr.s_addr = val->s_addr;
147
148 return addr;
149}
150
151static unsigned int
152bgp_address_hash_key_make (void *p)
153{
154 const struct bgp_addr *addr = p;
155
156 return jhash_1word(addr->addr.s_addr, 0);
157}
158
159static int
160bgp_address_hash_cmp (const void *p1, const void *p2)
161{
162 const struct bgp_addr *addr1 = p1;
163 const struct bgp_addr *addr2 = p2;
164
165 return addr1->addr.s_addr == addr2->addr.s_addr;
166}
167
168void
169bgp_address_init (void)
170{
171 bgp_address_hash = hash_create (bgp_address_hash_key_make,
172 bgp_address_hash_cmp);
173}
174
Lou Berger82dd7072016-01-12 13:41:57 -0500175void
176bgp_address_destroy (void)
177{
Lou Bergerd5d5e3e2016-01-12 13:41:58 -0500178 if (bgp_address_hash == NULL)
179 return;
180
Lou Berger82dd7072016-01-12 13:41:57 -0500181 hash_clean(bgp_address_hash, NULL);
182 hash_free(bgp_address_hash);
183 bgp_address_hash = NULL;
184}
185
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +0000186static void
187bgp_address_add (struct prefix *p)
188{
189 struct bgp_addr tmp;
190 struct bgp_addr *addr;
191
192 tmp.addr = p->u.prefix4;
193
194 addr = hash_get (bgp_address_hash, &tmp, bgp_address_hash_alloc);
Pradosh Mohapatra94627e62015-11-09 20:21:45 -0500195 if (!addr)
196 return;
197
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +0000198 addr->refcnt++;
199}
200
201static void
202bgp_address_del (struct prefix *p)
203{
204 struct bgp_addr tmp;
205 struct bgp_addr *addr;
206
207 tmp.addr = p->u.prefix4;
208
209 addr = hash_lookup (bgp_address_hash, &tmp);
Rakesh Garimella9e47abd2013-03-11 12:38:31 +0000210 /* may have been deleted earlier by bgp_interface_down() */
211 if (addr == NULL)
212 return;
213
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +0000214 addr->refcnt--;
215
216 if (addr->refcnt == 0)
217 {
218 hash_release (bgp_address_hash, addr);
219 XFREE (MTYPE_BGP_ADDR, addr);
220 }
221}
222
David Lamparter6b0655a2014-06-04 06:53:35 +0200223
paul59320202004-11-09 01:54:03 +0000224struct bgp_connected_ref
paul718e3742002-12-13 20:15:29 +0000225{
226 unsigned int refcnt;
227};
228
229void
230bgp_connected_add (struct connected *ifc)
231{
232 struct prefix p;
233 struct prefix *addr;
paul718e3742002-12-13 20:15:29 +0000234 struct interface *ifp;
235 struct bgp_node *rn;
paul59320202004-11-09 01:54:03 +0000236 struct bgp_connected_ref *bc;
paul718e3742002-12-13 20:15:29 +0000237
238 ifp = ifc->ifp;
239
240 if (! ifp)
241 return;
242
243 if (if_is_loopback (ifp))
244 return;
245
246 addr = ifc->address;
paul718e3742002-12-13 20:15:29 +0000247
Donald Sharp26a18eb2015-09-29 09:25:10 -0400248 p = *(CONNECTED_PREFIX(ifc));
paul718e3742002-12-13 20:15:29 +0000249 if (addr->family == AF_INET)
250 {
paul718e3742002-12-13 20:15:29 +0000251 apply_mask_ipv4 ((struct prefix_ipv4 *) &p);
252
253 if (prefix_ipv4_any ((struct prefix_ipv4 *) &p))
254 return;
255
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +0000256 bgp_address_add (addr);
257
paul59320202004-11-09 01:54:03 +0000258 rn = bgp_node_get (bgp_connected_table[AFI_IP], (struct prefix *) &p);
paul718e3742002-12-13 20:15:29 +0000259 if (rn->info)
260 {
261 bc = rn->info;
262 bc->refcnt++;
263 }
264 else
265 {
Chris Caputo6c88b442010-07-27 16:28:55 +0000266 bc = XCALLOC (MTYPE_BGP_CONN, sizeof (struct bgp_connected_ref));
paul718e3742002-12-13 20:15:29 +0000267 bc->refcnt = 1;
268 rn->info = bc;
269 }
270 }
Andrew J. Schorre4529632006-12-12 19:18:21 +0000271 else if (addr->family == AF_INET6)
paul718e3742002-12-13 20:15:29 +0000272 {
paul718e3742002-12-13 20:15:29 +0000273 apply_mask_ipv6 ((struct prefix_ipv6 *) &p);
274
275 if (IN6_IS_ADDR_UNSPECIFIED (&p.u.prefix6))
276 return;
277
278 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
279 return;
280
paul59320202004-11-09 01:54:03 +0000281 rn = bgp_node_get (bgp_connected_table[AFI_IP6], (struct prefix *) &p);
paul718e3742002-12-13 20:15:29 +0000282 if (rn->info)
283 {
284 bc = rn->info;
285 bc->refcnt++;
286 }
287 else
288 {
Chris Caputo6c88b442010-07-27 16:28:55 +0000289 bc = XCALLOC (MTYPE_BGP_CONN, sizeof (struct bgp_connected_ref));
paul718e3742002-12-13 20:15:29 +0000290 bc->refcnt = 1;
291 rn->info = bc;
292 }
293 }
paul718e3742002-12-13 20:15:29 +0000294}
295
296void
297bgp_connected_delete (struct connected *ifc)
298{
299 struct prefix p;
300 struct prefix *addr;
paul718e3742002-12-13 20:15:29 +0000301 struct interface *ifp;
302 struct bgp_node *rn;
paul59320202004-11-09 01:54:03 +0000303 struct bgp_connected_ref *bc;
paul718e3742002-12-13 20:15:29 +0000304
305 ifp = ifc->ifp;
306
307 if (if_is_loopback (ifp))
308 return;
309
310 addr = ifc->address;
paul718e3742002-12-13 20:15:29 +0000311
Donald Sharp26a18eb2015-09-29 09:25:10 -0400312 p = *(CONNECTED_PREFIX(ifc));
paul718e3742002-12-13 20:15:29 +0000313 if (addr->family == AF_INET)
314 {
paul718e3742002-12-13 20:15:29 +0000315 apply_mask_ipv4 ((struct prefix_ipv4 *) &p);
316
317 if (prefix_ipv4_any ((struct prefix_ipv4 *) &p))
318 return;
319
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +0000320 bgp_address_del (addr);
321
paul59320202004-11-09 01:54:03 +0000322 rn = bgp_node_lookup (bgp_connected_table[AFI_IP], &p);
paul718e3742002-12-13 20:15:29 +0000323 if (! rn)
324 return;
325
326 bc = rn->info;
327 bc->refcnt--;
328 if (bc->refcnt == 0)
329 {
Chris Caputo6c88b442010-07-27 16:28:55 +0000330 XFREE (MTYPE_BGP_CONN, bc);
paul718e3742002-12-13 20:15:29 +0000331 rn->info = NULL;
332 }
333 bgp_unlock_node (rn);
334 bgp_unlock_node (rn);
335 }
paul718e3742002-12-13 20:15:29 +0000336 else if (addr->family == AF_INET6)
337 {
paul718e3742002-12-13 20:15:29 +0000338 apply_mask_ipv6 ((struct prefix_ipv6 *) &p);
339
340 if (IN6_IS_ADDR_UNSPECIFIED (&p.u.prefix6))
341 return;
342
343 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
344 return;
345
paul59320202004-11-09 01:54:03 +0000346 rn = bgp_node_lookup (bgp_connected_table[AFI_IP6], (struct prefix *) &p);
paul718e3742002-12-13 20:15:29 +0000347 if (! rn)
348 return;
349
350 bc = rn->info;
351 bc->refcnt--;
352 if (bc->refcnt == 0)
353 {
Chris Caputo6c88b442010-07-27 16:28:55 +0000354 XFREE (MTYPE_BGP_CONN, bc);
paul718e3742002-12-13 20:15:29 +0000355 rn->info = NULL;
356 }
357 bgp_unlock_node (rn);
358 bgp_unlock_node (rn);
359 }
paul718e3742002-12-13 20:15:29 +0000360}
361
362int
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +0000363bgp_nexthop_self (struct attr *attr)
paul718e3742002-12-13 20:15:29 +0000364{
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +0000365 struct bgp_addr tmp, *addr;
paul718e3742002-12-13 20:15:29 +0000366
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +0000367 tmp.addr = attr->nexthop;
paul718e3742002-12-13 20:15:29 +0000368
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +0000369 addr = hash_lookup (bgp_address_hash, &tmp);
370 if (addr)
371 return 1;
372
paul718e3742002-12-13 20:15:29 +0000373 return 0;
374}
David Lamparter6b0655a2014-06-04 06:53:35 +0200375
paul718e3742002-12-13 20:15:29 +0000376int
Dinesh Duttd9ab53a2015-05-19 17:47:21 -0700377bgp_multiaccess_check_v4 (struct in_addr nexthop, struct peer *peer)
paul718e3742002-12-13 20:15:29 +0000378{
379 struct bgp_node *rn1;
380 struct bgp_node *rn2;
Dinesh Duttd9ab53a2015-05-19 17:47:21 -0700381 struct prefix p;
paul718e3742002-12-13 20:15:29 +0000382 int ret;
383
Dinesh Duttd9ab53a2015-05-19 17:47:21 -0700384 p.family = AF_INET;
385 p.prefixlen = IPV4_MAX_BITLEN;
386 p.u.prefix4 = nexthop;
387
388 rn1 = bgp_node_match (bgp_connected_table[AFI_IP], &p);
389 if (!rn1)
paul718e3742002-12-13 20:15:29 +0000390 return 0;
391
Dinesh Duttd9ab53a2015-05-19 17:47:21 -0700392 p.family = AF_INET;
393 p.prefixlen = IPV4_MAX_BITLEN;
394 p.u.prefix4 = peer->su.sin.sin_addr;
paul718e3742002-12-13 20:15:29 +0000395
Dinesh Duttd9ab53a2015-05-19 17:47:21 -0700396 rn2 = bgp_node_match (bgp_connected_table[AFI_IP], &p);
397 if (!rn2)
paul718e3742002-12-13 20:15:29 +0000398 {
Dinesh Duttd9ab53a2015-05-19 17:47:21 -0700399 bgp_unlock_node(rn1);
400 return 0;
paul718e3742002-12-13 20:15:29 +0000401 }
402
Dinesh Duttd9ab53a2015-05-19 17:47:21 -0700403 ret = (rn1 == rn2) ? 1 : 0;
paul718e3742002-12-13 20:15:29 +0000404
Dinesh Duttd9ab53a2015-05-19 17:47:21 -0700405 bgp_unlock_node(rn1);
406 bgp_unlock_node(rn2);
paul718e3742002-12-13 20:15:29 +0000407
Dinesh Duttd9ab53a2015-05-19 17:47:21 -0700408 return (ret);
paul718e3742002-12-13 20:15:29 +0000409}
410
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500411static int
412show_ip_bgp_nexthop_table (struct vty *vty, int detail)
413{
414 struct bgp_node *rn;
415 struct bgp_nexthop_cache *bnc;
416 char buf[INET6_ADDRSTRLEN];
417 struct nexthop *nexthop;
418 time_t tbuf;
419 afi_t afi;
420
421 vty_out (vty, "Current BGP nexthop cache:%s", VTY_NEWLINE);
422 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
423 {
Paul Jakma789dfc92016-09-06 11:20:27 +0100424 if (!bgp_nexthop_cache_table[afi])
425 continue;
426
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500427 for (rn = bgp_table_top (bgp_nexthop_cache_table[afi]); rn; rn = bgp_route_next (rn))
428 {
429 if ((bnc = rn->info) != NULL)
430 {
431 if (CHECK_FLAG(bnc->flags, BGP_NEXTHOP_VALID))
432 {
433 vty_out (vty, " %s valid [IGP metric %d], #paths %d%s",
434 inet_ntop (rn->p.family, &rn->p.u.prefix, buf, sizeof (buf)),
435 bnc->metric, bnc->path_count, VTY_NEWLINE);
436 if (detail)
437 for (nexthop = bnc->nexthop ; nexthop; nexthop = nexthop->next)
438 switch (nexthop->type)
439 {
440 case NEXTHOP_TYPE_IPV6:
441 vty_out (vty, " gate %s%s",
442 inet_ntop (AF_INET6, &nexthop->gate.ipv6,
443 buf, INET6_ADDRSTRLEN), VTY_NEWLINE);
444 break;
445 case NEXTHOP_TYPE_IPV6_IFINDEX:
446 vty_out(vty, " gate %s, if %s%s",
447 inet_ntop(AF_INET6, &nexthop->gate.ipv6, buf,
448 INET6_ADDRSTRLEN),
449 ifindex2ifname(nexthop->ifindex),
450 VTY_NEWLINE);
451 break;
452 case NEXTHOP_TYPE_IPV4:
453 vty_out (vty, " gate %s%s",
454 inet_ntop (AF_INET, &nexthop->gate.ipv4, buf,
455 INET6_ADDRSTRLEN), VTY_NEWLINE);
456 break;
457 case NEXTHOP_TYPE_IFINDEX:
458 vty_out (vty, " if %s%s",
459 ifindex2ifname(nexthop->ifindex), VTY_NEWLINE);
460 break;
461 case NEXTHOP_TYPE_IPV4_IFINDEX:
462 vty_out (vty, " gate %s, if %s%s",
463 inet_ntop(AF_INET, &nexthop->gate.ipv4, buf,
464 INET6_ADDRSTRLEN),
465 ifindex2ifname(nexthop->ifindex), VTY_NEWLINE);
466 break;
467 default:
468 vty_out (vty, " invalid nexthop type %u%s",
469 nexthop->type, VTY_NEWLINE);
470 }
471 }
472 else
473 vty_out (vty, " %s invalid%s",
474 inet_ntop (AF_INET, &rn->p.u.prefix, buf, sizeof (buf)), VTY_NEWLINE);
475#ifdef HAVE_CLOCK_MONOTONIC
476 tbuf = time(NULL) - (bgp_clock() - bnc->last_update);
477 vty_out (vty, " Last update: %s", ctime(&tbuf));
478#else
479 vty_out (vty, " Last update: %s", ctime(&bnc->uptime));
480#endif /* HAVE_CLOCK_MONOTONIC */
481 vty_out(vty, "%s", VTY_NEWLINE);
482 }
483 }
484 }
485 return CMD_SUCCESS;
486}
487
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500488DEFUN (show_ip_bgp_nexthop,
489 show_ip_bgp_nexthop_cmd,
490 "show ip bgp nexthop",
491 SHOW_STR
492 IP_STR
493 BGP_STR
494 "BGP nexthop table\n")
495{
496 return show_ip_bgp_nexthop_table (vty, 0);
497}
498
499DEFUN (show_ip_bgp_nexthop_detail,
500 show_ip_bgp_nexthop_detail_cmd,
501 "show ip bgp nexthop detail",
502 SHOW_STR
503 IP_STR
504 BGP_STR
505 "BGP nexthop table\n")
506{
507 return show_ip_bgp_nexthop_table (vty, 1);
508}
509
paul718e3742002-12-13 20:15:29 +0000510void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -0800511bgp_scan_init (void)
paul718e3742002-12-13 20:15:29 +0000512{
Paul Jakma64e580a2006-02-21 01:09:01 +0000513 cache1_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul59320202004-11-09 01:54:03 +0000514 bgp_nexthop_cache_table[AFI_IP] = cache1_table[AFI_IP];
paul718e3742002-12-13 20:15:29 +0000515
Paul Jakma64e580a2006-02-21 01:09:01 +0000516 bgp_connected_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +0000517
Paul Jakma64e580a2006-02-21 01:09:01 +0000518 cache1_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST);
paul59320202004-11-09 01:54:03 +0000519 bgp_nexthop_cache_table[AFI_IP6] = cache1_table[AFI_IP6];
Paul Jakma64e580a2006-02-21 01:09:01 +0000520 bgp_connected_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST);
Lou Berger810ab342016-09-05 12:18:15 -0400521
522 cache1_table[AFI_ETHER] = bgp_table_init (AFI_ETHER, SAFI_UNICAST);
523 bgp_nexthop_cache_table[AFI_ETHER] = cache1_table[AFI_ETHER];
524 bgp_connected_table[AFI_ETHER] = bgp_table_init (AFI_ETHER, SAFI_UNICAST);
Dinesh Duttd9ab53a2015-05-19 17:47:21 -0700525}
paul718e3742002-12-13 20:15:29 +0000526
Dinesh Duttd9ab53a2015-05-19 17:47:21 -0700527void
528bgp_scan_vty_init()
529{
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500530 install_element (VIEW_NODE, &show_ip_bgp_nexthop_cmd);
531 install_element (VIEW_NODE, &show_ip_bgp_nexthop_detail_cmd);
paul718e3742002-12-13 20:15:29 +0000532}
Chris Caputo228da422009-07-18 05:44:03 +0000533
534void
535bgp_scan_finish (void)
536{
Lou Berger056f3762013-04-10 12:30:04 -0700537 if (cache1_table[AFI_IP])
538 bgp_table_unlock (cache1_table[AFI_IP]);
Chris Caputo228da422009-07-18 05:44:03 +0000539 cache1_table[AFI_IP] = NULL;
540
Lou Berger056f3762013-04-10 12:30:04 -0700541 if (bgp_connected_table[AFI_IP])
542 bgp_table_unlock (bgp_connected_table[AFI_IP]);
Chris Caputo228da422009-07-18 05:44:03 +0000543 bgp_connected_table[AFI_IP] = NULL;
544
Lou Berger056f3762013-04-10 12:30:04 -0700545 if (cache1_table[AFI_IP6])
546 bgp_table_unlock (cache1_table[AFI_IP6]);
Chris Caputo228da422009-07-18 05:44:03 +0000547 cache1_table[AFI_IP6] = NULL;
548
Lou Berger056f3762013-04-10 12:30:04 -0700549 if (bgp_connected_table[AFI_IP6])
550 bgp_table_unlock (bgp_connected_table[AFI_IP6]);
Chris Caputo228da422009-07-18 05:44:03 +0000551 bgp_connected_table[AFI_IP6] = NULL;
Lou Berger810ab342016-09-05 12:18:15 -0400552
553 if (cache1_table[AFI_ETHER])
554 bgp_table_unlock (cache1_table[AFI_ETHER]);
555 cache1_table[AFI_ETHER] = NULL;
556
557 if (bgp_connected_table[AFI_ETHER])
558 bgp_table_unlock (bgp_connected_table[AFI_ETHER]);
559 bgp_connected_table[AFI_ETHER] = NULL;
560
Chris Caputo228da422009-07-18 05:44:03 +0000561}
Lou Berger82dd7072016-01-12 13:41:57 -0500562
563void
564bgp_scan_destroy (void)
565{
Lou Berger82dd7072016-01-12 13:41:57 -0500566 bgp_scan_finish();
Lou Berger82dd7072016-01-12 13:41:57 -0500567}