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