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