]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_updgrp.c
Merge pull request #10356 from opensourcerouting/pim6-adjust-20220117
[mirror_frr.git] / bgpd / bgp_updgrp.c
1 /**
2 * bgp_updgrp.c: BGP update group structures
3 *
4 * @copyright Copyright (C) 2014 Cumulus Networks, Inc.
5 *
6 * @author Avneesh Sachdev <avneesh@sproute.net>
7 * @author Rajesh Varadarajan <rajesh@sproute.net>
8 * @author Pradosh Mohapatra <pradosh@sproute.net>
9 *
10 * This file is part of GNU Zebra.
11 *
12 * GNU Zebra is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2, or (at your option) any
15 * later version.
16 *
17 * GNU Zebra is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; see the file COPYING; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
27 #include <zebra.h>
28
29 #include "prefix.h"
30 #include "thread.h"
31 #include "buffer.h"
32 #include "stream.h"
33 #include "command.h"
34 #include "sockunion.h"
35 #include "network.h"
36 #include "memory.h"
37 #include "filter.h"
38 #include "routemap.h"
39 #include "log.h"
40 #include "plist.h"
41 #include "linklist.h"
42 #include "workqueue.h"
43 #include "hash.h"
44 #include "jhash.h"
45 #include "queue.h"
46
47 #include "bgpd/bgpd.h"
48 #include "bgpd/bgp_table.h"
49 #include "bgpd/bgp_debug.h"
50 #include "bgpd/bgp_errors.h"
51 #include "bgpd/bgp_fsm.h"
52 #include "bgpd/bgp_addpath.h"
53 #include "bgpd/bgp_advertise.h"
54 #include "bgpd/bgp_packet.h"
55 #include "bgpd/bgp_updgrp.h"
56 #include "bgpd/bgp_route.h"
57 #include "bgpd/bgp_filter.h"
58 #include "bgpd/bgp_io.h"
59
60 /********************
61 * PRIVATE FUNCTIONS
62 ********************/
63
64 /**
65 * assign a unique ID to update group and subgroup. Mostly for display/
66 * debugging purposes. It's a 64-bit space - used leisurely without a
67 * worry about its wrapping and about filling gaps. While at it, timestamp
68 * the creation.
69 */
70 static void update_group_checkin(struct update_group *updgrp)
71 {
72 updgrp->id = ++bm->updgrp_idspace;
73 updgrp->uptime = bgp_clock();
74 }
75
76 static void update_subgroup_checkin(struct update_subgroup *subgrp,
77 struct update_group *updgrp)
78 {
79 subgrp->id = ++bm->subgrp_idspace;
80 subgrp->uptime = bgp_clock();
81 }
82
83 static void sync_init(struct update_subgroup *subgrp,
84 struct update_group *updgrp)
85 {
86 struct peer *peer = UPDGRP_PEER(updgrp);
87
88 subgrp->sync =
89 XCALLOC(MTYPE_BGP_SYNCHRONISE, sizeof(struct bgp_synchronize));
90 bgp_adv_fifo_init(&subgrp->sync->update);
91 bgp_adv_fifo_init(&subgrp->sync->withdraw);
92 bgp_adv_fifo_init(&subgrp->sync->withdraw_low);
93 subgrp->hash =
94 hash_create(baa_hash_key, baa_hash_cmp, "BGP SubGroup Hash");
95
96 /* We use a larger buffer for subgrp->work in the event that:
97 * - We RX a BGP_UPDATE where the attributes alone are just
98 * under 4096 or 65535 (if Extended Message capability negotiated).
99 * - The user configures an outbound route-map that does many as-path
100 * prepends or adds many communities. At most they can have
101 * CMD_ARGC_MAX
102 * args in a route-map so there is a finite limit on how large they
103 * can
104 * make the attributes.
105 *
106 * Having a buffer with BGP_MAX_PACKET_SIZE_OVERFLOW allows us to avoid
107 * bounds
108 * checking for every single attribute as we construct an UPDATE.
109 */
110 subgrp->work = stream_new(peer->max_packet_size
111 + BGP_MAX_PACKET_SIZE_OVERFLOW);
112 subgrp->scratch = stream_new(peer->max_packet_size);
113 }
114
115 static void sync_delete(struct update_subgroup *subgrp)
116 {
117 XFREE(MTYPE_BGP_SYNCHRONISE, subgrp->sync);
118 if (subgrp->hash)
119 hash_free(subgrp->hash);
120 subgrp->hash = NULL;
121 if (subgrp->work)
122 stream_free(subgrp->work);
123 subgrp->work = NULL;
124 if (subgrp->scratch)
125 stream_free(subgrp->scratch);
126 subgrp->scratch = NULL;
127 }
128
129 /**
130 * conf_copy
131 *
132 * copy only those fields that are relevant to update group match
133 */
134 static void conf_copy(struct peer *dst, struct peer *src, afi_t afi,
135 safi_t safi)
136 {
137 struct bgp_filter *srcfilter;
138 struct bgp_filter *dstfilter;
139
140 srcfilter = &src->filter[afi][safi];
141 dstfilter = &dst->filter[afi][safi];
142
143 dst->bgp = src->bgp;
144 dst->sort = src->sort;
145 dst->as = src->as;
146 dst->v_routeadv = src->v_routeadv;
147 dst->flags = src->flags;
148 dst->af_flags[afi][safi] = src->af_flags[afi][safi];
149 dst->pmax_out[afi][safi] = src->pmax_out[afi][safi];
150 dst->max_packet_size = src->max_packet_size;
151 XFREE(MTYPE_BGP_PEER_HOST, dst->host);
152
153 dst->host = XSTRDUP(MTYPE_BGP_PEER_HOST, src->host);
154 dst->cap = src->cap;
155 dst->af_cap[afi][safi] = src->af_cap[afi][safi];
156 dst->afc_nego[afi][safi] = src->afc_nego[afi][safi];
157 dst->orf_plist[afi][safi] = src->orf_plist[afi][safi];
158 dst->addpath_type[afi][safi] = src->addpath_type[afi][safi];
159 dst->local_as = src->local_as;
160 dst->change_local_as = src->change_local_as;
161 dst->shared_network = src->shared_network;
162 memcpy(&(dst->nexthop), &(src->nexthop), sizeof(struct bgp_nexthop));
163
164 dst->group = src->group;
165
166 if (src->default_rmap[afi][safi].name) {
167 dst->default_rmap[afi][safi].name =
168 XSTRDUP(MTYPE_ROUTE_MAP_NAME,
169 src->default_rmap[afi][safi].name);
170 dst->default_rmap[afi][safi].map =
171 src->default_rmap[afi][safi].map;
172 }
173
174 if (DISTRIBUTE_OUT_NAME(srcfilter)) {
175 DISTRIBUTE_OUT_NAME(dstfilter) = XSTRDUP(
176 MTYPE_BGP_FILTER_NAME, DISTRIBUTE_OUT_NAME(srcfilter));
177 DISTRIBUTE_OUT(dstfilter) = DISTRIBUTE_OUT(srcfilter);
178 }
179
180 if (PREFIX_LIST_OUT_NAME(srcfilter)) {
181 PREFIX_LIST_OUT_NAME(dstfilter) = XSTRDUP(
182 MTYPE_BGP_FILTER_NAME, PREFIX_LIST_OUT_NAME(srcfilter));
183 PREFIX_LIST_OUT(dstfilter) = PREFIX_LIST_OUT(srcfilter);
184 }
185
186 if (FILTER_LIST_OUT_NAME(srcfilter)) {
187 FILTER_LIST_OUT_NAME(dstfilter) = XSTRDUP(
188 MTYPE_BGP_FILTER_NAME, FILTER_LIST_OUT_NAME(srcfilter));
189 FILTER_LIST_OUT(dstfilter) = FILTER_LIST_OUT(srcfilter);
190 }
191
192 if (ROUTE_MAP_OUT_NAME(srcfilter)) {
193 ROUTE_MAP_OUT_NAME(dstfilter) = XSTRDUP(
194 MTYPE_BGP_FILTER_NAME, ROUTE_MAP_OUT_NAME(srcfilter));
195 ROUTE_MAP_OUT(dstfilter) = ROUTE_MAP_OUT(srcfilter);
196 }
197
198 if (UNSUPPRESS_MAP_NAME(srcfilter)) {
199 UNSUPPRESS_MAP_NAME(dstfilter) = XSTRDUP(
200 MTYPE_BGP_FILTER_NAME, UNSUPPRESS_MAP_NAME(srcfilter));
201 UNSUPPRESS_MAP(dstfilter) = UNSUPPRESS_MAP(srcfilter);
202 }
203
204 if (ADVERTISE_MAP_NAME(srcfilter)) {
205 ADVERTISE_MAP_NAME(dstfilter) = XSTRDUP(
206 MTYPE_BGP_FILTER_NAME, ADVERTISE_MAP_NAME(srcfilter));
207 ADVERTISE_MAP(dstfilter) = ADVERTISE_MAP(srcfilter);
208 ADVERTISE_CONDITION(dstfilter) = ADVERTISE_CONDITION(srcfilter);
209 }
210
211 if (CONDITION_MAP_NAME(srcfilter)) {
212 CONDITION_MAP_NAME(dstfilter) = XSTRDUP(
213 MTYPE_BGP_FILTER_NAME, CONDITION_MAP_NAME(srcfilter));
214 CONDITION_MAP(dstfilter) = CONDITION_MAP(srcfilter);
215 }
216 }
217
218 /**
219 * since we did a bunch of XSTRDUP's in conf_copy, time to free them up
220 */
221 static void conf_release(struct peer *src, afi_t afi, safi_t safi)
222 {
223 struct bgp_filter *srcfilter;
224
225 srcfilter = &src->filter[afi][safi];
226
227 XFREE(MTYPE_ROUTE_MAP_NAME, src->default_rmap[afi][safi].name);
228
229 XFREE(MTYPE_BGP_FILTER_NAME, srcfilter->dlist[FILTER_OUT].name);
230
231 XFREE(MTYPE_BGP_FILTER_NAME, srcfilter->plist[FILTER_OUT].name);
232
233 XFREE(MTYPE_BGP_FILTER_NAME, srcfilter->aslist[FILTER_OUT].name);
234
235 XFREE(MTYPE_BGP_FILTER_NAME, srcfilter->map[RMAP_OUT].name);
236
237 XFREE(MTYPE_BGP_FILTER_NAME, srcfilter->usmap.name);
238
239 XFREE(MTYPE_BGP_FILTER_NAME, srcfilter->advmap.aname);
240
241 XFREE(MTYPE_BGP_FILTER_NAME, srcfilter->advmap.cname);
242
243 XFREE(MTYPE_BGP_PEER_HOST, src->host);
244 }
245
246 static void peer2_updgrp_copy(struct update_group *updgrp, struct peer_af *paf)
247 {
248 struct peer *src;
249 struct peer *dst;
250
251 if (!updgrp || !paf)
252 return;
253
254 src = paf->peer;
255 dst = updgrp->conf;
256 if (!src || !dst)
257 return;
258
259 updgrp->afi = paf->afi;
260 updgrp->safi = paf->safi;
261 updgrp->afid = paf->afid;
262 updgrp->bgp = src->bgp;
263
264 conf_copy(dst, src, paf->afi, paf->safi);
265 }
266
267 /**
268 * auxiliary functions to maintain the hash table.
269 * - updgrp_hash_alloc - to create a new entry, passed to hash_get
270 * - updgrp_hash_key_make - makes the key for update group search
271 * - updgrp_hash_cmp - compare two update groups.
272 */
273 static void *updgrp_hash_alloc(void *p)
274 {
275 struct update_group *updgrp;
276 const struct update_group *in;
277
278 in = (const struct update_group *)p;
279 updgrp = XCALLOC(MTYPE_BGP_UPDGRP, sizeof(struct update_group));
280 memcpy(updgrp, in, sizeof(struct update_group));
281 updgrp->conf = XCALLOC(MTYPE_BGP_PEER, sizeof(struct peer));
282 conf_copy(updgrp->conf, in->conf, in->afi, in->safi);
283 return updgrp;
284 }
285
286 /**
287 * The hash value for a peer is computed from the following variables:
288 * v = f(
289 * 1. IBGP (1) or EBGP (2)
290 * 2. FLAGS based on configuration:
291 * LOCAL_AS_NO_PREPEND
292 * LOCAL_AS_REPLACE_AS
293 * 3. AF_FLAGS based on configuration:
294 * Refer to definition in bgp_updgrp.h
295 * 4. (AF-independent) Capability flags:
296 * AS4_RCV capability
297 * 5. (AF-dependent) Capability flags:
298 * ORF_PREFIX_SM_RCV (peer can send prefix ORF)
299 * 6. MRAI
300 * 7. peer-group name
301 * 8. Outbound route-map name (neighbor route-map <> out)
302 * 9. Outbound distribute-list name (neighbor distribute-list <> out)
303 * 10. Outbound prefix-list name (neighbor prefix-list <> out)
304 * 11. Outbound as-list name (neighbor filter-list <> out)
305 * 12. Unsuppress map name (neighbor unsuppress-map <>)
306 * 13. default rmap name (neighbor default-originate route-map <>)
307 * 14. encoding both global and link-local nexthop?
308 * 15. If peer is configured to be a lonesoul, peer ip address
309 * 16. Local-as should match, if configured.
310 * 17. maximum-prefix-out
311 * )
312 */
313 static unsigned int updgrp_hash_key_make(const void *p)
314 {
315 const struct update_group *updgrp;
316 const struct peer *peer;
317 const struct bgp_filter *filter;
318 uint32_t flags;
319 uint32_t key;
320 afi_t afi;
321 safi_t safi;
322
323 #define SEED1 999331
324 #define SEED2 2147483647
325
326 updgrp = p;
327 peer = updgrp->conf;
328 afi = updgrp->afi;
329 safi = updgrp->safi;
330 flags = peer->af_flags[afi][safi];
331 filter = &peer->filter[afi][safi];
332
333 key = 0;
334
335 key = jhash_1word(peer->sort, key); /* EBGP or IBGP */
336 key = jhash_1word((peer->flags & PEER_UPDGRP_FLAGS), key);
337 key = jhash_1word((flags & PEER_UPDGRP_AF_FLAGS), key);
338 key = jhash_1word((uint32_t)peer->addpath_type[afi][safi], key);
339 key = jhash_1word((peer->cap & PEER_UPDGRP_CAP_FLAGS), key);
340 key = jhash_1word((peer->af_cap[afi][safi] & PEER_UPDGRP_AF_CAP_FLAGS),
341 key);
342 key = jhash_1word(peer->v_routeadv, key);
343 key = jhash_1word(peer->change_local_as, key);
344 key = jhash_1word(peer->max_packet_size, key);
345 key = jhash_1word(peer->pmax_out[afi][safi], key);
346
347 if (peer->group)
348 key = jhash_1word(jhash(peer->group->name,
349 strlen(peer->group->name), SEED1),
350 key);
351
352 if (filter->map[RMAP_OUT].name)
353 key = jhash_1word(jhash(filter->map[RMAP_OUT].name,
354 strlen(filter->map[RMAP_OUT].name),
355 SEED1),
356 key);
357
358 if (filter->dlist[FILTER_OUT].name)
359 key = jhash_1word(jhash(filter->dlist[FILTER_OUT].name,
360 strlen(filter->dlist[FILTER_OUT].name),
361 SEED1),
362 key);
363
364 if (filter->plist[FILTER_OUT].name)
365 key = jhash_1word(jhash(filter->plist[FILTER_OUT].name,
366 strlen(filter->plist[FILTER_OUT].name),
367 SEED1),
368 key);
369
370 if (filter->aslist[FILTER_OUT].name)
371 key = jhash_1word(jhash(filter->aslist[FILTER_OUT].name,
372 strlen(filter->aslist[FILTER_OUT].name),
373 SEED1),
374 key);
375
376 if (filter->usmap.name)
377 key = jhash_1word(jhash(filter->usmap.name,
378 strlen(filter->usmap.name), SEED1),
379 key);
380
381 if (filter->advmap.aname)
382 key = jhash_1word(jhash(filter->advmap.aname,
383 strlen(filter->advmap.aname), SEED1),
384 key);
385
386 if (peer->default_rmap[afi][safi].name)
387 key = jhash_1word(
388 jhash(peer->default_rmap[afi][safi].name,
389 strlen(peer->default_rmap[afi][safi].name),
390 SEED1),
391 key);
392
393 /* If peer is on a shared network and is exchanging IPv6 prefixes,
394 * it needs to include link-local address. That's different from
395 * non-shared-network peers (nexthop encoded with 32 bytes vs 16
396 * bytes). We create different update groups to take care of that.
397 */
398 key = jhash_1word(
399 (peer->shared_network && peer_afi_active_nego(peer, AFI_IP6)),
400 key);
401
402 /*
403 * There are certain peers that must get their own update-group:
404 * - lonesoul peers
405 * - peers that negotiated ORF
406 * - maximum-prefix-out is set
407 */
408 if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL)
409 || CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
410 || CHECK_FLAG(peer->af_cap[afi][safi],
411 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
412 || CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT))
413 key = jhash_1word(jhash(peer->host, strlen(peer->host), SEED2),
414 key);
415
416 return key;
417 }
418
419 static bool updgrp_hash_cmp(const void *p1, const void *p2)
420 {
421 const struct update_group *grp1;
422 const struct update_group *grp2;
423 const struct peer *pe1;
424 const struct peer *pe2;
425 uint32_t flags1;
426 uint32_t flags2;
427 const struct bgp_filter *fl1;
428 const struct bgp_filter *fl2;
429 afi_t afi;
430 safi_t safi;
431
432 if (!p1 || !p2)
433 return false;
434
435 grp1 = p1;
436 grp2 = p2;
437 pe1 = grp1->conf;
438 pe2 = grp2->conf;
439 afi = grp1->afi;
440 safi = grp1->safi;
441 flags1 = pe1->af_flags[afi][safi];
442 flags2 = pe2->af_flags[afi][safi];
443 fl1 = &pe1->filter[afi][safi];
444 fl2 = &pe2->filter[afi][safi];
445
446 /* put EBGP and IBGP peers in different update groups */
447 if (pe1->sort != pe2->sort)
448 return false;
449
450 /* check peer flags */
451 if ((pe1->flags & PEER_UPDGRP_FLAGS)
452 != (pe2->flags & PEER_UPDGRP_FLAGS))
453 return false;
454
455 /* If there is 'local-as' configured, it should match. */
456 if (pe1->change_local_as != pe2->change_local_as)
457 return false;
458
459 if (pe1->pmax_out[afi][safi] != pe2->pmax_out[afi][safi])
460 return false;
461
462 /* flags like route reflector client */
463 if ((flags1 & PEER_UPDGRP_AF_FLAGS) != (flags2 & PEER_UPDGRP_AF_FLAGS))
464 return false;
465
466 if (pe1->addpath_type[afi][safi] != pe2->addpath_type[afi][safi])
467 return false;
468
469 if ((pe1->cap & PEER_UPDGRP_CAP_FLAGS)
470 != (pe2->cap & PEER_UPDGRP_CAP_FLAGS))
471 return false;
472
473 if ((pe1->af_cap[afi][safi] & PEER_UPDGRP_AF_CAP_FLAGS)
474 != (pe2->af_cap[afi][safi] & PEER_UPDGRP_AF_CAP_FLAGS))
475 return false;
476
477 if (pe1->v_routeadv != pe2->v_routeadv)
478 return false;
479
480 if (pe1->group != pe2->group)
481 return false;
482
483 /* route-map names should be the same */
484 if ((fl1->map[RMAP_OUT].name && !fl2->map[RMAP_OUT].name)
485 || (!fl1->map[RMAP_OUT].name && fl2->map[RMAP_OUT].name)
486 || (fl1->map[RMAP_OUT].name && fl2->map[RMAP_OUT].name
487 && strcmp(fl1->map[RMAP_OUT].name, fl2->map[RMAP_OUT].name)))
488 return false;
489
490 if ((fl1->dlist[FILTER_OUT].name && !fl2->dlist[FILTER_OUT].name)
491 || (!fl1->dlist[FILTER_OUT].name && fl2->dlist[FILTER_OUT].name)
492 || (fl1->dlist[FILTER_OUT].name && fl2->dlist[FILTER_OUT].name
493 && strcmp(fl1->dlist[FILTER_OUT].name,
494 fl2->dlist[FILTER_OUT].name)))
495 return false;
496
497 if ((fl1->plist[FILTER_OUT].name && !fl2->plist[FILTER_OUT].name)
498 || (!fl1->plist[FILTER_OUT].name && fl2->plist[FILTER_OUT].name)
499 || (fl1->plist[FILTER_OUT].name && fl2->plist[FILTER_OUT].name
500 && strcmp(fl1->plist[FILTER_OUT].name,
501 fl2->plist[FILTER_OUT].name)))
502 return false;
503
504 if ((fl1->aslist[FILTER_OUT].name && !fl2->aslist[FILTER_OUT].name)
505 || (!fl1->aslist[FILTER_OUT].name && fl2->aslist[FILTER_OUT].name)
506 || (fl1->aslist[FILTER_OUT].name && fl2->aslist[FILTER_OUT].name
507 && strcmp(fl1->aslist[FILTER_OUT].name,
508 fl2->aslist[FILTER_OUT].name)))
509 return false;
510
511 if ((fl1->usmap.name && !fl2->usmap.name)
512 || (!fl1->usmap.name && fl2->usmap.name)
513 || (fl1->usmap.name && fl2->usmap.name
514 && strcmp(fl1->usmap.name, fl2->usmap.name)))
515 return false;
516
517 if ((fl1->advmap.aname && !fl2->advmap.aname)
518 || (!fl1->advmap.aname && fl2->advmap.aname)
519 || (fl1->advmap.aname && fl2->advmap.aname
520 && strcmp(fl1->advmap.aname, fl2->advmap.aname)))
521 return false;
522
523 if ((pe1->default_rmap[afi][safi].name
524 && !pe2->default_rmap[afi][safi].name)
525 || (!pe1->default_rmap[afi][safi].name
526 && pe2->default_rmap[afi][safi].name)
527 || (pe1->default_rmap[afi][safi].name
528 && pe2->default_rmap[afi][safi].name
529 && strcmp(pe1->default_rmap[afi][safi].name,
530 pe2->default_rmap[afi][safi].name)))
531 return false;
532
533 if ((afi == AFI_IP6) && (pe1->shared_network != pe2->shared_network))
534 return false;
535
536 if ((CHECK_FLAG(pe1->flags, PEER_FLAG_LONESOUL)
537 || CHECK_FLAG(pe1->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
538 || CHECK_FLAG(pe1->af_cap[afi][safi],
539 PEER_CAP_ORF_PREFIX_SM_OLD_RCV))
540 && !sockunion_same(&pe1->su, &pe2->su))
541 return false;
542
543 return true;
544 }
545
546 static void peer_lonesoul_or_not(struct peer *peer, int set)
547 {
548 /* no change in status? */
549 if (set == (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL) > 0))
550 return;
551
552 if (set)
553 SET_FLAG(peer->flags, PEER_FLAG_LONESOUL);
554 else
555 UNSET_FLAG(peer->flags, PEER_FLAG_LONESOUL);
556
557 update_group_adjust_peer_afs(peer);
558 }
559
560 /*
561 * subgroup_total_packets_enqueued
562 *
563 * Returns the total number of packets enqueued to a subgroup.
564 */
565 static unsigned int
566 subgroup_total_packets_enqueued(struct update_subgroup *subgrp)
567 {
568 struct bpacket *pkt;
569
570 pkt = bpacket_queue_last(SUBGRP_PKTQ(subgrp));
571
572 return pkt->ver - 1;
573 }
574
575 static int update_group_show_walkcb(struct update_group *updgrp, void *arg)
576 {
577 struct updwalk_context *ctx = arg;
578 struct vty *vty;
579 struct update_subgroup *subgrp;
580 struct peer_af *paf;
581 struct bgp_filter *filter;
582 struct peer *peer = UPDGRP_PEER(updgrp);
583 int match = 0;
584
585 if (!ctx)
586 return CMD_SUCCESS;
587
588 if (ctx->subgrp_id) {
589 UPDGRP_FOREACH_SUBGRP (updgrp, subgrp) {
590 if (ctx->subgrp_id && (ctx->subgrp_id != subgrp->id))
591 continue;
592 else {
593 match = 1;
594 break;
595 }
596 }
597 } else {
598 match = 1;
599 }
600
601 if (!match) {
602 /* Since this routine is invoked from a walk, we cannot signal
603 * any */
604 /* error here, can only return. */
605 return CMD_SUCCESS;
606 }
607
608 vty = ctx->vty;
609
610 vty_out(vty, "Update-group %" PRIu64 ":\n", updgrp->id);
611 vty_out(vty, " Created: %s", timestamp_string(updgrp->uptime));
612 filter = &updgrp->conf->filter[updgrp->afi][updgrp->safi];
613 if (filter->map[RMAP_OUT].name)
614 vty_out(vty, " Outgoing route map: %s\n",
615 filter->map[RMAP_OUT].name);
616 vty_out(vty, " MRAI value (seconds): %d\n", updgrp->conf->v_routeadv);
617 if (updgrp->conf->change_local_as)
618 vty_out(vty, " Local AS %u%s%s\n",
619 updgrp->conf->change_local_as,
620 CHECK_FLAG(updgrp->conf->flags,
621 PEER_FLAG_LOCAL_AS_NO_PREPEND)
622 ? " no-prepend"
623 : "",
624 CHECK_FLAG(updgrp->conf->flags,
625 PEER_FLAG_LOCAL_AS_REPLACE_AS)
626 ? " replace-as"
627 : "");
628
629 UPDGRP_FOREACH_SUBGRP (updgrp, subgrp) {
630 if (ctx->subgrp_id && (ctx->subgrp_id != subgrp->id))
631 continue;
632 vty_out(vty, "\n");
633 vty_out(vty, " Update-subgroup %" PRIu64 ":\n", subgrp->id);
634 vty_out(vty, " Created: %s",
635 timestamp_string(subgrp->uptime));
636
637 if (subgrp->split_from.update_group_id
638 || subgrp->split_from.subgroup_id) {
639 vty_out(vty, " Split from group id: %" PRIu64 "\n",
640 subgrp->split_from.update_group_id);
641 vty_out(vty,
642 " Split from subgroup id: %" PRIu64 "\n",
643 subgrp->split_from.subgroup_id);
644 }
645
646 vty_out(vty, " Join events: %u\n", subgrp->join_events);
647 vty_out(vty, " Prune events: %u\n", subgrp->prune_events);
648 vty_out(vty, " Merge events: %u\n", subgrp->merge_events);
649 vty_out(vty, " Split events: %u\n", subgrp->split_events);
650 vty_out(vty, " Update group switch events: %u\n",
651 subgrp->updgrp_switch_events);
652 vty_out(vty, " Peer refreshes combined: %u\n",
653 subgrp->peer_refreshes_combined);
654 vty_out(vty, " Merge checks triggered: %u\n",
655 subgrp->merge_checks_triggered);
656 vty_out(vty, " Coalesce Time: %u%s\n",
657 (UPDGRP_INST(subgrp->update_group))->coalesce_time,
658 subgrp->t_coalesce ? "(Running)" : "");
659 vty_out(vty, " Version: %" PRIu64 "\n", subgrp->version);
660 vty_out(vty, " Packet queue length: %d\n",
661 bpacket_queue_length(SUBGRP_PKTQ(subgrp)));
662 vty_out(vty, " Total packets enqueued: %u\n",
663 subgroup_total_packets_enqueued(subgrp));
664 vty_out(vty, " Packet queue high watermark: %d\n",
665 bpacket_queue_hwm_length(SUBGRP_PKTQ(subgrp)));
666 vty_out(vty, " Adj-out list count: %u\n", subgrp->adj_count);
667 vty_out(vty, " Advertise list: %s\n",
668 advertise_list_is_empty(subgrp) ? "empty"
669 : "not empty");
670 vty_out(vty, " Flags: %s\n",
671 CHECK_FLAG(subgrp->flags, SUBGRP_FLAG_NEEDS_REFRESH)
672 ? "R"
673 : "");
674 if (peer)
675 vty_out(vty, " Max packet size: %d\n",
676 peer->max_packet_size);
677 if (subgrp->peer_count > 0) {
678 vty_out(vty, " Peers:\n");
679 SUBGRP_FOREACH_PEER (subgrp, paf)
680 vty_out(vty, " - %s\n", paf->peer->host);
681 }
682 }
683 return UPDWALK_CONTINUE;
684 }
685
686 /*
687 * Helper function to show the packet queue for each subgroup of update group.
688 * Will be constrained to a particular subgroup id if id !=0
689 */
690 static int updgrp_show_packet_queue_walkcb(struct update_group *updgrp,
691 void *arg)
692 {
693 struct updwalk_context *ctx = arg;
694 struct update_subgroup *subgrp;
695 struct vty *vty;
696
697 vty = ctx->vty;
698 UPDGRP_FOREACH_SUBGRP (updgrp, subgrp) {
699 if (ctx->subgrp_id && (ctx->subgrp_id != subgrp->id))
700 continue;
701 vty_out(vty, "update group %" PRIu64 ", subgroup %" PRIu64 "\n",
702 updgrp->id, subgrp->id);
703 bpacket_queue_show_vty(SUBGRP_PKTQ(subgrp), vty);
704 }
705 return UPDWALK_CONTINUE;
706 }
707
708 /*
709 * Show the packet queue for each subgroup of update group. Will be
710 * constrained to a particular subgroup id if id !=0
711 */
712 void update_group_show_packet_queue(struct bgp *bgp, afi_t afi, safi_t safi,
713 struct vty *vty, uint64_t id)
714 {
715 struct updwalk_context ctx;
716
717 memset(&ctx, 0, sizeof(ctx));
718 ctx.vty = vty;
719 ctx.subgrp_id = id;
720 ctx.flags = 0;
721 update_group_af_walk(bgp, afi, safi, updgrp_show_packet_queue_walkcb,
722 &ctx);
723 }
724
725 static struct update_group *update_group_find(struct peer_af *paf)
726 {
727 struct update_group *updgrp;
728 struct update_group tmp;
729 struct peer tmp_conf;
730
731 if (!peer_established(PAF_PEER(paf)))
732 return NULL;
733
734 memset(&tmp, 0, sizeof(tmp));
735 memset(&tmp_conf, 0, sizeof(tmp_conf));
736 tmp.conf = &tmp_conf;
737 peer2_updgrp_copy(&tmp, paf);
738
739 updgrp = hash_lookup(paf->peer->bgp->update_groups[paf->afid], &tmp);
740 conf_release(&tmp_conf, paf->afi, paf->safi);
741 return updgrp;
742 }
743
744 static struct update_group *update_group_create(struct peer_af *paf)
745 {
746 struct update_group *updgrp;
747 struct update_group tmp;
748 struct peer tmp_conf;
749
750 memset(&tmp, 0, sizeof(tmp));
751 memset(&tmp_conf, 0, sizeof(tmp_conf));
752 tmp.conf = &tmp_conf;
753 peer2_updgrp_copy(&tmp, paf);
754
755 updgrp = hash_get(paf->peer->bgp->update_groups[paf->afid], &tmp,
756 updgrp_hash_alloc);
757 if (!updgrp)
758 return NULL;
759 update_group_checkin(updgrp);
760
761 if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
762 zlog_debug("create update group %" PRIu64, updgrp->id);
763
764 UPDGRP_GLOBAL_STAT(updgrp, updgrps_created) += 1;
765
766 conf_release(&tmp_conf, paf->afi, paf->safi);
767 return updgrp;
768 }
769
770 static void update_group_delete(struct update_group *updgrp)
771 {
772 if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
773 zlog_debug("delete update group %" PRIu64, updgrp->id);
774
775 UPDGRP_GLOBAL_STAT(updgrp, updgrps_deleted) += 1;
776
777 hash_release(updgrp->bgp->update_groups[updgrp->afid], updgrp);
778 conf_release(updgrp->conf, updgrp->afi, updgrp->safi);
779
780 XFREE(MTYPE_BGP_PEER_HOST, updgrp->conf->host);
781
782 XFREE(MTYPE_BGP_PEER_IFNAME, updgrp->conf->ifname);
783
784 XFREE(MTYPE_BGP_PEER, updgrp->conf);
785 XFREE(MTYPE_BGP_UPDGRP, updgrp);
786 }
787
788 static void update_group_add_subgroup(struct update_group *updgrp,
789 struct update_subgroup *subgrp)
790 {
791 if (!updgrp || !subgrp)
792 return;
793
794 LIST_INSERT_HEAD(&(updgrp->subgrps), subgrp, updgrp_train);
795 subgrp->update_group = updgrp;
796 }
797
798 static void update_group_remove_subgroup(struct update_group *updgrp,
799 struct update_subgroup *subgrp)
800 {
801 if (!updgrp || !subgrp)
802 return;
803
804 LIST_REMOVE(subgrp, updgrp_train);
805 subgrp->update_group = NULL;
806 if (LIST_EMPTY(&(updgrp->subgrps)))
807 update_group_delete(updgrp);
808 }
809
810 static struct update_subgroup *
811 update_subgroup_create(struct update_group *updgrp)
812 {
813 struct update_subgroup *subgrp;
814
815 subgrp = XCALLOC(MTYPE_BGP_UPD_SUBGRP, sizeof(struct update_subgroup));
816 update_subgroup_checkin(subgrp, updgrp);
817 subgrp->v_coalesce = (UPDGRP_INST(updgrp))->coalesce_time;
818 sync_init(subgrp, updgrp);
819 bpacket_queue_init(SUBGRP_PKTQ(subgrp));
820 bpacket_queue_add(SUBGRP_PKTQ(subgrp), NULL, NULL);
821 TAILQ_INIT(&(subgrp->adjq));
822 if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
823 zlog_debug("create subgroup u%" PRIu64 ":s%" PRIu64, updgrp->id,
824 subgrp->id);
825
826 update_group_add_subgroup(updgrp, subgrp);
827
828 UPDGRP_INCR_STAT(updgrp, subgrps_created);
829
830 return subgrp;
831 }
832
833 static void update_subgroup_delete(struct update_subgroup *subgrp)
834 {
835 if (!subgrp)
836 return;
837
838 if (subgrp->update_group)
839 UPDGRP_INCR_STAT(subgrp->update_group, subgrps_deleted);
840
841 THREAD_OFF(subgrp->t_merge_check);
842 THREAD_OFF(subgrp->t_coalesce);
843
844 bpacket_queue_cleanup(SUBGRP_PKTQ(subgrp));
845 subgroup_clear_table(subgrp);
846
847 sync_delete(subgrp);
848
849 if (BGP_DEBUG(update_groups, UPDATE_GROUPS) && subgrp->update_group)
850 zlog_debug("delete subgroup u%" PRIu64 ":s%" PRIu64,
851 subgrp->update_group->id, subgrp->id);
852
853 update_group_remove_subgroup(subgrp->update_group, subgrp);
854
855 XFREE(MTYPE_BGP_UPD_SUBGRP, subgrp);
856 }
857
858 void update_subgroup_inherit_info(struct update_subgroup *to,
859 struct update_subgroup *from)
860 {
861 if (!to || !from)
862 return;
863
864 to->sflags = from->sflags;
865 }
866
867 /*
868 * update_subgroup_check_delete
869 *
870 * Delete a subgroup if it is ready to be deleted.
871 *
872 * Returns true if the subgroup was deleted.
873 */
874 static bool update_subgroup_check_delete(struct update_subgroup *subgrp)
875 {
876 if (!subgrp)
877 return false;
878
879 if (!LIST_EMPTY(&(subgrp->peers)))
880 return false;
881
882 update_subgroup_delete(subgrp);
883
884 return true;
885 }
886
887 /*
888 * update_subgroup_add_peer
889 *
890 * @param send_enqueued_packets If true all currently enqueued packets will
891 * also be sent to the peer.
892 */
893 static void update_subgroup_add_peer(struct update_subgroup *subgrp,
894 struct peer_af *paf,
895 int send_enqueued_pkts)
896 {
897 struct bpacket *pkt;
898
899 if (!subgrp || !paf)
900 return;
901
902 LIST_INSERT_HEAD(&(subgrp->peers), paf, subgrp_train);
903 paf->subgroup = subgrp;
904 subgrp->peer_count++;
905
906 if (bgp_debug_peer_updout_enabled(paf->peer->host)) {
907 UPDGRP_PEER_DBG_EN(subgrp->update_group);
908 }
909
910 SUBGRP_INCR_STAT(subgrp, join_events);
911
912 if (send_enqueued_pkts) {
913 pkt = bpacket_queue_first(SUBGRP_PKTQ(subgrp));
914 } else {
915
916 /*
917 * Hang the peer off of the last, placeholder, packet in the
918 * queue. This means it won't see any of the packets that are
919 * currently the queue.
920 */
921 pkt = bpacket_queue_last(SUBGRP_PKTQ(subgrp));
922 assert(pkt->buffer == NULL);
923 }
924
925 bpacket_add_peer(pkt, paf);
926
927 if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
928 zlog_debug("peer %s added to subgroup s%" PRIu64,
929 paf->peer->host, subgrp->id);
930 }
931
932 /*
933 * update_subgroup_remove_peer_internal
934 *
935 * Internal function that removes a peer from a subgroup, but does not
936 * delete the subgroup. A call to this function must almost always be
937 * followed by a call to update_subgroup_check_delete().
938 *
939 * @see update_subgroup_remove_peer
940 */
941 static void update_subgroup_remove_peer_internal(struct update_subgroup *subgrp,
942 struct peer_af *paf)
943 {
944 assert(subgrp && paf && subgrp->update_group);
945
946 if (bgp_debug_peer_updout_enabled(paf->peer->host)) {
947 UPDGRP_PEER_DBG_DIS(subgrp->update_group);
948 }
949
950 bpacket_queue_remove_peer(paf);
951 LIST_REMOVE(paf, subgrp_train);
952 paf->subgroup = NULL;
953 subgrp->peer_count--;
954
955 if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
956 zlog_debug("peer %s deleted from subgroup s%"
957 PRIu64 " peer cnt %d",
958 paf->peer->host, subgrp->id, subgrp->peer_count);
959 SUBGRP_INCR_STAT(subgrp, prune_events);
960 }
961
962 /*
963 * update_subgroup_remove_peer
964 */
965 void update_subgroup_remove_peer(struct update_subgroup *subgrp,
966 struct peer_af *paf)
967 {
968 if (!subgrp || !paf)
969 return;
970
971 update_subgroup_remove_peer_internal(subgrp, paf);
972
973 if (update_subgroup_check_delete(subgrp))
974 return;
975
976 /*
977 * The deletion of the peer may have caused some packets to be
978 * deleted from the subgroup packet queue. Check if the subgroup can
979 * be merged now.
980 */
981 update_subgroup_check_merge(subgrp, "removed peer from subgroup");
982 }
983
984 static struct update_subgroup *update_subgroup_find(struct update_group *updgrp,
985 struct peer_af *paf)
986 {
987 struct update_subgroup *subgrp = NULL;
988 uint64_t version;
989
990 if (paf->subgroup) {
991 assert(0);
992 return NULL;
993 } else
994 version = 0;
995
996 if (!peer_established(PAF_PEER(paf)))
997 return NULL;
998
999 UPDGRP_FOREACH_SUBGRP (updgrp, subgrp) {
1000 if (subgrp->version != version
1001 || CHECK_FLAG(subgrp->sflags,
1002 SUBGRP_STATUS_DEFAULT_ORIGINATE))
1003 continue;
1004
1005 /*
1006 * The version number is not meaningful on a subgroup that needs
1007 * a refresh.
1008 */
1009 if (update_subgroup_needs_refresh(subgrp))
1010 continue;
1011
1012 break;
1013 }
1014
1015 return subgrp;
1016 }
1017
1018 /*
1019 * update_subgroup_ready_for_merge
1020 *
1021 * Returns true if this subgroup is in a state that allows it to be
1022 * merged into another subgroup.
1023 */
1024 static bool update_subgroup_ready_for_merge(struct update_subgroup *subgrp)
1025 {
1026
1027 /*
1028 * Not ready if there are any encoded packets waiting to be written
1029 * out to peers.
1030 */
1031 if (!bpacket_queue_is_empty(SUBGRP_PKTQ(subgrp)))
1032 return false;
1033
1034 /*
1035 * Not ready if there enqueued updates waiting to be encoded.
1036 */
1037 if (!advertise_list_is_empty(subgrp))
1038 return false;
1039
1040 /*
1041 * Don't attempt to merge a subgroup that needs a refresh. For one,
1042 * we can't determine if the adj_out of such a group matches that of
1043 * another group.
1044 */
1045 if (update_subgroup_needs_refresh(subgrp))
1046 return false;
1047
1048 return true;
1049 }
1050
1051 /*
1052 * update_subgrp_can_merge_into
1053 *
1054 * Returns true if the first subgroup can merge into the second
1055 * subgroup.
1056 */
1057 static int update_subgroup_can_merge_into(struct update_subgroup *subgrp,
1058 struct update_subgroup *target)
1059 {
1060
1061 if (subgrp == target)
1062 return 0;
1063
1064 /*
1065 * Both must have processed the BRIB to the same point in order to
1066 * be merged.
1067 */
1068 if (subgrp->version != target->version)
1069 return 0;
1070
1071 if (CHECK_FLAG(subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE)
1072 != CHECK_FLAG(target->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
1073 return 0;
1074
1075 if (subgrp->adj_count != target->adj_count)
1076 return 0;
1077
1078 return update_subgroup_ready_for_merge(target);
1079 }
1080
1081 /*
1082 * update_subgroup_merge
1083 *
1084 * Merge the first subgroup into the second one.
1085 */
1086 static void update_subgroup_merge(struct update_subgroup *subgrp,
1087 struct update_subgroup *target,
1088 const char *reason)
1089 {
1090 struct peer_af *paf;
1091 int result;
1092 int peer_count;
1093
1094 assert(subgrp->adj_count == target->adj_count);
1095
1096 peer_count = subgrp->peer_count;
1097
1098 while (1) {
1099 paf = LIST_FIRST(&subgrp->peers);
1100 if (!paf)
1101 break;
1102
1103 update_subgroup_remove_peer_internal(subgrp, paf);
1104
1105 /*
1106 * Add the peer to the target subgroup, while making sure that
1107 * any currently enqueued packets won't be sent to it. Enqueued
1108 * packets could, for example, result in an unnecessary withdraw
1109 * followed by an advertise.
1110 */
1111 update_subgroup_add_peer(target, paf, 0);
1112 }
1113
1114 SUBGRP_INCR_STAT(target, merge_events);
1115
1116 if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
1117 zlog_debug("u%" PRIu64 ":s%" PRIu64" (%d peers) merged into u%" PRIu64 ":s%" PRIu64", trigger: %s",
1118 subgrp->update_group->id, subgrp->id, peer_count,
1119 target->update_group->id, target->id,
1120 reason ? reason : "unknown");
1121
1122 result = update_subgroup_check_delete(subgrp);
1123 assert(result);
1124 }
1125
1126 /*
1127 * update_subgroup_check_merge
1128 *
1129 * Merge this subgroup into another subgroup if possible.
1130 *
1131 * Returns true if the subgroup has been merged. The subgroup pointer
1132 * should not be accessed in this case.
1133 */
1134 bool update_subgroup_check_merge(struct update_subgroup *subgrp,
1135 const char *reason)
1136 {
1137 struct update_subgroup *target;
1138
1139 if (!update_subgroup_ready_for_merge(subgrp))
1140 return false;
1141
1142 /*
1143 * Look for a subgroup to merge into.
1144 */
1145 UPDGRP_FOREACH_SUBGRP (subgrp->update_group, target) {
1146 if (update_subgroup_can_merge_into(subgrp, target))
1147 break;
1148 }
1149
1150 if (!target)
1151 return false;
1152
1153 update_subgroup_merge(subgrp, target, reason);
1154 return true;
1155 }
1156
1157 /*
1158 * update_subgroup_merge_check_thread_cb
1159 */
1160 static int update_subgroup_merge_check_thread_cb(struct thread *thread)
1161 {
1162 struct update_subgroup *subgrp;
1163
1164 subgrp = THREAD_ARG(thread);
1165
1166 subgrp->t_merge_check = NULL;
1167
1168 update_subgroup_check_merge(subgrp, "triggered merge check");
1169 return 0;
1170 }
1171
1172 /*
1173 * update_subgroup_trigger_merge_check
1174 *
1175 * Triggers a call to update_subgroup_check_merge() on a clean context.
1176 *
1177 * @param force If true, the merge check will be triggered even if the
1178 * subgroup doesn't currently look ready for a merge.
1179 *
1180 * Returns true if a merge check will be performed shortly.
1181 */
1182 bool update_subgroup_trigger_merge_check(struct update_subgroup *subgrp,
1183 int force)
1184 {
1185 if (subgrp->t_merge_check)
1186 return true;
1187
1188 if (!force && !update_subgroup_ready_for_merge(subgrp))
1189 return false;
1190
1191 subgrp->t_merge_check = NULL;
1192 thread_add_timer_msec(bm->master, update_subgroup_merge_check_thread_cb,
1193 subgrp, 0, &subgrp->t_merge_check);
1194
1195 SUBGRP_INCR_STAT(subgrp, merge_checks_triggered);
1196
1197 return true;
1198 }
1199
1200 /*
1201 * update_subgroup_copy_adj_out
1202 *
1203 * Helper function that clones the adj out (state about advertised
1204 * routes) from one subgroup to another. It assumes that the adj out
1205 * of the target subgroup is empty.
1206 */
1207 static void update_subgroup_copy_adj_out(struct update_subgroup *source,
1208 struct update_subgroup *dest)
1209 {
1210 struct bgp_adj_out *aout, *aout_copy;
1211
1212 SUBGRP_FOREACH_ADJ (source, aout) {
1213 /*
1214 * Copy the adj out.
1215 */
1216 aout_copy = bgp_adj_out_alloc(dest, aout->dest,
1217 aout->addpath_tx_id);
1218 aout_copy->attr =
1219 aout->attr ? bgp_attr_intern(aout->attr) : NULL;
1220 }
1221
1222 dest->scount = source->scount;
1223 }
1224
1225 /*
1226 * update_subgroup_copy_packets
1227 *
1228 * Copy packets after and including the given packet to the subgroup
1229 * 'dest'.
1230 *
1231 * Returns the number of packets copied.
1232 */
1233 static int update_subgroup_copy_packets(struct update_subgroup *dest,
1234 struct bpacket *pkt)
1235 {
1236 int count;
1237
1238 count = 0;
1239 while (pkt && pkt->buffer) {
1240 bpacket_queue_add(SUBGRP_PKTQ(dest), stream_dup(pkt->buffer),
1241 &pkt->arr);
1242 count++;
1243 pkt = bpacket_next(pkt);
1244 }
1245
1246 return count;
1247 }
1248
1249 static bool updgrp_prefix_list_update(struct update_group *updgrp,
1250 const char *name)
1251 {
1252 struct peer *peer;
1253 struct bgp_filter *filter;
1254
1255 peer = UPDGRP_PEER(updgrp);
1256 filter = &peer->filter[UPDGRP_AFI(updgrp)][UPDGRP_SAFI(updgrp)];
1257
1258 if (PREFIX_LIST_OUT_NAME(filter)
1259 && (strcmp(name, PREFIX_LIST_OUT_NAME(filter)) == 0)) {
1260 PREFIX_LIST_OUT(filter) = prefix_list_lookup(
1261 UPDGRP_AFI(updgrp), PREFIX_LIST_OUT_NAME(filter));
1262 return true;
1263 }
1264 return false;
1265 }
1266
1267 static bool updgrp_filter_list_update(struct update_group *updgrp,
1268 const char *name)
1269 {
1270 struct peer *peer;
1271 struct bgp_filter *filter;
1272
1273 peer = UPDGRP_PEER(updgrp);
1274 filter = &peer->filter[UPDGRP_AFI(updgrp)][UPDGRP_SAFI(updgrp)];
1275
1276 if (FILTER_LIST_OUT_NAME(filter)
1277 && (strcmp(name, FILTER_LIST_OUT_NAME(filter)) == 0)) {
1278 FILTER_LIST_OUT(filter) =
1279 as_list_lookup(FILTER_LIST_OUT_NAME(filter));
1280 return true;
1281 }
1282 return false;
1283 }
1284
1285 static bool updgrp_distribute_list_update(struct update_group *updgrp,
1286 const char *name)
1287 {
1288 struct peer *peer;
1289 struct bgp_filter *filter;
1290
1291 peer = UPDGRP_PEER(updgrp);
1292 filter = &peer->filter[UPDGRP_AFI(updgrp)][UPDGRP_SAFI(updgrp)];
1293
1294 if (DISTRIBUTE_OUT_NAME(filter)
1295 && (strcmp(name, DISTRIBUTE_OUT_NAME(filter)) == 0)) {
1296 DISTRIBUTE_OUT(filter) = access_list_lookup(
1297 UPDGRP_AFI(updgrp), DISTRIBUTE_OUT_NAME(filter));
1298 return true;
1299 }
1300 return false;
1301 }
1302
1303 static int updgrp_route_map_update(struct update_group *updgrp,
1304 const char *name, int *def_rmap_changed)
1305 {
1306 struct peer *peer;
1307 struct bgp_filter *filter;
1308 int changed = 0;
1309 afi_t afi;
1310 safi_t safi;
1311
1312 peer = UPDGRP_PEER(updgrp);
1313 afi = UPDGRP_AFI(updgrp);
1314 safi = UPDGRP_SAFI(updgrp);
1315 filter = &peer->filter[afi][safi];
1316
1317 if (ROUTE_MAP_OUT_NAME(filter)
1318 && (strcmp(name, ROUTE_MAP_OUT_NAME(filter)) == 0)) {
1319 ROUTE_MAP_OUT(filter) = route_map_lookup_by_name(name);
1320
1321 changed = 1;
1322 }
1323
1324 if (UNSUPPRESS_MAP_NAME(filter)
1325 && (strcmp(name, UNSUPPRESS_MAP_NAME(filter)) == 0)) {
1326 UNSUPPRESS_MAP(filter) = route_map_lookup_by_name(name);
1327 changed = 1;
1328 }
1329
1330 /* process default-originate route-map */
1331 if (peer->default_rmap[afi][safi].name
1332 && (strcmp(name, peer->default_rmap[afi][safi].name) == 0)) {
1333 peer->default_rmap[afi][safi].map =
1334 route_map_lookup_by_name(name);
1335 if (def_rmap_changed)
1336 *def_rmap_changed = 1;
1337 }
1338 return changed;
1339 }
1340
1341 /*
1342 * hash iteration callback function to process a policy change for an
1343 * update group. Check if the changed policy matches the updgrp's
1344 * outbound route-map or unsuppress-map or default-originate map or
1345 * filter-list or prefix-list or distribute-list.
1346 * Trigger update generation accordingly.
1347 */
1348 static int updgrp_policy_update_walkcb(struct update_group *updgrp, void *arg)
1349 {
1350 struct updwalk_context *ctx = arg;
1351 struct update_subgroup *subgrp;
1352 int changed = 0;
1353 int def_changed = 0;
1354
1355 if (!updgrp || !ctx || !ctx->policy_name)
1356 return UPDWALK_CONTINUE;
1357
1358 switch (ctx->policy_type) {
1359 case BGP_POLICY_ROUTE_MAP:
1360 changed = updgrp_route_map_update(updgrp, ctx->policy_name,
1361 &def_changed);
1362 break;
1363 case BGP_POLICY_FILTER_LIST:
1364 changed = updgrp_filter_list_update(updgrp, ctx->policy_name);
1365 break;
1366 case BGP_POLICY_PREFIX_LIST:
1367 changed = updgrp_prefix_list_update(updgrp, ctx->policy_name);
1368 break;
1369 case BGP_POLICY_DISTRIBUTE_LIST:
1370 changed =
1371 updgrp_distribute_list_update(updgrp, ctx->policy_name);
1372 break;
1373 default:
1374 break;
1375 }
1376
1377 /* If not doing route update, return after updating "config" */
1378 if (!ctx->policy_route_update)
1379 return UPDWALK_CONTINUE;
1380
1381 /* If nothing has changed, return after updating "config" */
1382 if (!changed && !def_changed)
1383 return UPDWALK_CONTINUE;
1384
1385 /*
1386 * If something has changed, at the beginning of a route-map
1387 * modification
1388 * event, mark each subgroup's needs-refresh bit. For one, it signals to
1389 * whoever that the subgroup needs a refresh. Second, it prevents
1390 * premature
1391 * merge of this subgroup with another before a complete (outbound)
1392 * refresh.
1393 */
1394 if (ctx->policy_event_start_flag) {
1395 UPDGRP_FOREACH_SUBGRP (updgrp, subgrp) {
1396 update_subgroup_set_needs_refresh(subgrp, 1);
1397 }
1398 return UPDWALK_CONTINUE;
1399 }
1400
1401 UPDGRP_FOREACH_SUBGRP (updgrp, subgrp) {
1402 /* Avoid supressing duplicate routes later
1403 * when processing in subgroup_announce_table().
1404 */
1405 SET_FLAG(subgrp->sflags, SUBGRP_STATUS_FORCE_UPDATES);
1406
1407 if (changed) {
1408 if (bgp_debug_update(NULL, NULL, updgrp, 0))
1409 zlog_debug(
1410 "u%" PRIu64 ":s%" PRIu64" announcing routes upon policy %s (type %d) change",
1411 updgrp->id, subgrp->id,
1412 ctx->policy_name, ctx->policy_type);
1413 subgroup_announce_route(subgrp);
1414 }
1415 if (def_changed) {
1416 if (bgp_debug_update(NULL, NULL, updgrp, 0))
1417 zlog_debug(
1418 "u%" PRIu64 ":s%" PRIu64" announcing default upon default routemap %s change",
1419 updgrp->id, subgrp->id,
1420 ctx->policy_name);
1421 subgroup_default_originate(subgrp, 0);
1422 }
1423 update_subgroup_set_needs_refresh(subgrp, 0);
1424 }
1425 return UPDWALK_CONTINUE;
1426 }
1427
1428 static int update_group_walkcb(struct hash_bucket *bucket, void *arg)
1429 {
1430 struct update_group *updgrp = bucket->data;
1431 struct updwalk_context *wctx = arg;
1432 int ret = (*wctx->cb)(updgrp, wctx->context);
1433 return ret;
1434 }
1435
1436 static int update_group_periodic_merge_walkcb(struct update_group *updgrp,
1437 void *arg)
1438 {
1439 struct update_subgroup *subgrp;
1440 struct update_subgroup *tmp_subgrp;
1441 const char *reason = arg;
1442
1443 UPDGRP_FOREACH_SUBGRP_SAFE (updgrp, subgrp, tmp_subgrp)
1444 update_subgroup_check_merge(subgrp, reason);
1445 return UPDWALK_CONTINUE;
1446 }
1447
1448 /********************
1449 * PUBLIC FUNCTIONS
1450 ********************/
1451
1452 /*
1453 * trigger function when a policy (route-map/filter-list/prefix-list/
1454 * distribute-list etc.) content changes. Go through all the
1455 * update groups and process the change.
1456 *
1457 * bgp: the bgp instance
1458 * ptype: the type of policy that got modified, see bgpd.h
1459 * pname: name of the policy
1460 * route_update: flag to control if an automatic update generation should
1461 * occur
1462 * start_event: flag that indicates if it's the beginning of the change.
1463 * Esp. when the user is changing the content interactively
1464 * over multiple statements. Useful to set dirty flag on
1465 * update groups.
1466 */
1467 void update_group_policy_update(struct bgp *bgp, bgp_policy_type_e ptype,
1468 const char *pname, int route_update,
1469 int start_event)
1470 {
1471 struct updwalk_context ctx;
1472
1473 memset(&ctx, 0, sizeof(ctx));
1474 ctx.policy_type = ptype;
1475 ctx.policy_name = pname;
1476 ctx.policy_route_update = route_update;
1477 ctx.policy_event_start_flag = start_event;
1478 ctx.flags = 0;
1479
1480 update_group_walk(bgp, updgrp_policy_update_walkcb, &ctx);
1481 }
1482
1483 /*
1484 * update_subgroup_split_peer
1485 *
1486 * Ensure that the given peer is in a subgroup of its own in the
1487 * specified update group.
1488 */
1489 void update_subgroup_split_peer(struct peer_af *paf,
1490 struct update_group *updgrp)
1491 {
1492 struct update_subgroup *old_subgrp, *subgrp;
1493 uint64_t old_id;
1494
1495
1496 old_subgrp = paf->subgroup;
1497
1498 if (!updgrp)
1499 updgrp = old_subgrp->update_group;
1500
1501 /*
1502 * If the peer is alone in its subgroup, reuse the existing
1503 * subgroup.
1504 */
1505 if (old_subgrp->peer_count == 1) {
1506 if (updgrp == old_subgrp->update_group)
1507 return;
1508
1509 subgrp = old_subgrp;
1510 old_id = old_subgrp->update_group->id;
1511
1512 if (bgp_debug_peer_updout_enabled(paf->peer->host)) {
1513 UPDGRP_PEER_DBG_DIS(old_subgrp->update_group);
1514 }
1515
1516 update_group_remove_subgroup(old_subgrp->update_group,
1517 old_subgrp);
1518 update_group_add_subgroup(updgrp, subgrp);
1519
1520 if (bgp_debug_peer_updout_enabled(paf->peer->host)) {
1521 UPDGRP_PEER_DBG_EN(updgrp);
1522 }
1523 if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
1524 zlog_debug("u%" PRIu64 ":s%" PRIu64" peer %s moved to u%" PRIu64 ":s%" PRIu64,
1525 old_id, subgrp->id, paf->peer->host,
1526 updgrp->id, subgrp->id);
1527
1528 /*
1529 * The state of the subgroup (adj_out, advs, packet queue etc)
1530 * is consistent internally, but may not be identical to other
1531 * subgroups in the new update group even if the version number
1532 * matches up. Make sure a full refresh is done before the
1533 * subgroup is merged with another.
1534 */
1535 update_subgroup_set_needs_refresh(subgrp, 1);
1536
1537 SUBGRP_INCR_STAT(subgrp, updgrp_switch_events);
1538 return;
1539 }
1540
1541 /*
1542 * Create a new subgroup under the specified update group, and copy
1543 * over relevant state to it.
1544 */
1545 subgrp = update_subgroup_create(updgrp);
1546 update_subgroup_inherit_info(subgrp, old_subgrp);
1547
1548 subgrp->split_from.update_group_id = old_subgrp->update_group->id;
1549 subgrp->split_from.subgroup_id = old_subgrp->id;
1550
1551 /*
1552 * Copy out relevant state from the old subgroup.
1553 */
1554 update_subgroup_copy_adj_out(paf->subgroup, subgrp);
1555 update_subgroup_copy_packets(subgrp, paf->next_pkt_to_send);
1556
1557 if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
1558 zlog_debug("u%" PRIu64 ":s%" PRIu64" peer %s split and moved into u%" PRIu64":s%" PRIu64,
1559 paf->subgroup->update_group->id, paf->subgroup->id,
1560 paf->peer->host, updgrp->id, subgrp->id);
1561
1562 SUBGRP_INCR_STAT(paf->subgroup, split_events);
1563
1564 /*
1565 * Since queued advs were left behind, this new subgroup needs a
1566 * refresh.
1567 */
1568 update_subgroup_set_needs_refresh(subgrp, 1);
1569
1570 /*
1571 * Remove peer from old subgroup, and add it to the new one.
1572 */
1573 update_subgroup_remove_peer(paf->subgroup, paf);
1574
1575 update_subgroup_add_peer(subgrp, paf, 1);
1576 }
1577
1578 void update_bgp_group_init(struct bgp *bgp)
1579 {
1580 int afid;
1581
1582 AF_FOREACH (afid)
1583 bgp->update_groups[afid] =
1584 hash_create(updgrp_hash_key_make, updgrp_hash_cmp,
1585 "BGP Update Group Hash");
1586 }
1587
1588 void update_bgp_group_free(struct bgp *bgp)
1589 {
1590 int afid;
1591
1592 AF_FOREACH (afid) {
1593 if (bgp->update_groups[afid]) {
1594 hash_free(bgp->update_groups[afid]);
1595 bgp->update_groups[afid] = NULL;
1596 }
1597 }
1598 }
1599
1600 void update_group_show(struct bgp *bgp, afi_t afi, safi_t safi, struct vty *vty,
1601 uint64_t subgrp_id)
1602 {
1603 struct updwalk_context ctx;
1604 memset(&ctx, 0, sizeof(ctx));
1605 ctx.vty = vty;
1606 ctx.subgrp_id = subgrp_id;
1607
1608 update_group_af_walk(bgp, afi, safi, update_group_show_walkcb, &ctx);
1609 }
1610
1611 /*
1612 * update_group_show_stats
1613 *
1614 * Show global statistics about update groups.
1615 */
1616 void update_group_show_stats(struct bgp *bgp, struct vty *vty)
1617 {
1618 vty_out(vty, "Update groups created: %u\n",
1619 bgp->update_group_stats.updgrps_created);
1620 vty_out(vty, "Update groups deleted: %u\n",
1621 bgp->update_group_stats.updgrps_deleted);
1622 vty_out(vty, "Update subgroups created: %u\n",
1623 bgp->update_group_stats.subgrps_created);
1624 vty_out(vty, "Update subgroups deleted: %u\n",
1625 bgp->update_group_stats.subgrps_deleted);
1626 vty_out(vty, "Join events: %u\n", bgp->update_group_stats.join_events);
1627 vty_out(vty, "Prune events: %u\n",
1628 bgp->update_group_stats.prune_events);
1629 vty_out(vty, "Merge events: %u\n",
1630 bgp->update_group_stats.merge_events);
1631 vty_out(vty, "Split events: %u\n",
1632 bgp->update_group_stats.split_events);
1633 vty_out(vty, "Update group switch events: %u\n",
1634 bgp->update_group_stats.updgrp_switch_events);
1635 vty_out(vty, "Peer route refreshes combined: %u\n",
1636 bgp->update_group_stats.peer_refreshes_combined);
1637 vty_out(vty, "Merge checks triggered: %u\n",
1638 bgp->update_group_stats.merge_checks_triggered);
1639 }
1640
1641 /*
1642 * update_group_adjust_peer
1643 */
1644 void update_group_adjust_peer(struct peer_af *paf)
1645 {
1646 struct update_group *updgrp;
1647 struct update_subgroup *subgrp, *old_subgrp;
1648 struct peer *peer;
1649
1650 if (!paf)
1651 return;
1652
1653 peer = PAF_PEER(paf);
1654 if (!peer_established(peer)) {
1655 return;
1656 }
1657
1658 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE)) {
1659 return;
1660 }
1661
1662 if (!peer->afc_nego[paf->afi][paf->safi]) {
1663 return;
1664 }
1665
1666 updgrp = update_group_find(paf);
1667 if (!updgrp) {
1668 updgrp = update_group_create(paf);
1669 if (!updgrp) {
1670 flog_err(EC_BGP_UPDGRP_CREATE,
1671 "couldn't create update group for peer %s",
1672 paf->peer->host);
1673 return;
1674 }
1675 }
1676
1677 old_subgrp = paf->subgroup;
1678
1679 if (old_subgrp) {
1680
1681 /*
1682 * If the update group of the peer is unchanged, the peer can
1683 * stay
1684 * in its existing subgroup and we're done.
1685 */
1686 if (old_subgrp->update_group == updgrp)
1687 return;
1688
1689 /*
1690 * The peer is switching between update groups. Put it in its
1691 * own subgroup under the new update group.
1692 */
1693 update_subgroup_split_peer(paf, updgrp);
1694 return;
1695 }
1696
1697 subgrp = update_subgroup_find(updgrp, paf);
1698 if (!subgrp) {
1699 subgrp = update_subgroup_create(updgrp);
1700 if (!subgrp)
1701 return;
1702 }
1703
1704 update_subgroup_add_peer(subgrp, paf, 1);
1705 if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
1706 zlog_debug("u%" PRIu64 ":s%" PRIu64 " add peer %s", updgrp->id,
1707 subgrp->id, paf->peer->host);
1708
1709 return;
1710 }
1711
1712 int update_group_adjust_soloness(struct peer *peer, int set)
1713 {
1714 struct peer_group *group;
1715 struct listnode *node, *nnode;
1716
1717 if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
1718 peer_lonesoul_or_not(peer, set);
1719 if (peer_established(peer))
1720 bgp_announce_route_all(peer);
1721 } else {
1722 group = peer->group;
1723 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
1724 peer_lonesoul_or_not(peer, set);
1725 if (peer_established(peer))
1726 bgp_announce_route_all(peer);
1727 }
1728 }
1729 return 0;
1730 }
1731
1732 /*
1733 * update_subgroup_rib
1734 */
1735 struct bgp_table *update_subgroup_rib(struct update_subgroup *subgrp)
1736 {
1737 struct bgp *bgp;
1738
1739 bgp = SUBGRP_INST(subgrp);
1740 if (!bgp)
1741 return NULL;
1742
1743 return bgp->rib[SUBGRP_AFI(subgrp)][SUBGRP_SAFI(subgrp)];
1744 }
1745
1746 void update_group_af_walk(struct bgp *bgp, afi_t afi, safi_t safi,
1747 updgrp_walkcb cb, void *ctx)
1748 {
1749 struct updwalk_context wctx;
1750 int afid;
1751
1752 if (!bgp)
1753 return;
1754 afid = afindex(afi, safi);
1755 if (afid >= BGP_AF_MAX)
1756 return;
1757
1758 memset(&wctx, 0, sizeof(wctx));
1759 wctx.cb = cb;
1760 wctx.context = ctx;
1761
1762 if (bgp->update_groups[afid])
1763 hash_walk(bgp->update_groups[afid], update_group_walkcb, &wctx);
1764 }
1765
1766 void update_group_walk(struct bgp *bgp, updgrp_walkcb cb, void *ctx)
1767 {
1768 afi_t afi;
1769 safi_t safi;
1770
1771 FOREACH_AFI_SAFI (afi, safi) {
1772 update_group_af_walk(bgp, afi, safi, cb, ctx);
1773 }
1774 }
1775
1776 void update_group_periodic_merge(struct bgp *bgp)
1777 {
1778 char reason[] = "periodic merge check";
1779
1780 update_group_walk(bgp, update_group_periodic_merge_walkcb,
1781 (void *)reason);
1782 }
1783
1784 static int
1785 update_group_default_originate_route_map_walkcb(struct update_group *updgrp,
1786 void *arg)
1787 {
1788 struct update_subgroup *subgrp;
1789 struct peer *peer;
1790 afi_t afi;
1791 safi_t safi;
1792
1793 UPDGRP_FOREACH_SUBGRP (updgrp, subgrp) {
1794 peer = SUBGRP_PEER(subgrp);
1795 afi = SUBGRP_AFI(subgrp);
1796 safi = SUBGRP_SAFI(subgrp);
1797
1798 if (peer->default_rmap[afi][safi].name) {
1799 subgroup_default_originate(subgrp, 0);
1800 }
1801 }
1802
1803 return UPDWALK_CONTINUE;
1804 }
1805
1806 int update_group_refresh_default_originate_route_map(struct thread *thread)
1807 {
1808 struct bgp *bgp;
1809 char reason[] = "refresh default-originate route-map";
1810
1811 bgp = THREAD_ARG(thread);
1812 update_group_walk(bgp, update_group_default_originate_route_map_walkcb,
1813 reason);
1814 thread_cancel(&bgp->t_rmap_def_originate_eval);
1815 bgp_unlock(bgp);
1816
1817 return 0;
1818 }
1819
1820 /*
1821 * peer_af_announce_route
1822 *
1823 * Refreshes routes out to a peer_af immediately.
1824 *
1825 * If the combine parameter is true, then this function will try to
1826 * gather other peers in the subgroup for which a route announcement
1827 * is pending and efficently announce routes to all of them.
1828 *
1829 * For now, the 'combine' option has an effect only if all peers in
1830 * the subgroup have a route announcement pending.
1831 */
1832 void peer_af_announce_route(struct peer_af *paf, int combine)
1833 {
1834 struct update_subgroup *subgrp;
1835 struct peer_af *cur_paf;
1836 int all_pending;
1837
1838 subgrp = paf->subgroup;
1839 all_pending = 0;
1840
1841 if (combine) {
1842 /*
1843 * If there are other peers in the old subgroup that also need
1844 * routes to be announced, pull them into the peer's new
1845 * subgroup.
1846 * Combine route announcement with other peers if possible.
1847 *
1848 * For now, we combine only if all peers in the subgroup have an
1849 * announcement pending.
1850 */
1851 all_pending = 1;
1852
1853 SUBGRP_FOREACH_PEER (subgrp, cur_paf) {
1854 if (cur_paf == paf)
1855 continue;
1856
1857 if (cur_paf->t_announce_route)
1858 continue;
1859
1860 all_pending = 0;
1861 break;
1862 }
1863 }
1864 /*
1865 * Announce to the peer alone if we were not asked to combine peers,
1866 * or if some peers don't have a route annoucement pending.
1867 */
1868 if (!combine || !all_pending) {
1869 update_subgroup_split_peer(paf, NULL);
1870 subgrp = paf->subgroup;
1871
1872 assert(subgrp && subgrp->update_group);
1873 if (bgp_debug_update(paf->peer, NULL, subgrp->update_group, 0))
1874 zlog_debug("u%" PRIu64 ":s%" PRIu64" %s announcing routes",
1875 subgrp->update_group->id, subgrp->id,
1876 paf->peer->host);
1877
1878 subgroup_announce_route(paf->subgroup);
1879 return;
1880 }
1881
1882 /*
1883 * We will announce routes the entire subgroup.
1884 *
1885 * First stop refresh timers on all the other peers.
1886 */
1887 SUBGRP_FOREACH_PEER (subgrp, cur_paf) {
1888 if (cur_paf == paf)
1889 continue;
1890
1891 bgp_stop_announce_route_timer(cur_paf);
1892 }
1893
1894 if (bgp_debug_update(paf->peer, NULL, subgrp->update_group, 0))
1895 zlog_debug("u%" PRIu64 ":s%" PRIu64" announcing routes to %s, combined into %d peers",
1896 subgrp->update_group->id, subgrp->id,
1897 paf->peer->host, subgrp->peer_count);
1898
1899 subgroup_announce_route(subgrp);
1900
1901 SUBGRP_INCR_STAT_BY(subgrp, peer_refreshes_combined,
1902 subgrp->peer_count - 1);
1903 }
1904
1905 void subgroup_trigger_write(struct update_subgroup *subgrp)
1906 {
1907 struct peer_af *paf;
1908
1909 /*
1910 * For each peer in the subgroup, schedule a job to pull packets from
1911 * the subgroup output queue into their own output queue. This action
1912 * will trigger a write job on the I/O thread.
1913 */
1914 SUBGRP_FOREACH_PEER (subgrp, paf)
1915 if (peer_established(paf->peer))
1916 thread_add_timer_msec(
1917 bm->master, bgp_generate_updgrp_packets,
1918 paf->peer, 0,
1919 &paf->peer->t_generate_updgrp_packets);
1920 }
1921
1922 int update_group_clear_update_dbg(struct update_group *updgrp, void *arg)
1923 {
1924 UPDGRP_PEER_DBG_OFF(updgrp);
1925 return UPDWALK_CONTINUE;
1926 }
1927
1928 /* Return true if we should addpath encode NLRI to this peer */
1929 bool bgp_addpath_encode_tx(struct peer *peer, afi_t afi, safi_t safi)
1930 {
1931 return (CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV)
1932 && CHECK_FLAG(peer->af_cap[afi][safi],
1933 PEER_CAP_ADDPATH_AF_RX_RCV));
1934 }
1935
1936 bool bgp_check_selected(struct bgp_path_info *bpi, struct peer *peer,
1937 bool addpath_capable, afi_t afi, safi_t safi)
1938 {
1939 return (CHECK_FLAG(bpi->flags, BGP_PATH_SELECTED) ||
1940 (addpath_capable &&
1941 bgp_addpath_tx_path(peer->addpath_type[afi][safi], bpi)));
1942 }