]>
Commit | Line | Data |
---|---|---|
ea1c14f6 MS |
1 | /* |
2 | * Zebra dataplane layer. | |
3 | * Copyright (c) 2018 Volta Networks, Inc. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; see the file COPYING; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | */ | |
19 | ||
2618a52e DL |
20 | #ifdef HAVE_CONFIG_H |
21 | #include "config.h" | |
22 | #endif | |
23 | ||
18c37974 | 24 | #include "lib/libfrr.h" |
1d11b21f MS |
25 | #include "lib/debug.h" |
26 | #include "lib/frratomic.h" | |
7cdb1a84 | 27 | #include "lib/frr_pthread.h" |
1d11b21f | 28 | #include "lib/memory.h" |
7cdb1a84 | 29 | #include "lib/queue.h" |
1d11b21f | 30 | #include "lib/zebra.h" |
3801e764 | 31 | #include "zebra/zebra_router.h" |
7cdb1a84 | 32 | #include "zebra/zebra_dplane.h" |
f2a0ba3a | 33 | #include "zebra/zebra_vxlan_private.h" |
ee70f629 | 34 | #include "zebra/zebra_mpls.h" |
7cdb1a84 MS |
35 | #include "zebra/rt.h" |
36 | #include "zebra/debug.h" | |
f62e5480 | 37 | #include "zebra/zebra_pbr.h" |
c60522f7 | 38 | #include "printfrr.h" |
7cdb1a84 MS |
39 | |
40 | /* Memory type for context blocks */ | |
bf8d3d6a DL |
41 | DEFINE_MTYPE_STATIC(ZEBRA, DP_CTX, "Zebra DPlane Ctx"); |
42 | DEFINE_MTYPE_STATIC(ZEBRA, DP_INTF, "Zebra DPlane Intf"); | |
43 | DEFINE_MTYPE_STATIC(ZEBRA, DP_PROV, "Zebra DPlane Provider"); | |
44 | DEFINE_MTYPE_STATIC(ZEBRA, DP_NETFILTER, "Zebra Netfilter Internal Object"); | |
7cdb1a84 MS |
45 | |
46 | #ifndef AOK | |
47 | # define AOK 0 | |
48 | #endif | |
49 | ||
5917df09 MS |
50 | /* Control for collection of extra interface info with route updates; a plugin |
51 | * can enable the extra info via a dplane api. | |
52 | */ | |
53 | static bool dplane_collect_extra_intf_info; | |
54 | ||
e5a60d82 MS |
55 | /* Enable test dataplane provider */ |
56 | /*#define DPLANE_TEST_PROVIDER 1 */ | |
57 | ||
91f16812 MS |
58 | /* Default value for max queued incoming updates */ |
59 | const uint32_t DPLANE_DEFAULT_MAX_QUEUED = 200; | |
60 | ||
c831033f MS |
61 | /* Default value for new work per cycle */ |
62 | const uint32_t DPLANE_DEFAULT_NEW_WORK = 100; | |
63 | ||
7cdb1a84 MS |
64 | /* Validation check macro for context blocks */ |
65 | /* #define DPLANE_DEBUG 1 */ | |
66 | ||
67 | #ifdef DPLANE_DEBUG | |
68 | ||
25779064 MS |
69 | # define DPLANE_CTX_VALID(p) \ |
70 | assert((p) != NULL) | |
7cdb1a84 MS |
71 | |
72 | #else | |
73 | ||
5709131c | 74 | # define DPLANE_CTX_VALID(p) |
7cdb1a84 MS |
75 | |
76 | #endif /* DPLANE_DEBUG */ | |
77 | ||
0c8215cb SW |
78 | /* |
79 | * Nexthop information captured for nexthop/nexthop group updates | |
80 | */ | |
81 | struct dplane_nexthop_info { | |
82 | uint32_t id; | |
df3cef24 | 83 | uint32_t old_id; |
0c8215cb SW |
84 | afi_t afi; |
85 | vrf_id_t vrf_id; | |
38e40db1 | 86 | int type; |
0c8215cb SW |
87 | |
88 | struct nexthop_group ng; | |
e22e8001 SW |
89 | struct nh_grp nh_grp[MULTIPATH_NUM]; |
90 | uint8_t nh_grp_count; | |
0c8215cb SW |
91 | }; |
92 | ||
5917df09 MS |
93 | /* |
94 | * Optional extra info about interfaces used in route updates' nexthops. | |
95 | */ | |
96 | struct dplane_intf_extra { | |
97 | vrf_id_t vrf_id; | |
98 | uint32_t ifindex; | |
99 | uint32_t flags; | |
100 | uint32_t status; | |
101 | ||
102 | TAILQ_ENTRY(dplane_intf_extra) link; | |
103 | }; | |
104 | ||
7cdb1a84 | 105 | /* |
0f461727 | 106 | * Route information captured for route updates. |
7cdb1a84 | 107 | */ |
0f461727 | 108 | struct dplane_route_info { |
7cdb1a84 MS |
109 | |
110 | /* Dest and (optional) source prefixes */ | |
111 | struct prefix zd_dest; | |
112 | struct prefix zd_src; | |
113 | ||
0f461727 MS |
114 | afi_t zd_afi; |
115 | safi_t zd_safi; | |
7cdb1a84 MS |
116 | |
117 | int zd_type; | |
118 | int zd_old_type; | |
119 | ||
7cdb1a84 MS |
120 | route_tag_t zd_tag; |
121 | route_tag_t zd_old_tag; | |
122 | uint32_t zd_metric; | |
01ce7cba | 123 | uint32_t zd_old_metric; |
0f461727 | 124 | |
7cdb1a84 MS |
125 | uint16_t zd_instance; |
126 | uint16_t zd_old_instance; | |
127 | ||
128 | uint8_t zd_distance; | |
129 | uint8_t zd_old_distance; | |
130 | ||
131 | uint32_t zd_mtu; | |
132 | uint32_t zd_nexthop_mtu; | |
133 | ||
0c8215cb SW |
134 | /* Nexthop hash entry info */ |
135 | struct dplane_nexthop_info nhe; | |
f820d025 | 136 | |
7cdb1a84 | 137 | /* Nexthops */ |
1d48702e | 138 | uint32_t zd_nhg_id; |
7cdb1a84 MS |
139 | struct nexthop_group zd_ng; |
140 | ||
1d48702e MS |
141 | /* Backup nexthops (if present) */ |
142 | struct nexthop_group backup_ng; | |
143 | ||
4dfd7a02 | 144 | /* "Previous" nexthops, used only in route updates without netlink */ |
01ce7cba | 145 | struct nexthop_group zd_old_ng; |
1d48702e | 146 | struct nexthop_group old_backup_ng; |
01ce7cba | 147 | |
5917df09 MS |
148 | /* Optional list of extra interface info */ |
149 | TAILQ_HEAD(dp_intf_extra_q, dplane_intf_extra) intf_extra_q; | |
0f461727 MS |
150 | }; |
151 | ||
d613b8e1 MS |
152 | /* |
153 | * Pseudowire info for the dataplane | |
154 | */ | |
155 | struct dplane_pw_info { | |
d613b8e1 MS |
156 | int type; |
157 | int af; | |
158 | int status; | |
159 | uint32_t flags; | |
072b487b | 160 | uint32_t nhg_id; |
16d69787 | 161 | union g_addr dest; |
d613b8e1 MS |
162 | mpls_label_t local_label; |
163 | mpls_label_t remote_label; | |
164 | ||
072b487b MS |
165 | /* Nexthops that are valid and installed */ |
166 | struct nexthop_group fib_nhg; | |
167 | ||
168 | /* Primary and backup nexthop sets, copied from the resolving route. */ | |
169 | struct nexthop_group primary_nhg; | |
170 | struct nexthop_group backup_nhg; | |
16d69787 | 171 | |
d613b8e1 MS |
172 | union pw_protocol_fields fields; |
173 | }; | |
174 | ||
c60522f7 AK |
175 | /* |
176 | * Bridge port info for the dataplane | |
177 | */ | |
178 | struct dplane_br_port_info { | |
179 | uint32_t sph_filter_cnt; | |
180 | struct in_addr sph_filters[ES_VTEP_MAX_CNT]; | |
181 | /* DPLANE_BR_PORT_XXX - see zebra_dplane.h*/ | |
182 | uint32_t flags; | |
183 | uint32_t backup_nhg_id; | |
184 | }; | |
185 | ||
a4a4802a MS |
186 | /* |
187 | * Interface/prefix info for the dataplane | |
188 | */ | |
189 | struct dplane_intf_info { | |
190 | ||
a4a4802a MS |
191 | uint32_t metric; |
192 | uint32_t flags; | |
193 | ||
194 | #define DPLANE_INTF_CONNECTED (1 << 0) /* Connected peer, p2p */ | |
195 | #define DPLANE_INTF_SECONDARY (1 << 1) | |
64168803 | 196 | #define DPLANE_INTF_BROADCAST (1 << 2) |
0f3af738 | 197 | #define DPLANE_INTF_HAS_DEST DPLANE_INTF_CONNECTED |
64168803 | 198 | #define DPLANE_INTF_HAS_LABEL (1 << 4) |
a4a4802a MS |
199 | |
200 | /* Interface address/prefix */ | |
201 | struct prefix prefix; | |
202 | ||
203 | /* Dest address, for p2p, or broadcast prefix */ | |
204 | struct prefix dest_prefix; | |
205 | ||
206 | char *label; | |
207 | char label_buf[32]; | |
208 | }; | |
209 | ||
7597ac7b | 210 | /* |
0bbd4ff4 | 211 | * EVPN MAC address info for the dataplane. |
7597ac7b MS |
212 | */ |
213 | struct dplane_mac_info { | |
214 | vlanid_t vid; | |
478566d6 | 215 | ifindex_t br_ifindex; |
7597ac7b MS |
216 | struct ethaddr mac; |
217 | struct in_addr vtep_ip; | |
218 | bool is_sticky; | |
506efd37 | 219 | uint32_t nhg_id; |
f188e68e | 220 | uint32_t update_flags; |
7597ac7b MS |
221 | }; |
222 | ||
931fa60c | 223 | /* |
d68e74b4 | 224 | * Neighbor info for the dataplane |
931fa60c MS |
225 | */ |
226 | struct dplane_neigh_info { | |
227 | struct ipaddr ip_addr; | |
0a27a2fe PG |
228 | union { |
229 | struct ethaddr mac; | |
230 | struct ipaddr ip_addr; | |
231 | } link; | |
931fa60c MS |
232 | uint32_t flags; |
233 | uint16_t state; | |
f188e68e | 234 | uint32_t update_flags; |
931fa60c MS |
235 | }; |
236 | ||
e18747a9 PG |
237 | /* |
238 | * Neighbor Table | |
239 | */ | |
240 | struct dplane_neigh_table { | |
241 | uint8_t family; | |
242 | uint32_t app_probes; | |
243 | uint32_t ucast_probes; | |
244 | uint32_t mcast_probes; | |
245 | }; | |
246 | ||
60d8d43b JU |
247 | /* |
248 | * Policy based routing rule info for the dataplane | |
249 | */ | |
250 | struct dplane_ctx_rule { | |
251 | uint32_t priority; | |
252 | ||
253 | /* The route table pointed by this rule */ | |
254 | uint32_t table; | |
255 | ||
256 | /* Filter criteria */ | |
257 | uint32_t filter_bm; | |
258 | uint32_t fwmark; | |
01f23aff | 259 | uint8_t dsfield; |
60d8d43b JU |
260 | struct prefix src_ip; |
261 | struct prefix dst_ip; | |
8ccbc778 | 262 | uint8_t ip_proto; |
58a1d249 | 263 | char ifname[INTERFACE_NAMSIZ + 1]; |
60d8d43b JU |
264 | }; |
265 | ||
266 | struct dplane_rule_info { | |
267 | /* | |
268 | * Originating zclient sock fd, so we can know who to send | |
269 | * back to. | |
270 | */ | |
271 | int sock; | |
272 | ||
273 | int unique; | |
274 | int seq; | |
275 | ||
276 | struct dplane_ctx_rule new; | |
277 | struct dplane_ctx_rule old; | |
278 | }; | |
279 | ||
62b4b7e4 PG |
280 | struct dplane_gre_ctx { |
281 | uint32_t link_ifindex; | |
db51f0cd | 282 | unsigned int mtu; |
e3d3fa06 | 283 | struct zebra_l2info_gre info; |
62b4b7e4 | 284 | }; |
0f461727 MS |
285 | /* |
286 | * The context block used to exchange info about route updates across | |
287 | * the boundary between the zebra main context (and pthread) and the | |
288 | * dataplane layer (and pthread). | |
289 | */ | |
290 | struct zebra_dplane_ctx { | |
291 | ||
292 | /* Operation code */ | |
293 | enum dplane_op_e zd_op; | |
294 | ||
295 | /* Status on return */ | |
296 | enum zebra_dplane_result zd_status; | |
297 | ||
298 | /* Dplane provider id */ | |
299 | uint32_t zd_provider; | |
300 | ||
301 | /* Flags - used by providers, e.g. */ | |
302 | int zd_flags; | |
303 | ||
304 | bool zd_is_update; | |
305 | ||
306 | uint32_t zd_seq; | |
307 | uint32_t zd_old_seq; | |
308 | ||
0024a559 MS |
309 | /* Some updates may be generated by notifications: allow the |
310 | * plugin to notice and ignore results from its own notifications. | |
311 | */ | |
312 | uint32_t zd_notif_provider; | |
313 | ||
0f461727 MS |
314 | /* TODO -- internal/sub-operation status? */ |
315 | enum zebra_dplane_result zd_remote_status; | |
316 | enum zebra_dplane_result zd_kernel_status; | |
317 | ||
318 | vrf_id_t zd_vrf_id; | |
319 | uint32_t zd_table_id; | |
320 | ||
7c7ef4a8 MS |
321 | char zd_ifname[INTERFACE_NAMSIZ]; |
322 | ifindex_t zd_ifindex; | |
323 | ||
a4a4802a | 324 | /* Support info for different kinds of updates */ |
0f461727 MS |
325 | union { |
326 | struct dplane_route_info rinfo; | |
8f74a383 | 327 | struct zebra_lsp lsp; |
d613b8e1 | 328 | struct dplane_pw_info pw; |
c60522f7 | 329 | struct dplane_br_port_info br_port; |
a4a4802a | 330 | struct dplane_intf_info intf; |
7597ac7b | 331 | struct dplane_mac_info macinfo; |
931fa60c | 332 | struct dplane_neigh_info neigh; |
60d8d43b | 333 | struct dplane_rule_info rule; |
5162e000 | 334 | struct zebra_pbr_iptable iptable; |
ef524230 PG |
335 | struct zebra_pbr_ipset ipset; |
336 | union { | |
337 | struct zebra_pbr_ipset_entry entry; | |
338 | struct zebra_pbr_ipset_info info; | |
339 | } ipset_entry; | |
e18747a9 | 340 | struct dplane_neigh_table neightable; |
62b4b7e4 | 341 | struct dplane_gre_ctx gre; |
0f461727 MS |
342 | } u; |
343 | ||
344 | /* Namespace info, used especially for netlink kernel communication */ | |
345 | struct zebra_dplane_info zd_ns_info; | |
346 | ||
7cdb1a84 | 347 | /* Embedded list linkage */ |
25779064 | 348 | TAILQ_ENTRY(zebra_dplane_ctx) zd_q_entries; |
7cdb1a84 MS |
349 | }; |
350 | ||
c831033f MS |
351 | /* Flag that can be set by a pre-kernel provider as a signal that an update |
352 | * should bypass the kernel. | |
353 | */ | |
354 | #define DPLANE_CTX_FLAG_NO_KERNEL 0x01 | |
355 | ||
356 | ||
7cdb1a84 MS |
357 | /* |
358 | * Registration block for one dataplane provider. | |
359 | */ | |
25779064 | 360 | struct zebra_dplane_provider { |
7cdb1a84 MS |
361 | /* Name */ |
362 | char dp_name[DPLANE_PROVIDER_NAMELEN + 1]; | |
363 | ||
364 | /* Priority, for ordering among providers */ | |
365 | uint8_t dp_priority; | |
366 | ||
367 | /* Id value */ | |
368 | uint32_t dp_id; | |
369 | ||
c831033f MS |
370 | /* Mutex */ |
371 | pthread_mutex_t dp_mutex; | |
372 | ||
373 | /* Plugin-provided extra data */ | |
374 | void *dp_data; | |
375 | ||
376 | /* Flags */ | |
377 | int dp_flags; | |
378 | ||
1dd4ea8a MS |
379 | int (*dp_start)(struct zebra_dplane_provider *prov); |
380 | ||
4c206c8f | 381 | int (*dp_fp)(struct zebra_dplane_provider *prov); |
7cdb1a84 | 382 | |
4c206c8f | 383 | int (*dp_fini)(struct zebra_dplane_provider *prov, bool early_p); |
18c37974 | 384 | |
0545c373 | 385 | _Atomic uint32_t dp_in_counter; |
c9d17fe8 | 386 | _Atomic uint32_t dp_in_queued; |
c831033f MS |
387 | _Atomic uint32_t dp_in_max; |
388 | _Atomic uint32_t dp_out_counter; | |
c9d17fe8 | 389 | _Atomic uint32_t dp_out_queued; |
c831033f | 390 | _Atomic uint32_t dp_out_max; |
0545c373 | 391 | _Atomic uint32_t dp_error_counter; |
1d11b21f | 392 | |
c831033f MS |
393 | /* Queue of contexts inbound to the provider */ |
394 | struct dplane_ctx_q dp_ctx_in_q; | |
395 | ||
396 | /* Queue of completed contexts outbound from the provider back | |
397 | * towards the dataplane module. | |
398 | */ | |
399 | struct dplane_ctx_q dp_ctx_out_q; | |
7cdb1a84 | 400 | |
c831033f MS |
401 | /* Embedded list linkage for provider objects */ |
402 | TAILQ_ENTRY(zebra_dplane_provider) dp_prov_link; | |
7cdb1a84 MS |
403 | }; |
404 | ||
405 | /* | |
406 | * Globals | |
407 | */ | |
25779064 | 408 | static struct zebra_dplane_globals { |
7cdb1a84 MS |
409 | /* Mutex to control access to dataplane components */ |
410 | pthread_mutex_t dg_mutex; | |
411 | ||
412 | /* Results callback registered by zebra 'core' */ | |
4c206c8f | 413 | int (*dg_results_cb)(struct dplane_ctx_q *ctxlist); |
7cdb1a84 | 414 | |
4dfd7a02 MS |
415 | /* Sentinel for beginning of shutdown */ |
416 | volatile bool dg_is_shutdown; | |
417 | ||
418 | /* Sentinel for end of shutdown */ | |
1d11b21f MS |
419 | volatile bool dg_run; |
420 | ||
3fe4ccc4 MS |
421 | /* Update context queue inbound to the dataplane */ |
422 | TAILQ_HEAD(zdg_ctx_q, zebra_dplane_ctx) dg_update_ctx_q; | |
7cdb1a84 MS |
423 | |
424 | /* Ordered list of providers */ | |
25779064 | 425 | TAILQ_HEAD(zdg_prov_q, zebra_dplane_provider) dg_providers_q; |
7cdb1a84 | 426 | |
1d11b21f | 427 | /* Counter used to assign internal ids to providers */ |
b8e0423d MS |
428 | uint32_t dg_provider_id; |
429 | ||
91f16812 MS |
430 | /* Limit number of pending, unprocessed updates */ |
431 | _Atomic uint32_t dg_max_queued_updates; | |
432 | ||
cf363e1b MS |
433 | /* Control whether system route notifications should be produced. */ |
434 | bool dg_sys_route_notifs; | |
435 | ||
c831033f MS |
436 | /* Limit number of new updates dequeued at once, to pace an |
437 | * incoming burst. | |
438 | */ | |
439 | uint32_t dg_updates_per_cycle; | |
440 | ||
0545c373 | 441 | _Atomic uint32_t dg_routes_in; |
1d11b21f | 442 | _Atomic uint32_t dg_routes_queued; |
4dfd7a02 | 443 | _Atomic uint32_t dg_routes_queued_max; |
0545c373 | 444 | _Atomic uint32_t dg_route_errors; |
16c628de MS |
445 | _Atomic uint32_t dg_other_errors; |
446 | ||
f820d025 SW |
447 | _Atomic uint32_t dg_nexthops_in; |
448 | _Atomic uint32_t dg_nexthop_errors; | |
449 | ||
16c628de | 450 | _Atomic uint32_t dg_lsps_in; |
16c628de MS |
451 | _Atomic uint32_t dg_lsp_errors; |
452 | ||
97d8d05a MS |
453 | _Atomic uint32_t dg_pws_in; |
454 | _Atomic uint32_t dg_pw_errors; | |
455 | ||
c60522f7 AK |
456 | _Atomic uint32_t dg_br_port_in; |
457 | _Atomic uint32_t dg_br_port_errors; | |
458 | ||
64168803 MS |
459 | _Atomic uint32_t dg_intf_addrs_in; |
460 | _Atomic uint32_t dg_intf_addr_errors; | |
461 | ||
7597ac7b MS |
462 | _Atomic uint32_t dg_macs_in; |
463 | _Atomic uint32_t dg_mac_errors; | |
464 | ||
931fa60c MS |
465 | _Atomic uint32_t dg_neighs_in; |
466 | _Atomic uint32_t dg_neigh_errors; | |
467 | ||
60d8d43b JU |
468 | _Atomic uint32_t dg_rules_in; |
469 | _Atomic uint32_t dg_rule_errors; | |
470 | ||
c831033f | 471 | _Atomic uint32_t dg_update_yields; |
1d11b21f | 472 | |
5162e000 PG |
473 | _Atomic uint32_t dg_iptable_in; |
474 | _Atomic uint32_t dg_iptable_errors; | |
ef524230 PG |
475 | |
476 | _Atomic uint32_t dg_ipset_in; | |
477 | _Atomic uint32_t dg_ipset_errors; | |
478 | _Atomic uint32_t dg_ipset_entry_in; | |
479 | _Atomic uint32_t dg_ipset_entry_errors; | |
480 | ||
e18747a9 PG |
481 | _Atomic uint32_t dg_neightable_in; |
482 | _Atomic uint32_t dg_neightable_errors; | |
483 | ||
62b4b7e4 PG |
484 | _Atomic uint32_t dg_gre_set_in; |
485 | _Atomic uint32_t dg_gre_set_errors; | |
486 | ||
d8c16a95 MS |
487 | /* Dataplane pthread */ |
488 | struct frr_pthread *dg_pthread; | |
489 | ||
7cdb1a84 MS |
490 | /* Event-delivery context 'master' for the dplane */ |
491 | struct thread_master *dg_master; | |
492 | ||
493 | /* Event/'thread' pointer for queued updates */ | |
494 | struct thread *dg_t_update; | |
495 | ||
4dfd7a02 MS |
496 | /* Event pointer for pending shutdown check loop */ |
497 | struct thread *dg_t_shutdown_check; | |
498 | ||
25779064 | 499 | } zdplane_info; |
7cdb1a84 MS |
500 | |
501 | /* | |
c831033f | 502 | * Lock and unlock for interactions with the zebra 'core' pthread |
7cdb1a84 | 503 | */ |
25779064 | 504 | #define DPLANE_LOCK() pthread_mutex_lock(&zdplane_info.dg_mutex) |
25779064 | 505 | #define DPLANE_UNLOCK() pthread_mutex_unlock(&zdplane_info.dg_mutex) |
7cdb1a84 | 506 | |
c831033f MS |
507 | |
508 | /* | |
509 | * Lock and unlock for individual providers | |
510 | */ | |
511 | #define DPLANE_PROV_LOCK(p) pthread_mutex_lock(&((p)->dp_mutex)) | |
512 | #define DPLANE_PROV_UNLOCK(p) pthread_mutex_unlock(&((p)->dp_mutex)) | |
513 | ||
7cdb1a84 | 514 | /* Prototypes */ |
c831033f | 515 | static int dplane_thread_loop(struct thread *event); |
62b8bb7a MS |
516 | static void dplane_info_from_zns(struct zebra_dplane_info *ns_info, |
517 | struct zebra_ns *zns); | |
8f74a383 | 518 | static enum zebra_dplane_result lsp_update_internal(struct zebra_lsp *lsp, |
16c628de | 519 | enum dplane_op_e op); |
97d8d05a MS |
520 | static enum zebra_dplane_result pw_update_internal(struct zebra_pw *pw, |
521 | enum dplane_op_e op); | |
64168803 MS |
522 | static enum zebra_dplane_result intf_addr_update_internal( |
523 | const struct interface *ifp, const struct connected *ifc, | |
524 | enum dplane_op_e op); | |
f73a8467 | 525 | static enum zebra_dplane_result mac_update_common( |
7597ac7b | 526 | enum dplane_op_e op, const struct interface *ifp, |
478566d6 | 527 | const struct interface *br_ifp, |
7597ac7b | 528 | vlanid_t vid, const struct ethaddr *mac, |
f188e68e AK |
529 | struct in_addr vtep_ip, bool sticky, uint32_t nhg_id, |
530 | uint32_t update_flags); | |
0a27a2fe PG |
531 | static enum zebra_dplane_result |
532 | neigh_update_internal(enum dplane_op_e op, const struct interface *ifp, | |
533 | const void *link, int link_family, | |
534 | const struct ipaddr *ip, uint32_t flags, uint16_t state, | |
535 | uint32_t update_flags, int protocol); | |
7cdb1a84 MS |
536 | |
537 | /* | |
538 | * Public APIs | |
539 | */ | |
540 | ||
ad6aad4d MS |
541 | /* Obtain thread_master for dataplane thread */ |
542 | struct thread_master *dplane_get_thread_master(void) | |
543 | { | |
544 | return zdplane_info.dg_master; | |
545 | } | |
546 | ||
7cdb1a84 | 547 | /* |
b8e0423d | 548 | * Allocate a dataplane update context |
7cdb1a84 | 549 | */ |
593e4eb1 | 550 | struct zebra_dplane_ctx *dplane_ctx_alloc(void) |
7cdb1a84 | 551 | { |
25779064 | 552 | struct zebra_dplane_ctx *p; |
7cdb1a84 | 553 | |
b8e0423d MS |
554 | /* TODO -- just alloc'ing memory, but would like to maintain |
555 | * a pool | |
556 | */ | |
25779064 | 557 | p = XCALLOC(MTYPE_DP_CTX, sizeof(struct zebra_dplane_ctx)); |
7cdb1a84 | 558 | |
5709131c | 559 | return p; |
7cdb1a84 MS |
560 | } |
561 | ||
cf363e1b MS |
562 | /* Enable system route notifications */ |
563 | void dplane_enable_sys_route_notifs(void) | |
564 | { | |
565 | zdplane_info.dg_sys_route_notifs = true; | |
566 | } | |
567 | ||
7cdb1a84 | 568 | /* |
f73a8467 | 569 | * Clean up dependent/internal allocations inside a context object |
7cdb1a84 | 570 | */ |
f73a8467 | 571 | static void dplane_ctx_free_internal(struct zebra_dplane_ctx *ctx) |
7cdb1a84 | 572 | { |
5917df09 MS |
573 | struct dplane_intf_extra *if_extra, *if_tmp; |
574 | ||
f73a8467 MS |
575 | /* |
576 | * Some internal allocations may need to be freed, depending on | |
16c628de MS |
577 | * the type of info captured in the ctx. |
578 | */ | |
f73a8467 | 579 | switch (ctx->zd_op) { |
16c628de MS |
580 | case DPLANE_OP_ROUTE_INSTALL: |
581 | case DPLANE_OP_ROUTE_UPDATE: | |
582 | case DPLANE_OP_ROUTE_DELETE: | |
cf363e1b MS |
583 | case DPLANE_OP_SYS_ROUTE_ADD: |
584 | case DPLANE_OP_SYS_ROUTE_DELETE: | |
54818e3b | 585 | case DPLANE_OP_ROUTE_NOTIFY: |
b8e0423d | 586 | |
16c628de | 587 | /* Free allocated nexthops */ |
f73a8467 | 588 | if (ctx->u.rinfo.zd_ng.nexthop) { |
7cdb1a84 | 589 | /* This deals with recursive nexthops too */ |
f73a8467 | 590 | nexthops_free(ctx->u.rinfo.zd_ng.nexthop); |
16c628de | 591 | |
f73a8467 | 592 | ctx->u.rinfo.zd_ng.nexthop = NULL; |
7cdb1a84 MS |
593 | } |
594 | ||
1d48702e | 595 | /* Free backup info also (if present) */ |
f73a8467 | 596 | if (ctx->u.rinfo.backup_ng.nexthop) { |
1d48702e | 597 | /* This deals with recursive nexthops too */ |
f73a8467 | 598 | nexthops_free(ctx->u.rinfo.backup_ng.nexthop); |
1d48702e | 599 | |
f73a8467 | 600 | ctx->u.rinfo.backup_ng.nexthop = NULL; |
1d48702e MS |
601 | } |
602 | ||
f73a8467 | 603 | if (ctx->u.rinfo.zd_old_ng.nexthop) { |
4dfd7a02 | 604 | /* This deals with recursive nexthops too */ |
f73a8467 | 605 | nexthops_free(ctx->u.rinfo.zd_old_ng.nexthop); |
16c628de | 606 | |
f73a8467 | 607 | ctx->u.rinfo.zd_old_ng.nexthop = NULL; |
16c628de MS |
608 | } |
609 | ||
f73a8467 | 610 | if (ctx->u.rinfo.old_backup_ng.nexthop) { |
1d48702e | 611 | /* This deals with recursive nexthops too */ |
f73a8467 | 612 | nexthops_free(ctx->u.rinfo.old_backup_ng.nexthop); |
1d48702e | 613 | |
f73a8467 | 614 | ctx->u.rinfo.old_backup_ng.nexthop = NULL; |
1d48702e MS |
615 | } |
616 | ||
5917df09 MS |
617 | /* Optional extra interface info */ |
618 | TAILQ_FOREACH_SAFE(if_extra, &ctx->u.rinfo.intf_extra_q, | |
619 | link, if_tmp) { | |
620 | TAILQ_REMOVE(&ctx->u.rinfo.intf_extra_q, if_extra, | |
621 | link); | |
622 | XFREE(MTYPE_DP_INTF, if_extra); | |
623 | } | |
624 | ||
16c628de MS |
625 | break; |
626 | ||
f820d025 SW |
627 | case DPLANE_OP_NH_INSTALL: |
628 | case DPLANE_OP_NH_UPDATE: | |
629 | case DPLANE_OP_NH_DELETE: { | |
f73a8467 | 630 | if (ctx->u.rinfo.nhe.ng.nexthop) { |
0c8215cb | 631 | /* This deals with recursive nexthops too */ |
f73a8467 | 632 | nexthops_free(ctx->u.rinfo.nhe.ng.nexthop); |
0c8215cb | 633 | |
f73a8467 | 634 | ctx->u.rinfo.nhe.ng.nexthop = NULL; |
0c8215cb | 635 | } |
f820d025 SW |
636 | break; |
637 | } | |
638 | ||
16c628de MS |
639 | case DPLANE_OP_LSP_INSTALL: |
640 | case DPLANE_OP_LSP_UPDATE: | |
641 | case DPLANE_OP_LSP_DELETE: | |
104e3ad9 | 642 | case DPLANE_OP_LSP_NOTIFY: |
16c628de | 643 | { |
f2595bd5 | 644 | struct zebra_nhlfe *nhlfe; |
16c628de | 645 | |
cd4bb96f MS |
646 | /* Unlink and free allocated NHLFEs */ |
647 | frr_each_safe(nhlfe_list, &ctx->u.lsp.nhlfe_list, nhlfe) { | |
648 | nhlfe_list_del(&ctx->u.lsp.nhlfe_list, nhlfe); | |
649 | zebra_mpls_nhlfe_free(nhlfe); | |
650 | } | |
651 | ||
652 | /* Unlink and free allocated backup NHLFEs, if present */ | |
653 | frr_each_safe(nhlfe_list, | |
654 | &(ctx->u.lsp.backup_nhlfe_list), nhlfe) { | |
655 | nhlfe_list_del(&ctx->u.lsp.backup_nhlfe_list, | |
656 | nhlfe); | |
657 | zebra_mpls_nhlfe_free(nhlfe); | |
658 | } | |
01ce7cba | 659 | |
cd4bb96f | 660 | /* Clear pointers in lsp struct, in case we're caching |
16c628de MS |
661 | * free context structs. |
662 | */ | |
ee70f629 | 663 | nhlfe_list_init(&ctx->u.lsp.nhlfe_list); |
f73a8467 | 664 | ctx->u.lsp.best_nhlfe = NULL; |
cd4bb96f | 665 | nhlfe_list_init(&ctx->u.lsp.backup_nhlfe_list); |
16c628de MS |
666 | |
667 | break; | |
668 | } | |
669 | ||
97d8d05a MS |
670 | case DPLANE_OP_PW_INSTALL: |
671 | case DPLANE_OP_PW_UNINSTALL: | |
16d69787 | 672 | /* Free allocated nexthops */ |
072b487b | 673 | if (ctx->u.pw.fib_nhg.nexthop) { |
16d69787 | 674 | /* This deals with recursive nexthops too */ |
072b487b MS |
675 | nexthops_free(ctx->u.pw.fib_nhg.nexthop); |
676 | ||
677 | ctx->u.pw.fib_nhg.nexthop = NULL; | |
678 | } | |
679 | if (ctx->u.pw.primary_nhg.nexthop) { | |
680 | nexthops_free(ctx->u.pw.primary_nhg.nexthop); | |
16d69787 | 681 | |
072b487b MS |
682 | ctx->u.pw.primary_nhg.nexthop = NULL; |
683 | } | |
684 | if (ctx->u.pw.backup_nhg.nexthop) { | |
685 | nexthops_free(ctx->u.pw.backup_nhg.nexthop); | |
686 | ||
687 | ctx->u.pw.backup_nhg.nexthop = NULL; | |
16d69787 MS |
688 | } |
689 | break; | |
690 | ||
a4a4802a MS |
691 | case DPLANE_OP_ADDR_INSTALL: |
692 | case DPLANE_OP_ADDR_UNINSTALL: | |
9d59df63 MS |
693 | case DPLANE_OP_INTF_ADDR_ADD: |
694 | case DPLANE_OP_INTF_ADDR_DEL: | |
64168803 | 695 | /* Maybe free label string, if allocated */ |
f73a8467 MS |
696 | if (ctx->u.intf.label != NULL && |
697 | ctx->u.intf.label != ctx->u.intf.label_buf) { | |
698 | free(ctx->u.intf.label); | |
699 | ctx->u.intf.label = NULL; | |
64168803 MS |
700 | } |
701 | break; | |
702 | ||
7597ac7b MS |
703 | case DPLANE_OP_MAC_INSTALL: |
704 | case DPLANE_OP_MAC_DELETE: | |
f2412b2d | 705 | case DPLANE_OP_NEIGH_INSTALL: |
931fa60c | 706 | case DPLANE_OP_NEIGH_UPDATE: |
f2412b2d | 707 | case DPLANE_OP_NEIGH_DELETE: |
0bbd4ff4 MS |
708 | case DPLANE_OP_VTEP_ADD: |
709 | case DPLANE_OP_VTEP_DELETE: | |
60d8d43b JU |
710 | case DPLANE_OP_RULE_ADD: |
711 | case DPLANE_OP_RULE_DELETE: | |
712 | case DPLANE_OP_RULE_UPDATE: | |
d68e74b4 | 713 | case DPLANE_OP_NEIGH_DISCOVER: |
c60522f7 | 714 | case DPLANE_OP_BR_PORT_UPDATE: |
0a27a2fe PG |
715 | case DPLANE_OP_NEIGH_IP_INSTALL: |
716 | case DPLANE_OP_NEIGH_IP_DELETE: | |
16c628de | 717 | case DPLANE_OP_NONE: |
ef524230 PG |
718 | case DPLANE_OP_IPSET_ADD: |
719 | case DPLANE_OP_IPSET_DELETE: | |
16c628de | 720 | break; |
5162e000 | 721 | |
ef524230 PG |
722 | case DPLANE_OP_IPSET_ENTRY_ADD: |
723 | case DPLANE_OP_IPSET_ENTRY_DELETE: | |
724 | break; | |
e18747a9 PG |
725 | case DPLANE_OP_NEIGH_TABLE_UPDATE: |
726 | break; | |
5162e000 PG |
727 | case DPLANE_OP_IPTABLE_ADD: |
728 | case DPLANE_OP_IPTABLE_DELETE: | |
729 | if (ctx->u.iptable.interface_name_list) { | |
730 | struct listnode *node, *nnode; | |
731 | char *ifname; | |
732 | ||
733 | for (ALL_LIST_ELEMENTS( | |
734 | ctx->u.iptable.interface_name_list, node, | |
735 | nnode, ifname)) { | |
736 | LISTNODE_DETACH( | |
737 | ctx->u.iptable.interface_name_list, | |
738 | node); | |
ef524230 | 739 | XFREE(MTYPE_DP_NETFILTER, ifname); |
5162e000 PG |
740 | } |
741 | list_delete(&ctx->u.iptable.interface_name_list); | |
742 | } | |
62b4b7e4 PG |
743 | break; |
744 | case DPLANE_OP_GRE_SET: | |
745 | break; | |
7cdb1a84 | 746 | } |
f73a8467 MS |
747 | } |
748 | ||
749 | /* | |
750 | * Free a dataplane results context. | |
751 | */ | |
752 | static void dplane_ctx_free(struct zebra_dplane_ctx **pctx) | |
753 | { | |
754 | if (pctx == NULL) | |
755 | return; | |
756 | ||
757 | DPLANE_CTX_VALID(*pctx); | |
758 | ||
759 | /* TODO -- just freeing memory, but would like to maintain | |
760 | * a pool | |
761 | */ | |
762 | ||
763 | /* Some internal allocations may need to be freed, depending on | |
764 | * the type of info captured in the ctx. | |
765 | */ | |
766 | dplane_ctx_free_internal(*pctx); | |
16c628de MS |
767 | |
768 | XFREE(MTYPE_DP_CTX, *pctx); | |
7cdb1a84 MS |
769 | } |
770 | ||
f73a8467 MS |
771 | /* |
772 | * Reset an allocated context object for re-use. All internal allocations are | |
773 | * freed and the context is memset. | |
774 | */ | |
775 | void dplane_ctx_reset(struct zebra_dplane_ctx *ctx) | |
776 | { | |
777 | dplane_ctx_free_internal(ctx); | |
778 | memset(ctx, 0, sizeof(*ctx)); | |
779 | } | |
780 | ||
7cdb1a84 MS |
781 | /* |
782 | * Return a context block to the dplane module after processing | |
783 | */ | |
25779064 | 784 | void dplane_ctx_fini(struct zebra_dplane_ctx **pctx) |
7cdb1a84 | 785 | { |
14b0bc8e | 786 | /* TODO -- maintain pool; for now, just free */ |
7cdb1a84 MS |
787 | dplane_ctx_free(pctx); |
788 | } | |
789 | ||
790 | /* Enqueue a context block */ | |
25779064 MS |
791 | void dplane_ctx_enqueue_tail(struct dplane_ctx_q *q, |
792 | const struct zebra_dplane_ctx *ctx) | |
7cdb1a84 | 793 | { |
25779064 | 794 | TAILQ_INSERT_TAIL(q, (struct zebra_dplane_ctx *)ctx, zd_q_entries); |
7cdb1a84 MS |
795 | } |
796 | ||
14b0bc8e MS |
797 | /* Append a list of context blocks to another list */ |
798 | void dplane_ctx_list_append(struct dplane_ctx_q *to_list, | |
799 | struct dplane_ctx_q *from_list) | |
800 | { | |
801 | if (TAILQ_FIRST(from_list)) { | |
802 | TAILQ_CONCAT(to_list, from_list, zd_q_entries); | |
803 | ||
804 | /* And clear 'from' list */ | |
805 | TAILQ_INIT(from_list); | |
806 | } | |
807 | } | |
808 | ||
7cdb1a84 | 809 | /* Dequeue a context block from the head of a list */ |
68b375e0 | 810 | struct zebra_dplane_ctx *dplane_ctx_dequeue(struct dplane_ctx_q *q) |
7cdb1a84 | 811 | { |
25779064 | 812 | struct zebra_dplane_ctx *ctx = TAILQ_FIRST(q); |
5709131c MS |
813 | |
814 | if (ctx) | |
7cdb1a84 | 815 | TAILQ_REMOVE(q, ctx, zd_q_entries); |
7cdb1a84 | 816 | |
68b375e0 | 817 | return ctx; |
7cdb1a84 MS |
818 | } |
819 | ||
820 | /* | |
821 | * Accessors for information from the context object | |
822 | */ | |
25779064 MS |
823 | enum zebra_dplane_result dplane_ctx_get_status( |
824 | const struct zebra_dplane_ctx *ctx) | |
7cdb1a84 MS |
825 | { |
826 | DPLANE_CTX_VALID(ctx); | |
827 | ||
5709131c | 828 | return ctx->zd_status; |
7cdb1a84 MS |
829 | } |
830 | ||
c831033f MS |
831 | void dplane_ctx_set_status(struct zebra_dplane_ctx *ctx, |
832 | enum zebra_dplane_result status) | |
833 | { | |
834 | DPLANE_CTX_VALID(ctx); | |
835 | ||
836 | ctx->zd_status = status; | |
837 | } | |
838 | ||
839 | /* Retrieve last/current provider id */ | |
840 | uint32_t dplane_ctx_get_provider(const struct zebra_dplane_ctx *ctx) | |
841 | { | |
842 | DPLANE_CTX_VALID(ctx); | |
843 | return ctx->zd_provider; | |
844 | } | |
845 | ||
846 | /* Providers run before the kernel can control whether a kernel | |
847 | * update should be done. | |
848 | */ | |
849 | void dplane_ctx_set_skip_kernel(struct zebra_dplane_ctx *ctx) | |
850 | { | |
851 | DPLANE_CTX_VALID(ctx); | |
852 | ||
853 | SET_FLAG(ctx->zd_flags, DPLANE_CTX_FLAG_NO_KERNEL); | |
854 | } | |
855 | ||
856 | bool dplane_ctx_is_skip_kernel(const struct zebra_dplane_ctx *ctx) | |
857 | { | |
858 | DPLANE_CTX_VALID(ctx); | |
859 | ||
860 | return CHECK_FLAG(ctx->zd_flags, DPLANE_CTX_FLAG_NO_KERNEL); | |
861 | } | |
862 | ||
593e4eb1 MS |
863 | void dplane_ctx_set_op(struct zebra_dplane_ctx *ctx, enum dplane_op_e op) |
864 | { | |
865 | DPLANE_CTX_VALID(ctx); | |
866 | ctx->zd_op = op; | |
867 | } | |
868 | ||
25779064 | 869 | enum dplane_op_e dplane_ctx_get_op(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
870 | { |
871 | DPLANE_CTX_VALID(ctx); | |
872 | ||
5709131c | 873 | return ctx->zd_op; |
7cdb1a84 MS |
874 | } |
875 | ||
5709131c | 876 | const char *dplane_op2str(enum dplane_op_e op) |
7cdb1a84 MS |
877 | { |
878 | const char *ret = "UNKNOWN"; | |
879 | ||
5709131c | 880 | switch (op) { |
7cdb1a84 MS |
881 | case DPLANE_OP_NONE: |
882 | ret = "NONE"; | |
883 | break; | |
884 | ||
885 | /* Route update */ | |
886 | case DPLANE_OP_ROUTE_INSTALL: | |
887 | ret = "ROUTE_INSTALL"; | |
888 | break; | |
889 | case DPLANE_OP_ROUTE_UPDATE: | |
890 | ret = "ROUTE_UPDATE"; | |
891 | break; | |
892 | case DPLANE_OP_ROUTE_DELETE: | |
893 | ret = "ROUTE_DELETE"; | |
894 | break; | |
54818e3b MS |
895 | case DPLANE_OP_ROUTE_NOTIFY: |
896 | ret = "ROUTE_NOTIFY"; | |
897 | break; | |
7cdb1a84 | 898 | |
f820d025 SW |
899 | /* Nexthop update */ |
900 | case DPLANE_OP_NH_INSTALL: | |
901 | ret = "NH_INSTALL"; | |
902 | break; | |
903 | case DPLANE_OP_NH_UPDATE: | |
904 | ret = "NH_UPDATE"; | |
905 | break; | |
906 | case DPLANE_OP_NH_DELETE: | |
907 | ret = "NH_DELETE"; | |
908 | break; | |
909 | ||
16c628de MS |
910 | case DPLANE_OP_LSP_INSTALL: |
911 | ret = "LSP_INSTALL"; | |
912 | break; | |
913 | case DPLANE_OP_LSP_UPDATE: | |
914 | ret = "LSP_UPDATE"; | |
915 | break; | |
916 | case DPLANE_OP_LSP_DELETE: | |
917 | ret = "LSP_DELETE"; | |
918 | break; | |
104e3ad9 MS |
919 | case DPLANE_OP_LSP_NOTIFY: |
920 | ret = "LSP_NOTIFY"; | |
921 | break; | |
16c628de | 922 | |
97d8d05a MS |
923 | case DPLANE_OP_PW_INSTALL: |
924 | ret = "PW_INSTALL"; | |
925 | break; | |
926 | case DPLANE_OP_PW_UNINSTALL: | |
927 | ret = "PW_UNINSTALL"; | |
928 | break; | |
929 | ||
cf363e1b MS |
930 | case DPLANE_OP_SYS_ROUTE_ADD: |
931 | ret = "SYS_ROUTE_ADD"; | |
932 | break; | |
933 | case DPLANE_OP_SYS_ROUTE_DELETE: | |
934 | ret = "SYS_ROUTE_DEL"; | |
935 | break; | |
a4a4802a | 936 | |
c60522f7 AK |
937 | case DPLANE_OP_BR_PORT_UPDATE: |
938 | ret = "BR_PORT_UPDATE"; | |
939 | break; | |
940 | ||
a4a4802a MS |
941 | case DPLANE_OP_ADDR_INSTALL: |
942 | ret = "ADDR_INSTALL"; | |
943 | break; | |
944 | case DPLANE_OP_ADDR_UNINSTALL: | |
945 | ret = "ADDR_UNINSTALL"; | |
946 | break; | |
947 | ||
7597ac7b MS |
948 | case DPLANE_OP_MAC_INSTALL: |
949 | ret = "MAC_INSTALL"; | |
950 | break; | |
951 | case DPLANE_OP_MAC_DELETE: | |
952 | ret = "MAC_DELETE"; | |
953 | break; | |
f2412b2d MS |
954 | |
955 | case DPLANE_OP_NEIGH_INSTALL: | |
956 | ret = "NEIGH_INSTALL"; | |
957 | break; | |
931fa60c MS |
958 | case DPLANE_OP_NEIGH_UPDATE: |
959 | ret = "NEIGH_UPDATE"; | |
960 | break; | |
f2412b2d MS |
961 | case DPLANE_OP_NEIGH_DELETE: |
962 | ret = "NEIGH_DELETE"; | |
963 | break; | |
0bbd4ff4 MS |
964 | case DPLANE_OP_VTEP_ADD: |
965 | ret = "VTEP_ADD"; | |
966 | break; | |
967 | case DPLANE_OP_VTEP_DELETE: | |
968 | ret = "VTEP_DELETE"; | |
969 | break; | |
60d8d43b JU |
970 | |
971 | case DPLANE_OP_RULE_ADD: | |
972 | ret = "RULE_ADD"; | |
973 | break; | |
974 | case DPLANE_OP_RULE_DELETE: | |
975 | ret = "RULE_DELETE"; | |
976 | break; | |
977 | case DPLANE_OP_RULE_UPDATE: | |
978 | ret = "RULE_UPDATE"; | |
979 | break; | |
d68e74b4 JU |
980 | |
981 | case DPLANE_OP_NEIGH_DISCOVER: | |
982 | ret = "NEIGH_DISCOVER"; | |
983 | break; | |
5162e000 PG |
984 | |
985 | case DPLANE_OP_IPTABLE_ADD: | |
986 | ret = "IPTABLE_ADD"; | |
987 | break; | |
988 | case DPLANE_OP_IPTABLE_DELETE: | |
989 | ret = "IPTABLE_DELETE"; | |
990 | break; | |
ef524230 PG |
991 | case DPLANE_OP_IPSET_ADD: |
992 | ret = "IPSET_ADD"; | |
993 | break; | |
994 | case DPLANE_OP_IPSET_DELETE: | |
995 | ret = "IPSET_DELETE"; | |
996 | break; | |
997 | case DPLANE_OP_IPSET_ENTRY_ADD: | |
998 | ret = "IPSET_ENTRY_ADD"; | |
999 | break; | |
1000 | case DPLANE_OP_IPSET_ENTRY_DELETE: | |
1001 | ret = "IPSET_ENTRY_DELETE"; | |
1002 | break; | |
0a27a2fe PG |
1003 | case DPLANE_OP_NEIGH_IP_INSTALL: |
1004 | ret = "NEIGH_IP_INSTALL"; | |
1005 | break; | |
1006 | case DPLANE_OP_NEIGH_IP_DELETE: | |
1007 | ret = "NEIGH_IP_DELETE"; | |
1008 | break; | |
e18747a9 PG |
1009 | case DPLANE_OP_NEIGH_TABLE_UPDATE: |
1010 | ret = "NEIGH_TABLE_UPDATE"; | |
1011 | break; | |
62b4b7e4 PG |
1012 | |
1013 | case DPLANE_OP_GRE_SET: | |
1014 | ret = "GRE_SET"; | |
1015 | break; | |
9d59df63 MS |
1016 | |
1017 | case DPLANE_OP_INTF_ADDR_ADD: | |
1018 | return "INTF_ADDR_ADD"; | |
1019 | ||
1020 | case DPLANE_OP_INTF_ADDR_DEL: | |
1021 | return "INTF_ADDR_DEL"; | |
5b94ec50 | 1022 | } |
7cdb1a84 | 1023 | |
5709131c | 1024 | return ret; |
7cdb1a84 MS |
1025 | } |
1026 | ||
f183e380 MS |
1027 | const char *dplane_res2str(enum zebra_dplane_result res) |
1028 | { | |
1029 | const char *ret = "<Unknown>"; | |
1030 | ||
1031 | switch (res) { | |
1032 | case ZEBRA_DPLANE_REQUEST_FAILURE: | |
1033 | ret = "FAILURE"; | |
1034 | break; | |
1035 | case ZEBRA_DPLANE_REQUEST_QUEUED: | |
1036 | ret = "QUEUED"; | |
1037 | break; | |
1038 | case ZEBRA_DPLANE_REQUEST_SUCCESS: | |
1039 | ret = "SUCCESS"; | |
1040 | break; | |
5b94ec50 | 1041 | } |
f183e380 MS |
1042 | |
1043 | return ret; | |
1044 | } | |
1045 | ||
593e4eb1 MS |
1046 | void dplane_ctx_set_dest(struct zebra_dplane_ctx *ctx, |
1047 | const struct prefix *dest) | |
1048 | { | |
1049 | DPLANE_CTX_VALID(ctx); | |
1050 | ||
1051 | prefix_copy(&(ctx->u.rinfo.zd_dest), dest); | |
1052 | } | |
1053 | ||
25779064 | 1054 | const struct prefix *dplane_ctx_get_dest(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1055 | { |
1056 | DPLANE_CTX_VALID(ctx); | |
1057 | ||
0f461727 | 1058 | return &(ctx->u.rinfo.zd_dest); |
7cdb1a84 MS |
1059 | } |
1060 | ||
593e4eb1 MS |
1061 | void dplane_ctx_set_src(struct zebra_dplane_ctx *ctx, const struct prefix *src) |
1062 | { | |
1063 | DPLANE_CTX_VALID(ctx); | |
1064 | ||
1065 | if (src) | |
1066 | prefix_copy(&(ctx->u.rinfo.zd_src), src); | |
1067 | else | |
1068 | memset(&(ctx->u.rinfo.zd_src), 0, sizeof(struct prefix)); | |
1069 | } | |
1070 | ||
5709131c | 1071 | /* Source prefix is a little special - return NULL for "no src prefix" */ |
25779064 | 1072 | const struct prefix *dplane_ctx_get_src(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1073 | { |
1074 | DPLANE_CTX_VALID(ctx); | |
1075 | ||
0f461727 MS |
1076 | if (ctx->u.rinfo.zd_src.prefixlen == 0 && |
1077 | IN6_IS_ADDR_UNSPECIFIED(&(ctx->u.rinfo.zd_src.u.prefix6))) { | |
5709131c | 1078 | return NULL; |
7cdb1a84 | 1079 | } else { |
0f461727 | 1080 | return &(ctx->u.rinfo.zd_src); |
7cdb1a84 MS |
1081 | } |
1082 | } | |
1083 | ||
25779064 | 1084 | bool dplane_ctx_is_update(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1085 | { |
1086 | DPLANE_CTX_VALID(ctx); | |
1087 | ||
5709131c | 1088 | return ctx->zd_is_update; |
7cdb1a84 MS |
1089 | } |
1090 | ||
25779064 | 1091 | uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1092 | { |
1093 | DPLANE_CTX_VALID(ctx); | |
1094 | ||
5709131c | 1095 | return ctx->zd_seq; |
7cdb1a84 MS |
1096 | } |
1097 | ||
25779064 | 1098 | uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1099 | { |
1100 | DPLANE_CTX_VALID(ctx); | |
1101 | ||
5709131c | 1102 | return ctx->zd_old_seq; |
7cdb1a84 MS |
1103 | } |
1104 | ||
593e4eb1 MS |
1105 | void dplane_ctx_set_vrf(struct zebra_dplane_ctx *ctx, vrf_id_t vrf) |
1106 | { | |
1107 | DPLANE_CTX_VALID(ctx); | |
1108 | ||
1109 | ctx->zd_vrf_id = vrf; | |
1110 | } | |
1111 | ||
25779064 | 1112 | vrf_id_t dplane_ctx_get_vrf(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1113 | { |
1114 | DPLANE_CTX_VALID(ctx); | |
1115 | ||
5709131c | 1116 | return ctx->zd_vrf_id; |
7cdb1a84 MS |
1117 | } |
1118 | ||
971bad84 MS |
1119 | /* In some paths we have only a namespace id */ |
1120 | void dplane_ctx_set_ns_id(struct zebra_dplane_ctx *ctx, ns_id_t nsid) | |
1121 | { | |
1122 | DPLANE_CTX_VALID(ctx); | |
1123 | ||
1124 | ctx->zd_ns_info.ns_id = nsid; | |
1125 | } | |
1126 | ||
1127 | ns_id_t dplane_ctx_get_ns_id(const struct zebra_dplane_ctx *ctx) | |
1128 | { | |
1129 | DPLANE_CTX_VALID(ctx); | |
1130 | ||
1131 | return ctx->zd_ns_info.ns_id; | |
1132 | } | |
1133 | ||
0024a559 MS |
1134 | bool dplane_ctx_is_from_notif(const struct zebra_dplane_ctx *ctx) |
1135 | { | |
1136 | DPLANE_CTX_VALID(ctx); | |
1137 | ||
1138 | return (ctx->zd_notif_provider != 0); | |
1139 | } | |
1140 | ||
1141 | uint32_t dplane_ctx_get_notif_provider(const struct zebra_dplane_ctx *ctx) | |
1142 | { | |
1143 | DPLANE_CTX_VALID(ctx); | |
1144 | ||
1145 | return ctx->zd_notif_provider; | |
1146 | } | |
1147 | ||
9651af61 MS |
1148 | void dplane_ctx_set_notif_provider(struct zebra_dplane_ctx *ctx, |
1149 | uint32_t id) | |
1150 | { | |
1151 | DPLANE_CTX_VALID(ctx); | |
1152 | ||
1153 | ctx->zd_notif_provider = id; | |
1154 | } | |
fd563cc7 | 1155 | |
7c7ef4a8 MS |
1156 | const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx *ctx) |
1157 | { | |
1158 | DPLANE_CTX_VALID(ctx); | |
1159 | ||
1160 | return ctx->zd_ifname; | |
1161 | } | |
1162 | ||
fd563cc7 KS |
1163 | void dplane_ctx_set_ifname(struct zebra_dplane_ctx *ctx, const char *ifname) |
1164 | { | |
1165 | DPLANE_CTX_VALID(ctx); | |
1166 | ||
1167 | if (!ifname) | |
1168 | return; | |
1169 | ||
1170 | strlcpy(ctx->zd_ifname, ifname, sizeof(ctx->zd_ifname)); | |
1171 | } | |
1172 | ||
7c7ef4a8 MS |
1173 | ifindex_t dplane_ctx_get_ifindex(const struct zebra_dplane_ctx *ctx) |
1174 | { | |
1175 | DPLANE_CTX_VALID(ctx); | |
1176 | ||
1177 | return ctx->zd_ifindex; | |
1178 | } | |
9651af61 | 1179 | |
971bad84 MS |
1180 | void dplane_ctx_set_ifindex(struct zebra_dplane_ctx *ctx, ifindex_t ifindex) |
1181 | { | |
1182 | DPLANE_CTX_VALID(ctx); | |
1183 | ||
1184 | ctx->zd_ifindex = ifindex; | |
1185 | } | |
1186 | ||
593e4eb1 MS |
1187 | void dplane_ctx_set_type(struct zebra_dplane_ctx *ctx, int type) |
1188 | { | |
1189 | DPLANE_CTX_VALID(ctx); | |
1190 | ||
1191 | ctx->u.rinfo.zd_type = type; | |
1192 | } | |
1193 | ||
25779064 | 1194 | int dplane_ctx_get_type(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1195 | { |
1196 | DPLANE_CTX_VALID(ctx); | |
1197 | ||
0f461727 | 1198 | return ctx->u.rinfo.zd_type; |
7cdb1a84 MS |
1199 | } |
1200 | ||
25779064 | 1201 | int dplane_ctx_get_old_type(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1202 | { |
1203 | DPLANE_CTX_VALID(ctx); | |
1204 | ||
0f461727 | 1205 | return ctx->u.rinfo.zd_old_type; |
7cdb1a84 MS |
1206 | } |
1207 | ||
593e4eb1 MS |
1208 | void dplane_ctx_set_afi(struct zebra_dplane_ctx *ctx, afi_t afi) |
1209 | { | |
1210 | DPLANE_CTX_VALID(ctx); | |
1211 | ||
1212 | ctx->u.rinfo.zd_afi = afi; | |
1213 | } | |
1214 | ||
25779064 | 1215 | afi_t dplane_ctx_get_afi(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1216 | { |
1217 | DPLANE_CTX_VALID(ctx); | |
1218 | ||
0f461727 | 1219 | return ctx->u.rinfo.zd_afi; |
7cdb1a84 MS |
1220 | } |
1221 | ||
593e4eb1 MS |
1222 | void dplane_ctx_set_safi(struct zebra_dplane_ctx *ctx, safi_t safi) |
1223 | { | |
1224 | DPLANE_CTX_VALID(ctx); | |
1225 | ||
1226 | ctx->u.rinfo.zd_safi = safi; | |
1227 | } | |
1228 | ||
25779064 | 1229 | safi_t dplane_ctx_get_safi(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1230 | { |
1231 | DPLANE_CTX_VALID(ctx); | |
1232 | ||
0f461727 | 1233 | return ctx->u.rinfo.zd_safi; |
7cdb1a84 MS |
1234 | } |
1235 | ||
593e4eb1 MS |
1236 | void dplane_ctx_set_table(struct zebra_dplane_ctx *ctx, uint32_t table) |
1237 | { | |
1238 | DPLANE_CTX_VALID(ctx); | |
1239 | ||
1240 | ctx->zd_table_id = table; | |
1241 | } | |
1242 | ||
25779064 | 1243 | uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1244 | { |
1245 | DPLANE_CTX_VALID(ctx); | |
1246 | ||
5709131c | 1247 | return ctx->zd_table_id; |
7cdb1a84 MS |
1248 | } |
1249 | ||
25779064 | 1250 | route_tag_t dplane_ctx_get_tag(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1251 | { |
1252 | DPLANE_CTX_VALID(ctx); | |
1253 | ||
0f461727 | 1254 | return ctx->u.rinfo.zd_tag; |
7cdb1a84 MS |
1255 | } |
1256 | ||
6a91ae98 MS |
1257 | void dplane_ctx_set_tag(struct zebra_dplane_ctx *ctx, route_tag_t tag) |
1258 | { | |
1259 | DPLANE_CTX_VALID(ctx); | |
1260 | ||
1261 | ctx->u.rinfo.zd_tag = tag; | |
1262 | } | |
1263 | ||
25779064 | 1264 | route_tag_t dplane_ctx_get_old_tag(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1265 | { |
1266 | DPLANE_CTX_VALID(ctx); | |
1267 | ||
0f461727 | 1268 | return ctx->u.rinfo.zd_old_tag; |
7cdb1a84 MS |
1269 | } |
1270 | ||
25779064 | 1271 | uint16_t dplane_ctx_get_instance(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1272 | { |
1273 | DPLANE_CTX_VALID(ctx); | |
1274 | ||
0f461727 | 1275 | return ctx->u.rinfo.zd_instance; |
7cdb1a84 MS |
1276 | } |
1277 | ||
6a91ae98 MS |
1278 | void dplane_ctx_set_instance(struct zebra_dplane_ctx *ctx, uint16_t instance) |
1279 | { | |
1280 | DPLANE_CTX_VALID(ctx); | |
1281 | ||
1282 | ctx->u.rinfo.zd_instance = instance; | |
1283 | } | |
1284 | ||
25779064 | 1285 | uint16_t dplane_ctx_get_old_instance(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1286 | { |
1287 | DPLANE_CTX_VALID(ctx); | |
1288 | ||
0f461727 | 1289 | return ctx->u.rinfo.zd_old_instance; |
7cdb1a84 MS |
1290 | } |
1291 | ||
25779064 | 1292 | uint32_t dplane_ctx_get_metric(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1293 | { |
1294 | DPLANE_CTX_VALID(ctx); | |
1295 | ||
0f461727 | 1296 | return ctx->u.rinfo.zd_metric; |
7cdb1a84 MS |
1297 | } |
1298 | ||
25779064 | 1299 | uint32_t dplane_ctx_get_old_metric(const struct zebra_dplane_ctx *ctx) |
01ce7cba MS |
1300 | { |
1301 | DPLANE_CTX_VALID(ctx); | |
1302 | ||
0f461727 | 1303 | return ctx->u.rinfo.zd_old_metric; |
01ce7cba MS |
1304 | } |
1305 | ||
25779064 | 1306 | uint32_t dplane_ctx_get_mtu(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1307 | { |
1308 | DPLANE_CTX_VALID(ctx); | |
1309 | ||
0f461727 | 1310 | return ctx->u.rinfo.zd_mtu; |
7cdb1a84 MS |
1311 | } |
1312 | ||
25779064 | 1313 | uint32_t dplane_ctx_get_nh_mtu(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1314 | { |
1315 | DPLANE_CTX_VALID(ctx); | |
1316 | ||
0f461727 | 1317 | return ctx->u.rinfo.zd_nexthop_mtu; |
7cdb1a84 MS |
1318 | } |
1319 | ||
25779064 | 1320 | uint8_t dplane_ctx_get_distance(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1321 | { |
1322 | DPLANE_CTX_VALID(ctx); | |
1323 | ||
0f461727 | 1324 | return ctx->u.rinfo.zd_distance; |
7cdb1a84 MS |
1325 | } |
1326 | ||
6a91ae98 MS |
1327 | void dplane_ctx_set_distance(struct zebra_dplane_ctx *ctx, uint8_t distance) |
1328 | { | |
1329 | DPLANE_CTX_VALID(ctx); | |
1330 | ||
1331 | ctx->u.rinfo.zd_distance = distance; | |
1332 | } | |
1333 | ||
25779064 | 1334 | uint8_t dplane_ctx_get_old_distance(const struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
1335 | { |
1336 | DPLANE_CTX_VALID(ctx); | |
1337 | ||
0f461727 | 1338 | return ctx->u.rinfo.zd_old_distance; |
7cdb1a84 MS |
1339 | } |
1340 | ||
e1f3a8eb MS |
1341 | /* |
1342 | * Set the nexthops associated with a context: note that processing code | |
1343 | * may well expect that nexthops are in canonical (sorted) order, so we | |
1344 | * will enforce that here. | |
1345 | */ | |
593e4eb1 MS |
1346 | void dplane_ctx_set_nexthops(struct zebra_dplane_ctx *ctx, struct nexthop *nh) |
1347 | { | |
1348 | DPLANE_CTX_VALID(ctx); | |
1349 | ||
1350 | if (ctx->u.rinfo.zd_ng.nexthop) { | |
1351 | nexthops_free(ctx->u.rinfo.zd_ng.nexthop); | |
1352 | ctx->u.rinfo.zd_ng.nexthop = NULL; | |
1353 | } | |
e1f3a8eb | 1354 | nexthop_group_copy_nh_sorted(&(ctx->u.rinfo.zd_ng), nh); |
593e4eb1 MS |
1355 | } |
1356 | ||
928f94a9 MS |
1357 | /* |
1358 | * Set the list of backup nexthops; their ordering is preserved (they're not | |
1359 | * re-sorted.) | |
1360 | */ | |
1361 | void dplane_ctx_set_backup_nhg(struct zebra_dplane_ctx *ctx, | |
1362 | const struct nexthop_group *nhg) | |
1363 | { | |
1364 | struct nexthop *nh, *last_nh, *nexthop; | |
1365 | ||
1366 | DPLANE_CTX_VALID(ctx); | |
1367 | ||
1368 | if (ctx->u.rinfo.backup_ng.nexthop) { | |
1369 | nexthops_free(ctx->u.rinfo.backup_ng.nexthop); | |
1370 | ctx->u.rinfo.backup_ng.nexthop = NULL; | |
1371 | } | |
1372 | ||
1373 | last_nh = NULL; | |
1374 | ||
1375 | /* Be careful to preserve the order of the backup list */ | |
1376 | for (nh = nhg->nexthop; nh; nh = nh->next) { | |
1377 | nexthop = nexthop_dup(nh, NULL); | |
1378 | ||
1379 | if (last_nh) | |
1380 | NEXTHOP_APPEND(last_nh, nexthop); | |
1381 | else | |
1382 | ctx->u.rinfo.backup_ng.nexthop = nexthop; | |
1383 | ||
1384 | last_nh = nexthop; | |
1385 | } | |
1386 | } | |
1387 | ||
1d48702e MS |
1388 | uint32_t dplane_ctx_get_nhg_id(const struct zebra_dplane_ctx *ctx) |
1389 | { | |
1390 | DPLANE_CTX_VALID(ctx); | |
1391 | return ctx->u.rinfo.zd_nhg_id; | |
1392 | } | |
1393 | ||
25779064 MS |
1394 | const struct nexthop_group *dplane_ctx_get_ng( |
1395 | const struct zebra_dplane_ctx *ctx) | |
7cdb1a84 MS |
1396 | { |
1397 | DPLANE_CTX_VALID(ctx); | |
1398 | ||
0f461727 | 1399 | return &(ctx->u.rinfo.zd_ng); |
7cdb1a84 MS |
1400 | } |
1401 | ||
1d48702e MS |
1402 | const struct nexthop_group * |
1403 | dplane_ctx_get_backup_ng(const struct zebra_dplane_ctx *ctx) | |
1404 | { | |
1405 | DPLANE_CTX_VALID(ctx); | |
1406 | ||
1407 | return &(ctx->u.rinfo.backup_ng); | |
1408 | } | |
1409 | ||
1410 | const struct nexthop_group * | |
1411 | dplane_ctx_get_old_ng(const struct zebra_dplane_ctx *ctx) | |
01ce7cba MS |
1412 | { |
1413 | DPLANE_CTX_VALID(ctx); | |
1414 | ||
0f461727 | 1415 | return &(ctx->u.rinfo.zd_old_ng); |
01ce7cba MS |
1416 | } |
1417 | ||
1d48702e MS |
1418 | const struct nexthop_group * |
1419 | dplane_ctx_get_old_backup_ng(const struct zebra_dplane_ctx *ctx) | |
1420 | { | |
1421 | DPLANE_CTX_VALID(ctx); | |
1422 | ||
1423 | return &(ctx->u.rinfo.old_backup_ng); | |
1424 | } | |
1425 | ||
25779064 MS |
1426 | const struct zebra_dplane_info *dplane_ctx_get_ns( |
1427 | const struct zebra_dplane_ctx *ctx) | |
7cdb1a84 MS |
1428 | { |
1429 | DPLANE_CTX_VALID(ctx); | |
1430 | ||
5709131c | 1431 | return &(ctx->zd_ns_info); |
7cdb1a84 MS |
1432 | } |
1433 | ||
f820d025 | 1434 | /* Accessors for nexthop information */ |
0c8215cb SW |
1435 | uint32_t dplane_ctx_get_nhe_id(const struct zebra_dplane_ctx *ctx) |
1436 | { | |
1437 | DPLANE_CTX_VALID(ctx); | |
1438 | return ctx->u.rinfo.nhe.id; | |
1439 | } | |
1440 | ||
df3cef24 DS |
1441 | uint32_t dplane_ctx_get_old_nhe_id(const struct zebra_dplane_ctx *ctx) |
1442 | { | |
1443 | DPLANE_CTX_VALID(ctx); | |
1444 | return ctx->u.rinfo.nhe.old_id; | |
1445 | } | |
1446 | ||
0c8215cb SW |
1447 | afi_t dplane_ctx_get_nhe_afi(const struct zebra_dplane_ctx *ctx) |
1448 | { | |
1449 | DPLANE_CTX_VALID(ctx); | |
1450 | return ctx->u.rinfo.nhe.afi; | |
1451 | } | |
1452 | ||
1453 | vrf_id_t dplane_ctx_get_nhe_vrf_id(const struct zebra_dplane_ctx *ctx) | |
f820d025 SW |
1454 | { |
1455 | DPLANE_CTX_VALID(ctx); | |
0c8215cb SW |
1456 | return ctx->u.rinfo.nhe.vrf_id; |
1457 | } | |
1458 | ||
38e40db1 | 1459 | int dplane_ctx_get_nhe_type(const struct zebra_dplane_ctx *ctx) |
0c8215cb SW |
1460 | { |
1461 | DPLANE_CTX_VALID(ctx); | |
38e40db1 | 1462 | return ctx->u.rinfo.nhe.type; |
0c8215cb SW |
1463 | } |
1464 | ||
1465 | const struct nexthop_group * | |
1466 | dplane_ctx_get_nhe_ng(const struct zebra_dplane_ctx *ctx) | |
1467 | { | |
1468 | DPLANE_CTX_VALID(ctx); | |
1469 | return &(ctx->u.rinfo.nhe.ng); | |
1470 | } | |
1471 | ||
e22e8001 SW |
1472 | const struct nh_grp * |
1473 | dplane_ctx_get_nhe_nh_grp(const struct zebra_dplane_ctx *ctx) | |
0c8215cb SW |
1474 | { |
1475 | DPLANE_CTX_VALID(ctx); | |
e22e8001 | 1476 | return ctx->u.rinfo.nhe.nh_grp; |
0c8215cb SW |
1477 | } |
1478 | ||
e22e8001 | 1479 | uint8_t dplane_ctx_get_nhe_nh_grp_count(const struct zebra_dplane_ctx *ctx) |
0c8215cb SW |
1480 | { |
1481 | DPLANE_CTX_VALID(ctx); | |
e22e8001 | 1482 | return ctx->u.rinfo.nhe.nh_grp_count; |
f820d025 SW |
1483 | } |
1484 | ||
0f461727 MS |
1485 | /* Accessors for LSP information */ |
1486 | ||
1487 | mpls_label_t dplane_ctx_get_in_label(const struct zebra_dplane_ctx *ctx) | |
1488 | { | |
1489 | DPLANE_CTX_VALID(ctx); | |
1490 | ||
1491 | return ctx->u.lsp.ile.in_label; | |
1492 | } | |
1493 | ||
3ab54059 MS |
1494 | void dplane_ctx_set_in_label(struct zebra_dplane_ctx *ctx, mpls_label_t label) |
1495 | { | |
1496 | DPLANE_CTX_VALID(ctx); | |
1497 | ||
1498 | ctx->u.lsp.ile.in_label = label; | |
1499 | } | |
1500 | ||
0f461727 MS |
1501 | uint8_t dplane_ctx_get_addr_family(const struct zebra_dplane_ctx *ctx) |
1502 | { | |
1503 | DPLANE_CTX_VALID(ctx); | |
1504 | ||
1505 | return ctx->u.lsp.addr_family; | |
1506 | } | |
1507 | ||
3ab54059 MS |
1508 | void dplane_ctx_set_addr_family(struct zebra_dplane_ctx *ctx, |
1509 | uint8_t family) | |
1510 | { | |
1511 | DPLANE_CTX_VALID(ctx); | |
1512 | ||
1513 | ctx->u.lsp.addr_family = family; | |
1514 | } | |
1515 | ||
0f461727 MS |
1516 | uint32_t dplane_ctx_get_lsp_flags(const struct zebra_dplane_ctx *ctx) |
1517 | { | |
1518 | DPLANE_CTX_VALID(ctx); | |
1519 | ||
1520 | return ctx->u.lsp.flags; | |
1521 | } | |
1522 | ||
3ab54059 MS |
1523 | void dplane_ctx_set_lsp_flags(struct zebra_dplane_ctx *ctx, |
1524 | uint32_t flags) | |
1525 | { | |
1526 | DPLANE_CTX_VALID(ctx); | |
1527 | ||
1528 | ctx->u.lsp.flags = flags; | |
1529 | } | |
1530 | ||
ee70f629 MS |
1531 | const struct nhlfe_list_head *dplane_ctx_get_nhlfe_list( |
1532 | const struct zebra_dplane_ctx *ctx) | |
0f461727 MS |
1533 | { |
1534 | DPLANE_CTX_VALID(ctx); | |
ee70f629 | 1535 | return &(ctx->u.lsp.nhlfe_list); |
0f461727 MS |
1536 | } |
1537 | ||
cd4bb96f MS |
1538 | const struct nhlfe_list_head *dplane_ctx_get_backup_nhlfe_list( |
1539 | const struct zebra_dplane_ctx *ctx) | |
1540 | { | |
1541 | DPLANE_CTX_VALID(ctx); | |
1542 | return &(ctx->u.lsp.backup_nhlfe_list); | |
1543 | } | |
1544 | ||
f2595bd5 DS |
1545 | struct zebra_nhlfe *dplane_ctx_add_nhlfe(struct zebra_dplane_ctx *ctx, |
1546 | enum lsp_types_t lsp_type, | |
1547 | enum nexthop_types_t nh_type, | |
1548 | const union g_addr *gate, | |
1549 | ifindex_t ifindex, uint8_t num_labels, | |
1550 | mpls_label_t *out_labels) | |
3ab54059 | 1551 | { |
f2595bd5 | 1552 | struct zebra_nhlfe *nhlfe; |
3ab54059 MS |
1553 | |
1554 | DPLANE_CTX_VALID(ctx); | |
1555 | ||
1556 | nhlfe = zebra_mpls_lsp_add_nhlfe(&(ctx->u.lsp), | |
1557 | lsp_type, nh_type, gate, | |
5065db0a | 1558 | ifindex, num_labels, out_labels); |
3ab54059 MS |
1559 | |
1560 | return nhlfe; | |
1561 | } | |
1562 | ||
f2595bd5 DS |
1563 | struct zebra_nhlfe *dplane_ctx_add_backup_nhlfe( |
1564 | struct zebra_dplane_ctx *ctx, enum lsp_types_t lsp_type, | |
1565 | enum nexthop_types_t nh_type, const union g_addr *gate, | |
1566 | ifindex_t ifindex, uint8_t num_labels, mpls_label_t *out_labels) | |
cd4bb96f | 1567 | { |
f2595bd5 | 1568 | struct zebra_nhlfe *nhlfe; |
cd4bb96f MS |
1569 | |
1570 | DPLANE_CTX_VALID(ctx); | |
1571 | ||
1572 | nhlfe = zebra_mpls_lsp_add_backup_nhlfe(&(ctx->u.lsp), | |
1573 | lsp_type, nh_type, gate, | |
1574 | ifindex, num_labels, | |
1575 | out_labels); | |
1576 | ||
1577 | return nhlfe; | |
1578 | } | |
1579 | ||
f2595bd5 | 1580 | const struct zebra_nhlfe * |
81793ac1 | 1581 | dplane_ctx_get_best_nhlfe(const struct zebra_dplane_ctx *ctx) |
0f461727 MS |
1582 | { |
1583 | DPLANE_CTX_VALID(ctx); | |
1584 | ||
1585 | return ctx->u.lsp.best_nhlfe; | |
1586 | } | |
1587 | ||
f2595bd5 | 1588 | const struct zebra_nhlfe * |
3ab54059 | 1589 | dplane_ctx_set_best_nhlfe(struct zebra_dplane_ctx *ctx, |
f2595bd5 | 1590 | struct zebra_nhlfe *nhlfe) |
3ab54059 MS |
1591 | { |
1592 | DPLANE_CTX_VALID(ctx); | |
1593 | ||
1594 | ctx->u.lsp.best_nhlfe = nhlfe; | |
1595 | return ctx->u.lsp.best_nhlfe; | |
1596 | } | |
1597 | ||
0f461727 MS |
1598 | uint32_t dplane_ctx_get_lsp_num_ecmp(const struct zebra_dplane_ctx *ctx) |
1599 | { | |
1600 | DPLANE_CTX_VALID(ctx); | |
1601 | ||
1602 | return ctx->u.lsp.num_ecmp; | |
1603 | } | |
1604 | ||
d613b8e1 MS |
1605 | mpls_label_t dplane_ctx_get_pw_local_label(const struct zebra_dplane_ctx *ctx) |
1606 | { | |
1607 | DPLANE_CTX_VALID(ctx); | |
1608 | ||
1609 | return ctx->u.pw.local_label; | |
1610 | } | |
1611 | ||
1612 | mpls_label_t dplane_ctx_get_pw_remote_label(const struct zebra_dplane_ctx *ctx) | |
1613 | { | |
1614 | DPLANE_CTX_VALID(ctx); | |
1615 | ||
1616 | return ctx->u.pw.remote_label; | |
1617 | } | |
1618 | ||
1619 | int dplane_ctx_get_pw_type(const struct zebra_dplane_ctx *ctx) | |
1620 | { | |
1621 | DPLANE_CTX_VALID(ctx); | |
1622 | ||
1623 | return ctx->u.pw.type; | |
1624 | } | |
1625 | ||
1626 | int dplane_ctx_get_pw_af(const struct zebra_dplane_ctx *ctx) | |
1627 | { | |
1628 | DPLANE_CTX_VALID(ctx); | |
1629 | ||
1630 | return ctx->u.pw.af; | |
1631 | } | |
1632 | ||
1633 | uint32_t dplane_ctx_get_pw_flags(const struct zebra_dplane_ctx *ctx) | |
1634 | { | |
1635 | DPLANE_CTX_VALID(ctx); | |
1636 | ||
1637 | return ctx->u.pw.flags; | |
1638 | } | |
1639 | ||
1640 | int dplane_ctx_get_pw_status(const struct zebra_dplane_ctx *ctx) | |
1641 | { | |
1642 | DPLANE_CTX_VALID(ctx); | |
1643 | ||
1644 | return ctx->u.pw.status; | |
1645 | } | |
1646 | ||
fd563cc7 KS |
1647 | void dplane_ctx_set_pw_status(struct zebra_dplane_ctx *ctx, int status) |
1648 | { | |
1649 | DPLANE_CTX_VALID(ctx); | |
1650 | ||
1651 | ctx->u.pw.status = status; | |
1652 | } | |
1653 | ||
16d69787 | 1654 | const union g_addr *dplane_ctx_get_pw_dest( |
d613b8e1 MS |
1655 | const struct zebra_dplane_ctx *ctx) |
1656 | { | |
1657 | DPLANE_CTX_VALID(ctx); | |
1658 | ||
16d69787 | 1659 | return &(ctx->u.pw.dest); |
d613b8e1 MS |
1660 | } |
1661 | ||
1662 | const union pw_protocol_fields *dplane_ctx_get_pw_proto( | |
1663 | const struct zebra_dplane_ctx *ctx) | |
1664 | { | |
1665 | DPLANE_CTX_VALID(ctx); | |
1666 | ||
1667 | return &(ctx->u.pw.fields); | |
1668 | } | |
1669 | ||
09cd307c MS |
1670 | const struct nexthop_group * |
1671 | dplane_ctx_get_pw_nhg(const struct zebra_dplane_ctx *ctx) | |
1672 | { | |
1673 | DPLANE_CTX_VALID(ctx); | |
1674 | ||
072b487b MS |
1675 | return &(ctx->u.pw.fib_nhg); |
1676 | } | |
1677 | ||
1678 | const struct nexthop_group * | |
1679 | dplane_ctx_get_pw_primary_nhg(const struct zebra_dplane_ctx *ctx) | |
1680 | { | |
1681 | DPLANE_CTX_VALID(ctx); | |
1682 | ||
1683 | return &(ctx->u.pw.primary_nhg); | |
1684 | } | |
1685 | ||
1686 | const struct nexthop_group * | |
1687 | dplane_ctx_get_pw_backup_nhg(const struct zebra_dplane_ctx *ctx) | |
1688 | { | |
1689 | DPLANE_CTX_VALID(ctx); | |
1690 | ||
1691 | return &(ctx->u.pw.backup_nhg); | |
09cd307c MS |
1692 | } |
1693 | ||
a4a4802a | 1694 | /* Accessors for interface information */ |
a4a4802a MS |
1695 | uint32_t dplane_ctx_get_intf_metric(const struct zebra_dplane_ctx *ctx) |
1696 | { | |
1697 | DPLANE_CTX_VALID(ctx); | |
1698 | ||
1699 | return ctx->u.intf.metric; | |
1700 | } | |
1701 | ||
971bad84 MS |
1702 | void dplane_ctx_set_intf_metric(struct zebra_dplane_ctx *ctx, uint32_t metric) |
1703 | { | |
1704 | DPLANE_CTX_VALID(ctx); | |
1705 | ||
1706 | ctx->u.intf.metric = metric; | |
1707 | } | |
1708 | ||
a4a4802a MS |
1709 | /* Is interface addr p2p? */ |
1710 | bool dplane_ctx_intf_is_connected(const struct zebra_dplane_ctx *ctx) | |
1711 | { | |
1712 | DPLANE_CTX_VALID(ctx); | |
1713 | ||
1714 | return (ctx->u.intf.flags & DPLANE_INTF_CONNECTED); | |
1715 | } | |
1716 | ||
1717 | bool dplane_ctx_intf_is_secondary(const struct zebra_dplane_ctx *ctx) | |
1718 | { | |
1719 | DPLANE_CTX_VALID(ctx); | |
1720 | ||
1721 | return (ctx->u.intf.flags & DPLANE_INTF_SECONDARY); | |
1722 | } | |
1723 | ||
64168803 MS |
1724 | bool dplane_ctx_intf_is_broadcast(const struct zebra_dplane_ctx *ctx) |
1725 | { | |
1726 | DPLANE_CTX_VALID(ctx); | |
1727 | ||
1728 | return (ctx->u.intf.flags & DPLANE_INTF_BROADCAST); | |
1729 | } | |
1730 | ||
971bad84 MS |
1731 | void dplane_ctx_intf_set_connected(struct zebra_dplane_ctx *ctx) |
1732 | { | |
1733 | DPLANE_CTX_VALID(ctx); | |
1734 | ||
1735 | ctx->u.intf.flags |= DPLANE_INTF_CONNECTED; | |
1736 | } | |
1737 | ||
1738 | void dplane_ctx_intf_set_secondary(struct zebra_dplane_ctx *ctx) | |
1739 | { | |
1740 | DPLANE_CTX_VALID(ctx); | |
1741 | ||
1742 | ctx->u.intf.flags |= DPLANE_INTF_SECONDARY; | |
1743 | } | |
1744 | ||
1745 | void dplane_ctx_intf_set_broadcast(struct zebra_dplane_ctx *ctx) | |
1746 | { | |
1747 | DPLANE_CTX_VALID(ctx); | |
1748 | ||
1749 | ctx->u.intf.flags |= DPLANE_INTF_BROADCAST; | |
1750 | } | |
1751 | ||
a4a4802a MS |
1752 | const struct prefix *dplane_ctx_get_intf_addr( |
1753 | const struct zebra_dplane_ctx *ctx) | |
1754 | { | |
1755 | DPLANE_CTX_VALID(ctx); | |
1756 | ||
1757 | return &(ctx->u.intf.prefix); | |
1758 | } | |
1759 | ||
971bad84 MS |
1760 | void dplane_ctx_set_intf_addr(struct zebra_dplane_ctx *ctx, |
1761 | const struct prefix *p) | |
1762 | { | |
1763 | DPLANE_CTX_VALID(ctx); | |
1764 | ||
1765 | prefix_copy(&(ctx->u.intf.prefix), p); | |
1766 | } | |
1767 | ||
a4a4802a MS |
1768 | bool dplane_ctx_intf_has_dest(const struct zebra_dplane_ctx *ctx) |
1769 | { | |
1770 | DPLANE_CTX_VALID(ctx); | |
1771 | ||
1772 | return (ctx->u.intf.flags & DPLANE_INTF_HAS_DEST); | |
1773 | } | |
1774 | ||
1775 | const struct prefix *dplane_ctx_get_intf_dest( | |
1776 | const struct zebra_dplane_ctx *ctx) | |
1777 | { | |
1778 | DPLANE_CTX_VALID(ctx); | |
1779 | ||
971bad84 MS |
1780 | return &(ctx->u.intf.dest_prefix); |
1781 | } | |
1782 | ||
1783 | void dplane_ctx_set_intf_dest(struct zebra_dplane_ctx *ctx, | |
1784 | const struct prefix *p) | |
1785 | { | |
1786 | DPLANE_CTX_VALID(ctx); | |
1787 | ||
1788 | prefix_copy(&(ctx->u.intf.dest_prefix), p); | |
a4a4802a MS |
1789 | } |
1790 | ||
1791 | bool dplane_ctx_intf_has_label(const struct zebra_dplane_ctx *ctx) | |
1792 | { | |
1793 | DPLANE_CTX_VALID(ctx); | |
1794 | ||
1795 | return (ctx->u.intf.flags & DPLANE_INTF_HAS_LABEL); | |
1796 | } | |
1797 | ||
1798 | const char *dplane_ctx_get_intf_label(const struct zebra_dplane_ctx *ctx) | |
1799 | { | |
1800 | DPLANE_CTX_VALID(ctx); | |
1801 | ||
1802 | return ctx->u.intf.label; | |
1803 | } | |
1804 | ||
971bad84 MS |
1805 | void dplane_ctx_set_intf_label(struct zebra_dplane_ctx *ctx, const char *label) |
1806 | { | |
1807 | size_t len; | |
1808 | ||
1809 | DPLANE_CTX_VALID(ctx); | |
1810 | ||
1811 | if (ctx->u.intf.label && ctx->u.intf.label != ctx->u.intf.label_buf) | |
1812 | free(ctx->u.intf.label); | |
1813 | ||
1814 | ctx->u.intf.label = NULL; | |
1815 | ||
1816 | if (label) { | |
1817 | ctx->u.intf.flags |= DPLANE_INTF_HAS_LABEL; | |
1818 | ||
1819 | /* Use embedded buffer if it's adequate; else allocate. */ | |
1820 | len = strlen(label); | |
1821 | ||
1822 | if (len < sizeof(ctx->u.intf.label_buf)) { | |
1823 | strlcpy(ctx->u.intf.label_buf, label, | |
1824 | sizeof(ctx->u.intf.label_buf)); | |
1825 | ctx->u.intf.label = ctx->u.intf.label_buf; | |
1826 | } else { | |
1827 | ctx->u.intf.label = strdup(label); | |
1828 | } | |
1829 | } else { | |
1830 | ctx->u.intf.flags &= ~DPLANE_INTF_HAS_LABEL; | |
1831 | } | |
1832 | } | |
1833 | ||
7597ac7b MS |
1834 | /* Accessors for MAC information */ |
1835 | vlanid_t dplane_ctx_mac_get_vlan(const struct zebra_dplane_ctx *ctx) | |
1836 | { | |
1837 | DPLANE_CTX_VALID(ctx); | |
1838 | return ctx->u.macinfo.vid; | |
1839 | } | |
1840 | ||
1841 | bool dplane_ctx_mac_is_sticky(const struct zebra_dplane_ctx *ctx) | |
1842 | { | |
1843 | DPLANE_CTX_VALID(ctx); | |
1844 | return ctx->u.macinfo.is_sticky; | |
1845 | } | |
1846 | ||
506efd37 AK |
1847 | uint32_t dplane_ctx_mac_get_nhg_id(const struct zebra_dplane_ctx *ctx) |
1848 | { | |
1849 | DPLANE_CTX_VALID(ctx); | |
1850 | return ctx->u.macinfo.nhg_id; | |
1851 | } | |
1852 | ||
f188e68e AK |
1853 | uint32_t dplane_ctx_mac_get_update_flags(const struct zebra_dplane_ctx *ctx) |
1854 | { | |
1855 | DPLANE_CTX_VALID(ctx); | |
1856 | return ctx->u.macinfo.update_flags; | |
1857 | } | |
1858 | ||
7597ac7b MS |
1859 | const struct ethaddr *dplane_ctx_mac_get_addr( |
1860 | const struct zebra_dplane_ctx *ctx) | |
1861 | { | |
1862 | DPLANE_CTX_VALID(ctx); | |
1863 | return &(ctx->u.macinfo.mac); | |
1864 | } | |
1865 | ||
1866 | const struct in_addr *dplane_ctx_mac_get_vtep_ip( | |
1867 | const struct zebra_dplane_ctx *ctx) | |
1868 | { | |
1869 | DPLANE_CTX_VALID(ctx); | |
1870 | return &(ctx->u.macinfo.vtep_ip); | |
1871 | } | |
1872 | ||
478566d6 MS |
1873 | ifindex_t dplane_ctx_mac_get_br_ifindex(const struct zebra_dplane_ctx *ctx) |
1874 | { | |
1875 | DPLANE_CTX_VALID(ctx); | |
1876 | return ctx->u.macinfo.br_ifindex; | |
1877 | } | |
1878 | ||
931fa60c MS |
1879 | /* Accessors for neighbor information */ |
1880 | const struct ipaddr *dplane_ctx_neigh_get_ipaddr( | |
1881 | const struct zebra_dplane_ctx *ctx) | |
1882 | { | |
1883 | DPLANE_CTX_VALID(ctx); | |
1884 | return &(ctx->u.neigh.ip_addr); | |
1885 | } | |
1886 | ||
0a27a2fe PG |
1887 | const struct ipaddr * |
1888 | dplane_ctx_neigh_get_link_ip(const struct zebra_dplane_ctx *ctx) | |
1889 | { | |
1890 | DPLANE_CTX_VALID(ctx); | |
1891 | return &(ctx->u.neigh.link.ip_addr); | |
1892 | } | |
1893 | ||
931fa60c MS |
1894 | const struct ethaddr *dplane_ctx_neigh_get_mac( |
1895 | const struct zebra_dplane_ctx *ctx) | |
1896 | { | |
1897 | DPLANE_CTX_VALID(ctx); | |
0a27a2fe | 1898 | return &(ctx->u.neigh.link.mac); |
931fa60c MS |
1899 | } |
1900 | ||
1901 | uint32_t dplane_ctx_neigh_get_flags(const struct zebra_dplane_ctx *ctx) | |
1902 | { | |
1903 | DPLANE_CTX_VALID(ctx); | |
1904 | return ctx->u.neigh.flags; | |
1905 | } | |
1906 | ||
1907 | uint16_t dplane_ctx_neigh_get_state(const struct zebra_dplane_ctx *ctx) | |
1908 | { | |
1909 | DPLANE_CTX_VALID(ctx); | |
1910 | return ctx->u.neigh.state; | |
1911 | } | |
1912 | ||
f188e68e AK |
1913 | uint32_t dplane_ctx_neigh_get_update_flags(const struct zebra_dplane_ctx *ctx) |
1914 | { | |
1915 | DPLANE_CTX_VALID(ctx); | |
1916 | return ctx->u.neigh.update_flags; | |
1917 | } | |
1918 | ||
62b4b7e4 PG |
1919 | /* Accessor for GRE set */ |
1920 | uint32_t | |
1921 | dplane_ctx_gre_get_link_ifindex(const struct zebra_dplane_ctx *ctx) | |
1922 | { | |
1923 | DPLANE_CTX_VALID(ctx); | |
1924 | ||
1925 | return ctx->u.gre.link_ifindex; | |
1926 | } | |
1927 | ||
db51f0cd PG |
1928 | unsigned int |
1929 | dplane_ctx_gre_get_mtu(const struct zebra_dplane_ctx *ctx) | |
1930 | { | |
1931 | DPLANE_CTX_VALID(ctx); | |
1932 | ||
1933 | return ctx->u.gre.mtu; | |
1934 | } | |
1935 | ||
e3d3fa06 PG |
1936 | const struct zebra_l2info_gre * |
1937 | dplane_ctx_gre_get_info(const struct zebra_dplane_ctx *ctx) | |
1938 | { | |
1939 | DPLANE_CTX_VALID(ctx); | |
1940 | ||
1941 | return &ctx->u.gre.info; | |
1942 | } | |
1943 | ||
60d8d43b JU |
1944 | /* Accessors for PBR rule information */ |
1945 | int dplane_ctx_rule_get_sock(const struct zebra_dplane_ctx *ctx) | |
1946 | { | |
1947 | DPLANE_CTX_VALID(ctx); | |
1948 | ||
1949 | return ctx->u.rule.sock; | |
1950 | } | |
1951 | ||
58a1d249 DS |
1952 | const char *dplane_ctx_rule_get_ifname(const struct zebra_dplane_ctx *ctx) |
1953 | { | |
1954 | DPLANE_CTX_VALID(ctx); | |
1955 | ||
1956 | return ctx->u.rule.new.ifname; | |
1957 | } | |
1958 | ||
60d8d43b JU |
1959 | int dplane_ctx_rule_get_unique(const struct zebra_dplane_ctx *ctx) |
1960 | { | |
1961 | DPLANE_CTX_VALID(ctx); | |
1962 | ||
1963 | return ctx->u.rule.unique; | |
1964 | } | |
1965 | ||
1966 | int dplane_ctx_rule_get_seq(const struct zebra_dplane_ctx *ctx) | |
1967 | { | |
1968 | DPLANE_CTX_VALID(ctx); | |
1969 | ||
1970 | return ctx->u.rule.seq; | |
1971 | } | |
1972 | ||
1973 | uint32_t dplane_ctx_rule_get_priority(const struct zebra_dplane_ctx *ctx) | |
1974 | { | |
1975 | DPLANE_CTX_VALID(ctx); | |
1976 | ||
1977 | return ctx->u.rule.new.priority; | |
1978 | } | |
1979 | ||
1980 | uint32_t dplane_ctx_rule_get_old_priority(const struct zebra_dplane_ctx *ctx) | |
1981 | { | |
1982 | DPLANE_CTX_VALID(ctx); | |
1983 | ||
1984 | return ctx->u.rule.old.priority; | |
1985 | } | |
1986 | ||
1987 | uint32_t dplane_ctx_rule_get_table(const struct zebra_dplane_ctx *ctx) | |
1988 | { | |
1989 | DPLANE_CTX_VALID(ctx); | |
1990 | ||
1991 | return ctx->u.rule.new.table; | |
1992 | } | |
1993 | ||
1994 | uint32_t dplane_ctx_rule_get_old_table(const struct zebra_dplane_ctx *ctx) | |
1995 | { | |
1996 | DPLANE_CTX_VALID(ctx); | |
1997 | ||
1998 | return ctx->u.rule.old.table; | |
1999 | } | |
2000 | ||
2001 | uint32_t dplane_ctx_rule_get_filter_bm(const struct zebra_dplane_ctx *ctx) | |
2002 | { | |
2003 | DPLANE_CTX_VALID(ctx); | |
2004 | ||
2005 | return ctx->u.rule.new.filter_bm; | |
2006 | } | |
2007 | ||
2008 | uint32_t dplane_ctx_rule_get_old_filter_bm(const struct zebra_dplane_ctx *ctx) | |
2009 | { | |
2010 | DPLANE_CTX_VALID(ctx); | |
2011 | ||
2012 | return ctx->u.rule.old.filter_bm; | |
2013 | } | |
2014 | ||
2015 | uint32_t dplane_ctx_rule_get_fwmark(const struct zebra_dplane_ctx *ctx) | |
2016 | { | |
2017 | DPLANE_CTX_VALID(ctx); | |
2018 | ||
2019 | return ctx->u.rule.new.fwmark; | |
2020 | } | |
2021 | ||
2022 | uint32_t dplane_ctx_rule_get_old_fwmark(const struct zebra_dplane_ctx *ctx) | |
2023 | { | |
2024 | DPLANE_CTX_VALID(ctx); | |
2025 | ||
2026 | return ctx->u.rule.old.fwmark; | |
2027 | } | |
2028 | ||
8ccbc778 DS |
2029 | uint8_t dplane_ctx_rule_get_ipproto(const struct zebra_dplane_ctx *ctx) |
2030 | { | |
2031 | DPLANE_CTX_VALID(ctx); | |
2032 | ||
2033 | return ctx->u.rule.new.ip_proto; | |
2034 | } | |
2035 | ||
2036 | uint8_t dplane_ctx_rule_get_old_ipproto(const struct zebra_dplane_ctx *ctx) | |
2037 | { | |
2038 | DPLANE_CTX_VALID(ctx); | |
2039 | ||
2040 | return ctx->u.rule.old.ip_proto; | |
2041 | } | |
2042 | ||
01f23aff WC |
2043 | uint8_t dplane_ctx_rule_get_dsfield(const struct zebra_dplane_ctx *ctx) |
2044 | { | |
2045 | DPLANE_CTX_VALID(ctx); | |
2046 | ||
2047 | return ctx->u.rule.new.dsfield; | |
2048 | } | |
2049 | ||
2050 | uint8_t dplane_ctx_rule_get_old_dsfield(const struct zebra_dplane_ctx *ctx) | |
2051 | { | |
2052 | DPLANE_CTX_VALID(ctx); | |
2053 | ||
2054 | return ctx->u.rule.old.dsfield; | |
2055 | } | |
2056 | ||
60d8d43b JU |
2057 | const struct prefix * |
2058 | dplane_ctx_rule_get_src_ip(const struct zebra_dplane_ctx *ctx) | |
2059 | { | |
2060 | DPLANE_CTX_VALID(ctx); | |
2061 | ||
2062 | return &(ctx->u.rule.new.src_ip); | |
2063 | } | |
2064 | ||
2065 | const struct prefix * | |
2066 | dplane_ctx_rule_get_old_src_ip(const struct zebra_dplane_ctx *ctx) | |
2067 | { | |
2068 | DPLANE_CTX_VALID(ctx); | |
2069 | ||
2070 | return &(ctx->u.rule.old.src_ip); | |
2071 | } | |
2072 | ||
2073 | const struct prefix * | |
2074 | dplane_ctx_rule_get_dst_ip(const struct zebra_dplane_ctx *ctx) | |
2075 | { | |
2076 | DPLANE_CTX_VALID(ctx); | |
2077 | ||
2078 | return &(ctx->u.rule.new.dst_ip); | |
2079 | } | |
2080 | ||
2081 | const struct prefix * | |
2082 | dplane_ctx_rule_get_old_dst_ip(const struct zebra_dplane_ctx *ctx) | |
2083 | { | |
2084 | DPLANE_CTX_VALID(ctx); | |
2085 | ||
2086 | return &(ctx->u.rule.old.dst_ip); | |
2087 | } | |
2088 | ||
c60522f7 AK |
2089 | uint32_t dplane_ctx_get_br_port_flags(const struct zebra_dplane_ctx *ctx) |
2090 | { | |
2091 | DPLANE_CTX_VALID(ctx); | |
2092 | ||
2093 | return ctx->u.br_port.flags; | |
2094 | } | |
2095 | ||
2096 | uint32_t | |
2097 | dplane_ctx_get_br_port_sph_filter_cnt(const struct zebra_dplane_ctx *ctx) | |
2098 | { | |
2099 | DPLANE_CTX_VALID(ctx); | |
2100 | ||
2101 | return ctx->u.br_port.sph_filter_cnt; | |
2102 | } | |
2103 | ||
2104 | const struct in_addr * | |
2105 | dplane_ctx_get_br_port_sph_filters(const struct zebra_dplane_ctx *ctx) | |
2106 | { | |
2107 | DPLANE_CTX_VALID(ctx); | |
2108 | ||
2109 | return ctx->u.br_port.sph_filters; | |
2110 | } | |
2111 | ||
2112 | uint32_t | |
2113 | dplane_ctx_get_br_port_backup_nhg_id(const struct zebra_dplane_ctx *ctx) | |
2114 | { | |
2115 | DPLANE_CTX_VALID(ctx); | |
2116 | ||
2117 | return ctx->u.br_port.backup_nhg_id; | |
2118 | } | |
2119 | ||
5162e000 PG |
2120 | /* Accessors for PBR iptable information */ |
2121 | bool | |
2122 | dplane_ctx_get_pbr_iptable(const struct zebra_dplane_ctx *ctx, | |
2123 | struct zebra_pbr_iptable *table) | |
2124 | { | |
2125 | DPLANE_CTX_VALID(ctx); | |
2126 | ||
2127 | memcpy(table, &ctx->u.iptable, sizeof(struct zebra_pbr_iptable)); | |
2128 | return true; | |
2129 | } | |
2130 | ||
ef524230 PG |
2131 | bool dplane_ctx_get_pbr_ipset(const struct zebra_dplane_ctx *ctx, |
2132 | struct zebra_pbr_ipset *ipset) | |
2133 | { | |
2134 | DPLANE_CTX_VALID(ctx); | |
2135 | ||
2136 | if (!ipset) | |
2137 | return false; | |
2138 | if (ctx->zd_op == DPLANE_OP_IPSET_ENTRY_ADD || | |
2139 | ctx->zd_op == DPLANE_OP_IPSET_ENTRY_DELETE) { | |
2140 | memset(ipset, 0, sizeof(struct zebra_pbr_ipset)); | |
2141 | ipset->type = ctx->u.ipset_entry.info.type; | |
2142 | memcpy(&ipset->ipset_name, &ctx->u.ipset_entry.info.ipset_name, | |
2143 | ZEBRA_IPSET_NAME_SIZE); | |
2144 | } else | |
2145 | memcpy(ipset, &ctx->u.ipset, sizeof(struct zebra_pbr_ipset)); | |
2146 | return true; | |
2147 | } | |
2148 | ||
2149 | bool dplane_ctx_get_pbr_ipset_entry(const struct zebra_dplane_ctx *ctx, | |
2150 | struct zebra_pbr_ipset_entry *entry) | |
2151 | { | |
2152 | DPLANE_CTX_VALID(ctx); | |
2153 | ||
2154 | if (!entry) | |
2155 | return false; | |
2156 | memcpy(entry, &ctx->u.ipset_entry.entry, sizeof(struct zebra_pbr_ipset_entry)); | |
2157 | return true; | |
2158 | } | |
2159 | ||
7cdb1a84 MS |
2160 | /* |
2161 | * End of dplane context accessors | |
2162 | */ | |
2163 | ||
5917df09 MS |
2164 | /* Optional extra info about interfaces in nexthops - a plugin must enable |
2165 | * this extra info. | |
2166 | */ | |
2167 | const struct dplane_intf_extra * | |
2168 | dplane_ctx_get_intf_extra(const struct zebra_dplane_ctx *ctx) | |
2169 | { | |
2170 | return TAILQ_FIRST(&ctx->u.rinfo.intf_extra_q); | |
2171 | } | |
2172 | ||
2173 | const struct dplane_intf_extra * | |
2174 | dplane_ctx_intf_extra_next(const struct zebra_dplane_ctx *ctx, | |
2175 | const struct dplane_intf_extra *ptr) | |
2176 | { | |
2177 | return TAILQ_NEXT(ptr, link); | |
2178 | } | |
2179 | ||
2180 | vrf_id_t dplane_intf_extra_get_vrfid(const struct dplane_intf_extra *ptr) | |
2181 | { | |
2182 | return ptr->vrf_id; | |
2183 | } | |
2184 | ||
2185 | uint32_t dplane_intf_extra_get_ifindex(const struct dplane_intf_extra *ptr) | |
2186 | { | |
2187 | return ptr->ifindex; | |
2188 | } | |
2189 | ||
2190 | uint32_t dplane_intf_extra_get_flags(const struct dplane_intf_extra *ptr) | |
2191 | { | |
2192 | return ptr->flags; | |
2193 | } | |
2194 | ||
2195 | uint32_t dplane_intf_extra_get_status(const struct dplane_intf_extra *ptr) | |
2196 | { | |
2197 | return ptr->status; | |
2198 | } | |
2199 | ||
e18747a9 PG |
2200 | uint8_t dplane_ctx_neightable_get_family(const struct zebra_dplane_ctx *ctx) |
2201 | { | |
2202 | DPLANE_CTX_VALID(ctx); | |
2203 | ||
2204 | return ctx->u.neightable.family; | |
2205 | } | |
2206 | ||
2207 | uint32_t | |
2208 | dplane_ctx_neightable_get_app_probes(const struct zebra_dplane_ctx *ctx) | |
2209 | { | |
2210 | DPLANE_CTX_VALID(ctx); | |
2211 | ||
2212 | return ctx->u.neightable.app_probes; | |
2213 | } | |
2214 | ||
2215 | uint32_t | |
2216 | dplane_ctx_neightable_get_ucast_probes(const struct zebra_dplane_ctx *ctx) | |
2217 | { | |
2218 | DPLANE_CTX_VALID(ctx); | |
2219 | ||
2220 | return ctx->u.neightable.ucast_probes; | |
2221 | } | |
2222 | ||
2223 | uint32_t | |
2224 | dplane_ctx_neightable_get_mcast_probes(const struct zebra_dplane_ctx *ctx) | |
2225 | { | |
2226 | DPLANE_CTX_VALID(ctx); | |
2227 | ||
2228 | return ctx->u.neightable.mcast_probes; | |
2229 | } | |
2230 | ||
5917df09 MS |
2231 | /* |
2232 | * End of interface extra info accessors | |
2233 | */ | |
c831033f | 2234 | |
91f16812 MS |
2235 | /* |
2236 | * Retrieve the limit on the number of pending, unprocessed updates. | |
2237 | */ | |
2238 | uint32_t dplane_get_in_queue_limit(void) | |
2239 | { | |
2240 | return atomic_load_explicit(&zdplane_info.dg_max_queued_updates, | |
2241 | memory_order_relaxed); | |
2242 | } | |
2243 | ||
2244 | /* | |
2245 | * Configure limit on the number of pending, queued updates. | |
2246 | */ | |
2247 | void dplane_set_in_queue_limit(uint32_t limit, bool set) | |
2248 | { | |
2249 | /* Reset to default on 'unset' */ | |
2250 | if (!set) | |
2251 | limit = DPLANE_DEFAULT_MAX_QUEUED; | |
2252 | ||
2253 | atomic_store_explicit(&zdplane_info.dg_max_queued_updates, limit, | |
2254 | memory_order_relaxed); | |
2255 | } | |
2256 | ||
2257 | /* | |
2258 | * Retrieve the current queue depth of incoming, unprocessed updates | |
2259 | */ | |
2260 | uint32_t dplane_get_in_queue_len(void) | |
2261 | { | |
2262 | return atomic_load_explicit(&zdplane_info.dg_routes_queued, | |
2263 | memory_order_seq_cst); | |
2264 | } | |
2265 | ||
16c628de MS |
2266 | /* |
2267 | * Common dataplane context init with zebra namespace info. | |
2268 | */ | |
2269 | static int dplane_ctx_ns_init(struct zebra_dplane_ctx *ctx, | |
2270 | struct zebra_ns *zns, | |
2271 | bool is_update) | |
2272 | { | |
2273 | dplane_info_from_zns(&(ctx->zd_ns_info), zns); | |
2274 | ||
2275 | #if defined(HAVE_NETLINK) | |
2276 | /* Increment message counter after copying to context struct - may need | |
2277 | * two messages in some 'update' cases. | |
2278 | */ | |
2279 | if (is_update) | |
80dcc388 | 2280 | zns->netlink_dplane_out.seq += 2; |
16c628de | 2281 | else |
80dcc388 | 2282 | zns->netlink_dplane_out.seq++; |
16c628de MS |
2283 | #endif /* HAVE_NETLINK */ |
2284 | ||
2285 | return AOK; | |
2286 | } | |
2287 | ||
7cdb1a84 MS |
2288 | /* |
2289 | * Initialize a context block for a route update from zebra data structs. | |
2290 | */ | |
018e77bc RZ |
2291 | int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op, |
2292 | struct route_node *rn, struct route_entry *re) | |
7cdb1a84 MS |
2293 | { |
2294 | int ret = EINVAL; | |
2295 | const struct route_table *table = NULL; | |
630d5962 | 2296 | const struct rib_table_info *info; |
7cdb1a84 MS |
2297 | const struct prefix *p, *src_p; |
2298 | struct zebra_ns *zns; | |
2299 | struct zebra_vrf *zvrf; | |
f183e380 | 2300 | struct nexthop *nexthop; |
05843a27 | 2301 | struct zebra_l3vni *zl3vni; |
5917df09 MS |
2302 | const struct interface *ifp; |
2303 | struct dplane_intf_extra *if_extra; | |
7cdb1a84 | 2304 | |
5709131c | 2305 | if (!ctx || !rn || !re) |
7cdb1a84 | 2306 | goto done; |
7cdb1a84 | 2307 | |
5917df09 MS |
2308 | TAILQ_INIT(&ctx->u.rinfo.intf_extra_q); |
2309 | ||
7cdb1a84 | 2310 | ctx->zd_op = op; |
14b0bc8e | 2311 | ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; |
7cdb1a84 | 2312 | |
0f461727 MS |
2313 | ctx->u.rinfo.zd_type = re->type; |
2314 | ctx->u.rinfo.zd_old_type = re->type; | |
7cdb1a84 MS |
2315 | |
2316 | /* Prefixes: dest, and optional source */ | |
2317 | srcdest_rnode_prefixes(rn, &p, &src_p); | |
2318 | ||
0f461727 | 2319 | prefix_copy(&(ctx->u.rinfo.zd_dest), p); |
7cdb1a84 | 2320 | |
5709131c | 2321 | if (src_p) |
0f461727 | 2322 | prefix_copy(&(ctx->u.rinfo.zd_src), src_p); |
5709131c | 2323 | else |
0f461727 | 2324 | memset(&(ctx->u.rinfo.zd_src), 0, sizeof(ctx->u.rinfo.zd_src)); |
7cdb1a84 MS |
2325 | |
2326 | ctx->zd_table_id = re->table; | |
2327 | ||
0f461727 MS |
2328 | ctx->u.rinfo.zd_metric = re->metric; |
2329 | ctx->u.rinfo.zd_old_metric = re->metric; | |
7cdb1a84 | 2330 | ctx->zd_vrf_id = re->vrf_id; |
0f461727 MS |
2331 | ctx->u.rinfo.zd_mtu = re->mtu; |
2332 | ctx->u.rinfo.zd_nexthop_mtu = re->nexthop_mtu; | |
2333 | ctx->u.rinfo.zd_instance = re->instance; | |
2334 | ctx->u.rinfo.zd_tag = re->tag; | |
2335 | ctx->u.rinfo.zd_old_tag = re->tag; | |
2336 | ctx->u.rinfo.zd_distance = re->distance; | |
7cdb1a84 MS |
2337 | |
2338 | table = srcdest_rnode_table(rn); | |
2339 | info = table->info; | |
2340 | ||
0f461727 MS |
2341 | ctx->u.rinfo.zd_afi = info->afi; |
2342 | ctx->u.rinfo.zd_safi = info->safi; | |
7cdb1a84 | 2343 | |
7cdb1a84 | 2344 | /* Copy nexthops; recursive info is included too */ |
0eb97b86 | 2345 | copy_nexthops(&(ctx->u.rinfo.zd_ng.nexthop), |
c415d895 | 2346 | re->nhe->nhg.nexthop, NULL); |
1d48702e MS |
2347 | ctx->u.rinfo.zd_nhg_id = re->nhe->id; |
2348 | ||
2349 | /* Copy backup nexthop info, if present */ | |
2350 | if (re->nhe->backup_info && re->nhe->backup_info->nhe) { | |
2351 | copy_nexthops(&(ctx->u.rinfo.backup_ng.nexthop), | |
2352 | re->nhe->backup_info->nhe->nhg.nexthop, NULL); | |
2353 | } | |
7cdb1a84 | 2354 | |
f2a0ba3a RZ |
2355 | /* |
2356 | * Ensure that the dplane nexthops' flags are clear and copy | |
2357 | * encapsulation information. | |
2358 | */ | |
2359 | for (ALL_NEXTHOPS(ctx->u.rinfo.zd_ng, nexthop)) { | |
f183e380 | 2360 | UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); |
f183e380 | 2361 | |
5917df09 MS |
2362 | /* Optionally capture extra interface info while we're in the |
2363 | * main zebra pthread - a plugin has to ask for this info. | |
2364 | */ | |
2365 | if (dplane_collect_extra_intf_info) { | |
2366 | ifp = if_lookup_by_index(nexthop->ifindex, | |
2367 | nexthop->vrf_id); | |
2368 | ||
2369 | if (ifp) { | |
2370 | if_extra = XCALLOC( | |
2371 | MTYPE_DP_INTF, | |
2372 | sizeof(struct dplane_intf_extra)); | |
2373 | if_extra->vrf_id = nexthop->vrf_id; | |
2374 | if_extra->ifindex = nexthop->ifindex; | |
2375 | if_extra->flags = ifp->flags; | |
2376 | if_extra->status = ifp->status; | |
2377 | ||
2378 | TAILQ_INSERT_TAIL(&ctx->u.rinfo.intf_extra_q, | |
2379 | if_extra, link); | |
2380 | } | |
2381 | } | |
b364e87d MS |
2382 | |
2383 | /* Check for available evpn encapsulations. */ | |
2384 | if (!CHECK_FLAG(re->flags, ZEBRA_FLAG_EVPN_ROUTE)) | |
2385 | continue; | |
2386 | ||
2387 | zl3vni = zl3vni_from_vrf(nexthop->vrf_id); | |
2388 | if (zl3vni && is_l3vni_oper_up(zl3vni)) { | |
2389 | nexthop->nh_encap_type = NET_VXLAN; | |
2390 | nexthop->nh_encap.vni = zl3vni->vni; | |
2391 | } | |
f2a0ba3a RZ |
2392 | } |
2393 | ||
cf363e1b MS |
2394 | /* Don't need some info when capturing a system notification */ |
2395 | if (op == DPLANE_OP_SYS_ROUTE_ADD || | |
2396 | op == DPLANE_OP_SYS_ROUTE_DELETE) { | |
2397 | ret = AOK; | |
2398 | goto done; | |
2399 | } | |
2400 | ||
2401 | /* Extract ns info - can't use pointers to 'core' structs */ | |
2402 | zvrf = vrf_info_lookup(re->vrf_id); | |
2403 | zns = zvrf->zns; | |
2404 | dplane_ctx_ns_init(ctx, zns, (op == DPLANE_OP_ROUTE_UPDATE)); | |
2405 | ||
6df59152 | 2406 | #ifdef HAVE_NETLINK |
f924db49 | 2407 | { |
1d48702e | 2408 | struct nhg_hash_entry *nhe = zebra_nhg_resolve(re->nhe); |
6df59152 | 2409 | |
ae9bfa06 | 2410 | ctx->u.rinfo.nhe.id = nhe->id; |
df3cef24 | 2411 | ctx->u.rinfo.nhe.old_id = 0; |
6df59152 | 2412 | /* |
ae9bfa06 SW |
2413 | * Check if the nhe is installed/queued before doing anything |
2414 | * with this route. | |
08c51a38 SW |
2415 | * |
2416 | * If its a delete we only use the prefix anyway, so this only | |
2417 | * matters for INSTALL/UPDATE. | |
6df59152 | 2418 | */ |
1a39fdc2 DS |
2419 | if (zebra_nhg_kernel_nexthops_enabled() |
2420 | && (((op == DPLANE_OP_ROUTE_INSTALL) | |
2421 | || (op == DPLANE_OP_ROUTE_UPDATE)) | |
2422 | && !CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED) | |
2423 | && !CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_QUEUED))) { | |
6df59152 SW |
2424 | ret = ENOENT; |
2425 | goto done; | |
2426 | } | |
98cda54a | 2427 | } |
6df59152 | 2428 | #endif /* HAVE_NETLINK */ |
de3f5488 | 2429 | |
7cdb1a84 MS |
2430 | /* Trying out the sequence number idea, so we can try to detect |
2431 | * when a result is stale. | |
2432 | */ | |
1485bbe7 | 2433 | re->dplane_sequence = zebra_router_get_next_sequence(); |
7cdb1a84 MS |
2434 | ctx->zd_seq = re->dplane_sequence; |
2435 | ||
2436 | ret = AOK; | |
2437 | ||
2438 | done: | |
2439 | return ret; | |
2440 | } | |
2441 | ||
f820d025 SW |
2442 | /** |
2443 | * dplane_ctx_nexthop_init() - Initialize a context block for a nexthop update | |
2444 | * | |
2445 | * @ctx: Dataplane context to init | |
2446 | * @op: Operation being performed | |
2447 | * @nhe: Nexthop group hash entry | |
2448 | * | |
2449 | * Return: Result status | |
2450 | */ | |
a2072e71 | 2451 | int dplane_ctx_nexthop_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op, |
981ca597 | 2452 | struct nhg_hash_entry *nhe) |
f820d025 | 2453 | { |
a7df21c4 | 2454 | struct zebra_vrf *zvrf = NULL; |
8e401b25 | 2455 | struct zebra_ns *zns = NULL; |
f820d025 SW |
2456 | int ret = EINVAL; |
2457 | ||
2458 | if (!ctx || !nhe) | |
2459 | goto done; | |
2460 | ||
2461 | ctx->zd_op = op; | |
2462 | ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; | |
2463 | ||
2464 | /* Copy over nhe info */ | |
0c8215cb SW |
2465 | ctx->u.rinfo.nhe.id = nhe->id; |
2466 | ctx->u.rinfo.nhe.afi = nhe->afi; | |
2467 | ctx->u.rinfo.nhe.vrf_id = nhe->vrf_id; | |
38e40db1 | 2468 | ctx->u.rinfo.nhe.type = nhe->type; |
0c8215cb | 2469 | |
c415d895 | 2470 | nexthop_group_copy(&(ctx->u.rinfo.nhe.ng), &(nhe->nhg)); |
0c8215cb | 2471 | |
c415d895 | 2472 | /* If this is a group, convert it to a grp array of ids */ |
98cda54a SW |
2473 | if (!zebra_nhg_depends_is_empty(nhe) |
2474 | && !CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_RECURSIVE)) | |
8dbc800f SW |
2475 | ctx->u.rinfo.nhe.nh_grp_count = zebra_nhg_nhe2grp( |
2476 | ctx->u.rinfo.nhe.nh_grp, nhe, MULTIPATH_NUM); | |
f820d025 | 2477 | |
a7df21c4 SW |
2478 | zvrf = vrf_info_lookup(nhe->vrf_id); |
2479 | ||
2480 | /* | |
2481 | * Fallback to default namespace if the vrf got ripped out from under | |
2482 | * us. | |
2483 | */ | |
2484 | zns = zvrf ? zvrf->zns : zebra_ns_lookup(NS_DEFAULT); | |
1909e63a | 2485 | |
2d3c57e6 SW |
2486 | /* |
2487 | * TODO: Might not need to mark this as an update, since | |
2488 | * it probably won't require two messages | |
2489 | */ | |
1909e63a | 2490 | dplane_ctx_ns_init(ctx, zns, (op == DPLANE_OP_NH_UPDATE)); |
f6feb48b | 2491 | ctx->zd_is_update = (op == DPLANE_OP_NH_UPDATE); |
1909e63a | 2492 | |
f820d025 SW |
2493 | ret = AOK; |
2494 | ||
2495 | done: | |
2496 | return ret; | |
2497 | } | |
2498 | ||
16c628de MS |
2499 | /* |
2500 | * Capture information for an LSP update in a dplane context. | |
2501 | */ | |
65f264cf | 2502 | int dplane_ctx_lsp_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op, |
8f74a383 | 2503 | struct zebra_lsp *lsp) |
16c628de MS |
2504 | { |
2505 | int ret = AOK; | |
f2595bd5 | 2506 | struct zebra_nhlfe *nhlfe, *new_nhlfe; |
16c628de | 2507 | |
16c628de MS |
2508 | ctx->zd_op = op; |
2509 | ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; | |
2510 | ||
2511 | /* Capture namespace info */ | |
2512 | dplane_ctx_ns_init(ctx, zebra_ns_lookup(NS_DEFAULT), | |
2513 | (op == DPLANE_OP_LSP_UPDATE)); | |
f6feb48b | 2514 | ctx->zd_is_update = (op == DPLANE_OP_LSP_UPDATE); |
16c628de MS |
2515 | |
2516 | memset(&ctx->u.lsp, 0, sizeof(ctx->u.lsp)); | |
2517 | ||
ee70f629 | 2518 | nhlfe_list_init(&(ctx->u.lsp.nhlfe_list)); |
cd4bb96f | 2519 | nhlfe_list_init(&(ctx->u.lsp.backup_nhlfe_list)); |
65f264cf MS |
2520 | |
2521 | /* This may be called to create/init a dplane context, not necessarily | |
2522 | * to copy an lsp object. | |
2523 | */ | |
2524 | if (lsp == NULL) { | |
2525 | ret = AOK; | |
2526 | goto done; | |
2527 | } | |
2528 | ||
2529 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) | |
2530 | zlog_debug("init dplane ctx %s: in-label %u ecmp# %d", | |
2531 | dplane_op2str(op), lsp->ile.in_label, | |
2532 | lsp->num_ecmp); | |
2533 | ||
16c628de MS |
2534 | ctx->u.lsp.ile = lsp->ile; |
2535 | ctx->u.lsp.addr_family = lsp->addr_family; | |
2536 | ctx->u.lsp.num_ecmp = lsp->num_ecmp; | |
2537 | ctx->u.lsp.flags = lsp->flags; | |
2538 | ||
2539 | /* Copy source LSP's nhlfes, and capture 'best' nhlfe */ | |
ee70f629 | 2540 | frr_each(nhlfe_list, &lsp->nhlfe_list, nhlfe) { |
16c628de MS |
2541 | /* Not sure if this is meaningful... */ |
2542 | if (nhlfe->nexthop == NULL) | |
2543 | continue; | |
2544 | ||
cd4bb96f MS |
2545 | new_nhlfe = zebra_mpls_lsp_add_nh(&(ctx->u.lsp), nhlfe->type, |
2546 | nhlfe->nexthop); | |
16c628de MS |
2547 | if (new_nhlfe == NULL || new_nhlfe->nexthop == NULL) { |
2548 | ret = ENOMEM; | |
2549 | break; | |
2550 | } | |
2551 | ||
3c0e1622 | 2552 | /* Need to copy flags and backup info too */ |
16c628de MS |
2553 | new_nhlfe->flags = nhlfe->flags; |
2554 | new_nhlfe->nexthop->flags = nhlfe->nexthop->flags; | |
2555 | ||
3c0e1622 MS |
2556 | if (CHECK_FLAG(new_nhlfe->nexthop->flags, |
2557 | NEXTHOP_FLAG_HAS_BACKUP)) { | |
2558 | new_nhlfe->nexthop->backup_num = | |
2559 | nhlfe->nexthop->backup_num; | |
2560 | memcpy(new_nhlfe->nexthop->backup_idx, | |
2561 | nhlfe->nexthop->backup_idx, | |
2562 | new_nhlfe->nexthop->backup_num); | |
2563 | } | |
2564 | ||
16c628de MS |
2565 | if (nhlfe == lsp->best_nhlfe) |
2566 | ctx->u.lsp.best_nhlfe = new_nhlfe; | |
2567 | } | |
2568 | ||
cd4bb96f MS |
2569 | if (ret != AOK) |
2570 | goto done; | |
2571 | ||
2572 | /* Capture backup nhlfes/nexthops */ | |
2573 | frr_each(nhlfe_list, &lsp->backup_nhlfe_list, nhlfe) { | |
2574 | /* Not sure if this is meaningful... */ | |
2575 | if (nhlfe->nexthop == NULL) | |
2576 | continue; | |
2577 | ||
2578 | new_nhlfe = zebra_mpls_lsp_add_backup_nh(&(ctx->u.lsp), | |
2579 | nhlfe->type, | |
2580 | nhlfe->nexthop); | |
2581 | if (new_nhlfe == NULL || new_nhlfe->nexthop == NULL) { | |
2582 | ret = ENOMEM; | |
2583 | break; | |
2584 | } | |
2585 | ||
2586 | /* Need to copy flags too */ | |
2587 | new_nhlfe->flags = nhlfe->flags; | |
2588 | new_nhlfe->nexthop->flags = nhlfe->nexthop->flags; | |
2589 | } | |
2590 | ||
16c628de MS |
2591 | /* On error the ctx will be cleaned-up, so we don't need to |
2592 | * deal with any allocated nhlfe or nexthop structs here. | |
2593 | */ | |
cd4bb96f | 2594 | done: |
16c628de MS |
2595 | |
2596 | return ret; | |
2597 | } | |
2598 | ||
97d8d05a MS |
2599 | /* |
2600 | * Capture information for an LSP update in a dplane context. | |
2601 | */ | |
2602 | static int dplane_ctx_pw_init(struct zebra_dplane_ctx *ctx, | |
2603 | enum dplane_op_e op, | |
2604 | struct zebra_pw *pw) | |
2605 | { | |
072b487b | 2606 | int ret = EINVAL; |
09cd307c MS |
2607 | struct prefix p; |
2608 | afi_t afi; | |
2609 | struct route_table *table; | |
2610 | struct route_node *rn; | |
2611 | struct route_entry *re; | |
0024ea8e | 2612 | const struct nexthop_group *nhg; |
072b487b | 2613 | struct nexthop *nh, *newnh, *last_nh; |
09cd307c | 2614 | |
97d8d05a MS |
2615 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) |
2616 | zlog_debug("init dplane ctx %s: pw '%s', loc %u, rem %u", | |
2617 | dplane_op2str(op), pw->ifname, pw->local_label, | |
2618 | pw->remote_label); | |
2619 | ||
2620 | ctx->zd_op = op; | |
2621 | ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; | |
2622 | ||
2623 | /* Capture namespace info: no netlink support as of 12/18, | |
2624 | * but just in case... | |
2625 | */ | |
2626 | dplane_ctx_ns_init(ctx, zebra_ns_lookup(NS_DEFAULT), false); | |
2627 | ||
2628 | memset(&ctx->u.pw, 0, sizeof(ctx->u.pw)); | |
2629 | ||
2630 | /* This name appears to be c-string, so we use string copy. */ | |
7c7ef4a8 | 2631 | strlcpy(ctx->zd_ifname, pw->ifname, sizeof(ctx->zd_ifname)); |
16d69787 | 2632 | |
9bd9717b | 2633 | ctx->zd_vrf_id = pw->vrf_id; |
7c7ef4a8 | 2634 | ctx->zd_ifindex = pw->ifindex; |
97d8d05a MS |
2635 | ctx->u.pw.type = pw->type; |
2636 | ctx->u.pw.af = pw->af; | |
2637 | ctx->u.pw.local_label = pw->local_label; | |
2638 | ctx->u.pw.remote_label = pw->remote_label; | |
2639 | ctx->u.pw.flags = pw->flags; | |
2640 | ||
16d69787 | 2641 | ctx->u.pw.dest = pw->nexthop; |
97d8d05a MS |
2642 | |
2643 | ctx->u.pw.fields = pw->data; | |
2644 | ||
09cd307c MS |
2645 | /* Capture nexthop info for the pw destination. We need to look |
2646 | * up and use zebra datastructs, but we're running in the zebra | |
2647 | * pthread here so that should be ok. | |
2648 | */ | |
2649 | memcpy(&p.u, &pw->nexthop, sizeof(pw->nexthop)); | |
2650 | p.family = pw->af; | |
936fbaef | 2651 | p.prefixlen = ((pw->af == AF_INET) ? IPV4_MAX_BITLEN : IPV6_MAX_BITLEN); |
09cd307c MS |
2652 | |
2653 | afi = (pw->af == AF_INET) ? AFI_IP : AFI_IP6; | |
2654 | table = zebra_vrf_table(afi, SAFI_UNICAST, pw->vrf_id); | |
072b487b MS |
2655 | if (table == NULL) |
2656 | goto done; | |
2657 | ||
2658 | rn = route_node_match(table, &p); | |
2659 | if (rn == NULL) | |
2660 | goto done; | |
2661 | ||
2662 | re = NULL; | |
2663 | RNODE_FOREACH_RE(rn, re) { | |
2664 | if (CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED)) | |
2665 | break; | |
2666 | } | |
2667 | ||
2668 | if (re) { | |
2669 | /* We'll capture a 'fib' list of nexthops that meet our | |
2670 | * criteria: installed, and labelled. | |
2671 | */ | |
2672 | nhg = rib_get_fib_nhg(re); | |
2673 | last_nh = NULL; | |
2674 | ||
2675 | if (nhg && nhg->nexthop) { | |
2676 | for (ALL_NEXTHOPS_PTR(nhg, nh)) { | |
2677 | if (!CHECK_FLAG(nh->flags, NEXTHOP_FLAG_ACTIVE) | |
2678 | || CHECK_FLAG(nh->flags, | |
2679 | NEXTHOP_FLAG_RECURSIVE) | |
2680 | || nh->nh_label == NULL) | |
2681 | continue; | |
2682 | ||
2683 | newnh = nexthop_dup(nh, NULL); | |
2684 | ||
2685 | if (last_nh) | |
2686 | NEXTHOP_APPEND(last_nh, newnh); | |
2687 | else | |
2688 | ctx->u.pw.fib_nhg.nexthop = newnh; | |
2689 | last_nh = newnh; | |
09cd307c | 2690 | } |
072b487b | 2691 | } |
09cd307c | 2692 | |
072b487b MS |
2693 | /* Include any installed backup nexthops also. */ |
2694 | nhg = rib_get_fib_backup_nhg(re); | |
2695 | if (nhg && nhg->nexthop) { | |
2696 | for (ALL_NEXTHOPS_PTR(nhg, nh)) { | |
2697 | if (!CHECK_FLAG(nh->flags, NEXTHOP_FLAG_ACTIVE) | |
2698 | || CHECK_FLAG(nh->flags, | |
2699 | NEXTHOP_FLAG_RECURSIVE) | |
2700 | || nh->nh_label == NULL) | |
2701 | continue; | |
2702 | ||
2703 | newnh = nexthop_dup(nh, NULL); | |
2704 | ||
2705 | if (last_nh) | |
2706 | NEXTHOP_APPEND(last_nh, newnh); | |
2707 | else | |
2708 | ctx->u.pw.fib_nhg.nexthop = newnh; | |
2709 | last_nh = newnh; | |
0024ea8e | 2710 | } |
072b487b MS |
2711 | } |
2712 | ||
2713 | /* Copy primary nexthops; recursive info is included too */ | |
2714 | assert(re->nhe != NULL); /* SA warning */ | |
2715 | copy_nexthops(&(ctx->u.pw.primary_nhg.nexthop), | |
2716 | re->nhe->nhg.nexthop, NULL); | |
2717 | ctx->u.pw.nhg_id = re->nhe->id; | |
2718 | ||
2719 | /* Copy backup nexthop info, if present */ | |
2720 | if (re->nhe->backup_info && re->nhe->backup_info->nhe) { | |
2721 | copy_nexthops(&(ctx->u.pw.backup_nhg.nexthop), | |
2722 | re->nhe->backup_info->nhe->nhg.nexthop, | |
2723 | NULL); | |
09cd307c MS |
2724 | } |
2725 | } | |
072b487b | 2726 | route_unlock_node(rn); |
09cd307c | 2727 | |
072b487b MS |
2728 | ret = AOK; |
2729 | ||
2730 | done: | |
2731 | return ret; | |
97d8d05a MS |
2732 | } |
2733 | ||
f62e5480 JU |
2734 | /** |
2735 | * dplane_ctx_rule_init_single() - Initialize a dataplane representation of a | |
2736 | * PBR rule. | |
2737 | * | |
2738 | * @dplane_rule: Dataplane internal representation of a rule | |
2739 | * @rule: PBR rule | |
2740 | */ | |
2741 | static void dplane_ctx_rule_init_single(struct dplane_ctx_rule *dplane_rule, | |
2742 | struct zebra_pbr_rule *rule) | |
2743 | { | |
2744 | dplane_rule->priority = rule->rule.priority; | |
2745 | dplane_rule->table = rule->rule.action.table; | |
2746 | ||
2747 | dplane_rule->filter_bm = rule->rule.filter.filter_bm; | |
2748 | dplane_rule->fwmark = rule->rule.filter.fwmark; | |
01f23aff | 2749 | dplane_rule->dsfield = rule->rule.filter.dsfield; |
8ccbc778 | 2750 | dplane_rule->ip_proto = rule->rule.filter.ip_proto; |
f62e5480 JU |
2751 | prefix_copy(&(dplane_rule->dst_ip), &rule->rule.filter.dst_ip); |
2752 | prefix_copy(&(dplane_rule->src_ip), &rule->rule.filter.src_ip); | |
58a1d249 | 2753 | strlcpy(dplane_rule->ifname, rule->ifname, INTERFACE_NAMSIZ); |
f62e5480 JU |
2754 | } |
2755 | ||
2756 | /** | |
2757 | * dplane_ctx_rule_init() - Initialize a context block for a PBR rule update. | |
2758 | * | |
2759 | * @ctx: Dataplane context to init | |
2760 | * @op: Operation being performed | |
2761 | * @new_rule: PBR rule | |
2762 | * | |
2763 | * Return: Result status | |
2764 | */ | |
2765 | static int dplane_ctx_rule_init(struct zebra_dplane_ctx *ctx, | |
2766 | enum dplane_op_e op, | |
2767 | struct zebra_pbr_rule *new_rule, | |
2768 | struct zebra_pbr_rule *old_rule) | |
2769 | { | |
2dbe669b | 2770 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) |
f62e5480 | 2771 | zlog_debug( |
2dbe669b | 2772 | "init dplane ctx %s: IF %s Prio %u Fwmark %u Src %pFX Dst %pFX Table %u", |
f62e5480 | 2773 | dplane_op2str(op), new_rule->ifname, |
58a1d249 | 2774 | new_rule->rule.priority, new_rule->rule.filter.fwmark, |
2dbe669b DA |
2775 | &new_rule->rule.filter.src_ip, |
2776 | &new_rule->rule.filter.dst_ip, | |
f62e5480 | 2777 | new_rule->rule.action.table); |
f62e5480 JU |
2778 | |
2779 | ctx->zd_op = op; | |
2780 | ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; | |
2781 | ||
2782 | dplane_ctx_ns_init(ctx, zebra_ns_lookup(NS_DEFAULT), | |
2783 | op == DPLANE_OP_RULE_UPDATE); | |
f6feb48b | 2784 | ctx->zd_is_update = (op == DPLANE_OP_RULE_UPDATE); |
f62e5480 JU |
2785 | |
2786 | ctx->zd_vrf_id = new_rule->vrf_id; | |
bc86b347 | 2787 | strlcpy(ctx->zd_ifname, new_rule->ifname, sizeof(ctx->zd_ifname)); |
f62e5480 JU |
2788 | |
2789 | ctx->u.rule.sock = new_rule->sock; | |
2790 | ctx->u.rule.unique = new_rule->rule.unique; | |
2791 | ctx->u.rule.seq = new_rule->rule.seq; | |
2792 | ||
2793 | dplane_ctx_rule_init_single(&ctx->u.rule.new, new_rule); | |
2794 | if (op == DPLANE_OP_RULE_UPDATE) | |
2795 | dplane_ctx_rule_init_single(&ctx->u.rule.old, old_rule); | |
2796 | ||
2797 | return AOK; | |
2798 | } | |
2799 | ||
5162e000 PG |
2800 | /** |
2801 | * dplane_ctx_iptable_init() - Initialize a context block for a PBR iptable | |
2802 | * update. | |
2803 | * | |
2804 | * @ctx: Dataplane context to init | |
2805 | * @op: Operation being performed | |
2806 | * @new_rule: PBR iptable | |
2807 | * | |
2808 | * Return: Result status | |
2809 | */ | |
2810 | static int dplane_ctx_iptable_init(struct zebra_dplane_ctx *ctx, | |
2811 | enum dplane_op_e op, | |
2812 | struct zebra_pbr_iptable *iptable) | |
2813 | { | |
2814 | char *ifname; | |
2815 | struct listnode *node; | |
2816 | ||
2817 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) { | |
2818 | zlog_debug( | |
2819 | "init dplane ctx %s: Unique %u Fwmark %u Family %s Action %s", | |
2820 | dplane_op2str(op), iptable->unique, iptable->fwmark, | |
2821 | family2str(iptable->family), | |
2822 | iptable->action == ZEBRA_IPTABLES_DROP ? "Drop" | |
2823 | : "Forward"); | |
2824 | } | |
2825 | ||
2826 | ctx->zd_op = op; | |
2827 | ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; | |
2828 | ||
2829 | dplane_ctx_ns_init(ctx, zebra_ns_lookup(NS_DEFAULT), false); | |
2830 | ctx->zd_is_update = false; | |
2831 | ||
2832 | ctx->zd_vrf_id = iptable->vrf_id; | |
2833 | memcpy(&ctx->u.iptable, iptable, sizeof(struct zebra_pbr_iptable)); | |
2834 | ctx->u.iptable.interface_name_list = NULL; | |
2835 | if (iptable->nb_interface > 0) { | |
2836 | ctx->u.iptable.interface_name_list = list_new(); | |
2837 | for (ALL_LIST_ELEMENTS_RO(iptable->interface_name_list, node, | |
2838 | ifname)) { | |
2839 | listnode_add(ctx->u.iptable.interface_name_list, | |
ef524230 | 2840 | XSTRDUP(MTYPE_DP_NETFILTER, ifname)); |
5162e000 PG |
2841 | } |
2842 | } | |
2843 | return AOK; | |
2844 | } | |
2845 | ||
ef524230 PG |
2846 | /** |
2847 | * dplane_ctx_ipset_init() - Initialize a context block for a PBR ipset update. | |
2848 | * | |
2849 | * @ctx: Dataplane context to init | |
2850 | * @op: Operation being performed | |
2851 | * @new_rule: PBR ipset | |
2852 | * | |
2853 | * Return: Result status | |
2854 | */ | |
2855 | static int dplane_ctx_ipset_init(struct zebra_dplane_ctx *ctx, | |
2856 | enum dplane_op_e op, | |
2857 | struct zebra_pbr_ipset *ipset) | |
2858 | { | |
2859 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) { | |
2860 | zlog_debug("init dplane ctx %s: %s Unique %u Family %s Type %s", | |
2861 | dplane_op2str(op), ipset->ipset_name, ipset->unique, | |
2862 | family2str(ipset->family), | |
2863 | zebra_pbr_ipset_type2str(ipset->type)); | |
2864 | } | |
2865 | ||
2866 | ctx->zd_op = op; | |
2867 | ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; | |
2868 | ||
2869 | dplane_ctx_ns_init(ctx, zebra_ns_lookup(NS_DEFAULT), false); | |
2870 | ctx->zd_is_update = false; | |
2871 | ||
2872 | ctx->zd_vrf_id = ipset->vrf_id; | |
2873 | ||
2874 | memcpy(&ctx->u.ipset, ipset, sizeof(struct zebra_pbr_ipset)); | |
2875 | return AOK; | |
2876 | } | |
2877 | ||
2878 | /** | |
2879 | * dplane_ctx_ipset_entry_init() - Initialize a context block for a PBR ipset | |
2880 | * update. | |
2881 | * | |
2882 | * @ctx: Dataplane context to init | |
2883 | * @op: Operation being performed | |
2884 | * @new_rule: PBR ipset | |
2885 | * | |
2886 | * Return: Result status | |
2887 | */ | |
2888 | static int | |
2889 | dplane_ctx_ipset_entry_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op, | |
2890 | struct zebra_pbr_ipset_entry *ipset_entry) | |
2891 | { | |
2892 | struct zebra_pbr_ipset *ipset; | |
2893 | ||
2894 | ipset = ipset_entry->backpointer; | |
2895 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) { | |
2896 | zlog_debug("init dplane ctx %s: %s Unique %u filter %u", | |
2897 | dplane_op2str(op), ipset->ipset_name, | |
2898 | ipset_entry->unique, ipset_entry->filter_bm); | |
2899 | } | |
2900 | ||
2901 | ctx->zd_op = op; | |
2902 | ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; | |
2903 | ||
2904 | dplane_ctx_ns_init(ctx, zebra_ns_lookup(NS_DEFAULT), false); | |
2905 | ctx->zd_is_update = false; | |
2906 | ||
2907 | ctx->zd_vrf_id = ipset->vrf_id; | |
2908 | ||
2909 | memcpy(&ctx->u.ipset_entry.entry, ipset_entry, | |
2910 | sizeof(struct zebra_pbr_ipset_entry)); | |
2911 | ctx->u.ipset_entry.entry.backpointer = NULL; | |
2912 | ctx->u.ipset_entry.info.type = ipset->type; | |
2913 | memcpy(&ctx->u.ipset_entry.info.ipset_name, &ipset->ipset_name, | |
2914 | ZEBRA_IPSET_NAME_SIZE); | |
2915 | ||
2916 | return AOK; | |
2917 | } | |
2918 | ||
2919 | ||
7cdb1a84 | 2920 | /* |
3fe4ccc4 | 2921 | * Enqueue a new update, |
16c628de | 2922 | * and ensure an event is active for the dataplane pthread. |
7cdb1a84 | 2923 | */ |
3fe4ccc4 | 2924 | static int dplane_update_enqueue(struct zebra_dplane_ctx *ctx) |
7cdb1a84 MS |
2925 | { |
2926 | int ret = EINVAL; | |
91f16812 | 2927 | uint32_t high, curr; |
7cdb1a84 | 2928 | |
16c628de | 2929 | /* Enqueue for processing by the dataplane pthread */ |
7cdb1a84 MS |
2930 | DPLANE_LOCK(); |
2931 | { | |
3fe4ccc4 | 2932 | TAILQ_INSERT_TAIL(&zdplane_info.dg_update_ctx_q, ctx, |
25779064 | 2933 | zd_q_entries); |
7cdb1a84 MS |
2934 | } |
2935 | DPLANE_UNLOCK(); | |
2936 | ||
e3d9208a | 2937 | curr = atomic_fetch_add_explicit( |
e07e9549 | 2938 | &(zdplane_info.dg_routes_queued), |
e07e9549 | 2939 | 1, memory_order_seq_cst); |
91f16812 | 2940 | |
e3d9208a MS |
2941 | curr++; /* We got the pre-incremented value */ |
2942 | ||
91f16812 MS |
2943 | /* Maybe update high-water counter also */ |
2944 | high = atomic_load_explicit(&zdplane_info.dg_routes_queued_max, | |
2945 | memory_order_seq_cst); | |
2946 | while (high < curr) { | |
2947 | if (atomic_compare_exchange_weak_explicit( | |
2948 | &zdplane_info.dg_routes_queued_max, | |
2949 | &high, curr, | |
2950 | memory_order_seq_cst, | |
2951 | memory_order_seq_cst)) | |
2952 | break; | |
2953 | } | |
2954 | ||
7cdb1a84 | 2955 | /* Ensure that an event for the dataplane thread is active */ |
c831033f | 2956 | ret = dplane_provider_work_ready(); |
7cdb1a84 | 2957 | |
5709131c | 2958 | return ret; |
7cdb1a84 MS |
2959 | } |
2960 | ||
7cdb1a84 MS |
2961 | /* |
2962 | * Utility that prepares a route update and enqueues it for processing | |
2963 | */ | |
655d681a MS |
2964 | static enum zebra_dplane_result |
2965 | dplane_route_update_internal(struct route_node *rn, | |
2966 | struct route_entry *re, | |
2967 | struct route_entry *old_re, | |
5709131c | 2968 | enum dplane_op_e op) |
7cdb1a84 | 2969 | { |
655d681a | 2970 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; |
7cdb1a84 | 2971 | int ret = EINVAL; |
25779064 | 2972 | struct zebra_dplane_ctx *ctx = NULL; |
7cdb1a84 MS |
2973 | |
2974 | /* Obtain context block */ | |
2975 | ctx = dplane_ctx_alloc(); | |
7cdb1a84 MS |
2976 | |
2977 | /* Init context with info from zebra data structs */ | |
2978 | ret = dplane_ctx_route_init(ctx, op, rn, re); | |
2979 | if (ret == AOK) { | |
2980 | /* Capture some extra info for update case | |
2981 | * where there's a different 'old' route. | |
2982 | */ | |
b8e0423d MS |
2983 | if ((op == DPLANE_OP_ROUTE_UPDATE) && |
2984 | old_re && (old_re != re)) { | |
7cdb1a84 MS |
2985 | ctx->zd_is_update = true; |
2986 | ||
1485bbe7 DS |
2987 | old_re->dplane_sequence = |
2988 | zebra_router_get_next_sequence(); | |
7cdb1a84 MS |
2989 | ctx->zd_old_seq = old_re->dplane_sequence; |
2990 | ||
0f461727 MS |
2991 | ctx->u.rinfo.zd_old_tag = old_re->tag; |
2992 | ctx->u.rinfo.zd_old_type = old_re->type; | |
2993 | ctx->u.rinfo.zd_old_instance = old_re->instance; | |
2994 | ctx->u.rinfo.zd_old_distance = old_re->distance; | |
2995 | ctx->u.rinfo.zd_old_metric = old_re->metric; | |
df3cef24 | 2996 | ctx->u.rinfo.nhe.old_id = old_re->nhe->id; |
01ce7cba MS |
2997 | |
2998 | #ifndef HAVE_NETLINK | |
f183e380 MS |
2999 | /* For bsd, capture previous re's nexthops too, sigh. |
3000 | * We'll need these to do per-nexthop deletes. | |
3001 | */ | |
0f461727 | 3002 | copy_nexthops(&(ctx->u.rinfo.zd_old_ng.nexthop), |
c415d895 | 3003 | old_re->nhe->nhg.nexthop, NULL); |
1d48702e MS |
3004 | |
3005 | if (zebra_nhg_get_backup_nhg(old_re->nhe) != NULL) { | |
3006 | struct nexthop_group *nhg; | |
3007 | struct nexthop **nh; | |
3008 | ||
3009 | nhg = zebra_nhg_get_backup_nhg(old_re->nhe); | |
3010 | nh = &(ctx->u.rinfo.old_backup_ng.nexthop); | |
3011 | ||
3012 | if (nhg->nexthop) | |
3013 | copy_nexthops(nh, nhg->nexthop, NULL); | |
3014 | } | |
01ce7cba | 3015 | #endif /* !HAVE_NETLINK */ |
7cdb1a84 MS |
3016 | } |
3017 | ||
df3cef24 DS |
3018 | /* |
3019 | * If the old and new context type, and nexthop group id | |
3020 | * are the same there is no need to send down a route replace | |
3021 | * as that we know we have sent a nexthop group replace | |
3022 | * or an upper level protocol has sent us the exact | |
3023 | * same route again. | |
3024 | */ | |
3025 | if ((dplane_ctx_get_type(ctx) == dplane_ctx_get_old_type(ctx)) | |
3026 | && (dplane_ctx_get_nhe_id(ctx) | |
3d3a9dc8 SW |
3027 | == dplane_ctx_get_old_nhe_id(ctx)) |
3028 | && (dplane_ctx_get_nhe_id(ctx) >= ZEBRA_NHG_PROTO_LOWER)) { | |
27805e74 DS |
3029 | struct nexthop *nexthop; |
3030 | ||
df3cef24 DS |
3031 | if (IS_ZEBRA_DEBUG_DPLANE) |
3032 | zlog_debug( | |
3033 | "%s: Ignoring Route exactly the same", | |
3034 | __func__); | |
3035 | ||
27805e74 DS |
3036 | for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx), |
3037 | nexthop)) { | |
3038 | if (CHECK_FLAG(nexthop->flags, | |
3039 | NEXTHOP_FLAG_RECURSIVE)) | |
3040 | continue; | |
3041 | ||
3042 | if (CHECK_FLAG(nexthop->flags, | |
3043 | NEXTHOP_FLAG_ACTIVE)) | |
3044 | SET_FLAG(nexthop->flags, | |
3045 | NEXTHOP_FLAG_FIB); | |
3046 | } | |
3047 | ||
841f77ff | 3048 | dplane_ctx_free(&ctx); |
df3cef24 DS |
3049 | return ZEBRA_DPLANE_REQUEST_SUCCESS; |
3050 | } | |
3051 | ||
7cdb1a84 | 3052 | /* Enqueue context for processing */ |
3fe4ccc4 | 3053 | ret = dplane_update_enqueue(ctx); |
7cdb1a84 MS |
3054 | } |
3055 | ||
91f16812 | 3056 | /* Update counter */ |
25779064 | 3057 | atomic_fetch_add_explicit(&zdplane_info.dg_routes_in, 1, |
1d11b21f MS |
3058 | memory_order_relaxed); |
3059 | ||
91f16812 | 3060 | if (ret == AOK) |
655d681a | 3061 | result = ZEBRA_DPLANE_REQUEST_QUEUED; |
16c628de | 3062 | else { |
b96f64f7 DS |
3063 | atomic_fetch_add_explicit(&zdplane_info.dg_route_errors, 1, |
3064 | memory_order_relaxed); | |
16c628de MS |
3065 | if (ctx) |
3066 | dplane_ctx_free(&ctx); | |
1d11b21f | 3067 | } |
7cdb1a84 | 3068 | |
5709131c | 3069 | return result; |
7cdb1a84 MS |
3070 | } |
3071 | ||
f820d025 SW |
3072 | /** |
3073 | * dplane_nexthop_update_internal() - Helper for enqueuing nexthop changes | |
3074 | * | |
3075 | * @nhe: Nexthop group hash entry where the change occured | |
3076 | * @op: The operation to be enqued | |
3077 | * | |
3078 | * Return: Result of the change | |
3079 | */ | |
3080 | static enum zebra_dplane_result | |
3081 | dplane_nexthop_update_internal(struct nhg_hash_entry *nhe, enum dplane_op_e op) | |
3082 | { | |
3083 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
3084 | int ret = EINVAL; | |
3085 | struct zebra_dplane_ctx *ctx = NULL; | |
3086 | ||
3087 | /* Obtain context block */ | |
3088 | ctx = dplane_ctx_alloc(); | |
3089 | if (!ctx) { | |
3090 | ret = ENOMEM; | |
3091 | goto done; | |
3092 | } | |
3093 | ||
3094 | ret = dplane_ctx_nexthop_init(ctx, op, nhe); | |
2d3c57e6 | 3095 | if (ret == AOK) |
f820d025 | 3096 | ret = dplane_update_enqueue(ctx); |
2d3c57e6 | 3097 | |
f820d025 SW |
3098 | done: |
3099 | /* Update counter */ | |
3100 | atomic_fetch_add_explicit(&zdplane_info.dg_nexthops_in, 1, | |
3101 | memory_order_relaxed); | |
3102 | ||
3103 | if (ret == AOK) | |
3104 | result = ZEBRA_DPLANE_REQUEST_QUEUED; | |
3105 | else { | |
81505946 SW |
3106 | atomic_fetch_add_explicit(&zdplane_info.dg_nexthop_errors, 1, |
3107 | memory_order_relaxed); | |
f820d025 SW |
3108 | if (ctx) |
3109 | dplane_ctx_free(&ctx); | |
3110 | } | |
3111 | ||
3112 | return result; | |
3113 | } | |
3114 | ||
7cdb1a84 MS |
3115 | /* |
3116 | * Enqueue a route 'add' for the dataplane. | |
3117 | */ | |
655d681a MS |
3118 | enum zebra_dplane_result dplane_route_add(struct route_node *rn, |
3119 | struct route_entry *re) | |
7cdb1a84 | 3120 | { |
655d681a | 3121 | enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; |
7cdb1a84 | 3122 | |
5709131c | 3123 | if (rn == NULL || re == NULL) |
7cdb1a84 | 3124 | goto done; |
7cdb1a84 MS |
3125 | |
3126 | ret = dplane_route_update_internal(rn, re, NULL, | |
3127 | DPLANE_OP_ROUTE_INSTALL); | |
3128 | ||
3129 | done: | |
5709131c | 3130 | return ret; |
7cdb1a84 MS |
3131 | } |
3132 | ||
3133 | /* | |
3134 | * Enqueue a route update for the dataplane. | |
3135 | */ | |
655d681a MS |
3136 | enum zebra_dplane_result dplane_route_update(struct route_node *rn, |
3137 | struct route_entry *re, | |
3138 | struct route_entry *old_re) | |
7cdb1a84 | 3139 | { |
655d681a | 3140 | enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; |
7cdb1a84 | 3141 | |
5709131c | 3142 | if (rn == NULL || re == NULL) |
7cdb1a84 | 3143 | goto done; |
7cdb1a84 MS |
3144 | |
3145 | ret = dplane_route_update_internal(rn, re, old_re, | |
3146 | DPLANE_OP_ROUTE_UPDATE); | |
7cdb1a84 | 3147 | done: |
5709131c | 3148 | return ret; |
7cdb1a84 MS |
3149 | } |
3150 | ||
3151 | /* | |
3152 | * Enqueue a route removal for the dataplane. | |
3153 | */ | |
655d681a MS |
3154 | enum zebra_dplane_result dplane_route_delete(struct route_node *rn, |
3155 | struct route_entry *re) | |
7cdb1a84 | 3156 | { |
655d681a | 3157 | enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; |
7cdb1a84 | 3158 | |
5709131c | 3159 | if (rn == NULL || re == NULL) |
7cdb1a84 | 3160 | goto done; |
7cdb1a84 MS |
3161 | |
3162 | ret = dplane_route_update_internal(rn, re, NULL, | |
3163 | DPLANE_OP_ROUTE_DELETE); | |
3164 | ||
3165 | done: | |
5709131c | 3166 | return ret; |
7cdb1a84 MS |
3167 | } |
3168 | ||
cf363e1b MS |
3169 | /* |
3170 | * Notify the dplane when system/connected routes change. | |
3171 | */ | |
3172 | enum zebra_dplane_result dplane_sys_route_add(struct route_node *rn, | |
3173 | struct route_entry *re) | |
3174 | { | |
3175 | enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; | |
3176 | ||
3177 | /* Ignore this event unless a provider plugin has requested it. */ | |
3178 | if (!zdplane_info.dg_sys_route_notifs) { | |
3179 | ret = ZEBRA_DPLANE_REQUEST_SUCCESS; | |
3180 | goto done; | |
3181 | } | |
3182 | ||
3183 | if (rn == NULL || re == NULL) | |
3184 | goto done; | |
3185 | ||
3186 | ret = dplane_route_update_internal(rn, re, NULL, | |
3187 | DPLANE_OP_SYS_ROUTE_ADD); | |
3188 | ||
3189 | done: | |
3190 | return ret; | |
3191 | } | |
3192 | ||
3193 | /* | |
3194 | * Notify the dplane when system/connected routes are deleted. | |
3195 | */ | |
3196 | enum zebra_dplane_result dplane_sys_route_del(struct route_node *rn, | |
3197 | struct route_entry *re) | |
3198 | { | |
3199 | enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; | |
3200 | ||
3201 | /* Ignore this event unless a provider plugin has requested it. */ | |
3202 | if (!zdplane_info.dg_sys_route_notifs) { | |
3203 | ret = ZEBRA_DPLANE_REQUEST_SUCCESS; | |
3204 | goto done; | |
3205 | } | |
3206 | ||
3207 | if (rn == NULL || re == NULL) | |
3208 | goto done; | |
3209 | ||
3210 | ret = dplane_route_update_internal(rn, re, NULL, | |
3211 | DPLANE_OP_SYS_ROUTE_DELETE); | |
3212 | ||
3213 | done: | |
3214 | return ret; | |
3215 | } | |
3216 | ||
188a00e0 MS |
3217 | /* |
3218 | * Update from an async notification, to bring other fibs up-to-date. | |
3219 | */ | |
3220 | enum zebra_dplane_result | |
3221 | dplane_route_notif_update(struct route_node *rn, | |
3222 | struct route_entry *re, | |
3223 | enum dplane_op_e op, | |
3224 | struct zebra_dplane_ctx *ctx) | |
3225 | { | |
54d321aa MS |
3226 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; |
3227 | int ret = EINVAL; | |
188a00e0 MS |
3228 | struct zebra_dplane_ctx *new_ctx = NULL; |
3229 | struct nexthop *nexthop; | |
3c0e1622 | 3230 | struct nexthop_group *nhg; |
188a00e0 MS |
3231 | |
3232 | if (rn == NULL || re == NULL) | |
3233 | goto done; | |
3234 | ||
3235 | new_ctx = dplane_ctx_alloc(); | |
3236 | if (new_ctx == NULL) | |
3237 | goto done; | |
3238 | ||
3239 | /* Init context with info from zebra data structs */ | |
3240 | dplane_ctx_route_init(new_ctx, op, rn, re); | |
3241 | ||
3242 | /* For add/update, need to adjust the nexthops so that we match | |
3243 | * the notification state, which may not be the route-entry/RIB | |
3244 | * state. | |
3245 | */ | |
3246 | if (op == DPLANE_OP_ROUTE_UPDATE || | |
3247 | op == DPLANE_OP_ROUTE_INSTALL) { | |
3248 | ||
3249 | nexthops_free(new_ctx->u.rinfo.zd_ng.nexthop); | |
3250 | new_ctx->u.rinfo.zd_ng.nexthop = NULL; | |
3251 | ||
3c0e1622 MS |
3252 | nhg = rib_get_fib_nhg(re); |
3253 | if (nhg && nhg->nexthop) | |
3254 | copy_nexthops(&(new_ctx->u.rinfo.zd_ng.nexthop), | |
3255 | nhg->nexthop, NULL); | |
188a00e0 | 3256 | |
3c0e1622 MS |
3257 | /* Check for installed backup nexthops also */ |
3258 | nhg = rib_get_fib_backup_nhg(re); | |
3259 | if (nhg && nhg->nexthop) { | |
00a9b150 | 3260 | copy_nexthops(&(new_ctx->u.rinfo.zd_ng.nexthop), |
3c0e1622 | 3261 | nhg->nexthop, NULL); |
00a9b150 | 3262 | } |
188a00e0 MS |
3263 | |
3264 | for (ALL_NEXTHOPS(new_ctx->u.rinfo.zd_ng, nexthop)) | |
3265 | UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); | |
3266 | ||
3267 | } | |
3268 | ||
3269 | /* Capture info about the source of the notification, in 'ctx' */ | |
3270 | dplane_ctx_set_notif_provider(new_ctx, | |
3271 | dplane_ctx_get_notif_provider(ctx)); | |
3272 | ||
54d321aa | 3273 | ret = dplane_update_enqueue(new_ctx); |
188a00e0 MS |
3274 | |
3275 | done: | |
54d321aa MS |
3276 | if (ret == AOK) |
3277 | result = ZEBRA_DPLANE_REQUEST_QUEUED; | |
dd3b6cb5 MS |
3278 | else if (new_ctx) |
3279 | dplane_ctx_free(&new_ctx); | |
54d321aa MS |
3280 | |
3281 | return result; | |
188a00e0 MS |
3282 | } |
3283 | ||
f820d025 SW |
3284 | /* |
3285 | * Enqueue a nexthop add for the dataplane. | |
3286 | */ | |
3287 | enum zebra_dplane_result dplane_nexthop_add(struct nhg_hash_entry *nhe) | |
3288 | { | |
3289 | enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; | |
3290 | ||
3291 | if (nhe) | |
3292 | ret = dplane_nexthop_update_internal(nhe, DPLANE_OP_NH_INSTALL); | |
3293 | return ret; | |
3294 | } | |
3295 | ||
3296 | /* | |
3297 | * Enqueue a nexthop update for the dataplane. | |
81505946 SW |
3298 | * |
3299 | * Might not need this func since zebra's nexthop objects should be immutable? | |
f820d025 SW |
3300 | */ |
3301 | enum zebra_dplane_result dplane_nexthop_update(struct nhg_hash_entry *nhe) | |
3302 | { | |
3303 | enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; | |
3304 | ||
3305 | if (nhe) | |
3306 | ret = dplane_nexthop_update_internal(nhe, DPLANE_OP_NH_UPDATE); | |
3307 | return ret; | |
3308 | } | |
3309 | ||
3310 | /* | |
3311 | * Enqueue a nexthop removal for the dataplane. | |
3312 | */ | |
3313 | enum zebra_dplane_result dplane_nexthop_delete(struct nhg_hash_entry *nhe) | |
3314 | { | |
3315 | enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; | |
3316 | ||
3317 | if (nhe) | |
3318 | ret = dplane_nexthop_update_internal(nhe, DPLANE_OP_NH_DELETE); | |
3319 | ||
3320 | return ret; | |
3321 | } | |
3322 | ||
16c628de MS |
3323 | /* |
3324 | * Enqueue LSP add for the dataplane. | |
3325 | */ | |
8f74a383 | 3326 | enum zebra_dplane_result dplane_lsp_add(struct zebra_lsp *lsp) |
16c628de MS |
3327 | { |
3328 | enum zebra_dplane_result ret = | |
3329 | lsp_update_internal(lsp, DPLANE_OP_LSP_INSTALL); | |
3330 | ||
3331 | return ret; | |
3332 | } | |
3333 | ||
3334 | /* | |
3335 | * Enqueue LSP update for the dataplane. | |
3336 | */ | |
8f74a383 | 3337 | enum zebra_dplane_result dplane_lsp_update(struct zebra_lsp *lsp) |
16c628de MS |
3338 | { |
3339 | enum zebra_dplane_result ret = | |
3340 | lsp_update_internal(lsp, DPLANE_OP_LSP_UPDATE); | |
3341 | ||
3342 | return ret; | |
3343 | } | |
3344 | ||
3345 | /* | |
3346 | * Enqueue LSP delete for the dataplane. | |
3347 | */ | |
8f74a383 | 3348 | enum zebra_dplane_result dplane_lsp_delete(struct zebra_lsp *lsp) |
16c628de MS |
3349 | { |
3350 | enum zebra_dplane_result ret = | |
3351 | lsp_update_internal(lsp, DPLANE_OP_LSP_DELETE); | |
3352 | ||
3353 | return ret; | |
3354 | } | |
3355 | ||
188a00e0 MS |
3356 | /* Update or un-install resulting from an async notification */ |
3357 | enum zebra_dplane_result | |
8f74a383 | 3358 | dplane_lsp_notif_update(struct zebra_lsp *lsp, enum dplane_op_e op, |
188a00e0 MS |
3359 | struct zebra_dplane_ctx *notif_ctx) |
3360 | { | |
3361 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
3362 | int ret = EINVAL; | |
3363 | struct zebra_dplane_ctx *ctx = NULL; | |
00a9b150 | 3364 | struct nhlfe_list_head *head; |
f2595bd5 | 3365 | struct zebra_nhlfe *nhlfe, *new_nhlfe; |
188a00e0 MS |
3366 | |
3367 | /* Obtain context block */ | |
3368 | ctx = dplane_ctx_alloc(); | |
3369 | if (ctx == NULL) { | |
3370 | ret = ENOMEM; | |
3371 | goto done; | |
3372 | } | |
3373 | ||
00a9b150 | 3374 | /* Copy info from zebra LSP */ |
188a00e0 MS |
3375 | ret = dplane_ctx_lsp_init(ctx, op, lsp); |
3376 | if (ret != AOK) | |
3377 | goto done; | |
3378 | ||
00a9b150 MS |
3379 | /* Add any installed backup nhlfes */ |
3380 | head = &(ctx->u.lsp.backup_nhlfe_list); | |
3381 | frr_each(nhlfe_list, head, nhlfe) { | |
3382 | ||
3383 | if (CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED) && | |
3384 | CHECK_FLAG(nhlfe->nexthop->flags, NEXTHOP_FLAG_FIB)) { | |
3385 | new_nhlfe = zebra_mpls_lsp_add_nh(&(ctx->u.lsp), | |
3386 | nhlfe->type, | |
3387 | nhlfe->nexthop); | |
3388 | ||
3389 | /* Need to copy flags too */ | |
3390 | new_nhlfe->flags = nhlfe->flags; | |
3391 | new_nhlfe->nexthop->flags = nhlfe->nexthop->flags; | |
3392 | } | |
3393 | } | |
3394 | ||
188a00e0 MS |
3395 | /* Capture info about the source of the notification */ |
3396 | dplane_ctx_set_notif_provider( | |
3397 | ctx, | |
3398 | dplane_ctx_get_notif_provider(notif_ctx)); | |
3399 | ||
3fe4ccc4 | 3400 | ret = dplane_update_enqueue(ctx); |
188a00e0 MS |
3401 | |
3402 | done: | |
3403 | /* Update counter */ | |
3404 | atomic_fetch_add_explicit(&zdplane_info.dg_lsps_in, 1, | |
3405 | memory_order_relaxed); | |
3406 | ||
3407 | if (ret == AOK) | |
3408 | result = ZEBRA_DPLANE_REQUEST_QUEUED; | |
3409 | else { | |
3410 | atomic_fetch_add_explicit(&zdplane_info.dg_lsp_errors, 1, | |
3411 | memory_order_relaxed); | |
3412 | if (ctx) | |
3413 | dplane_ctx_free(&ctx); | |
3414 | } | |
3415 | return result; | |
3416 | } | |
3417 | ||
97d8d05a MS |
3418 | /* |
3419 | * Enqueue pseudowire install for the dataplane. | |
3420 | */ | |
3421 | enum zebra_dplane_result dplane_pw_install(struct zebra_pw *pw) | |
3422 | { | |
3423 | return pw_update_internal(pw, DPLANE_OP_PW_INSTALL); | |
3424 | } | |
3425 | ||
3426 | /* | |
3427 | * Enqueue pseudowire un-install for the dataplane. | |
3428 | */ | |
3429 | enum zebra_dplane_result dplane_pw_uninstall(struct zebra_pw *pw) | |
3430 | { | |
3431 | return pw_update_internal(pw, DPLANE_OP_PW_UNINSTALL); | |
3432 | } | |
3433 | ||
16c628de MS |
3434 | /* |
3435 | * Common internal LSP update utility | |
3436 | */ | |
8f74a383 | 3437 | static enum zebra_dplane_result lsp_update_internal(struct zebra_lsp *lsp, |
16c628de MS |
3438 | enum dplane_op_e op) |
3439 | { | |
3440 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
3441 | int ret = EINVAL; | |
3442 | struct zebra_dplane_ctx *ctx = NULL; | |
3443 | ||
3444 | /* Obtain context block */ | |
3445 | ctx = dplane_ctx_alloc(); | |
16c628de MS |
3446 | |
3447 | ret = dplane_ctx_lsp_init(ctx, op, lsp); | |
3448 | if (ret != AOK) | |
3449 | goto done; | |
3450 | ||
3fe4ccc4 | 3451 | ret = dplane_update_enqueue(ctx); |
16c628de MS |
3452 | |
3453 | done: | |
3454 | /* Update counter */ | |
3455 | atomic_fetch_add_explicit(&zdplane_info.dg_lsps_in, 1, | |
3456 | memory_order_relaxed); | |
3457 | ||
3458 | if (ret == AOK) | |
3459 | result = ZEBRA_DPLANE_REQUEST_QUEUED; | |
3460 | else { | |
3461 | atomic_fetch_add_explicit(&zdplane_info.dg_lsp_errors, 1, | |
3462 | memory_order_relaxed); | |
d8e479a3 | 3463 | dplane_ctx_free(&ctx); |
16c628de MS |
3464 | } |
3465 | ||
3466 | return result; | |
3467 | } | |
3468 | ||
97d8d05a MS |
3469 | /* |
3470 | * Internal, common handler for pseudowire updates. | |
3471 | */ | |
3472 | static enum zebra_dplane_result pw_update_internal(struct zebra_pw *pw, | |
3473 | enum dplane_op_e op) | |
3474 | { | |
3475 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
3476 | int ret; | |
3477 | struct zebra_dplane_ctx *ctx = NULL; | |
3478 | ||
3479 | ctx = dplane_ctx_alloc(); | |
97d8d05a MS |
3480 | |
3481 | ret = dplane_ctx_pw_init(ctx, op, pw); | |
3482 | if (ret != AOK) | |
3483 | goto done; | |
3484 | ||
3fe4ccc4 | 3485 | ret = dplane_update_enqueue(ctx); |
97d8d05a MS |
3486 | |
3487 | done: | |
3488 | /* Update counter */ | |
3489 | atomic_fetch_add_explicit(&zdplane_info.dg_pws_in, 1, | |
3490 | memory_order_relaxed); | |
3491 | ||
3492 | if (ret == AOK) | |
3493 | result = ZEBRA_DPLANE_REQUEST_QUEUED; | |
3494 | else { | |
3495 | atomic_fetch_add_explicit(&zdplane_info.dg_pw_errors, 1, | |
3496 | memory_order_relaxed); | |
d8e479a3 | 3497 | dplane_ctx_free(&ctx); |
97d8d05a MS |
3498 | } |
3499 | ||
3500 | return result; | |
3501 | } | |
3502 | ||
c60522f7 AK |
3503 | /* |
3504 | * Enqueue access br_port update. | |
3505 | */ | |
3506 | enum zebra_dplane_result | |
3507 | dplane_br_port_update(const struct interface *ifp, bool non_df, | |
3508 | uint32_t sph_filter_cnt, | |
3509 | const struct in_addr *sph_filters, uint32_t backup_nhg_id) | |
3510 | { | |
3511 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
3512 | uint32_t flags = 0; | |
3513 | int ret; | |
3514 | struct zebra_dplane_ctx *ctx = NULL; | |
3515 | struct zebra_ns *zns; | |
3516 | enum dplane_op_e op = DPLANE_OP_BR_PORT_UPDATE; | |
3517 | ||
3518 | if (non_df) | |
3519 | flags |= DPLANE_BR_PORT_NON_DF; | |
3520 | ||
28e80a03 | 3521 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL || IS_ZEBRA_DEBUG_EVPN_MH_ES) { |
c60522f7 AK |
3522 | uint32_t i; |
3523 | char vtep_str[ES_VTEP_LIST_STR_SZ]; | |
3524 | ||
3525 | vtep_str[0] = '\0'; | |
3526 | for (i = 0; i < sph_filter_cnt; ++i) { | |
3527 | snprintfrr(vtep_str + strlen(vtep_str), | |
3528 | sizeof(vtep_str) - strlen(vtep_str), "%pI4 ", | |
3529 | &sph_filters[i]); | |
3530 | } | |
3531 | zlog_debug( | |
3532 | "init br_port ctx %s: ifp %s, flags 0x%x backup_nhg 0x%x sph %s", | |
3533 | dplane_op2str(op), ifp->name, flags, backup_nhg_id, | |
3534 | vtep_str); | |
3535 | } | |
3536 | ||
3537 | ctx = dplane_ctx_alloc(); | |
3538 | ||
3539 | ctx->zd_op = op; | |
3540 | ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; | |
3541 | ctx->zd_vrf_id = ifp->vrf_id; | |
3542 | ||
3543 | zns = zebra_ns_lookup(ifp->vrf_id); | |
3544 | dplane_ctx_ns_init(ctx, zns, false); | |
3545 | ||
3546 | ctx->zd_ifindex = ifp->ifindex; | |
3547 | strlcpy(ctx->zd_ifname, ifp->name, sizeof(ctx->zd_ifname)); | |
3548 | ||
3549 | /* Init the br-port-specific data area */ | |
3550 | memset(&ctx->u.br_port, 0, sizeof(ctx->u.br_port)); | |
3551 | ||
3552 | ctx->u.br_port.flags = flags; | |
3553 | ctx->u.br_port.backup_nhg_id = backup_nhg_id; | |
3554 | ctx->u.br_port.sph_filter_cnt = sph_filter_cnt; | |
3555 | memcpy(ctx->u.br_port.sph_filters, sph_filters, | |
3556 | sizeof(ctx->u.br_port.sph_filters[0]) * sph_filter_cnt); | |
3557 | ||
3558 | /* Enqueue for processing on the dplane pthread */ | |
3559 | ret = dplane_update_enqueue(ctx); | |
3560 | ||
3561 | /* Increment counter */ | |
3562 | atomic_fetch_add_explicit(&zdplane_info.dg_br_port_in, 1, | |
3563 | memory_order_relaxed); | |
3564 | ||
3565 | if (ret == AOK) { | |
3566 | result = ZEBRA_DPLANE_REQUEST_QUEUED; | |
3567 | } else { | |
3568 | /* Error counter */ | |
3569 | atomic_fetch_add_explicit(&zdplane_info.dg_br_port_errors, 1, | |
3570 | memory_order_relaxed); | |
3571 | dplane_ctx_free(&ctx); | |
3572 | } | |
3573 | ||
3574 | return result; | |
3575 | } | |
3576 | ||
a4a4802a MS |
3577 | /* |
3578 | * Enqueue interface address add for the dataplane. | |
3579 | */ | |
3580 | enum zebra_dplane_result dplane_intf_addr_set(const struct interface *ifp, | |
3581 | const struct connected *ifc) | |
3582 | { | |
64168803 MS |
3583 | #if !defined(HAVE_NETLINK) && defined(HAVE_STRUCT_IFALIASREQ) |
3584 | /* Extra checks for this OS path. */ | |
3585 | ||
3586 | /* Don't configure PtP addresses on broadcast ifs or reverse */ | |
3587 | if (!(ifp->flags & IFF_POINTOPOINT) != !CONNECTED_PEER(ifc)) { | |
3588 | if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_DPLANE) | |
3589 | zlog_debug("Failed to set intf addr: mismatch p2p and connected"); | |
3590 | ||
3591 | return ZEBRA_DPLANE_REQUEST_FAILURE; | |
3592 | } | |
64168803 MS |
3593 | #endif |
3594 | ||
3595 | return intf_addr_update_internal(ifp, ifc, DPLANE_OP_ADDR_INSTALL); | |
a4a4802a MS |
3596 | } |
3597 | ||
3598 | /* | |
3599 | * Enqueue interface address remove/uninstall for the dataplane. | |
3600 | */ | |
3601 | enum zebra_dplane_result dplane_intf_addr_unset(const struct interface *ifp, | |
3602 | const struct connected *ifc) | |
3603 | { | |
64168803 MS |
3604 | return intf_addr_update_internal(ifp, ifc, DPLANE_OP_ADDR_UNINSTALL); |
3605 | } | |
3606 | ||
3607 | static enum zebra_dplane_result intf_addr_update_internal( | |
3608 | const struct interface *ifp, const struct connected *ifc, | |
3609 | enum dplane_op_e op) | |
3610 | { | |
3611 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
3612 | int ret = EINVAL; | |
3613 | struct zebra_dplane_ctx *ctx = NULL; | |
3614 | struct zebra_ns *zns; | |
3615 | ||
2dbe669b DA |
3616 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) |
3617 | zlog_debug("init intf ctx %s: idx %d, addr %u:%pFX", | |
a36898e7 | 3618 | dplane_op2str(op), ifp->ifindex, ifp->vrf_id, |
2dbe669b | 3619 | ifc->address); |
64168803 MS |
3620 | |
3621 | ctx = dplane_ctx_alloc(); | |
64168803 MS |
3622 | |
3623 | ctx->zd_op = op; | |
3624 | ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; | |
a36898e7 | 3625 | ctx->zd_vrf_id = ifp->vrf_id; |
64168803 | 3626 | |
a36898e7 | 3627 | zns = zebra_ns_lookup(ifp->vrf_id); |
64168803 MS |
3628 | dplane_ctx_ns_init(ctx, zns, false); |
3629 | ||
3630 | /* Init the interface-addr-specific area */ | |
3631 | memset(&ctx->u.intf, 0, sizeof(ctx->u.intf)); | |
3632 | ||
7c7ef4a8 MS |
3633 | strlcpy(ctx->zd_ifname, ifp->name, sizeof(ctx->zd_ifname)); |
3634 | ctx->zd_ifindex = ifp->ifindex; | |
64168803 MS |
3635 | ctx->u.intf.prefix = *(ifc->address); |
3636 | ||
3637 | if (if_is_broadcast(ifp)) | |
3638 | ctx->u.intf.flags |= DPLANE_INTF_BROADCAST; | |
3639 | ||
3640 | if (CONNECTED_PEER(ifc)) { | |
3641 | ctx->u.intf.dest_prefix = *(ifc->destination); | |
3642 | ctx->u.intf.flags |= | |
3643 | (DPLANE_INTF_CONNECTED | DPLANE_INTF_HAS_DEST); | |
64168803 MS |
3644 | } |
3645 | ||
3646 | if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY)) | |
3647 | ctx->u.intf.flags |= DPLANE_INTF_SECONDARY; | |
3648 | ||
3649 | if (ifc->label) { | |
3650 | size_t len; | |
3651 | ||
3652 | ctx->u.intf.flags |= DPLANE_INTF_HAS_LABEL; | |
3653 | ||
3654 | /* Use embedded buffer if it's adequate; else allocate. */ | |
3655 | len = strlen(ifc->label); | |
3656 | ||
3657 | if (len < sizeof(ctx->u.intf.label_buf)) { | |
b7b7bf31 | 3658 | strlcpy(ctx->u.intf.label_buf, ifc->label, |
64168803 MS |
3659 | sizeof(ctx->u.intf.label_buf)); |
3660 | ctx->u.intf.label = ctx->u.intf.label_buf; | |
3661 | } else { | |
3662 | ctx->u.intf.label = strdup(ifc->label); | |
3663 | } | |
3664 | } | |
3665 | ||
3fe4ccc4 | 3666 | ret = dplane_update_enqueue(ctx); |
64168803 | 3667 | |
64168803 MS |
3668 | /* Increment counter */ |
3669 | atomic_fetch_add_explicit(&zdplane_info.dg_intf_addrs_in, 1, | |
3670 | memory_order_relaxed); | |
3671 | ||
3672 | if (ret == AOK) | |
3673 | result = ZEBRA_DPLANE_REQUEST_QUEUED; | |
3674 | else { | |
3675 | /* Error counter */ | |
3676 | atomic_fetch_add_explicit(&zdplane_info.dg_intf_addr_errors, | |
3677 | 1, memory_order_relaxed); | |
d8e479a3 | 3678 | dplane_ctx_free(&ctx); |
64168803 MS |
3679 | } |
3680 | ||
3681 | return result; | |
a4a4802a MS |
3682 | } |
3683 | ||
7597ac7b MS |
3684 | /* |
3685 | * Enqueue vxlan/evpn mac add (or update). | |
3686 | */ | |
f188e68e | 3687 | enum zebra_dplane_result dplane_rem_mac_add(const struct interface *ifp, |
478566d6 | 3688 | const struct interface *bridge_ifp, |
7597ac7b MS |
3689 | vlanid_t vid, |
3690 | const struct ethaddr *mac, | |
3691 | struct in_addr vtep_ip, | |
506efd37 | 3692 | bool sticky, |
f188e68e AK |
3693 | uint32_t nhg_id, |
3694 | bool was_static) | |
7597ac7b MS |
3695 | { |
3696 | enum zebra_dplane_result result; | |
f188e68e AK |
3697 | uint32_t update_flags = 0; |
3698 | ||
3699 | update_flags |= DPLANE_MAC_REMOTE; | |
3700 | if (was_static) | |
3701 | update_flags |= DPLANE_MAC_WAS_STATIC; | |
7597ac7b MS |
3702 | |
3703 | /* Use common helper api */ | |
f73a8467 | 3704 | result = mac_update_common(DPLANE_OP_MAC_INSTALL, ifp, bridge_ifp, |
f188e68e | 3705 | vid, mac, vtep_ip, sticky, nhg_id, update_flags); |
7597ac7b MS |
3706 | return result; |
3707 | } | |
3708 | ||
3709 | /* | |
3710 | * Enqueue vxlan/evpn mac delete. | |
3711 | */ | |
f188e68e | 3712 | enum zebra_dplane_result dplane_rem_mac_del(const struct interface *ifp, |
478566d6 | 3713 | const struct interface *bridge_ifp, |
7597ac7b MS |
3714 | vlanid_t vid, |
3715 | const struct ethaddr *mac, | |
3716 | struct in_addr vtep_ip) | |
3717 | { | |
3718 | enum zebra_dplane_result result; | |
f188e68e AK |
3719 | uint32_t update_flags = 0; |
3720 | ||
3721 | update_flags |= DPLANE_MAC_REMOTE; | |
7597ac7b MS |
3722 | |
3723 | /* Use common helper api */ | |
f73a8467 | 3724 | result = mac_update_common(DPLANE_OP_MAC_DELETE, ifp, bridge_ifp, |
f188e68e AK |
3725 | vid, mac, vtep_ip, false, 0, update_flags); |
3726 | return result; | |
3727 | } | |
3728 | ||
0a27a2fe PG |
3729 | /* |
3730 | * API to configure link local with either MAC address or IP information | |
3731 | */ | |
3732 | enum zebra_dplane_result dplane_neigh_ip_update(enum dplane_op_e op, | |
3733 | const struct interface *ifp, | |
3734 | struct ipaddr *link_ip, | |
3735 | struct ipaddr *ip, | |
d603c077 | 3736 | uint32_t ndm_state, int protocol) |
0a27a2fe PG |
3737 | { |
3738 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
3739 | uint16_t state = 0; | |
3740 | uint32_t update_flags; | |
3741 | ||
80ff3f05 MS |
3742 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) |
3743 | zlog_debug("%s: init link ctx %s: ifp %s, link_ip %pIA ip %pIA", | |
3744 | __func__, dplane_op2str(op), ifp->name, link_ip, ip); | |
0a27a2fe | 3745 | |
d603c077 PG |
3746 | if (ndm_state == ZEBRA_NEIGH_STATE_REACHABLE) |
3747 | state = DPLANE_NUD_REACHABLE; | |
3748 | else if (ndm_state == ZEBRA_NEIGH_STATE_FAILED) | |
0a27a2fe PG |
3749 | state = DPLANE_NUD_FAILED; |
3750 | ||
3751 | update_flags = DPLANE_NEIGH_NO_EXTENSION; | |
3752 | ||
3753 | result = neigh_update_internal(op, ifp, (const void *)link_ip, | |
3754 | ipaddr_family(link_ip), ip, 0, state, | |
3755 | update_flags, protocol); | |
3756 | ||
3757 | return result; | |
3758 | } | |
3759 | ||
f188e68e AK |
3760 | /* |
3761 | * Enqueue local mac add (or update). | |
3762 | */ | |
3763 | enum zebra_dplane_result dplane_local_mac_add(const struct interface *ifp, | |
3764 | const struct interface *bridge_ifp, | |
3765 | vlanid_t vid, | |
3766 | const struct ethaddr *mac, | |
3767 | bool sticky, | |
3768 | uint32_t set_static, | |
3769 | uint32_t set_inactive) | |
3770 | { | |
3771 | enum zebra_dplane_result result; | |
3772 | uint32_t update_flags = 0; | |
3773 | struct in_addr vtep_ip; | |
3774 | ||
3775 | if (set_static) | |
3776 | update_flags |= DPLANE_MAC_SET_STATIC; | |
3777 | ||
3778 | if (set_inactive) | |
3779 | update_flags |= DPLANE_MAC_SET_INACTIVE; | |
3780 | ||
3781 | vtep_ip.s_addr = 0; | |
3782 | ||
3783 | /* Use common helper api */ | |
3784 | result = mac_update_common(DPLANE_OP_MAC_INSTALL, ifp, bridge_ifp, | |
3785 | vid, mac, vtep_ip, sticky, 0, | |
3786 | update_flags); | |
7597ac7b MS |
3787 | return result; |
3788 | } | |
3789 | ||
00a7710c AK |
3790 | /* |
3791 | * Enqueue local mac del | |
3792 | */ | |
3793 | enum zebra_dplane_result | |
3794 | dplane_local_mac_del(const struct interface *ifp, | |
3795 | const struct interface *bridge_ifp, vlanid_t vid, | |
3796 | const struct ethaddr *mac) | |
3797 | { | |
3798 | enum zebra_dplane_result result; | |
3799 | struct in_addr vtep_ip; | |
3800 | ||
3801 | vtep_ip.s_addr = 0; | |
3802 | ||
3803 | /* Use common helper api */ | |
3804 | result = mac_update_common(DPLANE_OP_MAC_DELETE, ifp, bridge_ifp, vid, | |
3805 | mac, vtep_ip, false, 0, 0); | |
3806 | return result; | |
3807 | } | |
7597ac7b | 3808 | /* |
f73a8467 MS |
3809 | * Public api to init an empty context - either newly-allocated or |
3810 | * reset/cleared - for a MAC update. | |
7597ac7b | 3811 | */ |
f73a8467 MS |
3812 | void dplane_mac_init(struct zebra_dplane_ctx *ctx, |
3813 | const struct interface *ifp, | |
3814 | const struct interface *br_ifp, | |
3815 | vlanid_t vid, | |
3816 | const struct ethaddr *mac, | |
3817 | struct in_addr vtep_ip, | |
506efd37 | 3818 | bool sticky, |
f188e68e AK |
3819 | uint32_t nhg_id, |
3820 | uint32_t update_flags) | |
7597ac7b | 3821 | { |
7597ac7b MS |
3822 | struct zebra_ns *zns; |
3823 | ||
7597ac7b MS |
3824 | ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; |
3825 | ctx->zd_vrf_id = ifp->vrf_id; | |
3826 | ||
3827 | zns = zebra_ns_lookup(ifp->vrf_id); | |
3828 | dplane_ctx_ns_init(ctx, zns, false); | |
3829 | ||
3830 | strlcpy(ctx->zd_ifname, ifp->name, sizeof(ctx->zd_ifname)); | |
3831 | ctx->zd_ifindex = ifp->ifindex; | |
3832 | ||
3833 | /* Init the mac-specific data area */ | |
3834 | memset(&ctx->u.macinfo, 0, sizeof(ctx->u.macinfo)); | |
3835 | ||
478566d6 | 3836 | ctx->u.macinfo.br_ifindex = br_ifp->ifindex; |
7597ac7b MS |
3837 | ctx->u.macinfo.vtep_ip = vtep_ip; |
3838 | ctx->u.macinfo.mac = *mac; | |
3839 | ctx->u.macinfo.vid = vid; | |
3840 | ctx->u.macinfo.is_sticky = sticky; | |
506efd37 | 3841 | ctx->u.macinfo.nhg_id = nhg_id; |
f188e68e | 3842 | ctx->u.macinfo.update_flags = update_flags; |
f73a8467 MS |
3843 | } |
3844 | ||
3845 | /* | |
3846 | * Common helper api for MAC address/vxlan updates | |
3847 | */ | |
3848 | static enum zebra_dplane_result | |
3849 | mac_update_common(enum dplane_op_e op, | |
3850 | const struct interface *ifp, | |
3851 | const struct interface *br_ifp, | |
3852 | vlanid_t vid, | |
3853 | const struct ethaddr *mac, | |
3854 | struct in_addr vtep_ip, | |
506efd37 | 3855 | bool sticky, |
f188e68e AK |
3856 | uint32_t nhg_id, |
3857 | uint32_t update_flags) | |
f73a8467 MS |
3858 | { |
3859 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
3860 | int ret; | |
3861 | struct zebra_dplane_ctx *ctx = NULL; | |
3862 | ||
ef7b8be4 DL |
3863 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) |
3864 | zlog_debug("init mac ctx %s: mac %pEA, ifp %s, vtep %pI4", | |
3865 | dplane_op2str(op), mac, ifp->name, &vtep_ip); | |
f73a8467 MS |
3866 | |
3867 | ctx = dplane_ctx_alloc(); | |
3868 | ctx->zd_op = op; | |
3869 | ||
3870 | /* Common init for the ctx */ | |
f188e68e AK |
3871 | dplane_mac_init(ctx, ifp, br_ifp, vid, mac, vtep_ip, sticky, |
3872 | nhg_id, update_flags); | |
7597ac7b MS |
3873 | |
3874 | /* Enqueue for processing on the dplane pthread */ | |
3875 | ret = dplane_update_enqueue(ctx); | |
3876 | ||
3877 | /* Increment counter */ | |
3878 | atomic_fetch_add_explicit(&zdplane_info.dg_macs_in, 1, | |
3879 | memory_order_relaxed); | |
3880 | ||
3881 | if (ret == AOK) | |
3882 | result = ZEBRA_DPLANE_REQUEST_QUEUED; | |
3883 | else { | |
3884 | /* Error counter */ | |
3885 | atomic_fetch_add_explicit(&zdplane_info.dg_mac_errors, 1, | |
3886 | memory_order_relaxed); | |
3887 | dplane_ctx_free(&ctx); | |
3888 | } | |
3889 | ||
3890 | return result; | |
3891 | } | |
3892 | ||
931fa60c MS |
3893 | /* |
3894 | * Enqueue evpn neighbor add for the dataplane. | |
3895 | */ | |
f188e68e | 3896 | enum zebra_dplane_result dplane_rem_neigh_add(const struct interface *ifp, |
931fa60c MS |
3897 | const struct ipaddr *ip, |
3898 | const struct ethaddr *mac, | |
f188e68e | 3899 | uint32_t flags, bool was_static) |
931fa60c MS |
3900 | { |
3901 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
f188e68e AK |
3902 | uint32_t update_flags = 0; |
3903 | ||
3904 | update_flags |= DPLANE_NEIGH_REMOTE; | |
3905 | ||
3906 | if (was_static) | |
3907 | update_flags |= DPLANE_NEIGH_WAS_STATIC; | |
931fa60c | 3908 | |
0a27a2fe PG |
3909 | result = neigh_update_internal( |
3910 | DPLANE_OP_NEIGH_INSTALL, ifp, (const void *)mac, AF_ETHERNET, | |
88217099 | 3911 | ip, flags, DPLANE_NUD_NOARP, update_flags, 0); |
f188e68e AK |
3912 | |
3913 | return result; | |
3914 | } | |
3915 | ||
3916 | /* | |
3917 | * Enqueue local neighbor add for the dataplane. | |
3918 | */ | |
3919 | enum zebra_dplane_result dplane_local_neigh_add(const struct interface *ifp, | |
931fa60c MS |
3920 | const struct ipaddr *ip, |
3921 | const struct ethaddr *mac, | |
f188e68e AK |
3922 | bool set_router, bool set_static, |
3923 | bool set_inactive) | |
931fa60c MS |
3924 | { |
3925 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
f188e68e AK |
3926 | uint32_t update_flags = 0; |
3927 | uint32_t ntf = 0; | |
3928 | uint16_t state; | |
3929 | ||
3930 | if (set_static) | |
3931 | update_flags |= DPLANE_NEIGH_SET_STATIC; | |
3932 | ||
3933 | if (set_inactive) { | |
3934 | update_flags |= DPLANE_NEIGH_SET_INACTIVE; | |
3935 | state = DPLANE_NUD_STALE; | |
3936 | } else { | |
3937 | state = DPLANE_NUD_REACHABLE; | |
3938 | } | |
3939 | ||
3940 | if (set_router) | |
3941 | ntf |= DPLANE_NTF_ROUTER; | |
931fa60c | 3942 | |
0a27a2fe PG |
3943 | result = neigh_update_internal(DPLANE_OP_NEIGH_INSTALL, ifp, |
3944 | (const void *)mac, AF_ETHERNET, ip, ntf, | |
88217099 | 3945 | state, update_flags, 0); |
931fa60c MS |
3946 | |
3947 | return result; | |
3948 | } | |
3949 | ||
931fa60c MS |
3950 | /* |
3951 | * Enqueue evpn neighbor delete for the dataplane. | |
3952 | */ | |
f188e68e | 3953 | enum zebra_dplane_result dplane_rem_neigh_delete(const struct interface *ifp, |
931fa60c MS |
3954 | const struct ipaddr *ip) |
3955 | { | |
0bbd4ff4 | 3956 | enum zebra_dplane_result result; |
f188e68e AK |
3957 | uint32_t update_flags = 0; |
3958 | ||
3959 | update_flags |= DPLANE_NEIGH_REMOTE; | |
931fa60c | 3960 | |
0a27a2fe | 3961 | result = neigh_update_internal(DPLANE_OP_NEIGH_DELETE, ifp, NULL, |
88217099 | 3962 | AF_ETHERNET, ip, 0, 0, update_flags, 0); |
931fa60c MS |
3963 | |
3964 | return result; | |
3965 | } | |
3966 | ||
0bbd4ff4 MS |
3967 | /* |
3968 | * Enqueue evpn VTEP add for the dataplane. | |
3969 | */ | |
3970 | enum zebra_dplane_result dplane_vtep_add(const struct interface *ifp, | |
3971 | const struct in_addr *ip, | |
3972 | vni_t vni) | |
3973 | { | |
3974 | enum zebra_dplane_result result; | |
3975 | struct ethaddr mac = { {0, 0, 0, 0, 0, 0} }; | |
3976 | struct ipaddr addr; | |
3977 | ||
3978 | if (IS_ZEBRA_DEBUG_VXLAN) | |
9bcef951 MS |
3979 | zlog_debug("Install %pI4 into flood list for VNI %u intf %s(%u)", |
3980 | ip, vni, ifp->name, ifp->ifindex); | |
0bbd4ff4 MS |
3981 | |
3982 | SET_IPADDR_V4(&addr); | |
3983 | addr.ipaddr_v4 = *ip; | |
3984 | ||
0a27a2fe | 3985 | result = neigh_update_internal(DPLANE_OP_VTEP_ADD, ifp, &mac, |
88217099 | 3986 | AF_ETHERNET, &addr, 0, 0, 0, 0); |
0bbd4ff4 MS |
3987 | |
3988 | return result; | |
3989 | } | |
3990 | ||
3991 | /* | |
3992 | * Enqueue evpn VTEP add for the dataplane. | |
3993 | */ | |
3994 | enum zebra_dplane_result dplane_vtep_delete(const struct interface *ifp, | |
3995 | const struct in_addr *ip, | |
3996 | vni_t vni) | |
3997 | { | |
3998 | enum zebra_dplane_result result; | |
3999 | struct ethaddr mac = { {0, 0, 0, 0, 0, 0} }; | |
4000 | struct ipaddr addr; | |
4001 | ||
4002 | if (IS_ZEBRA_DEBUG_VXLAN) | |
4003 | zlog_debug( | |
9bcef951 MS |
4004 | "Uninstall %pI4 from flood list for VNI %u intf %s(%u)", |
4005 | ip, vni, ifp->name, ifp->ifindex); | |
0bbd4ff4 MS |
4006 | |
4007 | SET_IPADDR_V4(&addr); | |
4008 | addr.ipaddr_v4 = *ip; | |
4009 | ||
0a27a2fe PG |
4010 | result = neigh_update_internal(DPLANE_OP_VTEP_DELETE, ifp, |
4011 | (const void *)&mac, AF_ETHERNET, &addr, | |
88217099 | 4012 | 0, 0, 0, 0); |
0bbd4ff4 MS |
4013 | |
4014 | return result; | |
4015 | } | |
4016 | ||
d68e74b4 JU |
4017 | enum zebra_dplane_result dplane_neigh_discover(const struct interface *ifp, |
4018 | const struct ipaddr *ip) | |
4019 | { | |
4020 | enum zebra_dplane_result result; | |
4021 | ||
0a27a2fe PG |
4022 | result = neigh_update_internal(DPLANE_OP_NEIGH_DISCOVER, ifp, NULL, |
4023 | AF_ETHERNET, ip, DPLANE_NTF_USE, | |
88217099 | 4024 | DPLANE_NUD_INCOMPLETE, 0, 0); |
d68e74b4 JU |
4025 | |
4026 | return result; | |
4027 | } | |
4028 | ||
e18747a9 PG |
4029 | enum zebra_dplane_result dplane_neigh_table_update(const struct interface *ifp, |
4030 | const uint8_t family, | |
4031 | const uint32_t app_probes, | |
4032 | const uint32_t ucast_probes, | |
4033 | const uint32_t mcast_probes) | |
4034 | { | |
4035 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
4036 | int ret; | |
4037 | struct zebra_dplane_ctx *ctx = NULL; | |
4038 | struct zebra_ns *zns; | |
4039 | enum dplane_op_e op = DPLANE_OP_NEIGH_TABLE_UPDATE; | |
4040 | ||
4041 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) { | |
4042 | zlog_debug("set neigh ctx %s: ifp %s, family %s", | |
4043 | dplane_op2str(op), ifp->name, family2str(family)); | |
4044 | } | |
4045 | ||
4046 | ctx = dplane_ctx_alloc(); | |
4047 | ||
4048 | ctx->zd_op = op; | |
4049 | ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; | |
4050 | ctx->zd_vrf_id = ifp->vrf_id; | |
4051 | ||
4052 | zns = zebra_ns_lookup(ifp->vrf_id); | |
4053 | dplane_ctx_ns_init(ctx, zns, false); | |
4054 | ||
4055 | strlcpy(ctx->zd_ifname, ifp->name, sizeof(ctx->zd_ifname)); | |
4056 | ctx->zd_ifindex = ifp->ifindex; | |
4057 | ||
4058 | /* Init the neighbor-specific data area */ | |
4059 | memset(&ctx->u.neightable, 0, sizeof(ctx->u.neightable)); | |
4060 | ||
4061 | ctx->u.neightable.family = family; | |
4062 | ctx->u.neightable.app_probes = app_probes; | |
4063 | ctx->u.neightable.ucast_probes = ucast_probes; | |
4064 | ctx->u.neightable.mcast_probes = mcast_probes; | |
4065 | ||
4066 | /* Enqueue for processing on the dplane pthread */ | |
4067 | ret = dplane_update_enqueue(ctx); | |
4068 | ||
4069 | /* Increment counter */ | |
4070 | atomic_fetch_add_explicit(&zdplane_info.dg_neightable_in, 1, | |
4071 | memory_order_relaxed); | |
4072 | ||
4073 | if (ret == AOK) | |
4074 | result = ZEBRA_DPLANE_REQUEST_QUEUED; | |
4075 | else { | |
4076 | /* Error counter */ | |
4077 | atomic_fetch_add_explicit(&zdplane_info.dg_neightable_errors, 1, | |
4078 | memory_order_relaxed); | |
4079 | dplane_ctx_free(&ctx); | |
4080 | } | |
4081 | ||
4082 | return result; | |
4083 | } | |
4084 | ||
931fa60c | 4085 | /* |
d68e74b4 | 4086 | * Common helper api for neighbor updates |
931fa60c MS |
4087 | */ |
4088 | static enum zebra_dplane_result | |
0a27a2fe PG |
4089 | neigh_update_internal(enum dplane_op_e op, const struct interface *ifp, |
4090 | const void *link, const int link_family, | |
4091 | const struct ipaddr *ip, uint32_t flags, uint16_t state, | |
4092 | uint32_t update_flags, int protocol) | |
931fa60c MS |
4093 | { |
4094 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
4095 | int ret; | |
4096 | struct zebra_dplane_ctx *ctx = NULL; | |
4097 | struct zebra_ns *zns; | |
0a27a2fe PG |
4098 | const struct ethaddr *mac = NULL; |
4099 | const struct ipaddr *link_ip = NULL; | |
931fa60c | 4100 | |
0a27a2fe PG |
4101 | if (link_family == AF_ETHERNET) |
4102 | mac = (const struct ethaddr *)link; | |
4103 | else | |
4104 | link_ip = (const struct ipaddr *)link; | |
4105 | ||
4106 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) { | |
4107 | char buf1[PREFIX_STRLEN]; | |
4108 | ||
4109 | buf1[0] = '\0'; | |
4110 | if (link_family == AF_ETHERNET) | |
4111 | prefix_mac2str(mac, buf1, sizeof(buf1)); | |
4112 | else | |
4113 | ipaddr2str(link_ip, buf1, sizeof(buf1)); | |
4114 | zlog_debug("init neigh ctx %s: ifp %s, %s %s, ip %pIA", | |
4115 | dplane_op2str(op), ifp->name, | |
4116 | link_family == AF_ETHERNET ? "mac " : "link ", | |
4117 | buf1, ip); | |
4118 | } | |
931fa60c MS |
4119 | |
4120 | ctx = dplane_ctx_alloc(); | |
4121 | ||
4122 | ctx->zd_op = op; | |
4123 | ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; | |
4124 | ctx->zd_vrf_id = ifp->vrf_id; | |
0a27a2fe | 4125 | dplane_ctx_set_type(ctx, protocol); |
931fa60c MS |
4126 | |
4127 | zns = zebra_ns_lookup(ifp->vrf_id); | |
4128 | dplane_ctx_ns_init(ctx, zns, false); | |
4129 | ||
4130 | strlcpy(ctx->zd_ifname, ifp->name, sizeof(ctx->zd_ifname)); | |
4131 | ctx->zd_ifindex = ifp->ifindex; | |
4132 | ||
4133 | /* Init the neighbor-specific data area */ | |
4134 | memset(&ctx->u.neigh, 0, sizeof(ctx->u.neigh)); | |
4135 | ||
4136 | ctx->u.neigh.ip_addr = *ip; | |
4137 | if (mac) | |
0a27a2fe PG |
4138 | ctx->u.neigh.link.mac = *mac; |
4139 | else if (link_ip) | |
4140 | ctx->u.neigh.link.ip_addr = *link_ip; | |
4141 | ||
931fa60c MS |
4142 | ctx->u.neigh.flags = flags; |
4143 | ctx->u.neigh.state = state; | |
f188e68e | 4144 | ctx->u.neigh.update_flags = update_flags; |
931fa60c MS |
4145 | |
4146 | /* Enqueue for processing on the dplane pthread */ | |
4147 | ret = dplane_update_enqueue(ctx); | |
4148 | ||
4149 | /* Increment counter */ | |
4150 | atomic_fetch_add_explicit(&zdplane_info.dg_neighs_in, 1, | |
4151 | memory_order_relaxed); | |
4152 | ||
4153 | if (ret == AOK) | |
4154 | result = ZEBRA_DPLANE_REQUEST_QUEUED; | |
4155 | else { | |
4156 | /* Error counter */ | |
4157 | atomic_fetch_add_explicit(&zdplane_info.dg_neigh_errors, 1, | |
4158 | memory_order_relaxed); | |
4159 | dplane_ctx_free(&ctx); | |
4160 | } | |
4161 | ||
4162 | return result; | |
4163 | } | |
4164 | ||
f62e5480 JU |
4165 | /* |
4166 | * Common helper api for PBR rule updates | |
4167 | */ | |
4168 | static enum zebra_dplane_result | |
4169 | rule_update_internal(enum dplane_op_e op, struct zebra_pbr_rule *new_rule, | |
4170 | struct zebra_pbr_rule *old_rule) | |
4171 | { | |
4172 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
4173 | struct zebra_dplane_ctx *ctx; | |
4174 | int ret; | |
4175 | ||
4176 | ctx = dplane_ctx_alloc(); | |
4177 | ||
4178 | ret = dplane_ctx_rule_init(ctx, op, new_rule, old_rule); | |
4179 | if (ret != AOK) | |
4180 | goto done; | |
4181 | ||
4182 | ret = dplane_update_enqueue(ctx); | |
4183 | ||
4184 | done: | |
4185 | atomic_fetch_add_explicit(&zdplane_info.dg_rules_in, 1, | |
4186 | memory_order_relaxed); | |
4187 | ||
4188 | if (ret == AOK) | |
4189 | result = ZEBRA_DPLANE_REQUEST_QUEUED; | |
4190 | else { | |
4191 | atomic_fetch_add_explicit(&zdplane_info.dg_rule_errors, 1, | |
4192 | memory_order_relaxed); | |
4193 | dplane_ctx_free(&ctx); | |
4194 | } | |
4195 | ||
4196 | return result; | |
4197 | } | |
4198 | ||
4199 | enum zebra_dplane_result dplane_pbr_rule_add(struct zebra_pbr_rule *rule) | |
4200 | { | |
4201 | return rule_update_internal(DPLANE_OP_RULE_ADD, rule, NULL); | |
4202 | } | |
4203 | ||
4204 | enum zebra_dplane_result dplane_pbr_rule_delete(struct zebra_pbr_rule *rule) | |
4205 | { | |
4206 | return rule_update_internal(DPLANE_OP_RULE_DELETE, rule, NULL); | |
4207 | } | |
4208 | ||
4209 | enum zebra_dplane_result dplane_pbr_rule_update(struct zebra_pbr_rule *old_rule, | |
4210 | struct zebra_pbr_rule *new_rule) | |
4211 | { | |
4212 | return rule_update_internal(DPLANE_OP_RULE_UPDATE, new_rule, old_rule); | |
4213 | } | |
5162e000 PG |
4214 | /* |
4215 | * Common helper api for iptable updates | |
4216 | */ | |
4217 | static enum zebra_dplane_result | |
4218 | iptable_update_internal(enum dplane_op_e op, struct zebra_pbr_iptable *iptable) | |
4219 | { | |
4220 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
4221 | struct zebra_dplane_ctx *ctx; | |
4222 | int ret; | |
4223 | ||
4224 | ctx = dplane_ctx_alloc(); | |
4225 | ||
4226 | ret = dplane_ctx_iptable_init(ctx, op, iptable); | |
4227 | if (ret != AOK) | |
4228 | goto done; | |
4229 | ||
4230 | ret = dplane_update_enqueue(ctx); | |
4231 | ||
4232 | done: | |
4233 | atomic_fetch_add_explicit(&zdplane_info.dg_iptable_in, 1, | |
4234 | memory_order_relaxed); | |
4235 | ||
4236 | if (ret == AOK) | |
4237 | result = ZEBRA_DPLANE_REQUEST_QUEUED; | |
4238 | else { | |
4239 | atomic_fetch_add_explicit(&zdplane_info.dg_iptable_errors, 1, | |
4240 | memory_order_relaxed); | |
4241 | dplane_ctx_free(&ctx); | |
4242 | } | |
4243 | ||
4244 | return result; | |
4245 | } | |
4246 | ||
4247 | enum zebra_dplane_result | |
4248 | dplane_pbr_iptable_add(struct zebra_pbr_iptable *iptable) | |
4249 | { | |
4250 | return iptable_update_internal(DPLANE_OP_IPTABLE_ADD, iptable); | |
4251 | } | |
4252 | ||
4253 | enum zebra_dplane_result | |
4254 | dplane_pbr_iptable_delete(struct zebra_pbr_iptable *iptable) | |
4255 | { | |
4256 | return iptable_update_internal(DPLANE_OP_IPTABLE_DELETE, iptable); | |
4257 | } | |
f62e5480 | 4258 | |
ef524230 PG |
4259 | /* |
4260 | * Common helper api for ipset updates | |
4261 | */ | |
4262 | static enum zebra_dplane_result | |
4263 | ipset_update_internal(enum dplane_op_e op, struct zebra_pbr_ipset *ipset) | |
4264 | { | |
4265 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
4266 | struct zebra_dplane_ctx *ctx; | |
4267 | int ret; | |
4268 | ||
4269 | ctx = dplane_ctx_alloc(); | |
4270 | ||
4271 | ret = dplane_ctx_ipset_init(ctx, op, ipset); | |
4272 | if (ret != AOK) | |
4273 | goto done; | |
4274 | ||
4275 | ret = dplane_update_enqueue(ctx); | |
4276 | ||
4277 | done: | |
4278 | atomic_fetch_add_explicit(&zdplane_info.dg_ipset_in, 1, | |
4279 | memory_order_relaxed); | |
4280 | ||
4281 | if (ret == AOK) | |
4282 | result = ZEBRA_DPLANE_REQUEST_QUEUED; | |
4283 | else { | |
4284 | atomic_fetch_add_explicit(&zdplane_info.dg_ipset_errors, 1, | |
4285 | memory_order_relaxed); | |
4286 | dplane_ctx_free(&ctx); | |
4287 | } | |
4288 | ||
4289 | return result; | |
4290 | } | |
4291 | ||
4292 | enum zebra_dplane_result dplane_pbr_ipset_add(struct zebra_pbr_ipset *ipset) | |
4293 | { | |
4294 | return ipset_update_internal(DPLANE_OP_IPSET_ADD, ipset); | |
4295 | } | |
4296 | ||
4297 | enum zebra_dplane_result dplane_pbr_ipset_delete(struct zebra_pbr_ipset *ipset) | |
4298 | { | |
4299 | return ipset_update_internal(DPLANE_OP_IPSET_DELETE, ipset); | |
4300 | } | |
4301 | ||
4302 | /* | |
4303 | * Common helper api for ipset updates | |
4304 | */ | |
4305 | static enum zebra_dplane_result | |
4306 | ipset_entry_update_internal(enum dplane_op_e op, | |
4307 | struct zebra_pbr_ipset_entry *ipset_entry) | |
4308 | { | |
4309 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
4310 | struct zebra_dplane_ctx *ctx; | |
4311 | int ret; | |
4312 | ||
4313 | ctx = dplane_ctx_alloc(); | |
4314 | ||
4315 | ret = dplane_ctx_ipset_entry_init(ctx, op, ipset_entry); | |
4316 | if (ret != AOK) | |
4317 | goto done; | |
4318 | ||
4319 | ret = dplane_update_enqueue(ctx); | |
4320 | ||
4321 | done: | |
4322 | atomic_fetch_add_explicit(&zdplane_info.dg_ipset_entry_in, 1, | |
4323 | memory_order_relaxed); | |
4324 | ||
4325 | if (ret == AOK) | |
4326 | result = ZEBRA_DPLANE_REQUEST_QUEUED; | |
4327 | else { | |
4328 | atomic_fetch_add_explicit(&zdplane_info.dg_ipset_entry_errors, | |
4329 | 1, memory_order_relaxed); | |
4330 | dplane_ctx_free(&ctx); | |
4331 | } | |
4332 | ||
4333 | return result; | |
4334 | } | |
4335 | ||
4336 | enum zebra_dplane_result | |
4337 | dplane_pbr_ipset_entry_add(struct zebra_pbr_ipset_entry *ipset) | |
4338 | { | |
4339 | return ipset_entry_update_internal(DPLANE_OP_IPSET_ENTRY_ADD, ipset); | |
4340 | } | |
4341 | ||
4342 | enum zebra_dplane_result | |
4343 | dplane_pbr_ipset_entry_delete(struct zebra_pbr_ipset_entry *ipset) | |
4344 | { | |
4345 | return ipset_entry_update_internal(DPLANE_OP_IPSET_ENTRY_DELETE, ipset); | |
4346 | } | |
4347 | ||
62b4b7e4 PG |
4348 | /* |
4349 | * Common helper api for GRE set | |
4350 | */ | |
4351 | enum zebra_dplane_result | |
e3d3fa06 PG |
4352 | dplane_gre_set(struct interface *ifp, struct interface *ifp_link, |
4353 | unsigned int mtu, const struct zebra_l2info_gre *gre_info) | |
62b4b7e4 PG |
4354 | { |
4355 | enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
4356 | struct zebra_dplane_ctx *ctx; | |
4357 | enum dplane_op_e op = DPLANE_OP_GRE_SET; | |
4358 | int ret; | |
4359 | struct zebra_ns *zns; | |
4360 | ||
4361 | ctx = dplane_ctx_alloc(); | |
4362 | ||
4363 | if (!ifp) | |
4364 | return result; | |
4365 | ||
4366 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) { | |
4367 | zlog_debug("init dplane ctx %s: if %s link %s%s", | |
4368 | dplane_op2str(op), ifp->name, | |
4369 | ifp_link ? "set" : "unset", ifp_link ? | |
4370 | ifp_link->name : ""); | |
4371 | } | |
4372 | ||
4373 | ctx->zd_op = op; | |
4374 | ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; | |
4375 | zns = zebra_ns_lookup(ifp->vrf_id); | |
4376 | if (!zns) | |
4377 | return result; | |
4378 | dplane_ctx_ns_init(ctx, zns, false); | |
4379 | ||
4380 | dplane_ctx_set_ifname(ctx, ifp->name); | |
4381 | ctx->zd_vrf_id = ifp->vrf_id; | |
4382 | ctx->zd_ifindex = ifp->ifindex; | |
4383 | if (ifp_link) | |
4384 | ctx->u.gre.link_ifindex = ifp_link->ifindex; | |
4385 | else | |
4386 | ctx->u.gre.link_ifindex = 0; | |
e3d3fa06 PG |
4387 | if (gre_info) |
4388 | memcpy(&ctx->u.gre.info, gre_info, sizeof(ctx->u.gre.info)); | |
db51f0cd PG |
4389 | ctx->u.gre.mtu = mtu; |
4390 | ||
62b4b7e4 PG |
4391 | ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; |
4392 | ||
4393 | /* Enqueue context for processing */ | |
4394 | ret = dplane_update_enqueue(ctx); | |
4395 | ||
4396 | /* Update counter */ | |
4397 | atomic_fetch_add_explicit(&zdplane_info.dg_gre_set_in, 1, | |
4398 | memory_order_relaxed); | |
4399 | ||
4400 | if (ret == AOK) | |
4401 | result = ZEBRA_DPLANE_REQUEST_QUEUED; | |
4402 | else { | |
4403 | atomic_fetch_add_explicit( | |
4404 | &zdplane_info.dg_gre_set_errors, 1, | |
4405 | memory_order_relaxed); | |
4406 | if (ctx) | |
4407 | dplane_ctx_free(&ctx); | |
4408 | result = ZEBRA_DPLANE_REQUEST_FAILURE; | |
4409 | } | |
4410 | return result; | |
4411 | } | |
4412 | ||
1d11b21f MS |
4413 | /* |
4414 | * Handler for 'show dplane' | |
4415 | */ | |
4416 | int dplane_show_helper(struct vty *vty, bool detailed) | |
4417 | { | |
16c628de MS |
4418 | uint64_t queued, queue_max, limit, errs, incoming, yields, |
4419 | other_errs; | |
1d11b21f | 4420 | |
4dfd7a02 | 4421 | /* Using atomics because counters are being changed in different |
c831033f | 4422 | * pthread contexts. |
4dfd7a02 | 4423 | */ |
25779064 | 4424 | incoming = atomic_load_explicit(&zdplane_info.dg_routes_in, |
1d11b21f | 4425 | memory_order_relaxed); |
91f16812 MS |
4426 | limit = atomic_load_explicit(&zdplane_info.dg_max_queued_updates, |
4427 | memory_order_relaxed); | |
25779064 | 4428 | queued = atomic_load_explicit(&zdplane_info.dg_routes_queued, |
1d11b21f | 4429 | memory_order_relaxed); |
25779064 | 4430 | queue_max = atomic_load_explicit(&zdplane_info.dg_routes_queued_max, |
4dfd7a02 | 4431 | memory_order_relaxed); |
25779064 | 4432 | errs = atomic_load_explicit(&zdplane_info.dg_route_errors, |
1d11b21f | 4433 | memory_order_relaxed); |
c831033f MS |
4434 | yields = atomic_load_explicit(&zdplane_info.dg_update_yields, |
4435 | memory_order_relaxed); | |
16c628de MS |
4436 | other_errs = atomic_load_explicit(&zdplane_info.dg_other_errors, |
4437 | memory_order_relaxed); | |
1d11b21f | 4438 | |
c831033f MS |
4439 | vty_out(vty, "Zebra dataplane:\nRoute updates: %"PRIu64"\n", |
4440 | incoming); | |
1d11b21f | 4441 | vty_out(vty, "Route update errors: %"PRIu64"\n", errs); |
16c628de | 4442 | vty_out(vty, "Other errors : %"PRIu64"\n", other_errs); |
91f16812 | 4443 | vty_out(vty, "Route update queue limit: %"PRIu64"\n", limit); |
1d11b21f | 4444 | vty_out(vty, "Route update queue depth: %"PRIu64"\n", queued); |
4dfd7a02 | 4445 | vty_out(vty, "Route update queue max: %"PRIu64"\n", queue_max); |
4280d91c MS |
4446 | vty_out(vty, "Dplane update yields: %"PRIu64"\n", yields); |
4447 | ||
4448 | incoming = atomic_load_explicit(&zdplane_info.dg_lsps_in, | |
4449 | memory_order_relaxed); | |
4450 | errs = atomic_load_explicit(&zdplane_info.dg_lsp_errors, | |
4451 | memory_order_relaxed); | |
4452 | vty_out(vty, "LSP updates: %"PRIu64"\n", incoming); | |
4453 | vty_out(vty, "LSP update errors: %"PRIu64"\n", errs); | |
4454 | ||
4455 | incoming = atomic_load_explicit(&zdplane_info.dg_pws_in, | |
4456 | memory_order_relaxed); | |
4457 | errs = atomic_load_explicit(&zdplane_info.dg_pw_errors, | |
4458 | memory_order_relaxed); | |
4459 | vty_out(vty, "PW updates: %"PRIu64"\n", incoming); | |
4460 | vty_out(vty, "PW update errors: %"PRIu64"\n", errs); | |
4461 | ||
4462 | incoming = atomic_load_explicit(&zdplane_info.dg_intf_addrs_in, | |
4463 | memory_order_relaxed); | |
4464 | errs = atomic_load_explicit(&zdplane_info.dg_intf_addr_errors, | |
4465 | memory_order_relaxed); | |
4466 | vty_out(vty, "Intf addr updates: %"PRIu64"\n", incoming); | |
4467 | vty_out(vty, "Intf addr errors: %"PRIu64"\n", errs); | |
4468 | ||
4469 | incoming = atomic_load_explicit(&zdplane_info.dg_macs_in, | |
4470 | memory_order_relaxed); | |
4471 | errs = atomic_load_explicit(&zdplane_info.dg_mac_errors, | |
4472 | memory_order_relaxed); | |
4473 | vty_out(vty, "EVPN MAC updates: %"PRIu64"\n", incoming); | |
4474 | vty_out(vty, "EVPN MAC errors: %"PRIu64"\n", errs); | |
1d11b21f | 4475 | |
931fa60c MS |
4476 | incoming = atomic_load_explicit(&zdplane_info.dg_neighs_in, |
4477 | memory_order_relaxed); | |
4478 | errs = atomic_load_explicit(&zdplane_info.dg_neigh_errors, | |
4479 | memory_order_relaxed); | |
4480 | vty_out(vty, "EVPN neigh updates: %"PRIu64"\n", incoming); | |
4481 | vty_out(vty, "EVPN neigh errors: %"PRIu64"\n", errs); | |
4482 | ||
60d8d43b JU |
4483 | incoming = atomic_load_explicit(&zdplane_info.dg_rules_in, |
4484 | memory_order_relaxed); | |
4485 | errs = atomic_load_explicit(&zdplane_info.dg_rule_errors, | |
4486 | memory_order_relaxed); | |
4487 | vty_out(vty, "Rule updates: %" PRIu64 "\n", incoming); | |
4488 | vty_out(vty, "Rule errors: %" PRIu64 "\n", errs); | |
4489 | ||
c60522f7 AK |
4490 | incoming = atomic_load_explicit(&zdplane_info.dg_br_port_in, |
4491 | memory_order_relaxed); | |
4492 | errs = atomic_load_explicit(&zdplane_info.dg_br_port_errors, | |
4493 | memory_order_relaxed); | |
4494 | vty_out(vty, "Bridge port updates: %" PRIu64 "\n", incoming); | |
4495 | vty_out(vty, "Bridge port errors: %" PRIu64 "\n", errs); | |
4496 | ||
5162e000 PG |
4497 | incoming = atomic_load_explicit(&zdplane_info.dg_iptable_in, |
4498 | memory_order_relaxed); | |
4499 | errs = atomic_load_explicit(&zdplane_info.dg_iptable_errors, | |
4500 | memory_order_relaxed); | |
4501 | vty_out(vty, "IPtable updates: %" PRIu64 "\n", incoming); | |
4502 | vty_out(vty, "IPtable errors: %" PRIu64 "\n", errs); | |
ef524230 PG |
4503 | incoming = atomic_load_explicit(&zdplane_info.dg_ipset_in, |
4504 | memory_order_relaxed); | |
4505 | errs = atomic_load_explicit(&zdplane_info.dg_ipset_errors, | |
4506 | memory_order_relaxed); | |
4507 | vty_out(vty, "IPset updates: %" PRIu64 "\n", incoming); | |
4508 | vty_out(vty, "IPset errors: %" PRIu64 "\n", errs); | |
4509 | incoming = atomic_load_explicit(&zdplane_info.dg_ipset_entry_in, | |
4510 | memory_order_relaxed); | |
4511 | errs = atomic_load_explicit(&zdplane_info.dg_ipset_entry_errors, | |
4512 | memory_order_relaxed); | |
4513 | vty_out(vty, "IPset entry updates: %" PRIu64 "\n", incoming); | |
4514 | vty_out(vty, "IPset entry errors: %" PRIu64 "\n", errs); | |
e18747a9 PG |
4515 | |
4516 | incoming = atomic_load_explicit(&zdplane_info.dg_neightable_in, | |
4517 | memory_order_relaxed); | |
4518 | errs = atomic_load_explicit(&zdplane_info.dg_neightable_errors, | |
4519 | memory_order_relaxed); | |
4520 | vty_out(vty, "Neighbor Table updates: %"PRIu64"\n", incoming); | |
4521 | vty_out(vty, "Neighbor Table errors: %"PRIu64"\n", errs); | |
62b4b7e4 PG |
4522 | |
4523 | incoming = atomic_load_explicit(&zdplane_info.dg_gre_set_in, | |
4524 | memory_order_relaxed); | |
4525 | errs = atomic_load_explicit(&zdplane_info.dg_gre_set_errors, | |
4526 | memory_order_relaxed); | |
4527 | vty_out(vty, "GRE set updates: %"PRIu64"\n", incoming); | |
4528 | vty_out(vty, "GRE set errors: %"PRIu64"\n", errs); | |
1d11b21f MS |
4529 | return CMD_SUCCESS; |
4530 | } | |
4531 | ||
4532 | /* | |
4533 | * Handler for 'show dplane providers' | |
4534 | */ | |
4535 | int dplane_show_provs_helper(struct vty *vty, bool detailed) | |
4536 | { | |
c831033f | 4537 | struct zebra_dplane_provider *prov; |
a88a7c8d | 4538 | uint64_t in, in_q, in_max, out, out_q, out_max; |
c831033f MS |
4539 | |
4540 | vty_out(vty, "Zebra dataplane providers:\n"); | |
4541 | ||
4542 | DPLANE_LOCK(); | |
4543 | prov = TAILQ_FIRST(&zdplane_info.dg_providers_q); | |
4544 | DPLANE_UNLOCK(); | |
4545 | ||
4546 | /* Show counters, useful info from each registered provider */ | |
4547 | while (prov) { | |
4548 | ||
4549 | in = atomic_load_explicit(&prov->dp_in_counter, | |
4550 | memory_order_relaxed); | |
a88a7c8d MS |
4551 | in_q = atomic_load_explicit(&prov->dp_in_queued, |
4552 | memory_order_relaxed); | |
c831033f MS |
4553 | in_max = atomic_load_explicit(&prov->dp_in_max, |
4554 | memory_order_relaxed); | |
4555 | out = atomic_load_explicit(&prov->dp_out_counter, | |
4556 | memory_order_relaxed); | |
a88a7c8d MS |
4557 | out_q = atomic_load_explicit(&prov->dp_out_queued, |
4558 | memory_order_relaxed); | |
c831033f MS |
4559 | out_max = atomic_load_explicit(&prov->dp_out_max, |
4560 | memory_order_relaxed); | |
4561 | ||
a88a7c8d MS |
4562 | vty_out(vty, "%s (%u): in: %"PRIu64", q: %"PRIu64", q_max: %"PRIu64", out: %"PRIu64", q: %"PRIu64", q_max: %"PRIu64"\n", |
4563 | prov->dp_name, prov->dp_id, in, in_q, in_max, | |
4564 | out, out_q, out_max); | |
c831033f MS |
4565 | |
4566 | DPLANE_LOCK(); | |
4567 | prov = TAILQ_NEXT(prov, dp_prov_link); | |
4568 | DPLANE_UNLOCK(); | |
4569 | } | |
1d11b21f MS |
4570 | |
4571 | return CMD_SUCCESS; | |
4572 | } | |
4573 | ||
f26730e1 MS |
4574 | /* |
4575 | * Helper for 'show run' etc. | |
4576 | */ | |
4577 | int dplane_config_write_helper(struct vty *vty) | |
4578 | { | |
4579 | if (zdplane_info.dg_max_queued_updates != DPLANE_DEFAULT_MAX_QUEUED) | |
4580 | vty_out(vty, "zebra dplane limit %u\n", | |
4581 | zdplane_info.dg_max_queued_updates); | |
4582 | ||
4583 | return 0; | |
4584 | } | |
4585 | ||
b8e0423d MS |
4586 | /* |
4587 | * Provider registration | |
4588 | */ | |
4589 | int dplane_provider_register(const char *name, | |
c831033f MS |
4590 | enum dplane_provider_prio prio, |
4591 | int flags, | |
1dd4ea8a | 4592 | int (*start_fp)(struct zebra_dplane_provider *), |
4c206c8f MS |
4593 | int (*fp)(struct zebra_dplane_provider *), |
4594 | int (*fini_fp)(struct zebra_dplane_provider *, | |
4595 | bool early), | |
1ff8a248 MS |
4596 | void *data, |
4597 | struct zebra_dplane_provider **prov_p) | |
b8e0423d MS |
4598 | { |
4599 | int ret = 0; | |
6fb51ccb | 4600 | struct zebra_dplane_provider *p = NULL, *last; |
b8e0423d MS |
4601 | |
4602 | /* Validate */ | |
4603 | if (fp == NULL) { | |
4604 | ret = EINVAL; | |
4605 | goto done; | |
4606 | } | |
4607 | ||
4608 | if (prio <= DPLANE_PRIO_NONE || | |
1bcea841 | 4609 | prio > DPLANE_PRIO_LAST) { |
b8e0423d MS |
4610 | ret = EINVAL; |
4611 | goto done; | |
4612 | } | |
4613 | ||
4614 | /* Allocate and init new provider struct */ | |
25779064 | 4615 | p = XCALLOC(MTYPE_DP_PROV, sizeof(struct zebra_dplane_provider)); |
b8e0423d | 4616 | |
c831033f MS |
4617 | pthread_mutex_init(&(p->dp_mutex), NULL); |
4618 | TAILQ_INIT(&(p->dp_ctx_in_q)); | |
4619 | TAILQ_INIT(&(p->dp_ctx_out_q)); | |
b8e0423d | 4620 | |
932dbb4d | 4621 | p->dp_flags = flags; |
b8e0423d MS |
4622 | p->dp_priority = prio; |
4623 | p->dp_fp = fp; | |
1dd4ea8a | 4624 | p->dp_start = start_fp; |
18c37974 | 4625 | p->dp_fini = fini_fp; |
c831033f | 4626 | p->dp_data = data; |
18c37974 | 4627 | |
c831033f | 4628 | /* Lock - the dplane pthread may be running */ |
18c37974 | 4629 | DPLANE_LOCK(); |
b8e0423d | 4630 | |
25779064 | 4631 | p->dp_id = ++zdplane_info.dg_provider_id; |
b8e0423d | 4632 | |
c831033f MS |
4633 | if (name) |
4634 | strlcpy(p->dp_name, name, DPLANE_PROVIDER_NAMELEN); | |
4635 | else | |
4636 | snprintf(p->dp_name, DPLANE_PROVIDER_NAMELEN, | |
4637 | "provider-%u", p->dp_id); | |
4638 | ||
b8e0423d | 4639 | /* Insert into list ordered by priority */ |
c831033f | 4640 | TAILQ_FOREACH(last, &zdplane_info.dg_providers_q, dp_prov_link) { |
5709131c | 4641 | if (last->dp_priority > p->dp_priority) |
b8e0423d | 4642 | break; |
b8e0423d MS |
4643 | } |
4644 | ||
5709131c | 4645 | if (last) |
c831033f | 4646 | TAILQ_INSERT_BEFORE(last, p, dp_prov_link); |
5709131c | 4647 | else |
25779064 | 4648 | TAILQ_INSERT_TAIL(&zdplane_info.dg_providers_q, p, |
c831033f | 4649 | dp_prov_link); |
b8e0423d | 4650 | |
18c37974 MS |
4651 | /* And unlock */ |
4652 | DPLANE_UNLOCK(); | |
4653 | ||
c831033f MS |
4654 | if (IS_ZEBRA_DEBUG_DPLANE) |
4655 | zlog_debug("dplane: registered new provider '%s' (%u), prio %d", | |
4656 | p->dp_name, p->dp_id, p->dp_priority); | |
4657 | ||
b8e0423d | 4658 | done: |
1ff8a248 MS |
4659 | if (prov_p) |
4660 | *prov_p = p; | |
4661 | ||
5709131c | 4662 | return ret; |
b8e0423d MS |
4663 | } |
4664 | ||
c831033f MS |
4665 | /* Accessors for provider attributes */ |
4666 | const char *dplane_provider_get_name(const struct zebra_dplane_provider *prov) | |
4667 | { | |
4668 | return prov->dp_name; | |
4669 | } | |
4670 | ||
4671 | uint32_t dplane_provider_get_id(const struct zebra_dplane_provider *prov) | |
4672 | { | |
4673 | return prov->dp_id; | |
4674 | } | |
4675 | ||
4676 | void *dplane_provider_get_data(const struct zebra_dplane_provider *prov) | |
4677 | { | |
4678 | return prov->dp_data; | |
4679 | } | |
4680 | ||
4681 | int dplane_provider_get_work_limit(const struct zebra_dplane_provider *prov) | |
4682 | { | |
4683 | return zdplane_info.dg_updates_per_cycle; | |
4684 | } | |
4685 | ||
ad6aad4d MS |
4686 | /* Lock/unlock a provider's mutex - iff the provider was registered with |
4687 | * the THREADED flag. | |
4688 | */ | |
4689 | void dplane_provider_lock(struct zebra_dplane_provider *prov) | |
4690 | { | |
4691 | if (dplane_provider_is_threaded(prov)) | |
4692 | DPLANE_PROV_LOCK(prov); | |
4693 | } | |
4694 | ||
4695 | void dplane_provider_unlock(struct zebra_dplane_provider *prov) | |
4696 | { | |
4697 | if (dplane_provider_is_threaded(prov)) | |
4698 | DPLANE_PROV_UNLOCK(prov); | |
4699 | } | |
4700 | ||
c831033f MS |
4701 | /* |
4702 | * Dequeue and maintain associated counter | |
4703 | */ | |
4704 | struct zebra_dplane_ctx *dplane_provider_dequeue_in_ctx( | |
4705 | struct zebra_dplane_provider *prov) | |
4706 | { | |
4707 | struct zebra_dplane_ctx *ctx = NULL; | |
4708 | ||
ad6aad4d | 4709 | dplane_provider_lock(prov); |
c831033f MS |
4710 | |
4711 | ctx = TAILQ_FIRST(&(prov->dp_ctx_in_q)); | |
4712 | if (ctx) { | |
4713 | TAILQ_REMOVE(&(prov->dp_ctx_in_q), ctx, zd_q_entries); | |
c9d17fe8 MS |
4714 | |
4715 | atomic_fetch_sub_explicit(&prov->dp_in_queued, 1, | |
4716 | memory_order_relaxed); | |
c831033f MS |
4717 | } |
4718 | ||
ad6aad4d | 4719 | dplane_provider_unlock(prov); |
c831033f MS |
4720 | |
4721 | return ctx; | |
4722 | } | |
4723 | ||
4724 | /* | |
4725 | * Dequeue work to a list, return count | |
4726 | */ | |
4727 | int dplane_provider_dequeue_in_list(struct zebra_dplane_provider *prov, | |
4728 | struct dplane_ctx_q *listp) | |
4729 | { | |
4730 | int limit, ret; | |
4731 | struct zebra_dplane_ctx *ctx; | |
4732 | ||
4733 | limit = zdplane_info.dg_updates_per_cycle; | |
4734 | ||
ad6aad4d | 4735 | dplane_provider_lock(prov); |
c831033f MS |
4736 | |
4737 | for (ret = 0; ret < limit; ret++) { | |
4738 | ctx = TAILQ_FIRST(&(prov->dp_ctx_in_q)); | |
4739 | if (ctx) { | |
4740 | TAILQ_REMOVE(&(prov->dp_ctx_in_q), ctx, zd_q_entries); | |
4741 | ||
4742 | TAILQ_INSERT_TAIL(listp, ctx, zd_q_entries); | |
4743 | } else { | |
4744 | break; | |
4745 | } | |
4746 | } | |
4747 | ||
c9d17fe8 MS |
4748 | if (ret > 0) |
4749 | atomic_fetch_sub_explicit(&prov->dp_in_queued, ret, | |
4750 | memory_order_relaxed); | |
4751 | ||
ad6aad4d | 4752 | dplane_provider_unlock(prov); |
c831033f MS |
4753 | |
4754 | return ret; | |
4755 | } | |
4756 | ||
53706b4e DE |
4757 | uint32_t dplane_provider_out_ctx_queue_len(struct zebra_dplane_provider *prov) |
4758 | { | |
4759 | return atomic_load_explicit(&(prov->dp_out_counter), | |
4760 | memory_order_relaxed); | |
4761 | } | |
4762 | ||
c831033f MS |
4763 | /* |
4764 | * Enqueue and maintain associated counter | |
4765 | */ | |
4766 | void dplane_provider_enqueue_out_ctx(struct zebra_dplane_provider *prov, | |
4767 | struct zebra_dplane_ctx *ctx) | |
4768 | { | |
a88a7c8d MS |
4769 | uint64_t curr, high; |
4770 | ||
ad6aad4d | 4771 | dplane_provider_lock(prov); |
c831033f MS |
4772 | |
4773 | TAILQ_INSERT_TAIL(&(prov->dp_ctx_out_q), ctx, | |
4774 | zd_q_entries); | |
4775 | ||
a88a7c8d MS |
4776 | /* Maintain out-queue counters */ |
4777 | atomic_fetch_add_explicit(&(prov->dp_out_queued), 1, | |
4778 | memory_order_relaxed); | |
4779 | curr = atomic_load_explicit(&prov->dp_out_queued, | |
4780 | memory_order_relaxed); | |
4781 | high = atomic_load_explicit(&prov->dp_out_max, | |
4782 | memory_order_relaxed); | |
4783 | if (curr > high) | |
4784 | atomic_store_explicit(&prov->dp_out_max, curr, | |
4785 | memory_order_relaxed); | |
4786 | ||
ad6aad4d | 4787 | dplane_provider_unlock(prov); |
c831033f MS |
4788 | |
4789 | atomic_fetch_add_explicit(&(prov->dp_out_counter), 1, | |
4790 | memory_order_relaxed); | |
4791 | } | |
4792 | ||
62b8bb7a MS |
4793 | /* |
4794 | * Accessor for provider object | |
4795 | */ | |
c831033f MS |
4796 | bool dplane_provider_is_threaded(const struct zebra_dplane_provider *prov) |
4797 | { | |
4798 | return (prov->dp_flags & DPLANE_PROV_FLAG_THREADED); | |
4799 | } | |
4800 | ||
62b8bb7a MS |
4801 | /* |
4802 | * Internal helper that copies information from a zebra ns object; this is | |
4803 | * called in the zebra main pthread context as part of dplane ctx init. | |
4804 | */ | |
4805 | static void dplane_info_from_zns(struct zebra_dplane_info *ns_info, | |
4806 | struct zebra_ns *zns) | |
4807 | { | |
4808 | ns_info->ns_id = zns->ns_id; | |
4809 | ||
4810 | #if defined(HAVE_NETLINK) | |
4811 | ns_info->is_cmd = true; | |
80dcc388 | 4812 | ns_info->nls = zns->netlink_dplane_out; |
62b8bb7a MS |
4813 | #endif /* NETLINK */ |
4814 | } | |
4815 | ||
c831033f MS |
4816 | /* |
4817 | * Provider api to signal that work/events are available | |
4818 | * for the dataplane pthread. | |
4819 | */ | |
4820 | int dplane_provider_work_ready(void) | |
4821 | { | |
e5a60d82 MS |
4822 | /* Note that during zebra startup, we may be offered work before |
4823 | * the dataplane pthread (and thread-master) are ready. We want to | |
4824 | * enqueue the work, but the event-scheduling machinery may not be | |
4825 | * available. | |
4826 | */ | |
4827 | if (zdplane_info.dg_run) { | |
4828 | thread_add_event(zdplane_info.dg_master, | |
4829 | dplane_thread_loop, NULL, 0, | |
4830 | &zdplane_info.dg_t_update); | |
4831 | } | |
c831033f MS |
4832 | |
4833 | return AOK; | |
4834 | } | |
4835 | ||
593e4eb1 MS |
4836 | /* |
4837 | * Enqueue a context directly to zebra main. | |
4838 | */ | |
4839 | void dplane_provider_enqueue_to_zebra(struct zebra_dplane_ctx *ctx) | |
4840 | { | |
4841 | struct dplane_ctx_q temp_list; | |
4842 | ||
4843 | /* Zebra's api takes a list, so we need to use a temporary list */ | |
4844 | TAILQ_INIT(&temp_list); | |
4845 | ||
4846 | TAILQ_INSERT_TAIL(&temp_list, ctx, zd_q_entries); | |
4847 | (zdplane_info.dg_results_cb)(&temp_list); | |
4848 | } | |
4849 | ||
7cdb1a84 | 4850 | /* |
c831033f | 4851 | * Kernel dataplane provider |
7cdb1a84 | 4852 | */ |
c831033f | 4853 | |
fef24b03 | 4854 | static void kernel_dplane_log_detail(struct zebra_dplane_ctx *ctx) |
c10a646d | 4855 | { |
fef24b03 | 4856 | char buf[PREFIX_STRLEN]; |
c10a646d | 4857 | |
fef24b03 | 4858 | switch (dplane_ctx_get_op(ctx)) { |
16c628de | 4859 | |
fef24b03 JU |
4860 | case DPLANE_OP_ROUTE_INSTALL: |
4861 | case DPLANE_OP_ROUTE_UPDATE: | |
4862 | case DPLANE_OP_ROUTE_DELETE: | |
2dbe669b DA |
4863 | zlog_debug("%u:%pFX Dplane route update ctx %p op %s", |
4864 | dplane_ctx_get_vrf(ctx), dplane_ctx_get_dest(ctx), | |
4865 | ctx, dplane_op2str(dplane_ctx_get_op(ctx))); | |
fef24b03 | 4866 | break; |
64168803 | 4867 | |
fef24b03 JU |
4868 | case DPLANE_OP_NH_INSTALL: |
4869 | case DPLANE_OP_NH_UPDATE: | |
4870 | case DPLANE_OP_NH_DELETE: | |
f820d025 | 4871 | zlog_debug("ID (%u) Dplane nexthop update ctx %p op %s", |
0c8215cb | 4872 | dplane_ctx_get_nhe_id(ctx), ctx, |
f820d025 | 4873 | dplane_op2str(dplane_ctx_get_op(ctx))); |
fef24b03 | 4874 | break; |
f820d025 | 4875 | |
fef24b03 JU |
4876 | case DPLANE_OP_LSP_INSTALL: |
4877 | case DPLANE_OP_LSP_UPDATE: | |
4878 | case DPLANE_OP_LSP_DELETE: | |
4879 | break; | |
f820d025 | 4880 | |
fef24b03 JU |
4881 | case DPLANE_OP_PW_INSTALL: |
4882 | case DPLANE_OP_PW_UNINSTALL: | |
4883 | zlog_debug("Dplane pw %s: op %s af %d loc: %u rem: %u", | |
4884 | dplane_ctx_get_ifname(ctx), | |
4885 | dplane_op2str(ctx->zd_op), dplane_ctx_get_pw_af(ctx), | |
4886 | dplane_ctx_get_pw_local_label(ctx), | |
4887 | dplane_ctx_get_pw_remote_label(ctx)); | |
4888 | break; | |
4889 | ||
4890 | case DPLANE_OP_ADDR_INSTALL: | |
4891 | case DPLANE_OP_ADDR_UNINSTALL: | |
2dbe669b | 4892 | zlog_debug("Dplane intf %s, idx %u, addr %pFX", |
fef24b03 | 4893 | dplane_op2str(dplane_ctx_get_op(ctx)), |
2dbe669b DA |
4894 | dplane_ctx_get_ifindex(ctx), |
4895 | dplane_ctx_get_intf_addr(ctx)); | |
fef24b03 | 4896 | break; |
036d93c0 | 4897 | |
fef24b03 JU |
4898 | case DPLANE_OP_MAC_INSTALL: |
4899 | case DPLANE_OP_MAC_DELETE: | |
036d93c0 MS |
4900 | prefix_mac2str(dplane_ctx_mac_get_addr(ctx), buf, |
4901 | sizeof(buf)); | |
4902 | ||
4903 | zlog_debug("Dplane %s, mac %s, ifindex %u", | |
4904 | dplane_op2str(dplane_ctx_get_op(ctx)), | |
4905 | buf, dplane_ctx_get_ifindex(ctx)); | |
fef24b03 | 4906 | break; |
931fa60c | 4907 | |
fef24b03 JU |
4908 | case DPLANE_OP_NEIGH_INSTALL: |
4909 | case DPLANE_OP_NEIGH_UPDATE: | |
4910 | case DPLANE_OP_NEIGH_DELETE: | |
4911 | case DPLANE_OP_VTEP_ADD: | |
4912 | case DPLANE_OP_VTEP_DELETE: | |
d68e74b4 | 4913 | case DPLANE_OP_NEIGH_DISCOVER: |
0a27a2fe PG |
4914 | case DPLANE_OP_NEIGH_IP_INSTALL: |
4915 | case DPLANE_OP_NEIGH_IP_DELETE: | |
931fa60c MS |
4916 | ipaddr2str(dplane_ctx_neigh_get_ipaddr(ctx), buf, |
4917 | sizeof(buf)); | |
4918 | ||
4919 | zlog_debug("Dplane %s, ip %s, ifindex %u", | |
4920 | dplane_op2str(dplane_ctx_get_op(ctx)), | |
4921 | buf, dplane_ctx_get_ifindex(ctx)); | |
fef24b03 | 4922 | break; |
931fa60c | 4923 | |
fef24b03 JU |
4924 | case DPLANE_OP_RULE_ADD: |
4925 | case DPLANE_OP_RULE_DELETE: | |
4926 | case DPLANE_OP_RULE_UPDATE: | |
f62e5480 JU |
4927 | zlog_debug("Dplane rule update op %s, if %s(%u), ctx %p", |
4928 | dplane_op2str(dplane_ctx_get_op(ctx)), | |
4929 | dplane_ctx_get_ifname(ctx), | |
4930 | dplane_ctx_get_ifindex(ctx), ctx); | |
fef24b03 | 4931 | break; |
f62e5480 | 4932 | |
fef24b03 JU |
4933 | case DPLANE_OP_SYS_ROUTE_ADD: |
4934 | case DPLANE_OP_SYS_ROUTE_DELETE: | |
4935 | case DPLANE_OP_ROUTE_NOTIFY: | |
4936 | case DPLANE_OP_LSP_NOTIFY: | |
c60522f7 | 4937 | case DPLANE_OP_BR_PORT_UPDATE: |
fef24b03 JU |
4938 | |
4939 | case DPLANE_OP_NONE: | |
4940 | break; | |
5162e000 PG |
4941 | |
4942 | case DPLANE_OP_IPTABLE_ADD: | |
4943 | case DPLANE_OP_IPTABLE_DELETE: { | |
4944 | struct zebra_pbr_iptable ipt; | |
4945 | ||
4946 | if (dplane_ctx_get_pbr_iptable(ctx, &ipt)) | |
4947 | zlog_debug("Dplane iptable update op %s, unique(%u), ctx %p", | |
4948 | dplane_op2str(dplane_ctx_get_op(ctx)), ipt.unique, ctx); | |
4949 | } break; | |
ef524230 PG |
4950 | case DPLANE_OP_IPSET_ADD: |
4951 | case DPLANE_OP_IPSET_DELETE: { | |
4952 | struct zebra_pbr_ipset ipset; | |
4953 | ||
4954 | if (dplane_ctx_get_pbr_ipset(ctx, &ipset)) | |
4955 | zlog_debug("Dplane ipset update op %s, unique(%u), ctx %p", | |
4956 | dplane_op2str(dplane_ctx_get_op(ctx)), | |
4957 | ipset.unique, ctx); | |
4958 | } break; | |
4959 | case DPLANE_OP_IPSET_ENTRY_ADD: | |
4960 | case DPLANE_OP_IPSET_ENTRY_DELETE: { | |
4961 | struct zebra_pbr_ipset_entry ipent; | |
4962 | ||
4963 | if (dplane_ctx_get_pbr_ipset_entry(ctx, &ipent)) | |
4964 | zlog_debug("Dplane ipset entry update op %s, unique(%u), ctx %p", | |
4965 | dplane_op2str(dplane_ctx_get_op(ctx)), | |
4966 | ipent.unique, ctx); | |
4967 | } break; | |
e18747a9 PG |
4968 | |
4969 | case DPLANE_OP_NEIGH_TABLE_UPDATE: | |
4970 | zlog_debug("Dplane neigh table op %s, ifp %s, family %s", | |
4971 | dplane_op2str(dplane_ctx_get_op(ctx)), | |
4972 | dplane_ctx_get_ifname(ctx), | |
4973 | family2str(dplane_ctx_neightable_get_family(ctx))); | |
4974 | break; | |
62b4b7e4 PG |
4975 | case DPLANE_OP_GRE_SET: |
4976 | zlog_debug("Dplane gre set op %s, ifp %s, link %u", | |
4977 | dplane_op2str(dplane_ctx_get_op(ctx)), | |
4978 | dplane_ctx_get_ifname(ctx), | |
4979 | ctx->u.gre.link_ifindex); | |
4980 | break; | |
9d59df63 MS |
4981 | |
4982 | case DPLANE_OP_INTF_ADDR_ADD: | |
4983 | case DPLANE_OP_INTF_ADDR_DEL: | |
4984 | zlog_debug("Dplane incoming op %s, intf %s, addr %pFX", | |
4985 | dplane_op2str(dplane_ctx_get_op(ctx)), | |
4986 | dplane_ctx_get_ifname(ctx), | |
4987 | dplane_ctx_get_intf_addr(ctx)); | |
4988 | break; | |
fef24b03 | 4989 | } |
2f74a82a | 4990 | } |
f62e5480 | 4991 | |
fef24b03 | 4992 | static void kernel_dplane_handle_result(struct zebra_dplane_ctx *ctx) |
2f74a82a | 4993 | { |
fef24b03 JU |
4994 | enum zebra_dplane_result res = dplane_ctx_get_status(ctx); |
4995 | ||
2f74a82a JU |
4996 | switch (dplane_ctx_get_op(ctx)) { |
4997 | ||
4998 | case DPLANE_OP_ROUTE_INSTALL: | |
4999 | case DPLANE_OP_ROUTE_UPDATE: | |
5000 | case DPLANE_OP_ROUTE_DELETE: | |
5001 | if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) | |
5002 | atomic_fetch_add_explicit(&zdplane_info.dg_route_errors, | |
5003 | 1, memory_order_relaxed); | |
fef24b03 JU |
5004 | |
5005 | if ((dplane_ctx_get_op(ctx) != DPLANE_OP_ROUTE_DELETE) | |
5006 | && (res == ZEBRA_DPLANE_REQUEST_SUCCESS)) { | |
5007 | struct nexthop *nexthop; | |
5008 | ||
5009 | /* Update installed nexthops to signal which have been | |
5010 | * installed. | |
5011 | */ | |
5012 | for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx), | |
5013 | nexthop)) { | |
5014 | if (CHECK_FLAG(nexthop->flags, | |
5015 | NEXTHOP_FLAG_RECURSIVE)) | |
5016 | continue; | |
5017 | ||
5018 | if (CHECK_FLAG(nexthop->flags, | |
5019 | NEXTHOP_FLAG_ACTIVE)) { | |
5020 | SET_FLAG(nexthop->flags, | |
5021 | NEXTHOP_FLAG_FIB); | |
5022 | } | |
5023 | } | |
5024 | } | |
2f74a82a JU |
5025 | break; |
5026 | ||
5027 | case DPLANE_OP_NH_INSTALL: | |
5028 | case DPLANE_OP_NH_UPDATE: | |
5029 | case DPLANE_OP_NH_DELETE: | |
5030 | if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) | |
5031 | atomic_fetch_add_explicit( | |
5032 | &zdplane_info.dg_nexthop_errors, 1, | |
5033 | memory_order_relaxed); | |
5034 | break; | |
5035 | ||
5036 | case DPLANE_OP_LSP_INSTALL: | |
5037 | case DPLANE_OP_LSP_UPDATE: | |
5038 | case DPLANE_OP_LSP_DELETE: | |
5039 | if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) | |
5040 | atomic_fetch_add_explicit(&zdplane_info.dg_lsp_errors, | |
5041 | 1, memory_order_relaxed); | |
5042 | break; | |
5043 | ||
5044 | case DPLANE_OP_PW_INSTALL: | |
5045 | case DPLANE_OP_PW_UNINSTALL: | |
5046 | if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) | |
5047 | atomic_fetch_add_explicit(&zdplane_info.dg_pw_errors, 1, | |
5048 | memory_order_relaxed); | |
5049 | break; | |
f62e5480 | 5050 | |
2f74a82a JU |
5051 | case DPLANE_OP_ADDR_INSTALL: |
5052 | case DPLANE_OP_ADDR_UNINSTALL: | |
5053 | if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) | |
5054 | atomic_fetch_add_explicit( | |
5055 | &zdplane_info.dg_intf_addr_errors, 1, | |
5056 | memory_order_relaxed); | |
5057 | break; | |
5058 | ||
5059 | case DPLANE_OP_MAC_INSTALL: | |
5060 | case DPLANE_OP_MAC_DELETE: | |
5061 | if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) | |
5062 | atomic_fetch_add_explicit(&zdplane_info.dg_mac_errors, | |
5063 | 1, memory_order_relaxed); | |
5064 | break; | |
5065 | ||
5066 | case DPLANE_OP_NEIGH_INSTALL: | |
5067 | case DPLANE_OP_NEIGH_UPDATE: | |
5068 | case DPLANE_OP_NEIGH_DELETE: | |
5069 | case DPLANE_OP_VTEP_ADD: | |
5070 | case DPLANE_OP_VTEP_DELETE: | |
d68e74b4 | 5071 | case DPLANE_OP_NEIGH_DISCOVER: |
0a27a2fe PG |
5072 | case DPLANE_OP_NEIGH_IP_INSTALL: |
5073 | case DPLANE_OP_NEIGH_IP_DELETE: | |
2f74a82a JU |
5074 | if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) |
5075 | atomic_fetch_add_explicit(&zdplane_info.dg_neigh_errors, | |
5076 | 1, memory_order_relaxed); | |
5077 | break; | |
5078 | ||
5079 | case DPLANE_OP_RULE_ADD: | |
5080 | case DPLANE_OP_RULE_DELETE: | |
5081 | case DPLANE_OP_RULE_UPDATE: | |
5082 | if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) | |
5083 | atomic_fetch_add_explicit(&zdplane_info.dg_rule_errors, | |
5084 | 1, memory_order_relaxed); | |
5085 | break; | |
5086 | ||
5162e000 PG |
5087 | case DPLANE_OP_IPTABLE_ADD: |
5088 | case DPLANE_OP_IPTABLE_DELETE: | |
5089 | if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) | |
5090 | atomic_fetch_add_explicit( | |
5091 | &zdplane_info.dg_iptable_errors, 1, | |
5092 | memory_order_relaxed); | |
5093 | break; | |
5094 | ||
ef524230 PG |
5095 | case DPLANE_OP_IPSET_ADD: |
5096 | case DPLANE_OP_IPSET_DELETE: | |
5097 | if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) | |
5098 | atomic_fetch_add_explicit(&zdplane_info.dg_ipset_errors, | |
5099 | 1, memory_order_relaxed); | |
5100 | break; | |
5101 | ||
5102 | case DPLANE_OP_IPSET_ENTRY_ADD: | |
5103 | case DPLANE_OP_IPSET_ENTRY_DELETE: | |
5104 | if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) | |
5105 | atomic_fetch_add_explicit( | |
5106 | &zdplane_info.dg_ipset_entry_errors, 1, | |
5107 | memory_order_relaxed); | |
5108 | break; | |
5109 | ||
e18747a9 PG |
5110 | case DPLANE_OP_NEIGH_TABLE_UPDATE: |
5111 | if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) | |
5112 | atomic_fetch_add_explicit( | |
5113 | &zdplane_info.dg_neightable_errors, 1, | |
5114 | memory_order_relaxed); | |
5115 | break; | |
5116 | ||
62b4b7e4 PG |
5117 | case DPLANE_OP_GRE_SET: |
5118 | if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) | |
5119 | atomic_fetch_add_explicit( | |
5120 | &zdplane_info.dg_gre_set_errors, 1, | |
5121 | memory_order_relaxed); | |
5122 | break; | |
2f74a82a JU |
5123 | /* Ignore 'notifications' - no-op */ |
5124 | case DPLANE_OP_SYS_ROUTE_ADD: | |
5125 | case DPLANE_OP_SYS_ROUTE_DELETE: | |
5126 | case DPLANE_OP_ROUTE_NOTIFY: | |
5127 | case DPLANE_OP_LSP_NOTIFY: | |
c60522f7 | 5128 | case DPLANE_OP_BR_PORT_UPDATE: |
fef24b03 JU |
5129 | break; |
5130 | ||
9d59df63 MS |
5131 | /* TODO -- error counters for incoming events? */ |
5132 | case DPLANE_OP_INTF_ADDR_ADD: | |
5133 | case DPLANE_OP_INTF_ADDR_DEL: | |
5134 | break; | |
5135 | ||
2f74a82a | 5136 | case DPLANE_OP_NONE: |
fef24b03 JU |
5137 | if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) |
5138 | atomic_fetch_add_explicit(&zdplane_info.dg_other_errors, | |
5139 | 1, memory_order_relaxed); | |
2f74a82a JU |
5140 | break; |
5141 | } | |
f62e5480 JU |
5142 | } |
5143 | ||
5162e000 PG |
5144 | static void kernel_dplane_process_iptable(struct zebra_dplane_provider *prov, |
5145 | struct zebra_dplane_ctx *ctx) | |
5146 | { | |
5147 | zebra_pbr_process_iptable(ctx); | |
5148 | dplane_provider_enqueue_out_ctx(prov, ctx); | |
5149 | } | |
5150 | ||
ef524230 PG |
5151 | static void kernel_dplane_process_ipset(struct zebra_dplane_provider *prov, |
5152 | struct zebra_dplane_ctx *ctx) | |
5153 | { | |
5154 | zebra_pbr_process_ipset(ctx); | |
5155 | dplane_provider_enqueue_out_ctx(prov, ctx); | |
5156 | } | |
5157 | ||
5158 | static void | |
5159 | kernel_dplane_process_ipset_entry(struct zebra_dplane_provider *prov, | |
5160 | struct zebra_dplane_ctx *ctx) | |
5161 | { | |
5162 | zebra_pbr_process_ipset_entry(ctx); | |
5163 | dplane_provider_enqueue_out_ctx(prov, ctx); | |
5164 | } | |
5165 | ||
fef24b03 JU |
5166 | /* |
5167 | * Kernel provider callback | |
5168 | */ | |
5169 | static int kernel_dplane_process_func(struct zebra_dplane_provider *prov) | |
5170 | { | |
5171 | struct zebra_dplane_ctx *ctx, *tctx; | |
5172 | struct dplane_ctx_q work_list; | |
5173 | int counter, limit; | |
5174 | ||
5175 | TAILQ_INIT(&work_list); | |
5176 | ||
5177 | limit = dplane_provider_get_work_limit(prov); | |
5178 | ||
5179 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) | |
5180 | zlog_debug("dplane provider '%s': processing", | |
5181 | dplane_provider_get_name(prov)); | |
5182 | ||
5183 | for (counter = 0; counter < limit; counter++) { | |
5184 | ctx = dplane_provider_dequeue_in_ctx(prov); | |
5185 | if (ctx == NULL) | |
5186 | break; | |
fef24b03 JU |
5187 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) |
5188 | kernel_dplane_log_detail(ctx); | |
2f74a82a | 5189 | |
ef524230 PG |
5190 | if ((dplane_ctx_get_op(ctx) == DPLANE_OP_IPTABLE_ADD |
5191 | || dplane_ctx_get_op(ctx) == DPLANE_OP_IPTABLE_DELETE)) | |
5162e000 | 5192 | kernel_dplane_process_iptable(prov, ctx); |
ef524230 PG |
5193 | else if ((dplane_ctx_get_op(ctx) == DPLANE_OP_IPSET_ADD |
5194 | || dplane_ctx_get_op(ctx) == DPLANE_OP_IPSET_DELETE)) | |
5195 | kernel_dplane_process_ipset(prov, ctx); | |
5196 | else if ((dplane_ctx_get_op(ctx) == DPLANE_OP_IPSET_ENTRY_ADD | |
5197 | || dplane_ctx_get_op(ctx) | |
5198 | == DPLANE_OP_IPSET_ENTRY_DELETE)) | |
5199 | kernel_dplane_process_ipset_entry(prov, ctx); | |
5162e000 PG |
5200 | else |
5201 | TAILQ_INSERT_TAIL(&work_list, ctx, zd_q_entries); | |
2f74a82a | 5202 | } |
c831033f | 5203 | |
18f60fe9 | 5204 | kernel_update_multi(&work_list); |
fef24b03 | 5205 | |
2f74a82a | 5206 | TAILQ_FOREACH_SAFE (ctx, &work_list, zd_q_entries, tctx) { |
fef24b03 JU |
5207 | kernel_dplane_handle_result(ctx); |
5208 | ||
2f74a82a | 5209 | TAILQ_REMOVE(&work_list, ctx, zd_q_entries); |
c831033f MS |
5210 | dplane_provider_enqueue_out_ctx(prov, ctx); |
5211 | } | |
5212 | ||
5213 | /* Ensure that we'll run the work loop again if there's still | |
5214 | * more work to do. | |
5215 | */ | |
5216 | if (counter >= limit) { | |
5217 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) | |
5218 | zlog_debug("dplane provider '%s' reached max updates %d", | |
5219 | dplane_provider_get_name(prov), counter); | |
5220 | ||
5221 | atomic_fetch_add_explicit(&zdplane_info.dg_update_yields, | |
5222 | 1, memory_order_relaxed); | |
5223 | ||
5224 | dplane_provider_work_ready(); | |
5225 | } | |
5226 | ||
5227 | return 0; | |
5228 | } | |
5229 | ||
1e20238a | 5230 | #ifdef DPLANE_TEST_PROVIDER |
e5a60d82 | 5231 | |
c831033f MS |
5232 | /* |
5233 | * Test dataplane provider plugin | |
5234 | */ | |
5235 | ||
5236 | /* | |
5237 | * Test provider process callback | |
5238 | */ | |
5239 | static int test_dplane_process_func(struct zebra_dplane_provider *prov) | |
5240 | { | |
5241 | struct zebra_dplane_ctx *ctx; | |
5242 | int counter, limit; | |
5243 | ||
5244 | /* Just moving from 'in' queue to 'out' queue */ | |
5245 | ||
5246 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) | |
5247 | zlog_debug("dplane provider '%s': processing", | |
5248 | dplane_provider_get_name(prov)); | |
5249 | ||
5250 | limit = dplane_provider_get_work_limit(prov); | |
5251 | ||
5252 | for (counter = 0; counter < limit; counter++) { | |
c831033f MS |
5253 | ctx = dplane_provider_dequeue_in_ctx(prov); |
5254 | if (ctx == NULL) | |
5255 | break; | |
5256 | ||
cf363e1b MS |
5257 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) |
5258 | zlog_debug("dplane provider '%s': op %s", | |
5259 | dplane_provider_get_name(prov), | |
5260 | dplane_op2str(dplane_ctx_get_op(ctx))); | |
5261 | ||
c831033f MS |
5262 | dplane_ctx_set_status(ctx, ZEBRA_DPLANE_REQUEST_SUCCESS); |
5263 | ||
5264 | dplane_provider_enqueue_out_ctx(prov, ctx); | |
5265 | } | |
5266 | ||
c9d17fe8 MS |
5267 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) |
5268 | zlog_debug("dplane provider '%s': processed %d", | |
5269 | dplane_provider_get_name(prov), counter); | |
5270 | ||
c831033f MS |
5271 | /* Ensure that we'll run the work loop again if there's still |
5272 | * more work to do. | |
5273 | */ | |
5274 | if (counter >= limit) | |
5275 | dplane_provider_work_ready(); | |
5276 | ||
5277 | return 0; | |
5278 | } | |
5279 | ||
5280 | /* | |
5281 | * Test provider shutdown/fini callback | |
5282 | */ | |
5283 | static int test_dplane_shutdown_func(struct zebra_dplane_provider *prov, | |
5284 | bool early) | |
5285 | { | |
5286 | if (IS_ZEBRA_DEBUG_DPLANE) | |
5287 | zlog_debug("dplane provider '%s': %sshutdown", | |
5288 | dplane_provider_get_name(prov), | |
5289 | early ? "early " : ""); | |
5290 | ||
5291 | return 0; | |
5292 | } | |
e5a60d82 | 5293 | #endif /* DPLANE_TEST_PROVIDER */ |
c831033f MS |
5294 | |
5295 | /* | |
5296 | * Register default kernel provider | |
5297 | */ | |
5298 | static void dplane_provider_init(void) | |
5299 | { | |
5300 | int ret; | |
5301 | ||
5302 | ret = dplane_provider_register("Kernel", | |
5303 | DPLANE_PRIO_KERNEL, | |
1dd4ea8a | 5304 | DPLANE_PROV_FLAGS_DEFAULT, NULL, |
c831033f MS |
5305 | kernel_dplane_process_func, |
5306 | NULL, | |
1ff8a248 | 5307 | NULL, NULL); |
c831033f MS |
5308 | |
5309 | if (ret != AOK) | |
5310 | zlog_err("Unable to register kernel dplane provider: %d", | |
5311 | ret); | |
5312 | ||
1e20238a | 5313 | #ifdef DPLANE_TEST_PROVIDER |
e5a60d82 | 5314 | /* Optional test provider ... */ |
c831033f MS |
5315 | ret = dplane_provider_register("Test", |
5316 | DPLANE_PRIO_PRE_KERNEL, | |
1dd4ea8a | 5317 | DPLANE_PROV_FLAGS_DEFAULT, NULL, |
c831033f MS |
5318 | test_dplane_process_func, |
5319 | test_dplane_shutdown_func, | |
1ff8a248 | 5320 | NULL /* data */, NULL); |
c831033f MS |
5321 | |
5322 | if (ret != AOK) | |
5323 | zlog_err("Unable to register test dplane provider: %d", | |
5324 | ret); | |
e5a60d82 | 5325 | #endif /* DPLANE_TEST_PROVIDER */ |
7cdb1a84 MS |
5326 | } |
5327 | ||
aa21da07 MS |
5328 | /* |
5329 | * Allow zebra code to walk the queue of pending contexts, evaluate each one | |
5330 | * using a callback function. If the function returns 'true', the context | |
5331 | * will be dequeued and freed without being processed. | |
5332 | */ | |
5333 | int dplane_clean_ctx_queue(bool (*context_cb)(struct zebra_dplane_ctx *ctx, | |
5334 | void *arg), void *val) | |
5335 | { | |
5336 | struct zebra_dplane_ctx *ctx, *temp; | |
5337 | struct dplane_ctx_q work_list; | |
5338 | ||
5339 | TAILQ_INIT(&work_list); | |
5340 | ||
5341 | if (context_cb == NULL) | |
5342 | goto done; | |
5343 | ||
5344 | /* Walk the pending context queue under the dplane lock. */ | |
5345 | DPLANE_LOCK(); | |
5346 | ||
5347 | TAILQ_FOREACH_SAFE(ctx, &zdplane_info.dg_update_ctx_q, zd_q_entries, | |
5348 | temp) { | |
5349 | if (context_cb(ctx, val)) { | |
5350 | TAILQ_REMOVE(&zdplane_info.dg_update_ctx_q, ctx, | |
5351 | zd_q_entries); | |
5352 | TAILQ_INSERT_TAIL(&work_list, ctx, zd_q_entries); | |
5353 | } | |
5354 | } | |
5355 | ||
5356 | DPLANE_UNLOCK(); | |
5357 | ||
5358 | /* Now free any contexts selected by the caller, without holding | |
5359 | * the lock. | |
5360 | */ | |
5361 | TAILQ_FOREACH_SAFE(ctx, &work_list, zd_q_entries, temp) { | |
5362 | TAILQ_REMOVE(&work_list, ctx, zd_q_entries); | |
5363 | dplane_ctx_fini(&ctx); | |
5364 | } | |
5365 | ||
5366 | done: | |
5367 | ||
5368 | return 0; | |
5369 | } | |
5370 | ||
4dfd7a02 MS |
5371 | /* Indicates zebra shutdown/exit is in progress. Some operations may be |
5372 | * simplified or skipped during shutdown processing. | |
5373 | */ | |
5374 | bool dplane_is_in_shutdown(void) | |
5375 | { | |
25779064 | 5376 | return zdplane_info.dg_is_shutdown; |
4dfd7a02 MS |
5377 | } |
5378 | ||
5917df09 MS |
5379 | /* |
5380 | * Enable collection of extra info about interfaces in route updates. | |
5381 | */ | |
5382 | void dplane_enable_intf_extra_info(void) | |
5383 | { | |
5384 | dplane_collect_extra_intf_info = true; | |
5385 | } | |
5386 | ||
4dfd7a02 MS |
5387 | /* |
5388 | * Early or pre-shutdown, de-init notification api. This runs pretty | |
5389 | * early during zebra shutdown, as a signal to stop new work and prepare | |
5390 | * for updates generated by shutdown/cleanup activity, as zebra tries to | |
5391 | * remove everything it's responsible for. | |
c9d17fe8 | 5392 | * NB: This runs in the main zebra pthread context. |
4dfd7a02 MS |
5393 | */ |
5394 | void zebra_dplane_pre_finish(void) | |
5395 | { | |
3c0e1622 | 5396 | struct zebra_dplane_provider *prov; |
6ba8db21 | 5397 | |
4dfd7a02 | 5398 | if (IS_ZEBRA_DEBUG_DPLANE) |
3c0e1622 | 5399 | zlog_debug("Zebra dataplane pre-finish called"); |
4dfd7a02 | 5400 | |
25779064 | 5401 | zdplane_info.dg_is_shutdown = true; |
4dfd7a02 | 5402 | |
6ba8db21 | 5403 | /* Notify provider(s) of pending shutdown. */ |
3c0e1622 MS |
5404 | TAILQ_FOREACH(prov, &zdplane_info.dg_providers_q, dp_prov_link) { |
5405 | if (prov->dp_fini == NULL) | |
6ba8db21 RZ |
5406 | continue; |
5407 | ||
3c0e1622 | 5408 | prov->dp_fini(prov, true /* early */); |
6ba8db21 | 5409 | } |
4dfd7a02 MS |
5410 | } |
5411 | ||
5412 | /* | |
5413 | * Utility to determine whether work remains enqueued within the dplane; | |
5414 | * used during system shutdown processing. | |
5415 | */ | |
5416 | static bool dplane_work_pending(void) | |
5417 | { | |
c9d17fe8 | 5418 | bool ret = false; |
25779064 | 5419 | struct zebra_dplane_ctx *ctx; |
c9d17fe8 | 5420 | struct zebra_dplane_provider *prov; |
4dfd7a02 | 5421 | |
c831033f MS |
5422 | /* TODO -- just checking incoming/pending work for now, must check |
5423 | * providers | |
5424 | */ | |
4dfd7a02 MS |
5425 | DPLANE_LOCK(); |
5426 | { | |
3fe4ccc4 | 5427 | ctx = TAILQ_FIRST(&zdplane_info.dg_update_ctx_q); |
c9d17fe8 | 5428 | prov = TAILQ_FIRST(&zdplane_info.dg_providers_q); |
4dfd7a02 MS |
5429 | } |
5430 | DPLANE_UNLOCK(); | |
5431 | ||
c9d17fe8 MS |
5432 | if (ctx != NULL) { |
5433 | ret = true; | |
5434 | goto done; | |
5435 | } | |
5436 | ||
5437 | while (prov) { | |
5438 | ||
ad6aad4d | 5439 | dplane_provider_lock(prov); |
c9d17fe8 MS |
5440 | |
5441 | ctx = TAILQ_FIRST(&(prov->dp_ctx_in_q)); | |
5442 | if (ctx == NULL) | |
5443 | ctx = TAILQ_FIRST(&(prov->dp_ctx_out_q)); | |
5444 | ||
ad6aad4d | 5445 | dplane_provider_unlock(prov); |
c9d17fe8 MS |
5446 | |
5447 | if (ctx != NULL) | |
5448 | break; | |
5449 | ||
5450 | DPLANE_LOCK(); | |
5451 | prov = TAILQ_NEXT(prov, dp_prov_link); | |
5452 | DPLANE_UNLOCK(); | |
5453 | } | |
5454 | ||
5455 | if (ctx != NULL) | |
5456 | ret = true; | |
5457 | ||
5458 | done: | |
5459 | return ret; | |
4dfd7a02 MS |
5460 | } |
5461 | ||
5462 | /* | |
5463 | * Shutdown-time intermediate callback, used to determine when all pending | |
5464 | * in-flight updates are done. If there's still work to do, reschedules itself. | |
5465 | * If all work is done, schedules an event to the main zebra thread for | |
5466 | * final zebra shutdown. | |
5467 | * This runs in the dplane pthread context. | |
5468 | */ | |
5469 | static int dplane_check_shutdown_status(struct thread *event) | |
5470 | { | |
5471 | if (IS_ZEBRA_DEBUG_DPLANE) | |
5472 | zlog_debug("Zebra dataplane shutdown status check called"); | |
5473 | ||
5474 | if (dplane_work_pending()) { | |
5475 | /* Reschedule dplane check on a short timer */ | |
25779064 | 5476 | thread_add_timer_msec(zdplane_info.dg_master, |
4dfd7a02 MS |
5477 | dplane_check_shutdown_status, |
5478 | NULL, 100, | |
25779064 | 5479 | &zdplane_info.dg_t_shutdown_check); |
4dfd7a02 MS |
5480 | |
5481 | /* TODO - give up and stop waiting after a short time? */ | |
5482 | ||
5483 | } else { | |
5484 | /* We appear to be done - schedule a final callback event | |
5485 | * for the zebra main pthread. | |
5486 | */ | |
3801e764 | 5487 | thread_add_event(zrouter.master, zebra_finalize, NULL, 0, NULL); |
4dfd7a02 MS |
5488 | } |
5489 | ||
5490 | return 0; | |
5491 | } | |
5492 | ||
18c37974 | 5493 | /* |
1d11b21f | 5494 | * Shutdown, de-init api. This runs pretty late during shutdown, |
4dfd7a02 MS |
5495 | * after zebra has tried to free/remove/uninstall all routes during shutdown. |
5496 | * At this point, dplane work may still remain to be done, so we can't just | |
5497 | * blindly terminate. If there's still work to do, we'll periodically check | |
5498 | * and when done, we'll enqueue a task to the zebra main thread for final | |
5499 | * termination processing. | |
5500 | * | |
1d11b21f | 5501 | * NB: This runs in the main zebra thread context. |
18c37974 | 5502 | */ |
1d11b21f | 5503 | void zebra_dplane_finish(void) |
18c37974 | 5504 | { |
4dfd7a02 MS |
5505 | if (IS_ZEBRA_DEBUG_DPLANE) |
5506 | zlog_debug("Zebra dataplane fini called"); | |
5507 | ||
25779064 | 5508 | thread_add_event(zdplane_info.dg_master, |
4dfd7a02 | 5509 | dplane_check_shutdown_status, NULL, 0, |
25779064 | 5510 | &zdplane_info.dg_t_shutdown_check); |
4dfd7a02 MS |
5511 | } |
5512 | ||
c831033f MS |
5513 | /* |
5514 | * Main dataplane pthread event loop. The thread takes new incoming work | |
5515 | * and offers it to the first provider. It then iterates through the | |
5516 | * providers, taking complete work from each one and offering it | |
5517 | * to the next in order. At each step, a limited number of updates are | |
5518 | * processed during a cycle in order to provide some fairness. | |
14b0bc8e MS |
5519 | * |
5520 | * This loop through the providers is only run once, so that the dataplane | |
5521 | * pthread can look for other pending work - such as i/o work on behalf of | |
5522 | * providers. | |
c831033f MS |
5523 | */ |
5524 | static int dplane_thread_loop(struct thread *event) | |
5525 | { | |
5526 | struct dplane_ctx_q work_list; | |
5527 | struct dplane_ctx_q error_list; | |
5528 | struct zebra_dplane_provider *prov; | |
5529 | struct zebra_dplane_ctx *ctx, *tctx; | |
5530 | int limit, counter, error_counter; | |
c9d17fe8 | 5531 | uint64_t curr, high; |
f1595ce4 | 5532 | bool reschedule = false; |
c831033f MS |
5533 | |
5534 | /* Capture work limit per cycle */ | |
5535 | limit = zdplane_info.dg_updates_per_cycle; | |
5536 | ||
14b0bc8e | 5537 | /* Init temporary lists used to move contexts among providers */ |
c831033f | 5538 | TAILQ_INIT(&work_list); |
14b0bc8e MS |
5539 | TAILQ_INIT(&error_list); |
5540 | error_counter = 0; | |
c831033f MS |
5541 | |
5542 | /* Check for zebra shutdown */ | |
5543 | if (!zdplane_info.dg_run) | |
5544 | goto done; | |
5545 | ||
5546 | /* Dequeue some incoming work from zebra (if any) onto the temporary | |
5547 | * working list. | |
5548 | */ | |
5549 | DPLANE_LOCK(); | |
5550 | ||
5551 | /* Locate initial registered provider */ | |
5552 | prov = TAILQ_FIRST(&zdplane_info.dg_providers_q); | |
5553 | ||
14b0bc8e | 5554 | /* Move new work from incoming list to temp list */ |
c831033f | 5555 | for (counter = 0; counter < limit; counter++) { |
3fe4ccc4 | 5556 | ctx = TAILQ_FIRST(&zdplane_info.dg_update_ctx_q); |
c831033f | 5557 | if (ctx) { |
3fe4ccc4 | 5558 | TAILQ_REMOVE(&zdplane_info.dg_update_ctx_q, ctx, |
c831033f MS |
5559 | zd_q_entries); |
5560 | ||
c831033f MS |
5561 | ctx->zd_provider = prov->dp_id; |
5562 | ||
5563 | TAILQ_INSERT_TAIL(&work_list, ctx, zd_q_entries); | |
5564 | } else { | |
5565 | break; | |
5566 | } | |
5567 | } | |
5568 | ||
5569 | DPLANE_UNLOCK(); | |
5570 | ||
14b0bc8e MS |
5571 | atomic_fetch_sub_explicit(&zdplane_info.dg_routes_queued, counter, |
5572 | memory_order_relaxed); | |
5573 | ||
c831033f MS |
5574 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) |
5575 | zlog_debug("dplane: incoming new work counter: %d", counter); | |
5576 | ||
5577 | /* Iterate through the registered providers, offering new incoming | |
5578 | * work. If the provider has outgoing work in its queue, take that | |
5579 | * work for the next provider | |
5580 | */ | |
5581 | while (prov) { | |
5582 | ||
14b0bc8e MS |
5583 | /* At each iteration, the temporary work list has 'counter' |
5584 | * items. | |
5585 | */ | |
c831033f MS |
5586 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) |
5587 | zlog_debug("dplane enqueues %d new work to provider '%s'", | |
5588 | counter, dplane_provider_get_name(prov)); | |
5589 | ||
5590 | /* Capture current provider id in each context; check for | |
5591 | * error status. | |
5592 | */ | |
5593 | TAILQ_FOREACH_SAFE(ctx, &work_list, zd_q_entries, tctx) { | |
5594 | if (dplane_ctx_get_status(ctx) == | |
5595 | ZEBRA_DPLANE_REQUEST_SUCCESS) { | |
5596 | ctx->zd_provider = prov->dp_id; | |
5597 | } else { | |
5598 | /* | |
5599 | * TODO -- improve error-handling: recirc | |
5600 | * errors backwards so that providers can | |
5601 | * 'undo' their work (if they want to) | |
5602 | */ | |
5603 | ||
5604 | /* Move to error list; will be returned | |
5605 | * zebra main. | |
5606 | */ | |
5607 | TAILQ_REMOVE(&work_list, ctx, zd_q_entries); | |
5608 | TAILQ_INSERT_TAIL(&error_list, | |
5609 | ctx, zd_q_entries); | |
5610 | error_counter++; | |
5611 | } | |
5612 | } | |
5613 | ||
5614 | /* Enqueue new work to the provider */ | |
ad6aad4d | 5615 | dplane_provider_lock(prov); |
c831033f MS |
5616 | |
5617 | if (TAILQ_FIRST(&work_list)) | |
5618 | TAILQ_CONCAT(&(prov->dp_ctx_in_q), &work_list, | |
5619 | zd_q_entries); | |
5620 | ||
c9d17fe8 MS |
5621 | atomic_fetch_add_explicit(&prov->dp_in_counter, counter, |
5622 | memory_order_relaxed); | |
5623 | atomic_fetch_add_explicit(&prov->dp_in_queued, counter, | |
5624 | memory_order_relaxed); | |
5625 | curr = atomic_load_explicit(&prov->dp_in_queued, | |
5626 | memory_order_relaxed); | |
5627 | high = atomic_load_explicit(&prov->dp_in_max, | |
5628 | memory_order_relaxed); | |
5629 | if (curr > high) | |
5630 | atomic_store_explicit(&prov->dp_in_max, curr, | |
c831033f MS |
5631 | memory_order_relaxed); |
5632 | ||
ad6aad4d | 5633 | dplane_provider_unlock(prov); |
c831033f | 5634 | |
14b0bc8e MS |
5635 | /* Reset the temp list (though the 'concat' may have done this |
5636 | * already), and the counter | |
5637 | */ | |
c831033f MS |
5638 | TAILQ_INIT(&work_list); |
5639 | counter = 0; | |
5640 | ||
14b0bc8e MS |
5641 | /* Call into the provider code. Note that this is |
5642 | * unconditional: we offer to do work even if we don't enqueue | |
5643 | * any _new_ work. | |
5644 | */ | |
c831033f MS |
5645 | (*prov->dp_fp)(prov); |
5646 | ||
5647 | /* Check for zebra shutdown */ | |
5648 | if (!zdplane_info.dg_run) | |
5649 | break; | |
5650 | ||
5651 | /* Dequeue completed work from the provider */ | |
ad6aad4d | 5652 | dplane_provider_lock(prov); |
c831033f MS |
5653 | |
5654 | while (counter < limit) { | |
5655 | ctx = TAILQ_FIRST(&(prov->dp_ctx_out_q)); | |
5656 | if (ctx) { | |
5657 | TAILQ_REMOVE(&(prov->dp_ctx_out_q), ctx, | |
5658 | zd_q_entries); | |
5659 | ||
5660 | TAILQ_INSERT_TAIL(&work_list, | |
5661 | ctx, zd_q_entries); | |
5662 | counter++; | |
5663 | } else | |
5664 | break; | |
5665 | } | |
5666 | ||
ad6aad4d | 5667 | dplane_provider_unlock(prov); |
c831033f | 5668 | |
f1595ce4 DE |
5669 | if (counter >= limit) |
5670 | reschedule = true; | |
5671 | ||
c831033f MS |
5672 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) |
5673 | zlog_debug("dplane dequeues %d completed work from provider %s", | |
5674 | counter, dplane_provider_get_name(prov)); | |
5675 | ||
5676 | /* Locate next provider */ | |
5677 | DPLANE_LOCK(); | |
5678 | prov = TAILQ_NEXT(prov, dp_prov_link); | |
5679 | DPLANE_UNLOCK(); | |
c831033f MS |
5680 | } |
5681 | ||
f1595ce4 DE |
5682 | /* |
5683 | * We hit the work limit while processing at least one provider's | |
5684 | * output queue - ensure we come back and finish it. | |
5685 | */ | |
5686 | if (reschedule) | |
5687 | dplane_provider_work_ready(); | |
5688 | ||
c831033f | 5689 | /* After all providers have been serviced, enqueue any completed |
14b0bc8e | 5690 | * work and any errors back to zebra so it can process the results. |
c831033f | 5691 | */ |
c831033f | 5692 | if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) |
14b0bc8e MS |
5693 | zlog_debug("dplane has %d completed, %d errors, for zebra main", |
5694 | counter, error_counter); | |
c831033f MS |
5695 | |
5696 | /* | |
4c206c8f | 5697 | * Hand lists through the api to zebra main, |
c831033f MS |
5698 | * to reduce the number of lock/unlock cycles |
5699 | */ | |
14b0bc8e | 5700 | |
4c206c8f MS |
5701 | /* Call through to zebra main */ |
5702 | (zdplane_info.dg_results_cb)(&error_list); | |
14b0bc8e | 5703 | |
4c206c8f | 5704 | TAILQ_INIT(&error_list); |
14b0bc8e | 5705 | |
4c206c8f MS |
5706 | /* Call through to zebra main */ |
5707 | (zdplane_info.dg_results_cb)(&work_list); | |
c831033f | 5708 | |
4c206c8f | 5709 | TAILQ_INIT(&work_list); |
c831033f MS |
5710 | |
5711 | done: | |
5712 | return 0; | |
5713 | } | |
5714 | ||
4dfd7a02 MS |
5715 | /* |
5716 | * Final phase of shutdown, after all work enqueued to dplane has been | |
5717 | * processed. This is called from the zebra main pthread context. | |
5718 | */ | |
5719 | void zebra_dplane_shutdown(void) | |
5720 | { | |
6ba8db21 RZ |
5721 | struct zebra_dplane_provider *dp; |
5722 | ||
4dfd7a02 MS |
5723 | if (IS_ZEBRA_DEBUG_DPLANE) |
5724 | zlog_debug("Zebra dataplane shutdown called"); | |
1d11b21f MS |
5725 | |
5726 | /* Stop dplane thread, if it's running */ | |
5727 | ||
25779064 | 5728 | zdplane_info.dg_run = false; |
1d11b21f | 5729 | |
9344d3fc SW |
5730 | if (zdplane_info.dg_t_update) |
5731 | thread_cancel_async(zdplane_info.dg_t_update->master, | |
5732 | &zdplane_info.dg_t_update, NULL); | |
1d11b21f | 5733 | |
d8c16a95 MS |
5734 | frr_pthread_stop(zdplane_info.dg_pthread, NULL); |
5735 | ||
5736 | /* Destroy pthread */ | |
5737 | frr_pthread_destroy(zdplane_info.dg_pthread); | |
5738 | zdplane_info.dg_pthread = NULL; | |
5739 | zdplane_info.dg_master = NULL; | |
4dfd7a02 | 5740 | |
3c0e1622 MS |
5741 | /* Notify provider(s) of final shutdown. |
5742 | * Note that this call is in the main pthread, so providers must | |
5743 | * be prepared for that. | |
5744 | */ | |
6ba8db21 RZ |
5745 | TAILQ_FOREACH(dp, &zdplane_info.dg_providers_q, dp_prov_link) { |
5746 | if (dp->dp_fini == NULL) | |
5747 | continue; | |
5748 | ||
5749 | dp->dp_fini(dp, false); | |
5750 | } | |
c831033f MS |
5751 | |
5752 | /* TODO -- Clean-up provider objects */ | |
5753 | ||
5754 | /* TODO -- Clean queue(s), free memory */ | |
5755 | } | |
5756 | ||
5757 | /* | |
5758 | * Initialize the dataplane module during startup, internal/private version | |
5759 | */ | |
2561d12e | 5760 | static void zebra_dplane_init_internal(void) |
c831033f MS |
5761 | { |
5762 | memset(&zdplane_info, 0, sizeof(zdplane_info)); | |
5763 | ||
5764 | pthread_mutex_init(&zdplane_info.dg_mutex, NULL); | |
1d11b21f | 5765 | |
3fe4ccc4 | 5766 | TAILQ_INIT(&zdplane_info.dg_update_ctx_q); |
c831033f | 5767 | TAILQ_INIT(&zdplane_info.dg_providers_q); |
1d11b21f | 5768 | |
c831033f MS |
5769 | zdplane_info.dg_updates_per_cycle = DPLANE_DEFAULT_NEW_WORK; |
5770 | ||
5771 | zdplane_info.dg_max_queued_updates = DPLANE_DEFAULT_MAX_QUEUED; | |
5772 | ||
5773 | /* Register default kernel 'provider' during init */ | |
5774 | dplane_provider_init(); | |
e5a60d82 | 5775 | } |
c831033f | 5776 | |
e5a60d82 MS |
5777 | /* |
5778 | * Start the dataplane pthread. This step needs to be run later than the | |
5779 | * 'init' step, in case zebra has fork-ed. | |
5780 | */ | |
5781 | void zebra_dplane_start(void) | |
5782 | { | |
1dd4ea8a | 5783 | struct zebra_dplane_provider *prov; |
c831033f MS |
5784 | struct frr_pthread_attr pattr = { |
5785 | .start = frr_pthread_attr_default.start, | |
5786 | .stop = frr_pthread_attr_default.stop | |
5787 | }; | |
5788 | ||
1dd4ea8a MS |
5789 | /* Start dataplane pthread */ |
5790 | ||
c831033f | 5791 | zdplane_info.dg_pthread = frr_pthread_new(&pattr, "Zebra dplane thread", |
0eca319c | 5792 | "zebra_dplane"); |
c831033f MS |
5793 | |
5794 | zdplane_info.dg_master = zdplane_info.dg_pthread->master; | |
5795 | ||
e5a60d82 MS |
5796 | zdplane_info.dg_run = true; |
5797 | ||
c831033f MS |
5798 | /* Enqueue an initial event for the dataplane pthread */ |
5799 | thread_add_event(zdplane_info.dg_master, dplane_thread_loop, NULL, 0, | |
5800 | &zdplane_info.dg_t_update); | |
5801 | ||
1dd4ea8a MS |
5802 | /* Call start callbacks for registered providers */ |
5803 | ||
5804 | DPLANE_LOCK(); | |
5805 | prov = TAILQ_FIRST(&zdplane_info.dg_providers_q); | |
5806 | DPLANE_UNLOCK(); | |
5807 | ||
5808 | while (prov) { | |
5809 | ||
5810 | if (prov->dp_start) | |
5811 | (prov->dp_start)(prov); | |
5812 | ||
5813 | /* Locate next provider */ | |
5814 | DPLANE_LOCK(); | |
5815 | prov = TAILQ_NEXT(prov, dp_prov_link); | |
5816 | DPLANE_UNLOCK(); | |
5817 | } | |
5818 | ||
c831033f | 5819 | frr_pthread_run(zdplane_info.dg_pthread, NULL); |
18c37974 MS |
5820 | } |
5821 | ||
7cdb1a84 | 5822 | /* |
b8e0423d | 5823 | * Initialize the dataplane module at startup; called by zebra rib_init() |
7cdb1a84 | 5824 | */ |
4c206c8f | 5825 | void zebra_dplane_init(int (*results_fp)(struct dplane_ctx_q *)) |
7cdb1a84 | 5826 | { |
2561d12e | 5827 | zebra_dplane_init_internal(); |
4c206c8f | 5828 | zdplane_info.dg_results_cb = results_fp; |
7cdb1a84 | 5829 | } |