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_errors.h"
48 #include "bgpd/bgp_mpath.h"
49 #include "bgpd/bgp_nexthop.h"
50 #include "bgpd/bgp_nht.h"
51 #include "bgpd/bgp_bfd.h"
52 #include "bgpd/bgp_label.h"
54 #include "bgpd/rfapi/rfapi_backend.h"
55 #include "bgpd/rfapi/vnc_export_bgp.h"
57 #include "bgpd/bgp_evpn.h"
58 #include "bgpd/bgp_mplsvpn.h"
59 #include "bgpd/bgp_labelpool.h"
60 #include "bgpd/bgp_pbr.h"
61 #include "bgpd/bgp_evpn_private.h"
63 /* All information about zebra. */
64 struct zclient
*zclient
= NULL
;
66 /* Can we install into zebra? */
67 static inline int bgp_install_info_to_zebra(struct bgp
*bgp
)
69 if (zclient
->sock
<= 0)
72 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
)) {
73 zlog_debug("%s: No zebra instance to talk to, not installing information",
81 int zclient_num_connects
;
83 /* Router-id update message from zebra. */
84 static int bgp_router_id_update(int command
, struct zclient
*zclient
,
85 zebra_size_t length
, vrf_id_t vrf_id
)
87 struct prefix router_id
;
89 zebra_router_id_update_read(zclient
->ibuf
, &router_id
);
91 if (BGP_DEBUG(zebra
, ZEBRA
)) {
92 char buf
[PREFIX2STR_BUFFER
];
93 prefix2str(&router_id
, buf
, sizeof(buf
));
94 zlog_debug("Rx Router Id update VRF %u Id %s", vrf_id
, buf
);
97 bgp_router_id_zebra_bump(vrf_id
, &router_id
);
101 /* Nexthop update message from zebra. */
102 static int bgp_read_nexthop_update(int command
, struct zclient
*zclient
,
103 zebra_size_t length
, vrf_id_t vrf_id
)
105 bgp_parse_nexthop_update(command
, vrf_id
);
109 static int bgp_read_import_check_update(int command
, struct zclient
*zclient
,
110 zebra_size_t length
, vrf_id_t vrf_id
)
112 bgp_parse_nexthop_update(command
, vrf_id
);
116 /* Set or clear interface on which unnumbered neighbor is configured. This
117 * would in turn cause BGP to initiate or turn off IPv6 RAs on this
120 static void bgp_update_interface_nbrs(struct bgp
*bgp
, struct interface
*ifp
,
121 struct interface
*upd_ifp
)
123 struct listnode
*node
, *nnode
;
126 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
127 if (peer
->conf_if
&& (strcmp(peer
->conf_if
, ifp
->name
) == 0)) {
130 bgp_zebra_initiate_radv(bgp
, peer
);
132 bgp_zebra_terminate_radv(bgp
, peer
);
139 static int bgp_read_fec_update(int command
, struct zclient
*zclient
,
142 bgp_parse_fec_update();
146 static void bgp_start_interface_nbrs(struct bgp
*bgp
, struct interface
*ifp
)
148 struct listnode
*node
, *nnode
;
151 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
152 if (peer
->conf_if
&& (strcmp(peer
->conf_if
, ifp
->name
) == 0)
153 && peer
->status
!= Established
) {
154 if (peer_active(peer
))
155 BGP_EVENT_ADD(peer
, BGP_Stop
);
156 BGP_EVENT_ADD(peer
, BGP_Start
);
161 static void bgp_nbr_connected_add(struct bgp
*bgp
, struct nbr_connected
*ifc
)
163 struct listnode
*node
;
164 struct connected
*connected
;
165 struct interface
*ifp
;
168 /* Kick-off the FSM for any relevant peers only if there is a
169 * valid local address on the interface.
172 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
)) {
173 p
= connected
->address
;
174 if (p
->family
== AF_INET6
175 && IN6_IS_ADDR_LINKLOCAL(&p
->u
.prefix6
))
181 bgp_start_interface_nbrs(bgp
, ifp
);
184 static void bgp_nbr_connected_delete(struct bgp
*bgp
, struct nbr_connected
*ifc
,
187 struct listnode
*node
, *nnode
;
189 struct interface
*ifp
;
191 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
193 && (strcmp(peer
->conf_if
, ifc
->ifp
->name
) == 0)) {
194 peer
->last_reset
= PEER_DOWN_NBR_ADDR_DEL
;
195 BGP_EVENT_ADD(peer
, BGP_Stop
);
198 /* Free neighbor also, if we're asked to. */
201 listnode_delete(ifp
->nbr_connected
, ifc
);
202 nbr_connected_free(ifc
);
206 /* Inteface addition message from zebra. */
207 static int bgp_interface_add(int command
, struct zclient
*zclient
,
208 zebra_size_t length
, vrf_id_t vrf_id
)
210 struct interface
*ifp
;
213 ifp
= zebra_interface_add_read(zclient
->ibuf
, vrf_id
);
214 if (!ifp
) // unexpected
217 if (BGP_DEBUG(zebra
, ZEBRA
) && ifp
)
218 zlog_debug("Rx Intf add VRF %u IF %s", vrf_id
, ifp
->name
);
220 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
224 bgp_update_interface_nbrs(bgp
, ifp
, ifp
);
228 static int bgp_interface_delete(int command
, struct zclient
*zclient
,
229 zebra_size_t length
, vrf_id_t vrf_id
)
232 struct interface
*ifp
;
235 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
238 ifp
= zebra_interface_state_read(s
, vrf_id
);
239 if (!ifp
) /* This may happen if we've just unregistered for a VRF. */
242 if (BGP_DEBUG(zebra
, ZEBRA
))
243 zlog_debug("Rx Intf del VRF %u IF %s", vrf_id
, ifp
->name
);
246 bgp_update_interface_nbrs(bgp
, ifp
, NULL
);
248 if_set_index(ifp
, IFINDEX_INTERNAL
);
252 static int bgp_interface_up(int command
, struct zclient
*zclient
,
253 zebra_size_t length
, vrf_id_t vrf_id
)
256 struct interface
*ifp
;
258 struct nbr_connected
*nc
;
259 struct listnode
*node
, *nnode
;
262 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
265 ifp
= zebra_interface_state_read(s
, vrf_id
);
270 if (BGP_DEBUG(zebra
, ZEBRA
))
271 zlog_debug("Rx Intf up VRF %u IF %s", vrf_id
, ifp
->name
);
276 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, c
))
277 bgp_connected_add(bgp
, c
);
279 for (ALL_LIST_ELEMENTS(ifp
->nbr_connected
, node
, nnode
, nc
))
280 bgp_nbr_connected_add(bgp
, nc
);
285 static int bgp_interface_down(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 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
299 ifp
= zebra_interface_state_read(s
, vrf_id
);
303 if (BGP_DEBUG(zebra
, ZEBRA
))
304 zlog_debug("Rx Intf down VRF %u IF %s", vrf_id
, ifp
->name
);
309 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, c
))
310 bgp_connected_delete(bgp
, c
);
312 for (ALL_LIST_ELEMENTS(ifp
->nbr_connected
, node
, nnode
, nc
))
313 bgp_nbr_connected_delete(bgp
, nc
, 1);
315 /* Fast external-failover */
316 if (!CHECK_FLAG(bgp
->flags
, BGP_FLAG_NO_FAST_EXT_FAILOVER
)) {
318 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
319 #if defined(HAVE_CUMULUS)
320 /* Take down directly connected EBGP peers as well as
322 * tracked (directly connected) IBGP peers.
324 if ((peer
->ttl
!= 1) && (peer
->gtsm_hops
!= 1)
326 || bgp_bfd_is_peer_multihop(peer
)))
328 /* Take down directly connected EBGP peers */
329 if ((peer
->ttl
!= 1) && (peer
->gtsm_hops
!= 1))
333 if (ifp
== peer
->nexthop
.ifp
) {
334 BGP_EVENT_ADD(peer
, BGP_Stop
);
335 peer
->last_reset
= PEER_DOWN_IF_DOWN
;
343 static int bgp_interface_address_add(int command
, struct zclient
*zclient
,
344 zebra_size_t length
, vrf_id_t vrf_id
)
346 struct connected
*ifc
;
349 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
351 ifc
= zebra_interface_address_read(command
, zclient
->ibuf
, vrf_id
);
356 if (bgp_debug_zebra(ifc
->address
)) {
357 char buf
[PREFIX2STR_BUFFER
];
358 prefix2str(ifc
->address
, buf
, sizeof(buf
));
359 zlog_debug("Rx Intf address add VRF %u IF %s addr %s", vrf_id
,
360 ifc
->ifp
->name
, buf
);
366 if (if_is_operative(ifc
->ifp
)) {
367 bgp_connected_add(bgp
, ifc
);
369 /* If we have learnt of any neighbors on this interface,
370 * check to kick off any BGP interface-based neighbors,
371 * but only if this is a link-local address.
373 if (IN6_IS_ADDR_LINKLOCAL(&ifc
->address
->u
.prefix6
)
374 && !list_isempty(ifc
->ifp
->nbr_connected
))
375 bgp_start_interface_nbrs(bgp
, ifc
->ifp
);
381 static int bgp_interface_address_delete(int command
, struct zclient
*zclient
,
382 zebra_size_t length
, vrf_id_t vrf_id
)
384 struct connected
*ifc
;
387 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
389 ifc
= zebra_interface_address_read(command
, zclient
->ibuf
, vrf_id
);
394 if (bgp_debug_zebra(ifc
->address
)) {
395 char buf
[PREFIX2STR_BUFFER
];
396 prefix2str(ifc
->address
, buf
, sizeof(buf
));
397 zlog_debug("Rx Intf address del VRF %u IF %s addr %s", vrf_id
,
398 ifc
->ifp
->name
, buf
);
401 if (bgp
&& if_is_operative(ifc
->ifp
)) {
402 bgp_connected_delete(bgp
, ifc
);
410 static int bgp_interface_nbr_address_add(int command
, struct zclient
*zclient
,
411 zebra_size_t length
, vrf_id_t vrf_id
)
413 struct nbr_connected
*ifc
= NULL
;
416 ifc
= zebra_interface_nbr_address_read(command
, zclient
->ibuf
, vrf_id
);
421 if (bgp_debug_zebra(ifc
->address
)) {
422 char buf
[PREFIX2STR_BUFFER
];
423 prefix2str(ifc
->address
, buf
, sizeof(buf
));
424 zlog_debug("Rx Intf neighbor add VRF %u IF %s addr %s", vrf_id
,
425 ifc
->ifp
->name
, buf
);
428 if (if_is_operative(ifc
->ifp
)) {
429 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
431 bgp_nbr_connected_add(bgp
, ifc
);
437 static int bgp_interface_nbr_address_delete(int command
,
438 struct zclient
*zclient
,
442 struct nbr_connected
*ifc
= NULL
;
445 ifc
= zebra_interface_nbr_address_read(command
, zclient
->ibuf
, vrf_id
);
450 if (bgp_debug_zebra(ifc
->address
)) {
451 char buf
[PREFIX2STR_BUFFER
];
452 prefix2str(ifc
->address
, buf
, sizeof(buf
));
453 zlog_debug("Rx Intf neighbor del VRF %u IF %s addr %s", vrf_id
,
454 ifc
->ifp
->name
, buf
);
457 if (if_is_operative(ifc
->ifp
)) {
458 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
460 bgp_nbr_connected_delete(bgp
, ifc
, 0);
463 nbr_connected_free(ifc
);
468 /* VRF update for an interface. */
469 static int bgp_interface_vrf_update(int command
, struct zclient
*zclient
,
470 zebra_size_t length
, vrf_id_t vrf_id
)
472 struct interface
*ifp
;
475 struct nbr_connected
*nc
;
476 struct listnode
*node
, *nnode
;
480 ifp
= zebra_interface_vrf_update_read(zclient
->ibuf
, vrf_id
,
485 if (BGP_DEBUG(zebra
, ZEBRA
) && ifp
)
486 zlog_debug("Rx Intf VRF change VRF %u IF %s NewVRF %u", vrf_id
,
487 ifp
->name
, new_vrf_id
);
489 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
492 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, c
))
493 bgp_connected_delete(bgp
, c
);
495 for (ALL_LIST_ELEMENTS(ifp
->nbr_connected
, node
, nnode
, nc
))
496 bgp_nbr_connected_delete(bgp
, nc
, 1);
498 /* Fast external-failover */
499 if (!CHECK_FLAG(bgp
->flags
, BGP_FLAG_NO_FAST_EXT_FAILOVER
)) {
500 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
501 if ((peer
->ttl
!= 1) && (peer
->gtsm_hops
!= 1))
504 if (ifp
== peer
->nexthop
.ifp
)
505 BGP_EVENT_ADD(peer
, BGP_Stop
);
510 if_update_to_new_vrf(ifp
, new_vrf_id
);
512 bgp
= bgp_lookup_by_vrf_id(new_vrf_id
);
516 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, c
))
517 bgp_connected_add(bgp
, c
);
519 for (ALL_LIST_ELEMENTS(ifp
->nbr_connected
, node
, nnode
, nc
))
520 bgp_nbr_connected_add(bgp
, nc
);
524 /* Zebra route add and delete treatment. */
525 static int zebra_read_route(int command
, struct zclient
*zclient
,
526 zebra_size_t length
, vrf_id_t vrf_id
)
528 enum nexthop_types_t nhtype
;
529 struct zapi_route api
;
530 union g_addr nexthop
;
535 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
539 if (zapi_route_decode(zclient
->ibuf
, &api
) < 0)
542 /* we completely ignore srcdest routes for now. */
543 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_SRCPFX
))
546 /* ignore link-local address. */
547 if (api
.prefix
.family
== AF_INET6
548 && IN6_IS_ADDR_LINKLOCAL(&api
.prefix
.u
.prefix6
))
551 nexthop
= api
.nexthops
[0].gate
;
552 ifindex
= api
.nexthops
[0].ifindex
;
553 nhtype
= api
.nexthops
[0].type
;
555 add
= (command
== ZEBRA_REDISTRIBUTE_ROUTE_ADD
);
558 * The ADD message is actually an UPDATE and there is no
560 * for a prior redistributed route, if any. So, perform an
562 * DEL processing for the same redistributed route from any
566 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
568 bgp_redistribute_delete(bgp
, &api
.prefix
, i
,
572 /* Now perform the add/update. */
573 bgp_redistribute_add(bgp
, &api
.prefix
, &nexthop
, ifindex
,
574 nhtype
, api
.metric
, api
.type
, api
.instance
,
577 bgp_redistribute_delete(bgp
, &api
.prefix
, api
.type
,
581 if (bgp_debug_zebra(&api
.prefix
)) {
582 char buf
[2][PREFIX_STRLEN
];
584 prefix2str(&api
.prefix
, buf
[0], sizeof(buf
[0]));
586 inet_ntop(api
.prefix
.family
, &nexthop
, buf
[1],
589 "Rx route ADD VRF %u %s[%d] %s nexthop %s (type %d if %u) metric %u tag %" ROUTE_TAG_PRI
,
590 vrf_id
, zebra_route_string(api
.type
),
591 api
.instance
, buf
[0], buf
[1], nhtype
,
592 ifindex
, api
.metric
, api
.tag
);
595 "Rx route DEL VRF %u %s[%d] %s",
596 vrf_id
, zebra_route_string(api
.type
),
597 api
.instance
, buf
[0]);
604 struct interface
*if_lookup_by_ipv4(struct in_addr
*addr
, vrf_id_t vrf_id
)
607 struct listnode
*cnode
;
608 struct interface
*ifp
;
609 struct connected
*connected
;
610 struct prefix_ipv4 p
;
613 vrf
= vrf_lookup_by_id(vrf_id
);
619 p
.prefixlen
= IPV4_MAX_BITLEN
;
621 FOR_ALL_INTERFACES (vrf
, ifp
) {
622 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
)) {
623 cp
= connected
->address
;
625 if (cp
->family
== AF_INET
)
626 if (prefix_match(cp
, (struct prefix
*)&p
))
633 struct interface
*if_lookup_by_ipv4_exact(struct in_addr
*addr
, vrf_id_t vrf_id
)
636 struct listnode
*cnode
;
637 struct interface
*ifp
;
638 struct connected
*connected
;
641 vrf
= vrf_lookup_by_id(vrf_id
);
645 FOR_ALL_INTERFACES (vrf
, ifp
) {
646 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
)) {
647 cp
= connected
->address
;
649 if (cp
->family
== AF_INET
)
650 if (IPV4_ADDR_SAME(&cp
->u
.prefix4
, addr
))
657 struct interface
*if_lookup_by_ipv6(struct in6_addr
*addr
, ifindex_t ifindex
,
661 struct listnode
*cnode
;
662 struct interface
*ifp
;
663 struct connected
*connected
;
664 struct prefix_ipv6 p
;
667 vrf
= vrf_lookup_by_id(vrf_id
);
673 p
.prefixlen
= IPV6_MAX_BITLEN
;
675 FOR_ALL_INTERFACES (vrf
, ifp
) {
676 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
)) {
677 cp
= connected
->address
;
679 if (cp
->family
== AF_INET6
)
680 if (prefix_match(cp
, (struct prefix
*)&p
)) {
681 if (IN6_IS_ADDR_LINKLOCAL(
683 if (ifindex
== ifp
->ifindex
)
693 struct interface
*if_lookup_by_ipv6_exact(struct in6_addr
*addr
,
694 ifindex_t ifindex
, vrf_id_t vrf_id
)
697 struct listnode
*cnode
;
698 struct interface
*ifp
;
699 struct connected
*connected
;
702 vrf
= vrf_lookup_by_id(vrf_id
);
706 FOR_ALL_INTERFACES (vrf
, ifp
) {
707 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
)) {
708 cp
= connected
->address
;
710 if (cp
->family
== AF_INET6
)
711 if (IPV6_ADDR_SAME(&cp
->u
.prefix6
, addr
)) {
712 if (IN6_IS_ADDR_LINKLOCAL(
714 if (ifindex
== ifp
->ifindex
)
724 static int if_get_ipv6_global(struct interface
*ifp
, struct in6_addr
*addr
)
726 struct listnode
*cnode
;
727 struct connected
*connected
;
730 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
)) {
731 cp
= connected
->address
;
733 if (cp
->family
== AF_INET6
)
734 if (!IN6_IS_ADDR_LINKLOCAL(&cp
->u
.prefix6
)) {
735 memcpy(addr
, &cp
->u
.prefix6
, IPV6_MAX_BYTELEN
);
742 static int if_get_ipv6_local(struct interface
*ifp
, struct in6_addr
*addr
)
744 struct listnode
*cnode
;
745 struct connected
*connected
;
748 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
)) {
749 cp
= connected
->address
;
751 if (cp
->family
== AF_INET6
)
752 if (IN6_IS_ADDR_LINKLOCAL(&cp
->u
.prefix6
)) {
753 memcpy(addr
, &cp
->u
.prefix6
, IPV6_MAX_BYTELEN
);
760 static int if_get_ipv4_address(struct interface
*ifp
, struct in_addr
*addr
)
762 struct listnode
*cnode
;
763 struct connected
*connected
;
766 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
)) {
767 cp
= connected
->address
;
768 if ((cp
->family
== AF_INET
)
769 && !ipv4_martian(&(cp
->u
.prefix4
))) {
770 *addr
= cp
->u
.prefix4
;
778 bool bgp_zebra_nexthop_set(union sockunion
*local
, union sockunion
*remote
,
779 struct bgp_nexthop
*nexthop
, struct peer
*peer
)
782 struct interface
*ifp
= NULL
;
784 memset(nexthop
, 0, sizeof(struct bgp_nexthop
));
791 if (local
->sa
.sa_family
== AF_INET
) {
792 nexthop
->v4
= local
->sin
.sin_addr
;
794 ifp
= if_lookup_by_name(peer
->update_if
,
797 ifp
= if_lookup_by_ipv4_exact(&local
->sin
.sin_addr
,
800 if (local
->sa
.sa_family
== AF_INET6
) {
801 if (IN6_IS_ADDR_LINKLOCAL(&local
->sin6
.sin6_addr
)) {
802 if (peer
->conf_if
|| peer
->ifname
)
803 ifp
= if_lookup_by_name(peer
->conf_if
807 } else if (peer
->update_if
)
808 ifp
= if_lookup_by_name(peer
->update_if
,
811 ifp
= if_lookup_by_ipv6_exact(&local
->sin6
.sin6_addr
,
812 local
->sin6
.sin6_scope_id
,
818 * BGP views do not currently get proper data
819 * from zebra( when attached ) to be able to
820 * properly resolve nexthops, so give this
821 * instance type a pass.
823 if (peer
->bgp
->inst_type
== BGP_INSTANCE_TYPE_VIEW
)
826 * If we have no interface data but we have established
827 * some connection w/ zebra than something has gone
828 * terribly terribly wrong here, so say this failed
829 * If we do not any zebra connection then not
830 * having a ifp pointer is ok.
832 return zclient_num_connects
? false : true;
837 /* IPv4 connection, fetch and store IPv6 local address(es) if any. */
838 if (local
->sa
.sa_family
== AF_INET
) {
840 ret
= if_get_ipv6_global(ifp
, &nexthop
->v6_global
);
843 /* There is no global nexthop. Use link-local address as
845 * global and link-local nexthop. In this scenario, the
847 * for interop is that the network admin would use a
849 * specify the global IPv6 nexthop.
851 if_get_ipv6_local(ifp
, &nexthop
->v6_global
);
852 memcpy(&nexthop
->v6_local
, &nexthop
->v6_global
,
855 if_get_ipv6_local(ifp
, &nexthop
->v6_local
);
857 if (if_lookup_by_ipv4(&remote
->sin
.sin_addr
, peer
->bgp
->vrf_id
))
858 peer
->shared_network
= 1;
860 peer
->shared_network
= 0;
863 /* IPv6 connection, fetch and store IPv4 local address if any. */
864 if (local
->sa
.sa_family
== AF_INET6
) {
865 struct interface
*direct
= NULL
;
868 ret
= if_get_ipv4_address(ifp
, &nexthop
->v4
);
869 if (!ret
&& peer
->local_id
.s_addr
)
870 nexthop
->v4
= peer
->local_id
;
873 if (!IN6_IS_ADDR_LINKLOCAL(&local
->sin6
.sin6_addr
)) {
874 memcpy(&nexthop
->v6_global
, &local
->sin6
.sin6_addr
,
877 /* If directory connected set link-local address. */
878 direct
= if_lookup_by_ipv6(&remote
->sin6
.sin6_addr
,
879 remote
->sin6
.sin6_scope_id
,
882 if_get_ipv6_local(ifp
, &nexthop
->v6_local
);
884 /* Link-local address. */
886 ret
= if_get_ipv6_global(ifp
, &nexthop
->v6_global
);
888 /* If there is no global address. Set link-local
890 global. I know this break RFC specification... */
891 /* In this scenario, the expectation for interop is that
893 * network admin would use a route-map to specify the
898 memcpy(&nexthop
->v6_global
,
899 &local
->sin6
.sin6_addr
,
901 /* Always set the link-local address */
902 memcpy(&nexthop
->v6_local
, &local
->sin6
.sin6_addr
,
906 if (IN6_IS_ADDR_LINKLOCAL(&local
->sin6
.sin6_addr
)
907 || if_lookup_by_ipv6(&remote
->sin6
.sin6_addr
,
908 remote
->sin6
.sin6_scope_id
,
910 peer
->shared_network
= 1;
912 peer
->shared_network
= 0;
915 /* KAME stack specific treatment. */
917 if (IN6_IS_ADDR_LINKLOCAL(&nexthop
->v6_global
)
918 && IN6_LINKLOCAL_IFINDEX(nexthop
->v6_global
)) {
919 SET_IN6_LINKLOCAL_IFINDEX(nexthop
->v6_global
, 0);
921 if (IN6_IS_ADDR_LINKLOCAL(&nexthop
->v6_local
)
922 && IN6_LINKLOCAL_IFINDEX(nexthop
->v6_local
)) {
923 SET_IN6_LINKLOCAL_IFINDEX(nexthop
->v6_local
, 0);
927 /* If we have identified the local interface, there is no error for now.
932 static struct in6_addr
*
933 bgp_path_info_to_ipv6_nexthop(struct bgp_path_info
*path
, ifindex_t
*ifindex
)
935 struct in6_addr
*nexthop
= NULL
;
937 /* Only global address nexthop exists. */
938 if (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
) {
939 nexthop
= &path
->attr
->mp_nexthop_global
;
940 if (IN6_IS_ADDR_LINKLOCAL(nexthop
))
941 *ifindex
= path
->attr
->nh_ifindex
;
944 /* If both global and link-local address present. */
945 if (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
) {
946 /* Check if route-map is set to prefer global over link-local */
947 if (path
->attr
->mp_nexthop_prefer_global
) {
948 nexthop
= &path
->attr
->mp_nexthop_global
;
949 if (IN6_IS_ADDR_LINKLOCAL(nexthop
))
950 *ifindex
= path
->attr
->nh_ifindex
;
952 /* Workaround for Cisco's nexthop bug. */
953 if (IN6_IS_ADDR_UNSPECIFIED(
954 &path
->attr
->mp_nexthop_global
)
955 && path
->peer
->su_remote
->sa
.sa_family
958 &path
->peer
->su_remote
->sin6
.sin6_addr
;
959 if (IN6_IS_ADDR_LINKLOCAL(nexthop
))
960 *ifindex
= path
->peer
->nexthop
.ifp
963 nexthop
= &path
->attr
->mp_nexthop_local
;
964 if (IN6_IS_ADDR_LINKLOCAL(nexthop
))
965 *ifindex
= path
->attr
->nh_lla_ifindex
;
973 static int bgp_table_map_apply(struct route_map
*map
, struct prefix
*p
,
974 struct bgp_path_info
*path
)
976 route_map_result_t ret
;
978 ret
= route_map_apply(map
, p
, RMAP_BGP
, path
);
979 bgp_attr_flush(path
->attr
);
981 if (ret
!= RMAP_DENYMATCH
)
984 if (bgp_debug_zebra(p
)) {
985 if (p
->family
== AF_INET
) {
986 char buf
[2][INET_ADDRSTRLEN
];
988 "Zebra rmap deny: IPv4 route %s/%d nexthop %s",
989 inet_ntop(AF_INET
, &p
->u
.prefix4
, buf
[0],
992 inet_ntop(AF_INET
, &path
->attr
->nexthop
, buf
[1],
995 if (p
->family
== AF_INET6
) {
996 char buf
[2][INET6_ADDRSTRLEN
];
998 struct in6_addr
*nexthop
;
1000 nexthop
= bgp_path_info_to_ipv6_nexthop(path
, &ifindex
);
1002 "Zebra rmap deny: IPv6 route %s/%d nexthop %s",
1003 inet_ntop(AF_INET6
, &p
->u
.prefix6
, buf
[0],
1006 inet_ntop(AF_INET6
, nexthop
,
1007 buf
[1], sizeof(buf
[1])));
1013 static struct thread
*bgp_tm_thread_connect
;
1014 static bool bgp_tm_status_connected
;
1015 static bool bgp_tm_chunk_obtained
;
1016 #define BGP_FLOWSPEC_TABLE_CHUNK 100000
1017 static uint32_t bgp_tm_min
, bgp_tm_max
, bgp_tm_chunk_size
;
1018 struct bgp
*bgp_tm_bgp
;
1020 static int bgp_zebra_tm_connect(struct thread
*t
)
1022 struct zclient
*zclient
;
1023 int delay
= 10, ret
= 0;
1025 zclient
= THREAD_ARG(t
);
1026 if (bgp_tm_status_connected
&& zclient
->sock
> 0)
1029 bgp_tm_status_connected
= false;
1030 ret
= tm_table_manager_connect(zclient
);
1033 zlog_info("Error connecting to table manager!");
1034 bgp_tm_status_connected
= false;
1036 if (!bgp_tm_status_connected
)
1037 zlog_debug("Connecting to table manager. Success");
1038 bgp_tm_status_connected
= true;
1039 if (!bgp_tm_chunk_obtained
) {
1040 if (bgp_zebra_get_table_range(bgp_tm_chunk_size
,
1042 &bgp_tm_max
) >= 0) {
1043 bgp_tm_chunk_obtained
= true;
1044 /* parse non installed entries */
1045 bgp_zebra_announce_table(bgp_tm_bgp
, AFI_IP
, SAFI_FLOWSPEC
);
1049 thread_add_timer(bm
->master
, bgp_zebra_tm_connect
, zclient
, delay
,
1050 &bgp_tm_thread_connect
);
1054 bool bgp_zebra_tm_chunk_obtained(void)
1056 return bgp_tm_chunk_obtained
;
1059 uint32_t bgp_zebra_tm_get_id(void)
1061 static int table_id
;
1063 if (!bgp_tm_chunk_obtained
)
1065 return bgp_tm_min
++;
1068 void bgp_zebra_init_tm_connect(struct bgp
*bgp
)
1072 /* if already set, do nothing
1074 if (bgp_tm_thread_connect
!= NULL
)
1076 bgp_tm_status_connected
= false;
1077 bgp_tm_chunk_obtained
= false;
1078 bgp_tm_min
= bgp_tm_max
= 0;
1079 bgp_tm_chunk_size
= BGP_FLOWSPEC_TABLE_CHUNK
;
1081 thread_add_timer(bm
->master
, bgp_zebra_tm_connect
, zclient
, delay
,
1082 &bgp_tm_thread_connect
);
1085 int bgp_zebra_get_table_range(uint32_t chunk_size
,
1086 uint32_t *start
, uint32_t *end
)
1090 if (!bgp_tm_status_connected
)
1092 ret
= tm_get_table_chunk(zclient
, chunk_size
, start
, end
);
1094 flog_err(EC_BGP_TABLE_CHUNK
,
1095 "BGP: Error getting table chunk %u", chunk_size
);
1098 zlog_info("BGP: Table Manager returns range from chunk %u is [%u %u]",
1099 chunk_size
, *start
, *end
);
1103 static int update_ipv4nh_for_route_install(int nh_othervrf
,
1104 struct in_addr
*nexthop
,
1107 struct zapi_nexthop
*api_nh
)
1109 api_nh
->gate
.ipv4
= *nexthop
;
1111 /* Need to set fields appropriately for EVPN routes imported into
1112 * a VRF (which are programmed as onlink on l3-vni SVI) as well as
1113 * connected routes leaked into a VRF.
1116 api_nh
->type
= NEXTHOP_TYPE_IPV4_IFINDEX
;
1117 else if (nh_othervrf
&&
1118 api_nh
->gate
.ipv4
.s_addr
== INADDR_ANY
) {
1119 api_nh
->type
= NEXTHOP_TYPE_IFINDEX
;
1120 api_nh
->ifindex
= attr
->nh_ifindex
;
1122 api_nh
->type
= NEXTHOP_TYPE_IPV4
;
1128 update_ipv6nh_for_route_install(int nh_othervrf
, struct in6_addr
*nexthop
,
1129 ifindex_t ifindex
, struct bgp_path_info
*pi
,
1130 struct bgp_path_info
*best_pi
, bool is_evpn
,
1131 struct zapi_nexthop
*api_nh
)
1138 api_nh
->type
= NEXTHOP_TYPE_IPV6_IFINDEX
;
1139 else if (nh_othervrf
) {
1140 if (IN6_IS_ADDR_UNSPECIFIED(nexthop
)) {
1141 api_nh
->type
= NEXTHOP_TYPE_IFINDEX
;
1142 api_nh
->ifindex
= attr
->nh_ifindex
;
1143 } else if (IN6_IS_ADDR_LINKLOCAL(nexthop
)) {
1146 api_nh
->type
= NEXTHOP_TYPE_IPV6_IFINDEX
;
1147 api_nh
->ifindex
= ifindex
;
1149 api_nh
->type
= NEXTHOP_TYPE_IPV6
;
1150 api_nh
->ifindex
= 0;
1153 if (IN6_IS_ADDR_LINKLOCAL(nexthop
)) {
1155 && attr
->mp_nexthop_len
1156 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
1157 if (pi
->peer
->nexthop
.ifp
)
1159 pi
->peer
->nexthop
.ifp
->ifindex
;
1161 if (pi
->peer
->conf_if
)
1162 ifindex
= pi
->peer
->ifp
->ifindex
;
1163 else if (pi
->peer
->ifname
)
1164 ifindex
= ifname2ifindex(
1166 pi
->peer
->bgp
->vrf_id
);
1167 else if (pi
->peer
->nexthop
.ifp
)
1169 pi
->peer
->nexthop
.ifp
->ifindex
;
1174 api_nh
->type
= NEXTHOP_TYPE_IPV6_IFINDEX
;
1175 api_nh
->ifindex
= ifindex
;
1177 api_nh
->type
= NEXTHOP_TYPE_IPV6
;
1178 api_nh
->ifindex
= 0;
1181 api_nh
->gate
.ipv6
= *nexthop
;
1186 void bgp_zebra_announce(struct bgp_node
*rn
, struct prefix
*p
,
1187 struct bgp_path_info
*info
, struct bgp
*bgp
, afi_t afi
,
1190 struct zapi_route api
;
1191 struct zapi_nexthop
*api_nh
;
1193 unsigned int valid_nh_count
= 0;
1194 int has_valid_label
= 0;
1197 struct bgp_path_info
*mpinfo
;
1199 struct attr local_attr
;
1200 struct bgp_path_info local_info
;
1201 struct bgp_path_info
*mpinfo_cp
= &local_info
;
1204 int nh_othervrf
= 0;
1205 char buf_prefix
[PREFIX_STRLEN
]; /* filled in if we are debugging */
1209 /* Don't try to install if we're not connected to Zebra or Zebra doesn't
1210 * know of this instance.
1212 if (!bgp_install_info_to_zebra(bgp
))
1215 if (bgp
->main_zebra_update_hold
)
1218 if (bgp_debug_zebra(p
))
1219 prefix2str(p
, buf_prefix
, sizeof(buf_prefix
));
1221 if (safi
== SAFI_FLOWSPEC
) {
1222 bgp_pbr_update_entry(bgp
, &rn
->p
, info
, afi
, safi
, true);
1227 * vrf leaking support (will have only one nexthop)
1229 if (info
->extra
&& info
->extra
->bgp_orig
)
1232 /* Make Zebra API structure. */
1233 memset(&api
, 0, sizeof(api
));
1234 api
.vrf_id
= bgp
->vrf_id
;
1235 api
.type
= ZEBRA_ROUTE_BGP
;
1238 SET_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
);
1242 if (info
->type
== ZEBRA_ROUTE_BGP
1243 && info
->sub_type
== BGP_ROUTE_IMPORTED
) {
1245 /* Obtain peer from parent */
1246 if (info
->extra
&& info
->extra
->parent
)
1247 peer
= ((struct bgp_path_info
*)(info
->extra
->parent
))
1251 tag
= info
->attr
->tag
;
1253 /* If the route's source is EVPN, flag as such. */
1254 is_evpn
= is_route_parent_evpn(info
);
1256 SET_FLAG(api
.flags
, ZEBRA_FLAG_EVPN_ROUTE
);
1258 if (peer
->sort
== BGP_PEER_IBGP
|| peer
->sort
== BGP_PEER_CONFED
1259 || info
->sub_type
== BGP_ROUTE_AGGREGATE
) {
1260 SET_FLAG(api
.flags
, ZEBRA_FLAG_IBGP
);
1261 SET_FLAG(api
.flags
, ZEBRA_FLAG_ALLOW_RECURSION
);
1264 if ((peer
->sort
== BGP_PEER_EBGP
&& peer
->ttl
!= 1)
1265 || CHECK_FLAG(peer
->flags
, PEER_FLAG_DISABLE_CONNECTED_CHECK
)
1266 || bgp_flag_check(bgp
, BGP_FLAG_DISABLE_NH_CONNECTED_CHK
))
1268 SET_FLAG(api
.flags
, ZEBRA_FLAG_ALLOW_RECURSION
);
1270 /* Metric is currently based on the best-path only */
1271 metric
= info
->attr
->med
;
1272 for (mpinfo
= info
; mpinfo
; mpinfo
= bgp_path_info_mpath_next(mpinfo
)) {
1273 if (valid_nh_count
>= multipath_num
)
1276 *mpinfo_cp
= *mpinfo
;
1278 /* Get nexthop address-family */
1279 if (p
->family
== AF_INET
1280 && !BGP_ATTR_NEXTHOP_AFI_IP6(mpinfo_cp
->attr
))
1281 nh_family
= AF_INET
;
1282 else if (p
->family
== AF_INET6
1283 || (p
->family
== AF_INET
1284 && BGP_ATTR_NEXTHOP_AFI_IP6(mpinfo_cp
->attr
)))
1285 nh_family
= AF_INET6
;
1289 api_nh
= &api
.nexthops
[valid_nh_count
];
1290 api_nh
->vrf_id
= nh_othervrf
? info
->extra
->bgp_orig
->vrf_id
1292 if (nh_family
== AF_INET
) {
1293 if (bgp_debug_zebra(&api
.prefix
)) {
1294 if (mpinfo
->extra
) {
1296 "%s: p=%s, bgp_is_valid_label: %d",
1297 __func__
, buf_prefix
,
1303 "%s: p=%s, extra is NULL, no label",
1304 __func__
, buf_prefix
);
1308 if (bgp
->table_map
[afi
][safi
].name
) {
1309 /* Copy info and attributes, so the route-map
1310 apply doesn't modify the BGP route info. */
1311 local_attr
= *mpinfo
->attr
;
1312 mpinfo_cp
->attr
= &local_attr
;
1315 if (bgp
->table_map
[afi
][safi
].name
) {
1316 if (!bgp_table_map_apply(
1317 bgp
->table_map
[afi
][safi
].map
, p
,
1321 /* metric/tag is only allowed to be
1322 * overridden on 1st nexthop */
1323 if (mpinfo
== info
) {
1324 metric
= mpinfo_cp
->attr
->med
;
1325 tag
= mpinfo_cp
->attr
->tag
;
1329 nh_updated
= update_ipv4nh_for_route_install(
1331 &mpinfo_cp
->attr
->nexthop
,
1332 mpinfo_cp
->attr
, is_evpn
, api_nh
);
1334 ifindex_t ifindex
= IFINDEX_INTERNAL
;
1335 struct in6_addr
*nexthop
;
1337 if (bgp
->table_map
[afi
][safi
].name
) {
1338 /* Copy info and attributes, so the route-map
1339 apply doesn't modify the BGP route info. */
1340 local_attr
= *mpinfo
->attr
;
1341 mpinfo_cp
->attr
= &local_attr
;
1344 if (bgp
->table_map
[afi
][safi
].name
) {
1345 /* Copy info and attributes, so the route-map
1346 apply doesn't modify the BGP route info. */
1347 local_attr
= *mpinfo
->attr
;
1348 mpinfo_cp
->attr
= &local_attr
;
1350 if (!bgp_table_map_apply(
1351 bgp
->table_map
[afi
][safi
].map
, p
,
1355 /* metric/tag is only allowed to be
1356 * overridden on 1st nexthop */
1357 if (mpinfo
== info
) {
1358 metric
= mpinfo_cp
->attr
->med
;
1359 tag
= mpinfo_cp
->attr
->tag
;
1362 nexthop
= bgp_path_info_to_ipv6_nexthop(mpinfo_cp
,
1364 nh_updated
= update_ipv6nh_for_route_install(
1365 nh_othervrf
, nexthop
, ifindex
,
1366 mpinfo
, info
, is_evpn
, api_nh
);
1369 /* Did we get proper nexthop info to update zebra? */
1374 && bgp_is_valid_label(&mpinfo
->extra
->label
[0])
1375 && !CHECK_FLAG(api
.flags
, ZEBRA_FLAG_EVPN_ROUTE
)) {
1376 has_valid_label
= 1;
1377 label
= label_pton(&mpinfo
->extra
->label
[0]);
1379 api_nh
->label_num
= 1;
1380 api_nh
->labels
[0] = label
;
1382 memcpy(&api_nh
->rmac
, &(mpinfo
->attr
->rmac
),
1383 sizeof(struct ethaddr
));
1388 /* if this is a evpn route we don't have to include the label */
1389 if (has_valid_label
&& !(CHECK_FLAG(api
.flags
, ZEBRA_FLAG_EVPN_ROUTE
)))
1390 SET_FLAG(api
.message
, ZAPI_MESSAGE_LABEL
);
1393 * When we create an aggregate route we must also
1394 * install a Null0 route in the RIB, so overwrite
1395 * what was written into api with a blackhole route
1397 if (info
->sub_type
== BGP_ROUTE_AGGREGATE
)
1398 zapi_route_set_blackhole(&api
, BLACKHOLE_NULL
);
1400 api
.nexthop_num
= valid_nh_count
;
1402 SET_FLAG(api
.message
, ZAPI_MESSAGE_METRIC
);
1403 api
.metric
= metric
;
1406 SET_FLAG(api
.message
, ZAPI_MESSAGE_TAG
);
1410 distance
= bgp_distance_apply(p
, info
, afi
, safi
, bgp
);
1412 SET_FLAG(api
.message
, ZAPI_MESSAGE_DISTANCE
);
1413 api
.distance
= distance
;
1416 if (bgp_debug_zebra(p
)) {
1417 char prefix_buf
[PREFIX_STRLEN
];
1418 char nh_buf
[INET6_ADDRSTRLEN
];
1422 prefix2str(&api
.prefix
, prefix_buf
, sizeof(prefix_buf
));
1423 zlog_debug("Tx route %s VRF %u %s metric %u tag %" ROUTE_TAG_PRI
1425 valid_nh_count
? "add" : "delete", bgp
->vrf_id
,
1426 prefix_buf
, api
.metric
, api
.tag
, api
.nexthop_num
);
1427 for (i
= 0; i
< api
.nexthop_num
; i
++) {
1428 api_nh
= &api
.nexthops
[i
];
1430 if (api_nh
->type
== NEXTHOP_TYPE_IFINDEX
)
1433 if (api_nh
->type
== NEXTHOP_TYPE_IPV4
)
1434 nh_family
= AF_INET
;
1436 nh_family
= AF_INET6
;
1437 inet_ntop(nh_family
, &api_nh
->gate
, nh_buf
,
1441 label_buf
[0] = '\0';
1443 && !CHECK_FLAG(api
.flags
, ZEBRA_FLAG_EVPN_ROUTE
))
1444 sprintf(label_buf
, "label %u",
1446 zlog_debug(" nhop [%d]: %s if %u VRF %u %s",
1447 i
+ 1, nh_buf
, api_nh
->ifindex
,
1448 api_nh
->vrf_id
, label_buf
);
1452 if (bgp_debug_zebra(p
)) {
1453 int recursion_flag
= 0;
1455 if (CHECK_FLAG(api
.flags
, ZEBRA_FLAG_ALLOW_RECURSION
))
1458 zlog_debug("%s: %s: announcing to zebra (recursion %sset)",
1459 __func__
, buf_prefix
,
1460 (recursion_flag
? "" : "NOT "));
1462 zclient_route_send(valid_nh_count
? ZEBRA_ROUTE_ADD
1463 : ZEBRA_ROUTE_DELETE
,
1467 /* Announce all routes of a table to zebra */
1468 void bgp_zebra_announce_table(struct bgp
*bgp
, afi_t afi
, safi_t safi
)
1470 struct bgp_node
*rn
;
1471 struct bgp_table
*table
;
1472 struct bgp_path_info
*pi
;
1474 /* Don't try to install if we're not connected to Zebra or Zebra doesn't
1475 * know of this instance.
1477 if (!bgp_install_info_to_zebra(bgp
))
1480 table
= bgp
->rib
[afi
][safi
];
1484 for (rn
= bgp_table_top(table
); rn
; rn
= bgp_route_next(rn
))
1485 for (pi
= bgp_node_get_bgp_path_info(rn
); pi
; pi
= pi
->next
)
1486 if (CHECK_FLAG(pi
->flags
, BGP_PATH_SELECTED
) &&
1488 (pi
->type
== ZEBRA_ROUTE_BGP
1489 && (pi
->sub_type
== BGP_ROUTE_NORMAL
1490 || pi
->sub_type
== BGP_ROUTE_IMPORTED
)))
1492 bgp_zebra_announce(rn
, &rn
->p
, pi
, bgp
, afi
,
1496 void bgp_zebra_withdraw(struct prefix
*p
, struct bgp_path_info
*info
,
1497 struct bgp
*bgp
, safi_t safi
)
1499 struct zapi_route api
;
1502 /* Don't try to install if we're not connected to Zebra or Zebra doesn't
1503 * know of this instance.
1505 if (!bgp_install_info_to_zebra(bgp
))
1508 if (safi
== SAFI_FLOWSPEC
) {
1510 bgp_pbr_update_entry(peer
->bgp
, p
, info
, AFI_IP
, safi
, false);
1514 memset(&api
, 0, sizeof(api
));
1515 api
.vrf_id
= bgp
->vrf_id
;
1516 api
.type
= ZEBRA_ROUTE_BGP
;
1520 /* If the route's source is EVPN, flag as such. */
1521 if (is_route_parent_evpn(info
))
1522 SET_FLAG(api
.flags
, ZEBRA_FLAG_EVPN_ROUTE
);
1524 if (bgp_debug_zebra(p
)) {
1525 char buf
[PREFIX_STRLEN
];
1527 prefix2str(&api
.prefix
, buf
, sizeof(buf
));
1528 zlog_debug("Tx route delete VRF %u %s", bgp
->vrf_id
, buf
);
1531 zclient_route_send(ZEBRA_ROUTE_DELETE
, zclient
, &api
);
1534 struct bgp_redist
*bgp_redist_lookup(struct bgp
*bgp
, afi_t afi
, uint8_t type
,
1535 unsigned short instance
)
1537 struct list
*red_list
;
1538 struct listnode
*node
;
1539 struct bgp_redist
*red
;
1541 red_list
= bgp
->redist
[afi
][type
];
1545 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
))
1546 if (red
->instance
== instance
)
1552 struct bgp_redist
*bgp_redist_add(struct bgp
*bgp
, afi_t afi
, uint8_t type
,
1553 unsigned short instance
)
1555 struct list
*red_list
;
1556 struct bgp_redist
*red
;
1558 red
= bgp_redist_lookup(bgp
, afi
, type
, instance
);
1562 if (!bgp
->redist
[afi
][type
])
1563 bgp
->redist
[afi
][type
] = list_new();
1565 red_list
= bgp
->redist
[afi
][type
];
1566 red
= (struct bgp_redist
*)XCALLOC(MTYPE_BGP_REDIST
,
1567 sizeof(struct bgp_redist
));
1568 red
->instance
= instance
;
1570 listnode_add(red_list
, red
);
1575 static void bgp_redist_del(struct bgp
*bgp
, afi_t afi
, uint8_t type
,
1576 unsigned short instance
)
1578 struct bgp_redist
*red
;
1580 red
= bgp_redist_lookup(bgp
, afi
, type
, instance
);
1583 listnode_delete(bgp
->redist
[afi
][type
], red
);
1584 XFREE(MTYPE_BGP_REDIST
, red
);
1585 if (!bgp
->redist
[afi
][type
]->count
)
1586 list_delete(&bgp
->redist
[afi
][type
]);
1590 /* Other routes redistribution into BGP. */
1591 int bgp_redistribute_set(struct bgp
*bgp
, afi_t afi
, int type
,
1592 unsigned short instance
, bool changed
)
1594 /* If redistribute options are changed call
1595 * bgp_redistribute_unreg() to reset the option and withdraw
1599 bgp_redistribute_unreg(bgp
, afi
, type
, instance
);
1601 /* Return if already redistribute flag is set. */
1603 if (redist_check_instance(&zclient
->mi_redist
[afi
][type
],
1607 redist_add_instance(&zclient
->mi_redist
[afi
][type
], instance
);
1609 if (vrf_bitmap_check(zclient
->redist
[afi
][type
], bgp
->vrf_id
))
1613 if (bgp
->vrf_id
== VRF_DEFAULT
1614 && type
== ZEBRA_ROUTE_VNC_DIRECT
) {
1615 vnc_export_bgp_enable(
1616 bgp
, afi
); /* only enables if mode bits cfg'd */
1620 vrf_bitmap_set(zclient
->redist
[afi
][type
], bgp
->vrf_id
);
1624 * Don't try to register if we're not connected to Zebra or Zebra
1625 * doesn't know of this instance.
1627 * When we come up later well resend if needed.
1629 if (!bgp_install_info_to_zebra(bgp
))
1632 if (BGP_DEBUG(zebra
, ZEBRA
))
1633 zlog_debug("Tx redistribute add VRF %u afi %d %s %d",
1634 bgp
->vrf_id
, afi
, zebra_route_string(type
),
1637 /* Send distribute add message to zebra. */
1638 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD
, zclient
, afi
, type
,
1639 instance
, bgp
->vrf_id
);
1644 int bgp_redistribute_resend(struct bgp
*bgp
, afi_t afi
, int type
,
1645 unsigned short instance
)
1647 /* Don't try to send if we're not connected to Zebra or Zebra doesn't
1648 * know of this instance.
1650 if (!bgp_install_info_to_zebra(bgp
))
1653 if (BGP_DEBUG(zebra
, ZEBRA
))
1654 zlog_debug("Tx redistribute del/add VRF %u afi %d %s %d",
1655 bgp
->vrf_id
, afi
, zebra_route_string(type
),
1658 /* Send distribute add message to zebra. */
1659 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE
, zclient
, afi
, type
,
1660 instance
, bgp
->vrf_id
);
1661 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD
, zclient
, afi
, type
,
1662 instance
, bgp
->vrf_id
);
1667 /* Redistribute with route-map specification. */
1668 int bgp_redistribute_rmap_set(struct bgp_redist
*red
, const char *name
,
1669 struct route_map
*route_map
)
1671 if (red
->rmap
.name
&& (strcmp(red
->rmap
.name
, name
) == 0))
1675 XFREE(MTYPE_ROUTE_MAP_NAME
, red
->rmap
.name
);
1676 red
->rmap
.name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, name
);
1677 red
->rmap
.map
= route_map
;
1682 /* Redistribute with metric specification. */
1683 int bgp_redistribute_metric_set(struct bgp
*bgp
, struct bgp_redist
*red
,
1684 afi_t afi
, int type
, uint32_t metric
)
1686 struct bgp_node
*rn
;
1687 struct bgp_path_info
*pi
;
1689 if (red
->redist_metric_flag
&& red
->redist_metric
== metric
)
1692 red
->redist_metric_flag
= 1;
1693 red
->redist_metric
= metric
;
1695 for (rn
= bgp_table_top(bgp
->rib
[afi
][SAFI_UNICAST
]); rn
;
1696 rn
= bgp_route_next(rn
)) {
1697 for (pi
= bgp_node_get_bgp_path_info(rn
); pi
; pi
= pi
->next
) {
1698 if (pi
->sub_type
== BGP_ROUTE_REDISTRIBUTE
1700 && pi
->instance
== red
->instance
) {
1701 struct attr
*old_attr
;
1702 struct attr new_attr
;
1704 bgp_attr_dup(&new_attr
, pi
->attr
);
1705 new_attr
.med
= red
->redist_metric
;
1706 old_attr
= pi
->attr
;
1707 pi
->attr
= bgp_attr_intern(&new_attr
);
1708 bgp_attr_unintern(&old_attr
);
1710 bgp_path_info_set_flag(rn
, pi
,
1711 BGP_PATH_ATTR_CHANGED
);
1712 bgp_process(bgp
, rn
, afi
, SAFI_UNICAST
);
1720 /* Unset redistribution. */
1721 int bgp_redistribute_unreg(struct bgp
*bgp
, afi_t afi
, int type
,
1722 unsigned short instance
)
1724 struct bgp_redist
*red
;
1726 red
= bgp_redist_lookup(bgp
, afi
, type
, instance
);
1730 /* Return if zebra connection is disabled. */
1732 if (!redist_check_instance(&zclient
->mi_redist
[afi
][type
],
1735 redist_del_instance(&zclient
->mi_redist
[afi
][type
], instance
);
1737 if (!vrf_bitmap_check(zclient
->redist
[afi
][type
], bgp
->vrf_id
))
1739 vrf_bitmap_unset(zclient
->redist
[afi
][type
], bgp
->vrf_id
);
1743 if (bgp_install_info_to_zebra(bgp
)) {
1744 /* Send distribute delete message to zebra. */
1745 if (BGP_DEBUG(zebra
, ZEBRA
))
1746 zlog_debug("Tx redistribute del VRF %u afi %d %s %d",
1747 bgp
->vrf_id
, afi
, zebra_route_string(type
),
1749 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE
, zclient
, afi
,
1750 type
, instance
, bgp
->vrf_id
);
1753 /* Withdraw redistributed routes from current BGP's routing table. */
1754 bgp_redistribute_withdraw(bgp
, afi
, type
, instance
);
1759 /* Unset redistribution. */
1760 int bgp_redistribute_unset(struct bgp
*bgp
, afi_t afi
, int type
,
1761 unsigned short instance
)
1763 struct bgp_redist
*red
;
1766 * vnc and vpn->vrf checks must be before red check because
1767 * they operate within bgpd irrespective of zebra connection
1768 * status. red lookup fails if there is no zebra connection.
1771 if (bgp
->vrf_id
== VRF_DEFAULT
&& type
== ZEBRA_ROUTE_VNC_DIRECT
) {
1772 vnc_export_bgp_disable(bgp
, afi
);
1776 red
= bgp_redist_lookup(bgp
, afi
, type
, instance
);
1780 bgp_redistribute_unreg(bgp
, afi
, type
, instance
);
1782 /* Unset route-map. */
1784 XFREE(MTYPE_ROUTE_MAP_NAME
, red
->rmap
.name
);
1785 red
->rmap
.name
= NULL
;
1786 red
->rmap
.map
= NULL
;
1789 red
->redist_metric_flag
= 0;
1790 red
->redist_metric
= 0;
1792 bgp_redist_del(bgp
, afi
, type
, instance
);
1797 /* Update redistribute vrf bitmap during triggers like
1798 restart networking or delete/add VRFs */
1799 void bgp_update_redist_vrf_bitmaps(struct bgp
*bgp
, vrf_id_t old_vrf_id
)
1804 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
1805 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
1806 if ((old_vrf_id
== VRF_UNKNOWN
)
1807 || vrf_bitmap_check(zclient
->redist
[afi
][i
],
1809 vrf_bitmap_unset(zclient
->redist
[afi
][i
],
1811 vrf_bitmap_set(zclient
->redist
[afi
][i
],
1817 void bgp_zclient_reset(void)
1819 zclient_reset(zclient
);
1822 /* Register this instance with Zebra. Invoked upon connect (for
1823 * default instance) and when other VRFs are learnt (or created and
1826 void bgp_zebra_instance_register(struct bgp
*bgp
)
1828 /* Don't try to register if we're not connected to Zebra */
1829 if (!zclient
|| zclient
->sock
< 0)
1832 if (BGP_DEBUG(zebra
, ZEBRA
))
1833 zlog_debug("Registering VRF %u", bgp
->vrf_id
);
1835 /* Register for router-id, interfaces, redistributed routes. */
1836 zclient_send_reg_requests(zclient
, bgp
->vrf_id
);
1838 /* For default instance, register to learn about VNIs, if appropriate.
1840 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
&& is_evpn_enabled())
1841 bgp_zebra_advertise_all_vni(bgp
, 1);
1843 bgp_nht_register_nexthops(bgp
);
1846 /* Deregister this instance with Zebra. Invoked upon the instance
1847 * being deleted (default or VRF) and it is already registered.
1849 void bgp_zebra_instance_deregister(struct bgp
*bgp
)
1851 /* Don't try to deregister if we're not connected to Zebra */
1852 if (zclient
->sock
< 0)
1855 if (BGP_DEBUG(zebra
, ZEBRA
))
1856 zlog_debug("Deregistering VRF %u", bgp
->vrf_id
);
1858 /* For default instance, unregister learning about VNIs, if appropriate.
1860 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
&& is_evpn_enabled())
1861 bgp_zebra_advertise_all_vni(bgp
, 0);
1863 /* Deregister for router-id, interfaces, redistributed routes. */
1864 zclient_send_dereg_requests(zclient
, bgp
->vrf_id
);
1867 void bgp_zebra_initiate_radv(struct bgp
*bgp
, struct peer
*peer
)
1869 int ra_interval
= BGP_UNNUM_DEFAULT_RA_INTERVAL
;
1871 /* Don't try to initiate if we're not connected to Zebra */
1872 if (zclient
->sock
< 0)
1875 if (BGP_DEBUG(zebra
, ZEBRA
))
1876 zlog_debug("%u: Initiating RA for peer %s", bgp
->vrf_id
,
1879 zclient_send_interface_radv_req(zclient
, bgp
->vrf_id
, peer
->ifp
, 1,
1883 void bgp_zebra_terminate_radv(struct bgp
*bgp
, struct peer
*peer
)
1885 /* Don't try to terminate if we're not connected to Zebra */
1886 if (zclient
->sock
< 0)
1889 if (BGP_DEBUG(zebra
, ZEBRA
))
1890 zlog_debug("%u: Terminating RA for peer %s", bgp
->vrf_id
,
1893 zclient_send_interface_radv_req(zclient
, bgp
->vrf_id
, peer
->ifp
, 0, 0);
1896 int bgp_zebra_advertise_subnet(struct bgp
*bgp
, int advertise
, vni_t vni
)
1898 struct stream
*s
= NULL
;
1901 if (!zclient
|| zclient
->sock
< 0)
1904 /* Don't try to register if Zebra doesn't know of this instance. */
1905 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
)) {
1906 if (BGP_DEBUG(zebra
, ZEBRA
))
1907 zlog_debug("%s: No zebra instance to talk to, cannot advertise subnet",
1908 __PRETTY_FUNCTION__
);
1915 zclient_create_header(s
, ZEBRA_ADVERTISE_SUBNET
, bgp
->vrf_id
);
1916 stream_putc(s
, advertise
);
1917 stream_put3(s
, vni
);
1918 stream_putw_at(s
, 0, stream_get_endp(s
));
1920 return zclient_send_message(zclient
);
1923 int bgp_zebra_advertise_gw_macip(struct bgp
*bgp
, int advertise
, vni_t vni
)
1925 struct stream
*s
= NULL
;
1928 if (!zclient
|| zclient
->sock
< 0)
1931 /* Don't try to register if Zebra doesn't know of this instance. */
1932 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
)) {
1933 if (BGP_DEBUG(zebra
, ZEBRA
))
1934 zlog_debug("%s: No zebra instance to talk to, not installing gw_macip",
1935 __PRETTY_FUNCTION__
);
1942 zclient_create_header(s
, ZEBRA_ADVERTISE_DEFAULT_GW
, bgp
->vrf_id
);
1943 stream_putc(s
, advertise
);
1944 stream_putl(s
, vni
);
1945 stream_putw_at(s
, 0, stream_get_endp(s
));
1947 return zclient_send_message(zclient
);
1950 int bgp_zebra_vxlan_flood_control(struct bgp
*bgp
,
1951 enum vxlan_flood_control flood_ctrl
)
1956 if (!zclient
|| zclient
->sock
< 0)
1959 /* Don't try to register if Zebra doesn't know of this instance. */
1960 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
)) {
1961 if (BGP_DEBUG(zebra
, ZEBRA
))
1962 zlog_debug("%s: No zebra instance to talk to, not installing all vni",
1963 __PRETTY_FUNCTION__
);
1970 zclient_create_header(s
, ZEBRA_VXLAN_FLOOD_CONTROL
, bgp
->vrf_id
);
1971 stream_putc(s
, flood_ctrl
);
1972 stream_putw_at(s
, 0, stream_get_endp(s
));
1974 return zclient_send_message(zclient
);
1977 int bgp_zebra_advertise_all_vni(struct bgp
*bgp
, int advertise
)
1982 if (!zclient
|| zclient
->sock
< 0)
1985 /* Don't try to register if Zebra doesn't know of this instance. */
1986 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
))
1992 zclient_create_header(s
, ZEBRA_ADVERTISE_ALL_VNI
, bgp
->vrf_id
);
1993 stream_putc(s
, advertise
);
1994 /* Also inform current BUM handling setting. This is really
1995 * relevant only when 'advertise' is set.
1997 stream_putc(s
, bgp
->vxlan_flood_ctrl
);
1998 stream_putw_at(s
, 0, stream_get_endp(s
));
2000 return zclient_send_message(zclient
);
2003 int bgp_zebra_dup_addr_detection(struct bgp
*bgp
)
2008 if (!zclient
|| zclient
->sock
< 0)
2011 /* Don't try to register if Zebra doesn't know of this instance. */
2012 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
))
2015 if (BGP_DEBUG(zebra
, ZEBRA
))
2016 zlog_debug("dup addr detect %s max_moves %u time %u freeze %s freeze_time %u",
2017 bgp
->evpn_info
->dup_addr_detect
?
2018 "enable" : "disable",
2019 bgp
->evpn_info
->dad_max_moves
,
2020 bgp
->evpn_info
->dad_time
,
2021 bgp
->evpn_info
->dad_freeze
?
2022 "enable" : "disable",
2023 bgp
->evpn_info
->dad_freeze_time
);
2027 zclient_create_header(s
, ZEBRA_DUPLICATE_ADDR_DETECTION
,
2029 stream_putl(s
, bgp
->evpn_info
->dup_addr_detect
);
2030 stream_putl(s
, bgp
->evpn_info
->dad_time
);
2031 stream_putl(s
, bgp
->evpn_info
->dad_max_moves
);
2032 stream_putl(s
, bgp
->evpn_info
->dad_freeze
);
2033 stream_putl(s
, bgp
->evpn_info
->dad_freeze_time
);
2034 stream_putw_at(s
, 0, stream_get_endp(s
));
2036 return zclient_send_message(zclient
);
2039 static int rule_notify_owner(int command
, struct zclient
*zclient
,
2040 zebra_size_t length
, vrf_id_t vrf_id
)
2042 uint32_t seqno
, priority
, unique
;
2043 enum zapi_rule_notify_owner note
;
2044 struct bgp_pbr_action
*bgp_pbra
;
2047 if (!zapi_rule_notify_decode(zclient
->ibuf
, &seqno
, &priority
, &unique
,
2051 bgp_pbra
= bgp_pbr_action_rule_lookup(vrf_id
, unique
);
2053 if (BGP_DEBUG(zebra
, ZEBRA
))
2054 zlog_debug("%s: Fail to look BGP rule (%u)",
2055 __PRETTY_FUNCTION__
, unique
);
2060 case ZAPI_RULE_FAIL_INSTALL
:
2061 if (BGP_DEBUG(zebra
, ZEBRA
))
2062 zlog_debug("%s: Received RULE_FAIL_INSTALL",
2063 __PRETTY_FUNCTION__
);
2064 bgp_pbra
->installed
= false;
2065 bgp_pbra
->install_in_progress
= false;
2067 case ZAPI_RULE_INSTALLED
:
2068 bgp_pbra
->installed
= true;
2069 bgp_pbra
->install_in_progress
= false;
2070 if (BGP_DEBUG(zebra
, ZEBRA
))
2071 zlog_debug("%s: Received RULE_INSTALLED",
2072 __PRETTY_FUNCTION__
);
2074 case ZAPI_RULE_FAIL_REMOVE
:
2075 case ZAPI_RULE_REMOVED
:
2076 if (BGP_DEBUG(zebra
, ZEBRA
))
2077 zlog_debug("%s: Received RULE REMOVED",
2078 __PRETTY_FUNCTION__
);
2085 static int ipset_notify_owner(int command
, struct zclient
*zclient
,
2086 zebra_size_t length
, vrf_id_t vrf_id
)
2089 enum zapi_ipset_notify_owner note
;
2090 struct bgp_pbr_match
*bgp_pbim
;
2092 if (!zapi_ipset_notify_decode(zclient
->ibuf
,
2097 bgp_pbim
= bgp_pbr_match_ipset_lookup(vrf_id
, unique
);
2099 if (BGP_DEBUG(zebra
, ZEBRA
))
2100 zlog_debug("%s: Fail to look BGP match ( %u, ID %u)",
2101 __PRETTY_FUNCTION__
, note
, unique
);
2106 case ZAPI_IPSET_FAIL_INSTALL
:
2107 if (BGP_DEBUG(zebra
, ZEBRA
))
2108 zlog_debug("%s: Received IPSET_FAIL_INSTALL",
2109 __PRETTY_FUNCTION__
);
2110 bgp_pbim
->installed
= false;
2111 bgp_pbim
->install_in_progress
= false;
2113 case ZAPI_IPSET_INSTALLED
:
2114 bgp_pbim
->installed
= true;
2115 bgp_pbim
->install_in_progress
= false;
2116 if (BGP_DEBUG(zebra
, ZEBRA
))
2117 zlog_debug("%s: Received IPSET_INSTALLED",
2118 __PRETTY_FUNCTION__
);
2120 case ZAPI_IPSET_FAIL_REMOVE
:
2121 case ZAPI_IPSET_REMOVED
:
2122 if (BGP_DEBUG(zebra
, ZEBRA
))
2123 zlog_debug("%s: Received IPSET REMOVED",
2124 __PRETTY_FUNCTION__
);
2131 static int ipset_entry_notify_owner(int command
, struct zclient
*zclient
,
2132 zebra_size_t length
, vrf_id_t vrf_id
)
2135 char ipset_name
[ZEBRA_IPSET_NAME_SIZE
];
2136 enum zapi_ipset_entry_notify_owner note
;
2137 struct bgp_pbr_match_entry
*bgp_pbime
;
2139 if (!zapi_ipset_entry_notify_decode(
2145 bgp_pbime
= bgp_pbr_match_ipset_entry_lookup(vrf_id
,
2149 if (BGP_DEBUG(zebra
, ZEBRA
))
2150 zlog_debug("%s: Fail to look BGP match entry (%u, ID %u)",
2151 __PRETTY_FUNCTION__
, note
, unique
);
2156 case ZAPI_IPSET_ENTRY_FAIL_INSTALL
:
2157 if (BGP_DEBUG(zebra
, ZEBRA
))
2158 zlog_debug("%s: Received IPSET_ENTRY_FAIL_INSTALL",
2159 __PRETTY_FUNCTION__
);
2160 bgp_pbime
->installed
= false;
2161 bgp_pbime
->install_in_progress
= false;
2163 case ZAPI_IPSET_ENTRY_INSTALLED
:
2165 struct bgp_path_info
*path
;
2166 struct bgp_path_info_extra
*extra
;
2168 bgp_pbime
->installed
= true;
2169 bgp_pbime
->install_in_progress
= false;
2170 if (BGP_DEBUG(zebra
, ZEBRA
))
2171 zlog_debug("%s: Received IPSET_ENTRY_INSTALLED",
2172 __PRETTY_FUNCTION__
);
2173 /* link bgp_path_info to bpme */
2174 path
= (struct bgp_path_info
*)bgp_pbime
->path
;
2175 extra
= bgp_path_info_extra_get(path
);
2176 if (extra
->bgp_fs_pbr
== NULL
)
2177 extra
->bgp_fs_pbr
= list_new();
2178 listnode_add(extra
->bgp_fs_pbr
, bgp_pbime
);
2181 case ZAPI_IPSET_ENTRY_FAIL_REMOVE
:
2182 case ZAPI_IPSET_ENTRY_REMOVED
:
2183 if (BGP_DEBUG(zebra
, ZEBRA
))
2184 zlog_debug("%s: Received IPSET_ENTRY_REMOVED",
2185 __PRETTY_FUNCTION__
);
2191 static int iptable_notify_owner(int command
, struct zclient
*zclient
,
2192 zebra_size_t length
, vrf_id_t vrf_id
)
2195 enum zapi_iptable_notify_owner note
;
2196 struct bgp_pbr_match
*bgpm
;
2198 if (!zapi_iptable_notify_decode(
2203 bgpm
= bgp_pbr_match_iptable_lookup(vrf_id
, unique
);
2205 if (BGP_DEBUG(zebra
, ZEBRA
))
2206 zlog_debug("%s: Fail to look BGP iptable (%u %u)",
2207 __PRETTY_FUNCTION__
, note
, unique
);
2211 case ZAPI_IPTABLE_FAIL_INSTALL
:
2212 if (BGP_DEBUG(zebra
, ZEBRA
))
2213 zlog_debug("%s: Received IPTABLE_FAIL_INSTALL",
2214 __PRETTY_FUNCTION__
);
2215 bgpm
->installed_in_iptable
= false;
2216 bgpm
->install_iptable_in_progress
= false;
2218 case ZAPI_IPTABLE_INSTALLED
:
2219 bgpm
->installed_in_iptable
= true;
2220 bgpm
->install_iptable_in_progress
= false;
2221 if (BGP_DEBUG(zebra
, ZEBRA
))
2222 zlog_debug("%s: Received IPTABLE_INSTALLED",
2223 __PRETTY_FUNCTION__
);
2224 bgpm
->action
->refcnt
++;
2226 case ZAPI_IPTABLE_FAIL_REMOVE
:
2227 case ZAPI_IPTABLE_REMOVED
:
2228 if (BGP_DEBUG(zebra
, ZEBRA
))
2229 zlog_debug("%s: Received IPTABLE REMOVED",
2230 __PRETTY_FUNCTION__
);
2236 static void bgp_encode_pbr_rule_action(struct stream
*s
,
2237 struct bgp_pbr_action
*pbra
)
2241 stream_putl(s
, 0); /* seqno unused */
2242 stream_putl(s
, 0); /* ruleno unused */
2244 stream_putl(s
, pbra
->unique
);
2246 memset(&any
, 0, sizeof(any
));
2247 any
.family
= AF_INET
;
2248 stream_putc(s
, any
.family
);
2249 stream_putc(s
, any
.prefixlen
);
2250 stream_put(s
, &any
.u
.prefix
, prefix_blen(&any
));
2252 stream_putw(s
, 0); /* src port */
2254 stream_putc(s
, any
.family
);
2255 stream_putc(s
, any
.prefixlen
);
2256 stream_put(s
, &any
.u
.prefix
, prefix_blen(&any
));
2258 stream_putw(s
, 0); /* dst port */
2260 stream_putl(s
, pbra
->fwmark
); /* fwmark */
2262 stream_putl(s
, pbra
->table_id
);
2264 stream_putl(s
, 0); /* ifindex unused */
2267 static void bgp_encode_pbr_ipset_match(struct stream
*s
,
2268 struct bgp_pbr_match
*pbim
)
2270 stream_putl(s
, pbim
->unique
);
2271 stream_putl(s
, pbim
->type
);
2273 stream_put(s
, pbim
->ipset_name
,
2274 ZEBRA_IPSET_NAME_SIZE
);
2277 static void bgp_encode_pbr_ipset_entry_match(struct stream
*s
,
2278 struct bgp_pbr_match_entry
*pbime
)
2280 stream_putl(s
, pbime
->unique
);
2281 /* check that back pointer is not null */
2282 stream_put(s
, pbime
->backpointer
->ipset_name
,
2283 ZEBRA_IPSET_NAME_SIZE
);
2285 stream_putc(s
, pbime
->src
.family
);
2286 stream_putc(s
, pbime
->src
.prefixlen
);
2287 stream_put(s
, &pbime
->src
.u
.prefix
, prefix_blen(&pbime
->src
));
2289 stream_putc(s
, pbime
->dst
.family
);
2290 stream_putc(s
, pbime
->dst
.prefixlen
);
2291 stream_put(s
, &pbime
->dst
.u
.prefix
, prefix_blen(&pbime
->dst
));
2293 stream_putw(s
, pbime
->src_port_min
);
2294 stream_putw(s
, pbime
->src_port_max
);
2295 stream_putw(s
, pbime
->dst_port_min
);
2296 stream_putw(s
, pbime
->dst_port_max
);
2297 stream_putc(s
, pbime
->proto
);
2300 static void bgp_encode_pbr_iptable_match(struct stream
*s
,
2301 struct bgp_pbr_action
*bpa
,
2302 struct bgp_pbr_match
*pbm
)
2304 stream_putl(s
, pbm
->unique2
);
2306 stream_putl(s
, pbm
->type
);
2308 stream_putl(s
, pbm
->flags
);
2310 /* TODO: correlate with what is contained
2311 * into bgp_pbr_action.
2312 * currently only forward supported
2314 if (bpa
->nh
.type
== NEXTHOP_TYPE_BLACKHOLE
)
2315 stream_putl(s
, ZEBRA_IPTABLES_DROP
);
2317 stream_putl(s
, ZEBRA_IPTABLES_FORWARD
);
2318 stream_putl(s
, bpa
->fwmark
);
2319 stream_put(s
, pbm
->ipset_name
,
2320 ZEBRA_IPSET_NAME_SIZE
);
2321 stream_putw(s
, pbm
->pkt_len_min
);
2322 stream_putw(s
, pbm
->pkt_len_max
);
2323 stream_putw(s
, pbm
->tcp_flags
);
2324 stream_putw(s
, pbm
->tcp_mask_flags
);
2325 stream_putc(s
, pbm
->dscp_value
);
2326 stream_putc(s
, pbm
->fragment
);
2329 /* BGP has established connection with Zebra. */
2330 static void bgp_zebra_connected(struct zclient
*zclient
)
2334 zclient_num_connects
++; /* increment even if not responding */
2336 /* At this point, we may or may not have BGP instances configured, but
2337 * we're only interested in the default VRF (others wouldn't have learnt
2338 * the VRF from Zebra yet.)
2340 bgp
= bgp_get_default();
2344 bgp_zebra_instance_register(bgp
);
2346 /* Send the client registration */
2347 bfd_client_sendmsg(zclient
, ZEBRA_BFD_CLIENT_REGISTER
);
2349 /* tell label pool that zebra is connected */
2350 bgp_lp_event_zebra_up();
2352 /* TODO - What if we have peers and networks configured, do we have to
2357 static int bgp_zebra_process_local_es(int cmd
, struct zclient
*zclient
,
2358 zebra_size_t length
, vrf_id_t vrf_id
)
2361 struct bgp
*bgp
= NULL
;
2362 struct stream
*s
= NULL
;
2363 char buf
[ESI_STR_LEN
];
2364 char buf1
[INET6_ADDRSTRLEN
];
2365 struct ipaddr originator_ip
;
2367 memset(&esi
, 0, sizeof(esi_t
));
2368 memset(&originator_ip
, 0, sizeof(struct ipaddr
));
2370 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
2375 stream_get(&esi
, s
, sizeof(esi_t
));
2376 stream_get(&originator_ip
, s
, sizeof(struct ipaddr
));
2378 if (BGP_DEBUG(zebra
, ZEBRA
))
2379 zlog_debug("Rx %s ESI %s originator-ip %s",
2380 (cmd
== ZEBRA_LOCAL_ES_ADD
) ? "add" : "del",
2381 esi_to_str(&esi
, buf
, sizeof(buf
)),
2382 ipaddr2str(&originator_ip
, buf1
, sizeof(buf1
)));
2384 if (cmd
== ZEBRA_LOCAL_ES_ADD
)
2385 bgp_evpn_local_es_add(bgp
, &esi
, &originator_ip
);
2387 bgp_evpn_local_es_del(bgp
, &esi
, &originator_ip
);
2391 static int bgp_zebra_process_local_l3vni(int cmd
, struct zclient
*zclient
,
2392 zebra_size_t length
, vrf_id_t vrf_id
)
2395 char buf
[ETHER_ADDR_STRLEN
];
2397 struct ethaddr rmac
;
2398 struct in_addr originator_ip
;
2401 memset(&rmac
, 0, sizeof(struct ethaddr
));
2402 memset(&originator_ip
, 0, sizeof(struct in_addr
));
2404 l3vni
= stream_getl(s
);
2405 if (cmd
== ZEBRA_L3VNI_ADD
) {
2406 stream_get(&rmac
, s
, sizeof(struct ethaddr
));
2407 originator_ip
.s_addr
= stream_get_ipv4(s
);
2408 stream_get(&filter
, s
, sizeof(int));
2411 if (BGP_DEBUG(zebra
, ZEBRA
))
2412 zlog_debug("Rx L3-VNI %s VRF %s VNI %u RMAC %s filter %s",
2413 (cmd
== ZEBRA_L3VNI_ADD
) ? "add" : "del",
2414 vrf_id_to_name(vrf_id
), l3vni
,
2415 prefix_mac2str(&rmac
, buf
, sizeof(buf
)),
2416 filter
? "prefix-routes-only" : "none");
2418 if (cmd
== ZEBRA_L3VNI_ADD
)
2419 bgp_evpn_local_l3vni_add(l3vni
, vrf_id
, &rmac
, originator_ip
,
2422 bgp_evpn_local_l3vni_del(l3vni
, vrf_id
);
2427 static int bgp_zebra_process_local_vni(int command
, struct zclient
*zclient
,
2428 zebra_size_t length
, vrf_id_t vrf_id
)
2433 struct in_addr vtep_ip
= {INADDR_ANY
};
2434 vrf_id_t tenant_vrf_id
= VRF_DEFAULT
;
2437 vni
= stream_getl(s
);
2438 if (command
== ZEBRA_VNI_ADD
) {
2439 vtep_ip
.s_addr
= stream_get_ipv4(s
);
2440 stream_get(&tenant_vrf_id
, s
, sizeof(vrf_id_t
));
2443 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
2447 if (BGP_DEBUG(zebra
, ZEBRA
))
2448 zlog_debug("Rx VNI %s VRF %s VNI %u tenant-vrf %s",
2449 (command
== ZEBRA_VNI_ADD
) ? "add" : "del",
2450 vrf_id_to_name(vrf_id
), vni
,
2451 vrf_id_to_name(tenant_vrf_id
));
2453 if (command
== ZEBRA_VNI_ADD
)
2454 return bgp_evpn_local_vni_add(
2455 bgp
, vni
, vtep_ip
.s_addr
? vtep_ip
: bgp
->router_id
,
2458 return bgp_evpn_local_vni_del(bgp
, vni
);
2461 static int bgp_zebra_process_local_macip(int command
, struct zclient
*zclient
,
2462 zebra_size_t length
, vrf_id_t vrf_id
)
2470 char buf
[ETHER_ADDR_STRLEN
];
2471 char buf1
[INET6_ADDRSTRLEN
];
2473 uint32_t seqnum
= 0;
2475 memset(&ip
, 0, sizeof(ip
));
2477 vni
= stream_getl(s
);
2478 stream_get(&mac
.octet
, s
, ETH_ALEN
);
2479 ipa_len
= stream_getl(s
);
2480 if (ipa_len
!= 0 && ipa_len
!= IPV4_MAX_BYTELEN
2481 && ipa_len
!= IPV6_MAX_BYTELEN
) {
2482 flog_err(EC_BGP_MACIP_LEN
,
2483 "%u:Recv MACIP %s with invalid IP addr length %d",
2484 vrf_id
, (command
== ZEBRA_MACIP_ADD
) ? "Add" : "Del",
2491 (ipa_len
== IPV4_MAX_BYTELEN
) ? IPADDR_V4
: IPADDR_V6
;
2492 stream_get(&ip
.ip
.addr
, s
, ipa_len
);
2494 if (command
== ZEBRA_MACIP_ADD
) {
2495 flags
= stream_getc(s
);
2496 seqnum
= stream_getl(s
);
2499 bgp
= bgp_lookup_by_vrf_id(vrf_id
);
2503 if (BGP_DEBUG(zebra
, ZEBRA
))
2504 zlog_debug("%u:Recv MACIP %s flags 0x%x MAC %s IP %s VNI %u seq %u",
2505 vrf_id
, (command
== ZEBRA_MACIP_ADD
) ? "Add" : "Del",
2506 flags
, prefix_mac2str(&mac
, buf
, sizeof(buf
)),
2507 ipaddr2str(&ip
, buf1
, sizeof(buf1
)), vni
, seqnum
);
2509 if (command
== ZEBRA_MACIP_ADD
)
2510 return bgp_evpn_local_macip_add(bgp
, vni
, &mac
, &ip
,
2513 return bgp_evpn_local_macip_del(bgp
, vni
, &mac
, &ip
);
2516 static void bgp_zebra_process_local_ip_prefix(int cmd
, struct zclient
*zclient
,
2517 zebra_size_t length
,
2520 struct stream
*s
= NULL
;
2521 struct bgp
*bgp_vrf
= NULL
;
2523 char buf
[PREFIX_STRLEN
];
2525 memset(&p
, 0, sizeof(struct prefix
));
2527 stream_get(&p
, s
, sizeof(struct prefix
));
2529 bgp_vrf
= bgp_lookup_by_vrf_id(vrf_id
);
2533 if (BGP_DEBUG(zebra
, ZEBRA
))
2534 zlog_debug("Recv prefix %s %s on vrf %s",
2535 prefix2str(&p
, buf
, sizeof(buf
)),
2536 (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
) ? "ADD" : "DEL",
2537 vrf_id_to_name(vrf_id
));
2539 if (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
) {
2541 if (p
.family
== AF_INET
)
2542 bgp_evpn_advertise_type5_route(bgp_vrf
, &p
, NULL
,
2543 AFI_IP
, SAFI_UNICAST
);
2545 bgp_evpn_advertise_type5_route(bgp_vrf
, &p
, NULL
,
2546 AFI_IP6
, SAFI_UNICAST
);
2549 if (p
.family
== AF_INET
)
2550 bgp_evpn_withdraw_type5_route(bgp_vrf
, &p
, AFI_IP
,
2553 bgp_evpn_withdraw_type5_route(bgp_vrf
, &p
, AFI_IP6
,
2558 static void bgp_zebra_process_label_chunk(
2560 struct zclient
*zclient
,
2561 zebra_size_t length
,
2564 struct stream
*s
= NULL
;
2565 uint8_t response_keep
;
2569 unsigned short instance
;
2572 STREAM_GETC(s
, proto
);
2573 STREAM_GETW(s
, instance
);
2574 STREAM_GETC(s
, response_keep
);
2575 STREAM_GETL(s
, first
);
2576 STREAM_GETL(s
, last
);
2578 if (zclient
->redist_default
!= proto
) {
2579 flog_err(EC_BGP_LM_ERROR
, "Got LM msg with wrong proto %u",
2583 if (zclient
->instance
!= instance
) {
2584 flog_err(EC_BGP_LM_ERROR
, "Got LM msg with wrong instance %u",
2590 first
< MPLS_LABEL_UNRESERVED_MIN
||
2591 last
> MPLS_LABEL_UNRESERVED_MAX
) {
2593 flog_err(EC_BGP_LM_ERROR
, "%s: Invalid Label chunk: %u - %u",
2594 __func__
, first
, last
);
2597 if (BGP_DEBUG(zebra
, ZEBRA
)) {
2598 zlog_debug("Label Chunk assign: %u - %u (%u) ",
2599 first
, last
, response_keep
);
2602 bgp_lp_event_chunk(response_keep
, first
, last
);
2604 stream_failure
: /* for STREAM_GETX */
2608 extern struct zebra_privs_t bgpd_privs
;
2610 void bgp_zebra_init(struct thread_master
*master
, unsigned short instance
)
2612 zclient_num_connects
= 0;
2614 /* Set default values. */
2615 zclient
= zclient_new(master
, &zclient_options_default
);
2616 zclient_init(zclient
, ZEBRA_ROUTE_BGP
, 0, &bgpd_privs
);
2617 zclient
->zebra_connected
= bgp_zebra_connected
;
2618 zclient
->router_id_update
= bgp_router_id_update
;
2619 zclient
->interface_add
= bgp_interface_add
;
2620 zclient
->interface_delete
= bgp_interface_delete
;
2621 zclient
->interface_address_add
= bgp_interface_address_add
;
2622 zclient
->interface_address_delete
= bgp_interface_address_delete
;
2623 zclient
->interface_nbr_address_add
= bgp_interface_nbr_address_add
;
2624 zclient
->interface_nbr_address_delete
=
2625 bgp_interface_nbr_address_delete
;
2626 zclient
->interface_vrf_update
= bgp_interface_vrf_update
;
2627 zclient
->redistribute_route_add
= zebra_read_route
;
2628 zclient
->redistribute_route_del
= zebra_read_route
;
2629 zclient
->interface_up
= bgp_interface_up
;
2630 zclient
->interface_down
= bgp_interface_down
;
2631 zclient
->nexthop_update
= bgp_read_nexthop_update
;
2632 zclient
->import_check_update
= bgp_read_import_check_update
;
2633 zclient
->fec_update
= bgp_read_fec_update
;
2634 zclient
->local_es_add
= bgp_zebra_process_local_es
;
2635 zclient
->local_es_del
= bgp_zebra_process_local_es
;
2636 zclient
->local_vni_add
= bgp_zebra_process_local_vni
;
2637 zclient
->local_vni_del
= bgp_zebra_process_local_vni
;
2638 zclient
->local_macip_add
= bgp_zebra_process_local_macip
;
2639 zclient
->local_macip_del
= bgp_zebra_process_local_macip
;
2640 zclient
->local_l3vni_add
= bgp_zebra_process_local_l3vni
;
2641 zclient
->local_l3vni_del
= bgp_zebra_process_local_l3vni
;
2642 zclient
->local_ip_prefix_add
= bgp_zebra_process_local_ip_prefix
;
2643 zclient
->local_ip_prefix_del
= bgp_zebra_process_local_ip_prefix
;
2644 zclient
->label_chunk
= bgp_zebra_process_label_chunk
;
2645 zclient
->rule_notify_owner
= rule_notify_owner
;
2646 zclient
->ipset_notify_owner
= ipset_notify_owner
;
2647 zclient
->ipset_entry_notify_owner
= ipset_entry_notify_owner
;
2648 zclient
->iptable_notify_owner
= iptable_notify_owner
;
2649 zclient
->instance
= instance
;
2652 void bgp_zebra_destroy(void)
2654 if (zclient
== NULL
)
2656 zclient_stop(zclient
);
2657 zclient_free(zclient
);
2661 int bgp_zebra_num_connects(void)
2663 return zclient_num_connects
;
2666 void bgp_send_pbr_rule_action(struct bgp_pbr_action
*pbra
, bool install
)
2670 if (pbra
->install_in_progress
)
2672 if (BGP_DEBUG(zebra
, ZEBRA
))
2673 zlog_debug("%s: table %d fwmark %d %d",
2674 __PRETTY_FUNCTION__
,
2675 pbra
->table_id
, pbra
->fwmark
, install
);
2679 zclient_create_header(s
,
2680 install
? ZEBRA_RULE_ADD
: ZEBRA_RULE_DELETE
,
2682 stream_putl(s
, 1); /* send one pbr action */
2684 bgp_encode_pbr_rule_action(s
, pbra
);
2686 stream_putw_at(s
, 0, stream_get_endp(s
));
2687 if (!zclient_send_message(zclient
) && install
)
2688 pbra
->install_in_progress
= true;
2691 void bgp_send_pbr_ipset_match(struct bgp_pbr_match
*pbrim
, bool install
)
2695 if (pbrim
->install_in_progress
)
2697 if (BGP_DEBUG(zebra
, ZEBRA
))
2698 zlog_debug("%s: name %s type %d %d, ID %u",
2699 __PRETTY_FUNCTION__
,
2700 pbrim
->ipset_name
, pbrim
->type
,
2701 install
, pbrim
->unique
);
2705 zclient_create_header(s
,
2706 install
? ZEBRA_IPSET_CREATE
:
2707 ZEBRA_IPSET_DESTROY
,
2710 stream_putl(s
, 1); /* send one pbr action */
2712 bgp_encode_pbr_ipset_match(s
, pbrim
);
2714 stream_putw_at(s
, 0, stream_get_endp(s
));
2715 if (!zclient_send_message(zclient
) && install
)
2716 pbrim
->install_in_progress
= true;
2719 void bgp_send_pbr_ipset_entry_match(struct bgp_pbr_match_entry
*pbrime
,
2724 if (pbrime
->install_in_progress
)
2726 if (BGP_DEBUG(zebra
, ZEBRA
))
2727 zlog_debug("%s: name %s %d %d, ID %u", __PRETTY_FUNCTION__
,
2728 pbrime
->backpointer
->ipset_name
,
2729 pbrime
->unique
, install
, pbrime
->unique
);
2733 zclient_create_header(s
,
2734 install
? ZEBRA_IPSET_ENTRY_ADD
:
2735 ZEBRA_IPSET_ENTRY_DELETE
,
2738 stream_putl(s
, 1); /* send one pbr action */
2740 bgp_encode_pbr_ipset_entry_match(s
, pbrime
);
2742 stream_putw_at(s
, 0, stream_get_endp(s
));
2743 if (!zclient_send_message(zclient
) && install
)
2744 pbrime
->install_in_progress
= true;
2747 static void bgp_encode_pbr_interface_list(struct bgp
*bgp
, struct stream
*s
)
2749 struct bgp_pbr_config
*bgp_pbr_cfg
= bgp
->bgp_pbr_cfg
;
2750 struct bgp_pbr_interface_head
*head
;
2751 struct bgp_pbr_interface
*pbr_if
;
2752 struct interface
*ifp
;
2756 head
= &(bgp_pbr_cfg
->ifaces_by_name_ipv4
);
2758 RB_FOREACH (pbr_if
, bgp_pbr_interface_head
, head
) {
2759 ifp
= if_lookup_by_name(pbr_if
->name
, bgp
->vrf_id
);
2761 stream_putl(s
, ifp
->ifindex
);
2765 static int bgp_pbr_get_ifnumber(struct bgp
*bgp
)
2767 struct bgp_pbr_config
*bgp_pbr_cfg
= bgp
->bgp_pbr_cfg
;
2768 struct bgp_pbr_interface_head
*head
;
2769 struct bgp_pbr_interface
*pbr_if
;
2774 head
= &(bgp_pbr_cfg
->ifaces_by_name_ipv4
);
2776 RB_FOREACH (pbr_if
, bgp_pbr_interface_head
, head
) {
2777 if (if_lookup_by_name(pbr_if
->name
, bgp
->vrf_id
))
2783 void bgp_send_pbr_iptable(struct bgp_pbr_action
*pba
,
2784 struct bgp_pbr_match
*pbm
,
2791 if (pbm
->install_iptable_in_progress
)
2793 if (BGP_DEBUG(zebra
, ZEBRA
))
2794 zlog_debug("%s: name %s type %d mark %d %d, ID %u",
2795 __PRETTY_FUNCTION__
, pbm
->ipset_name
,
2796 pbm
->type
, pba
->fwmark
, install
,
2801 zclient_create_header(s
,
2802 install
? ZEBRA_IPTABLE_ADD
:
2803 ZEBRA_IPTABLE_DELETE
,
2806 bgp_encode_pbr_iptable_match(s
, pba
, pbm
);
2807 nb_interface
= bgp_pbr_get_ifnumber(pba
->bgp
);
2808 stream_putl(s
, nb_interface
);
2810 bgp_encode_pbr_interface_list(pba
->bgp
, s
);
2811 stream_putw_at(s
, 0, stream_get_endp(s
));
2812 ret
= zclient_send_message(zclient
);
2817 pbm
->install_iptable_in_progress
= true;
2821 /* inject in table <table_id> a default route to:
2822 * - if nexthop IP is present : to this nexthop
2823 * - if vrf is different from local : to the matching VRF
2825 void bgp_zebra_announce_default(struct bgp
*bgp
, struct nexthop
*nh
,
2826 afi_t afi
, uint32_t table_id
, bool announce
)
2828 struct zapi_nexthop
*api_nh
;
2829 struct zapi_route api
;
2832 if (!nh
|| nh
->type
!= NEXTHOP_TYPE_IPV4
2833 || nh
->vrf_id
== VRF_UNKNOWN
)
2835 memset(&p
, 0, sizeof(struct prefix
));
2840 memset(&api
, 0, sizeof(api
));
2841 api
.vrf_id
= bgp
->vrf_id
;
2842 api
.type
= ZEBRA_ROUTE_BGP
;
2843 api
.safi
= SAFI_UNICAST
;
2845 api
.tableid
= table_id
;
2846 api
.nexthop_num
= 1;
2847 SET_FLAG(api
.message
, ZAPI_MESSAGE_TABLEID
);
2848 SET_FLAG(api
.message
, ZAPI_MESSAGE_NEXTHOP
);
2849 api_nh
= &api
.nexthops
[0];
2852 if (nh
->gate
.ipv4
.s_addr
) {
2853 char buff
[PREFIX_STRLEN
];
2855 api_nh
->vrf_id
= nh
->vrf_id
;
2856 api_nh
->gate
.ipv4
= nh
->gate
.ipv4
;
2857 api_nh
->type
= NEXTHOP_TYPE_IPV4
;
2859 inet_ntop(AF_INET
, &(nh
->gate
.ipv4
), buff
, INET_ADDRSTRLEN
);
2860 if (BGP_DEBUG(zebra
, ZEBRA
))
2861 zlog_info("BGP: %s default route to %s table %d (redirect IP)",
2862 announce
? "adding" : "withdrawing",
2864 zclient_route_send(announce
? ZEBRA_ROUTE_ADD
2865 : ZEBRA_ROUTE_DELETE
,
2867 } else if (nh
->vrf_id
!= bgp
->vrf_id
) {
2869 struct interface
*ifp
;
2871 vrf
= vrf_lookup_by_id(nh
->vrf_id
);
2874 /* create default route with interface <VRF>
2875 * with nexthop-vrf <VRF>
2877 ifp
= if_lookup_by_name_all_vrf(vrf
->name
);
2880 api_nh
->vrf_id
= nh
->vrf_id
;
2881 api_nh
->type
= NEXTHOP_TYPE_IFINDEX
;
2882 api_nh
->ifindex
= ifp
->ifindex
;
2883 if (BGP_DEBUG(zebra
, ZEBRA
))
2884 zlog_info("BGP: %s default route to %s table %d (redirect VRF)",
2885 announce
? "adding" : "withdrawing",
2886 vrf
->name
, table_id
);
2887 zclient_route_send(announce
? ZEBRA_ROUTE_ADD
2888 : ZEBRA_ROUTE_DELETE
,