2 * Copyright (C) 1997, 98, 99 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
28 #include "sockunion.h"
40 #include "bgpd/bgpd.h"
41 #include "bgpd/bgp_route.h"
42 #include "bgpd/bgp_attr.h"
43 #include "bgpd/bgp_nexthop.h"
44 #include "bgpd/bgp_zebra.h"
45 #include "bgpd/bgp_fsm.h"
46 #include "bgpd/bgp_debug.h"
47 #include "bgpd/bgp_mpath.h"
48 #include "bgpd/bgp_nexthop.h"
49 #include "bgpd/bgp_nht.h"
50 #include "bgpd/bgp_bfd.h"
51 #include "bgpd/bgp_label.h"
53 #include "bgpd/rfapi/rfapi_backend.h"
54 #include "bgpd/rfapi/vnc_export_bgp.h"
56 #include "bgpd/bgp_evpn.h"
58 /* All information about zebra. */
59 struct zclient
*zclient
= NULL
;
61 /* Growable buffer for nexthops sent to zebra */
62 struct stream
*bgp_nexthop_buf
= NULL
;
63 struct stream
*bgp_ifindices_buf
= NULL
;
64 struct stream
*bgp_label_buf
= NULL
;
66 /* These array buffers are used in making a copy of the attributes for
67 route-map apply. Arrays are being used here to minimize mallocs and
68 frees for the temporary copy of the attributes.
69 Given the zapi api expects the nexthop buffer to contain pointer to
70 pointers for nexthops, we couldnt have used a single nexthop variable
71 on the stack, hence we had two options:
72 1. maintain a linked-list and free it after zapi_*_route call
73 2. use an array to avoid number of mallocs.
74 Number of supported next-hops are finite, use of arrays should be ok. */
75 struct attr attr_cp
[MULTIPATH_NUM
];
76 unsigned int attr_index
= 0;
78 /* Once per address-family initialization of the attribute array */
79 #define BGP_INFO_ATTR_BUF_INIT() \
81 memset(attr_cp, 0, MULTIPATH_NUM * sizeof(struct attr)); \
85 #define BGP_INFO_ATTR_BUF_COPY(info_src, info_dst) \
87 *info_dst = *info_src; \
88 assert(attr_index != multipath_num); \
89 bgp_attr_dup(&attr_cp[attr_index], info_src->attr); \
90 bgp_attr_deep_dup(&attr_cp[attr_index], info_src->attr); \
91 info_dst->attr = &attr_cp[attr_index]; \
95 #define BGP_INFO_ATTR_BUF_FREE(info) \
97 bgp_attr_deep_free(info->attr); \
101 /* Can we install into zebra? */
102 static inline int bgp_install_info_to_zebra(struct bgp
*bgp
)
104 if (zclient
->sock
<= 0)
107 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
))
113 int zclient_num_connects
;
115 /* Router-id update message from zebra. */
116 static int bgp_router_id_update(int command
, struct zclient
*zclient
,
117 zebra_size_t length
, vrf_id_t vrf_id
)
119 struct prefix router_id
;
121 zebra_router_id_update_read(zclient
->ibuf
, &router_id
);
123 if (BGP_DEBUG(zebra
, ZEBRA
)) {
124 char buf
[PREFIX2STR_BUFFER
];
125 prefix2str(&router_id
, buf
, sizeof(buf
));
126 zlog_debug("Rx Router Id update VRF %u Id %s", vrf_id
, buf
);
129 bgp_router_id_zebra_bump(vrf_id
, &router_id
);
133 /* Nexthop update message from zebra. */
134 static int bgp_read_nexthop_update(int command
, struct zclient
*zclient
,
135 zebra_size_t length
, vrf_id_t vrf_id
)
137 bgp_parse_nexthop_update(command
, vrf_id
);
141 static int bgp_read_import_check_update(int command
, struct zclient
*zclient
,
142 zebra_size_t length
, vrf_id_t vrf_id
)
144 bgp_parse_nexthop_update(command
, vrf_id
);
148 /* Set or clear interface on which unnumbered neighbor is configured. This
149 * would in turn cause BGP to initiate or turn off IPv6 RAs on this
152 static void bgp_update_interface_nbrs(struct bgp
*bgp
, struct interface
*ifp
,
153 struct interface
*upd_ifp
)
155 struct listnode
*node
, *nnode
;
158 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
159 if (peer
->conf_if
&& (strcmp(peer
->conf_if
, ifp
->name
) == 0)) {
162 bgp_zebra_initiate_radv(bgp
, peer
);
164 bgp_zebra_terminate_radv(bgp
, peer
);
171 static int bgp_read_fec_update(int command
, struct zclient
*zclient
,
174 bgp_parse_fec_update();
178 static void bgp_start_interface_nbrs(struct bgp
*bgp
, struct interface
*ifp
)
180 struct listnode
*node
, *nnode
;
183 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
184 if (peer
->conf_if
&& (strcmp(peer
->conf_if
, ifp
->name
) == 0)
185 && peer
->status
!= Established
) {
186 if (peer_active(peer
))
187 BGP_EVENT_ADD(peer
, BGP_Stop
);
188 BGP_EVENT_ADD(peer
, BGP_Start
);
193 static void bgp_nbr_connected_add(struct bgp
*bgp
, struct nbr_connected
*ifc
)
195 struct listnode
*node
;
196 struct connected
*connected
;
197 struct interface
*ifp
;
200 /* Kick-off the FSM for any relevant peers only if there is a
201 * valid local address on the interface.
204 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
)) {
205 p
= connected
->address
;
206 if (p
->family
== AF_INET6
207 && IN6_IS_ADDR_LINKLOCAL(&p
->u
.prefix6
))
213 bgp_start_interface_nbrs(bgp
, ifp
);
216 static void bgp_nbr_connected_delete(struct bgp
*bgp
, struct nbr_connected
*ifc
,
219 struct listnode
*node
, *nnode
;
221 struct interface
*ifp
;
223 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
225 && (strcmp(peer
->conf_if
, ifc
->ifp
->name
) == 0)) {
226 peer
->last_reset
= PEER_DOWN_NBR_ADDR_DEL
;
227 BGP_EVENT_ADD(peer
, BGP_Stop
);
230 /* Free neighbor also, if we're asked to. */
233 listnode_delete(ifp
->nbr_connected
, ifc
);
234 nbr_connected_free(ifc
);
238 /* Inteface addition message from zebra. */
239 static int bgp_interface_add(int command
, struct zclient
*zclient
,
240 zebra_size_t length
, vrf_id_t vrf_id
)
242 struct interface
*ifp
;
245 ifp
= zebra_interface_add_read(zclient
->ibuf
, vrf_id
);
246 if (!ifp
) // unexpected
249 if (BGP_DEBUG(zebra
, ZEBRA
) && ifp
)
250 zlog_debug("Rx Intf add VRF %u IF %s", vrf_id
, ifp
->name
);
252 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
256 bgp_update_interface_nbrs(bgp
, ifp
, ifp
);
260 static int bgp_interface_delete(int command
, struct zclient
*zclient
,
261 zebra_size_t length
, vrf_id_t vrf_id
)
264 struct interface
*ifp
;
268 ifp
= zebra_interface_state_read(s
, vrf_id
);
269 if (!ifp
) /* This may happen if we've just unregistered for a VRF. */
272 if (BGP_DEBUG(zebra
, ZEBRA
))
273 zlog_debug("Rx Intf del VRF %u IF %s", vrf_id
, ifp
->name
);
275 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
279 bgp_update_interface_nbrs(bgp
, ifp
, NULL
);
281 ifp
->ifindex
= IFINDEX_DELETED
;
285 static int bgp_interface_up(int command
, struct zclient
*zclient
,
286 zebra_size_t length
, vrf_id_t vrf_id
)
289 struct interface
*ifp
;
291 struct nbr_connected
*nc
;
292 struct listnode
*node
, *nnode
;
296 ifp
= zebra_interface_state_read(s
, vrf_id
);
301 if (BGP_DEBUG(zebra
, ZEBRA
))
302 zlog_debug("Rx Intf up VRF %u IF %s", vrf_id
, ifp
->name
);
304 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
308 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, c
))
309 bgp_connected_add(bgp
, c
);
311 for (ALL_LIST_ELEMENTS(ifp
->nbr_connected
, node
, nnode
, nc
))
312 bgp_nbr_connected_add(bgp
, nc
);
317 static int bgp_interface_down(int command
, struct zclient
*zclient
,
318 zebra_size_t length
, vrf_id_t vrf_id
)
321 struct interface
*ifp
;
323 struct nbr_connected
*nc
;
324 struct listnode
*node
, *nnode
;
328 ifp
= zebra_interface_state_read(s
, vrf_id
);
332 if (BGP_DEBUG(zebra
, ZEBRA
))
333 zlog_debug("Rx Intf down VRF %u IF %s", vrf_id
, ifp
->name
);
335 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
339 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, c
))
340 bgp_connected_delete(bgp
, c
);
342 for (ALL_LIST_ELEMENTS(ifp
->nbr_connected
, node
, nnode
, nc
))
343 bgp_nbr_connected_delete(bgp
, nc
, 1);
345 /* Fast external-failover */
349 if (CHECK_FLAG(bgp
->flags
, BGP_FLAG_NO_FAST_EXT_FAILOVER
))
352 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
353 #if defined(HAVE_CUMULUS)
354 /* Take down directly connected EBGP peers as well as
356 * tracked (directly connected) IBGP peers.
358 if ((peer
->ttl
!= 1) && (peer
->gtsm_hops
!= 1)
360 || bgp_bfd_is_peer_multihop(peer
)))
362 /* Take down directly connected EBGP peers */
363 if ((peer
->ttl
!= 1) && (peer
->gtsm_hops
!= 1))
367 if (ifp
== peer
->nexthop
.ifp
) {
368 BGP_EVENT_ADD(peer
, BGP_Stop
);
369 peer
->last_reset
= PEER_DOWN_IF_DOWN
;
377 static int bgp_interface_address_add(int command
, struct zclient
*zclient
,
378 zebra_size_t length
, vrf_id_t vrf_id
)
380 struct connected
*ifc
;
382 ifc
= zebra_interface_address_read(command
, zclient
->ibuf
, vrf_id
);
387 if (bgp_debug_zebra(ifc
->address
)) {
388 char buf
[PREFIX2STR_BUFFER
];
389 prefix2str(ifc
->address
, buf
, sizeof(buf
));
390 zlog_debug("Rx Intf address add VRF %u IF %s addr %s", vrf_id
,
391 ifc
->ifp
->name
, buf
);
394 if (if_is_operative(ifc
->ifp
)) {
397 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
401 bgp_connected_add(bgp
, ifc
);
402 /* If we have learnt of any neighbors on this interface,
403 * check to kick off any BGP interface-based neighbors,
404 * but only if this is a link-local address.
406 if (IN6_IS_ADDR_LINKLOCAL(&ifc
->address
->u
.prefix6
)
407 && !list_isempty(ifc
->ifp
->nbr_connected
))
408 bgp_start_interface_nbrs(bgp
, ifc
->ifp
);
414 static int bgp_interface_address_delete(int command
, struct zclient
*zclient
,
415 zebra_size_t length
, vrf_id_t vrf_id
)
417 struct connected
*ifc
;
420 ifc
= zebra_interface_address_read(command
, zclient
->ibuf
, vrf_id
);
425 if (bgp_debug_zebra(ifc
->address
)) {
426 char buf
[PREFIX2STR_BUFFER
];
427 prefix2str(ifc
->address
, buf
, sizeof(buf
));
428 zlog_debug("Rx Intf address del VRF %u IF %s addr %s", vrf_id
,
429 ifc
->ifp
->name
, buf
);
432 if (if_is_operative(ifc
->ifp
)) {
433 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
435 bgp_connected_delete(bgp
, ifc
);
443 static int bgp_interface_nbr_address_add(int command
, struct zclient
*zclient
,
444 zebra_size_t length
, vrf_id_t vrf_id
)
446 struct nbr_connected
*ifc
= NULL
;
449 ifc
= zebra_interface_nbr_address_read(command
, zclient
->ibuf
, vrf_id
);
454 if (bgp_debug_zebra(ifc
->address
)) {
455 char buf
[PREFIX2STR_BUFFER
];
456 prefix2str(ifc
->address
, buf
, sizeof(buf
));
457 zlog_debug("Rx Intf neighbor add VRF %u IF %s addr %s", vrf_id
,
458 ifc
->ifp
->name
, buf
);
461 if (if_is_operative(ifc
->ifp
)) {
462 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
464 bgp_nbr_connected_add(bgp
, ifc
);
470 static int bgp_interface_nbr_address_delete(int command
,
471 struct zclient
*zclient
,
475 struct nbr_connected
*ifc
= NULL
;
478 ifc
= zebra_interface_nbr_address_read(command
, zclient
->ibuf
, vrf_id
);
483 if (bgp_debug_zebra(ifc
->address
)) {
484 char buf
[PREFIX2STR_BUFFER
];
485 prefix2str(ifc
->address
, buf
, sizeof(buf
));
486 zlog_debug("Rx Intf neighbor del VRF %u IF %s addr %s", vrf_id
,
487 ifc
->ifp
->name
, buf
);
490 if (if_is_operative(ifc
->ifp
)) {
491 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
493 bgp_nbr_connected_delete(bgp
, ifc
, 0);
496 nbr_connected_free(ifc
);
501 /* VRF update for an interface. */
502 static int bgp_interface_vrf_update(int command
, struct zclient
*zclient
,
503 zebra_size_t length
, vrf_id_t vrf_id
)
505 struct interface
*ifp
;
508 struct nbr_connected
*nc
;
509 struct listnode
*node
, *nnode
;
512 ifp
= zebra_interface_vrf_update_read(zclient
->ibuf
, vrf_id
,
517 if (BGP_DEBUG(zebra
, ZEBRA
) && ifp
)
518 zlog_debug("Rx Intf VRF change VRF %u IF %s NewVRF %u", vrf_id
,
519 ifp
->name
, new_vrf_id
);
521 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
525 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, c
))
526 bgp_connected_delete(bgp
, c
);
528 for (ALL_LIST_ELEMENTS(ifp
->nbr_connected
, node
, nnode
, nc
))
529 bgp_nbr_connected_delete(bgp
, nc
, 1);
531 /* Fast external-failover */
535 if (CHECK_FLAG(bgp
->flags
, BGP_FLAG_NO_FAST_EXT_FAILOVER
))
538 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
539 if ((peer
->ttl
!= 1) && (peer
->gtsm_hops
!= 1))
542 if (ifp
== peer
->nexthop
.ifp
)
543 BGP_EVENT_ADD(peer
, BGP_Stop
);
547 if_update_to_new_vrf(ifp
, new_vrf_id
);
549 bgp
= bgp_lookup_by_vrf_id(new_vrf_id
);
553 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, c
))
554 bgp_connected_add(bgp
, c
);
556 for (ALL_LIST_ELEMENTS(ifp
->nbr_connected
, node
, nnode
, nc
))
557 bgp_nbr_connected_add(bgp
, nc
);
561 /* Zebra route add and delete treatment. */
562 static int zebra_read_ipv4(int command
, struct zclient
*zclient
,
563 zebra_size_t length
, vrf_id_t vrf_id
)
566 struct zapi_ipv4 api
;
567 struct in_addr nexthop
;
568 struct prefix_ipv4 p
;
569 unsigned int ifindex
;
573 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
580 /* Type, flags, message. */
581 api
.type
= stream_getc(s
);
582 api
.instance
= stream_getw(s
);
583 api
.flags
= stream_getl(s
);
584 api
.message
= stream_getc(s
);
587 memset(&p
, 0, sizeof(struct prefix_ipv4
));
589 p
.prefixlen
= MIN(IPV4_MAX_PREFIXLEN
, stream_getc(s
));
590 stream_get(&p
.prefix
, s
, PSIZE(p
.prefixlen
));
592 /* Nexthop, ifindex, distance, metric. */
593 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
)) {
594 api
.nexthop_num
= stream_getc(s
);
595 nexthop
.s_addr
= stream_get_ipv4(s
);
598 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_IFINDEX
)) {
599 api
.ifindex_num
= stream_getc(s
);
600 ifindex
= stream_getl(s
); /* ifindex, unused */
605 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_DISTANCE
))
606 api
.distance
= stream_getc(s
);
608 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_METRIC
))
609 api
.metric
= stream_getl(s
);
613 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_TAG
))
614 api
.tag
= stream_getl(s
);
618 if (command
== ZEBRA_REDISTRIBUTE_IPV4_ADD
) {
619 if (bgp_debug_zebra((struct prefix
*)&p
)) {
620 char buf
[2][INET_ADDRSTRLEN
];
622 "Rx IPv4 route add VRF %u %s[%d] %s/%d nexthop %s metric %u tag %" ROUTE_TAG_PRI
,
623 vrf_id
, zebra_route_string(api
.type
),
624 api
.instance
, inet_ntop(AF_INET
, &p
.prefix
,
625 buf
[0], sizeof(buf
[0])),
626 p
.prefixlen
, inet_ntop(AF_INET
, &nexthop
,
627 buf
[1], sizeof(buf
[1])),
628 api
.metric
, api
.tag
);
632 * The ADD message is actually an UPDATE and there is no
634 * for a prior redistributed route, if any. So, perform an
636 * DEL processing for the same redistributed route from any
640 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
642 bgp_redistribute_delete(bgp
,
643 (struct prefix
*)&p
, i
,
647 /* Now perform the add/update. */
648 bgp_redistribute_add(bgp
, (struct prefix
*)&p
, &nexthop
, NULL
,
649 ifindex
, api
.metric
, api
.type
,
650 api
.instance
, api
.tag
);
651 } else if (command
== ZEBRA_REDISTRIBUTE_IPV4_DEL
) {
652 if (bgp_debug_zebra((struct prefix
*)&p
)) {
653 char buf
[2][INET_ADDRSTRLEN
];
655 "Rx IPv4 route delete VRF %u %s[%d] %s/%d "
656 "nexthop %s metric %u tag %" ROUTE_TAG_PRI
,
657 vrf_id
, zebra_route_string(api
.type
),
658 api
.instance
, inet_ntop(AF_INET
, &p
.prefix
,
659 buf
[0], sizeof(buf
[0])),
660 p
.prefixlen
, inet_ntop(AF_INET
, &nexthop
,
661 buf
[1], sizeof(buf
[1])),
662 api
.metric
, api
.tag
);
664 bgp_redistribute_delete(bgp
, (struct prefix
*)&p
, api
.type
,
671 /* Zebra route add and delete treatment. */
672 static int zebra_read_ipv6(int command
, struct zclient
*zclient
,
673 zebra_size_t length
, vrf_id_t vrf_id
)
676 struct zapi_ipv6 api
;
677 struct in6_addr nexthop
;
678 struct prefix_ipv6 p
, src_p
;
679 unsigned int ifindex
;
683 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
688 memset(&nexthop
, 0, sizeof(struct in6_addr
));
690 /* Type, flags, message. */
691 api
.type
= stream_getc(s
);
692 api
.instance
= stream_getw(s
);
693 api
.flags
= stream_getl(s
);
694 api
.message
= stream_getc(s
);
697 memset(&p
, 0, sizeof(struct prefix_ipv6
));
699 p
.prefixlen
= MIN(IPV6_MAX_PREFIXLEN
, stream_getc(s
));
700 stream_get(&p
.prefix
, s
, PSIZE(p
.prefixlen
));
702 memset(&src_p
, 0, sizeof(struct prefix_ipv6
));
703 src_p
.family
= AF_INET6
;
704 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_SRCPFX
)) {
705 src_p
.prefixlen
= stream_getc(s
);
706 stream_get(&src_p
.prefix
, s
, PSIZE(src_p
.prefixlen
));
710 /* we completely ignore srcdest routes for now. */
713 /* Nexthop, ifindex, distance, metric. */
714 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
)) {
715 api
.nexthop_num
= stream_getc(s
);
716 stream_get(&nexthop
, s
, 16);
719 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_IFINDEX
)) {
720 api
.ifindex_num
= stream_getc(s
);
721 ifindex
= stream_getl(s
); /* ifindex, unused */
726 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_DISTANCE
))
727 api
.distance
= stream_getc(s
);
731 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_METRIC
))
732 api
.metric
= stream_getl(s
);
736 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_TAG
))
737 api
.tag
= stream_getl(s
);
741 /* Simply ignore link-local address. */
742 if (IN6_IS_ADDR_LINKLOCAL(&p
.prefix
))
745 if (command
== ZEBRA_REDISTRIBUTE_IPV6_ADD
) {
746 if (bgp_debug_zebra((struct prefix
*)&p
)) {
747 char buf
[2][INET6_ADDRSTRLEN
];
749 "Rx IPv6 route add VRF %u %s[%d] %s/%d nexthop %s metric %u tag %" ROUTE_TAG_PRI
,
750 vrf_id
, zebra_route_string(api
.type
),
751 api
.instance
, inet_ntop(AF_INET6
, &p
.prefix
,
752 buf
[0], sizeof(buf
[0])),
753 p
.prefixlen
, inet_ntop(AF_INET
, &nexthop
,
754 buf
[1], sizeof(buf
[1])),
755 api
.metric
, api
.tag
);
759 * The ADD message is actually an UPDATE and there is no
761 * for a prior redistributed route, if any. So, perform an
763 * DEL processing for the same redistributed route from any
767 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
769 bgp_redistribute_delete(bgp
,
770 (struct prefix
*)&p
, i
,
774 bgp_redistribute_add(bgp
, (struct prefix
*)&p
, NULL
, &nexthop
,
775 ifindex
, api
.metric
, api
.type
,
776 api
.instance
, api
.tag
);
777 } else if (command
== ZEBRA_REDISTRIBUTE_IPV6_DEL
) {
778 if (bgp_debug_zebra((struct prefix
*)&p
)) {
779 char buf
[2][INET6_ADDRSTRLEN
];
781 "Rx IPv6 route delete VRF %u %s[%d] %s/%d "
782 "nexthop %s metric %u tag %" ROUTE_TAG_PRI
,
783 vrf_id
, zebra_route_string(api
.type
),
784 api
.instance
, inet_ntop(AF_INET6
, &p
.prefix
,
785 buf
[0], sizeof(buf
[0])),
786 p
.prefixlen
, inet_ntop(AF_INET6
, &nexthop
,
787 buf
[1], sizeof(buf
[1])),
788 api
.metric
, api
.tag
);
790 bgp_redistribute_delete(bgp
, (struct prefix
*)&p
, api
.type
,
797 struct interface
*if_lookup_by_ipv4(struct in_addr
*addr
, vrf_id_t vrf_id
)
799 struct listnode
*ifnode
;
800 struct listnode
*cnode
;
801 struct interface
*ifp
;
802 struct connected
*connected
;
803 struct prefix_ipv4 p
;
808 p
.prefixlen
= IPV4_MAX_BITLEN
;
810 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id
), ifnode
, ifp
)) {
811 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
)) {
812 cp
= connected
->address
;
814 if (cp
->family
== AF_INET
)
815 if (prefix_match(cp
, (struct prefix
*)&p
))
822 struct interface
*if_lookup_by_ipv4_exact(struct in_addr
*addr
, vrf_id_t vrf_id
)
824 struct listnode
*ifnode
;
825 struct listnode
*cnode
;
826 struct interface
*ifp
;
827 struct connected
*connected
;
830 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id
), ifnode
, ifp
)) {
831 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
)) {
832 cp
= connected
->address
;
834 if (cp
->family
== AF_INET
)
835 if (IPV4_ADDR_SAME(&cp
->u
.prefix4
, addr
))
842 struct interface
*if_lookup_by_ipv6(struct in6_addr
*addr
, ifindex_t ifindex
,
845 struct listnode
*ifnode
;
846 struct listnode
*cnode
;
847 struct interface
*ifp
;
848 struct connected
*connected
;
849 struct prefix_ipv6 p
;
854 p
.prefixlen
= IPV6_MAX_BITLEN
;
856 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id
), ifnode
, ifp
)) {
857 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
)) {
858 cp
= connected
->address
;
860 if (cp
->family
== AF_INET6
)
861 if (prefix_match(cp
, (struct prefix
*)&p
)) {
862 if (IN6_IS_ADDR_LINKLOCAL(
864 if (ifindex
== ifp
->ifindex
)
874 struct interface
*if_lookup_by_ipv6_exact(struct in6_addr
*addr
,
875 ifindex_t ifindex
, vrf_id_t vrf_id
)
877 struct listnode
*ifnode
;
878 struct listnode
*cnode
;
879 struct interface
*ifp
;
880 struct connected
*connected
;
883 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id
), ifnode
, ifp
)) {
884 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
)) {
885 cp
= connected
->address
;
887 if (cp
->family
== AF_INET6
)
888 if (IPV6_ADDR_SAME(&cp
->u
.prefix6
, addr
)) {
889 if (IN6_IS_ADDR_LINKLOCAL(
891 if (ifindex
== ifp
->ifindex
)
901 static int if_get_ipv6_global(struct interface
*ifp
, struct in6_addr
*addr
)
903 struct listnode
*cnode
;
904 struct connected
*connected
;
907 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
)) {
908 cp
= connected
->address
;
910 if (cp
->family
== AF_INET6
)
911 if (!IN6_IS_ADDR_LINKLOCAL(&cp
->u
.prefix6
)) {
912 memcpy(addr
, &cp
->u
.prefix6
, IPV6_MAX_BYTELEN
);
919 static int if_get_ipv6_local(struct interface
*ifp
, struct in6_addr
*addr
)
921 struct listnode
*cnode
;
922 struct connected
*connected
;
925 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
)) {
926 cp
= connected
->address
;
928 if (cp
->family
== AF_INET6
)
929 if (IN6_IS_ADDR_LINKLOCAL(&cp
->u
.prefix6
)) {
930 memcpy(addr
, &cp
->u
.prefix6
, IPV6_MAX_BYTELEN
);
937 static int if_get_ipv4_address(struct interface
*ifp
, struct in_addr
*addr
)
939 struct listnode
*cnode
;
940 struct connected
*connected
;
943 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
)) {
944 cp
= connected
->address
;
945 if ((cp
->family
== AF_INET
)
946 && !ipv4_martian(&(cp
->u
.prefix4
))) {
947 *addr
= cp
->u
.prefix4
;
954 int bgp_nexthop_set(union sockunion
*local
, union sockunion
*remote
,
955 struct bgp_nexthop
*nexthop
, struct peer
*peer
)
958 struct interface
*ifp
= NULL
;
960 memset(nexthop
, 0, sizeof(struct bgp_nexthop
));
967 if (local
->sa
.sa_family
== AF_INET
) {
968 nexthop
->v4
= local
->sin
.sin_addr
;
970 ifp
= if_lookup_by_name(peer
->update_if
,
973 ifp
= if_lookup_by_ipv4_exact(&local
->sin
.sin_addr
,
976 if (local
->sa
.sa_family
== AF_INET6
) {
977 if (IN6_IS_ADDR_LINKLOCAL(&local
->sin6
.sin6_addr
)) {
978 if (peer
->conf_if
|| peer
->ifname
)
979 ifp
= if_lookup_by_name(peer
->conf_if
983 } else if (peer
->update_if
)
984 ifp
= if_lookup_by_name(peer
->update_if
,
987 ifp
= if_lookup_by_ipv6_exact(&local
->sin6
.sin6_addr
,
988 local
->sin6
.sin6_scope_id
,
997 /* IPv4 connection, fetch and store IPv6 local address(es) if any. */
998 if (local
->sa
.sa_family
== AF_INET
) {
1000 ret
= if_get_ipv6_global(ifp
, &nexthop
->v6_global
);
1003 /* There is no global nexthop. Use link-local address as
1005 * global and link-local nexthop. In this scenario, the
1007 * for interop is that the network admin would use a
1009 * specify the global IPv6 nexthop.
1011 if_get_ipv6_local(ifp
, &nexthop
->v6_global
);
1012 memcpy(&nexthop
->v6_local
, &nexthop
->v6_global
,
1015 if_get_ipv6_local(ifp
, &nexthop
->v6_local
);
1017 if (if_lookup_by_ipv4(&remote
->sin
.sin_addr
, peer
->bgp
->vrf_id
))
1018 peer
->shared_network
= 1;
1020 peer
->shared_network
= 0;
1023 /* IPv6 connection, fetch and store IPv4 local address if any. */
1024 if (local
->sa
.sa_family
== AF_INET6
) {
1025 struct interface
*direct
= NULL
;
1028 ret
= if_get_ipv4_address(ifp
, &nexthop
->v4
);
1029 if (!ret
&& peer
->local_id
.s_addr
)
1030 nexthop
->v4
= peer
->local_id
;
1033 if (!IN6_IS_ADDR_LINKLOCAL(&local
->sin6
.sin6_addr
)) {
1034 memcpy(&nexthop
->v6_global
, &local
->sin6
.sin6_addr
,
1037 /* If directory connected set link-local address. */
1038 direct
= if_lookup_by_ipv6(&remote
->sin6
.sin6_addr
,
1039 remote
->sin6
.sin6_scope_id
,
1042 if_get_ipv6_local(ifp
, &nexthop
->v6_local
);
1044 /* Link-local address. */
1046 ret
= if_get_ipv6_global(ifp
, &nexthop
->v6_global
);
1048 /* If there is no global address. Set link-local
1050 global. I know this break RFC specification... */
1051 /* In this scenario, the expectation for interop is that
1053 * network admin would use a route-map to specify the
1058 memcpy(&nexthop
->v6_global
,
1059 &local
->sin6
.sin6_addr
,
1061 /* Always set the link-local address */
1062 memcpy(&nexthop
->v6_local
, &local
->sin6
.sin6_addr
,
1066 if (IN6_IS_ADDR_LINKLOCAL(&local
->sin6
.sin6_addr
)
1067 || if_lookup_by_ipv6(&remote
->sin6
.sin6_addr
,
1068 remote
->sin6
.sin6_scope_id
,
1070 peer
->shared_network
= 1;
1072 peer
->shared_network
= 0;
1075 /* KAME stack specific treatment. */
1077 if (IN6_IS_ADDR_LINKLOCAL(&nexthop
->v6_global
)
1078 && IN6_LINKLOCAL_IFINDEX(nexthop
->v6_global
)) {
1079 SET_IN6_LINKLOCAL_IFINDEX(nexthop
->v6_global
, 0);
1081 if (IN6_IS_ADDR_LINKLOCAL(&nexthop
->v6_local
)
1082 && IN6_LINKLOCAL_IFINDEX(nexthop
->v6_local
)) {
1083 SET_IN6_LINKLOCAL_IFINDEX(nexthop
->v6_local
, 0);
1087 /* If we have identified the local interface, there is no error for now.
1092 static struct in6_addr
*bgp_info_to_ipv6_nexthop(struct bgp_info
*info
)
1094 struct in6_addr
*nexthop
= NULL
;
1096 /* Only global address nexthop exists. */
1097 if (info
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
)
1098 nexthop
= &info
->attr
->mp_nexthop_global
;
1100 /* If both global and link-local address present. */
1101 if (info
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
) {
1102 /* Check if route-map is set to prefer global over link-local */
1103 if (info
->attr
->mp_nexthop_prefer_global
)
1104 nexthop
= &info
->attr
->mp_nexthop_global
;
1106 /* Workaround for Cisco's nexthop bug. */
1107 if (IN6_IS_ADDR_UNSPECIFIED(
1108 &info
->attr
->mp_nexthop_global
)
1109 && info
->peer
->su_remote
->sa
.sa_family
== AF_INET6
)
1111 &info
->peer
->su_remote
->sin6
.sin6_addr
;
1113 nexthop
= &info
->attr
->mp_nexthop_local
;
1120 static int bgp_table_map_apply(struct route_map
*map
, struct prefix
*p
,
1121 struct bgp_info
*info
)
1123 if (route_map_apply(map
, p
, RMAP_BGP
, info
) != RMAP_DENYMATCH
)
1126 if (bgp_debug_zebra(p
)) {
1127 if (p
->family
== AF_INET
) {
1128 char buf
[2][INET_ADDRSTRLEN
];
1130 "Zebra rmap deny: IPv4 route %s/%d nexthop %s",
1131 inet_ntop(AF_INET
, &p
->u
.prefix4
, buf
[0],
1134 inet_ntop(AF_INET
, &info
->attr
->nexthop
, buf
[1],
1137 if (p
->family
== AF_INET6
) {
1138 char buf
[2][INET6_ADDRSTRLEN
];
1140 "Zebra rmap deny: IPv6 route %s/%d nexthop %s",
1141 inet_ntop(AF_INET6
, &p
->u
.prefix6
, buf
[0],
1145 bgp_info_to_ipv6_nexthop(info
),
1146 buf
[1], sizeof(buf
[1])));
1152 void bgp_zebra_announce(struct bgp_node
*rn
, struct prefix
*p
,
1153 struct bgp_info
*info
, struct bgp
*bgp
, afi_t afi
,
1159 struct bgp_info
*mpinfo
;
1161 struct bgp_info local_info
;
1162 struct bgp_info
*info_cp
= &local_info
;
1166 /* Don't try to install if we're not connected to Zebra or Zebra doesn't
1167 * know of this instance.
1169 if (!bgp_install_info_to_zebra(bgp
))
1172 if ((p
->family
== AF_INET
1173 && !vrf_bitmap_check(zclient
->redist
[AFI_IP
][ZEBRA_ROUTE_BGP
],
1175 || (p
->family
== AF_INET6
1176 && !vrf_bitmap_check(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_BGP
],
1180 if (bgp
->main_zebra_update_hold
)
1186 tag
= info
->attr
->tag
;
1188 /* When we create an aggregate route we must also install a Null0 route
1191 if (info
->sub_type
== BGP_ROUTE_AGGREGATE
)
1192 SET_FLAG(flags
, ZEBRA_FLAG_BLACKHOLE
);
1194 if (peer
->sort
== BGP_PEER_IBGP
|| peer
->sort
== BGP_PEER_CONFED
1195 || info
->sub_type
== BGP_ROUTE_AGGREGATE
) {
1196 SET_FLAG(flags
, ZEBRA_FLAG_IBGP
);
1197 SET_FLAG(flags
, ZEBRA_FLAG_INTERNAL
);
1200 if ((peer
->sort
== BGP_PEER_EBGP
&& peer
->ttl
!= 1)
1201 || CHECK_FLAG(peer
->flags
, PEER_FLAG_DISABLE_CONNECTED_CHECK
)
1202 || bgp_flag_check(bgp
, BGP_FLAG_DISABLE_NH_CONNECTED_CHK
))
1204 SET_FLAG(flags
, ZEBRA_FLAG_INTERNAL
);
1206 if (p
->family
== AF_INET
&& !BGP_ATTR_NEXTHOP_AFI_IP6(info
->attr
)) {
1207 struct zapi_ipv4 api
;
1208 struct in_addr
*nexthop
;
1209 char buf
[2][INET_ADDRSTRLEN
];
1210 int valid_nh_count
= 0;
1211 int has_valid_label
= 0;
1213 /* resize nexthop buffer size if necessary */
1214 stream_reset(bgp_nexthop_buf
);
1217 stream_reset(bgp_label_buf
);
1219 if (bgp
->table_map
[afi
][safi
].name
)
1220 BGP_INFO_ATTR_BUF_INIT();
1222 /* Metric is currently based on the best-path only */
1223 metric
= info
->attr
->med
;
1224 for (mpinfo
= info
; mpinfo
;
1225 mpinfo
= bgp_info_mpath_next(mpinfo
)) {
1228 if (bgp
->table_map
[afi
][safi
].name
) {
1229 /* Copy info and attributes, so the route-map
1230 apply doesn't modify the
1232 BGP_INFO_ATTR_BUF_COPY(mpinfo
, info_cp
);
1233 if (bgp_table_map_apply(
1234 bgp
->table_map
[afi
][safi
].map
, p
,
1236 if (mpinfo
== info
) {
1237 /* Metric is currently based on
1238 * the best-path only */
1239 metric
= info_cp
->attr
->med
;
1240 tag
= info_cp
->attr
->tag
;
1242 nexthop
= &info_cp
->attr
->nexthop
;
1244 BGP_INFO_ATTR_BUF_FREE(info_cp
);
1246 nexthop
= &mpinfo
->attr
->nexthop
;
1248 if (nexthop
== NULL
)
1251 stream_put(bgp_nexthop_buf
, &nexthop
,
1252 sizeof(struct in_addr
*));
1254 && bgp_is_valid_label(&mpinfo
->extra
->label
)) {
1255 has_valid_label
= 1;
1256 label
= label_pton(&mpinfo
->extra
->label
);
1257 stream_put(bgp_label_buf
, &label
,
1258 sizeof(mpls_label_t
));
1263 api
.vrf_id
= bgp
->vrf_id
;
1265 api
.type
= ZEBRA_ROUTE_BGP
;
1269 SET_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
);
1271 if (has_valid_label
)
1272 SET_FLAG(api
.message
, ZAPI_MESSAGE_LABEL
);
1274 /* Note that this currently only applies to Null0 routes for
1276 * ZEBRA_FLAG_BLACKHOLE signals zapi_ipv4_route to encode a
1278 * BLACKHOLE nexthop. We want to set api.nexthop_num to zero
1280 * do not want to also encode the 0.0.0.0 nexthop for the
1283 if (CHECK_FLAG(flags
, ZEBRA_FLAG_BLACKHOLE
))
1284 api
.nexthop_num
= 0;
1286 api
.nexthop_num
= valid_nh_count
;
1288 api
.nexthop
= (struct in_addr
**)STREAM_DATA(bgp_nexthop_buf
);
1289 if (has_valid_label
) {
1290 api
.label_num
= valid_nh_count
;
1291 api
.label
= (unsigned int *)STREAM_DATA(bgp_label_buf
);
1296 api
.ifindex_num
= 0;
1297 SET_FLAG(api
.message
, ZAPI_MESSAGE_METRIC
);
1298 api
.metric
= metric
;
1302 SET_FLAG(api
.message
, ZAPI_MESSAGE_TAG
);
1306 distance
= bgp_distance_apply(p
, info
, afi
, safi
, bgp
);
1308 SET_FLAG(api
.message
, ZAPI_MESSAGE_DISTANCE
);
1309 api
.distance
= distance
;
1312 if (bgp_debug_zebra(p
)) {
1316 "Tx IPv4 route %s VRF %u %s/%d metric %u tag %" ROUTE_TAG_PRI
1318 (valid_nh_count
? "add" : "delete"),
1319 bgp
->vrf_id
, inet_ntop(AF_INET
, &p
->u
.prefix4
,
1320 buf
[0], sizeof(buf
[0])),
1321 p
->prefixlen
, api
.metric
, api
.tag
,
1323 for (i
= 0; i
< api
.nexthop_num
; i
++) {
1324 label_buf
[0] = '\0';
1325 if (has_valid_label
)
1326 sprintf(label_buf
, "label %u",
1328 zlog_debug(" nhop [%d]: %s %s", i
+ 1,
1329 inet_ntop(AF_INET
, api
.nexthop
[i
],
1330 buf
[1], sizeof(buf
[1])),
1335 zapi_ipv4_route(valid_nh_count
? ZEBRA_IPV4_ROUTE_ADD
1336 : ZEBRA_IPV4_ROUTE_DELETE
,
1337 zclient
, (struct prefix_ipv4
*)p
, &api
);
1340 /* We have to think about a IPv6 link-local address curse. */
1341 if (p
->family
== AF_INET6
1342 || (p
->family
== AF_INET
&& BGP_ATTR_NEXTHOP_AFI_IP6(info
->attr
))) {
1344 struct in6_addr
*nexthop
;
1345 struct zapi_ipv6 api
;
1346 int valid_nh_count
= 0;
1347 char buf
[2][INET6_ADDRSTRLEN
];
1348 int has_valid_label
= 0;
1350 stream_reset(bgp_nexthop_buf
);
1351 stream_reset(bgp_ifindices_buf
);
1352 stream_reset(bgp_label_buf
);
1357 if (bgp
->table_map
[afi
][safi
].name
)
1358 BGP_INFO_ATTR_BUF_INIT();
1360 metric
= info
->attr
->med
;
1361 for (mpinfo
= info
; mpinfo
;
1362 mpinfo
= bgp_info_mpath_next(mpinfo
)) {
1366 if (bgp
->table_map
[afi
][safi
].name
) {
1367 /* Copy info and attributes, so the route-map
1368 apply doesn't modify the
1370 BGP_INFO_ATTR_BUF_COPY(mpinfo
, info_cp
);
1371 if (bgp_table_map_apply(
1372 bgp
->table_map
[afi
][safi
].map
, p
,
1374 if (mpinfo
== info
) {
1375 metric
= info_cp
->attr
->med
;
1376 tag
= info_cp
->attr
->tag
;
1378 nexthop
= bgp_info_to_ipv6_nexthop(
1381 BGP_INFO_ATTR_BUF_FREE(info_cp
);
1383 nexthop
= bgp_info_to_ipv6_nexthop(mpinfo
);
1385 if (nexthop
== NULL
)
1388 if ((mpinfo
== info
)
1389 && mpinfo
->attr
->mp_nexthop_len
1390 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
1391 if (mpinfo
->peer
->nexthop
.ifp
)
1392 ifindex
= mpinfo
->peer
->nexthop
.ifp
1396 if (mpinfo
->peer
->conf_if
1397 || mpinfo
->peer
->ifname
)
1398 ifindex
= ifname2ifindex(
1399 mpinfo
->peer
->conf_if
1400 ? mpinfo
->peer
->conf_if
1401 : mpinfo
->peer
->ifname
,
1403 else if (mpinfo
->peer
->nexthop
.ifp
)
1404 ifindex
= mpinfo
->peer
->nexthop
.ifp
1410 stream_put(bgp_nexthop_buf
, &nexthop
,
1411 sizeof(struct in6_addr
*));
1412 stream_put(bgp_ifindices_buf
, &ifindex
,
1413 sizeof(unsigned int));
1416 && bgp_is_valid_label(&mpinfo
->extra
->label
)) {
1417 has_valid_label
= 1;
1418 label
= label_pton(&mpinfo
->extra
->label
);
1419 stream_put(bgp_label_buf
, &label
,
1420 sizeof(mpls_label_t
));
1425 /* Make Zebra API structure. */
1426 api
.vrf_id
= bgp
->vrf_id
;
1428 api
.type
= ZEBRA_ROUTE_BGP
;
1432 SET_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
);
1434 if (has_valid_label
)
1435 SET_FLAG(api
.message
, ZAPI_MESSAGE_LABEL
);
1437 /* Note that this currently only applies to Null0 routes for
1439 * ZEBRA_FLAG_BLACKHOLE signals zapi_ipv6_route to encode a
1441 * BLACKHOLE nexthop. We want to set api.nexthop_num to zero
1443 * do not want to also encode the :: nexthop for the aggregate
1446 if (CHECK_FLAG(flags
, ZEBRA_FLAG_BLACKHOLE
))
1447 api
.nexthop_num
= 0;
1449 api
.nexthop_num
= valid_nh_count
;
1451 api
.nexthop
= (struct in6_addr
**)STREAM_DATA(bgp_nexthop_buf
);
1452 SET_FLAG(api
.message
, ZAPI_MESSAGE_IFINDEX
);
1453 api
.ifindex_num
= valid_nh_count
;
1454 api
.ifindex
= (ifindex_t
*)STREAM_DATA(bgp_ifindices_buf
);
1455 if (has_valid_label
) {
1456 api
.label_num
= valid_nh_count
;
1457 api
.label
= (unsigned int *)STREAM_DATA(bgp_label_buf
);
1462 SET_FLAG(api
.message
, ZAPI_MESSAGE_METRIC
);
1463 api
.metric
= metric
;
1467 SET_FLAG(api
.message
, ZAPI_MESSAGE_TAG
);
1471 distance
= bgp_distance_apply(p
, info
, afi
, safi
, bgp
);
1473 SET_FLAG(api
.message
, ZAPI_MESSAGE_DISTANCE
);
1474 api
.distance
= distance
;
1477 if (p
->family
== AF_INET
) {
1478 if (bgp_debug_zebra(p
)) {
1482 "Tx IPv4 route %s VRF %u %s/%d metric %u tag %" ROUTE_TAG_PRI
,
1483 valid_nh_count
? "add" : "delete",
1485 inet_ntop(AF_INET
, &p
->u
.prefix4
,
1486 buf
[0], sizeof(buf
[0])),
1487 p
->prefixlen
, api
.metric
, api
.tag
);
1488 for (i
= 0; i
< api
.nexthop_num
; i
++) {
1489 label_buf
[0] = '\0';
1490 if (has_valid_label
)
1491 sprintf(label_buf
, "label %u",
1494 " nhop [%d]: %s if %s %s",
1500 ifindex2ifname(api
.ifindex
[i
],
1507 zapi_ipv4_route_ipv6_nexthop(
1508 ZEBRA_IPV4_ROUTE_IPV6_NEXTHOP_ADD
,
1509 zclient
, (struct prefix_ipv4
*)p
,
1510 (struct zapi_ipv6
*)&api
);
1512 zapi_ipv4_route(ZEBRA_IPV4_ROUTE_DELETE
,
1514 (struct prefix_ipv4
*)p
,
1515 (struct zapi_ipv4
*)&api
);
1517 if (bgp_debug_zebra(p
)) {
1521 "Tx IPv6 route %s VRF %u %s/%d metric %u tag %" ROUTE_TAG_PRI
,
1522 valid_nh_count
? "add" : "delete",
1524 inet_ntop(AF_INET6
, &p
->u
.prefix6
,
1525 buf
[0], sizeof(buf
[0])),
1526 p
->prefixlen
, api
.metric
, api
.tag
);
1527 for (i
= 0; i
< api
.nexthop_num
; i
++) {
1528 label_buf
[0] = '\0';
1529 if (has_valid_label
)
1530 sprintf(label_buf
, "label %u",
1533 " nhop [%d]: %s if %s %s",
1539 ifindex2ifname(api
.ifindex
[i
],
1546 valid_nh_count
? ZEBRA_IPV6_ROUTE_ADD
1547 : ZEBRA_IPV6_ROUTE_DELETE
,
1548 zclient
, (struct prefix_ipv6
*)p
, NULL
, &api
);
1553 /* Announce all routes of a table to zebra */
1554 void bgp_zebra_announce_table(struct bgp
*bgp
, afi_t afi
, safi_t safi
)
1556 struct bgp_node
*rn
;
1557 struct bgp_table
*table
;
1558 struct bgp_info
*ri
;
1560 /* Don't try to install if we're not connected to Zebra or Zebra doesn't
1561 * know of this instance.
1563 if (!bgp_install_info_to_zebra(bgp
))
1566 table
= bgp
->rib
[afi
][safi
];
1570 for (rn
= bgp_table_top(table
); rn
; rn
= bgp_route_next(rn
))
1571 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
1572 if (CHECK_FLAG(ri
->flags
, BGP_INFO_SELECTED
)
1573 && ri
->type
== ZEBRA_ROUTE_BGP
1574 && ri
->sub_type
== BGP_ROUTE_NORMAL
)
1575 bgp_zebra_announce(rn
, &rn
->p
, ri
, bgp
, afi
,
1579 void bgp_zebra_withdraw(struct prefix
*p
, struct bgp_info
*info
, safi_t safi
)
1587 /* Don't try to install if we're not connected to Zebra or Zebra doesn't
1588 * know of this instance.
1590 if (!bgp_install_info_to_zebra(peer
->bgp
))
1593 if ((p
->family
== AF_INET
1594 && !vrf_bitmap_check(zclient
->redist
[AFI_IP
][ZEBRA_ROUTE_BGP
],
1596 || (p
->family
== AF_INET6
1597 && !vrf_bitmap_check(zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_BGP
],
1598 peer
->bgp
->vrf_id
)))
1603 if (peer
->sort
== BGP_PEER_IBGP
) {
1604 SET_FLAG(flags
, ZEBRA_FLAG_INTERNAL
);
1605 SET_FLAG(flags
, ZEBRA_FLAG_IBGP
);
1608 if ((peer
->sort
== BGP_PEER_EBGP
&& peer
->ttl
!= 1)
1609 || CHECK_FLAG(peer
->flags
, PEER_FLAG_DISABLE_CONNECTED_CHECK
)
1610 || bgp_flag_check(peer
->bgp
, BGP_FLAG_DISABLE_NH_CONNECTED_CHK
))
1611 SET_FLAG(flags
, ZEBRA_FLAG_INTERNAL
);
1613 if (p
->family
== AF_INET
) {
1614 struct zapi_ipv4 api
;
1616 api
.vrf_id
= peer
->bgp
->vrf_id
;
1619 api
.type
= ZEBRA_ROUTE_BGP
;
1623 SET_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
);
1624 api
.nexthop_num
= 0;
1628 api
.ifindex_num
= 0;
1629 SET_FLAG(api
.message
, ZAPI_MESSAGE_METRIC
);
1630 api
.metric
= info
->attr
->med
;
1633 if (info
->attr
->tag
!= 0) {
1634 SET_FLAG(api
.message
, ZAPI_MESSAGE_TAG
);
1635 api
.tag
= info
->attr
->tag
;
1638 if (bgp_debug_zebra(p
)) {
1639 char buf
[2][INET_ADDRSTRLEN
];
1641 "Tx IPv4 route delete VRF %u %s/%d metric %u tag %" ROUTE_TAG_PRI
,
1643 inet_ntop(AF_INET
, &p
->u
.prefix4
, buf
[0],
1645 p
->prefixlen
, api
.metric
, api
.tag
);
1648 zapi_ipv4_route(ZEBRA_IPV4_ROUTE_DELETE
, zclient
,
1649 (struct prefix_ipv4
*)p
, &api
);
1651 /* We have to think about a IPv6 link-local address curse. */
1652 if (p
->family
== AF_INET6
) {
1653 struct zapi_ipv6 api
;
1655 api
.vrf_id
= peer
->bgp
->vrf_id
;
1657 api
.type
= ZEBRA_ROUTE_BGP
;
1661 SET_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
);
1662 api
.nexthop_num
= 0;
1664 api
.ifindex_num
= 0;
1666 SET_FLAG(api
.message
, ZAPI_MESSAGE_METRIC
);
1667 api
.metric
= info
->attr
->med
;
1670 if (info
->attr
->tag
!= 0) {
1671 SET_FLAG(api
.message
, ZAPI_MESSAGE_TAG
);
1672 api
.tag
= info
->attr
->tag
;
1675 if (bgp_debug_zebra(p
)) {
1676 char buf
[2][INET6_ADDRSTRLEN
];
1678 "Tx IPv6 route delete VRF %u %s/%d metric %u tag %" ROUTE_TAG_PRI
,
1680 inet_ntop(AF_INET6
, &p
->u
.prefix6
, buf
[0],
1682 p
->prefixlen
, api
.metric
, api
.tag
);
1685 zapi_ipv6_route(ZEBRA_IPV6_ROUTE_DELETE
, zclient
,
1686 (struct prefix_ipv6
*)p
, NULL
, &api
);
1690 struct bgp_redist
*bgp_redist_lookup(struct bgp
*bgp
, afi_t afi
, u_char type
,
1693 struct list
*red_list
;
1694 struct listnode
*node
;
1695 struct bgp_redist
*red
;
1697 red_list
= bgp
->redist
[afi
][type
];
1701 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
))
1702 if (red
->instance
== instance
)
1708 struct bgp_redist
*bgp_redist_add(struct bgp
*bgp
, afi_t afi
, u_char type
,
1711 struct list
*red_list
;
1712 struct bgp_redist
*red
;
1714 red
= bgp_redist_lookup(bgp
, afi
, type
, instance
);
1718 if (!bgp
->redist
[afi
][type
])
1719 bgp
->redist
[afi
][type
] = list_new();
1721 red_list
= bgp
->redist
[afi
][type
];
1722 red
= (struct bgp_redist
*)XCALLOC(MTYPE_BGP_REDIST
,
1723 sizeof(struct bgp_redist
));
1724 red
->instance
= instance
;
1726 listnode_add(red_list
, red
);
1731 static void bgp_redist_del(struct bgp
*bgp
, afi_t afi
, u_char type
,
1734 struct bgp_redist
*red
;
1736 red
= bgp_redist_lookup(bgp
, afi
, type
, instance
);
1739 listnode_delete(bgp
->redist
[afi
][type
], red
);
1740 XFREE(MTYPE_BGP_REDIST
, red
);
1741 if (!bgp
->redist
[afi
][type
]->count
) {
1742 list_free(bgp
->redist
[afi
][type
]);
1743 bgp
->redist
[afi
][type
] = NULL
;
1748 /* Other routes redistribution into BGP. */
1749 int bgp_redistribute_set(struct bgp
*bgp
, afi_t afi
, int type
, u_short instance
)
1752 /* Return if already redistribute flag is set. */
1754 if (redist_check_instance(&zclient
->mi_redist
[afi
][type
],
1758 redist_add_instance(&zclient
->mi_redist
[afi
][type
], instance
);
1760 if (vrf_bitmap_check(zclient
->redist
[afi
][type
], bgp
->vrf_id
))
1764 if (bgp
->vrf_id
== VRF_DEFAULT
1765 && type
== ZEBRA_ROUTE_VNC_DIRECT
) {
1766 vnc_export_bgp_enable(
1767 bgp
, afi
); /* only enables if mode bits cfg'd */
1771 vrf_bitmap_set(zclient
->redist
[afi
][type
], bgp
->vrf_id
);
1774 /* Don't try to register if we're not connected to Zebra or Zebra
1776 * know of this instance.
1778 if (!bgp_install_info_to_zebra(bgp
))
1779 return CMD_WARNING_CONFIG_FAILED
;
1781 if (BGP_DEBUG(zebra
, ZEBRA
))
1782 zlog_debug("Tx redistribute add VRF %u afi %d %s %d",
1783 bgp
->vrf_id
, afi
, zebra_route_string(type
),
1786 /* Send distribute add message to zebra. */
1787 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD
, zclient
, afi
, type
,
1788 instance
, bgp
->vrf_id
);
1793 int bgp_redistribute_resend(struct bgp
*bgp
, afi_t afi
, int type
,
1796 /* Don't try to send if we're not connected to Zebra or Zebra doesn't
1797 * know of this instance.
1799 if (!bgp_install_info_to_zebra(bgp
))
1802 if (BGP_DEBUG(zebra
, ZEBRA
))
1803 zlog_debug("Tx redistribute del/add VRF %u afi %d %s %d",
1804 bgp
->vrf_id
, afi
, zebra_route_string(type
),
1807 /* Send distribute add message to zebra. */
1808 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE
, zclient
, afi
, type
,
1809 instance
, bgp
->vrf_id
);
1810 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD
, zclient
, afi
, type
,
1811 instance
, bgp
->vrf_id
);
1816 /* Redistribute with route-map specification. */
1817 int bgp_redistribute_rmap_set(struct bgp_redist
*red
, const char *name
)
1819 if (red
->rmap
.name
&& (strcmp(red
->rmap
.name
, name
) == 0))
1823 XFREE(MTYPE_ROUTE_MAP_NAME
, red
->rmap
.name
);
1824 red
->rmap
.name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, name
);
1825 red
->rmap
.map
= route_map_lookup_by_name(name
);
1830 /* Redistribute with metric specification. */
1831 int bgp_redistribute_metric_set(struct bgp
*bgp
, struct bgp_redist
*red
,
1832 afi_t afi
, int type
, u_int32_t metric
)
1834 struct bgp_node
*rn
;
1835 struct bgp_info
*ri
;
1837 if (red
->redist_metric_flag
&& red
->redist_metric
== metric
)
1840 red
->redist_metric_flag
= 1;
1841 red
->redist_metric
= metric
;
1843 for (rn
= bgp_table_top(bgp
->rib
[afi
][SAFI_UNICAST
]); rn
;
1844 rn
= bgp_route_next(rn
)) {
1845 for (ri
= rn
->info
; ri
; ri
= ri
->next
) {
1846 if (ri
->sub_type
== BGP_ROUTE_REDISTRIBUTE
1848 && ri
->instance
== red
->instance
) {
1849 struct attr
*old_attr
;
1850 struct attr new_attr
;
1852 bgp_attr_dup(&new_attr
, ri
->attr
);
1853 new_attr
.med
= red
->redist_metric
;
1854 old_attr
= ri
->attr
;
1855 ri
->attr
= bgp_attr_intern(&new_attr
);
1856 bgp_attr_unintern(&old_attr
);
1858 bgp_info_set_flag(rn
, ri
,
1859 BGP_INFO_ATTR_CHANGED
);
1860 bgp_process(bgp
, rn
, afi
, SAFI_UNICAST
);
1868 /* Unset redistribution. */
1869 int bgp_redistribute_unreg(struct bgp
*bgp
, afi_t afi
, int type
,
1872 struct bgp_redist
*red
;
1874 red
= bgp_redist_lookup(bgp
, afi
, type
, instance
);
1878 /* Return if zebra connection is disabled. */
1880 if (!redist_check_instance(&zclient
->mi_redist
[afi
][type
],
1883 redist_del_instance(&zclient
->mi_redist
[afi
][type
], instance
);
1885 if (!vrf_bitmap_check(zclient
->redist
[afi
][type
], bgp
->vrf_id
))
1887 vrf_bitmap_unset(zclient
->redist
[afi
][type
], bgp
->vrf_id
);
1891 if (bgp
->vrf_id
== VRF_DEFAULT
&& type
== ZEBRA_ROUTE_VNC_DIRECT
) {
1892 vnc_export_bgp_disable(bgp
, afi
);
1896 if (bgp_install_info_to_zebra(bgp
)) {
1897 /* Send distribute delete message to zebra. */
1898 if (BGP_DEBUG(zebra
, ZEBRA
))
1899 zlog_debug("Tx redistribute del VRF %u afi %d %s %d",
1900 bgp
->vrf_id
, afi
, zebra_route_string(type
),
1902 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE
, zclient
, afi
,
1903 type
, instance
, bgp
->vrf_id
);
1906 /* Withdraw redistributed routes from current BGP's routing table. */
1907 bgp_redistribute_withdraw(bgp
, afi
, type
, instance
);
1912 /* Unset redistribution. */
1913 int bgp_redistribute_unset(struct bgp
*bgp
, afi_t afi
, int type
,
1916 struct bgp_redist
*red
;
1918 red
= bgp_redist_lookup(bgp
, afi
, type
, instance
);
1922 bgp_redistribute_unreg(bgp
, afi
, type
, instance
);
1924 /* Unset route-map. */
1926 XFREE(MTYPE_ROUTE_MAP_NAME
, red
->rmap
.name
);
1927 red
->rmap
.name
= NULL
;
1928 red
->rmap
.map
= NULL
;
1931 red
->redist_metric_flag
= 0;
1932 red
->redist_metric
= 0;
1934 bgp_redist_del(bgp
, afi
, type
, instance
);
1939 /* Update redistribute vrf bitmap during triggers like
1940 restart networking or delete/add VRFs */
1941 void bgp_update_redist_vrf_bitmaps(struct bgp
*bgp
, vrf_id_t old_vrf_id
)
1946 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
1947 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
1948 if (vrf_bitmap_check(zclient
->redist
[afi
][i
],
1950 vrf_bitmap_unset(zclient
->redist
[afi
][i
],
1952 vrf_bitmap_set(zclient
->redist
[afi
][i
],
1958 void bgp_zclient_reset(void)
1960 zclient_reset(zclient
);
1963 /* Register this instance with Zebra. Invoked upon connect (for
1964 * default instance) and when other VRFs are learnt (or created and
1967 void bgp_zebra_instance_register(struct bgp
*bgp
)
1969 /* Don't try to register if we're not connected to Zebra */
1970 if (!zclient
|| zclient
->sock
< 0)
1973 if (BGP_DEBUG(zebra
, ZEBRA
))
1974 zlog_debug("Registering VRF %u", bgp
->vrf_id
);
1976 /* Register for router-id, interfaces, redistributed routes. */
1977 zclient_send_reg_requests(zclient
, bgp
->vrf_id
);
1979 /* For default instance, register to learn about VNIs, if appropriate.
1981 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
1982 && bgp
->advertise_all_vni
)
1983 bgp_zebra_advertise_all_vni(bgp
, 1);
1986 /* Deregister this instance with Zebra. Invoked upon the instance
1987 * being deleted (default or VRF) and it is already registered.
1989 void bgp_zebra_instance_deregister(struct bgp
*bgp
)
1991 /* Don't try to deregister if we're not connected to Zebra */
1992 if (zclient
->sock
< 0)
1995 if (BGP_DEBUG(zebra
, ZEBRA
))
1996 zlog_debug("Deregistering VRF %u", bgp
->vrf_id
);
1998 /* For default instance, unregister learning about VNIs, if appropriate.
2000 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
2001 && bgp
->advertise_all_vni
)
2002 bgp_zebra_advertise_all_vni(bgp
, 0);
2004 /* Deregister for router-id, interfaces, redistributed routes. */
2005 zclient_send_dereg_requests(zclient
, bgp
->vrf_id
);
2008 void bgp_zebra_initiate_radv(struct bgp
*bgp
, struct peer
*peer
)
2010 int ra_interval
= BGP_UNNUM_DEFAULT_RA_INTERVAL
;
2012 /* Don't try to initiate if we're not connected to Zebra */
2013 if (zclient
->sock
< 0)
2016 if (BGP_DEBUG(zebra
, ZEBRA
))
2017 zlog_debug("%u: Initiating RA for peer %s", bgp
->vrf_id
,
2020 zclient_send_interface_radv_req(zclient
, bgp
->vrf_id
, peer
->ifp
, 1,
2024 void bgp_zebra_terminate_radv(struct bgp
*bgp
, struct peer
*peer
)
2026 /* Don't try to terminate if we're not connected to Zebra */
2027 if (zclient
->sock
< 0)
2030 if (BGP_DEBUG(zebra
, ZEBRA
))
2031 zlog_debug("%u: Terminating RA for peer %s", bgp
->vrf_id
,
2034 zclient_send_interface_radv_req(zclient
, bgp
->vrf_id
, peer
->ifp
, 0, 0);
2037 int bgp_zebra_advertise_all_vni(struct bgp
*bgp
, int advertise
)
2042 if (!zclient
|| zclient
->sock
< 0)
2045 /* Don't try to register if Zebra doesn't know of this instance. */
2046 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
))
2052 zclient_create_header(s
, ZEBRA_ADVERTISE_ALL_VNI
, bgp
->vrf_id
);
2053 stream_putc(s
, advertise
);
2054 stream_putw_at(s
, 0, stream_get_endp(s
));
2056 return zclient_send_message(zclient
);
2059 /* BGP has established connection with Zebra. */
2060 static void bgp_zebra_connected(struct zclient
*zclient
)
2064 zclient_num_connects
++; /* increment even if not responding */
2066 /* At this point, we may or may not have BGP instances configured, but
2067 * we're only interested in the default VRF (others wouldn't have learnt
2068 * the VRF from Zebra yet.)
2070 bgp
= bgp_get_default();
2074 bgp_zebra_instance_register(bgp
);
2076 /* Send the client registration */
2077 bfd_client_sendmsg(zclient
, ZEBRA_BFD_CLIENT_REGISTER
);
2079 /* TODO - What if we have peers and networks configured, do we have to
2084 static int bgp_zebra_process_local_vni(int command
, struct zclient
*zclient
,
2085 zebra_size_t length
, vrf_id_t vrf_id
)
2090 struct in_addr vtep_ip
;
2093 vni
= stream_getl(s
);
2094 if (command
== ZEBRA_VNI_ADD
)
2095 vtep_ip
.s_addr
= stream_get_ipv4(s
);
2096 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
2100 if (BGP_DEBUG(zebra
, ZEBRA
))
2101 zlog_debug("Rx VNI %s VRF %u VNI %u",
2102 (command
== ZEBRA_VNI_ADD
) ? "add" : "del", vrf_id
,
2105 if (command
== ZEBRA_VNI_ADD
)
2106 return bgp_evpn_local_vni_add(
2107 bgp
, vni
, vtep_ip
.s_addr
? vtep_ip
: bgp
->router_id
);
2109 return bgp_evpn_local_vni_del(bgp
, vni
);
2112 static int bgp_zebra_process_local_macip(int command
, struct zclient
*zclient
,
2113 zebra_size_t length
, vrf_id_t vrf_id
)
2121 char buf
[ETHER_ADDR_STRLEN
];
2122 char buf1
[INET6_ADDRSTRLEN
];
2125 memset(&ip
, 0, sizeof(ip
));
2127 vni
= stream_getl(s
);
2128 stream_get(&mac
.octet
, s
, ETH_ALEN
);
2129 ipa_len
= stream_getl(s
);
2130 if (ipa_len
!= 0 && ipa_len
!= IPV4_MAX_BYTELEN
2131 && ipa_len
!= IPV6_MAX_BYTELEN
) {
2132 zlog_err("%u:Recv MACIP %s with invalid IP addr length %d",
2133 vrf_id
, (command
== ZEBRA_MACIP_ADD
) ? "Add" : "Del",
2140 (ipa_len
== IPV4_MAX_BYTELEN
) ? IPADDR_V4
: IPADDR_V6
;
2141 stream_get(&ip
.ip
.addr
, s
, ipa_len
);
2143 sticky
= stream_getc(s
);
2145 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
2149 if (BGP_DEBUG(zebra
, ZEBRA
))
2150 zlog_debug("%u:Recv MACIP %s %sMAC %s IP %s VNI %u", vrf_id
,
2151 (command
== ZEBRA_MACIP_ADD
) ? "Add" : "Del",
2152 sticky
? "sticky " : "",
2153 prefix_mac2str(&mac
, buf
, sizeof(buf
)),
2154 ipaddr2str(&ip
, buf1
, sizeof(buf1
)), vni
);
2156 if (command
== ZEBRA_MACIP_ADD
)
2157 return bgp_evpn_local_macip_add(bgp
, vni
, &mac
, &ip
, sticky
);
2159 return bgp_evpn_local_macip_del(bgp
, vni
, &mac
, &ip
);
2162 void bgp_zebra_init(struct thread_master
*master
)
2164 zclient_num_connects
= 0;
2166 /* Set default values. */
2167 zclient
= zclient_new(master
);
2168 zclient_init(zclient
, ZEBRA_ROUTE_BGP
, 0);
2169 zclient
->zebra_connected
= bgp_zebra_connected
;
2170 zclient
->router_id_update
= bgp_router_id_update
;
2171 zclient
->interface_add
= bgp_interface_add
;
2172 zclient
->interface_delete
= bgp_interface_delete
;
2173 zclient
->interface_address_add
= bgp_interface_address_add
;
2174 zclient
->interface_address_delete
= bgp_interface_address_delete
;
2175 zclient
->interface_nbr_address_add
= bgp_interface_nbr_address_add
;
2176 zclient
->interface_nbr_address_delete
=
2177 bgp_interface_nbr_address_delete
;
2178 zclient
->interface_vrf_update
= bgp_interface_vrf_update
;
2179 zclient
->redistribute_route_ipv4_add
= zebra_read_ipv4
;
2180 zclient
->redistribute_route_ipv4_del
= zebra_read_ipv4
;
2181 zclient
->interface_up
= bgp_interface_up
;
2182 zclient
->interface_down
= bgp_interface_down
;
2183 zclient
->redistribute_route_ipv6_add
= zebra_read_ipv6
;
2184 zclient
->redistribute_route_ipv6_del
= zebra_read_ipv6
;
2185 zclient
->nexthop_update
= bgp_read_nexthop_update
;
2186 zclient
->import_check_update
= bgp_read_import_check_update
;
2187 zclient
->fec_update
= bgp_read_fec_update
;
2188 zclient
->local_vni_add
= bgp_zebra_process_local_vni
;
2189 zclient
->local_vni_del
= bgp_zebra_process_local_vni
;
2190 zclient
->local_macip_add
= bgp_zebra_process_local_macip
;
2191 zclient
->local_macip_del
= bgp_zebra_process_local_macip
;
2193 bgp_nexthop_buf
= stream_new(multipath_num
* sizeof(struct in6_addr
));
2194 bgp_ifindices_buf
= stream_new(multipath_num
* sizeof(unsigned int));
2195 bgp_label_buf
= stream_new(multipath_num
* sizeof(unsigned int));
2198 void bgp_zebra_destroy(void)
2201 if (bgp_nexthop_buf
)
2202 stream_free(bgp_nexthop_buf
);
2203 if (bgp_ifindices_buf
)
2204 stream_free(bgp_ifindices_buf
);
2206 stream_free(bgp_label_buf
);
2208 if (zclient
== NULL
)
2210 zclient_stop(zclient
);
2211 zclient_free(zclient
);
2215 int bgp_zebra_num_connects(void)
2217 return zclient_num_connects
;