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