1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * bgp_updgrp.c: BGP update group structures
5 * @copyright Copyright (C) 2014 Cumulus Networks, Inc.
7 * @author Avneesh Sachdev <avneesh@sproute.net>
8 * @author Rajesh Varadarajan <rajesh@sproute.net>
9 * @author Pradosh Mohapatra <pradosh@sproute.net>
19 #include "sockunion.h"
27 #include "workqueue.h"
32 #include "bgpd/bgpd.h"
33 #include "bgpd/bgp_table.h"
34 #include "bgpd/bgp_debug.h"
35 #include "bgpd/bgp_errors.h"
36 #include "bgpd/bgp_fsm.h"
37 #include "bgpd/bgp_addpath.h"
38 #include "bgpd/bgp_advertise.h"
39 #include "bgpd/bgp_packet.h"
40 #include "bgpd/bgp_updgrp.h"
41 #include "bgpd/bgp_route.h"
42 #include "bgpd/bgp_filter.h"
43 #include "bgpd/bgp_io.h"
50 * assign a unique ID to update group and subgroup. Mostly for display/
51 * debugging purposes. It's a 64-bit space - used leisurely without a
52 * worry about its wrapping and about filling gaps. While at it, timestamp
55 static void update_group_checkin(struct update_group
*updgrp
)
57 updgrp
->id
= ++bm
->updgrp_idspace
;
58 updgrp
->uptime
= monotime(NULL
);
61 static void update_subgroup_checkin(struct update_subgroup
*subgrp
,
62 struct update_group
*updgrp
)
64 subgrp
->id
= ++bm
->subgrp_idspace
;
65 subgrp
->uptime
= monotime(NULL
);
68 static void sync_init(struct update_subgroup
*subgrp
,
69 struct update_group
*updgrp
)
71 struct peer
*peer
= UPDGRP_PEER(updgrp
);
74 XCALLOC(MTYPE_BGP_SYNCHRONISE
, sizeof(struct bgp_synchronize
));
75 bgp_adv_fifo_init(&subgrp
->sync
->update
);
76 bgp_adv_fifo_init(&subgrp
->sync
->withdraw
);
77 bgp_adv_fifo_init(&subgrp
->sync
->withdraw_low
);
79 hash_create(bgp_advertise_attr_hash_key
,
80 bgp_advertise_attr_hash_cmp
, "BGP SubGroup Hash");
82 /* We use a larger buffer for subgrp->work in the event that:
83 * - We RX a BGP_UPDATE where the attributes alone are just
84 * under 4096 or 65535 (if Extended Message capability negotiated).
85 * - The user configures an outbound route-map that does many as-path
86 * prepends or adds many communities. At most they can have
88 * args in a route-map so there is a finite limit on how large they
90 * make the attributes.
92 * Having a buffer with BGP_MAX_PACKET_SIZE_OVERFLOW allows us to avoid
94 * checking for every single attribute as we construct an UPDATE.
96 subgrp
->work
= stream_new(peer
->max_packet_size
97 + BGP_MAX_PACKET_SIZE_OVERFLOW
);
98 subgrp
->scratch
= stream_new(peer
->max_packet_size
);
101 static void sync_delete(struct update_subgroup
*subgrp
)
103 XFREE(MTYPE_BGP_SYNCHRONISE
, subgrp
->sync
);
104 hash_clean_and_free(&subgrp
->hash
,
105 (void (*)(void *))bgp_advertise_attr_free
);
108 stream_free(subgrp
->work
);
111 stream_free(subgrp
->scratch
);
112 subgrp
->scratch
= NULL
;
118 * copy only those fields that are relevant to update group match
120 static void conf_copy(struct peer
*dst
, struct peer
*src
, afi_t afi
,
123 struct bgp_filter
*srcfilter
;
124 struct bgp_filter
*dstfilter
;
126 srcfilter
= &src
->filter
[afi
][safi
];
127 dstfilter
= &dst
->filter
[afi
][safi
];
130 dst
->sort
= src
->sort
;
132 dst
->v_routeadv
= src
->v_routeadv
;
133 dst
->flags
= src
->flags
;
134 dst
->af_flags
[afi
][safi
] = src
->af_flags
[afi
][safi
];
135 dst
->pmax_out
[afi
][safi
] = src
->pmax_out
[afi
][safi
];
136 dst
->max_packet_size
= src
->max_packet_size
;
137 XFREE(MTYPE_BGP_PEER_HOST
, dst
->host
);
139 dst
->host
= XSTRDUP(MTYPE_BGP_PEER_HOST
, src
->host
);
141 dst
->af_cap
[afi
][safi
] = src
->af_cap
[afi
][safi
];
142 dst
->afc_nego
[afi
][safi
] = src
->afc_nego
[afi
][safi
];
143 dst
->orf_plist
[afi
][safi
] = src
->orf_plist
[afi
][safi
];
144 dst
->addpath_type
[afi
][safi
] = src
->addpath_type
[afi
][safi
];
145 dst
->local_as
= src
->local_as
;
146 dst
->change_local_as
= src
->change_local_as
;
147 dst
->shared_network
= src
->shared_network
;
148 dst
->local_role
= src
->local_role
;
149 dst
->as_path_loop_detection
= src
->as_path_loop_detection
;
151 if (src
->soo
[afi
][safi
]) {
152 ecommunity_free(&dst
->soo
[afi
][safi
]);
153 dst
->soo
[afi
][safi
] = ecommunity_dup(src
->soo
[afi
][safi
]);
156 memcpy(&(dst
->nexthop
), &(src
->nexthop
), sizeof(struct bgp_nexthop
));
158 dst
->group
= src
->group
;
160 if (src
->default_rmap
[afi
][safi
].name
) {
161 dst
->default_rmap
[afi
][safi
].name
=
162 XSTRDUP(MTYPE_ROUTE_MAP_NAME
,
163 src
->default_rmap
[afi
][safi
].name
);
164 dst
->default_rmap
[afi
][safi
].map
=
165 src
->default_rmap
[afi
][safi
].map
;
168 if (DISTRIBUTE_OUT_NAME(srcfilter
)) {
169 DISTRIBUTE_OUT_NAME(dstfilter
) = XSTRDUP(
170 MTYPE_BGP_FILTER_NAME
, DISTRIBUTE_OUT_NAME(srcfilter
));
171 DISTRIBUTE_OUT(dstfilter
) = DISTRIBUTE_OUT(srcfilter
);
174 if (PREFIX_LIST_OUT_NAME(srcfilter
)) {
175 PREFIX_LIST_OUT_NAME(dstfilter
) = XSTRDUP(
176 MTYPE_BGP_FILTER_NAME
, PREFIX_LIST_OUT_NAME(srcfilter
));
177 PREFIX_LIST_OUT(dstfilter
) = PREFIX_LIST_OUT(srcfilter
);
180 if (FILTER_LIST_OUT_NAME(srcfilter
)) {
181 FILTER_LIST_OUT_NAME(dstfilter
) = XSTRDUP(
182 MTYPE_BGP_FILTER_NAME
, FILTER_LIST_OUT_NAME(srcfilter
));
183 FILTER_LIST_OUT(dstfilter
) = FILTER_LIST_OUT(srcfilter
);
186 if (ROUTE_MAP_OUT_NAME(srcfilter
)) {
187 ROUTE_MAP_OUT_NAME(dstfilter
) = XSTRDUP(
188 MTYPE_BGP_FILTER_NAME
, ROUTE_MAP_OUT_NAME(srcfilter
));
189 ROUTE_MAP_OUT(dstfilter
) = ROUTE_MAP_OUT(srcfilter
);
192 if (UNSUPPRESS_MAP_NAME(srcfilter
)) {
193 UNSUPPRESS_MAP_NAME(dstfilter
) = XSTRDUP(
194 MTYPE_BGP_FILTER_NAME
, UNSUPPRESS_MAP_NAME(srcfilter
));
195 UNSUPPRESS_MAP(dstfilter
) = UNSUPPRESS_MAP(srcfilter
);
198 if (ADVERTISE_MAP_NAME(srcfilter
)) {
199 ADVERTISE_MAP_NAME(dstfilter
) = XSTRDUP(
200 MTYPE_BGP_FILTER_NAME
, ADVERTISE_MAP_NAME(srcfilter
));
201 ADVERTISE_MAP(dstfilter
) = ADVERTISE_MAP(srcfilter
);
202 ADVERTISE_CONDITION(dstfilter
) = ADVERTISE_CONDITION(srcfilter
);
205 if (CONDITION_MAP_NAME(srcfilter
)) {
206 CONDITION_MAP_NAME(dstfilter
) = XSTRDUP(
207 MTYPE_BGP_FILTER_NAME
, CONDITION_MAP_NAME(srcfilter
));
208 CONDITION_MAP(dstfilter
) = CONDITION_MAP(srcfilter
);
211 dstfilter
->advmap
.update_type
= srcfilter
->advmap
.update_type
;
215 * since we did a bunch of XSTRDUP's in conf_copy, time to free them up
217 static void conf_release(struct peer
*src
, afi_t afi
, safi_t safi
)
219 struct bgp_filter
*srcfilter
;
221 srcfilter
= &src
->filter
[afi
][safi
];
223 XFREE(MTYPE_ROUTE_MAP_NAME
, src
->default_rmap
[afi
][safi
].name
);
225 XFREE(MTYPE_BGP_FILTER_NAME
, srcfilter
->dlist
[FILTER_OUT
].name
);
227 XFREE(MTYPE_BGP_FILTER_NAME
, srcfilter
->plist
[FILTER_OUT
].name
);
229 XFREE(MTYPE_BGP_FILTER_NAME
, srcfilter
->aslist
[FILTER_OUT
].name
);
231 XFREE(MTYPE_BGP_FILTER_NAME
, srcfilter
->map
[RMAP_OUT
].name
);
233 XFREE(MTYPE_BGP_FILTER_NAME
, srcfilter
->usmap
.name
);
235 XFREE(MTYPE_BGP_FILTER_NAME
, srcfilter
->advmap
.aname
);
237 XFREE(MTYPE_BGP_FILTER_NAME
, srcfilter
->advmap
.cname
);
239 XFREE(MTYPE_BGP_PEER_HOST
, src
->host
);
241 ecommunity_free(&src
->soo
[afi
][safi
]);
244 static void peer2_updgrp_copy(struct update_group
*updgrp
, struct peer_af
*paf
)
257 updgrp
->afi
= paf
->afi
;
258 updgrp
->safi
= paf
->safi
;
259 updgrp
->afid
= paf
->afid
;
260 updgrp
->bgp
= src
->bgp
;
262 conf_copy(dst
, src
, paf
->afi
, paf
->safi
);
266 * auxiliary functions to maintain the hash table.
267 * - updgrp_hash_alloc - to create a new entry, passed to hash_get
268 * - updgrp_hash_key_make - makes the key for update group search
269 * - updgrp_hash_cmp - compare two update groups.
271 static void *updgrp_hash_alloc(void *p
)
273 struct update_group
*updgrp
;
274 const struct update_group
*in
;
276 in
= (const struct update_group
*)p
;
277 updgrp
= XCALLOC(MTYPE_BGP_UPDGRP
, sizeof(struct update_group
));
278 memcpy(updgrp
, in
, sizeof(struct update_group
));
279 updgrp
->conf
= XCALLOC(MTYPE_BGP_PEER
, sizeof(struct peer
));
280 conf_copy(updgrp
->conf
, in
->conf
, in
->afi
, in
->safi
);
285 * The hash value for a peer is computed from the following variables:
287 * 1. IBGP (1) or EBGP (2)
288 * 2. FLAGS based on configuration:
289 * LOCAL_AS_NO_PREPEND
290 * LOCAL_AS_REPLACE_AS
291 * 3. AF_FLAGS based on configuration:
292 * Refer to definition in bgp_updgrp.h
293 * 4. (AF-independent) Capability flags:
295 * 5. (AF-dependent) Capability flags:
296 * ORF_PREFIX_SM_RCV (peer can send prefix ORF)
299 * 8. Outbound route-map name (neighbor route-map <> out)
300 * 9. Outbound distribute-list name (neighbor distribute-list <> out)
301 * 10. Outbound prefix-list name (neighbor prefix-list <> out)
302 * 11. Outbound as-list name (neighbor filter-list <> out)
303 * 12. Unsuppress map name (neighbor unsuppress-map <>)
304 * 13. default rmap name (neighbor default-originate route-map <>)
305 * 14. encoding both global and link-local nexthop?
306 * 15. If peer is configured to be a lonesoul, peer ip address
307 * 16. Local-as should match, if configured.
308 * 17. maximum-prefix-out
309 * 18. Local-role should also match, if configured.
312 static unsigned int updgrp_hash_key_make(const void *p
)
314 const struct update_group
*updgrp
;
315 const struct peer
*peer
;
316 const struct bgp_filter
*filter
;
323 * IF YOU ADD AN ADDITION TO THE HASH KEY TO ENSURE
324 * THAT THE UPDATE GROUP CALCULATION IS CORRECT THEN
325 * PLEASE ADD IT TO THE DEBUG OUTPUT TOO AT THE BOTTOM
328 #define SEED2 2147483647
334 flags
= peer
->af_flags
[afi
][safi
];
335 filter
= &peer
->filter
[afi
][safi
];
339 key
= jhash_1word(peer
->sort
, key
); /* EBGP or IBGP */
340 key
= jhash_1word((peer
->flags
& PEER_UPDGRP_FLAGS
), key
);
341 key
= jhash_1word((flags
& PEER_UPDGRP_AF_FLAGS
), key
);
342 key
= jhash_1word((uint32_t)peer
->addpath_type
[afi
][safi
], key
);
343 key
= jhash_1word((peer
->cap
& PEER_UPDGRP_CAP_FLAGS
), key
);
344 key
= jhash_1word((peer
->af_cap
[afi
][safi
] & PEER_UPDGRP_AF_CAP_FLAGS
),
346 key
= jhash_1word(peer
->v_routeadv
, key
);
347 key
= jhash_1word(peer
->change_local_as
, key
);
348 key
= jhash_1word(peer
->max_packet_size
, key
);
349 key
= jhash_1word(peer
->pmax_out
[afi
][safi
], key
);
351 if (peer
->as_path_loop_detection
)
352 key
= jhash_2words(peer
->as
, peer
->as_path_loop_detection
, key
);
355 key
= jhash_1word(jhash(peer
->group
->name
,
356 strlen(peer
->group
->name
), SEED1
),
359 if (filter
->map
[RMAP_OUT
].name
)
360 key
= jhash_1word(jhash(filter
->map
[RMAP_OUT
].name
,
361 strlen(filter
->map
[RMAP_OUT
].name
),
365 if (filter
->dlist
[FILTER_OUT
].name
)
366 key
= jhash_1word(jhash(filter
->dlist
[FILTER_OUT
].name
,
367 strlen(filter
->dlist
[FILTER_OUT
].name
),
371 if (filter
->plist
[FILTER_OUT
].name
)
372 key
= jhash_1word(jhash(filter
->plist
[FILTER_OUT
].name
,
373 strlen(filter
->plist
[FILTER_OUT
].name
),
377 if (filter
->aslist
[FILTER_OUT
].name
)
378 key
= jhash_1word(jhash(filter
->aslist
[FILTER_OUT
].name
,
379 strlen(filter
->aslist
[FILTER_OUT
].name
),
383 if (filter
->usmap
.name
)
384 key
= jhash_1word(jhash(filter
->usmap
.name
,
385 strlen(filter
->usmap
.name
), SEED1
),
388 if (filter
->advmap
.aname
)
389 key
= jhash_1word(jhash(filter
->advmap
.aname
,
390 strlen(filter
->advmap
.aname
), SEED1
),
393 if (filter
->advmap
.update_type
)
394 key
= jhash_1word(filter
->advmap
.update_type
, key
);
396 if (peer
->default_rmap
[afi
][safi
].name
)
398 jhash(peer
->default_rmap
[afi
][safi
].name
,
399 strlen(peer
->default_rmap
[afi
][safi
].name
),
403 /* If peer is on a shared network and is exchanging IPv6 prefixes,
404 * it needs to include link-local address. That's different from
405 * non-shared-network peers (nexthop encoded with 32 bytes vs 16
406 * bytes). We create different update groups to take care of that.
409 (peer
->shared_network
&& peer_afi_active_nego(peer
, AFI_IP6
)),
412 * There are certain peers that must get their own update-group:
414 * - peers that negotiated ORF
415 * - maximum-prefix-out is set
417 if (CHECK_FLAG(peer
->flags
, PEER_FLAG_LONESOUL
)
418 || CHECK_FLAG(peer
->af_cap
[afi
][safi
], PEER_CAP_ORF_PREFIX_SM_RCV
)
419 || CHECK_FLAG(peer
->af_cap
[afi
][safi
],
420 PEER_CAP_ORF_PREFIX_SM_OLD_RCV
)
421 || CHECK_FLAG(peer
->af_flags
[afi
][safi
], PEER_FLAG_MAX_PREFIX_OUT
))
422 key
= jhash_1word(jhash(peer
->host
, strlen(peer
->host
), SEED2
),
425 * Multiple sessions with the same neighbor should get their own
426 * update-group if they have different roles.
428 key
= jhash_1word(peer
->local_role
, key
);
430 /* Neighbors configured with the AIGP attribute are put in a separate
431 * update group from other neighbors.
433 key
= jhash_1word((peer
->flags
& PEER_FLAG_AIGP
), key
);
435 if (peer
->soo
[afi
][safi
]) {
436 char *soo_str
= ecommunity_str(peer
->soo
[afi
][safi
]);
438 key
= jhash_1word(jhash(soo_str
, strlen(soo_str
), SEED1
), key
);
442 * ANY NEW ITEMS THAT ARE ADDED TO THE key, ENSURE DEBUG
443 * STATEMENT STAYS UP TO DATE
445 if (bgp_debug_neighbor_events(peer
)) {
447 "%pBP Update Group Hash: sort: %d UpdGrpFlags: %ju UpdGrpAFFlags: %ju",
449 (intmax_t)CHECK_FLAG(peer
->flags
, PEER_UPDGRP_FLAGS
),
450 (intmax_t)CHECK_FLAG(flags
, PEER_UPDGRP_AF_FLAGS
));
452 "%pBP Update Group Hash: addpath: %u UpdGrpCapFlag: %u UpdGrpCapAFFlag: %u route_adv: %u change local as: %u, as_path_loop_detection: %d",
453 peer
, (uint32_t)peer
->addpath_type
[afi
][safi
],
454 CHECK_FLAG(peer
->cap
, PEER_UPDGRP_CAP_FLAGS
),
455 CHECK_FLAG(peer
->af_cap
[afi
][safi
],
456 PEER_UPDGRP_AF_CAP_FLAGS
),
457 peer
->v_routeadv
, peer
->change_local_as
,
458 peer
->as_path_loop_detection
);
460 "%pBP Update Group Hash: max packet size: %u pmax_out: %u Peer Group: %s rmap out: %s",
461 peer
, peer
->max_packet_size
, peer
->pmax_out
[afi
][safi
],
462 peer
->group
? peer
->group
->name
: "(NONE)",
463 ROUTE_MAP_OUT_NAME(filter
) ? ROUTE_MAP_OUT_NAME(filter
)
466 "%pBP Update Group Hash: dlist out: %s plist out: %s aslist out: %s usmap out: %s advmap: %s %d",
468 DISTRIBUTE_OUT_NAME(filter
)
469 ? DISTRIBUTE_OUT_NAME(filter
)
471 PREFIX_LIST_OUT_NAME(filter
)
472 ? PREFIX_LIST_OUT_NAME(filter
)
474 FILTER_LIST_OUT_NAME(filter
)
475 ? FILTER_LIST_OUT_NAME(filter
)
477 UNSUPPRESS_MAP_NAME(filter
)
478 ? UNSUPPRESS_MAP_NAME(filter
)
480 ADVERTISE_MAP_NAME(filter
) ? ADVERTISE_MAP_NAME(filter
)
482 filter
->advmap
.update_type
);
484 "%pBP Update Group Hash: default rmap: %s shared network and afi active network: %d",
486 peer
->default_rmap
[afi
][safi
].name
487 ? peer
->default_rmap
[afi
][safi
].name
489 peer
->shared_network
&&
490 peer_afi_active_nego(peer
, AFI_IP6
));
492 "%pBP Update Group Hash: Lonesoul: %d ORF prefix: %u ORF old: %u max prefix out: %ju",
493 peer
, !!CHECK_FLAG(peer
->flags
, PEER_FLAG_LONESOUL
),
494 CHECK_FLAG(peer
->af_cap
[afi
][safi
],
495 PEER_CAP_ORF_PREFIX_SM_RCV
),
496 CHECK_FLAG(peer
->af_cap
[afi
][safi
],
497 PEER_CAP_ORF_PREFIX_SM_OLD_RCV
),
498 (intmax_t)CHECK_FLAG(peer
->af_flags
[afi
][safi
],
499 PEER_FLAG_MAX_PREFIX_OUT
));
501 "%pBP Update Group Hash: local role: %u AIGP: %d SOO: %s",
502 peer
, peer
->local_role
,
503 !!CHECK_FLAG(peer
->flags
, PEER_FLAG_AIGP
),
505 ? ecommunity_str(peer
->soo
[afi
][safi
])
507 zlog_debug("%pBP Update Group Hash key: %u", peer
, key
);
512 static bool updgrp_hash_cmp(const void *p1
, const void *p2
)
514 const struct update_group
*grp1
;
515 const struct update_group
*grp2
;
516 const struct peer
*pe1
;
517 const struct peer
*pe2
;
520 const struct bgp_filter
*fl1
;
521 const struct bgp_filter
*fl2
;
534 flags1
= pe1
->af_flags
[afi
][safi
];
535 flags2
= pe2
->af_flags
[afi
][safi
];
536 fl1
= &pe1
->filter
[afi
][safi
];
537 fl2
= &pe2
->filter
[afi
][safi
];
539 /* put EBGP and IBGP peers in different update groups */
540 if (pe1
->sort
!= pe2
->sort
)
543 /* check peer flags */
544 if ((pe1
->flags
& PEER_UPDGRP_FLAGS
)
545 != (pe2
->flags
& PEER_UPDGRP_FLAGS
))
548 /* If there is 'local-as' configured, it should match. */
549 if (pe1
->change_local_as
!= pe2
->change_local_as
)
552 if (pe1
->pmax_out
[afi
][safi
] != pe2
->pmax_out
[afi
][safi
])
555 /* flags like route reflector client */
556 if ((flags1
& PEER_UPDGRP_AF_FLAGS
) != (flags2
& PEER_UPDGRP_AF_FLAGS
))
559 if (pe1
->addpath_type
[afi
][safi
] != pe2
->addpath_type
[afi
][safi
])
562 if ((pe1
->cap
& PEER_UPDGRP_CAP_FLAGS
)
563 != (pe2
->cap
& PEER_UPDGRP_CAP_FLAGS
))
566 if ((pe1
->af_cap
[afi
][safi
] & PEER_UPDGRP_AF_CAP_FLAGS
)
567 != (pe2
->af_cap
[afi
][safi
] & PEER_UPDGRP_AF_CAP_FLAGS
))
570 if (pe1
->v_routeadv
!= pe2
->v_routeadv
)
573 if (pe1
->group
!= pe2
->group
)
576 /* Roles can affect filtering */
577 if (pe1
->local_role
!= pe2
->local_role
)
580 /* route-map names should be the same */
581 if ((fl1
->map
[RMAP_OUT
].name
&& !fl2
->map
[RMAP_OUT
].name
)
582 || (!fl1
->map
[RMAP_OUT
].name
&& fl2
->map
[RMAP_OUT
].name
)
583 || (fl1
->map
[RMAP_OUT
].name
&& fl2
->map
[RMAP_OUT
].name
584 && strcmp(fl1
->map
[RMAP_OUT
].name
, fl2
->map
[RMAP_OUT
].name
)))
587 if ((fl1
->dlist
[FILTER_OUT
].name
&& !fl2
->dlist
[FILTER_OUT
].name
)
588 || (!fl1
->dlist
[FILTER_OUT
].name
&& fl2
->dlist
[FILTER_OUT
].name
)
589 || (fl1
->dlist
[FILTER_OUT
].name
&& fl2
->dlist
[FILTER_OUT
].name
590 && strcmp(fl1
->dlist
[FILTER_OUT
].name
,
591 fl2
->dlist
[FILTER_OUT
].name
)))
594 if ((fl1
->plist
[FILTER_OUT
].name
&& !fl2
->plist
[FILTER_OUT
].name
)
595 || (!fl1
->plist
[FILTER_OUT
].name
&& fl2
->plist
[FILTER_OUT
].name
)
596 || (fl1
->plist
[FILTER_OUT
].name
&& fl2
->plist
[FILTER_OUT
].name
597 && strcmp(fl1
->plist
[FILTER_OUT
].name
,
598 fl2
->plist
[FILTER_OUT
].name
)))
601 if ((fl1
->aslist
[FILTER_OUT
].name
&& !fl2
->aslist
[FILTER_OUT
].name
)
602 || (!fl1
->aslist
[FILTER_OUT
].name
&& fl2
->aslist
[FILTER_OUT
].name
)
603 || (fl1
->aslist
[FILTER_OUT
].name
&& fl2
->aslist
[FILTER_OUT
].name
604 && strcmp(fl1
->aslist
[FILTER_OUT
].name
,
605 fl2
->aslist
[FILTER_OUT
].name
)))
608 if ((fl1
->usmap
.name
&& !fl2
->usmap
.name
)
609 || (!fl1
->usmap
.name
&& fl2
->usmap
.name
)
610 || (fl1
->usmap
.name
&& fl2
->usmap
.name
611 && strcmp(fl1
->usmap
.name
, fl2
->usmap
.name
)))
614 if ((fl1
->advmap
.aname
&& !fl2
->advmap
.aname
)
615 || (!fl1
->advmap
.aname
&& fl2
->advmap
.aname
)
616 || (fl1
->advmap
.aname
&& fl2
->advmap
.aname
617 && strcmp(fl1
->advmap
.aname
, fl2
->advmap
.aname
)))
620 if (fl1
->advmap
.update_type
!= fl2
->advmap
.update_type
)
623 if ((pe1
->default_rmap
[afi
][safi
].name
624 && !pe2
->default_rmap
[afi
][safi
].name
)
625 || (!pe1
->default_rmap
[afi
][safi
].name
626 && pe2
->default_rmap
[afi
][safi
].name
)
627 || (pe1
->default_rmap
[afi
][safi
].name
628 && pe2
->default_rmap
[afi
][safi
].name
629 && strcmp(pe1
->default_rmap
[afi
][safi
].name
,
630 pe2
->default_rmap
[afi
][safi
].name
)))
633 if ((afi
== AFI_IP6
) && (pe1
->shared_network
!= pe2
->shared_network
))
636 if ((CHECK_FLAG(pe1
->flags
, PEER_FLAG_LONESOUL
)
637 || CHECK_FLAG(pe1
->af_cap
[afi
][safi
], PEER_CAP_ORF_PREFIX_SM_RCV
)
638 || CHECK_FLAG(pe1
->af_cap
[afi
][safi
],
639 PEER_CAP_ORF_PREFIX_SM_OLD_RCV
))
640 && !sockunion_same(&pe1
->su
, &pe2
->su
))
646 static void peer_lonesoul_or_not(struct peer
*peer
, int set
)
648 /* no change in status? */
649 if (set
== (CHECK_FLAG(peer
->flags
, PEER_FLAG_LONESOUL
) > 0))
653 SET_FLAG(peer
->flags
, PEER_FLAG_LONESOUL
);
655 UNSET_FLAG(peer
->flags
, PEER_FLAG_LONESOUL
);
657 update_group_adjust_peer_afs(peer
);
661 * subgroup_total_packets_enqueued
663 * Returns the total number of packets enqueued to a subgroup.
666 subgroup_total_packets_enqueued(struct update_subgroup
*subgrp
)
670 pkt
= bpacket_queue_last(SUBGRP_PKTQ(subgrp
));
675 static int update_group_show_walkcb(struct update_group
*updgrp
, void *arg
)
677 struct updwalk_context
*ctx
= arg
;
679 struct update_subgroup
*subgrp
;
681 struct bgp_filter
*filter
;
682 struct peer
*peer
= UPDGRP_PEER(updgrp
);
684 json_object
*json_updgrp
= NULL
;
685 json_object
*json_subgrps
= NULL
;
686 json_object
*json_subgrp
= NULL
;
687 json_object
*json_time
= NULL
;
688 json_object
*json_subgrp_time
= NULL
;
689 json_object
*json_subgrp_event
= NULL
;
690 json_object
*json_peers
= NULL
;
691 json_object
*json_pkt_info
= NULL
;
692 time_t epoch_tbuf
, tbuf
;
697 if (ctx
->subgrp_id
) {
698 UPDGRP_FOREACH_SUBGRP (updgrp
, subgrp
) {
699 if (ctx
->subgrp_id
&& (ctx
->subgrp_id
!= subgrp
->id
))
711 /* Since this routine is invoked from a walk, we cannot signal
713 /* error here, can only return. */
720 json_updgrp
= json_object_new_object();
721 /* Display json o/p */
722 tbuf
= monotime(NULL
);
723 tbuf
-= updgrp
->uptime
;
724 epoch_tbuf
= time(NULL
) - tbuf
;
725 json_time
= json_object_new_object();
726 json_object_int_add(json_time
, "epoch", epoch_tbuf
);
727 json_object_string_add(json_time
, "epochString",
729 json_object_object_add(json_updgrp
, "groupCreateTime",
731 json_object_string_add(json_updgrp
, "afi",
732 afi2str(updgrp
->afi
));
733 json_object_string_add(json_updgrp
, "safi",
734 safi2str(updgrp
->safi
));
736 vty_out(vty
, "Update-group %" PRIu64
":\n", updgrp
->id
);
737 vty_out(vty
, " Created: %s", timestamp_string(updgrp
->uptime
));
740 filter
= &updgrp
->conf
->filter
[updgrp
->afi
][updgrp
->safi
];
741 if (filter
->map
[RMAP_OUT
].name
) {
743 json_object_string_add(json_updgrp
, "outRouteMap",
744 filter
->map
[RMAP_OUT
].name
);
746 vty_out(vty
, " Outgoing route map: %s\n",
747 filter
->map
[RMAP_OUT
].name
);
751 json_object_int_add(json_updgrp
, "minRouteAdvInt",
752 updgrp
->conf
->v_routeadv
);
754 vty_out(vty
, " MRAI value (seconds): %d\n",
755 updgrp
->conf
->v_routeadv
);
757 if (updgrp
->conf
->change_local_as
) {
759 json_object_int_add(json_updgrp
, "localAs",
760 updgrp
->conf
->change_local_as
);
761 json_object_boolean_add(
762 json_updgrp
, "noPrepend",
763 CHECK_FLAG(updgrp
->conf
->flags
,
764 PEER_FLAG_LOCAL_AS_NO_PREPEND
));
765 json_object_boolean_add(
766 json_updgrp
, "replaceLocalAs",
767 CHECK_FLAG(updgrp
->conf
->flags
,
768 PEER_FLAG_LOCAL_AS_REPLACE_AS
));
770 vty_out(vty
, " Local AS %u%s%s\n",
771 updgrp
->conf
->change_local_as
,
772 CHECK_FLAG(updgrp
->conf
->flags
,
773 PEER_FLAG_LOCAL_AS_NO_PREPEND
)
776 CHECK_FLAG(updgrp
->conf
->flags
,
777 PEER_FLAG_LOCAL_AS_REPLACE_AS
)
783 json_subgrps
= json_object_new_array();
784 UPDGRP_FOREACH_SUBGRP (updgrp
, subgrp
) {
785 if (ctx
->subgrp_id
&& (ctx
->subgrp_id
!= subgrp
->id
))
788 json_subgrp
= json_object_new_object();
789 json_object_int_add(json_subgrp
, "subGroupId",
791 tbuf
= monotime(NULL
);
792 tbuf
-= subgrp
->uptime
;
793 epoch_tbuf
= time(NULL
) - tbuf
;
794 json_subgrp_time
= json_object_new_object();
795 json_object_int_add(json_subgrp_time
, "epoch",
797 json_object_string_add(json_subgrp_time
, "epochString",
799 json_object_object_add(json_subgrp
, "groupCreateTime",
803 vty_out(vty
, " Update-subgroup %" PRIu64
":\n",
805 vty_out(vty
, " Created: %s",
806 timestamp_string(subgrp
->uptime
));
809 if (subgrp
->split_from
.update_group_id
810 || subgrp
->split_from
.subgroup_id
) {
813 json_subgrp
, "splitGroupId",
814 subgrp
->split_from
.update_group_id
);
816 json_subgrp
, "splitSubGroupId",
817 subgrp
->split_from
.subgroup_id
);
820 " Split from group id: %" PRIu64
822 subgrp
->split_from
.update_group_id
);
824 " Split from subgroup id: %" PRIu64
826 subgrp
->split_from
.subgroup_id
);
831 json_subgrp_event
= json_object_new_object();
832 json_object_int_add(json_subgrp_event
, "joinEvents",
833 subgrp
->join_events
);
834 json_object_int_add(json_subgrp_event
, "pruneEvents",
835 subgrp
->prune_events
);
836 json_object_int_add(json_subgrp_event
, "mergeEvents",
837 subgrp
->merge_events
);
838 json_object_int_add(json_subgrp_event
, "splitEvents",
839 subgrp
->split_events
);
840 json_object_int_add(json_subgrp_event
, "switchEvents",
841 subgrp
->updgrp_switch_events
);
842 json_object_int_add(json_subgrp_event
,
844 subgrp
->peer_refreshes_combined
);
845 json_object_int_add(json_subgrp_event
,
847 subgrp
->merge_checks_triggered
);
848 json_object_object_add(json_subgrp
, "statistics",
850 json_object_int_add(json_subgrp
, "coalesceTime",
851 (UPDGRP_INST(subgrp
->update_group
))
853 json_object_int_add(json_subgrp
, "version",
855 json_pkt_info
= json_object_new_object();
857 json_pkt_info
, "qeueueLen",
858 bpacket_queue_length(SUBGRP_PKTQ(subgrp
)));
860 json_pkt_info
, "queuedTotal",
861 subgroup_total_packets_enqueued(subgrp
));
863 json_pkt_info
, "queueHwmLen",
864 bpacket_queue_hwm_length(SUBGRP_PKTQ(subgrp
)));
866 json_pkt_info
, "totalEnqueued",
867 subgroup_total_packets_enqueued(subgrp
));
868 json_object_object_add(json_subgrp
, "packetQueueInfo",
870 json_object_int_add(json_subgrp
, "adjListCount",
872 json_object_boolean_add(
873 json_subgrp
, "needsRefresh",
874 CHECK_FLAG(subgrp
->flags
,
875 SUBGRP_FLAG_NEEDS_REFRESH
));
877 vty_out(vty
, " Join events: %u\n",
878 subgrp
->join_events
);
879 vty_out(vty
, " Prune events: %u\n",
880 subgrp
->prune_events
);
881 vty_out(vty
, " Merge events: %u\n",
882 subgrp
->merge_events
);
883 vty_out(vty
, " Split events: %u\n",
884 subgrp
->split_events
);
885 vty_out(vty
, " Update group switch events: %u\n",
886 subgrp
->updgrp_switch_events
);
887 vty_out(vty
, " Peer refreshes combined: %u\n",
888 subgrp
->peer_refreshes_combined
);
889 vty_out(vty
, " Merge checks triggered: %u\n",
890 subgrp
->merge_checks_triggered
);
891 vty_out(vty
, " Coalesce Time: %u%s\n",
892 (UPDGRP_INST(subgrp
->update_group
))
894 subgrp
->t_coalesce
? "(Running)" : "");
895 vty_out(vty
, " Version: %" PRIu64
"\n",
897 vty_out(vty
, " Packet queue length: %d\n",
898 bpacket_queue_length(SUBGRP_PKTQ(subgrp
)));
899 vty_out(vty
, " Total packets enqueued: %u\n",
900 subgroup_total_packets_enqueued(subgrp
));
901 vty_out(vty
, " Packet queue high watermark: %d\n",
902 bpacket_queue_hwm_length(SUBGRP_PKTQ(subgrp
)));
903 vty_out(vty
, " Adj-out list count: %u\n",
905 vty_out(vty
, " Advertise list: %s\n",
906 advertise_list_is_empty(subgrp
) ? "empty"
908 vty_out(vty
, " Flags: %s\n",
909 CHECK_FLAG(subgrp
->flags
,
910 SUBGRP_FLAG_NEEDS_REFRESH
)
914 vty_out(vty
, " Max packet size: %d\n",
915 peer
->max_packet_size
);
917 if (subgrp
->peer_count
> 0) {
919 json_peers
= json_object_new_array();
920 SUBGRP_FOREACH_PEER (subgrp
, paf
) {
922 json_object_new_string(
924 json_object_array_add(json_peers
, peer
);
926 json_object_object_add(json_subgrp
, "peers",
929 vty_out(vty
, " Peers:\n");
930 SUBGRP_FOREACH_PEER (subgrp
, paf
)
931 vty_out(vty
, " - %s\n",
937 json_object_array_add(json_subgrps
, json_subgrp
);
941 json_object_object_add(json_updgrp
, "subGroup", json_subgrps
);
942 json_object_object_addf(ctx
->json_updategrps
, json_updgrp
,
943 "%" PRIu64
, updgrp
->id
);
946 return UPDWALK_CONTINUE
;
950 * Helper function to show the packet queue for each subgroup of update group.
951 * Will be constrained to a particular subgroup id if id !=0
953 static int updgrp_show_packet_queue_walkcb(struct update_group
*updgrp
,
956 struct updwalk_context
*ctx
= arg
;
957 struct update_subgroup
*subgrp
;
961 UPDGRP_FOREACH_SUBGRP (updgrp
, subgrp
) {
962 if (ctx
->subgrp_id
&& (ctx
->subgrp_id
!= subgrp
->id
))
964 vty_out(vty
, "update group %" PRIu64
", subgroup %" PRIu64
"\n",
965 updgrp
->id
, subgrp
->id
);
966 bpacket_queue_show_vty(SUBGRP_PKTQ(subgrp
), vty
);
968 return UPDWALK_CONTINUE
;
972 * Show the packet queue for each subgroup of update group. Will be
973 * constrained to a particular subgroup id if id !=0
975 void update_group_show_packet_queue(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
976 struct vty
*vty
, uint64_t id
)
978 struct updwalk_context ctx
;
980 memset(&ctx
, 0, sizeof(ctx
));
984 update_group_af_walk(bgp
, afi
, safi
, updgrp_show_packet_queue_walkcb
,
988 static struct update_group
*update_group_find(struct peer_af
*paf
)
990 struct update_group
*updgrp
;
991 struct update_group tmp
;
992 struct peer tmp_conf
;
994 if (!peer_established(PAF_PEER(paf
)))
997 memset(&tmp
, 0, sizeof(tmp
));
998 memset(&tmp_conf
, 0, sizeof(tmp_conf
));
999 tmp
.conf
= &tmp_conf
;
1000 peer2_updgrp_copy(&tmp
, paf
);
1002 updgrp
= hash_lookup(paf
->peer
->bgp
->update_groups
[paf
->afid
], &tmp
);
1003 conf_release(&tmp_conf
, paf
->afi
, paf
->safi
);
1007 static struct update_group
*update_group_create(struct peer_af
*paf
)
1009 struct update_group
*updgrp
;
1010 struct update_group tmp
;
1011 struct peer tmp_conf
;
1013 memset(&tmp
, 0, sizeof(tmp
));
1014 memset(&tmp_conf
, 0, sizeof(tmp_conf
));
1015 tmp
.conf
= &tmp_conf
;
1016 peer2_updgrp_copy(&tmp
, paf
);
1018 updgrp
= hash_get(paf
->peer
->bgp
->update_groups
[paf
->afid
], &tmp
,
1020 update_group_checkin(updgrp
);
1022 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
1023 zlog_debug("create update group %" PRIu64
, updgrp
->id
);
1025 UPDGRP_GLOBAL_STAT(updgrp
, updgrps_created
) += 1;
1027 conf_release(&tmp_conf
, paf
->afi
, paf
->safi
);
1031 static void update_group_delete(struct update_group
*updgrp
)
1033 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
1034 zlog_debug("delete update group %" PRIu64
, updgrp
->id
);
1036 UPDGRP_GLOBAL_STAT(updgrp
, updgrps_deleted
) += 1;
1038 hash_release(updgrp
->bgp
->update_groups
[updgrp
->afid
], updgrp
);
1039 conf_release(updgrp
->conf
, updgrp
->afi
, updgrp
->safi
);
1041 XFREE(MTYPE_BGP_PEER_HOST
, updgrp
->conf
->host
);
1043 XFREE(MTYPE_BGP_PEER_IFNAME
, updgrp
->conf
->ifname
);
1045 XFREE(MTYPE_BGP_PEER
, updgrp
->conf
);
1046 XFREE(MTYPE_BGP_UPDGRP
, updgrp
);
1049 static void update_group_add_subgroup(struct update_group
*updgrp
,
1050 struct update_subgroup
*subgrp
)
1052 if (!updgrp
|| !subgrp
)
1055 LIST_INSERT_HEAD(&(updgrp
->subgrps
), subgrp
, updgrp_train
);
1056 subgrp
->update_group
= updgrp
;
1059 static void update_group_remove_subgroup(struct update_group
*updgrp
,
1060 struct update_subgroup
*subgrp
)
1062 if (!updgrp
|| !subgrp
)
1065 LIST_REMOVE(subgrp
, updgrp_train
);
1066 subgrp
->update_group
= NULL
;
1067 if (LIST_EMPTY(&(updgrp
->subgrps
)))
1068 update_group_delete(updgrp
);
1071 static struct update_subgroup
*
1072 update_subgroup_create(struct update_group
*updgrp
)
1074 struct update_subgroup
*subgrp
;
1076 subgrp
= XCALLOC(MTYPE_BGP_UPD_SUBGRP
, sizeof(struct update_subgroup
));
1077 update_subgroup_checkin(subgrp
, updgrp
);
1078 subgrp
->v_coalesce
= (UPDGRP_INST(updgrp
))->coalesce_time
;
1079 sync_init(subgrp
, updgrp
);
1080 bpacket_queue_init(SUBGRP_PKTQ(subgrp
));
1081 bpacket_queue_add(SUBGRP_PKTQ(subgrp
), NULL
, NULL
);
1082 TAILQ_INIT(&(subgrp
->adjq
));
1083 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
1084 zlog_debug("create subgroup u%" PRIu64
":s%" PRIu64
, updgrp
->id
,
1087 update_group_add_subgroup(updgrp
, subgrp
);
1089 UPDGRP_INCR_STAT(updgrp
, subgrps_created
);
1094 static void update_subgroup_delete(struct update_subgroup
*subgrp
)
1099 if (subgrp
->update_group
)
1100 UPDGRP_INCR_STAT(subgrp
->update_group
, subgrps_deleted
);
1102 EVENT_OFF(subgrp
->t_merge_check
);
1103 EVENT_OFF(subgrp
->t_coalesce
);
1105 bpacket_queue_cleanup(SUBGRP_PKTQ(subgrp
));
1106 subgroup_clear_table(subgrp
);
1108 sync_delete(subgrp
);
1110 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
) && subgrp
->update_group
)
1111 zlog_debug("delete subgroup u%" PRIu64
":s%" PRIu64
,
1112 subgrp
->update_group
->id
, subgrp
->id
);
1114 update_group_remove_subgroup(subgrp
->update_group
, subgrp
);
1116 XFREE(MTYPE_BGP_UPD_SUBGRP
, subgrp
);
1119 void update_subgroup_inherit_info(struct update_subgroup
*to
,
1120 struct update_subgroup
*from
)
1125 to
->sflags
= from
->sflags
;
1129 * update_subgroup_check_delete
1131 * Delete a subgroup if it is ready to be deleted.
1133 * Returns true if the subgroup was deleted.
1135 static bool update_subgroup_check_delete(struct update_subgroup
*subgrp
)
1140 if (!LIST_EMPTY(&(subgrp
->peers
)))
1143 update_subgroup_delete(subgrp
);
1149 * update_subgroup_add_peer
1151 * @param send_enqueued_packets If true all currently enqueued packets will
1152 * also be sent to the peer.
1154 static void update_subgroup_add_peer(struct update_subgroup
*subgrp
,
1155 struct peer_af
*paf
,
1156 int send_enqueued_pkts
)
1158 struct bpacket
*pkt
;
1160 if (!subgrp
|| !paf
)
1163 LIST_INSERT_HEAD(&(subgrp
->peers
), paf
, subgrp_train
);
1164 paf
->subgroup
= subgrp
;
1165 subgrp
->peer_count
++;
1167 if (bgp_debug_peer_updout_enabled(paf
->peer
->host
)) {
1168 UPDGRP_PEER_DBG_EN(subgrp
->update_group
);
1171 SUBGRP_INCR_STAT(subgrp
, join_events
);
1173 if (send_enqueued_pkts
) {
1174 pkt
= bpacket_queue_first(SUBGRP_PKTQ(subgrp
));
1178 * Hang the peer off of the last, placeholder, packet in the
1179 * queue. This means it won't see any of the packets that are
1180 * currently the queue.
1182 pkt
= bpacket_queue_last(SUBGRP_PKTQ(subgrp
));
1183 assert(pkt
->buffer
== NULL
);
1186 bpacket_add_peer(pkt
, paf
);
1188 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
1189 zlog_debug("peer %s added to subgroup s%" PRIu64
,
1190 paf
->peer
->host
, subgrp
->id
);
1194 * update_subgroup_remove_peer_internal
1196 * Internal function that removes a peer from a subgroup, but does not
1197 * delete the subgroup. A call to this function must almost always be
1198 * followed by a call to update_subgroup_check_delete().
1200 * @see update_subgroup_remove_peer
1202 static void update_subgroup_remove_peer_internal(struct update_subgroup
*subgrp
,
1203 struct peer_af
*paf
)
1205 assert(subgrp
&& paf
&& subgrp
->update_group
);
1207 if (bgp_debug_peer_updout_enabled(paf
->peer
->host
)) {
1208 UPDGRP_PEER_DBG_DIS(subgrp
->update_group
);
1211 bpacket_queue_remove_peer(paf
);
1212 LIST_REMOVE(paf
, subgrp_train
);
1213 paf
->subgroup
= NULL
;
1214 subgrp
->peer_count
--;
1216 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
1217 zlog_debug("peer %s deleted from subgroup s%"
1218 PRIu64
" peer cnt %d",
1219 paf
->peer
->host
, subgrp
->id
, subgrp
->peer_count
);
1220 SUBGRP_INCR_STAT(subgrp
, prune_events
);
1224 * update_subgroup_remove_peer
1226 void update_subgroup_remove_peer(struct update_subgroup
*subgrp
,
1227 struct peer_af
*paf
)
1229 if (!subgrp
|| !paf
)
1232 update_subgroup_remove_peer_internal(subgrp
, paf
);
1234 if (update_subgroup_check_delete(subgrp
))
1238 * The deletion of the peer may have caused some packets to be
1239 * deleted from the subgroup packet queue. Check if the subgroup can
1242 update_subgroup_check_merge(subgrp
, "removed peer from subgroup");
1245 static struct update_subgroup
*update_subgroup_find(struct update_group
*updgrp
,
1246 struct peer_af
*paf
)
1248 struct update_subgroup
*subgrp
= NULL
;
1251 if (paf
->subgroup
) {
1257 if (!peer_established(PAF_PEER(paf
)))
1260 UPDGRP_FOREACH_SUBGRP (updgrp
, subgrp
) {
1261 if (subgrp
->version
!= version
1262 || CHECK_FLAG(subgrp
->sflags
,
1263 SUBGRP_STATUS_DEFAULT_ORIGINATE
))
1267 * The version number is not meaningful on a subgroup that needs
1270 if (update_subgroup_needs_refresh(subgrp
))
1280 * update_subgroup_ready_for_merge
1282 * Returns true if this subgroup is in a state that allows it to be
1283 * merged into another subgroup.
1285 static bool update_subgroup_ready_for_merge(struct update_subgroup
*subgrp
)
1289 * Not ready if there are any encoded packets waiting to be written
1292 if (!bpacket_queue_is_empty(SUBGRP_PKTQ(subgrp
)))
1296 * Not ready if there enqueued updates waiting to be encoded.
1298 if (!advertise_list_is_empty(subgrp
))
1302 * Don't attempt to merge a subgroup that needs a refresh. For one,
1303 * we can't determine if the adj_out of such a group matches that of
1306 if (update_subgroup_needs_refresh(subgrp
))
1313 * update_subgrp_can_merge_into
1315 * Returns true if the first subgroup can merge into the second
1318 static int update_subgroup_can_merge_into(struct update_subgroup
*subgrp
,
1319 struct update_subgroup
*target
)
1322 if (subgrp
== target
)
1326 * Both must have processed the BRIB to the same point in order to
1329 if (subgrp
->version
!= target
->version
)
1332 if (CHECK_FLAG(subgrp
->sflags
, SUBGRP_STATUS_DEFAULT_ORIGINATE
)
1333 != CHECK_FLAG(target
->sflags
, SUBGRP_STATUS_DEFAULT_ORIGINATE
))
1336 if (subgrp
->adj_count
!= target
->adj_count
)
1339 return update_subgroup_ready_for_merge(target
);
1343 * update_subgroup_merge
1345 * Merge the first subgroup into the second one.
1347 static void update_subgroup_merge(struct update_subgroup
*subgrp
,
1348 struct update_subgroup
*target
,
1351 struct peer_af
*paf
;
1355 assert(subgrp
->adj_count
== target
->adj_count
);
1357 peer_count
= subgrp
->peer_count
;
1360 paf
= LIST_FIRST(&subgrp
->peers
);
1364 update_subgroup_remove_peer_internal(subgrp
, paf
);
1367 * Add the peer to the target subgroup, while making sure that
1368 * any currently enqueued packets won't be sent to it. Enqueued
1369 * packets could, for example, result in an unnecessary withdraw
1370 * followed by an advertise.
1372 update_subgroup_add_peer(target
, paf
, 0);
1375 SUBGRP_INCR_STAT(target
, merge_events
);
1377 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
1378 zlog_debug("u%" PRIu64
":s%" PRIu64
" (%d peers) merged into u%" PRIu64
":s%" PRIu64
", trigger: %s",
1379 subgrp
->update_group
->id
, subgrp
->id
, peer_count
,
1380 target
->update_group
->id
, target
->id
,
1381 reason
? reason
: "unknown");
1383 result
= update_subgroup_check_delete(subgrp
);
1388 * update_subgroup_check_merge
1390 * Merge this subgroup into another subgroup if possible.
1392 * Returns true if the subgroup has been merged. The subgroup pointer
1393 * should not be accessed in this case.
1395 bool update_subgroup_check_merge(struct update_subgroup
*subgrp
,
1398 struct update_subgroup
*target
;
1400 if (!update_subgroup_ready_for_merge(subgrp
))
1404 * Look for a subgroup to merge into.
1406 UPDGRP_FOREACH_SUBGRP (subgrp
->update_group
, target
) {
1407 if (update_subgroup_can_merge_into(subgrp
, target
))
1414 update_subgroup_merge(subgrp
, target
, reason
);
1419 * update_subgroup_merge_check_thread_cb
1421 static void update_subgroup_merge_check_thread_cb(struct event
*thread
)
1423 struct update_subgroup
*subgrp
;
1425 subgrp
= EVENT_ARG(thread
);
1427 subgrp
->t_merge_check
= NULL
;
1429 update_subgroup_check_merge(subgrp
, "triggered merge check");
1433 * update_subgroup_trigger_merge_check
1435 * Triggers a call to update_subgroup_check_merge() on a clean context.
1437 * @param force If true, the merge check will be triggered even if the
1438 * subgroup doesn't currently look ready for a merge.
1440 * Returns true if a merge check will be performed shortly.
1442 bool update_subgroup_trigger_merge_check(struct update_subgroup
*subgrp
,
1445 if (subgrp
->t_merge_check
)
1448 if (!force
&& !update_subgroup_ready_for_merge(subgrp
))
1451 subgrp
->t_merge_check
= NULL
;
1452 event_add_timer_msec(bm
->master
, update_subgroup_merge_check_thread_cb
,
1453 subgrp
, 0, &subgrp
->t_merge_check
);
1455 SUBGRP_INCR_STAT(subgrp
, merge_checks_triggered
);
1461 * update_subgroup_copy_adj_out
1463 * Helper function that clones the adj out (state about advertised
1464 * routes) from one subgroup to another. It assumes that the adj out
1465 * of the target subgroup is empty.
1467 static void update_subgroup_copy_adj_out(struct update_subgroup
*source
,
1468 struct update_subgroup
*dest
)
1470 struct bgp_adj_out
*aout
, *aout_copy
;
1472 SUBGRP_FOREACH_ADJ (source
, aout
) {
1476 aout_copy
= bgp_adj_out_alloc(dest
, aout
->dest
,
1477 aout
->addpath_tx_id
);
1479 aout
->attr
? bgp_attr_intern(aout
->attr
) : NULL
;
1482 dest
->scount
= source
->scount
;
1486 * update_subgroup_copy_packets
1488 * Copy packets after and including the given packet to the subgroup
1491 * Returns the number of packets copied.
1493 static int update_subgroup_copy_packets(struct update_subgroup
*dest
,
1494 struct bpacket
*pkt
)
1499 while (pkt
&& pkt
->buffer
) {
1500 bpacket_queue_add(SUBGRP_PKTQ(dest
), stream_dup(pkt
->buffer
),
1503 pkt
= bpacket_next(pkt
);
1509 static bool updgrp_prefix_list_update(struct update_group
*updgrp
,
1513 struct bgp_filter
*filter
;
1515 peer
= UPDGRP_PEER(updgrp
);
1516 filter
= &peer
->filter
[UPDGRP_AFI(updgrp
)][UPDGRP_SAFI(updgrp
)];
1518 if (PREFIX_LIST_OUT_NAME(filter
)
1519 && (strcmp(name
, PREFIX_LIST_OUT_NAME(filter
)) == 0)) {
1520 PREFIX_LIST_OUT(filter
) = prefix_list_lookup(
1521 UPDGRP_AFI(updgrp
), PREFIX_LIST_OUT_NAME(filter
));
1527 static bool updgrp_filter_list_update(struct update_group
*updgrp
,
1531 struct bgp_filter
*filter
;
1533 peer
= UPDGRP_PEER(updgrp
);
1534 filter
= &peer
->filter
[UPDGRP_AFI(updgrp
)][UPDGRP_SAFI(updgrp
)];
1536 if (FILTER_LIST_OUT_NAME(filter
)
1537 && (strcmp(name
, FILTER_LIST_OUT_NAME(filter
)) == 0)) {
1538 FILTER_LIST_OUT(filter
) =
1539 as_list_lookup(FILTER_LIST_OUT_NAME(filter
));
1545 static bool updgrp_distribute_list_update(struct update_group
*updgrp
,
1549 struct bgp_filter
*filter
;
1551 peer
= UPDGRP_PEER(updgrp
);
1552 filter
= &peer
->filter
[UPDGRP_AFI(updgrp
)][UPDGRP_SAFI(updgrp
)];
1554 if (DISTRIBUTE_OUT_NAME(filter
)
1555 && (strcmp(name
, DISTRIBUTE_OUT_NAME(filter
)) == 0)) {
1556 DISTRIBUTE_OUT(filter
) = access_list_lookup(
1557 UPDGRP_AFI(updgrp
), DISTRIBUTE_OUT_NAME(filter
));
1563 static int updgrp_route_map_update(struct update_group
*updgrp
,
1564 const char *name
, int *def_rmap_changed
)
1567 struct bgp_filter
*filter
;
1572 peer
= UPDGRP_PEER(updgrp
);
1573 afi
= UPDGRP_AFI(updgrp
);
1574 safi
= UPDGRP_SAFI(updgrp
);
1575 filter
= &peer
->filter
[afi
][safi
];
1577 if (ROUTE_MAP_OUT_NAME(filter
)
1578 && (strcmp(name
, ROUTE_MAP_OUT_NAME(filter
)) == 0)) {
1579 ROUTE_MAP_OUT(filter
) = route_map_lookup_by_name(name
);
1584 if (UNSUPPRESS_MAP_NAME(filter
)
1585 && (strcmp(name
, UNSUPPRESS_MAP_NAME(filter
)) == 0)) {
1586 UNSUPPRESS_MAP(filter
) = route_map_lookup_by_name(name
);
1590 /* process default-originate route-map */
1591 if (peer
->default_rmap
[afi
][safi
].name
1592 && (strcmp(name
, peer
->default_rmap
[afi
][safi
].name
) == 0)) {
1593 peer
->default_rmap
[afi
][safi
].map
=
1594 route_map_lookup_by_name(name
);
1595 if (def_rmap_changed
)
1596 *def_rmap_changed
= 1;
1602 * hash iteration callback function to process a policy change for an
1603 * update group. Check if the changed policy matches the updgrp's
1604 * outbound route-map or unsuppress-map or default-originate map or
1605 * filter-list or prefix-list or distribute-list.
1606 * Trigger update generation accordingly.
1608 static int updgrp_policy_update_walkcb(struct update_group
*updgrp
, void *arg
)
1610 struct updwalk_context
*ctx
= arg
;
1611 struct update_subgroup
*subgrp
;
1613 int def_changed
= 0;
1615 if (!updgrp
|| !ctx
|| !ctx
->policy_name
)
1616 return UPDWALK_CONTINUE
;
1618 switch (ctx
->policy_type
) {
1619 case BGP_POLICY_ROUTE_MAP
:
1620 changed
= updgrp_route_map_update(updgrp
, ctx
->policy_name
,
1623 case BGP_POLICY_FILTER_LIST
:
1624 changed
= updgrp_filter_list_update(updgrp
, ctx
->policy_name
);
1626 case BGP_POLICY_PREFIX_LIST
:
1627 changed
= updgrp_prefix_list_update(updgrp
, ctx
->policy_name
);
1629 case BGP_POLICY_DISTRIBUTE_LIST
:
1631 updgrp_distribute_list_update(updgrp
, ctx
->policy_name
);
1637 /* If not doing route update, return after updating "config" */
1638 if (!ctx
->policy_route_update
)
1639 return UPDWALK_CONTINUE
;
1641 /* If nothing has changed, return after updating "config" */
1642 if (!changed
&& !def_changed
)
1643 return UPDWALK_CONTINUE
;
1646 * If something has changed, at the beginning of a route-map
1648 * event, mark each subgroup's needs-refresh bit. For one, it signals to
1649 * whoever that the subgroup needs a refresh. Second, it prevents
1651 * merge of this subgroup with another before a complete (outbound)
1654 if (ctx
->policy_event_start_flag
) {
1655 UPDGRP_FOREACH_SUBGRP (updgrp
, subgrp
) {
1656 update_subgroup_set_needs_refresh(subgrp
, 1);
1658 return UPDWALK_CONTINUE
;
1661 UPDGRP_FOREACH_SUBGRP (updgrp
, subgrp
) {
1662 /* Avoid supressing duplicate routes later
1663 * when processing in subgroup_announce_table().
1665 SET_FLAG(subgrp
->sflags
, SUBGRP_STATUS_FORCE_UPDATES
);
1668 if (bgp_debug_update(NULL
, NULL
, updgrp
, 0))
1670 "u%" PRIu64
":s%" PRIu64
" announcing routes upon policy %s (type %d) change",
1671 updgrp
->id
, subgrp
->id
,
1672 ctx
->policy_name
, ctx
->policy_type
);
1673 subgroup_announce_route(subgrp
);
1676 if (bgp_debug_update(NULL
, NULL
, updgrp
, 0))
1678 "u%" PRIu64
":s%" PRIu64
" announcing default upon default routemap %s change",
1679 updgrp
->id
, subgrp
->id
,
1681 if (route_map_lookup_by_name(ctx
->policy_name
)) {
1683 * When there is change in routemap, this flow
1684 * is triggered. the routemap is still present
1685 * in lib, hence its a update flow. The flag
1686 * needs to be unset.
1688 UNSET_FLAG(subgrp
->sflags
,
1689 SUBGRP_STATUS_DEFAULT_ORIGINATE
);
1690 subgroup_default_originate(subgrp
, 0);
1693 * This is a explicit withdraw, since the
1694 * routemap is not present in routemap lib. need
1695 * to pass 1 for withdraw arg.
1697 subgroup_default_originate(subgrp
, 1);
1700 update_subgroup_set_needs_refresh(subgrp
, 0);
1702 return UPDWALK_CONTINUE
;
1705 static int update_group_walkcb(struct hash_bucket
*bucket
, void *arg
)
1707 struct update_group
*updgrp
= bucket
->data
;
1708 struct updwalk_context
*wctx
= arg
;
1709 int ret
= (*wctx
->cb
)(updgrp
, wctx
->context
);
1713 static int update_group_periodic_merge_walkcb(struct update_group
*updgrp
,
1716 struct update_subgroup
*subgrp
;
1717 struct update_subgroup
*tmp_subgrp
;
1718 const char *reason
= arg
;
1720 UPDGRP_FOREACH_SUBGRP_SAFE (updgrp
, subgrp
, tmp_subgrp
)
1721 update_subgroup_check_merge(subgrp
, reason
);
1722 return UPDWALK_CONTINUE
;
1725 /********************
1727 ********************/
1730 * trigger function when a policy (route-map/filter-list/prefix-list/
1731 * distribute-list etc.) content changes. Go through all the
1732 * update groups and process the change.
1734 * bgp: the bgp instance
1735 * ptype: the type of policy that got modified, see bgpd.h
1736 * pname: name of the policy
1737 * route_update: flag to control if an automatic update generation should
1739 * start_event: flag that indicates if it's the beginning of the change.
1740 * Esp. when the user is changing the content interactively
1741 * over multiple statements. Useful to set dirty flag on
1744 void update_group_policy_update(struct bgp
*bgp
, enum bgp_policy_type ptype
,
1745 const char *pname
, bool route_update
,
1748 struct updwalk_context ctx
;
1750 memset(&ctx
, 0, sizeof(ctx
));
1751 ctx
.policy_type
= ptype
;
1752 ctx
.policy_name
= pname
;
1753 ctx
.policy_route_update
= route_update
;
1754 ctx
.policy_event_start_flag
= start_event
;
1757 update_group_walk(bgp
, updgrp_policy_update_walkcb
, &ctx
);
1761 * update_subgroup_split_peer
1763 * Ensure that the given peer is in a subgroup of its own in the
1764 * specified update group.
1766 void update_subgroup_split_peer(struct peer_af
*paf
,
1767 struct update_group
*updgrp
)
1769 struct update_subgroup
*old_subgrp
, *subgrp
;
1773 old_subgrp
= paf
->subgroup
;
1776 updgrp
= old_subgrp
->update_group
;
1779 * If the peer is alone in its subgroup, reuse the existing
1782 if (old_subgrp
->peer_count
== 1) {
1783 if (updgrp
== old_subgrp
->update_group
)
1786 subgrp
= old_subgrp
;
1787 old_id
= old_subgrp
->update_group
->id
;
1789 if (bgp_debug_peer_updout_enabled(paf
->peer
->host
)) {
1790 UPDGRP_PEER_DBG_DIS(old_subgrp
->update_group
);
1793 update_group_remove_subgroup(old_subgrp
->update_group
,
1795 update_group_add_subgroup(updgrp
, subgrp
);
1797 if (bgp_debug_peer_updout_enabled(paf
->peer
->host
)) {
1798 UPDGRP_PEER_DBG_EN(updgrp
);
1800 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
1801 zlog_debug("u%" PRIu64
":s%" PRIu64
" peer %s moved to u%" PRIu64
":s%" PRIu64
,
1802 old_id
, subgrp
->id
, paf
->peer
->host
,
1803 updgrp
->id
, subgrp
->id
);
1806 * The state of the subgroup (adj_out, advs, packet queue etc)
1807 * is consistent internally, but may not be identical to other
1808 * subgroups in the new update group even if the version number
1809 * matches up. Make sure a full refresh is done before the
1810 * subgroup is merged with another.
1812 update_subgroup_set_needs_refresh(subgrp
, 1);
1814 SUBGRP_INCR_STAT(subgrp
, updgrp_switch_events
);
1819 * Create a new subgroup under the specified update group, and copy
1820 * over relevant state to it.
1822 subgrp
= update_subgroup_create(updgrp
);
1823 update_subgroup_inherit_info(subgrp
, old_subgrp
);
1825 subgrp
->split_from
.update_group_id
= old_subgrp
->update_group
->id
;
1826 subgrp
->split_from
.subgroup_id
= old_subgrp
->id
;
1829 * Copy out relevant state from the old subgroup.
1831 update_subgroup_copy_adj_out(paf
->subgroup
, subgrp
);
1832 update_subgroup_copy_packets(subgrp
, paf
->next_pkt_to_send
);
1834 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
1835 zlog_debug("u%" PRIu64
":s%" PRIu64
" peer %s split and moved into u%" PRIu64
":s%" PRIu64
,
1836 paf
->subgroup
->update_group
->id
, paf
->subgroup
->id
,
1837 paf
->peer
->host
, updgrp
->id
, subgrp
->id
);
1839 SUBGRP_INCR_STAT(paf
->subgroup
, split_events
);
1842 * Since queued advs were left behind, this new subgroup needs a
1845 update_subgroup_set_needs_refresh(subgrp
, 1);
1848 * Remove peer from old subgroup, and add it to the new one.
1850 update_subgroup_remove_peer(paf
->subgroup
, paf
);
1852 update_subgroup_add_peer(subgrp
, paf
, 1);
1855 void update_bgp_group_init(struct bgp
*bgp
)
1860 bgp
->update_groups
[afid
] =
1861 hash_create(updgrp_hash_key_make
, updgrp_hash_cmp
,
1862 "BGP Update Group Hash");
1865 void update_bgp_group_free(struct bgp
*bgp
)
1870 if (bgp
->update_groups
[afid
]) {
1871 hash_free(bgp
->update_groups
[afid
]);
1872 bgp
->update_groups
[afid
] = NULL
;
1877 void update_group_show(struct bgp
*bgp
, afi_t afi
, safi_t safi
, struct vty
*vty
,
1878 uint64_t subgrp_id
, bool uj
)
1880 struct updwalk_context ctx
;
1881 json_object
*json_vrf_obj
= NULL
;
1883 memset(&ctx
, 0, sizeof(ctx
));
1885 ctx
.subgrp_id
= subgrp_id
;
1889 ctx
.json_updategrps
= json_object_new_object();
1890 json_vrf_obj
= json_object_new_object();
1893 update_group_af_walk(bgp
, afi
, safi
, update_group_show_walkcb
, &ctx
);
1898 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
)
1899 vname
= VRF_DEFAULT_NAME
;
1902 json_object_object_add(json_vrf_obj
, vname
,
1903 ctx
.json_updategrps
);
1904 vty_json(vty
, json_vrf_obj
);
1909 * update_group_show_stats
1911 * Show global statistics about update groups.
1913 void update_group_show_stats(struct bgp
*bgp
, struct vty
*vty
)
1915 vty_out(vty
, "Update groups created: %u\n",
1916 bgp
->update_group_stats
.updgrps_created
);
1917 vty_out(vty
, "Update groups deleted: %u\n",
1918 bgp
->update_group_stats
.updgrps_deleted
);
1919 vty_out(vty
, "Update subgroups created: %u\n",
1920 bgp
->update_group_stats
.subgrps_created
);
1921 vty_out(vty
, "Update subgroups deleted: %u\n",
1922 bgp
->update_group_stats
.subgrps_deleted
);
1923 vty_out(vty
, "Join events: %u\n", bgp
->update_group_stats
.join_events
);
1924 vty_out(vty
, "Prune events: %u\n",
1925 bgp
->update_group_stats
.prune_events
);
1926 vty_out(vty
, "Merge events: %u\n",
1927 bgp
->update_group_stats
.merge_events
);
1928 vty_out(vty
, "Split events: %u\n",
1929 bgp
->update_group_stats
.split_events
);
1930 vty_out(vty
, "Update group switch events: %u\n",
1931 bgp
->update_group_stats
.updgrp_switch_events
);
1932 vty_out(vty
, "Peer route refreshes combined: %u\n",
1933 bgp
->update_group_stats
.peer_refreshes_combined
);
1934 vty_out(vty
, "Merge checks triggered: %u\n",
1935 bgp
->update_group_stats
.merge_checks_triggered
);
1939 * update_group_adjust_peer
1941 void update_group_adjust_peer(struct peer_af
*paf
)
1943 struct update_group
*updgrp
;
1944 struct update_subgroup
*subgrp
, *old_subgrp
;
1950 peer
= PAF_PEER(paf
);
1951 if (!peer_established(peer
)) {
1955 if (!CHECK_FLAG(peer
->flags
, PEER_FLAG_CONFIG_NODE
)) {
1959 if (!peer
->afc_nego
[paf
->afi
][paf
->safi
]) {
1963 updgrp
= update_group_find(paf
);
1965 updgrp
= update_group_create(paf
);
1967 old_subgrp
= paf
->subgroup
;
1972 * If the update group of the peer is unchanged, the peer can
1974 * in its existing subgroup and we're done.
1976 if (old_subgrp
->update_group
== updgrp
)
1980 * The peer is switching between update groups. Put it in its
1981 * own subgroup under the new update group.
1983 update_subgroup_split_peer(paf
, updgrp
);
1987 subgrp
= update_subgroup_find(updgrp
, paf
);
1989 subgrp
= update_subgroup_create(updgrp
);
1991 update_subgroup_add_peer(subgrp
, paf
, 1);
1992 if (BGP_DEBUG(update_groups
, UPDATE_GROUPS
))
1993 zlog_debug("u%" PRIu64
":s%" PRIu64
" add peer %s", updgrp
->id
,
1994 subgrp
->id
, paf
->peer
->host
);
1999 int update_group_adjust_soloness(struct peer
*peer
, int set
)
2001 struct peer_group
*group
;
2002 struct listnode
*node
, *nnode
;
2004 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
2005 peer_lonesoul_or_not(peer
, set
);
2006 if (peer_established(peer
))
2007 bgp_announce_route_all(peer
);
2009 group
= peer
->group
;
2010 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
, peer
)) {
2011 peer_lonesoul_or_not(peer
, set
);
2012 if (peer_established(peer
))
2013 bgp_announce_route_all(peer
);
2020 * update_subgroup_rib
2022 struct bgp_table
*update_subgroup_rib(struct update_subgroup
*subgrp
)
2026 bgp
= SUBGRP_INST(subgrp
);
2030 return bgp
->rib
[SUBGRP_AFI(subgrp
)][SUBGRP_SAFI(subgrp
)];
2033 void update_group_af_walk(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
2034 updgrp_walkcb cb
, void *ctx
)
2036 struct updwalk_context wctx
;
2041 afid
= afindex(afi
, safi
);
2042 if (afid
>= BGP_AF_MAX
)
2045 memset(&wctx
, 0, sizeof(wctx
));
2049 if (bgp
->update_groups
[afid
])
2050 hash_walk(bgp
->update_groups
[afid
], update_group_walkcb
, &wctx
);
2053 void update_group_walk(struct bgp
*bgp
, updgrp_walkcb cb
, void *ctx
)
2058 FOREACH_AFI_SAFI (afi
, safi
) {
2059 update_group_af_walk(bgp
, afi
, safi
, cb
, ctx
);
2063 void update_group_periodic_merge(struct bgp
*bgp
)
2065 char reason
[] = "periodic merge check";
2067 update_group_walk(bgp
, update_group_periodic_merge_walkcb
,
2072 update_group_default_originate_route_map_walkcb(struct update_group
*updgrp
,
2075 struct update_subgroup
*subgrp
;
2080 UPDGRP_FOREACH_SUBGRP (updgrp
, subgrp
) {
2081 peer
= SUBGRP_PEER(subgrp
);
2082 afi
= SUBGRP_AFI(subgrp
);
2083 safi
= SUBGRP_SAFI(subgrp
);
2085 if (peer
->default_rmap
[afi
][safi
].name
) {
2087 * When there is change in routemap this flow will
2088 * be triggered. We need to unset the Flag to ensure
2089 * the update flow gets triggered.
2091 UNSET_FLAG(subgrp
->sflags
,
2092 SUBGRP_STATUS_DEFAULT_ORIGINATE
);
2093 subgroup_default_originate(subgrp
, 0);
2097 return UPDWALK_CONTINUE
;
2100 void update_group_refresh_default_originate_route_map(struct event
*thread
)
2103 char reason
[] = "refresh default-originate route-map";
2105 bgp
= EVENT_ARG(thread
);
2106 update_group_walk(bgp
, update_group_default_originate_route_map_walkcb
,
2108 EVENT_OFF(bgp
->t_rmap_def_originate_eval
);
2113 * peer_af_announce_route
2115 * Refreshes routes out to a peer_af immediately.
2117 * If the combine parameter is true, then this function will try to
2118 * gather other peers in the subgroup for which a route announcement
2119 * is pending and efficently announce routes to all of them.
2121 * For now, the 'combine' option has an effect only if all peers in
2122 * the subgroup have a route announcement pending.
2124 void peer_af_announce_route(struct peer_af
*paf
, int combine
)
2126 struct update_subgroup
*subgrp
;
2127 struct peer_af
*cur_paf
;
2130 subgrp
= paf
->subgroup
;
2135 * If there are other peers in the old subgroup that also need
2136 * routes to be announced, pull them into the peer's new
2138 * Combine route announcement with other peers if possible.
2140 * For now, we combine only if all peers in the subgroup have an
2141 * announcement pending.
2145 SUBGRP_FOREACH_PEER (subgrp
, cur_paf
) {
2149 if (cur_paf
->t_announce_route
)
2157 * Announce to the peer alone if we were not asked to combine peers,
2158 * or if some peers don't have a route annoucement pending.
2160 if (!combine
|| !all_pending
) {
2161 update_subgroup_split_peer(paf
, NULL
);
2162 subgrp
= paf
->subgroup
;
2164 assert(subgrp
&& subgrp
->update_group
);
2165 if (bgp_debug_update(paf
->peer
, NULL
, subgrp
->update_group
, 0))
2166 zlog_debug("u%" PRIu64
":s%" PRIu64
" %s announcing routes",
2167 subgrp
->update_group
->id
, subgrp
->id
,
2170 subgroup_announce_route(paf
->subgroup
);
2175 * We will announce routes the entire subgroup.
2177 * First stop refresh timers on all the other peers.
2179 SUBGRP_FOREACH_PEER (subgrp
, cur_paf
) {
2183 bgp_stop_announce_route_timer(cur_paf
);
2186 if (bgp_debug_update(paf
->peer
, NULL
, subgrp
->update_group
, 0))
2187 zlog_debug("u%" PRIu64
":s%" PRIu64
" announcing routes to %s, combined into %d peers",
2188 subgrp
->update_group
->id
, subgrp
->id
,
2189 paf
->peer
->host
, subgrp
->peer_count
);
2191 subgroup_announce_route(subgrp
);
2193 SUBGRP_INCR_STAT_BY(subgrp
, peer_refreshes_combined
,
2194 subgrp
->peer_count
- 1);
2197 void subgroup_trigger_write(struct update_subgroup
*subgrp
)
2199 struct peer_af
*paf
;
2202 * For each peer in the subgroup, schedule a job to pull packets from
2203 * the subgroup output queue into their own output queue. This action
2204 * will trigger a write job on the I/O thread.
2206 SUBGRP_FOREACH_PEER (subgrp
, paf
)
2207 if (peer_established(paf
->peer
))
2208 event_add_timer_msec(
2209 bm
->master
, bgp_generate_updgrp_packets
,
2211 &paf
->peer
->t_generate_updgrp_packets
);
2214 int update_group_clear_update_dbg(struct update_group
*updgrp
, void *arg
)
2216 UPDGRP_PEER_DBG_OFF(updgrp
);
2217 return UPDWALK_CONTINUE
;
2220 /* Return true if we should addpath encode NLRI to this peer */
2221 bool bgp_addpath_encode_tx(struct peer
*peer
, afi_t afi
, safi_t safi
)
2223 return (CHECK_FLAG(peer
->af_cap
[afi
][safi
], PEER_CAP_ADDPATH_AF_TX_ADV
)
2224 && CHECK_FLAG(peer
->af_cap
[afi
][safi
],
2225 PEER_CAP_ADDPATH_AF_RX_RCV
));
2228 bool bgp_addpath_capable(struct bgp_path_info
*bpi
, struct peer
*peer
,
2229 afi_t afi
, safi_t safi
)
2231 return (bgp_addpath_tx_path(peer
->addpath_type
[afi
][safi
], bpi
) ||
2232 (safi
== SAFI_LABELED_UNICAST
&&
2233 bgp_addpath_tx_path(peer
->addpath_type
[afi
][SAFI_UNICAST
],
2237 bool bgp_check_selected(struct bgp_path_info
*bpi
, struct peer
*peer
,
2238 bool addpath_capable
, afi_t afi
, safi_t safi
)
2240 return (CHECK_FLAG(bpi
->flags
, BGP_PATH_SELECTED
) ||
2241 (addpath_capable
&& bgp_addpath_capable(bpi
, peer
, afi
, safi
)));