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