2 * Copyright (C) 2000 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
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
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.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
37 #include "bgpd/bgpd.h"
38 #include "bgpd/bgp_table.h"
39 #include "bgpd/bgp_route.h"
40 #include "bgpd/bgp_attr.h"
41 #include "bgpd/bgp_nexthop.h"
42 #include "bgpd/bgp_nht.h"
43 #include "bgpd/bgp_debug.h"
44 #include "bgpd/bgp_damp.h"
45 #include "bgpd/bgp_fsm.h"
46 #include "bgpd/bgp_vty.h"
48 DEFINE_MTYPE_STATIC(BGPD
, MARTIAN_STRING
, "BGP Martian Address Intf String");
50 char *bnc_str(struct bgp_nexthop_cache
*bnc
, char *buf
, int size
)
52 prefix2str(&(bnc
->node
->p
), buf
, size
);
56 void bnc_nexthop_free(struct bgp_nexthop_cache
*bnc
)
58 nexthops_free(bnc
->nexthop
);
61 struct bgp_nexthop_cache
*bnc_new(void)
63 struct bgp_nexthop_cache
*bnc
;
65 bnc
= XCALLOC(MTYPE_BGP_NEXTHOP_CACHE
,
66 sizeof(struct bgp_nexthop_cache
));
67 LIST_INIT(&(bnc
->paths
));
71 void bnc_free(struct bgp_nexthop_cache
*bnc
)
73 bnc_nexthop_free(bnc
);
74 XFREE(MTYPE_BGP_NEXTHOP_CACHE
, bnc
);
77 /* Reset and free all BGP nexthop cache. */
78 static void bgp_nexthop_cache_reset(struct bgp_table
*table
)
81 struct bgp_nexthop_cache
*bnc
;
83 for (rn
= bgp_table_top(table
); rn
; rn
= bgp_route_next(rn
)) {
84 bnc
= bgp_node_get_bgp_nexthop_info(rn
);
88 while (!LIST_EMPTY(&(bnc
->paths
))) {
89 struct bgp_path_info
*path
= LIST_FIRST(&(bnc
->paths
));
91 path_nh_map(path
, bnc
, false);
95 bgp_node_set_bgp_nexthop_info(rn
, NULL
);
100 static void *bgp_tip_hash_alloc(void *p
)
102 const struct in_addr
*val
= (const struct in_addr
*)p
;
103 struct tip_addr
*addr
;
105 addr
= XMALLOC(MTYPE_TIP_ADDR
, sizeof(struct tip_addr
));
107 addr
->addr
.s_addr
= val
->s_addr
;
112 static void bgp_tip_hash_free(void *addr
)
114 XFREE(MTYPE_TIP_ADDR
, addr
);
117 static unsigned int bgp_tip_hash_key_make(const void *p
)
119 const struct tip_addr
*addr
= p
;
121 return jhash_1word(addr
->addr
.s_addr
, 0);
124 static bool bgp_tip_hash_cmp(const void *p1
, const void *p2
)
126 const struct tip_addr
*addr1
= p1
;
127 const struct tip_addr
*addr2
= p2
;
129 return addr1
->addr
.s_addr
== addr2
->addr
.s_addr
;
132 void bgp_tip_hash_init(struct bgp
*bgp
)
134 bgp
->tip_hash
= hash_create(bgp_tip_hash_key_make
, bgp_tip_hash_cmp
,
138 void bgp_tip_hash_destroy(struct bgp
*bgp
)
140 if (bgp
->tip_hash
== NULL
)
142 hash_clean(bgp
->tip_hash
, bgp_tip_hash_free
);
143 hash_free(bgp
->tip_hash
);
144 bgp
->tip_hash
= NULL
;
147 void bgp_tip_add(struct bgp
*bgp
, struct in_addr
*tip
)
150 struct tip_addr
*addr
;
154 addr
= hash_get(bgp
->tip_hash
, &tmp
, bgp_tip_hash_alloc
);
161 void bgp_tip_del(struct bgp
*bgp
, struct in_addr
*tip
)
164 struct tip_addr
*addr
;
168 addr
= hash_lookup(bgp
->tip_hash
, &tmp
);
169 /* may have been deleted earlier by bgp_interface_down() */
175 if (addr
->refcnt
== 0) {
176 hash_release(bgp
->tip_hash
, addr
);
177 XFREE(MTYPE_TIP_ADDR
, addr
);
181 /* BGP own address structure */
184 struct list
*ifp_name_list
;
187 static void show_address_entry(struct hash_bucket
*bucket
, void *args
)
189 struct vty
*vty
= (struct vty
*)args
;
190 struct bgp_addr
*addr
= (struct bgp_addr
*)bucket
->data
;
192 struct listnode
*node
;
193 char str
[INET6_ADDRSTRLEN
] = {0};
195 if (addr
->p
->family
== AF_INET
) {
196 vty_out(vty
, "addr: %s, count: %d : ", inet_ntop(AF_INET
,
197 &(addr
->p
->u
.prefix4
),
198 str
, INET_ADDRSTRLEN
),
199 addr
->ifp_name_list
->count
);
200 } else if (addr
->p
->family
== AF_INET6
) {
201 vty_out(vty
, "addr: %s, count: %d : ", inet_ntop(AF_INET6
,
202 &(addr
->p
->u
.prefix6
),
203 str
, INET6_ADDRSTRLEN
),
204 addr
->ifp_name_list
->count
);
207 for (ALL_LIST_ELEMENTS_RO(addr
->ifp_name_list
, node
, name
)) {
208 vty_out(vty
, " %s,", name
);
214 void bgp_nexthop_show_address_hash(struct vty
*vty
, struct bgp
*bgp
)
216 hash_iterate(bgp
->address_hash
,
217 (void (*)(struct hash_bucket
*, void *))show_address_entry
,
221 static void bgp_address_hash_string_del(void *val
)
225 XFREE(MTYPE_MARTIAN_STRING
, data
);
228 static void *bgp_address_hash_alloc(void *p
)
230 struct bgp_addr
*copy_addr
= p
;
231 struct bgp_addr
*addr
= NULL
;
233 addr
= XMALLOC(MTYPE_BGP_ADDR
, sizeof(struct bgp_addr
));
234 addr
->p
= prefix_new();
235 prefix_copy(addr
->p
, copy_addr
->p
);
237 addr
->ifp_name_list
= list_new();
238 addr
->ifp_name_list
->del
= bgp_address_hash_string_del
;
243 static void bgp_address_hash_free(void *data
)
245 struct bgp_addr
*addr
= data
;
247 prefix_free(&addr
->p
);
248 list_delete(&addr
->ifp_name_list
);
249 XFREE(MTYPE_BGP_ADDR
, addr
);
252 static unsigned int bgp_address_hash_key_make(const void *p
)
254 const struct bgp_addr
*addr
= p
;
256 return prefix_hash_key((const void *)(addr
->p
));
259 static bool bgp_address_hash_cmp(const void *p1
, const void *p2
)
261 const struct bgp_addr
*addr1
= p1
;
262 const struct bgp_addr
*addr2
= p2
;
264 return prefix_same(addr1
->p
, addr2
->p
);
267 void bgp_address_init(struct bgp
*bgp
)
270 hash_create(bgp_address_hash_key_make
, bgp_address_hash_cmp
,
271 "BGP Connected Address Hash");
274 void bgp_address_destroy(struct bgp
*bgp
)
276 if (bgp
->address_hash
== NULL
)
278 hash_clean(bgp
->address_hash
, bgp_address_hash_free
);
279 hash_free(bgp
->address_hash
);
280 bgp
->address_hash
= NULL
;
283 static void bgp_address_add(struct bgp
*bgp
, struct connected
*ifc
,
287 struct bgp_addr
*addr
;
288 struct listnode
*node
;
293 if (tmp
.p
->family
== AF_INET
)
294 tmp
.p
->prefixlen
= IPV4_MAX_BITLEN
;
295 else if (tmp
.p
->family
== AF_INET6
)
296 tmp
.p
->prefixlen
= IPV6_MAX_BITLEN
;
298 addr
= hash_get(bgp
->address_hash
, &tmp
, bgp_address_hash_alloc
);
300 for (ALL_LIST_ELEMENTS_RO(addr
->ifp_name_list
, node
, name
)) {
301 if (strcmp(ifc
->ifp
->name
, name
) == 0)
305 name
= XSTRDUP(MTYPE_MARTIAN_STRING
, ifc
->ifp
->name
);
306 listnode_add(addr
->ifp_name_list
, name
);
310 static void bgp_address_del(struct bgp
*bgp
, struct connected
*ifc
,
314 struct bgp_addr
*addr
;
315 struct listnode
*node
;
320 if (tmp
.p
->family
== AF_INET
)
321 tmp
.p
->prefixlen
= IPV4_MAX_BITLEN
;
322 else if (tmp
.p
->family
== AF_INET6
)
323 tmp
.p
->prefixlen
= IPV6_MAX_BITLEN
;
325 addr
= hash_lookup(bgp
->address_hash
, &tmp
);
326 /* may have been deleted earlier by bgp_interface_down() */
330 for (ALL_LIST_ELEMENTS_RO(addr
->ifp_name_list
, node
, name
)) {
331 if (strcmp(ifc
->ifp
->name
, name
) == 0)
336 list_delete_node(addr
->ifp_name_list
, node
);
337 XFREE(MTYPE_MARTIAN_STRING
, name
);
340 if (addr
->ifp_name_list
->count
== 0) {
341 hash_release(bgp
->address_hash
, addr
);
342 list_delete(&addr
->ifp_name_list
);
343 XFREE(MTYPE_BGP_ADDR
, addr
);
348 struct bgp_connected_ref
{
352 void bgp_connected_add(struct bgp
*bgp
, struct connected
*ifc
)
357 struct bgp_connected_ref
*bc
;
358 struct listnode
*node
, *nnode
;
363 p
= *(CONNECTED_PREFIX(ifc
));
364 if (addr
->family
== AF_INET
) {
365 apply_mask_ipv4((struct prefix_ipv4
*)&p
);
367 if (prefix_ipv4_any((struct prefix_ipv4
*)&p
))
370 bgp_address_add(bgp
, ifc
, addr
);
372 rn
= bgp_node_get(bgp
->connected_table
[AFI_IP
],
373 (struct prefix
*)&p
);
374 bc
= bgp_node_get_bgp_connected_ref_info(rn
);
378 bc
= XCALLOC(MTYPE_BGP_CONN
,
379 sizeof(struct bgp_connected_ref
));
381 bgp_node_set_bgp_connected_ref_info(rn
, bc
);
384 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
386 && (strcmp(peer
->conf_if
, ifc
->ifp
->name
) == 0)
387 && peer
->status
!= Established
388 && !CHECK_FLAG(peer
->flags
,
389 PEER_FLAG_IFPEER_V6ONLY
)) {
390 if (peer_active(peer
))
391 BGP_EVENT_ADD(peer
, BGP_Stop
);
392 BGP_EVENT_ADD(peer
, BGP_Start
);
395 } else if (addr
->family
== AF_INET6
) {
396 apply_mask_ipv6((struct prefix_ipv6
*)&p
);
398 if (IN6_IS_ADDR_UNSPECIFIED(&p
.u
.prefix6
))
401 if (IN6_IS_ADDR_LINKLOCAL(&p
.u
.prefix6
))
404 bgp_address_add(bgp
, ifc
, addr
);
406 rn
= bgp_node_get(bgp
->connected_table
[AFI_IP6
],
407 (struct prefix
*)&p
);
409 bc
= bgp_node_get_bgp_connected_ref_info(rn
);
413 bc
= XCALLOC(MTYPE_BGP_CONN
,
414 sizeof(struct bgp_connected_ref
));
416 bgp_node_set_bgp_connected_ref_info(rn
, bc
);
421 void bgp_connected_delete(struct bgp
*bgp
, struct connected
*ifc
)
425 struct bgp_node
*rn
= NULL
;
426 struct bgp_connected_ref
*bc
;
430 p
= *(CONNECTED_PREFIX(ifc
));
432 if (addr
->family
== AF_INET
) {
433 if (prefix_ipv4_any((struct prefix_ipv4
*)&p
))
436 bgp_address_del(bgp
, ifc
, addr
);
438 rn
= bgp_node_lookup(bgp
->connected_table
[AFI_IP
], &p
);
439 } else if (addr
->family
== AF_INET6
) {
440 if (IN6_IS_ADDR_UNSPECIFIED(&p
.u
.prefix6
))
443 if (IN6_IS_ADDR_LINKLOCAL(&p
.u
.prefix6
))
446 bgp_address_del(bgp
, ifc
, addr
);
448 rn
= bgp_node_lookup(bgp
->connected_table
[AFI_IP6
],
449 (struct prefix
*)&p
);
455 bc
= bgp_node_get_bgp_connected_ref_info(rn
);
457 if (bc
->refcnt
== 0) {
458 XFREE(MTYPE_BGP_CONN
, bc
);
459 bgp_node_set_bgp_connected_ref_info(rn
, NULL
);
465 static void bgp_connected_cleanup(struct route_table
*table
,
466 struct route_node
*rn
)
468 struct bgp_connected_ref
*bc
;
469 struct bgp_node
*bn
= bgp_node_from_rnode(rn
);
471 bc
= bgp_node_get_bgp_connected_ref_info(bn
);
476 if (bc
->refcnt
== 0) {
477 XFREE(MTYPE_BGP_CONN
, bc
);
478 bgp_node_set_bgp_connected_ref_info(bn
, NULL
);
482 int bgp_nexthop_self(struct bgp
*bgp
, afi_t afi
, uint8_t type
, uint8_t sub_type
,
483 struct attr
*attr
, struct bgp_node
*rn
)
485 struct prefix p
= {0};
487 struct bgp_addr tmp_addr
= {0}, *addr
= NULL
;
488 struct tip_addr tmp_tip
, *tip
= NULL
;
490 bool is_bgp_static_route
= ((type
== ZEBRA_ROUTE_BGP
)
491 && (sub_type
== BGP_ROUTE_STATIC
))
495 if (!is_bgp_static_route
)
496 new_afi
= BGP_ATTR_NEXTHOP_AFI_IP6(attr
) ? AFI_IP6
: AFI_IP
;
501 if (is_bgp_static_route
) {
502 p
.u
.prefix4
= rn
->p
.u
.prefix4
;
503 p
.prefixlen
= rn
->p
.prefixlen
;
505 /* Here we need to find out which nexthop to be used*/
507 ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
)) {
509 p
.u
.prefix4
= attr
->nexthop
;
510 p
.prefixlen
= IPV4_MAX_BITLEN
;
512 } else if ((attr
->mp_nexthop_len
) &&
513 ((attr
->mp_nexthop_len
==
514 BGP_ATTR_NHLEN_IPV4
) ||
515 (attr
->mp_nexthop_len
==
516 BGP_ATTR_NHLEN_VPNV4
))) {
518 attr
->mp_nexthop_global_in
;
519 p
.prefixlen
= IPV4_MAX_BITLEN
;
527 if (is_bgp_static_route
) {
528 p
.u
.prefix6
= rn
->p
.u
.prefix6
;
529 p
.prefixlen
= rn
->p
.prefixlen
;
531 p
.u
.prefix6
= attr
->mp_nexthop_global
;
532 p
.prefixlen
= IPV6_MAX_BITLEN
;
540 addr
= hash_lookup(bgp
->address_hash
, &tmp_addr
);
544 if (new_afi
== AFI_IP
) {
545 memset(&tmp_tip
, 0, sizeof(struct tip_addr
));
546 tmp_tip
.addr
= attr
->nexthop
;
548 if (attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
)) {
549 tmp_tip
.addr
= attr
->nexthop
;
550 } else if ((attr
->mp_nexthop_len
) &&
551 ((attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
)
552 || (attr
->mp_nexthop_len
==
553 BGP_ATTR_NHLEN_VPNV4
))) {
554 tmp_tip
.addr
= attr
->mp_nexthop_global_in
;
557 tip
= hash_lookup(bgp
->tip_hash
, &tmp_tip
);
565 int bgp_multiaccess_check_v4(struct in_addr nexthop
, struct peer
*peer
)
567 struct bgp_node
*rn1
;
568 struct bgp_node
*rn2
;
573 p
.prefixlen
= IPV4_MAX_BITLEN
;
574 p
.u
.prefix4
= nexthop
;
576 rn1
= bgp_node_match(peer
->bgp
->connected_table
[AFI_IP
], &p
);
581 p
.prefixlen
= IPV4_MAX_BITLEN
;
582 p
.u
.prefix4
= peer
->su
.sin
.sin_addr
;
584 rn2
= bgp_node_match(peer
->bgp
->connected_table
[AFI_IP
], &p
);
586 bgp_unlock_node(rn1
);
590 ret
= (rn1
== rn2
) ? 1 : 0;
592 bgp_unlock_node(rn1
);
593 bgp_unlock_node(rn2
);
598 int bgp_multiaccess_check_v6(struct in6_addr nexthop
, struct peer
*peer
)
600 struct bgp_node
*rn1
;
601 struct bgp_node
*rn2
;
606 p
.prefixlen
= IPV6_MAX_BITLEN
;
607 p
.u
.prefix6
= nexthop
;
609 rn1
= bgp_node_match(peer
->bgp
->connected_table
[AFI_IP6
], &p
);
614 p
.prefixlen
= IPV6_MAX_BITLEN
;
615 p
.u
.prefix6
= peer
->su
.sin6
.sin6_addr
;
617 rn2
= bgp_node_match(peer
->bgp
->connected_table
[AFI_IP6
], &p
);
619 bgp_unlock_node(rn1
);
623 ret
= (rn1
== rn2
) ? 1 : 0;
625 bgp_unlock_node(rn1
);
626 bgp_unlock_node(rn2
);
631 int bgp_subgrp_multiaccess_check_v6(struct in6_addr nexthop
,
632 struct update_subgroup
*subgrp
)
634 struct bgp_node
*rn1
= NULL
, *rn2
= NULL
;
635 struct peer_af
*paf
= NULL
;
636 struct prefix p
= {0}, np
= {0};
637 struct bgp
*bgp
= NULL
;
639 np
.family
= AF_INET6
;
640 np
.prefixlen
= IPV6_MAX_BITLEN
;
641 np
.u
.prefix6
= nexthop
;
644 p
.prefixlen
= IPV6_MAX_BITLEN
;
646 bgp
= SUBGRP_INST(subgrp
);
647 rn1
= bgp_node_match(bgp
->connected_table
[AFI_IP6
], &np
);
651 SUBGRP_FOREACH_PEER (subgrp
, paf
) {
653 p
.u
.prefix6
= paf
->peer
->su
.sin6
.sin6_addr
;
654 rn2
= bgp_node_match(bgp
->connected_table
[AFI_IP6
], &p
);
656 bgp_unlock_node(rn1
);
657 bgp_unlock_node(rn2
);
662 bgp_unlock_node(rn2
);
665 bgp_unlock_node(rn1
);
669 int bgp_subgrp_multiaccess_check_v4(struct in_addr nexthop
,
670 struct update_subgroup
*subgrp
)
672 struct bgp_node
*rn1
, *rn2
;
678 np
.prefixlen
= IPV4_MAX_BITLEN
;
679 np
.u
.prefix4
= nexthop
;
682 p
.prefixlen
= IPV4_MAX_BITLEN
;
684 bgp
= SUBGRP_INST(subgrp
);
685 rn1
= bgp_node_match(bgp
->connected_table
[AFI_IP
], &np
);
689 SUBGRP_FOREACH_PEER (subgrp
, paf
) {
690 p
.u
.prefix4
= paf
->peer
->su
.sin
.sin_addr
;
692 rn2
= bgp_node_match(bgp
->connected_table
[AFI_IP
], &p
);
694 bgp_unlock_node(rn1
);
695 bgp_unlock_node(rn2
);
700 bgp_unlock_node(rn2
);
703 bgp_unlock_node(rn1
);
707 static void bgp_show_nexthops_detail(struct vty
*vty
, struct bgp
*bgp
,
708 struct bgp_nexthop_cache
*bnc
)
710 char buf
[PREFIX2STR_BUFFER
];
711 struct nexthop
*nexthop
;
713 for (nexthop
= bnc
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
714 switch (nexthop
->type
) {
715 case NEXTHOP_TYPE_IPV6
:
716 vty_out(vty
, " gate %s\n",
717 inet_ntop(AF_INET6
, &nexthop
->gate
.ipv6
, buf
,
720 case NEXTHOP_TYPE_IPV6_IFINDEX
:
721 vty_out(vty
, " gate %s, if %s\n",
722 inet_ntop(AF_INET6
, &nexthop
->gate
.ipv6
, buf
,
724 ifindex2ifname(nexthop
->ifindex
, bgp
->vrf_id
));
726 case NEXTHOP_TYPE_IPV4
:
727 vty_out(vty
, " gate %s\n",
728 inet_ntop(AF_INET
, &nexthop
->gate
.ipv4
, buf
,
731 case NEXTHOP_TYPE_IFINDEX
:
732 vty_out(vty
, " if %s\n",
733 ifindex2ifname(nexthop
->ifindex
, bgp
->vrf_id
));
735 case NEXTHOP_TYPE_IPV4_IFINDEX
:
736 vty_out(vty
, " gate %s, if %s\n",
737 inet_ntop(AF_INET
, &nexthop
->gate
.ipv4
, buf
,
739 ifindex2ifname(nexthop
->ifindex
, bgp
->vrf_id
));
741 case NEXTHOP_TYPE_BLACKHOLE
:
742 vty_out(vty
, " blackhole\n");
745 vty_out(vty
, " invalid nexthop type %u\n",
750 static void bgp_show_nexthops(struct vty
*vty
, struct bgp
*bgp
, int detail
,
754 struct bgp_nexthop_cache
*bnc
;
755 char buf
[PREFIX2STR_BUFFER
];
758 struct bgp_table
**table
;
761 vty_out(vty
, "Current BGP import check cache:\n");
763 vty_out(vty
, "Current BGP nexthop cache:\n");
765 table
= bgp
->import_check_table
;
767 table
= bgp
->nexthop_cache_table
;
768 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
769 if (!table
|| !table
[afi
])
771 for (rn
= bgp_table_top(table
[afi
]); rn
;
772 rn
= bgp_route_next(rn
)) {
775 bnc
= bgp_node_get_bgp_nexthop_info(rn
);
778 peer
= (struct peer
*)bnc
->nht_info
;
780 if (CHECK_FLAG(bnc
->flags
, BGP_NEXTHOP_VALID
)) {
782 " %s valid [IGP metric %d], #paths %d",
783 inet_ntop(rn
->p
.family
,
784 &rn
->p
.u
.prefix
, buf
,
786 bnc
->metric
, bnc
->path_count
);
788 vty_out(vty
, ", peer %s", peer
->host
);
794 bgp_show_nexthops_detail(vty
, bgp
, bnc
);
797 vty_out(vty
, " %s invalid",
798 inet_ntop(rn
->p
.family
,
799 &rn
->p
.u
.prefix
, buf
,
802 vty_out(vty
, ", peer %s", peer
->host
);
804 if (CHECK_FLAG(bnc
->flags
,
805 BGP_NEXTHOP_CONNECTED
))
806 vty_out(vty
, " Must be Connected\n");
807 if (!CHECK_FLAG(bnc
->flags
,
808 BGP_NEXTHOP_REGISTERED
))
809 vty_out(vty
, " Is not Registered\n");
811 tbuf
= time(NULL
) - (bgp_clock() - bnc
->last_update
);
812 vty_out(vty
, " Last update: %s", ctime(&tbuf
));
818 static int show_ip_bgp_nexthop_table(struct vty
*vty
, const char *name
,
819 int detail
, bool import_table
)
824 bgp
= bgp_lookup_by_name(name
);
826 bgp
= bgp_get_default();
828 vty_out(vty
, "%% No such BGP instance exist\n");
832 bgp_show_nexthops(vty
, bgp
, detail
, import_table
);
837 static void bgp_show_all_instances_nexthops_vty(struct vty
*vty
)
839 struct listnode
*node
, *nnode
;
842 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
843 vty_out(vty
, "\nInstance %s:\n",
844 (bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
)
847 bgp_show_nexthops(vty
, bgp
, 0, false);
851 DEFUN (show_ip_bgp_nexthop
,
852 show_ip_bgp_nexthop_cmd
,
853 "show [ip] bgp [<view|vrf> VIEWVRFNAME] nexthop [detail]",
857 BGP_INSTANCE_HELP_STR
858 "BGP nexthop table\n"
859 "Show detailed information\n")
864 if (argv_find(argv
, argc
, "view", &idx
)
865 || argv_find(argv
, argc
, "vrf", &idx
))
866 vrf
= argv
[++idx
]->arg
;
867 int detail
= argv_find(argv
, argc
, "detail", &idx
) ? 1 : 0;
869 return show_ip_bgp_nexthop_table(vty
, vrf
, detail
, false);
872 DEFUN (show_ip_bgp_import_check
,
873 show_ip_bgp_import_check_cmd
,
874 "show [ip] bgp [<view|vrf> VIEWVRFNAME] import-check-table [detail]",
878 BGP_INSTANCE_HELP_STR
879 "BGP import check table\n"
880 "Show detailed information\n")
885 if (argv_find(argv
, argc
, "view", &idx
)
886 || argv_find(argv
, argc
, "vrf", &idx
))
887 vrf
= argv
[++idx
]->arg
;
888 int detail
= argv_find(argv
, argc
, "detail", &idx
) ? 1 : 0;
889 return show_ip_bgp_nexthop_table(vty
, vrf
, detail
, true);
892 DEFUN (show_ip_bgp_instance_all_nexthop
,
893 show_ip_bgp_instance_all_nexthop_cmd
,
894 "show [ip] bgp <view|vrf> all nexthop",
898 BGP_INSTANCE_ALL_HELP_STR
899 "BGP nexthop table\n")
901 bgp_show_all_instances_nexthops_vty(vty
);
905 void bgp_scan_init(struct bgp
*bgp
)
909 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
910 bgp
->nexthop_cache_table
[afi
] =
911 bgp_table_init(bgp
, afi
, SAFI_UNICAST
);
912 bgp
->connected_table
[afi
] = bgp_table_init(bgp
, afi
,
914 bgp
->import_check_table
[afi
] =
915 bgp_table_init(bgp
, afi
, SAFI_UNICAST
);
919 void bgp_scan_vty_init(void)
921 install_element(VIEW_NODE
, &show_ip_bgp_nexthop_cmd
);
922 install_element(VIEW_NODE
, &show_ip_bgp_import_check_cmd
);
923 install_element(VIEW_NODE
, &show_ip_bgp_instance_all_nexthop_cmd
);
926 void bgp_scan_finish(struct bgp
*bgp
)
930 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
931 /* Only the current one needs to be reset. */
932 bgp_nexthop_cache_reset(bgp
->nexthop_cache_table
[afi
]);
933 bgp_table_unlock(bgp
->nexthop_cache_table
[afi
]);
934 bgp
->nexthop_cache_table
[afi
] = NULL
;
936 bgp
->connected_table
[afi
]->route_table
->cleanup
=
937 bgp_connected_cleanup
;
938 bgp_table_unlock(bgp
->connected_table
[afi
]);
939 bgp
->connected_table
[afi
] = NULL
;
941 bgp_table_unlock(bgp
->import_check_table
[afi
]);
942 bgp
->import_check_table
[afi
] = NULL
;