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"
39 #include "bgpd/bgpd.h"
40 #include "bgpd/bgp_route.h"
41 #include "bgpd/bgp_attr.h"
42 #include "bgpd/bgp_nexthop.h"
43 #include "bgpd/bgp_zebra.h"
44 #include "bgpd/bgp_fsm.h"
45 #include "bgpd/bgp_debug.h"
46 #include "bgpd/bgp_mpath.h"
47 #include "bgpd/bgp_nexthop.h"
48 #include "bgpd/bgp_nht.h"
49 #include "bgpd/bgp_bfd.h"
50 #include "bgpd/bgp_label.h"
52 # include "bgpd/rfapi/rfapi_backend.h"
53 # include "bgpd/rfapi/vnc_export_bgp.h"
56 /* All information about zebra. */
57 struct zclient
*zclient
= NULL
;
59 /* Growable buffer for nexthops sent to zebra */
60 struct stream
*bgp_nexthop_buf
= NULL
;
61 struct stream
*bgp_ifindices_buf
= NULL
;
62 struct stream
*bgp_label_buf
= NULL
;
64 /* These array buffers are used in making a copy of the attributes for
65 route-map apply. Arrays are being used here to minimize mallocs and
66 frees for the temporary copy of the attributes.
67 Given the zapi api expects the nexthop buffer to contain pointer to
68 pointers for nexthops, we couldnt have used a single nexthop variable
69 on the stack, hence we had two options:
70 1. maintain a linked-list and free it after zapi_*_route call
71 2. use an array to avoid number of mallocs.
72 Number of supported next-hops are finite, use of arrays should be ok. */
73 struct attr attr_cp
[MULTIPATH_NUM
];
74 struct attr_extra attr_extra_cp
[MULTIPATH_NUM
];
75 unsigned int attr_index
= 0;
77 /* Once per address-family initialization of the attribute array */
78 #define BGP_INFO_ATTR_BUF_INIT()\
80 memset(attr_cp, 0, MULTIPATH_NUM * sizeof(struct attr));\
81 memset(attr_extra_cp, 0, MULTIPATH_NUM * sizeof(struct attr_extra));\
85 #define BGP_INFO_ATTR_BUF_COPY(info_src, info_dst)\
87 *info_dst = *info_src; \
88 assert(attr_index != multipath_num);\
89 attr_cp[attr_index].extra = &attr_extra_cp[attr_index]; \
90 bgp_attr_dup (&attr_cp[attr_index], info_src->attr); \
91 bgp_attr_deep_dup (&attr_cp[attr_index], info_src->attr); \
92 info_dst->attr = &attr_cp[attr_index]; \
96 #define BGP_INFO_ATTR_BUF_FREE(info) \
98 bgp_attr_deep_free(info->attr); \
102 /* Can we install into zebra? */
104 bgp_install_info_to_zebra (struct bgp
*bgp
)
106 if (zclient
->sock
<= 0)
109 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
))
115 int zclient_num_connects
;
117 /* Router-id update message from zebra. */
119 bgp_router_id_update (int command
, struct zclient
*zclient
, zebra_size_t length
,
122 struct prefix router_id
;
124 zebra_router_id_update_read(zclient
->ibuf
,&router_id
);
126 if (BGP_DEBUG (zebra
, ZEBRA
))
128 char buf
[PREFIX2STR_BUFFER
];
129 prefix2str(&router_id
, buf
, sizeof(buf
));
130 zlog_debug("Rx Router Id update VRF %u Id %s", vrf_id
, buf
);
133 bgp_router_id_zebra_bump (vrf_id
, &router_id
);
137 /* Nexthop update message from zebra. */
139 bgp_read_nexthop_update (int command
, struct zclient
*zclient
,
140 zebra_size_t length
, vrf_id_t vrf_id
)
142 bgp_parse_nexthop_update(command
, vrf_id
);
147 bgp_read_import_check_update(int command
, struct zclient
*zclient
,
148 zebra_size_t length
, vrf_id_t vrf_id
)
150 bgp_parse_nexthop_update(command
, vrf_id
);
154 /* Set or clear interface on which unnumbered neighbor is configured. This
155 * would in turn cause BGP to initiate or turn off IPv6 RAs on this
159 bgp_update_interface_nbrs (struct bgp
*bgp
, struct interface
*ifp
,
160 struct interface
*upd_ifp
)
162 struct listnode
*node
, *nnode
;
165 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
168 (strcmp (peer
->conf_if
, ifp
->name
) == 0))
173 bgp_zebra_initiate_radv (bgp
, peer
);
177 bgp_zebra_terminate_radv (bgp
, peer
);
185 bgp_read_fec_update (int command
, struct zclient
*zclient
,
188 bgp_parse_fec_update();
193 bgp_start_interface_nbrs (struct bgp
*bgp
, struct interface
*ifp
)
195 struct listnode
*node
, *nnode
;
198 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
201 (strcmp (peer
->conf_if
, ifp
->name
) == 0) &&
202 peer
->status
!= Established
)
204 if (peer_active(peer
))
205 BGP_EVENT_ADD (peer
, BGP_Stop
);
206 BGP_EVENT_ADD (peer
, BGP_Start
);
212 bgp_nbr_connected_add (struct bgp
*bgp
, struct nbr_connected
*ifc
)
214 struct listnode
*node
;
215 struct connected
*connected
;
216 struct interface
*ifp
;
219 /* Kick-off the FSM for any relevant peers only if there is a
220 * valid local address on the interface.
223 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, node
, connected
))
225 p
= connected
->address
;
226 if (p
->family
== AF_INET6
&&
227 IN6_IS_ADDR_LINKLOCAL (&p
->u
.prefix6
))
233 bgp_start_interface_nbrs (bgp
, ifp
);
237 bgp_nbr_connected_delete (struct bgp
*bgp
, struct nbr_connected
*ifc
, int del
)
239 struct listnode
*node
, *nnode
;
241 struct interface
*ifp
;
243 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
245 if (peer
->conf_if
&& (strcmp (peer
->conf_if
, ifc
->ifp
->name
) == 0))
247 peer
->last_reset
= PEER_DOWN_NBR_ADDR_DEL
;
248 BGP_EVENT_ADD (peer
, BGP_Stop
);
251 /* Free neighbor also, if we're asked to. */
255 listnode_delete (ifp
->nbr_connected
, ifc
);
256 nbr_connected_free (ifc
);
260 /* Inteface addition message from zebra. */
262 bgp_interface_add (int command
, struct zclient
*zclient
, zebra_size_t length
,
265 struct interface
*ifp
;
268 ifp
= zebra_interface_add_read (zclient
->ibuf
, vrf_id
);
269 if (!ifp
) // unexpected
272 if (BGP_DEBUG (zebra
, ZEBRA
) && ifp
)
273 zlog_debug("Rx Intf add VRF %u IF %s", vrf_id
, ifp
->name
);
275 bgp
= bgp_lookup_by_vrf_id (vrf_id
);
279 bgp_update_interface_nbrs (bgp
, ifp
, ifp
);
284 bgp_interface_delete (int command
, struct zclient
*zclient
,
285 zebra_size_t length
, vrf_id_t vrf_id
)
288 struct interface
*ifp
;
292 ifp
= zebra_interface_state_read (s
, vrf_id
);
293 if (!ifp
) /* This may happen if we've just unregistered for a VRF. */
296 ifp
->ifindex
= IFINDEX_DELETED
;
298 if (BGP_DEBUG (zebra
, ZEBRA
))
299 zlog_debug("Rx Intf del VRF %u IF %s", vrf_id
, ifp
->name
);
301 bgp
= bgp_lookup_by_vrf_id (vrf_id
);
305 bgp_update_interface_nbrs (bgp
, ifp
, NULL
);
310 bgp_interface_up (int command
, struct zclient
*zclient
, zebra_size_t length
,
314 struct interface
*ifp
;
316 struct nbr_connected
*nc
;
317 struct listnode
*node
, *nnode
;
321 ifp
= zebra_interface_state_read (s
, vrf_id
);
326 if (BGP_DEBUG (zebra
, ZEBRA
))
327 zlog_debug("Rx Intf up VRF %u IF %s", vrf_id
, ifp
->name
);
329 bgp
= bgp_lookup_by_vrf_id (vrf_id
);
333 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, nnode
, c
))
334 bgp_connected_add (bgp
, c
);
336 for (ALL_LIST_ELEMENTS (ifp
->nbr_connected
, node
, nnode
, nc
))
337 bgp_nbr_connected_add (bgp
, nc
);
343 bgp_interface_down (int command
, struct zclient
*zclient
, zebra_size_t length
,
347 struct interface
*ifp
;
349 struct nbr_connected
*nc
;
350 struct listnode
*node
, *nnode
;
354 ifp
= zebra_interface_state_read (s
, vrf_id
);
358 if (BGP_DEBUG (zebra
, ZEBRA
))
359 zlog_debug("Rx Intf down VRF %u IF %s", vrf_id
, ifp
->name
);
361 bgp
= bgp_lookup_by_vrf_id (vrf_id
);
365 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, nnode
, c
))
366 bgp_connected_delete (bgp
, c
);
368 for (ALL_LIST_ELEMENTS (ifp
->nbr_connected
, node
, nnode
, nc
))
369 bgp_nbr_connected_delete (bgp
, nc
, 1);
371 /* Fast external-failover */
375 if (CHECK_FLAG (bgp
->flags
, BGP_FLAG_NO_FAST_EXT_FAILOVER
))
378 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
380 #if defined(HAVE_CUMULUS)
381 /* Take down directly connected EBGP peers as well as 1-hop BFD
382 * tracked (directly connected) IBGP peers.
384 if ((peer
->ttl
!= 1) && (peer
->gtsm_hops
!= 1) &&
385 (!peer
->bfd_info
|| bgp_bfd_is_peer_multihop(peer
)))
387 /* Take down directly connected EBGP peers */
388 if ((peer
->ttl
!= 1) && (peer
->gtsm_hops
!= 1))
392 if (ifp
== peer
->nexthop
.ifp
)
394 BGP_EVENT_ADD (peer
, BGP_Stop
);
395 peer
->last_reset
= PEER_DOWN_IF_DOWN
;
404 bgp_interface_address_add (int command
, struct zclient
*zclient
,
405 zebra_size_t length
, vrf_id_t vrf_id
)
407 struct connected
*ifc
;
409 ifc
= zebra_interface_address_read (command
, zclient
->ibuf
, vrf_id
);
414 if (bgp_debug_zebra(ifc
->address
))
416 char buf
[PREFIX2STR_BUFFER
];
417 prefix2str(ifc
->address
, buf
, sizeof(buf
));
418 zlog_debug("Rx Intf address add VRF %u IF %s addr %s",
419 vrf_id
, ifc
->ifp
->name
, buf
);
422 if (if_is_operative (ifc
->ifp
))
426 bgp
= bgp_lookup_by_vrf_id (vrf_id
);
430 bgp_connected_add (bgp
, ifc
);
431 /* If we have learnt of any neighbors on this interface,
432 * check to kick off any BGP interface-based neighbors,
433 * but only if this is a link-local address.
435 if (IN6_IS_ADDR_LINKLOCAL(&ifc
->address
->u
.prefix6
) &&
436 !list_isempty(ifc
->ifp
->nbr_connected
))
437 bgp_start_interface_nbrs (bgp
, ifc
->ifp
);
444 bgp_interface_address_delete (int command
, struct zclient
*zclient
,
445 zebra_size_t length
, vrf_id_t vrf_id
)
447 struct connected
*ifc
;
450 ifc
= zebra_interface_address_read (command
, zclient
->ibuf
, vrf_id
);
455 if (bgp_debug_zebra(ifc
->address
))
457 char buf
[PREFIX2STR_BUFFER
];
458 prefix2str(ifc
->address
, buf
, sizeof(buf
));
459 zlog_debug("Rx Intf address del VRF %u IF %s addr %s",
460 vrf_id
, ifc
->ifp
->name
, buf
);
463 if (if_is_operative (ifc
->ifp
))
465 bgp
= bgp_lookup_by_vrf_id (vrf_id
);
467 bgp_connected_delete (bgp
, ifc
);
470 connected_free (ifc
);
476 bgp_interface_nbr_address_add (int command
, struct zclient
*zclient
,
477 zebra_size_t length
, vrf_id_t vrf_id
)
479 struct nbr_connected
*ifc
= NULL
;
482 ifc
= zebra_interface_nbr_address_read (command
, zclient
->ibuf
, vrf_id
);
487 if (bgp_debug_zebra(ifc
->address
))
489 char buf
[PREFIX2STR_BUFFER
];
490 prefix2str(ifc
->address
, buf
, sizeof(buf
));
491 zlog_debug("Rx Intf neighbor add VRF %u IF %s addr %s",
492 vrf_id
, ifc
->ifp
->name
, buf
);
495 if (if_is_operative (ifc
->ifp
))
497 bgp
= bgp_lookup_by_vrf_id (vrf_id
);
499 bgp_nbr_connected_add (bgp
, ifc
);
506 bgp_interface_nbr_address_delete (int command
, struct zclient
*zclient
,
507 zebra_size_t length
, vrf_id_t vrf_id
)
509 struct nbr_connected
*ifc
= NULL
;
512 ifc
= zebra_interface_nbr_address_read (command
, zclient
->ibuf
, vrf_id
);
517 if (bgp_debug_zebra(ifc
->address
))
519 char buf
[PREFIX2STR_BUFFER
];
520 prefix2str(ifc
->address
, buf
, sizeof(buf
));
521 zlog_debug("Rx Intf neighbor del VRF %u IF %s addr %s",
522 vrf_id
, ifc
->ifp
->name
, buf
);
525 if (if_is_operative (ifc
->ifp
))
527 bgp
= bgp_lookup_by_vrf_id (vrf_id
);
529 bgp_nbr_connected_delete (bgp
, ifc
, 0);
532 nbr_connected_free (ifc
);
537 /* VRF update for an interface. */
539 bgp_interface_vrf_update (int command
, struct zclient
*zclient
, zebra_size_t length
,
542 struct interface
*ifp
;
545 struct nbr_connected
*nc
;
546 struct listnode
*node
, *nnode
;
549 ifp
= zebra_interface_vrf_update_read (zclient
->ibuf
, vrf_id
, &new_vrf_id
);
553 if (BGP_DEBUG (zebra
, ZEBRA
) && ifp
)
554 zlog_debug("Rx Intf VRF change VRF %u IF %s NewVRF %u",
555 vrf_id
, ifp
->name
, new_vrf_id
);
557 bgp
= bgp_lookup_by_vrf_id (vrf_id
);
561 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, nnode
, c
))
562 bgp_connected_delete (bgp
, c
);
564 for (ALL_LIST_ELEMENTS (ifp
->nbr_connected
, node
, nnode
, nc
))
565 bgp_nbr_connected_delete (bgp
, nc
, 1);
567 /* Fast external-failover */
571 if (CHECK_FLAG (bgp
->flags
, BGP_FLAG_NO_FAST_EXT_FAILOVER
))
574 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
576 if ((peer
->ttl
!= 1) && (peer
->gtsm_hops
!= 1))
579 if (ifp
== peer
->nexthop
.ifp
)
580 BGP_EVENT_ADD (peer
, BGP_Stop
);
584 if_update_to_new_vrf (ifp
, new_vrf_id
);
586 bgp
= bgp_lookup_by_vrf_id (new_vrf_id
);
590 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, nnode
, c
))
591 bgp_connected_add (bgp
, c
);
593 for (ALL_LIST_ELEMENTS (ifp
->nbr_connected
, node
, nnode
, nc
))
594 bgp_nbr_connected_add (bgp
, nc
);
598 /* Zebra route add and delete treatment. */
600 zebra_read_ipv4 (int command
, struct zclient
*zclient
, zebra_size_t length
,
604 struct zapi_ipv4 api
;
605 struct in_addr nexthop
;
606 struct prefix_ipv4 p
;
607 unsigned int ifindex
;
611 bgp
= bgp_lookup_by_vrf_id (vrf_id
);
618 /* Type, flags, message. */
619 api
.type
= stream_getc (s
);
620 api
.instance
= stream_getw (s
);
621 api
.flags
= stream_getl (s
);
622 api
.message
= stream_getc (s
);
625 memset (&p
, 0, sizeof (struct prefix_ipv4
));
627 p
.prefixlen
= MIN(IPV4_MAX_PREFIXLEN
, stream_getc (s
));
628 stream_get (&p
.prefix
, s
, PSIZE (p
.prefixlen
));
630 /* Nexthop, ifindex, distance, metric. */
631 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
))
633 api
.nexthop_num
= stream_getc (s
);
634 nexthop
.s_addr
= stream_get_ipv4 (s
);
637 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_IFINDEX
))
639 api
.ifindex_num
= stream_getc (s
);
640 ifindex
= stream_getl (s
); /* ifindex, unused */
647 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_DISTANCE
))
648 api
.distance
= stream_getc (s
);
650 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_METRIC
))
651 api
.metric
= stream_getl (s
);
655 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_TAG
))
656 api
.tag
= stream_getl (s
);
660 if (command
== ZEBRA_REDISTRIBUTE_IPV4_ADD
)
662 if (bgp_debug_zebra((struct prefix
*)&p
))
664 char buf
[2][INET_ADDRSTRLEN
];
665 zlog_debug("Rx IPv4 route add VRF %u %s[%d] %s/%d nexthop %s metric %u tag %"ROUTE_TAG_PRI
,
667 zebra_route_string(api
.type
), api
.instance
,
668 inet_ntop(AF_INET
, &p
.prefix
, buf
[0], sizeof(buf
[0])),
670 inet_ntop(AF_INET
, &nexthop
, buf
[1], sizeof(buf
[1])),
676 * The ADD message is actually an UPDATE and there is no explicit DEL
677 * for a prior redistributed route, if any. So, perform an implicit
678 * DEL processing for the same redistributed route from any other
681 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
684 bgp_redistribute_delete(bgp
, (struct prefix
*)&p
, i
, api
.instance
);
687 /* Now perform the add/update. */
688 bgp_redistribute_add(bgp
, (struct prefix
*)&p
, &nexthop
, NULL
, ifindex
,
689 api
.metric
, api
.type
, api
.instance
, api
.tag
);
691 else if (command
== ZEBRA_REDISTRIBUTE_IPV4_DEL
)
693 if (bgp_debug_zebra((struct prefix
*)&p
))
695 char buf
[2][INET_ADDRSTRLEN
];
696 zlog_debug("Rx IPv4 route delete VRF %u %s[%d] %s/%d "
697 "nexthop %s metric %u tag %"ROUTE_TAG_PRI
,
699 zebra_route_string(api
.type
), api
.instance
,
700 inet_ntop(AF_INET
, &p
.prefix
, buf
[0], sizeof(buf
[0])),
702 inet_ntop(AF_INET
, &nexthop
, buf
[1], sizeof(buf
[1])),
706 bgp_redistribute_delete(bgp
, (struct prefix
*)&p
, api
.type
, api
.instance
);
712 /* Zebra route add and delete treatment. */
714 zebra_read_ipv6 (int command
, struct zclient
*zclient
, zebra_size_t length
,
718 struct zapi_ipv6 api
;
719 struct in6_addr nexthop
;
720 struct prefix_ipv6 p
, src_p
;
721 unsigned int ifindex
;
725 bgp
= bgp_lookup_by_vrf_id (vrf_id
);
730 memset (&nexthop
, 0, sizeof (struct in6_addr
));
732 /* Type, flags, message. */
733 api
.type
= stream_getc (s
);
734 api
.instance
= stream_getw (s
);
735 api
.flags
= stream_getl (s
);
736 api
.message
= stream_getc (s
);
739 memset (&p
, 0, sizeof (struct prefix_ipv6
));
741 p
.prefixlen
= MIN(IPV6_MAX_PREFIXLEN
, stream_getc (s
));
742 stream_get (&p
.prefix
, s
, PSIZE (p
.prefixlen
));
744 memset (&src_p
, 0, sizeof (struct prefix_ipv6
));
745 src_p
.family
= AF_INET6
;
746 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_SRCPFX
))
748 src_p
.prefixlen
= stream_getc (s
);
749 stream_get (&src_p
.prefix
, s
, PSIZE (src_p
.prefixlen
));
753 /* we completely ignore srcdest routes for now. */
756 /* Nexthop, ifindex, distance, metric. */
757 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
))
759 api
.nexthop_num
= stream_getc (s
);
760 stream_get (&nexthop
, s
, 16);
763 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_IFINDEX
))
765 api
.ifindex_num
= stream_getc (s
);
766 ifindex
= stream_getl (s
); /* ifindex, unused */
773 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_DISTANCE
))
774 api
.distance
= stream_getc (s
);
778 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_METRIC
))
779 api
.metric
= stream_getl (s
);
783 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_TAG
))
784 api
.tag
= stream_getl (s
);
788 /* Simply ignore link-local address. */
789 if (IN6_IS_ADDR_LINKLOCAL (&p
.prefix
))
792 if (command
== ZEBRA_REDISTRIBUTE_IPV6_ADD
)
794 if (bgp_debug_zebra((struct prefix
*)&p
))
796 char buf
[2][INET6_ADDRSTRLEN
];
797 zlog_debug("Rx IPv6 route add VRF %u %s[%d] %s/%d nexthop %s metric %u tag %"ROUTE_TAG_PRI
,
799 zebra_route_string(api
.type
), api
.instance
,
800 inet_ntop(AF_INET6
, &p
.prefix
, buf
[0], sizeof(buf
[0])),
802 inet_ntop(AF_INET
, &nexthop
, buf
[1], sizeof(buf
[1])),
808 * The ADD message is actually an UPDATE and there is no explicit DEL
809 * for a prior redistributed route, if any. So, perform an implicit
810 * DEL processing for the same redistributed route from any other
813 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
816 bgp_redistribute_delete(bgp
, (struct prefix
*)&p
, i
, api
.instance
);
819 bgp_redistribute_add (bgp
, (struct prefix
*)&p
, NULL
, &nexthop
, ifindex
,
820 api
.metric
, api
.type
, api
.instance
, api
.tag
);
822 else if (command
== ZEBRA_REDISTRIBUTE_IPV6_DEL
)
824 if (bgp_debug_zebra((struct prefix
*)&p
))
826 char buf
[2][INET6_ADDRSTRLEN
];
827 zlog_debug("Rx IPv6 route delete VRF %u %s[%d] %s/%d "
828 "nexthop %s metric %u tag %"ROUTE_TAG_PRI
,
830 zebra_route_string(api
.type
), api
.instance
,
831 inet_ntop(AF_INET6
, &p
.prefix
, buf
[0], sizeof(buf
[0])),
833 inet_ntop(AF_INET6
, &nexthop
, buf
[1], sizeof(buf
[1])),
837 bgp_redistribute_delete (bgp
, (struct prefix
*) &p
, api
.type
, api
.instance
);
844 if_lookup_by_ipv4 (struct in_addr
*addr
, vrf_id_t vrf_id
)
846 struct listnode
*ifnode
;
847 struct listnode
*cnode
;
848 struct interface
*ifp
;
849 struct connected
*connected
;
850 struct prefix_ipv4 p
;
855 p
.prefixlen
= IPV4_MAX_BITLEN
;
857 for (ALL_LIST_ELEMENTS_RO (vrf_iflist(vrf_id
), ifnode
, ifp
))
859 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, connected
))
861 cp
= connected
->address
;
863 if (cp
->family
== AF_INET
)
864 if (prefix_match (cp
, (struct prefix
*)&p
))
872 if_lookup_by_ipv4_exact (struct in_addr
*addr
, vrf_id_t vrf_id
)
874 struct listnode
*ifnode
;
875 struct listnode
*cnode
;
876 struct interface
*ifp
;
877 struct connected
*connected
;
880 for (ALL_LIST_ELEMENTS_RO (vrf_iflist(vrf_id
), ifnode
, ifp
))
882 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, connected
))
884 cp
= connected
->address
;
886 if (cp
->family
== AF_INET
)
887 if (IPV4_ADDR_SAME (&cp
->u
.prefix4
, addr
))
895 if_lookup_by_ipv6 (struct in6_addr
*addr
, ifindex_t ifindex
, vrf_id_t vrf_id
)
897 struct listnode
*ifnode
;
898 struct listnode
*cnode
;
899 struct interface
*ifp
;
900 struct connected
*connected
;
901 struct prefix_ipv6 p
;
906 p
.prefixlen
= IPV6_MAX_BITLEN
;
908 for (ALL_LIST_ELEMENTS_RO (vrf_iflist(vrf_id
), ifnode
, ifp
))
910 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, connected
))
912 cp
= connected
->address
;
914 if (cp
->family
== AF_INET6
)
915 if (prefix_match (cp
, (struct prefix
*)&p
))
917 if (IN6_IS_ADDR_LINKLOCAL(&cp
->u
.prefix6
))
919 if (ifindex
== ifp
->ifindex
)
931 if_lookup_by_ipv6_exact (struct in6_addr
*addr
, ifindex_t ifindex
, vrf_id_t vrf_id
)
933 struct listnode
*ifnode
;
934 struct listnode
*cnode
;
935 struct interface
*ifp
;
936 struct connected
*connected
;
939 for (ALL_LIST_ELEMENTS_RO (vrf_iflist(vrf_id
), ifnode
, ifp
))
941 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, connected
))
943 cp
= connected
->address
;
945 if (cp
->family
== AF_INET6
)
946 if (IPV6_ADDR_SAME (&cp
->u
.prefix6
, addr
))
948 if (IN6_IS_ADDR_LINKLOCAL(&cp
->u
.prefix6
))
950 if (ifindex
== ifp
->ifindex
)
962 if_get_ipv6_global (struct interface
*ifp
, struct in6_addr
*addr
)
964 struct listnode
*cnode
;
965 struct connected
*connected
;
968 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, connected
))
970 cp
= connected
->address
;
972 if (cp
->family
== AF_INET6
)
973 if (! IN6_IS_ADDR_LINKLOCAL (&cp
->u
.prefix6
))
975 memcpy (addr
, &cp
->u
.prefix6
, IPV6_MAX_BYTELEN
);
983 if_get_ipv6_local (struct interface
*ifp
, struct in6_addr
*addr
)
985 struct listnode
*cnode
;
986 struct connected
*connected
;
989 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, connected
))
991 cp
= connected
->address
;
993 if (cp
->family
== AF_INET6
)
994 if (IN6_IS_ADDR_LINKLOCAL (&cp
->u
.prefix6
))
996 memcpy (addr
, &cp
->u
.prefix6
, IPV6_MAX_BYTELEN
);
1004 if_get_ipv4_address (struct interface
*ifp
, struct in_addr
*addr
)
1006 struct listnode
*cnode
;
1007 struct connected
*connected
;
1010 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, connected
))
1012 cp
= connected
->address
;
1013 if ((cp
->family
== AF_INET
) && !ipv4_martian(&(cp
->u
.prefix4
)))
1015 *addr
= cp
->u
.prefix4
;
1023 bgp_nexthop_set (union sockunion
*local
, union sockunion
*remote
,
1024 struct bgp_nexthop
*nexthop
, struct peer
*peer
)
1027 struct interface
*ifp
= NULL
;
1029 memset (nexthop
, 0, sizeof (struct bgp_nexthop
));
1036 if (local
->sa
.sa_family
== AF_INET
)
1038 nexthop
->v4
= local
->sin
.sin_addr
;
1039 if (peer
->update_if
)
1040 ifp
= if_lookup_by_name (peer
->update_if
, peer
->bgp
->vrf_id
);
1042 ifp
= if_lookup_by_ipv4_exact (&local
->sin
.sin_addr
, peer
->bgp
->vrf_id
);
1044 if (local
->sa
.sa_family
== AF_INET6
)
1046 if (IN6_IS_ADDR_LINKLOCAL (&local
->sin6
.sin6_addr
))
1048 if (peer
->conf_if
|| peer
->ifname
)
1049 ifp
= if_lookup_by_name (peer
->conf_if
? peer
->conf_if
: peer
->ifname
, peer
->bgp
->vrf_id
);
1051 else if (peer
->update_if
)
1052 ifp
= if_lookup_by_name (peer
->update_if
, peer
->bgp
->vrf_id
);
1054 ifp
= if_lookup_by_ipv6_exact (&local
->sin6
.sin6_addr
,
1055 local
->sin6
.sin6_scope_id
,
1064 /* IPv4 connection, fetch and store IPv6 local address(es) if any. */
1065 if (local
->sa
.sa_family
== AF_INET
)
1068 ret
= if_get_ipv6_global (ifp
, &nexthop
->v6_global
);
1072 /* There is no global nexthop. Use link-local address as both the
1073 * global and link-local nexthop. In this scenario, the expectation
1074 * for interop is that the network admin would use a route-map to
1075 * specify the global IPv6 nexthop.
1077 if_get_ipv6_local (ifp
, &nexthop
->v6_global
);
1078 memcpy (&nexthop
->v6_local
, &nexthop
->v6_global
,
1082 if_get_ipv6_local (ifp
, &nexthop
->v6_local
);
1084 if (if_lookup_by_ipv4 (&remote
->sin
.sin_addr
, peer
->bgp
->vrf_id
))
1085 peer
->shared_network
= 1;
1087 peer
->shared_network
= 0;
1090 /* IPv6 connection, fetch and store IPv4 local address if any. */
1091 if (local
->sa
.sa_family
== AF_INET6
)
1093 struct interface
*direct
= NULL
;
1096 ret
= if_get_ipv4_address(ifp
, &nexthop
->v4
);
1097 if (!ret
&& peer
->local_id
.s_addr
)
1098 nexthop
->v4
= peer
->local_id
;
1101 if (! IN6_IS_ADDR_LINKLOCAL (&local
->sin6
.sin6_addr
))
1103 memcpy (&nexthop
->v6_global
, &local
->sin6
.sin6_addr
,
1106 /* If directory connected set link-local address. */
1107 direct
= if_lookup_by_ipv6 (&remote
->sin6
.sin6_addr
,
1108 remote
->sin6
.sin6_scope_id
, peer
->bgp
->vrf_id
);
1110 if_get_ipv6_local (ifp
, &nexthop
->v6_local
);
1113 /* Link-local address. */
1115 ret
= if_get_ipv6_global (ifp
, &nexthop
->v6_global
);
1117 /* If there is no global address. Set link-local address as
1118 global. I know this break RFC specification... */
1119 /* In this scenario, the expectation for interop is that the
1120 * network admin would use a route-map to specify the global
1124 memcpy (&nexthop
->v6_global
, &local
->sin6
.sin6_addr
,
1126 /* Always set the link-local address */
1127 memcpy (&nexthop
->v6_local
, &local
->sin6
.sin6_addr
,
1131 if (IN6_IS_ADDR_LINKLOCAL (&local
->sin6
.sin6_addr
) ||
1132 if_lookup_by_ipv6 (&remote
->sin6
.sin6_addr
, remote
->sin6
.sin6_scope_id
,
1134 peer
->shared_network
= 1;
1136 peer
->shared_network
= 0;
1139 /* KAME stack specific treatment. */
1141 if (IN6_IS_ADDR_LINKLOCAL (&nexthop
->v6_global
)
1142 && IN6_LINKLOCAL_IFINDEX (nexthop
->v6_global
))
1144 SET_IN6_LINKLOCAL_IFINDEX (nexthop
->v6_global
, 0);
1146 if (IN6_IS_ADDR_LINKLOCAL (&nexthop
->v6_local
)
1147 && IN6_LINKLOCAL_IFINDEX (nexthop
->v6_local
))
1149 SET_IN6_LINKLOCAL_IFINDEX (nexthop
->v6_local
, 0);
1153 /* If we have identified the local interface, there is no error for now. */
1157 static struct in6_addr
*
1158 bgp_info_to_ipv6_nexthop (struct bgp_info
*info
)
1160 struct in6_addr
*nexthop
= NULL
;
1162 /* Only global address nexthop exists. */
1163 if (info
->attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL
)
1164 nexthop
= &info
->attr
->extra
->mp_nexthop_global
;
1166 /* If both global and link-local address present. */
1167 if (info
->attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
1169 /* Check if route-map is set to prefer global over link-local */
1170 if (info
->attr
->extra
->mp_nexthop_prefer_global
)
1171 nexthop
= &info
->attr
->extra
->mp_nexthop_global
;
1174 /* Workaround for Cisco's nexthop bug. */
1175 if (IN6_IS_ADDR_UNSPECIFIED (&info
->attr
->extra
->mp_nexthop_global
)
1176 && info
->peer
->su_remote
->sa
.sa_family
== AF_INET6
)
1177 nexthop
= &info
->peer
->su_remote
->sin6
.sin6_addr
;
1179 nexthop
= &info
->attr
->extra
->mp_nexthop_local
;
1187 bgp_table_map_apply (struct route_map
*map
, struct prefix
*p
,
1188 struct bgp_info
*info
)
1190 if (route_map_apply(map
, p
, RMAP_BGP
, info
) != RMAP_DENYMATCH
)
1193 if (bgp_debug_zebra(p
))
1195 if (p
->family
== AF_INET
)
1197 char buf
[2][INET_ADDRSTRLEN
];
1198 zlog_debug("Zebra rmap deny: IPv4 route %s/%d nexthop %s",
1199 inet_ntop(AF_INET
, &p
->u
.prefix4
, buf
[0], sizeof(buf
[0])),
1201 inet_ntop(AF_INET
, &info
->attr
->nexthop
, buf
[1],
1204 if (p
->family
== AF_INET6
)
1206 char buf
[2][INET6_ADDRSTRLEN
];
1207 zlog_debug("Zebra rmap deny: IPv6 route %s/%d nexthop %s",
1208 inet_ntop(AF_INET6
, &p
->u
.prefix6
, buf
[0], sizeof(buf
[0])),
1210 inet_ntop(AF_INET6
, bgp_info_to_ipv6_nexthop(info
), buf
[1],
1218 bgp_zebra_announce (struct bgp_node
*rn
, struct prefix
*p
, struct bgp_info
*info
,
1219 struct bgp
*bgp
, afi_t afi
, safi_t safi
)
1224 struct bgp_info
*mpinfo
;
1225 size_t oldsize
, newsize
;
1226 u_int32_t nhcount
, metric
;
1227 struct bgp_info local_info
;
1228 struct bgp_info
*info_cp
= &local_info
;
1232 /* Don't try to install if we're not connected to Zebra or Zebra doesn't
1233 * know of this instance.
1235 if (!bgp_install_info_to_zebra (bgp
))
1238 if ((p
->family
== AF_INET
&&
1239 !vrf_bitmap_check (zclient
->redist
[AFI_IP
][ZEBRA_ROUTE_BGP
], bgp
->vrf_id
))
1240 || (p
->family
== AF_INET6
&&
1241 !vrf_bitmap_check (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_BGP
], bgp
->vrf_id
)))
1244 if (bgp
->main_zebra_update_hold
)
1250 if ((info
->attr
->extra
) && (info
->attr
->extra
->tag
!= 0))
1251 tag
= info
->attr
->extra
->tag
;
1255 /* When we create an aggregate route we must also install a Null0 route in
1257 if (info
->sub_type
== BGP_ROUTE_AGGREGATE
)
1258 SET_FLAG (flags
, ZEBRA_FLAG_BLACKHOLE
);
1260 if (peer
->sort
== BGP_PEER_IBGP
|| peer
->sort
== BGP_PEER_CONFED
||
1261 info
->sub_type
== BGP_ROUTE_AGGREGATE
)
1263 SET_FLAG (flags
, ZEBRA_FLAG_IBGP
);
1264 SET_FLAG (flags
, ZEBRA_FLAG_INTERNAL
);
1267 if ((peer
->sort
== BGP_PEER_EBGP
&& peer
->ttl
!= 1)
1268 || CHECK_FLAG (peer
->flags
, PEER_FLAG_DISABLE_CONNECTED_CHECK
)
1269 || bgp_flag_check(bgp
, BGP_FLAG_DISABLE_NH_CONNECTED_CHK
))
1271 SET_FLAG (flags
, ZEBRA_FLAG_INTERNAL
);
1273 nhcount
= 1 + bgp_info_mpath_count (info
);
1275 if (p
->family
== AF_INET
&& !BGP_ATTR_NEXTHOP_AFI_IP6(info
->attr
))
1277 struct zapi_ipv4 api
;
1278 struct in_addr
*nexthop
;
1279 char buf
[2][INET_ADDRSTRLEN
];
1280 int valid_nh_count
= 0;
1282 /* resize nexthop buffer size if necessary */
1283 if ((oldsize
= stream_get_size (bgp_nexthop_buf
)) <
1284 (sizeof (struct in_addr
*) * nhcount
))
1286 newsize
= sizeof (struct in_addr
*) * nhcount
;
1287 newsize
= stream_resize (bgp_nexthop_buf
, newsize
);
1288 if (newsize
== oldsize
)
1290 zlog_err ("can't resize nexthop buffer");
1294 stream_reset (bgp_nexthop_buf
);
1297 /* For labeled unicast, each nexthop has a label too. Resize label
1298 * buffer, if required.
1300 if (safi
== SAFI_LABELED_UNICAST
)
1302 if ((oldsize
= stream_get_size (bgp_label_buf
)) <
1303 (sizeof (unsigned int) * nhcount
))
1305 newsize
= (sizeof (unsigned int) * nhcount
);
1306 newsize
= stream_resize (bgp_label_buf
, newsize
);
1307 if (newsize
== oldsize
)
1309 zlog_err ("can't resize label buffer");
1313 stream_reset (bgp_label_buf
);
1316 /* Metric is currently based on the best-path only. */
1317 metric
= info
->attr
->med
;
1319 if (bgp
->table_map
[afi
][safi
].name
)
1321 BGP_INFO_ATTR_BUF_INIT();
1323 /* Copy info and attributes, so the route-map apply doesn't modify the
1325 BGP_INFO_ATTR_BUF_COPY(info
, info_cp
);
1326 if (bgp_table_map_apply(bgp
->table_map
[afi
][safi
].map
, p
, info_cp
))
1328 metric
= info_cp
->attr
->med
;
1329 nexthop
= &info_cp
->attr
->nexthop
;
1331 if (info_cp
->attr
->extra
)
1332 tag
= info_cp
->attr
->extra
->tag
;
1334 BGP_INFO_ATTR_BUF_FREE(info_cp
);
1338 nexthop
= &info
->attr
->nexthop
;
1343 stream_put (bgp_nexthop_buf
, &nexthop
, sizeof (struct in_addr
*));
1345 if (safi
== SAFI_LABELED_UNICAST
)
1347 label
= label_pton(info
->extra
->tag
);
1348 stream_put (bgp_label_buf
, &label
, sizeof (u_int32_t
));
1352 for (mpinfo
= bgp_info_mpath_first (info
); mpinfo
;
1353 mpinfo
= bgp_info_mpath_next (mpinfo
))
1357 if (bgp
->table_map
[afi
][safi
].name
)
1359 /* Copy info and attributes, so the route-map apply doesn't modify the
1361 BGP_INFO_ATTR_BUF_COPY(mpinfo
, info_cp
);
1362 if (bgp_table_map_apply(bgp
->table_map
[afi
][safi
].map
, p
, info_cp
))
1363 nexthop
= &info_cp
->attr
->nexthop
;
1364 BGP_INFO_ATTR_BUF_FREE(info_cp
);
1368 nexthop
= &mpinfo
->attr
->nexthop
;
1371 if (nexthop
== NULL
)
1374 stream_put (bgp_nexthop_buf
, &nexthop
, sizeof (struct in_addr
*));
1375 if (safi
== SAFI_LABELED_UNICAST
)
1377 label
= label_pton(mpinfo
->extra
->tag
);
1378 stream_put (bgp_label_buf
, &label
, sizeof (u_int32_t
));
1383 api
.vrf_id
= bgp
->vrf_id
;
1385 api
.type
= ZEBRA_ROUTE_BGP
;
1388 api
.safi
= (safi
== SAFI_LABELED_UNICAST
) ? SAFI_UNICAST
: safi
;
1389 SET_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
);
1390 if (safi
== SAFI_LABELED_UNICAST
)
1391 SET_FLAG (api
.message
, ZAPI_MESSAGE_LABEL
);
1393 /* Note that this currently only applies to Null0 routes for aggregates.
1394 * ZEBRA_FLAG_BLACKHOLE signals zapi_ipv4_route to encode a special
1395 * BLACKHOLE nexthop. We want to set api.nexthop_num to zero since we
1396 * do not want to also encode the 0.0.0.0 nexthop for the aggregate route.
1398 if (CHECK_FLAG(flags
, ZEBRA_FLAG_BLACKHOLE
))
1399 api
.nexthop_num
= 0;
1401 api
.nexthop_num
= valid_nh_count
;
1403 api
.nexthop
= (struct in_addr
**)STREAM_DATA (bgp_nexthop_buf
);
1404 if (safi
== SAFI_LABELED_UNICAST
)
1406 api
.label_num
= valid_nh_count
;
1407 api
.label
= (unsigned int *)STREAM_DATA (bgp_label_buf
);
1414 api
.ifindex_num
= 0;
1415 SET_FLAG (api
.message
, ZAPI_MESSAGE_METRIC
);
1416 api
.metric
= metric
;
1421 SET_FLAG (api
.message
, ZAPI_MESSAGE_TAG
);
1425 distance
= bgp_distance_apply (p
, info
, afi
, safi
, bgp
);
1428 SET_FLAG (api
.message
, ZAPI_MESSAGE_DISTANCE
);
1429 api
.distance
= distance
;
1432 if (bgp_debug_zebra(p
))
1436 zlog_debug("Tx IPv4 route %s VRF %u %s/%d metric %u tag %"ROUTE_TAG_PRI
1437 " count %d", (valid_nh_count
? "add":"delete"),
1439 inet_ntop(AF_INET
, &p
->u
.prefix4
, buf
[0], sizeof(buf
[0])),
1440 p
->prefixlen
, api
.metric
, api
.tag
, api
.nexthop_num
);
1441 for (i
= 0; i
< api
.nexthop_num
; i
++)
1443 label_buf
[0] = '\0';
1444 if (safi
== SAFI_LABELED_UNICAST
)
1445 sprintf(label_buf
, "label %u", api
.label
[i
]);
1446 zlog_debug(" nhop [%d]: %s %s",
1448 inet_ntop(AF_INET
, api
.nexthop
[i
], buf
[1], sizeof(buf
[1])),
1453 zapi_ipv4_route (valid_nh_count
? ZEBRA_IPV4_ROUTE_ADD
: ZEBRA_IPV4_ROUTE_DELETE
,
1454 zclient
, (struct prefix_ipv4
*) p
, &api
);
1457 /* We have to think about a IPv6 link-local address curse. */
1458 if (p
->family
== AF_INET6
||
1459 (p
->family
== AF_INET
&& BGP_ATTR_NEXTHOP_AFI_IP6(info
->attr
)))
1462 struct in6_addr
*nexthop
;
1463 struct zapi_ipv6 api
;
1464 int valid_nh_count
= 0;
1465 char buf
[2][INET6_ADDRSTRLEN
];
1467 /* resize nexthop buffer size if necessary */
1468 if ((oldsize
= stream_get_size (bgp_nexthop_buf
)) <
1469 (sizeof (struct in6_addr
*) * nhcount
))
1471 newsize
= (sizeof (struct in6_addr
*) * nhcount
);
1472 newsize
= stream_resize (bgp_nexthop_buf
, newsize
);
1473 if (newsize
== oldsize
)
1475 zlog_err ("can't resize nexthop buffer");
1479 stream_reset (bgp_nexthop_buf
);
1481 /* resize ifindices buffer size if necessary */
1482 if ((oldsize
= stream_get_size (bgp_ifindices_buf
)) <
1483 (sizeof (unsigned int) * nhcount
))
1485 newsize
= (sizeof (unsigned int) * nhcount
);
1486 newsize
= stream_resize (bgp_ifindices_buf
, newsize
);
1487 if (newsize
== oldsize
)
1489 zlog_err ("can't resize nexthop buffer");
1493 stream_reset (bgp_ifindices_buf
);
1495 /* For labeled unicast, each nexthop has a label too. Resize label
1496 * buffer, if required.
1498 if (safi
== SAFI_LABELED_UNICAST
)
1500 if ((oldsize
= stream_get_size (bgp_label_buf
)) <
1501 (sizeof (unsigned int) * nhcount
))
1503 newsize
= (sizeof (unsigned int) * nhcount
);
1504 newsize
= stream_resize (bgp_label_buf
, newsize
);
1505 if (newsize
== oldsize
)
1507 zlog_err ("can't resize label buffer");
1511 stream_reset (bgp_label_buf
);
1517 assert (info
->attr
->extra
);
1519 /* Metric is currently based on the best-path only. */
1520 metric
= info
->attr
->med
;
1522 if (bgp
->table_map
[afi
][safi
].name
)
1524 BGP_INFO_ATTR_BUF_INIT();
1526 /* Copy info and attributes, so the route-map apply doesn't modify the
1528 BGP_INFO_ATTR_BUF_COPY(info
, info_cp
);
1529 if (bgp_table_map_apply(bgp
->table_map
[afi
][safi
].map
, p
, info_cp
))
1531 metric
= info_cp
->attr
->med
;
1532 nexthop
= bgp_info_to_ipv6_nexthop(info_cp
);
1534 if (info_cp
->attr
->extra
)
1535 tag
= info_cp
->attr
->extra
->tag
;
1537 BGP_INFO_ATTR_BUF_FREE(info_cp
);
1541 nexthop
= bgp_info_to_ipv6_nexthop(info
);
1546 if (info
->attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
1547 if (info
->peer
->nexthop
.ifp
)
1548 ifindex
= info
->peer
->nexthop
.ifp
->ifindex
;
1552 if (info
->peer
->conf_if
|| info
->peer
->ifname
)
1553 ifindex
= if_nametoindex (info
->peer
->conf_if
? info
->peer
->conf_if
: info
->peer
->ifname
);
1554 else if (info
->peer
->nexthop
.ifp
)
1555 ifindex
= info
->peer
->nexthop
.ifp
->ifindex
;
1557 stream_put (bgp_nexthop_buf
, &nexthop
, sizeof (struct in6_addr
*));
1558 stream_put (bgp_ifindices_buf
, &ifindex
, sizeof (unsigned int));
1559 if (safi
== SAFI_LABELED_UNICAST
)
1561 label
= label_pton(info
->extra
->tag
);
1562 stream_put (bgp_label_buf
, &label
, sizeof (u_int32_t
));
1567 for (mpinfo
= bgp_info_mpath_first (info
); mpinfo
;
1568 mpinfo
= bgp_info_mpath_next (mpinfo
))
1573 if (bgp
->table_map
[afi
][safi
].name
)
1575 /* Copy info and attributes, so the route-map apply doesn't modify the
1577 BGP_INFO_ATTR_BUF_COPY(mpinfo
, info_cp
);
1578 if (bgp_table_map_apply(bgp
->table_map
[afi
][safi
].map
, p
, info_cp
))
1579 nexthop
= bgp_info_to_ipv6_nexthop(info_cp
);
1580 BGP_INFO_ATTR_BUF_FREE(info_cp
);
1584 nexthop
= bgp_info_to_ipv6_nexthop(mpinfo
);
1587 if (nexthop
== NULL
)
1590 if (mpinfo
->attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
1591 if (mpinfo
->peer
->nexthop
.ifp
)
1592 ifindex
= mpinfo
->peer
->nexthop
.ifp
->ifindex
;
1596 if (mpinfo
->peer
->conf_if
|| mpinfo
->peer
->ifname
)
1597 ifindex
= ifname2ifindex (mpinfo
->peer
->conf_if
? mpinfo
->peer
->conf_if
: mpinfo
->peer
->ifname
, bgp
->vrf_id
);
1598 else if (mpinfo
->peer
->nexthop
.ifp
)
1599 ifindex
= mpinfo
->peer
->nexthop
.ifp
->ifindex
;
1604 stream_put (bgp_nexthop_buf
, &nexthop
, sizeof (struct in6_addr
*));
1605 stream_put (bgp_ifindices_buf
, &ifindex
, sizeof (unsigned int));
1606 if (safi
== SAFI_LABELED_UNICAST
)
1608 label
= label_pton(mpinfo
->extra
->tag
);
1609 stream_put (bgp_label_buf
, &label
, sizeof (u_int32_t
));
1614 /* Make Zebra API structure. */
1615 api
.vrf_id
= bgp
->vrf_id
;
1617 api
.type
= ZEBRA_ROUTE_BGP
;
1620 api
.safi
= (safi
== SAFI_LABELED_UNICAST
) ? SAFI_UNICAST
: safi
;
1621 SET_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
);
1622 if (safi
== SAFI_LABELED_UNICAST
)
1623 SET_FLAG (api
.message
, ZAPI_MESSAGE_LABEL
);
1625 /* Note that this currently only applies to Null0 routes for aggregates.
1626 * ZEBRA_FLAG_BLACKHOLE signals zapi_ipv6_route to encode a special
1627 * BLACKHOLE nexthop. We want to set api.nexthop_num to zero since we
1628 * do not want to also encode the :: nexthop for the aggregate route.
1630 if (CHECK_FLAG(flags
, ZEBRA_FLAG_BLACKHOLE
))
1631 api
.nexthop_num
= 0;
1633 api
.nexthop_num
= valid_nh_count
;
1635 api
.nexthop
= (struct in6_addr
**)STREAM_DATA (bgp_nexthop_buf
);
1636 SET_FLAG (api
.message
, ZAPI_MESSAGE_IFINDEX
);
1637 api
.ifindex_num
= valid_nh_count
;
1638 api
.ifindex
= (ifindex_t
*)STREAM_DATA (bgp_ifindices_buf
);
1639 if (safi
== SAFI_LABELED_UNICAST
)
1641 api
.label_num
= valid_nh_count
;
1642 api
.label
= (unsigned int *)STREAM_DATA (bgp_label_buf
);
1649 SET_FLAG (api
.message
, ZAPI_MESSAGE_METRIC
);
1650 api
.metric
= metric
;
1655 SET_FLAG (api
.message
, ZAPI_MESSAGE_TAG
);
1659 distance
= bgp_distance_apply (p
, info
, afi
, safi
, bgp
);
1662 SET_FLAG (api
.message
, ZAPI_MESSAGE_DISTANCE
);
1663 api
.distance
= distance
;
1666 if (p
->family
== AF_INET
)
1668 if (bgp_debug_zebra(p
))
1672 zlog_debug("Tx IPv4 route %s VRF %u %s/%d metric %u tag %"ROUTE_TAG_PRI
,
1673 valid_nh_count
? "add" : "delete", bgp
->vrf_id
,
1674 inet_ntop(AF_INET
, &p
->u
.prefix4
, buf
[0], sizeof(buf
[0])),
1675 p
->prefixlen
, api
.metric
, api
.tag
);
1676 for (i
= 0; i
< api
.nexthop_num
; i
++)
1678 label_buf
[0] = '\0';
1679 if (safi
== SAFI_LABELED_UNICAST
)
1680 sprintf(label_buf
, "label %u", api
.label
[i
]);
1681 zlog_debug(" nhop [%d]: %s if %s %s",
1683 inet_ntop(AF_INET6
, api
.nexthop
[i
], buf
[1], sizeof(buf
[1])),
1684 ifindex2ifname (api
.ifindex
[i
], bgp
->vrf_id
),
1690 zapi_ipv4_route_ipv6_nexthop (ZEBRA_IPV4_ROUTE_IPV6_NEXTHOP_ADD
,
1691 zclient
, (struct prefix_ipv4
*) p
,
1692 (struct zapi_ipv6
*)&api
);
1694 zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE
,
1695 zclient
, (struct prefix_ipv4
*) p
, (struct zapi_ipv4
*)&api
);
1699 if (bgp_debug_zebra(p
))
1703 zlog_debug("Tx IPv6 route %s VRF %u %s/%d metric %u tag %"ROUTE_TAG_PRI
,
1704 valid_nh_count
? "add" : "delete", bgp
->vrf_id
,
1705 inet_ntop(AF_INET6
, &p
->u
.prefix6
, buf
[0], sizeof(buf
[0])),
1706 p
->prefixlen
, api
.metric
, api
.tag
);
1707 for (i
= 0; i
< api
.nexthop_num
; i
++)
1709 label_buf
[0] = '\0';
1710 if (safi
== SAFI_LABELED_UNICAST
)
1711 sprintf(label_buf
, "label %u", api
.label
[i
]);
1712 zlog_debug(" nhop [%d]: %s if %s %s",
1714 inet_ntop(AF_INET6
, api
.nexthop
[i
], buf
[1], sizeof(buf
[1])),
1715 ifindex2ifname (api
.ifindex
[i
], bgp
->vrf_id
),
1720 zapi_ipv6_route (valid_nh_count
?
1721 ZEBRA_IPV6_ROUTE_ADD
: ZEBRA_IPV6_ROUTE_DELETE
,
1722 zclient
, (struct prefix_ipv6
*) p
, NULL
, &api
);
1727 /* Announce all routes of a table to zebra */
1729 bgp_zebra_announce_table (struct bgp
*bgp
, afi_t afi
, safi_t safi
)
1731 struct bgp_node
*rn
;
1732 struct bgp_table
*table
;
1733 struct bgp_info
*ri
;
1735 /* Don't try to install if we're not connected to Zebra or Zebra doesn't
1736 * know of this instance.
1738 if (!bgp_install_info_to_zebra (bgp
))
1741 table
= bgp
->rib
[afi
][safi
];
1744 for (rn
= bgp_table_top (table
); rn
; rn
= bgp_route_next (rn
))
1745 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
1746 if (CHECK_FLAG (ri
->flags
, BGP_INFO_SELECTED
)
1747 && ri
->type
== ZEBRA_ROUTE_BGP
1748 && ri
->sub_type
== BGP_ROUTE_NORMAL
)
1749 bgp_zebra_announce (rn
, &rn
->p
, ri
, bgp
, afi
, safi
);
1753 bgp_zebra_withdraw (struct prefix
*p
, struct bgp_info
*info
, safi_t safi
)
1761 /* Don't try to install if we're not connected to Zebra or Zebra doesn't
1762 * know of this instance.
1764 if (!bgp_install_info_to_zebra (peer
->bgp
))
1767 if ((p
->family
== AF_INET
&&
1768 !vrf_bitmap_check (zclient
->redist
[AFI_IP
][ZEBRA_ROUTE_BGP
], peer
->bgp
->vrf_id
))
1769 || (p
->family
== AF_INET6
&&
1770 !vrf_bitmap_check (zclient
->redist
[AFI_IP6
][ZEBRA_ROUTE_BGP
], peer
->bgp
->vrf_id
)))
1775 if (peer
->sort
== BGP_PEER_IBGP
)
1777 SET_FLAG (flags
, ZEBRA_FLAG_INTERNAL
);
1778 SET_FLAG (flags
, ZEBRA_FLAG_IBGP
);
1781 if ((peer
->sort
== BGP_PEER_EBGP
&& peer
->ttl
!= 1)
1782 || CHECK_FLAG (peer
->flags
, PEER_FLAG_DISABLE_CONNECTED_CHECK
)
1783 || bgp_flag_check(peer
->bgp
, BGP_FLAG_DISABLE_NH_CONNECTED_CHK
))
1784 SET_FLAG (flags
, ZEBRA_FLAG_INTERNAL
);
1786 if (p
->family
== AF_INET
)
1788 struct zapi_ipv4 api
;
1790 api
.vrf_id
= peer
->bgp
->vrf_id
;
1793 api
.type
= ZEBRA_ROUTE_BGP
;
1796 api
.safi
= (safi
== SAFI_LABELED_UNICAST
) ? SAFI_UNICAST
: safi
;
1797 SET_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
);
1798 if (safi
== SAFI_LABELED_UNICAST
)
1799 SET_FLAG (api
.message
, ZAPI_MESSAGE_LABEL
);
1800 api
.nexthop_num
= 0;
1804 api
.ifindex_num
= 0;
1805 SET_FLAG (api
.message
, ZAPI_MESSAGE_METRIC
);
1806 api
.metric
= info
->attr
->med
;
1809 if ((info
->attr
->extra
) && (info
->attr
->extra
->tag
!= 0))
1811 SET_FLAG(api
.message
, ZAPI_MESSAGE_TAG
);
1812 api
.tag
= info
->attr
->extra
->tag
;
1815 if (bgp_debug_zebra(p
))
1817 char buf
[2][INET_ADDRSTRLEN
];
1818 zlog_debug("Tx IPv4 route delete VRF %u %s/%d metric %u tag %"ROUTE_TAG_PRI
,
1820 inet_ntop(AF_INET
, &p
->u
.prefix4
, buf
[0], sizeof(buf
[0])),
1821 p
->prefixlen
, api
.metric
, api
.tag
);
1824 zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE
, zclient
,
1825 (struct prefix_ipv4
*) p
, &api
);
1827 /* We have to think about a IPv6 link-local address curse. */
1828 if (p
->family
== AF_INET6
)
1830 struct zapi_ipv6 api
;
1832 assert (info
->attr
->extra
);
1834 api
.vrf_id
= peer
->bgp
->vrf_id
;
1836 api
.type
= ZEBRA_ROUTE_BGP
;
1839 api
.safi
= (safi
== SAFI_LABELED_UNICAST
) ? SAFI_UNICAST
: safi
;
1840 SET_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
);
1841 if (safi
== SAFI_LABELED_UNICAST
)
1842 SET_FLAG (api
.message
, ZAPI_MESSAGE_LABEL
);
1843 api
.nexthop_num
= 0;
1845 api
.ifindex_num
= 0;
1847 SET_FLAG (api
.message
, ZAPI_MESSAGE_METRIC
);
1848 api
.metric
= info
->attr
->med
;
1851 if ((info
->attr
->extra
) && (info
->attr
->extra
->tag
!= 0))
1853 SET_FLAG(api
.message
, ZAPI_MESSAGE_TAG
);
1854 api
.tag
= info
->attr
->extra
->tag
;
1857 if (bgp_debug_zebra(p
))
1859 char buf
[2][INET6_ADDRSTRLEN
];
1860 zlog_debug("Tx IPv6 route delete VRF %u %s/%d metric %u tag %"ROUTE_TAG_PRI
,
1862 inet_ntop(AF_INET6
, &p
->u
.prefix6
, buf
[0], sizeof(buf
[0])),
1863 p
->prefixlen
, api
.metric
, api
.tag
);
1866 zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE
, zclient
,
1867 (struct prefix_ipv6
*) p
, NULL
, &api
);
1872 bgp_redist_lookup (struct bgp
*bgp
, afi_t afi
, u_char type
, u_short instance
)
1874 struct list
*red_list
;
1875 struct listnode
*node
;
1876 struct bgp_redist
*red
;
1878 red_list
= bgp
->redist
[afi
][type
];
1882 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
))
1883 if (red
->instance
== instance
)
1890 bgp_redist_add (struct bgp
*bgp
, afi_t afi
, u_char type
, u_short instance
)
1892 struct list
*red_list
;
1893 struct bgp_redist
*red
;
1895 red
= bgp_redist_lookup(bgp
, afi
, type
, instance
);
1899 if (!bgp
->redist
[afi
][type
])
1900 bgp
->redist
[afi
][type
] = list_new();
1902 red_list
= bgp
->redist
[afi
][type
];
1903 red
= (struct bgp_redist
*)XCALLOC(MTYPE_BGP_REDIST
, sizeof(struct bgp_redist
));
1904 red
->instance
= instance
;
1906 listnode_add(red_list
, red
);
1912 bgp_redist_del (struct bgp
*bgp
, afi_t afi
, u_char type
, u_short instance
)
1914 struct bgp_redist
*red
;
1916 red
= bgp_redist_lookup(bgp
, afi
, type
, instance
);
1920 listnode_delete(bgp
->redist
[afi
][type
], red
);
1921 XFREE (MTYPE_BGP_REDIST
, red
);
1922 if (!bgp
->redist
[afi
][type
]->count
)
1924 list_free(bgp
->redist
[afi
][type
]);
1925 bgp
->redist
[afi
][type
] = NULL
;
1930 /* Other routes redistribution into BGP. */
1932 bgp_redistribute_set (struct bgp
*bgp
, afi_t afi
, int type
, u_short instance
)
1935 /* Return if already redistribute flag is set. */
1938 if (redist_check_instance(&zclient
->mi_redist
[afi
][type
], instance
))
1941 redist_add_instance(&zclient
->mi_redist
[afi
][type
], instance
);
1945 if (vrf_bitmap_check (zclient
->redist
[afi
][type
], bgp
->vrf_id
))
1949 if (bgp
->vrf_id
== VRF_DEFAULT
&&
1950 type
== ZEBRA_ROUTE_VNC_DIRECT
) {
1951 vnc_export_bgp_enable(bgp
, afi
); /* only enables if mode bits cfg'd */
1955 vrf_bitmap_set (zclient
->redist
[afi
][type
], bgp
->vrf_id
);
1958 /* Don't try to register if we're not connected to Zebra or Zebra doesn't
1959 * know of this instance.
1961 if (!bgp_install_info_to_zebra (bgp
))
1964 if (BGP_DEBUG (zebra
, ZEBRA
))
1965 zlog_debug("Tx redistribute add VRF %u afi %d %s %d",
1967 zebra_route_string(type
), instance
);
1969 /* Send distribute add message to zebra. */
1970 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD
, zclient
, afi
, type
,
1971 instance
, bgp
->vrf_id
);
1977 bgp_redistribute_resend (struct bgp
*bgp
, afi_t afi
, int type
, u_short instance
)
1979 /* Don't try to send if we're not connected to Zebra or Zebra doesn't
1980 * know of this instance.
1982 if (!bgp_install_info_to_zebra (bgp
))
1985 if (BGP_DEBUG (zebra
, ZEBRA
))
1986 zlog_debug("Tx redistribute del/add VRF %u afi %d %s %d",
1988 zebra_route_string(type
), instance
);
1990 /* Send distribute add message to zebra. */
1991 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE
, zclient
, afi
, type
,
1992 instance
, bgp
->vrf_id
);
1993 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD
, zclient
, afi
, type
,
1994 instance
, bgp
->vrf_id
);
1999 /* Redistribute with route-map specification. */
2001 bgp_redistribute_rmap_set (struct bgp_redist
*red
, const char *name
)
2004 && (strcmp (red
->rmap
.name
, name
) == 0))
2008 XFREE(MTYPE_ROUTE_MAP_NAME
, red
->rmap
.name
);
2009 red
->rmap
.name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, name
);
2010 red
->rmap
.map
= route_map_lookup_by_name (name
);
2015 /* Redistribute with metric specification. */
2017 bgp_redistribute_metric_set (struct bgp
*bgp
, struct bgp_redist
*red
, afi_t afi
,
2018 int type
, u_int32_t metric
)
2020 struct bgp_node
*rn
;
2021 struct bgp_info
*ri
;
2023 if (red
->redist_metric_flag
2024 && red
->redist_metric
== metric
)
2027 red
->redist_metric_flag
= 1;
2028 red
->redist_metric
= metric
;
2030 for (rn
= bgp_table_top(bgp
->rib
[afi
][SAFI_UNICAST
]); rn
; rn
= bgp_route_next(rn
))
2032 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
2034 if (ri
->sub_type
== BGP_ROUTE_REDISTRIBUTE
&&
2036 ri
->instance
== red
->instance
)
2038 struct attr
*old_attr
;
2039 struct attr new_attr
;
2040 struct attr_extra new_extra
;
2042 new_attr
.extra
= &new_extra
;
2043 bgp_attr_dup (&new_attr
, ri
->attr
);
2044 new_attr
.med
= red
->redist_metric
;
2045 old_attr
= ri
->attr
;
2046 ri
->attr
= bgp_attr_intern (&new_attr
);
2047 bgp_attr_unintern (&old_attr
);
2049 bgp_info_set_flag(rn
, ri
, BGP_INFO_ATTR_CHANGED
);
2050 bgp_process(bgp
, rn
, afi
, SAFI_UNICAST
);
2058 /* Unset redistribution. */
2060 bgp_redistribute_unreg (struct bgp
*bgp
, afi_t afi
, int type
, u_short instance
)
2062 struct bgp_redist
*red
;
2064 red
= bgp_redist_lookup(bgp
, afi
, type
, instance
);
2068 /* Return if zebra connection is disabled. */
2071 if (!redist_check_instance(&zclient
->mi_redist
[afi
][type
], instance
))
2073 redist_del_instance(&zclient
->mi_redist
[afi
][type
], instance
);
2077 if (! vrf_bitmap_check (zclient
->redist
[afi
][type
], bgp
->vrf_id
))
2079 vrf_bitmap_unset (zclient
->redist
[afi
][type
], bgp
->vrf_id
);
2083 if (bgp
->vrf_id
== VRF_DEFAULT
&&
2084 type
== ZEBRA_ROUTE_VNC_DIRECT
) {
2085 vnc_export_bgp_disable(bgp
, afi
);
2089 if (bgp_install_info_to_zebra (bgp
))
2091 /* Send distribute delete message to zebra. */
2092 if (BGP_DEBUG (zebra
, ZEBRA
))
2093 zlog_debug("Tx redistribute del VRF %u afi %d %s %d",
2094 bgp
->vrf_id
, afi
, zebra_route_string(type
), instance
);
2095 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE
, zclient
, afi
, type
, instance
,
2099 /* Withdraw redistributed routes from current BGP's routing table. */
2100 bgp_redistribute_withdraw (bgp
, afi
, type
, instance
);
2105 /* Unset redistribution. */
2107 bgp_redistribute_unset (struct bgp
*bgp
, afi_t afi
, int type
, u_short instance
)
2109 struct bgp_redist
*red
;
2111 red
= bgp_redist_lookup(bgp
, afi
, type
, instance
);
2115 bgp_redistribute_unreg(bgp
, afi
, type
, instance
);
2117 /* Unset route-map. */
2119 XFREE(MTYPE_ROUTE_MAP_NAME
, red
->rmap
.name
);
2120 red
->rmap
.name
= NULL
;
2121 red
->rmap
.map
= NULL
;
2124 red
->redist_metric_flag
= 0;
2125 red
->redist_metric
= 0;
2127 bgp_redist_del(bgp
, afi
, type
, instance
);
2132 /* Update redistribute vrf bitmap during triggers like
2133 restart networking or delete/add VRFs */
2135 bgp_update_redist_vrf_bitmaps (struct bgp
*bgp
, vrf_id_t old_vrf_id
)
2140 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2141 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
2142 if (vrf_bitmap_check (zclient
->redist
[afi
][i
], old_vrf_id
))
2144 vrf_bitmap_unset (zclient
->redist
[afi
][i
], old_vrf_id
);
2145 vrf_bitmap_set (zclient
->redist
[afi
][i
], bgp
->vrf_id
);
2151 bgp_zclient_reset (void)
2153 zclient_reset (zclient
);
2156 /* Register this instance with Zebra. Invoked upon connect (for
2157 * default instance) and when other VRFs are learnt (or created and
2161 bgp_zebra_instance_register (struct bgp
*bgp
)
2163 /* Don't try to register if we're not connected to Zebra */
2164 if (!zclient
|| zclient
->sock
< 0)
2167 if (BGP_DEBUG (zebra
, ZEBRA
))
2168 zlog_debug("Registering VRF %u", bgp
->vrf_id
);
2170 /* Register for router-id, interfaces, redistributed routes. */
2171 zclient_send_reg_requests (zclient
, bgp
->vrf_id
);
2174 /* Deregister this instance with Zebra. Invoked upon the instance
2175 * being deleted (default or VRF) and it is already registered.
2178 bgp_zebra_instance_deregister (struct bgp
*bgp
)
2180 /* Don't try to deregister if we're not connected to Zebra */
2181 if (zclient
->sock
< 0)
2184 if (BGP_DEBUG (zebra
, ZEBRA
))
2185 zlog_debug("Deregistering VRF %u", bgp
->vrf_id
);
2187 /* Deregister for router-id, interfaces, redistributed routes. */
2188 zclient_send_dereg_requests (zclient
, bgp
->vrf_id
);
2192 bgp_zebra_initiate_radv (struct bgp
*bgp
, struct peer
*peer
)
2194 int ra_interval
= BGP_UNNUM_DEFAULT_RA_INTERVAL
;
2196 /* Don't try to initiate if we're not connected to Zebra */
2197 if (zclient
->sock
< 0)
2200 if (BGP_DEBUG (zebra
, ZEBRA
))
2201 zlog_debug("%u: Initiating RA for peer %s", bgp
->vrf_id
, peer
->host
);
2203 zclient_send_interface_radv_req (zclient
, bgp
->vrf_id
, peer
->ifp
, 1, ra_interval
);
2207 bgp_zebra_terminate_radv (struct bgp
*bgp
, struct peer
*peer
)
2209 /* Don't try to terminate if we're not connected to Zebra */
2210 if (zclient
->sock
< 0)
2213 if (BGP_DEBUG (zebra
, ZEBRA
))
2214 zlog_debug("%u: Terminating RA for peer %s", bgp
->vrf_id
, peer
->host
);
2216 zclient_send_interface_radv_req (zclient
, bgp
->vrf_id
, peer
->ifp
, 0, 0);
2219 /* BGP has established connection with Zebra. */
2221 bgp_zebra_connected (struct zclient
*zclient
)
2225 zclient_num_connects
++; /* increment even if not responding */
2227 /* At this point, we may or may not have BGP instances configured, but
2228 * we're only interested in the default VRF (others wouldn't have learnt
2229 * the VRF from Zebra yet.)
2231 bgp
= bgp_get_default();
2235 bgp_zebra_instance_register (bgp
);
2237 /* Send the client registration */
2238 bfd_client_sendmsg(zclient
, ZEBRA_BFD_CLIENT_REGISTER
);
2240 /* TODO - What if we have peers and networks configured, do we have to
2247 bgp_zebra_init (struct thread_master
*master
)
2249 zclient_num_connects
= 0;
2251 /* Set default values. */
2252 zclient
= zclient_new (master
);
2253 zclient_init (zclient
, ZEBRA_ROUTE_BGP
, 0);
2254 zclient
->zebra_connected
= bgp_zebra_connected
;
2255 zclient
->router_id_update
= bgp_router_id_update
;
2256 zclient
->interface_add
= bgp_interface_add
;
2257 zclient
->interface_delete
= bgp_interface_delete
;
2258 zclient
->interface_address_add
= bgp_interface_address_add
;
2259 zclient
->interface_address_delete
= bgp_interface_address_delete
;
2260 zclient
->interface_nbr_address_add
= bgp_interface_nbr_address_add
;
2261 zclient
->interface_nbr_address_delete
= bgp_interface_nbr_address_delete
;
2262 zclient
->interface_vrf_update
= bgp_interface_vrf_update
;
2263 zclient
->redistribute_route_ipv4_add
= zebra_read_ipv4
;
2264 zclient
->redistribute_route_ipv4_del
= zebra_read_ipv4
;
2265 zclient
->interface_up
= bgp_interface_up
;
2266 zclient
->interface_down
= bgp_interface_down
;
2267 zclient
->redistribute_route_ipv6_add
= zebra_read_ipv6
;
2268 zclient
->redistribute_route_ipv6_del
= zebra_read_ipv6
;
2269 zclient
->nexthop_update
= bgp_read_nexthop_update
;
2270 zclient
->import_check_update
= bgp_read_import_check_update
;
2271 zclient
->fec_update
= bgp_read_fec_update
;
2273 bgp_nexthop_buf
= stream_new(BGP_NEXTHOP_BUF_SIZE
);
2274 bgp_ifindices_buf
= stream_new(BGP_IFINDICES_BUF_SIZE
);
2275 bgp_label_buf
= stream_new(BGP_LABEL_BUF_SIZE
);
2279 bgp_zebra_destroy(void)
2281 if (zclient
== NULL
)
2283 zclient_stop(zclient
);
2284 zclient_free(zclient
);
2289 bgp_zebra_num_connects(void)
2291 return zclient_num_connects
;