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