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