]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_updgrp.h
Merge pull request #10565 from lyq140/patch-thread
[mirror_frr.git] / bgpd / bgp_updgrp.h
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 #ifndef _QUAGGA_BGP_UPDGRP_H
28 #define _QUAGGA_BGP_UPDGRP_H
29
30 #include "bgp_advertise.h"
31
32 /*
33 * The following three heuristic constants determine how long advertisement to
34 * a subgroup will be delayed after it is created. The intent is to allow
35 * transient changes in peer state (primarily session establishment) to settle,
36 * so that more peers can be grouped together and benefit from sharing
37 * advertisement computations with the subgroup.
38 *
39 * These values have a very large impact on initial convergence time; any
40 * changes should be accompanied by careful performance testing at all scales.
41 *
42 * The coalesce time 'C' for a new subgroup within a particular BGP instance
43 * 'B' with total number of known peers 'P', established or not, is computed as
44 * follows:
45 *
46 * C = MIN(BGP_MAX_SUBGROUP_COALESCE_TIME,
47 * BGP_DEFAULT_SUBGROUP_COALESCE_TIME +
48 * (P*BGP_PEER_ADJUST_SUBGROUP_COALESCE_TIME))
49 */
50 #define BGP_DEFAULT_SUBGROUP_COALESCE_TIME 1000
51 #define BGP_MAX_SUBGROUP_COALESCE_TIME 10000
52 #define BGP_PEER_ADJUST_SUBGROUP_COALESCE_TIME 50
53
54 #define PEER_UPDGRP_FLAGS \
55 (PEER_FLAG_LOCAL_AS_NO_PREPEND | PEER_FLAG_LOCAL_AS_REPLACE_AS)
56
57 #define PEER_UPDGRP_AF_FLAGS \
58 (PEER_FLAG_SEND_COMMUNITY | PEER_FLAG_SEND_EXT_COMMUNITY \
59 | PEER_FLAG_SEND_LARGE_COMMUNITY \
60 | PEER_FLAG_DEFAULT_ORIGINATE | PEER_FLAG_REFLECTOR_CLIENT \
61 | PEER_FLAG_RSERVER_CLIENT | PEER_FLAG_NEXTHOP_SELF \
62 | PEER_FLAG_NEXTHOP_UNCHANGED | PEER_FLAG_FORCE_NEXTHOP_SELF \
63 | PEER_FLAG_AS_PATH_UNCHANGED | PEER_FLAG_MED_UNCHANGED \
64 | PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED | PEER_FLAG_REMOVE_PRIVATE_AS \
65 | PEER_FLAG_REMOVE_PRIVATE_AS_ALL \
66 | PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE \
67 | PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE \
68 | PEER_FLAG_AS_OVERRIDE)
69
70 #define PEER_UPDGRP_CAP_FLAGS (PEER_CAP_AS4_RCV)
71
72 #define PEER_UPDGRP_AF_CAP_FLAGS \
73 (PEER_CAP_ORF_PREFIX_SM_RCV | PEER_CAP_ORF_PREFIX_SM_OLD_RCV \
74 | PEER_CAP_ADDPATH_AF_TX_ADV | PEER_CAP_ADDPATH_AF_RX_RCV \
75 | PEER_CAP_ENHE_AF_NEGO)
76
77 typedef enum { BGP_ATTR_VEC_NH = 0, BGP_ATTR_VEC_MAX } bpacket_attr_vec_type;
78
79 typedef struct {
80 uint32_t flags;
81 unsigned long offset;
82 } bpacket_attr_vec;
83
84 #define BPKT_ATTRVEC_FLAGS_UPDATED (1 << 0)
85 #define BPKT_ATTRVEC_FLAGS_RMAP_NH_PEER_ADDRESS (1 << 1)
86 #define BPKT_ATTRVEC_FLAGS_REFLECTED (1 << 2)
87 #define BPKT_ATTRVEC_FLAGS_RMAP_NH_UNCHANGED (1 << 3)
88 #define BPKT_ATTRVEC_FLAGS_RMAP_IPV4_NH_CHANGED (1 << 4)
89 #define BPKT_ATTRVEC_FLAGS_RMAP_IPV6_GNH_CHANGED (1 << 5)
90 #define BPKT_ATTRVEC_FLAGS_RMAP_IPV6_LNH_CHANGED (1 << 6)
91
92 typedef struct bpacket_attr_vec_arr {
93 bpacket_attr_vec entries[BGP_ATTR_VEC_MAX];
94 } bpacket_attr_vec_arr;
95
96 struct bpacket {
97 /* for being part of an update subgroup's message list */
98 TAILQ_ENTRY(bpacket) pkt_train;
99
100 /* list of peers (well, peer_afs) that the packet needs to be sent to */
101 LIST_HEAD(pkt_peer_list, peer_af) peers;
102
103 struct stream *buffer;
104 bpacket_attr_vec_arr arr;
105
106 unsigned int ver;
107 };
108
109 struct bpacket_queue {
110 TAILQ_HEAD(pkt_queue, bpacket) pkts;
111
112 unsigned int conf_max_count;
113 unsigned int curr_count;
114 unsigned int hwm_count;
115 unsigned int max_count_reached_count;
116 };
117
118 struct update_group {
119 /* back pointer to the BGP instance */
120 struct bgp *bgp;
121
122 /* list of subgroups that belong to the update group */
123 LIST_HEAD(subgrp_list, update_subgroup) subgrps;
124
125 /* lazy way to store configuration common to all peers
126 hash function will compute from this data */
127 struct peer *conf;
128
129 afi_t afi;
130 safi_t safi;
131 int afid;
132
133 uint64_t id;
134 time_t uptime;
135
136 uint32_t join_events;
137 uint32_t prune_events;
138 uint32_t merge_events;
139 uint32_t updgrp_switch_events;
140 uint32_t peer_refreshes_combined;
141 uint32_t adj_count;
142 uint32_t split_events;
143 uint32_t merge_checks_triggered;
144
145 uint32_t subgrps_created;
146 uint32_t subgrps_deleted;
147
148 uint32_t num_dbg_en_peers;
149 };
150
151 /*
152 * Shorthand for a global statistics counter.
153 */
154 #define UPDGRP_GLOBAL_STAT(updgrp, stat) \
155 ((updgrp)->bgp->update_group_stats.stat)
156
157 /*
158 * Add the given value to a counter on an update group and the bgp
159 * instance.
160 */
161 #define UPDGRP_INCR_STAT_BY(updgrp, stat, value) \
162 do { \
163 (updgrp)->stat += (value); \
164 UPDGRP_GLOBAL_STAT(updgrp, stat) += (value); \
165 } while (0)
166
167 /*
168 * Increment a counter on a update group and its parent structures.
169 */
170 #define UPDGRP_INCR_STAT(subgrp, stat) UPDGRP_INCR_STAT_BY(subgrp, stat, 1)
171
172 struct update_subgroup {
173 /* back pointer to the parent update group */
174 struct update_group *update_group;
175
176 /* list of peers that belong to the subgroup */
177 LIST_HEAD(peer_list, peer_af) peers;
178 int peer_count;
179
180 /* for being part of an update group's subgroup list */
181 LIST_ENTRY(update_subgroup) updgrp_train;
182
183 struct bpacket_queue pkt_queue;
184
185 /*
186 * List of adj-out structures for this subgroup.
187 * It essentially represents the snapshot of every prefix that
188 * has been advertised to the members of the subgroup
189 */
190 TAILQ_HEAD(adjout_queue, bgp_adj_out) adjq;
191
192 /* packet buffer for update generation */
193 struct stream *work;
194
195 /* We use a separate stream to encode MP_REACH_NLRI for efficient
196 * NLRI packing. peer->obuf_work stores all the other attributes. The
197 * actual packet is then constructed by concatenating the two.
198 */
199 struct stream *scratch;
200
201 /* synchronization list and time */
202 struct bgp_synchronize *sync;
203
204 /* send prefix count */
205 uint32_t scount;
206
207 /* send prefix count prior to packet update */
208 uint32_t pscount;
209
210 /* announcement attribute hash */
211 struct hash *hash;
212
213 struct thread *t_coalesce;
214 uint32_t v_coalesce;
215
216 struct thread *t_merge_check;
217
218 /* table version that the subgroup has caught up to. */
219 uint64_t version;
220
221 /* version maintained to record adj changes */
222 uint64_t adj_version;
223
224 time_t uptime;
225
226 /*
227 * Identifying information about the subgroup that this subgroup was
228 * split
229 * from, if any.
230 */
231 struct {
232 uint64_t update_group_id;
233 uint64_t subgroup_id;
234 } split_from;
235
236 uint32_t join_events;
237 uint32_t prune_events;
238
239 /*
240 * This is bumped up when another subgroup merges into this one.
241 */
242 uint32_t merge_events;
243 uint32_t updgrp_switch_events;
244 uint32_t peer_refreshes_combined;
245 uint32_t adj_count;
246 uint32_t split_events;
247 uint32_t merge_checks_triggered;
248
249 uint64_t id;
250
251 uint16_t sflags;
252 #define SUBGRP_STATUS_DEFAULT_ORIGINATE (1 << 0)
253 #define SUBGRP_STATUS_FORCE_UPDATES (1 << 1)
254 #define SUBGRP_STATUS_TABLE_REPARSING (1 << 2)
255
256 uint16_t flags;
257 #define SUBGRP_FLAG_NEEDS_REFRESH (1 << 0)
258 };
259
260 /*
261 * Add the given value to the specified counter on a subgroup and its
262 * parent structures.
263 */
264 #define SUBGRP_INCR_STAT_BY(subgrp, stat, value) \
265 do { \
266 (subgrp)->stat += (value); \
267 if ((subgrp)->update_group) \
268 UPDGRP_INCR_STAT_BY((subgrp)->update_group, stat, \
269 value); \
270 } while (0)
271
272 /*
273 * Increment a counter on a subgroup and its parent structures.
274 */
275 #define SUBGRP_INCR_STAT(subgrp, stat) SUBGRP_INCR_STAT_BY(subgrp, stat, 1)
276
277 /*
278 * Decrement a counter on a subgroup and its parent structures.
279 */
280 #define SUBGRP_DECR_STAT(subgrp, stat) SUBGRP_INCR_STAT_BY(subgrp, stat, -1)
281
282 typedef int (*updgrp_walkcb)(struct update_group *updgrp, void *ctx);
283
284 /* really a private structure */
285 struct updwalk_context {
286 struct vty *vty;
287 struct bgp_dest *dest;
288 struct bgp_path_info *pi;
289 uint64_t updgrp_id;
290 uint64_t subgrp_id;
291 bgp_policy_type_e policy_type;
292 const char *policy_name;
293 int policy_event_start_flag;
294 int policy_route_update;
295 updgrp_walkcb cb;
296 void *context;
297 uint8_t flags;
298
299 #define UPDWALK_FLAGS_ADVQUEUE (1 << 0)
300 #define UPDWALK_FLAGS_ADVERTISED (1 << 1)
301 };
302
303 #define UPDWALK_CONTINUE HASHWALK_CONTINUE
304 #define UPDWALK_ABORT HASHWALK_ABORT
305
306 #define PAF_PEER(p) ((p)->peer)
307 #define PAF_SUBGRP(p) ((p)->subgroup)
308 #define PAF_UPDGRP(p) ((p)->subgroup->update_group)
309 #define PAF_PKTQ(f) SUBGRP_PKTQ((f)->subgroup)
310
311 #define UPDGRP_PEER(u) ((u)->conf)
312 #define UPDGRP_AFI(u) ((u)->afi)
313 #define UPDGRP_SAFI(u) ((u)->safi)
314 #define UPDGRP_INST(u) ((u)->bgp)
315 #define UPDGRP_AFFLAGS(u) ((u)->conf->af_flags[UPDGRP_AFI(u)][UPDGRP_SAFI(u)])
316 #define UPDGRP_DBG_ON(u) ((u)->num_dbg_en_peers)
317 #define UPDGRP_PEER_DBG_EN(u) (((u)->num_dbg_en_peers)++)
318 #define UPDGRP_PEER_DBG_DIS(u) (((u)->num_dbg_en_peers)--)
319 #define UPDGRP_PEER_DBG_OFF(u) (u)->num_dbg_en_peers = 0
320
321 #define SUBGRP_AFI(s) UPDGRP_AFI((s)->update_group)
322 #define SUBGRP_SAFI(s) UPDGRP_SAFI((s)->update_group)
323 #define SUBGRP_PEER(s) UPDGRP_PEER((s)->update_group)
324 #define SUBGRP_PCOUNT(s) ((s)->peer_count)
325 #define SUBGRP_PFIRST(s) LIST_FIRST(&((s)->peers))
326 #define SUBGRP_PKTQ(s) &((s)->pkt_queue)
327 #define SUBGRP_INST(s) UPDGRP_INST((s)->update_group)
328 #define SUBGRP_AFFLAGS(s) UPDGRP_AFFLAGS((s)->update_group)
329 #define SUBGRP_UPDGRP(s) ((s)->update_group)
330
331 /*
332 * Walk all subgroups in an update group.
333 */
334 #define UPDGRP_FOREACH_SUBGRP(updgrp, subgrp) \
335 LIST_FOREACH (subgrp, &((updgrp)->subgrps), updgrp_train)
336
337 #define UPDGRP_FOREACH_SUBGRP_SAFE(updgrp, subgrp, tmp_subgrp) \
338 LIST_FOREACH_SAFE (subgrp, &((updgrp)->subgrps), updgrp_train, \
339 tmp_subgrp)
340
341 #define SUBGRP_FOREACH_PEER(subgrp, paf) \
342 LIST_FOREACH (paf, &(subgrp->peers), subgrp_train)
343
344 #define SUBGRP_FOREACH_PEER_SAFE(subgrp, paf, temp_paf) \
345 LIST_FOREACH_SAFE (paf, &(subgrp->peers), subgrp_train, temp_paf)
346
347 #define SUBGRP_FOREACH_ADJ(subgrp, adj) \
348 TAILQ_FOREACH (adj, &(subgrp->adjq), subgrp_adj_train)
349
350 #define SUBGRP_FOREACH_ADJ_SAFE(subgrp, adj, adj_temp) \
351 TAILQ_FOREACH_SAFE (adj, &(subgrp->adjq), subgrp_adj_train, adj_temp)
352
353 /* Prototypes. */
354 /* bgp_updgrp.c */
355 extern void update_bgp_group_init(struct bgp *);
356 extern void udpate_bgp_group_free(struct bgp *);
357
358 extern void update_group_show(struct bgp *bgp, afi_t afi, safi_t safi,
359 struct vty *vty, uint64_t subgrp_id);
360 extern void update_group_show_stats(struct bgp *bgp, struct vty *vty);
361 extern void update_group_adjust_peer(struct peer_af *paf);
362 extern int update_group_adjust_soloness(struct peer *peer, int set);
363
364 extern void update_subgroup_remove_peer(struct update_subgroup *,
365 struct peer_af *);
366 extern struct bgp_table *update_subgroup_rib(struct update_subgroup *);
367 extern void update_subgroup_split_peer(struct peer_af *, struct update_group *);
368 extern bool update_subgroup_check_merge(struct update_subgroup *, const char *);
369 extern bool update_subgroup_trigger_merge_check(struct update_subgroup *,
370 int force);
371 extern void update_group_policy_update(struct bgp *bgp, bgp_policy_type_e ptype,
372 const char *pname, int route_update,
373 int start_event);
374 extern void update_group_af_walk(struct bgp *bgp, afi_t afi, safi_t safi,
375 updgrp_walkcb cb, void *ctx);
376 extern void update_group_walk(struct bgp *bgp, updgrp_walkcb cb, void *ctx);
377 extern void update_group_periodic_merge(struct bgp *bgp);
378 extern void
379 update_group_refresh_default_originate_route_map(struct thread *thread);
380 extern void update_group_start_advtimer(struct bgp *bgp);
381
382 extern void update_subgroup_inherit_info(struct update_subgroup *to,
383 struct update_subgroup *from);
384
385 /* bgp_updgrp_packet.c */
386 extern struct bpacket *bpacket_alloc(void);
387 extern void bpacket_free(struct bpacket *pkt);
388 extern void bpacket_queue_init(struct bpacket_queue *q);
389 extern void bpacket_queue_cleanup(struct bpacket_queue *q);
390 extern void bpacket_queue_sanity_check(struct bpacket_queue *q);
391 extern struct bpacket *bpacket_queue_add(struct bpacket_queue *q,
392 struct stream *s,
393 struct bpacket_attr_vec_arr *vecarr);
394 struct bpacket *bpacket_queue_remove(struct bpacket_queue *q);
395 extern struct bpacket *bpacket_queue_first(struct bpacket_queue *q);
396 struct bpacket *bpacket_queue_last(struct bpacket_queue *q);
397 unsigned int bpacket_queue_length(struct bpacket_queue *q);
398 unsigned int bpacket_queue_hwm_length(struct bpacket_queue *q);
399 bool bpacket_queue_is_full(struct bgp *bgp, struct bpacket_queue *q);
400 extern void bpacket_queue_advance_peer(struct peer_af *paf);
401 extern void bpacket_queue_remove_peer(struct peer_af *paf);
402 extern void bpacket_add_peer(struct bpacket *pkt, struct peer_af *paf);
403 unsigned int bpacket_queue_virtual_length(struct peer_af *paf);
404 extern void bpacket_queue_show_vty(struct bpacket_queue *q, struct vty *vty);
405 bool subgroup_packets_to_build(struct update_subgroup *subgrp);
406 extern struct bpacket *subgroup_update_packet(struct update_subgroup *s);
407 extern struct bpacket *subgroup_withdraw_packet(struct update_subgroup *s);
408 extern struct stream *bpacket_reformat_for_peer(struct bpacket *pkt,
409 struct peer_af *paf);
410 extern void bpacket_attr_vec_arr_reset(struct bpacket_attr_vec_arr *vecarr);
411 extern void bpacket_attr_vec_arr_set_vec(struct bpacket_attr_vec_arr *vecarr,
412 bpacket_attr_vec_type type,
413 struct stream *s, struct attr *attr);
414 extern void subgroup_default_update_packet(struct update_subgroup *subgrp,
415 struct attr *attr,
416 struct peer *from);
417 extern void subgroup_default_withdraw_packet(struct update_subgroup *subgrp);
418
419 /* bgp_updgrp_adv.c */
420 extern struct bgp_advertise *
421 bgp_advertise_clean_subgroup(struct update_subgroup *subgrp,
422 struct bgp_adj_out *adj);
423 extern void update_group_show_adj_queue(struct bgp *bgp, afi_t afi, safi_t safi,
424 struct vty *vty, uint64_t id);
425 extern void update_group_show_advertised(struct bgp *bgp, afi_t afi,
426 safi_t safi, struct vty *vty,
427 uint64_t id);
428 extern void update_group_show_packet_queue(struct bgp *bgp, afi_t afi,
429 safi_t safi, struct vty *vty,
430 uint64_t id);
431 extern void subgroup_announce_route(struct update_subgroup *subgrp);
432 extern void subgroup_announce_all(struct update_subgroup *subgrp);
433
434 extern void subgroup_default_originate(struct update_subgroup *subgrp,
435 int withdraw);
436 extern void group_announce_route(struct bgp *bgp, afi_t afi, safi_t safi,
437 struct bgp_dest *dest,
438 struct bgp_path_info *pi);
439 extern void subgroup_clear_table(struct update_subgroup *subgrp);
440 extern void update_group_announce(struct bgp *bgp);
441 extern void update_group_announce_rrclients(struct bgp *bgp);
442 extern void peer_af_announce_route(struct peer_af *paf, int combine);
443 extern struct bgp_adj_out *bgp_adj_out_alloc(struct update_subgroup *subgrp,
444 struct bgp_dest *dest,
445 uint32_t addpath_tx_id);
446 extern void bgp_adj_out_remove_subgroup(struct bgp_dest *dest,
447 struct bgp_adj_out *adj,
448 struct update_subgroup *subgrp);
449 extern void bgp_adj_out_set_subgroup(struct bgp_dest *dest,
450 struct update_subgroup *subgrp,
451 struct attr *attr,
452 struct bgp_path_info *path);
453 extern void bgp_adj_out_unset_subgroup(struct bgp_dest *dest,
454 struct update_subgroup *subgrp,
455 char withdraw, uint32_t addpath_tx_id);
456 void subgroup_announce_table(struct update_subgroup *subgrp,
457 struct bgp_table *table);
458 extern void subgroup_trigger_write(struct update_subgroup *subgrp);
459
460 extern int update_group_clear_update_dbg(struct update_group *updgrp,
461 void *arg);
462
463 extern void update_bgp_group_free(struct bgp *bgp);
464 extern bool bgp_addpath_encode_tx(struct peer *peer, afi_t afi, safi_t safi);
465 extern bool bgp_check_selected(struct bgp_path_info *bpi, struct peer *peer,
466 bool addpath_capable, afi_t afi, safi_t safi);
467
468 /*
469 * Inline functions
470 */
471
472 /*
473 * bpacket_queue_is_empty
474 */
475 static inline int bpacket_queue_is_empty(struct bpacket_queue *queue)
476 {
477
478 /*
479 * The packet queue is empty if it only contains a sentinel.
480 */
481 if (queue->curr_count != 1)
482 return 0;
483
484 assert(bpacket_queue_first(queue)->buffer == NULL);
485 return 1;
486 }
487
488 /*
489 * bpacket_next
490 *
491 * Returns the packet after the given packet in a bpacket queue.
492 */
493 static inline struct bpacket *bpacket_next(struct bpacket *pkt)
494 {
495 return TAILQ_NEXT(pkt, pkt_train);
496 }
497
498 /*
499 * update_group_adjust_peer_afs
500 *
501 * Adjust all peer_af structures for the given peer.
502 */
503 static inline void update_group_adjust_peer_afs(struct peer *peer)
504 {
505 struct peer_af *paf;
506 int afidx;
507
508 for (afidx = BGP_AF_START; afidx < BGP_AF_MAX; afidx++) {
509 paf = peer->peer_af_array[afidx];
510 if (paf != NULL)
511 update_group_adjust_peer(paf);
512 }
513 }
514
515 /*
516 * update_group_remove_peer_afs
517 *
518 * Remove all peer_af structures for the given peer from their subgroups.
519 */
520 static inline void update_group_remove_peer_afs(struct peer *peer)
521 {
522 struct peer_af *paf;
523 int afidx;
524
525 for (afidx = BGP_AF_START; afidx < BGP_AF_MAX; afidx++) {
526 paf = peer->peer_af_array[afidx];
527 if (paf != NULL)
528 update_subgroup_remove_peer(PAF_SUBGRP(paf), paf);
529 }
530 }
531
532 /*
533 * update_subgroup_needs_refresh
534 */
535 static inline int
536 update_subgroup_needs_refresh(const struct update_subgroup *subgrp)
537 {
538 if (CHECK_FLAG(subgrp->flags, SUBGRP_FLAG_NEEDS_REFRESH))
539 return 1;
540 else
541 return 0;
542 }
543
544 /*
545 * update_subgroup_set_needs_refresh
546 */
547 static inline void
548 update_subgroup_set_needs_refresh(struct update_subgroup *subgrp, int value)
549 {
550 if (value)
551 SET_FLAG(subgrp->flags, SUBGRP_FLAG_NEEDS_REFRESH);
552 else
553 UNSET_FLAG(subgrp->flags, SUBGRP_FLAG_NEEDS_REFRESH);
554 }
555
556 static inline struct update_subgroup *peer_subgroup(struct peer *peer,
557 afi_t afi, safi_t safi)
558 {
559 struct peer_af *paf;
560
561 paf = peer_af_find(peer, afi, safi);
562 if (paf)
563 return PAF_SUBGRP(paf);
564 return NULL;
565 }
566
567 /*
568 * update_group_adjust_peer_afs
569 *
570 * Adjust all peer_af structures for the given peer.
571 */
572 static inline void bgp_announce_peer(struct peer *peer)
573 {
574 struct peer_af *paf;
575 int afidx;
576
577 for (afidx = BGP_AF_START; afidx < BGP_AF_MAX; afidx++) {
578 paf = peer->peer_af_array[afidx];
579 if (paf != NULL)
580 subgroup_announce_all(PAF_SUBGRP(paf));
581 }
582 }
583
584 /**
585 * advertise_list_is_empty
586 */
587 static inline int advertise_list_is_empty(struct update_subgroup *subgrp)
588 {
589 if (bgp_adv_fifo_count(&subgrp->sync->update)
590 || bgp_adv_fifo_count(&subgrp->sync->withdraw)
591 || bgp_adv_fifo_count(&subgrp->sync->withdraw_low)) {
592 return 0;
593 }
594
595 return 1;
596 }
597
598 #endif /* _QUAGGA_BGP_UPDGRP_H */