2 * bgp_updgrp_adv.c: BGP update group advertisement and adjacency
6 * @copyright Copyright (C) 2014 Cumulus Networks, Inc.
8 * @author Avneesh Sachdev <avneesh@sproute.net>
9 * @author Rajesh Varadarajan <rajesh@sproute.net>
10 * @author Pradosh Mohapatra <pradosh@sproute.net>
12 * This file is part of GNU Zebra.
14 * GNU Zebra is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2, or (at your option) any
19 * GNU Zebra is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; see the file COPYING; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
40 #include "bgpd/bgpd.h"
41 #include "bgpd/bgp_table.h"
42 #include "bgpd/bgp_debug.h"
43 #include "bgpd/bgp_route.h"
44 #include "bgpd/bgp_advertise.h"
45 #include "bgpd/bgp_attr.h"
46 #include "bgpd/bgp_aspath.h"
47 #include "bgpd/bgp_packet.h"
48 #include "bgpd/bgp_fsm.h"
49 #include "bgpd/bgp_mplsvpn.h"
50 #include "bgpd/bgp_updgrp.h"
51 #include "bgpd/bgp_advertise.h"
52 #include "bgpd/bgp_addpath.h"
58 static int bgp_adj_out_compare(const struct bgp_adj_out
*o1
,
59 const struct bgp_adj_out
*o2
)
61 if (o1
->subgroup
< o2
->subgroup
)
64 if (o1
->subgroup
> o2
->subgroup
)
67 if (o1
->addpath_tx_id
< o2
->addpath_tx_id
)
70 if (o1
->addpath_tx_id
> o2
->addpath_tx_id
)
75 RB_GENERATE(bgp_adj_out_rb
, bgp_adj_out
, adj_entry
, bgp_adj_out_compare
);
77 static inline struct bgp_adj_out
*adj_lookup(struct bgp_dest
*dest
,
78 struct update_subgroup
*subgrp
,
79 uint32_t addpath_tx_id
)
81 struct bgp_adj_out lookup
;
86 /* update-groups that do not support addpath will pass 0 for
88 lookup
.subgroup
= subgrp
;
89 lookup
.addpath_tx_id
= addpath_tx_id
;
91 return RB_FIND(bgp_adj_out_rb
, &dest
->adj_out
, &lookup
);
94 static void adj_free(struct bgp_adj_out
*adj
)
96 TAILQ_REMOVE(&(adj
->subgroup
->adjq
), adj
, subgrp_adj_train
);
97 SUBGRP_DECR_STAT(adj
->subgroup
, adj_count
);
99 RB_REMOVE(bgp_adj_out_rb
, &adj
->dest
->adj_out
, adj
);
100 bgp_dest_unlock_node(adj
->dest
);
102 XFREE(MTYPE_BGP_ADJ_OUT
, adj
);
105 static void subgrp_withdraw_stale_addpath(struct updwalk_context
*ctx
,
106 struct update_subgroup
*subgrp
)
108 struct bgp_adj_out
*adj
, *adj_next
;
110 struct bgp_path_info
*pi
;
111 afi_t afi
= SUBGRP_AFI(subgrp
);
112 safi_t safi
= SUBGRP_SAFI(subgrp
);
113 struct peer
*peer
= SUBGRP_PEER(subgrp
);
115 /* Look through all of the paths we have advertised for this rn and send
116 * a withdraw for the ones that are no longer present */
117 RB_FOREACH_SAFE (adj
, bgp_adj_out_rb
, &ctx
->dest
->adj_out
, adj_next
) {
119 if (adj
->subgroup
== subgrp
) {
120 for (pi
= bgp_dest_get_bgp_path_info(ctx
->dest
); pi
;
122 id
= bgp_addpath_id_for_peer(peer
, afi
, safi
,
125 if (id
== adj
->addpath_tx_id
) {
131 subgroup_process_announce_selected(
132 subgrp
, NULL
, ctx
->dest
,
139 static int group_announce_route_walkcb(struct update_group
*updgrp
, void *arg
)
141 struct updwalk_context
*ctx
= arg
;
142 struct update_subgroup
*subgrp
;
143 struct bgp_path_info
*pi
;
147 struct bgp_adj_out
*adj
, *adj_next
;
150 afi
= UPDGRP_AFI(updgrp
);
151 safi
= UPDGRP_SAFI(updgrp
);
152 peer
= UPDGRP_PEER(updgrp
);
153 addpath_capable
= bgp_addpath_encode_tx(peer
, afi
, safi
);
155 if (BGP_DEBUG(update
, UPDATE_OUT
))
156 zlog_debug("%s: afi=%s, safi=%s, p=%pRN", __func__
,
157 afi2str(afi
), safi2str(safi
),
158 bgp_dest_to_rnode(ctx
->dest
));
160 UPDGRP_FOREACH_SUBGRP (updgrp
, subgrp
) {
163 * Skip the subgroups that have coalesce timer running. We will
164 * walk the entire prefix table for those subgroups when the
165 * coalesce timer fires.
167 if (!subgrp
->t_coalesce
) {
168 /* An update-group that uses addpath */
169 if (addpath_capable
) {
170 subgrp_withdraw_stale_addpath(ctx
, subgrp
);
172 for (pi
= bgp_dest_get_bgp_path_info(ctx
->dest
);
174 /* Skip the bestpath for now */
178 subgroup_process_announce_selected(
179 subgrp
, pi
, ctx
->dest
,
180 bgp_addpath_id_for_peer(
185 /* Process the bestpath last so the "show [ip]
186 * bgp neighbor x.x.x.x advertised"
187 * output shows the attributes from the bestpath
190 subgroup_process_announce_selected(
191 subgrp
, ctx
->pi
, ctx
->dest
,
192 bgp_addpath_id_for_peer(
194 &ctx
->pi
->tx_addpath
));
197 /* An update-group that does not use addpath */
200 subgroup_process_announce_selected(
201 subgrp
, ctx
->pi
, ctx
->dest
,
202 bgp_addpath_id_for_peer(
204 &ctx
->pi
->tx_addpath
));
206 /* Find the addpath_tx_id of the path we
209 RB_FOREACH_SAFE (adj
, bgp_adj_out_rb
,
212 if (adj
->subgroup
== subgrp
) {
213 subgroup_process_announce_selected(
223 /* Notify BGP Conditional advertisement */
224 bgp_notify_conditional_adv_scanner(subgrp
);
227 return UPDWALK_CONTINUE
;
230 static void subgrp_show_adjq_vty(struct update_subgroup
*subgrp
,
231 struct vty
*vty
, uint8_t flags
)
233 struct bgp_table
*table
;
234 struct bgp_adj_out
*adj
;
235 unsigned long output_count
;
236 struct bgp_dest
*dest
;
241 bgp
= SUBGRP_INST(subgrp
);
245 table
= bgp
->rib
[SUBGRP_AFI(subgrp
)][SUBGRP_SAFI(subgrp
)];
249 for (dest
= bgp_table_top(table
); dest
; dest
= bgp_route_next(dest
)) {
250 const struct prefix
*dest_p
= bgp_dest_get_prefix(dest
);
252 RB_FOREACH (adj
, bgp_adj_out_rb
, &dest
->adj_out
)
253 if (adj
->subgroup
== subgrp
) {
256 "BGP table version is %" PRIu64
257 ", local router ID is %pI4\n",
260 vty_out(vty
, BGP_SHOW_SCODE_HEADER
);
261 vty_out(vty
, BGP_SHOW_OCODE_HEADER
);
265 vty_out(vty
, BGP_SHOW_HEADER
);
268 if ((flags
& UPDWALK_FLAGS_ADVQUEUE
) && adj
->adv
270 route_vty_out_tmp(vty
, dest
, dest_p
,
276 if ((flags
& UPDWALK_FLAGS_ADVERTISED
)
278 route_vty_out_tmp(vty
, dest
, dest_p
,
286 if (output_count
!= 0)
287 vty_out(vty
, "\nTotal number of prefixes %ld\n", output_count
);
290 static int updgrp_show_adj_walkcb(struct update_group
*updgrp
, void *arg
)
292 struct updwalk_context
*ctx
= arg
;
293 struct update_subgroup
*subgrp
;
297 UPDGRP_FOREACH_SUBGRP (updgrp
, subgrp
) {
298 if (ctx
->subgrp_id
&& (ctx
->subgrp_id
!= subgrp
->id
))
300 vty_out(vty
, "update group %" PRIu64
", subgroup %" PRIu64
"\n",
301 updgrp
->id
, subgrp
->id
);
302 subgrp_show_adjq_vty(subgrp
, vty
, ctx
->flags
);
304 return UPDWALK_CONTINUE
;
307 static void updgrp_show_adj(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
308 struct vty
*vty
, uint64_t id
, uint8_t flags
)
310 struct updwalk_context ctx
;
311 memset(&ctx
, 0, sizeof(ctx
));
316 update_group_af_walk(bgp
, afi
, safi
, updgrp_show_adj_walkcb
, &ctx
);
319 static int subgroup_coalesce_timer(struct thread
*thread
)
321 struct update_subgroup
*subgrp
;
324 subgrp
= THREAD_ARG(thread
);
325 if (bgp_debug_update(NULL
, NULL
, subgrp
->update_group
, 0))
326 zlog_debug("u%" PRIu64
":s%" PRIu64
" announcing routes upon coalesce timer expiry(%u ms)",
327 (SUBGRP_UPDGRP(subgrp
))->id
, subgrp
->id
,
329 subgrp
->t_coalesce
= NULL
;
330 subgrp
->v_coalesce
= 0;
331 bgp
= SUBGRP_INST(subgrp
);
332 subgroup_announce_route(subgrp
);
335 /* While the announce_route() may kick off the route advertisement timer
337 * the members of the subgroup, we'd like to send the initial updates
339 * faster (i.e., without enforcing MRAI). Also, if there were no routes
341 * announce, this is the method currently employed to trigger the EOR.
343 if (!bgp_update_delay_active(SUBGRP_INST(subgrp
)) &&
344 !(BGP_SUPPRESS_FIB_ENABLED(bgp
))) {
348 SUBGRP_FOREACH_PEER (subgrp
, paf
) {
349 peer
= PAF_PEER(paf
);
350 BGP_TIMER_OFF(peer
->t_routeadv
);
351 BGP_TIMER_ON(peer
->t_routeadv
, bgp_routeadv_timer
, 0);
358 static int update_group_announce_walkcb(struct update_group
*updgrp
, void *arg
)
360 struct update_subgroup
*subgrp
;
362 UPDGRP_FOREACH_SUBGRP (updgrp
, subgrp
) {
363 subgroup_announce_all(subgrp
);
366 return UPDWALK_CONTINUE
;
369 static int update_group_announce_rrc_walkcb(struct update_group
*updgrp
,
372 struct update_subgroup
*subgrp
;
377 afi
= UPDGRP_AFI(updgrp
);
378 safi
= UPDGRP_SAFI(updgrp
);
379 peer
= UPDGRP_PEER(updgrp
);
381 /* Only announce if this is a group of route-reflector-clients */
382 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
], PEER_FLAG_REFLECTOR_CLIENT
)) {
383 UPDGRP_FOREACH_SUBGRP (updgrp
, subgrp
) {
384 subgroup_announce_all(subgrp
);
388 return UPDWALK_CONTINUE
;
391 /********************
393 ********************/
396 * Allocate an adj-out object. Do proper initialization of its fields,
397 * primarily its association with the subgroup and the prefix.
399 struct bgp_adj_out
*bgp_adj_out_alloc(struct update_subgroup
*subgrp
,
400 struct bgp_dest
*dest
,
401 uint32_t addpath_tx_id
)
403 struct bgp_adj_out
*adj
;
405 adj
= XCALLOC(MTYPE_BGP_ADJ_OUT
, sizeof(struct bgp_adj_out
));
406 adj
->subgroup
= subgrp
;
407 adj
->addpath_tx_id
= addpath_tx_id
;
409 RB_INSERT(bgp_adj_out_rb
, &dest
->adj_out
, adj
);
410 bgp_dest_lock_node(dest
);
413 TAILQ_INSERT_TAIL(&(subgrp
->adjq
), adj
, subgrp_adj_train
);
414 SUBGRP_INCR_STAT(subgrp
, adj_count
);
419 struct bgp_advertise
*
420 bgp_advertise_clean_subgroup(struct update_subgroup
*subgrp
,
421 struct bgp_adj_out
*adj
)
423 struct bgp_advertise
*adv
;
424 struct bgp_advertise_attr
*baa
;
425 struct bgp_advertise
*next
;
426 struct bgp_adv_fifo_head
*fhead
;
433 fhead
= &subgrp
->sync
->update
;
435 /* Unlink myself from advertise attribute FIFO. */
436 bgp_advertise_delete(baa
, adv
);
438 /* Fetch next advertise candidate. */
441 /* Unintern BGP advertise attribute. */
442 bgp_advertise_unintern(subgrp
->hash
, baa
);
444 fhead
= &subgrp
->sync
->withdraw
;
447 /* Unlink myself from advertisement FIFO. */
448 bgp_adv_fifo_del(fhead
, adv
);
451 bgp_advertise_free(adj
->adv
);
457 void bgp_adj_out_set_subgroup(struct bgp_dest
*dest
,
458 struct update_subgroup
*subgrp
, struct attr
*attr
,
459 struct bgp_path_info
*path
)
461 struct bgp_adj_out
*adj
= NULL
;
462 struct bgp_advertise
*adv
;
466 struct peer
*adv_peer
;
469 uint32_t attr_hash
= attrhash_key_make(attr
);
471 peer
= SUBGRP_PEER(subgrp
);
472 afi
= SUBGRP_AFI(subgrp
);
473 safi
= SUBGRP_SAFI(subgrp
);
474 bgp
= SUBGRP_INST(subgrp
);
476 if (DISABLE_BGP_ANNOUNCE
)
479 /* Look for adjacency information. */
482 bgp_addpath_id_for_peer(peer
, afi
, safi
, &path
->tx_addpath
));
485 adj
= bgp_adj_out_alloc(
487 bgp_addpath_id_for_peer(peer
, afi
, safi
,
493 /* Check if we are sending the same route. This is needed to
494 * avoid duplicate UPDATES. For instance, filtering communities
495 * at egress, neighbors will see duplicate UPDATES despite
496 * the route wasn't changed actually.
497 * Do not suppress BGP UPDATES for route-refresh.
499 if (CHECK_FLAG(bgp
->flags
, BGP_FLAG_SUPPRESS_DUPLICATES
)
500 && !CHECK_FLAG(subgrp
->sflags
, SUBGRP_STATUS_FORCE_UPDATES
)
501 && adj
->attr_hash
== attr_hash
) {
502 if (BGP_DEBUG(update
, UPDATE_OUT
)) {
503 char attr_str
[BUFSIZ
] = {0};
505 bgp_dump_attr(attr
, attr_str
, sizeof(attr_str
));
507 zlog_debug("%s suppress UPDATE w/ attr: %s", peer
->host
,
514 bgp_advertise_clean_subgroup(subgrp
, adj
);
515 adj
->adv
= bgp_advertise_new();
519 assert(adv
->pathi
== NULL
);
520 /* bgp_path_info adj_out reference */
521 adv
->pathi
= bgp_path_info_lock(path
);
523 adv
->baa
= bgp_advertise_intern(subgrp
->hash
, attr
);
525 adj
->attr_hash
= attr_hash
;
527 /* Add new advertisement to advertisement attribute list. */
528 bgp_advertise_add(adv
->baa
, adv
);
531 * If the update adv list is empty, trigger the member peers'
532 * mrai timers so the socket writes can happen.
534 if (!bgp_adv_fifo_count(&subgrp
->sync
->update
)) {
535 SUBGRP_FOREACH_PEER (subgrp
, paf
) {
536 /* If there are no routes in the withdraw list, set
537 * the flag PEER_STATUS_ADV_DELAY which will allow
538 * more routes to be sent in the update message
540 if (BGP_SUPPRESS_FIB_ENABLED(bgp
)) {
541 adv_peer
= PAF_PEER(paf
);
542 if (!bgp_adv_fifo_count(
543 &subgrp
->sync
->withdraw
))
544 SET_FLAG(adv_peer
->thread_flags
,
545 PEER_THREAD_SUBGRP_ADV_DELAY
);
547 UNSET_FLAG(adv_peer
->thread_flags
,
548 PEER_THREAD_SUBGRP_ADV_DELAY
);
550 bgp_adjust_routeadv(PAF_PEER(paf
));
554 bgp_adv_fifo_add_tail(&subgrp
->sync
->update
, adv
);
556 subgrp
->version
= max(subgrp
->version
, dest
->version
);
559 /* The only time 'withdraw' will be false is if we are sending
560 * the "neighbor x.x.x.x default-originate" default and need to clear
561 * bgp_adj_out for the 0.0.0.0/0 route in the BGP table.
563 void bgp_adj_out_unset_subgroup(struct bgp_dest
*dest
,
564 struct update_subgroup
*subgrp
, char withdraw
,
565 uint32_t addpath_tx_id
)
567 struct bgp_adj_out
*adj
;
568 struct bgp_advertise
*adv
;
571 if (DISABLE_BGP_ANNOUNCE
)
574 /* Lookup existing adjacency */
575 adj
= adj_lookup(dest
, subgrp
, addpath_tx_id
);
577 /* Clean up previous advertisement. */
579 bgp_advertise_clean_subgroup(subgrp
, adj
);
581 /* If default originate is enabled and the route is default
582 * route, do not send withdraw. This will prevent deletion of
583 * the default route at the peer.
585 if (CHECK_FLAG(subgrp
->sflags
, SUBGRP_STATUS_DEFAULT_ORIGINATE
)
586 && is_default_prefix(bgp_dest_get_prefix(dest
)))
589 if (adj
->attr
&& withdraw
) {
590 /* We need advertisement structure. */
591 adj
->adv
= bgp_advertise_new();
596 /* Note if we need to trigger a packet write */
598 !bgp_adv_fifo_count(&subgrp
->sync
->withdraw
);
600 /* Add to synchronization entry for withdraw
602 bgp_adv_fifo_add_tail(&subgrp
->sync
->withdraw
, adv
);
605 subgroup_trigger_write(subgrp
);
607 /* Free allocated information. */
612 subgrp
->version
= max(subgrp
->version
, dest
->version
);
615 void bgp_adj_out_remove_subgroup(struct bgp_dest
*dest
, struct bgp_adj_out
*adj
,
616 struct update_subgroup
*subgrp
)
619 bgp_attr_unintern(&adj
->attr
);
622 bgp_advertise_clean_subgroup(subgrp
, adj
);
628 * Go through all the routes and clean up the adj/adv structures corresponding
631 void subgroup_clear_table(struct update_subgroup
*subgrp
)
633 struct bgp_adj_out
*aout
, *taout
;
635 SUBGRP_FOREACH_ADJ_SAFE (subgrp
, aout
, taout
)
636 bgp_adj_out_remove_subgroup(aout
->dest
, aout
, subgrp
);
640 * subgroup_announce_table
642 void subgroup_announce_table(struct update_subgroup
*subgrp
,
643 struct bgp_table
*table
)
645 struct bgp_dest
*dest
;
646 struct bgp_path_info
*ri
;
655 peer
= SUBGRP_PEER(subgrp
);
656 afi
= SUBGRP_AFI(subgrp
);
657 safi
= SUBGRP_SAFI(subgrp
);
658 bgp
= SUBGRP_INST(subgrp
);
659 addpath_capable
= bgp_addpath_encode_tx(peer
, afi
, safi
);
661 if (safi
== SAFI_LABELED_UNICAST
)
665 table
= peer
->bgp
->rib
[afi
][safi
];
667 if (safi
!= SAFI_MPLS_VPN
&& safi
!= SAFI_ENCAP
&& safi
!= SAFI_EVPN
668 && CHECK_FLAG(peer
->af_flags
[afi
][safi
],
669 PEER_FLAG_DEFAULT_ORIGINATE
))
670 subgroup_default_originate(subgrp
, 0);
672 for (dest
= bgp_table_top(table
); dest
; dest
= bgp_route_next(dest
)) {
673 const struct prefix
*dest_p
= bgp_dest_get_prefix(dest
);
675 /* Check if the route can be advertised */
676 advertise
= bgp_check_advertise(bgp
, dest
);
678 for (ri
= bgp_dest_get_bgp_path_info(dest
); ri
; ri
= ri
->next
)
680 if (CHECK_FLAG(ri
->flags
, BGP_PATH_SELECTED
)
682 && bgp_addpath_tx_path(
683 peer
->addpath_type
[afi
][safi
],
685 if (subgroup_announce_check(dest
, ri
, subgrp
,
688 /* Check if route can be advertised */
690 bgp_adj_out_set_subgroup(dest
,
695 /* If default originate is enabled for
696 * the peer, do not send explicit
697 * withdraw. This will prevent deletion
698 * of default route advertised through
702 peer
->af_flags
[afi
][safi
],
703 PEER_FLAG_DEFAULT_ORIGINATE
)
704 && is_default_prefix(bgp_dest_get_prefix(dest
)))
707 bgp_adj_out_unset_subgroup(
709 bgp_addpath_id_for_peer(
717 * We walked through the whole table -- make sure our version number
718 * is consistent with the one on the table. This should allow
719 * subgroups to merge sooner if a peer comes up when the route node
720 * with the largest version is no longer in the table. This also
721 * covers the pathological case where all routes in the table have
724 subgrp
->version
= max(subgrp
->version
, table
->version
);
727 * Start a task to merge the subgroup if necessary.
729 update_subgroup_trigger_merge_check(subgrp
, 0);
733 * subgroup_announce_route
735 * Refresh all routes out to a subgroup.
737 void subgroup_announce_route(struct update_subgroup
*subgrp
)
739 struct bgp_dest
*dest
;
740 struct bgp_table
*table
;
741 struct peer
*onlypeer
;
743 if (update_subgroup_needs_refresh(subgrp
)) {
744 update_subgroup_set_needs_refresh(subgrp
, 0);
748 * First update is deferred until ORF or ROUTE-REFRESH is received
750 onlypeer
= ((SUBGRP_PCOUNT(subgrp
) == 1) ? (SUBGRP_PFIRST(subgrp
))->peer
752 if (onlypeer
&& CHECK_FLAG(onlypeer
->af_sflags
[SUBGRP_AFI(subgrp
)]
753 [SUBGRP_SAFI(subgrp
)],
754 PEER_STATUS_ORF_WAIT_REFRESH
))
757 if (SUBGRP_SAFI(subgrp
) != SAFI_MPLS_VPN
758 && SUBGRP_SAFI(subgrp
) != SAFI_ENCAP
759 && SUBGRP_SAFI(subgrp
) != SAFI_EVPN
)
760 subgroup_announce_table(subgrp
, NULL
);
762 for (dest
= bgp_table_top(update_subgroup_rib(subgrp
)); dest
;
763 dest
= bgp_route_next(dest
)) {
764 table
= bgp_dest_get_bgp_table_info(dest
);
767 subgroup_announce_table(subgrp
, table
);
771 void subgroup_default_originate(struct update_subgroup
*subgrp
, int withdraw
)
775 struct attr
*new_attr
= &attr
;
778 struct bgp_dest
*dest
;
779 struct bgp_path_info
*pi
;
781 struct bgp_adj_out
*adj
;
782 route_map_result_t ret
= RMAP_DENYMATCH
;
789 peer
= SUBGRP_PEER(subgrp
);
790 afi
= SUBGRP_AFI(subgrp
);
791 safi
= SUBGRP_SAFI(subgrp
);
793 if (!(afi
== AFI_IP
|| afi
== AFI_IP6
))
797 from
= bgp
->peer_self
;
799 bgp_attr_default_set(&attr
, BGP_ORIGIN_IGP
);
801 attr
.local_pref
= bgp
->default_local_pref
;
803 if ((afi
== AFI_IP6
) || peer_cap_enhe(peer
, afi
, safi
)) {
804 /* IPv6 global nexthop must be included. */
805 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
807 /* If the peer is on shared nextwork and we have link-local
809 if (peer
->shared_network
810 && !IN6_IS_ADDR_UNSPECIFIED(&peer
->nexthop
.v6_local
))
811 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
814 if (peer
->default_rmap
[afi
][safi
].name
) {
815 SET_FLAG(bgp
->peer_self
->rmap_type
, PEER_RMAP_TYPE_DEFAULT
);
817 /* Iterate over the RIB to see if we can announce
818 * the default route. We announce the default
819 * route only if route-map has a match.
821 for (dest
= bgp_table_top(bgp
->rib
[afi
][safi
]); dest
;
822 dest
= bgp_route_next(dest
)) {
823 if (!bgp_dest_has_bgp_path_info_data(dest
))
826 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
;
828 struct attr tmp_attr
;
829 struct bgp_path_info tmp_pi
;
830 struct bgp_path_info_extra tmp_pie
;
832 tmp_attr
= *pi
->attr
;
833 tmp_attr
.aspath
= attr
.aspath
;
835 prep_for_rmap_apply(&tmp_pi
, &tmp_pie
, dest
, pi
,
836 pi
->peer
, &tmp_attr
);
838 ret
= route_map_apply(
839 peer
->default_rmap
[afi
][safi
].map
,
840 bgp_dest_get_prefix(dest
), &tmp_pi
);
842 if (ret
== RMAP_DENYMATCH
) {
843 /* The aspath belongs to 'attr' */
844 tmp_attr
.aspath
= NULL
;
845 bgp_attr_flush(&tmp_attr
);
848 new_attr
= bgp_attr_intern(&tmp_attr
);
850 subgroup_announce_reset_nhop(
851 (peer_cap_enhe(peer
, afi
, safi
)
859 if (ret
== RMAP_PERMITMATCH
) {
860 bgp_dest_unlock_node(dest
);
864 bgp
->peer_self
->rmap_type
= 0;
866 if (ret
== RMAP_DENYMATCH
)
870 /* Check if the default route is in local BGP RIB which is
871 * installed through redistribute or network command
873 memset(&p
, 0, sizeof(p
));
874 p
.family
= afi2family(afi
);
876 dest
= bgp_afi_node_lookup(bgp
->rib
[afi
][safi
], afi
, safi
, &p
, NULL
);
879 /* Withdraw the default route advertised using default
882 if (CHECK_FLAG(subgrp
->sflags
, SUBGRP_STATUS_DEFAULT_ORIGINATE
))
883 subgroup_default_withdraw_packet(subgrp
);
884 UNSET_FLAG(subgrp
->sflags
, SUBGRP_STATUS_DEFAULT_ORIGINATE
);
886 /* If default route is present in the local RIB, advertise the
890 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
;
892 if (CHECK_FLAG(pi
->flags
, BGP_PATH_SELECTED
))
893 if (subgroup_announce_check(
895 bgp_dest_get_prefix(dest
),
897 bgp_adj_out_set_subgroup(
901 bgp_dest_unlock_node(dest
);
904 if (!CHECK_FLAG(subgrp
->sflags
,
905 SUBGRP_STATUS_DEFAULT_ORIGINATE
)) {
907 /* The 'neighbor x.x.x.x default-originate' default will
909 * implicit withdraw for any previous UPDATEs sent for
911 * clear adj_out for the 0.0.0.0/0 prefix in the BGP
915 /* Remove the adjacency for the previously
916 * advertised default route
920 BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE
);
922 /* Clean up previous advertisement. */
924 bgp_advertise_clean_subgroup(
927 /* Free allocated information. */
930 bgp_dest_unlock_node(dest
);
933 /* Advertise the default route */
934 if (bgp_in_graceful_shutdown(bgp
))
935 bgp_attr_add_gshut_community(new_attr
);
937 SET_FLAG(subgrp
->sflags
,
938 SUBGRP_STATUS_DEFAULT_ORIGINATE
);
939 subgroup_default_update_packet(subgrp
, new_attr
, from
);
945 * Announce the BGP table to a subgroup.
947 * At startup, we try to optimize route announcement by coalescing the
948 * peer-up events. This is done only the first time - from then on,
949 * subgrp->v_coalesce will be set to zero and the normal logic
952 void subgroup_announce_all(struct update_subgroup
*subgrp
)
958 * If coalesce timer value is not set, announce routes immediately.
960 if (!subgrp
->v_coalesce
) {
961 if (bgp_debug_update(NULL
, NULL
, subgrp
->update_group
, 0))
962 zlog_debug("u%" PRIu64
":s%" PRIu64
" announcing all routes",
963 subgrp
->update_group
->id
, subgrp
->id
);
964 subgroup_announce_route(subgrp
);
969 * We should wait for the coalesce timer. Arm the timer if not done.
971 if (!subgrp
->t_coalesce
) {
972 thread_add_timer_msec(bm
->master
, subgroup_coalesce_timer
,
973 subgrp
, subgrp
->v_coalesce
,
974 &subgrp
->t_coalesce
);
979 * Go through all update subgroups and set up the adv queue for the
982 void group_announce_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
983 struct bgp_dest
*dest
, struct bgp_path_info
*pi
)
985 struct updwalk_context ctx
;
989 /* If suppress fib is enabled, the route will be advertised when
990 * FIB status is received
992 if (!bgp_check_advertise(bgp
, dest
))
995 update_group_af_walk(bgp
, afi
, safi
, group_announce_route_walkcb
, &ctx
);
998 void update_group_show_adj_queue(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
999 struct vty
*vty
, uint64_t id
)
1001 updgrp_show_adj(bgp
, afi
, safi
, vty
, id
, UPDWALK_FLAGS_ADVQUEUE
);
1004 void update_group_show_advertised(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
1005 struct vty
*vty
, uint64_t id
)
1007 updgrp_show_adj(bgp
, afi
, safi
, vty
, id
, UPDWALK_FLAGS_ADVERTISED
);
1010 void update_group_announce(struct bgp
*bgp
)
1012 update_group_walk(bgp
, update_group_announce_walkcb
, NULL
);
1015 void update_group_announce_rrclients(struct bgp
*bgp
)
1017 update_group_walk(bgp
, update_group_announce_rrc_walkcb
, NULL
);