]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_updgrp_adv.c
Merge pull request #1472 from opensourcerouting/lintian-warning
[mirror_frr.git] / bgpd / bgp_updgrp_adv.c
1 /**
2 * bgp_updgrp_adv.c: BGP update group advertisement and adjacency
3 * maintenance
4 *
5 *
6 * @copyright Copyright (C) 2014 Cumulus Networks, Inc.
7 *
8 * @author Avneesh Sachdev <avneesh@sproute.net>
9 * @author Rajesh Varadarajan <rajesh@sproute.net>
10 * @author Pradosh Mohapatra <pradosh@sproute.net>
11 *
12 * This file is part of GNU Zebra.
13 *
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
17 * later version.
18 *
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.
23 *
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
27 */
28
29 #include <zebra.h>
30
31 #include "command.h"
32 #include "memory.h"
33 #include "prefix.h"
34 #include "hash.h"
35 #include "thread.h"
36 #include "queue.h"
37 #include "routemap.h"
38 #include "filter.h"
39
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
53
54 /********************
55 * PRIVATE FUNCTIONS
56 ********************/
57
58 static inline struct bgp_adj_out *adj_lookup(struct bgp_node *rn,
59 struct update_subgroup *subgrp,
60 u_int32_t addpath_tx_id)
61 {
62 struct bgp_adj_out *adj;
63 struct peer *peer;
64 afi_t afi;
65 safi_t safi;
66 int addpath_capable;
67
68 if (!rn || !subgrp)
69 return NULL;
70
71 peer = SUBGRP_PEER(subgrp);
72 afi = SUBGRP_AFI(subgrp);
73 safi = SUBGRP_SAFI(subgrp);
74 addpath_capable = bgp_addpath_encode_tx(peer, afi, safi);
75
76 /* update-groups that do not support addpath will pass 0 for
77 * addpath_tx_id so do not both matching against it */
78 for (adj = rn->adj_out; adj; adj = adj->next) {
79 if (adj->subgroup == subgrp) {
80 if (addpath_capable) {
81 if (adj->addpath_tx_id == addpath_tx_id) {
82 break;
83 }
84 } else {
85 break;
86 }
87 }
88 }
89
90 return adj;
91 }
92
93 static void adj_free(struct bgp_adj_out *adj)
94 {
95 TAILQ_REMOVE(&(adj->subgroup->adjq), adj, subgrp_adj_train);
96 SUBGRP_DECR_STAT(adj->subgroup, adj_count);
97 XFREE(MTYPE_BGP_ADJ_OUT, adj);
98 }
99
100 static int group_announce_route_walkcb(struct update_group *updgrp, void *arg)
101 {
102 struct updwalk_context *ctx = arg;
103 struct update_subgroup *subgrp;
104 struct bgp_info *ri;
105 afi_t afi;
106 safi_t safi;
107 struct peer *peer;
108 struct bgp_adj_out *adj, *adj_next;
109 int addpath_capable;
110
111 afi = UPDGRP_AFI(updgrp);
112 safi = UPDGRP_SAFI(updgrp);
113 peer = UPDGRP_PEER(updgrp);
114 addpath_capable = bgp_addpath_encode_tx(peer, afi, safi);
115
116 UPDGRP_FOREACH_SUBGRP (updgrp, subgrp) {
117
118 /*
119 * Skip the subgroups that have coalesce timer running. We will
120 * walk the entire prefix table for those subgroups when the
121 * coalesce timer fires.
122 */
123 if (!subgrp->t_coalesce) {
124 /* An update-group that uses addpath */
125 if (addpath_capable) {
126 /* Look through all of the paths we have
127 * advertised for this rn and
128 * send a withdraw for the ones that are no
129 * longer present */
130 for (adj = ctx->rn->adj_out; adj;
131 adj = adj_next) {
132 adj_next = adj->next;
133
134 if (adj->subgroup == subgrp) {
135 for (ri = ctx->rn->info; ri;
136 ri = ri->next) {
137 if (ri->addpath_tx_id
138 == adj->addpath_tx_id) {
139 break;
140 }
141 }
142
143 if (!ri) {
144 subgroup_process_announce_selected(
145 subgrp, NULL,
146 ctx->rn,
147 adj->addpath_tx_id);
148 }
149 }
150 }
151
152 for (ri = ctx->rn->info; ri; ri = ri->next) {
153 /* Skip the bestpath for now */
154 if (ri == ctx->ri)
155 continue;
156
157 subgroup_process_announce_selected(
158 subgrp, ri, ctx->rn,
159 ri->addpath_tx_id);
160 }
161
162 /* Process the bestpath last so the "show [ip]
163 * bgp neighbor x.x.x.x advertised"
164 * output shows the attributes from the bestpath
165 */
166 if (ctx->ri)
167 subgroup_process_announce_selected(
168 subgrp, ctx->ri, ctx->rn,
169 ctx->ri->addpath_tx_id);
170 }
171
172 /* An update-group that does not use addpath */
173 else {
174 if (ctx->ri) {
175 subgroup_process_announce_selected(
176 subgrp, ctx->ri, ctx->rn,
177 ctx->ri->addpath_tx_id);
178 } else {
179 /* Find the addpath_tx_id of the path we
180 * had advertised and
181 * send a withdraw */
182 for (adj = ctx->rn->adj_out; adj;
183 adj = adj_next) {
184 adj_next = adj->next;
185
186 if (adj->subgroup == subgrp) {
187 subgroup_process_announce_selected(
188 subgrp, NULL,
189 ctx->rn,
190 adj->addpath_tx_id);
191 }
192 }
193 }
194 }
195 }
196 }
197
198 return UPDWALK_CONTINUE;
199 }
200
201 static void subgrp_show_adjq_vty(struct update_subgroup *subgrp,
202 struct vty *vty, u_int8_t flags)
203 {
204 struct bgp_table *table;
205 struct bgp_adj_out *adj;
206 unsigned long output_count;
207 struct bgp_node *rn;
208 int header1 = 1;
209 struct bgp *bgp;
210 int header2 = 1;
211
212 bgp = SUBGRP_INST(subgrp);
213 if (!bgp)
214 return;
215
216 table = bgp->rib[SUBGRP_AFI(subgrp)][SUBGRP_SAFI(subgrp)];
217
218 output_count = 0;
219
220 for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn))
221 for (adj = rn->adj_out; adj; adj = adj->next)
222 if (adj->subgroup == subgrp) {
223 if (header1) {
224 vty_out(vty,
225 "BGP table version is %" PRIu64
226 ", local router ID is %s\n",
227 table->version,
228 inet_ntoa(bgp->router_id));
229 vty_out(vty, BGP_SHOW_SCODE_HEADER);
230 vty_out(vty, BGP_SHOW_OCODE_HEADER);
231 header1 = 0;
232 }
233 if (header2) {
234 vty_out(vty, BGP_SHOW_HEADER);
235 header2 = 0;
236 }
237 if ((flags & UPDWALK_FLAGS_ADVQUEUE) && adj->adv
238 && adj->adv->baa) {
239 route_vty_out_tmp(vty, &rn->p,
240 adj->adv->baa->attr,
241 SUBGRP_SAFI(subgrp),
242 0, NULL);
243 output_count++;
244 }
245 if ((flags & UPDWALK_FLAGS_ADVERTISED)
246 && adj->attr) {
247 route_vty_out_tmp(
248 vty, &rn->p, adj->attr,
249 SUBGRP_SAFI(subgrp), 0, NULL);
250 output_count++;
251 }
252 }
253 if (output_count != 0)
254 vty_out(vty, "\nTotal number of prefixes %ld\n", output_count);
255 }
256
257 static int updgrp_show_adj_walkcb(struct update_group *updgrp, void *arg)
258 {
259 struct updwalk_context *ctx = arg;
260 struct update_subgroup *subgrp;
261 struct vty *vty;
262
263 vty = ctx->vty;
264 UPDGRP_FOREACH_SUBGRP (updgrp, subgrp) {
265 if (ctx->subgrp_id && (ctx->subgrp_id != subgrp->id))
266 continue;
267 vty_out(vty, "update group %" PRIu64 ", subgroup %" PRIu64 "\n",
268 updgrp->id, subgrp->id);
269 subgrp_show_adjq_vty(subgrp, vty, ctx->flags);
270 }
271 return UPDWALK_CONTINUE;
272 }
273
274 static void updgrp_show_adj(struct bgp *bgp, afi_t afi, safi_t safi,
275 struct vty *vty, uint64_t id, u_int8_t flags)
276 {
277 struct updwalk_context ctx;
278 memset(&ctx, 0, sizeof(ctx));
279 ctx.vty = vty;
280 ctx.subgrp_id = id;
281 ctx.flags = flags;
282
283 update_group_af_walk(bgp, afi, safi, updgrp_show_adj_walkcb, &ctx);
284 }
285
286 static int subgroup_coalesce_timer(struct thread *thread)
287 {
288 struct update_subgroup *subgrp;
289
290 subgrp = THREAD_ARG(thread);
291 if (bgp_debug_update(NULL, NULL, subgrp->update_group, 0))
292 zlog_debug("u%" PRIu64 ":s%" PRIu64
293 " announcing routes upon coalesce timer expiry",
294 (SUBGRP_UPDGRP(subgrp))->id, subgrp->id);
295 subgrp->t_coalesce = NULL;
296 subgrp->v_coalesce = 0;
297 subgroup_announce_route(subgrp);
298
299
300 /* While the announce_route() may kick off the route advertisement timer
301 * for
302 * the members of the subgroup, we'd like to send the initial updates
303 * much
304 * faster (i.e., without enforcing MRAI). Also, if there were no routes
305 * to
306 * announce, this is the method currently employed to trigger the EOR.
307 */
308 if (!bgp_update_delay_active(SUBGRP_INST(subgrp))) {
309 struct peer_af *paf;
310 struct peer *peer;
311
312 SUBGRP_FOREACH_PEER (subgrp, paf) {
313 peer = PAF_PEER(paf);
314 BGP_TIMER_OFF(peer->t_routeadv);
315 BGP_TIMER_ON(peer->t_routeadv, bgp_routeadv_timer, 0);
316 }
317 }
318
319 return 0;
320 }
321
322 static int update_group_announce_walkcb(struct update_group *updgrp, void *arg)
323 {
324 struct update_subgroup *subgrp;
325
326 UPDGRP_FOREACH_SUBGRP (updgrp, subgrp) {
327 subgroup_announce_all(subgrp);
328 }
329
330 return UPDWALK_CONTINUE;
331 }
332
333 static int update_group_announce_rrc_walkcb(struct update_group *updgrp,
334 void *arg)
335 {
336 struct update_subgroup *subgrp;
337 afi_t afi;
338 safi_t safi;
339 struct peer *peer;
340
341 afi = UPDGRP_AFI(updgrp);
342 safi = UPDGRP_SAFI(updgrp);
343 peer = UPDGRP_PEER(updgrp);
344
345 /* Only announce if this is a group of route-reflector-clients */
346 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)) {
347 UPDGRP_FOREACH_SUBGRP (updgrp, subgrp) {
348 subgroup_announce_all(subgrp);
349 }
350 }
351
352 return UPDWALK_CONTINUE;
353 }
354
355 /********************
356 * PUBLIC FUNCTIONS
357 ********************/
358
359 /**
360 * Allocate an adj-out object. Do proper initialization of its fields,
361 * primarily its association with the subgroup and the prefix.
362 */
363 struct bgp_adj_out *bgp_adj_out_alloc(struct update_subgroup *subgrp,
364 struct bgp_node *rn,
365 u_int32_t addpath_tx_id)
366 {
367 struct bgp_adj_out *adj;
368
369 adj = XCALLOC(MTYPE_BGP_ADJ_OUT, sizeof(struct bgp_adj_out));
370 adj->subgroup = subgrp;
371 if (rn) {
372 BGP_ADJ_OUT_ADD(rn, adj);
373 bgp_lock_node(rn);
374 adj->rn = rn;
375 }
376
377 adj->addpath_tx_id = addpath_tx_id;
378 TAILQ_INSERT_TAIL(&(subgrp->adjq), adj, subgrp_adj_train);
379 SUBGRP_INCR_STAT(subgrp, adj_count);
380 return adj;
381 }
382
383
384 struct bgp_advertise *
385 bgp_advertise_clean_subgroup(struct update_subgroup *subgrp,
386 struct bgp_adj_out *adj)
387 {
388 struct bgp_advertise *adv;
389 struct bgp_advertise_attr *baa;
390 struct bgp_advertise *next;
391 struct bgp_advertise_fifo *fhead;
392
393 adv = adj->adv;
394 baa = adv->baa;
395 next = NULL;
396
397 if (baa) {
398 fhead = &subgrp->sync->update;
399
400 /* Unlink myself from advertise attribute FIFO. */
401 bgp_advertise_delete(baa, adv);
402
403 /* Fetch next advertise candidate. */
404 next = baa->adv;
405
406 /* Unintern BGP advertise attribute. */
407 bgp_advertise_unintern(subgrp->hash, baa);
408 } else
409 fhead = &subgrp->sync->withdraw;
410
411
412 /* Unlink myself from advertisement FIFO. */
413 BGP_ADV_FIFO_DEL(fhead, adv);
414
415 /* Free memory. */
416 bgp_advertise_free(adj->adv);
417 adj->adv = NULL;
418
419 return next;
420 }
421
422 void bgp_adj_out_set_subgroup(struct bgp_node *rn,
423 struct update_subgroup *subgrp, struct attr *attr,
424 struct bgp_info *binfo)
425 {
426 struct bgp_adj_out *adj = NULL;
427 struct bgp_advertise *adv;
428
429 if (DISABLE_BGP_ANNOUNCE)
430 return;
431
432 /* Look for adjacency information. */
433 adj = adj_lookup(rn, subgrp, binfo->addpath_tx_id);
434
435 if (!adj) {
436 adj = bgp_adj_out_alloc(subgrp, rn, binfo->addpath_tx_id);
437 if (!adj)
438 return;
439 }
440
441 if (adj->adv)
442 bgp_advertise_clean_subgroup(subgrp, adj);
443 adj->adv = bgp_advertise_new();
444
445 adv = adj->adv;
446 adv->rn = rn;
447 assert(adv->binfo == NULL);
448 adv->binfo = bgp_info_lock(binfo); /* bgp_info adj_out reference */
449
450 if (attr)
451 adv->baa = bgp_advertise_intern(subgrp->hash, attr);
452 else
453 adv->baa = baa_new();
454 adv->adj = adj;
455
456 /* Add new advertisement to advertisement attribute list. */
457 bgp_advertise_add(adv->baa, adv);
458
459 /*
460 * If the update adv list is empty, trigger the member peers'
461 * mrai timers so the socket writes can happen.
462 */
463 if (BGP_ADV_FIFO_EMPTY(&subgrp->sync->update)) {
464 struct peer_af *paf;
465
466 SUBGRP_FOREACH_PEER (subgrp, paf) {
467 bgp_adjust_routeadv(PAF_PEER(paf));
468 }
469 }
470
471 BGP_ADV_FIFO_ADD(&subgrp->sync->update, &adv->fifo);
472
473 subgrp->version = max(subgrp->version, rn->version);
474 }
475
476 /* The only time 'withdraw' will be false is if we are sending
477 * the "neighbor x.x.x.x default-originate" default and need to clear
478 * bgp_adj_out for the 0.0.0.0/0 route in the BGP table.
479 */
480 void bgp_adj_out_unset_subgroup(struct bgp_node *rn,
481 struct update_subgroup *subgrp, char withdraw,
482 u_int32_t addpath_tx_id)
483 {
484 struct bgp_adj_out *adj;
485 struct bgp_advertise *adv;
486 bool trigger_write;
487
488 if (DISABLE_BGP_ANNOUNCE)
489 return;
490
491 /* Lookup existing adjacency */
492 if ((adj = adj_lookup(rn, subgrp, addpath_tx_id)) != NULL) {
493 /* Clean up previous advertisement. */
494 if (adj->adv)
495 bgp_advertise_clean_subgroup(subgrp, adj);
496
497 if (adj->attr && withdraw) {
498 /* We need advertisement structure. */
499 adj->adv = bgp_advertise_new();
500 adv = adj->adv;
501 adv->rn = rn;
502 adv->adj = adj;
503
504 /* Note if we need to trigger a packet write */
505 trigger_write =
506 BGP_ADV_FIFO_EMPTY(&subgrp->sync->withdraw);
507
508 /* Add to synchronization entry for withdraw
509 * announcement. */
510 BGP_ADV_FIFO_ADD(&subgrp->sync->withdraw, &adv->fifo);
511
512 if (trigger_write)
513 subgroup_trigger_write(subgrp);
514 } else {
515 /* Remove myself from adjacency. */
516 BGP_ADJ_OUT_DEL(rn, adj);
517
518 /* Free allocated information. */
519 adj_free(adj);
520
521 bgp_unlock_node(rn);
522 }
523 }
524
525 subgrp->version = max(subgrp->version, rn->version);
526 }
527
528 void bgp_adj_out_remove_subgroup(struct bgp_node *rn, struct bgp_adj_out *adj,
529 struct update_subgroup *subgrp)
530 {
531 if (adj->attr)
532 bgp_attr_unintern(&adj->attr);
533
534 if (adj->adv)
535 bgp_advertise_clean_subgroup(subgrp, adj);
536
537 BGP_ADJ_OUT_DEL(rn, adj);
538 adj_free(adj);
539 }
540
541 /*
542 * Go through all the routes and clean up the adj/adv structures corresponding
543 * to the subgroup.
544 */
545 void subgroup_clear_table(struct update_subgroup *subgrp)
546 {
547 struct bgp_adj_out *aout, *taout;
548
549 SUBGRP_FOREACH_ADJ_SAFE (subgrp, aout, taout) {
550 struct bgp_node *rn = aout->rn;
551 bgp_adj_out_remove_subgroup(rn, aout, subgrp);
552 bgp_unlock_node(rn);
553 }
554 }
555
556 /*
557 * subgroup_announce_table
558 */
559 void subgroup_announce_table(struct update_subgroup *subgrp,
560 struct bgp_table *table)
561 {
562 struct bgp_node *rn;
563 struct bgp_info *ri;
564 struct attr attr;
565 struct peer *peer;
566 afi_t afi;
567 safi_t safi;
568 int addpath_capable;
569
570 peer = SUBGRP_PEER(subgrp);
571 afi = SUBGRP_AFI(subgrp);
572 safi = SUBGRP_SAFI(subgrp);
573 addpath_capable = bgp_addpath_encode_tx(peer, afi, safi);
574
575 if (safi == SAFI_LABELED_UNICAST)
576 safi = SAFI_UNICAST;
577
578 if (!table)
579 table = peer->bgp->rib[afi][safi];
580
581 if (safi != SAFI_MPLS_VPN && safi != SAFI_ENCAP && safi != SAFI_EVPN
582 && CHECK_FLAG(peer->af_flags[afi][safi],
583 PEER_FLAG_DEFAULT_ORIGINATE))
584 subgroup_default_originate(subgrp, 0);
585
586 for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn))
587 for (ri = rn->info; ri; ri = ri->next)
588
589 if (CHECK_FLAG(ri->flags, BGP_INFO_SELECTED)
590 || (addpath_capable
591 && bgp_addpath_tx_path(peer, afi, safi, ri))) {
592 if (subgroup_announce_check(rn, ri, subgrp,
593 &rn->p, &attr))
594 bgp_adj_out_set_subgroup(rn, subgrp,
595 &attr, ri);
596 else
597 bgp_adj_out_unset_subgroup(
598 rn, subgrp, 1,
599 ri->addpath_tx_id);
600 }
601
602 /*
603 * We walked through the whole table -- make sure our version number
604 * is consistent with the one on the table. This should allow
605 * subgroups to merge sooner if a peer comes up when the route node
606 * with the largest version is no longer in the table. This also
607 * covers the pathological case where all routes in the table have
608 * now been deleted.
609 */
610 subgrp->version = max(subgrp->version, table->version);
611
612 /*
613 * Start a task to merge the subgroup if necessary.
614 */
615 update_subgroup_trigger_merge_check(subgrp, 0);
616 }
617
618 /*
619 * subgroup_announce_route
620 *
621 * Refresh all routes out to a subgroup.
622 */
623 void subgroup_announce_route(struct update_subgroup *subgrp)
624 {
625 struct bgp_node *rn;
626 struct bgp_table *table;
627 struct peer *onlypeer;
628
629 if (update_subgroup_needs_refresh(subgrp)) {
630 update_subgroup_set_needs_refresh(subgrp, 0);
631 }
632
633 /*
634 * First update is deferred until ORF or ROUTE-REFRESH is received
635 */
636 onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ? (SUBGRP_PFIRST(subgrp))->peer
637 : NULL);
638 if (onlypeer && CHECK_FLAG(onlypeer->af_sflags[SUBGRP_AFI(subgrp)]
639 [SUBGRP_SAFI(subgrp)],
640 PEER_STATUS_ORF_WAIT_REFRESH))
641 return;
642
643 if (SUBGRP_SAFI(subgrp) != SAFI_MPLS_VPN
644 && SUBGRP_SAFI(subgrp) != SAFI_ENCAP
645 && SUBGRP_SAFI(subgrp) != SAFI_EVPN)
646 subgroup_announce_table(subgrp, NULL);
647 else
648 for (rn = bgp_table_top(update_subgroup_rib(subgrp)); rn;
649 rn = bgp_route_next(rn))
650 if ((table = (rn->info)) != NULL)
651 subgroup_announce_table(subgrp, table);
652 }
653
654 void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw)
655 {
656 struct bgp *bgp;
657 struct attr attr;
658 struct aspath *aspath;
659 struct prefix p;
660 struct peer *from;
661 struct bgp_node *rn;
662 struct bgp_info *ri;
663 struct peer *peer;
664 int ret = RMAP_DENYMATCH;
665 afi_t afi;
666 safi_t safi;
667
668 if (!subgrp)
669 return;
670
671 peer = SUBGRP_PEER(subgrp);
672 afi = SUBGRP_AFI(subgrp);
673 safi = SUBGRP_SAFI(subgrp);
674
675 if (!(afi == AFI_IP || afi == AFI_IP6))
676 return;
677
678 bgp = peer->bgp;
679 from = bgp->peer_self;
680
681 bgp_attr_default_set(&attr, BGP_ORIGIN_IGP);
682 aspath = attr.aspath;
683
684 attr.local_pref = bgp->default_local_pref;
685
686 memset(&p, 0, sizeof(p));
687 p.family = afi2family(afi);
688 p.prefixlen = 0;
689
690 if ((afi == AFI_IP6) || peer_cap_enhe(peer, afi, safi)) {
691 /* IPv6 global nexthop must be included. */
692 attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
693
694 /* If the peer is on shared nextwork and we have link-local
695 nexthop set it. */
696 if (peer->shared_network
697 && !IN6_IS_ADDR_UNSPECIFIED(&peer->nexthop.v6_local))
698 attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
699 }
700
701 if (peer->default_rmap[afi][safi].name) {
702 SET_FLAG(bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
703 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn;
704 rn = bgp_route_next(rn)) {
705 for (ri = rn->info; ri; ri = ri->next) {
706 struct attr dummy_attr;
707 struct bgp_info info;
708
709 /* Provide dummy so the route-map can't modify
710 * the attributes */
711 bgp_attr_dup(&dummy_attr, ri->attr);
712 info.peer = ri->peer;
713 info.attr = &dummy_attr;
714
715 ret = route_map_apply(
716 peer->default_rmap[afi][safi].map,
717 &rn->p, RMAP_BGP, &info);
718
719 /* The route map might have set attributes. If
720 * we don't flush them
721 * here, they will be leaked. */
722 bgp_attr_flush(&dummy_attr);
723 if (ret != RMAP_DENYMATCH)
724 break;
725 }
726 if (ret != RMAP_DENYMATCH)
727 break;
728 }
729 bgp->peer_self->rmap_type = 0;
730
731 if (ret == RMAP_DENYMATCH)
732 withdraw = 1;
733 }
734
735 if (withdraw) {
736 if (CHECK_FLAG(subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
737 subgroup_default_withdraw_packet(subgrp);
738 UNSET_FLAG(subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE);
739 } else {
740 if (!CHECK_FLAG(subgrp->sflags,
741 SUBGRP_STATUS_DEFAULT_ORIGINATE)) {
742
743 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
744 bgp_attr_add_gshut_community(&attr);
745 }
746
747 SET_FLAG(subgrp->sflags,
748 SUBGRP_STATUS_DEFAULT_ORIGINATE);
749 subgroup_default_update_packet(subgrp, &attr, from);
750
751 /* The 'neighbor x.x.x.x default-originate' default will
752 * act as an
753 * implicit withdraw for any previous UPDATEs sent for
754 * 0.0.0.0/0 so
755 * clear adj_out for the 0.0.0.0/0 prefix in the BGP
756 * table.
757 */
758 memset(&p, 0, sizeof(p));
759 p.family = afi2family(afi);
760 p.prefixlen = 0;
761
762 rn = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi,
763 &p, NULL);
764 bgp_adj_out_unset_subgroup(
765 rn, subgrp, 0,
766 BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE);
767 }
768 }
769
770 aspath_unintern(&aspath);
771 }
772
773 /*
774 * Announce the BGP table to a subgroup.
775 *
776 * At startup, we try to optimize route announcement by coalescing the
777 * peer-up events. This is done only the first time - from then on,
778 * subgrp->v_coalesce will be set to zero and the normal logic
779 * prevails.
780 */
781 void subgroup_announce_all(struct update_subgroup *subgrp)
782 {
783 if (!subgrp)
784 return;
785
786 /*
787 * If coalesce timer value is not set, announce routes immediately.
788 */
789 if (!subgrp->v_coalesce) {
790 if (bgp_debug_update(NULL, NULL, subgrp->update_group, 0))
791 zlog_debug("u%" PRIu64 ":s%" PRIu64
792 " announcing all routes",
793 subgrp->update_group->id, subgrp->id);
794 subgroup_announce_route(subgrp);
795 return;
796 }
797
798 /*
799 * We should wait for the coalesce timer. Arm the timer if not done.
800 */
801 if (!subgrp->t_coalesce) {
802 thread_add_timer_msec(bm->master, subgroup_coalesce_timer,
803 subgrp, subgrp->v_coalesce,
804 &subgrp->t_coalesce);
805 }
806 }
807
808 /*
809 * Go through all update subgroups and set up the adv queue for the
810 * input route.
811 */
812 void group_announce_route(struct bgp *bgp, afi_t afi, safi_t safi,
813 struct bgp_node *rn, struct bgp_info *ri)
814 {
815 struct updwalk_context ctx;
816 ctx.ri = ri;
817 ctx.rn = rn;
818 update_group_af_walk(bgp, afi, safi, group_announce_route_walkcb, &ctx);
819 }
820
821 void update_group_show_adj_queue(struct bgp *bgp, afi_t afi, safi_t safi,
822 struct vty *vty, uint64_t id)
823 {
824 updgrp_show_adj(bgp, afi, safi, vty, id, UPDWALK_FLAGS_ADVQUEUE);
825 }
826
827 void update_group_show_advertised(struct bgp *bgp, afi_t afi, safi_t safi,
828 struct vty *vty, uint64_t id)
829 {
830 updgrp_show_adj(bgp, afi, safi, vty, id, UPDWALK_FLAGS_ADVERTISED);
831 }
832
833 void update_group_announce(struct bgp *bgp)
834 {
835 update_group_walk(bgp, update_group_announce_walkcb, NULL);
836 }
837
838 void update_group_announce_rrclients(struct bgp *bgp)
839 {
840 update_group_walk(bgp, update_group_announce_rrc_walkcb, NULL);
841 }