]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_dplane.h
Merge pull request #5429 from Spantik/bug_fix
[mirror_frr.git] / zebra / zebra_dplane.h
1 /*
2 * Zebra dataplane layer api interfaces.
3 * Copyright (c) 2018 Volta Networks, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #ifndef _ZEBRA_DPLANE_H
21 #define _ZEBRA_DPLANE_H 1
22
23 #include "lib/zebra.h"
24 #include "lib/prefix.h"
25 #include "lib/nexthop.h"
26 #include "lib/nexthop_group.h"
27 #include "lib/queue.h"
28 #include "lib/vlan.h"
29 #include "zebra/zebra_ns.h"
30 #include "zebra/rib.h"
31 #include "zebra/zserv.h"
32 #include "zebra/zebra_mpls.h"
33 #include "zebra/zebra_nhg.h"
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 /* Key netlink info from zebra ns */
40 struct zebra_dplane_info {
41 ns_id_t ns_id;
42
43 #if defined(HAVE_NETLINK)
44 struct nlsock nls;
45 bool is_cmd;
46 #endif
47 };
48
49 /* Utility to fill in zns info from main zns struct */
50 static inline void
51 zebra_dplane_info_from_zns(struct zebra_dplane_info *zns_info,
52 const struct zebra_ns *zns, bool is_cmd)
53 {
54 zns_info->ns_id = zns->ns_id;
55
56 #if defined(HAVE_NETLINK)
57 zns_info->is_cmd = is_cmd;
58 if (is_cmd) {
59 zns_info->nls = zns->netlink_cmd;
60 } else {
61 zns_info->nls = zns->netlink;
62 }
63 #endif /* NETLINK */
64 }
65
66 /*
67 * Result codes used when returning status back to the main zebra context.
68 */
69
70 /*
71 * Philosophy Note:
72 *
73 * Flags being SET/UNSET do not belong in the South Bound
74 * Interface. This Setting belongs at the calling level
75 * because we can and will have multiple different interfaces
76 * and we will have potentially multiple different
77 * modules/filters to call. As such Setting/Unsetting
78 * success failure should be handled by the caller.
79 */
80 enum zebra_dplane_status {
81 ZEBRA_DPLANE_STATUS_NONE = 0,
82 ZEBRA_DPLANE_INSTALL_SUCCESS,
83 ZEBRA_DPLANE_INSTALL_FAILURE,
84 ZEBRA_DPLANE_DELETE_SUCCESS,
85 ZEBRA_DPLANE_DELETE_FAILURE,
86
87 };
88
89 enum zebra_dplane_result {
90 ZEBRA_DPLANE_REQUEST_QUEUED,
91 ZEBRA_DPLANE_REQUEST_SUCCESS,
92 ZEBRA_DPLANE_REQUEST_FAILURE,
93 };
94
95 /*
96 * API between the zebra dataplane system and the main zebra processing
97 * context.
98 */
99
100 /*
101 * Enqueue a route install or update for the dataplane.
102 */
103 enum dplane_op_e {
104 DPLANE_OP_NONE = 0,
105
106 /* Route update */
107 DPLANE_OP_ROUTE_INSTALL,
108 DPLANE_OP_ROUTE_UPDATE,
109 DPLANE_OP_ROUTE_DELETE,
110 DPLANE_OP_ROUTE_NOTIFY,
111
112 /* Nexthop update */
113 DPLANE_OP_NH_INSTALL,
114 DPLANE_OP_NH_UPDATE,
115 DPLANE_OP_NH_DELETE,
116
117 /* LSP update */
118 DPLANE_OP_LSP_INSTALL,
119 DPLANE_OP_LSP_UPDATE,
120 DPLANE_OP_LSP_DELETE,
121 DPLANE_OP_LSP_NOTIFY,
122
123 /* Pseudowire update */
124 DPLANE_OP_PW_INSTALL,
125 DPLANE_OP_PW_UNINSTALL,
126
127 /* System route notification */
128 DPLANE_OP_SYS_ROUTE_ADD,
129 DPLANE_OP_SYS_ROUTE_DELETE,
130
131 /* Interface address update */
132 DPLANE_OP_ADDR_INSTALL,
133 DPLANE_OP_ADDR_UNINSTALL,
134
135 /* MAC address update */
136 DPLANE_OP_MAC_INSTALL,
137 DPLANE_OP_MAC_DELETE,
138
139 /* EVPN neighbor updates */
140 DPLANE_OP_NEIGH_INSTALL,
141 DPLANE_OP_NEIGH_UPDATE,
142 DPLANE_OP_NEIGH_DELETE,
143
144 /* EVPN VTEP updates */
145 DPLANE_OP_VTEP_ADD,
146 DPLANE_OP_VTEP_DELETE,
147 };
148
149 /*
150 * The vxlan/evpn neighbor management code needs some values to use
151 * when programming neighbor changes. Offer some platform-neutral values
152 * here for use within the dplane apis and plugins.
153 */
154
155 /* Neighbor cache flags */
156 #define DPLANE_NTF_EXT_LEARNED 0x01
157 #define DPLANE_NTF_ROUTER 0x02
158
159 /* Neighbor cache states */
160 #define DPLANE_NUD_REACHABLE 0x01
161 #define DPLANE_NUD_STALE 0x02
162 #define DPLANE_NUD_NOARP 0x04
163 #define DPLANE_NUD_PROBE 0x08
164
165 /* Enable system route notifications */
166 void dplane_enable_sys_route_notifs(void);
167
168 /*
169 * The dataplane context struct is used to exchange info between the main zebra
170 * context and the dataplane module(s). If these are two independent pthreads,
171 * they cannot share existing global data structures safely.
172 */
173
174 /* Define a tailq list type for context blocks. The list is exposed/public,
175 * but the internal linkage in the context struct is private, so there
176 * are accessor apis that support enqueue and dequeue.
177 */
178 TAILQ_HEAD(dplane_ctx_q, zebra_dplane_ctx);
179
180 /* Allocate a context object */
181 struct zebra_dplane_ctx *dplane_ctx_alloc(void);
182
183 /* Return a dataplane results context block after use; the caller's pointer will
184 * be cleared.
185 */
186 void dplane_ctx_fini(struct zebra_dplane_ctx **pctx);
187
188 /* Enqueue a context block to caller's tailq. This exists so that the
189 * context struct can remain opaque.
190 */
191 void dplane_ctx_enqueue_tail(struct dplane_ctx_q *q,
192 const struct zebra_dplane_ctx *ctx);
193
194 /* Append a list of context blocks to another list - again, just keeping
195 * the context struct opaque.
196 */
197 void dplane_ctx_list_append(struct dplane_ctx_q *to_list,
198 struct dplane_ctx_q *from_list);
199
200 /* Dequeue a context block from the head of caller's tailq */
201 struct zebra_dplane_ctx *dplane_ctx_dequeue(struct dplane_ctx_q *q);
202
203 /*
204 * Accessors for information from the context object
205 */
206 enum zebra_dplane_result dplane_ctx_get_status(
207 const struct zebra_dplane_ctx *ctx);
208 void dplane_ctx_set_status(struct zebra_dplane_ctx *ctx,
209 enum zebra_dplane_result status);
210 const char *dplane_res2str(enum zebra_dplane_result res);
211
212 enum dplane_op_e dplane_ctx_get_op(const struct zebra_dplane_ctx *ctx);
213 void dplane_ctx_set_op(struct zebra_dplane_ctx *ctx, enum dplane_op_e op);
214 const char *dplane_op2str(enum dplane_op_e op);
215
216 const struct prefix *dplane_ctx_get_dest(const struct zebra_dplane_ctx *ctx);
217 void dplane_ctx_set_dest(struct zebra_dplane_ctx *ctx,
218 const struct prefix *dest);
219 const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx *ctx);
220 ifindex_t dplane_ctx_get_ifindex(const struct zebra_dplane_ctx *ctx);
221
222 /* Retrieve last/current provider id */
223 uint32_t dplane_ctx_get_provider(const struct zebra_dplane_ctx *ctx);
224
225 /* Providers running before the kernel can control whether a kernel
226 * update should be done.
227 */
228 void dplane_ctx_set_skip_kernel(struct zebra_dplane_ctx *ctx);
229 bool dplane_ctx_is_skip_kernel(const struct zebra_dplane_ctx *ctx);
230
231 /* Source prefix is a little special - use convention to return NULL
232 * to mean "no src prefix"
233 */
234 const struct prefix *dplane_ctx_get_src(const struct zebra_dplane_ctx *ctx);
235 void dplane_ctx_set_src(struct zebra_dplane_ctx *ctx, const struct prefix *src);
236
237 bool dplane_ctx_is_update(const struct zebra_dplane_ctx *ctx);
238 uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx *ctx);
239 uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx *ctx);
240 void dplane_ctx_set_vrf(struct zebra_dplane_ctx *ctx, vrf_id_t vrf);
241 vrf_id_t dplane_ctx_get_vrf(const struct zebra_dplane_ctx *ctx);
242
243 bool dplane_ctx_is_from_notif(const struct zebra_dplane_ctx *ctx);
244 void dplane_ctx_set_notif_provider(struct zebra_dplane_ctx *ctx,
245 uint32_t id);
246 uint32_t dplane_ctx_get_notif_provider(const struct zebra_dplane_ctx *ctx);
247
248 /* Accessors for route update information */
249 void dplane_ctx_set_type(struct zebra_dplane_ctx *ctx, int type);
250 int dplane_ctx_get_type(const struct zebra_dplane_ctx *ctx);
251 int dplane_ctx_get_old_type(const struct zebra_dplane_ctx *ctx);
252 void dplane_ctx_set_afi(struct zebra_dplane_ctx *ctx, afi_t afi);
253 afi_t dplane_ctx_get_afi(const struct zebra_dplane_ctx *ctx);
254 void dplane_ctx_set_safi(struct zebra_dplane_ctx *ctx, safi_t safi);
255 safi_t dplane_ctx_get_safi(const struct zebra_dplane_ctx *ctx);
256 void dplane_ctx_set_table(struct zebra_dplane_ctx *ctx, uint32_t table);
257 uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx *ctx);
258 route_tag_t dplane_ctx_get_tag(const struct zebra_dplane_ctx *ctx);
259 void dplane_ctx_set_tag(struct zebra_dplane_ctx *ctx, route_tag_t tag);
260 route_tag_t dplane_ctx_get_old_tag(const struct zebra_dplane_ctx *ctx);
261 uint16_t dplane_ctx_get_instance(const struct zebra_dplane_ctx *ctx);
262 void dplane_ctx_set_instance(struct zebra_dplane_ctx *ctx, uint16_t instance);
263 uint16_t dplane_ctx_get_old_instance(const struct zebra_dplane_ctx *ctx);
264 uint32_t dplane_ctx_get_metric(const struct zebra_dplane_ctx *ctx);
265 uint32_t dplane_ctx_get_old_metric(const struct zebra_dplane_ctx *ctx);
266 uint32_t dplane_ctx_get_mtu(const struct zebra_dplane_ctx *ctx);
267 uint32_t dplane_ctx_get_nh_mtu(const struct zebra_dplane_ctx *ctx);
268 uint8_t dplane_ctx_get_distance(const struct zebra_dplane_ctx *ctx);
269 void dplane_ctx_set_distance(struct zebra_dplane_ctx *ctx, uint8_t distance);
270 uint8_t dplane_ctx_get_old_distance(const struct zebra_dplane_ctx *ctx);
271
272 void dplane_ctx_set_nexthops(struct zebra_dplane_ctx *ctx, struct nexthop *nh);
273 const struct nexthop_group *dplane_ctx_get_ng(
274 const struct zebra_dplane_ctx *ctx);
275 const struct nexthop_group *dplane_ctx_get_old_ng(
276 const struct zebra_dplane_ctx *ctx);
277
278 /* Accessors for nexthop information */
279 uint32_t dplane_ctx_get_nhe_id(const struct zebra_dplane_ctx *ctx);
280 afi_t dplane_ctx_get_nhe_afi(const struct zebra_dplane_ctx *ctx);
281 vrf_id_t dplane_ctx_get_nhe_vrf_id(const struct zebra_dplane_ctx *ctx);
282 int dplane_ctx_get_nhe_type(const struct zebra_dplane_ctx *ctx);
283 const struct nexthop_group *
284 dplane_ctx_get_nhe_ng(const struct zebra_dplane_ctx *ctx);
285 const struct nh_grp *
286 dplane_ctx_get_nhe_nh_grp(const struct zebra_dplane_ctx *ctx);
287 uint8_t dplane_ctx_get_nhe_nh_grp_count(const struct zebra_dplane_ctx *ctx);
288
289 /* Accessors for LSP information */
290 mpls_label_t dplane_ctx_get_in_label(const struct zebra_dplane_ctx *ctx);
291 void dplane_ctx_set_in_label(struct zebra_dplane_ctx *ctx,
292 mpls_label_t label);
293 uint8_t dplane_ctx_get_addr_family(const struct zebra_dplane_ctx *ctx);
294 void dplane_ctx_set_addr_family(struct zebra_dplane_ctx *ctx,
295 uint8_t family);
296 uint32_t dplane_ctx_get_lsp_flags(const struct zebra_dplane_ctx *ctx);
297 void dplane_ctx_set_lsp_flags(struct zebra_dplane_ctx *ctx,
298 uint32_t flags);
299 const zebra_nhlfe_t *dplane_ctx_get_nhlfe(const struct zebra_dplane_ctx *ctx);
300 zebra_nhlfe_t *dplane_ctx_add_nhlfe(struct zebra_dplane_ctx *ctx,
301 enum lsp_types_t lsp_type,
302 enum nexthop_types_t nh_type,
303 union g_addr *gate,
304 ifindex_t ifindex,
305 uint8_t num_labels,
306 mpls_label_t out_labels[]);
307
308 const zebra_nhlfe_t *dplane_ctx_get_best_nhlfe(
309 const struct zebra_dplane_ctx *ctx);
310 const zebra_nhlfe_t *dplane_ctx_set_best_nhlfe(struct zebra_dplane_ctx *ctx,
311 zebra_nhlfe_t *nhlfe);
312 uint32_t dplane_ctx_get_lsp_num_ecmp(const struct zebra_dplane_ctx *ctx);
313
314 /* Accessors for pseudowire information */
315 mpls_label_t dplane_ctx_get_pw_local_label(const struct zebra_dplane_ctx *ctx);
316 mpls_label_t dplane_ctx_get_pw_remote_label(const struct zebra_dplane_ctx *ctx);
317 int dplane_ctx_get_pw_type(const struct zebra_dplane_ctx *ctx);
318 int dplane_ctx_get_pw_af(const struct zebra_dplane_ctx *ctx);
319 uint32_t dplane_ctx_get_pw_flags(const struct zebra_dplane_ctx *ctx);
320 int dplane_ctx_get_pw_status(const struct zebra_dplane_ctx *ctx);
321 const union g_addr *dplane_ctx_get_pw_dest(
322 const struct zebra_dplane_ctx *ctx);
323 const union pw_protocol_fields *dplane_ctx_get_pw_proto(
324 const struct zebra_dplane_ctx *ctx);
325 const struct nexthop_group *dplane_ctx_get_pw_nhg(
326 const struct zebra_dplane_ctx *ctx);
327
328 /* Accessors for interface information */
329 uint32_t dplane_ctx_get_intf_metric(const struct zebra_dplane_ctx *ctx);
330 /* Is interface addr p2p? */
331 bool dplane_ctx_intf_is_connected(const struct zebra_dplane_ctx *ctx);
332 bool dplane_ctx_intf_is_secondary(const struct zebra_dplane_ctx *ctx);
333 bool dplane_ctx_intf_is_broadcast(const struct zebra_dplane_ctx *ctx);
334 const struct prefix *dplane_ctx_get_intf_addr(
335 const struct zebra_dplane_ctx *ctx);
336 bool dplane_ctx_intf_has_dest(const struct zebra_dplane_ctx *ctx);
337 const struct prefix *dplane_ctx_get_intf_dest(
338 const struct zebra_dplane_ctx *ctx);
339 bool dplane_ctx_intf_has_label(const struct zebra_dplane_ctx *ctx);
340 const char *dplane_ctx_get_intf_label(const struct zebra_dplane_ctx *ctx);
341
342 /* Accessors for MAC information */
343 vlanid_t dplane_ctx_mac_get_vlan(const struct zebra_dplane_ctx *ctx);
344 bool dplane_ctx_mac_is_sticky(const struct zebra_dplane_ctx *ctx);
345 const struct ethaddr *dplane_ctx_mac_get_addr(
346 const struct zebra_dplane_ctx *ctx);
347 const struct in_addr *dplane_ctx_mac_get_vtep_ip(
348 const struct zebra_dplane_ctx *ctx);
349 ifindex_t dplane_ctx_mac_get_br_ifindex(const struct zebra_dplane_ctx *ctx);
350
351 /* Accessors for neighbor information */
352 const struct ipaddr *dplane_ctx_neigh_get_ipaddr(
353 const struct zebra_dplane_ctx *ctx);
354 const struct ethaddr *dplane_ctx_neigh_get_mac(
355 const struct zebra_dplane_ctx *ctx);
356 uint32_t dplane_ctx_neigh_get_flags(const struct zebra_dplane_ctx *ctx);
357 uint16_t dplane_ctx_neigh_get_state(const struct zebra_dplane_ctx *ctx);
358
359 /* Namespace info - esp. for netlink communication */
360 const struct zebra_dplane_info *dplane_ctx_get_ns(
361 const struct zebra_dplane_ctx *ctx);
362
363 /* Indicates zebra shutdown/exit is in progress. Some operations may be
364 * simplified or skipped during shutdown processing.
365 */
366 bool dplane_is_in_shutdown(void);
367
368 /*
369 * Enqueue route change operations for the dataplane.
370 */
371 enum zebra_dplane_result dplane_route_add(struct route_node *rn,
372 struct route_entry *re);
373
374 enum zebra_dplane_result dplane_route_update(struct route_node *rn,
375 struct route_entry *re,
376 struct route_entry *old_re);
377
378 enum zebra_dplane_result dplane_route_delete(struct route_node *rn,
379 struct route_entry *re);
380
381 /* Notify the dplane when system/connected routes change */
382 enum zebra_dplane_result dplane_sys_route_add(struct route_node *rn,
383 struct route_entry *re);
384 enum zebra_dplane_result dplane_sys_route_del(struct route_node *rn,
385 struct route_entry *re);
386
387 /* Update from an async notification, to bring other fibs up-to-date */
388 enum zebra_dplane_result dplane_route_notif_update(
389 struct route_node *rn,
390 struct route_entry *re,
391 enum dplane_op_e op,
392 struct zebra_dplane_ctx *ctx);
393
394
395 /* Forward ref of nhg_hash_entry */
396 struct nhg_hash_entry;
397 /*
398 * Enqueue a nexthop change operation for the dataplane.
399 */
400 enum zebra_dplane_result dplane_nexthop_add(struct nhg_hash_entry *nhe);
401 enum zebra_dplane_result dplane_nexthop_update(struct nhg_hash_entry *nhe);
402 enum zebra_dplane_result dplane_nexthop_delete(struct nhg_hash_entry *nhe);
403
404 /*
405 * Enqueue LSP change operations for the dataplane.
406 */
407 enum zebra_dplane_result dplane_lsp_add(zebra_lsp_t *lsp);
408 enum zebra_dplane_result dplane_lsp_update(zebra_lsp_t *lsp);
409 enum zebra_dplane_result dplane_lsp_delete(zebra_lsp_t *lsp);
410
411 /* Update or un-install resulting from an async notification */
412 enum zebra_dplane_result dplane_lsp_notif_update(zebra_lsp_t *lsp,
413 enum dplane_op_e op,
414 struct zebra_dplane_ctx *ctx);
415
416 /*
417 * Enqueue pseudowire operations for the dataplane.
418 */
419 enum zebra_dplane_result dplane_pw_install(struct zebra_pw *pw);
420 enum zebra_dplane_result dplane_pw_uninstall(struct zebra_pw *pw);
421
422 /*
423 * Enqueue interface address changes for the dataplane.
424 */
425 enum zebra_dplane_result dplane_intf_addr_set(const struct interface *ifp,
426 const struct connected *ifc);
427 enum zebra_dplane_result dplane_intf_addr_unset(const struct interface *ifp,
428 const struct connected *ifc);
429
430 /*
431 * Enqueue evpn mac operations for the dataplane.
432 */
433 enum zebra_dplane_result dplane_mac_add(const struct interface *ifp,
434 const struct interface *bridge_ifp,
435 vlanid_t vid,
436 const struct ethaddr *mac,
437 struct in_addr vtep_ip,
438 bool sticky);
439
440 enum zebra_dplane_result dplane_mac_del(const struct interface *ifp,
441 const struct interface *bridge_ifp,
442 vlanid_t vid,
443 const struct ethaddr *mac,
444 struct in_addr vtep_ip);
445
446 /*
447 * Enqueue evpn neighbor updates for the dataplane.
448 */
449 enum zebra_dplane_result dplane_neigh_add(const struct interface *ifp,
450 const struct ipaddr *ip,
451 const struct ethaddr *mac,
452 uint32_t flags);
453 enum zebra_dplane_result dplane_neigh_update(const struct interface *ifp,
454 const struct ipaddr *ip,
455 const struct ethaddr *mac);
456 enum zebra_dplane_result dplane_neigh_delete(const struct interface *ifp,
457 const struct ipaddr *ip);
458
459 /*
460 * Enqueue evpn VTEP updates for the dataplane.
461 */
462 enum zebra_dplane_result dplane_vtep_add(const struct interface *ifp,
463 const struct in_addr *ip,
464 vni_t vni);
465 enum zebra_dplane_result dplane_vtep_delete(const struct interface *ifp,
466 const struct in_addr *ip,
467 vni_t vni);
468
469
470 /* Retrieve the limit on the number of pending, unprocessed updates. */
471 uint32_t dplane_get_in_queue_limit(void);
472
473 /* Configure limit on the number of pending, queued updates. If 'unset', reset
474 * to default value.
475 */
476 void dplane_set_in_queue_limit(uint32_t limit, bool set);
477
478 /* Retrieve the current queue depth of incoming, unprocessed updates */
479 uint32_t dplane_get_in_queue_len(void);
480
481 /*
482 * Vty/cli apis
483 */
484 int dplane_show_helper(struct vty *vty, bool detailed);
485 int dplane_show_provs_helper(struct vty *vty, bool detailed);
486 int dplane_config_write_helper(struct vty *vty);
487
488 /*
489 * Dataplane providers: modules that process or consume dataplane events.
490 */
491
492 struct zebra_dplane_provider;
493
494 /* Support string name for a dataplane provider */
495 #define DPLANE_PROVIDER_NAMELEN 64
496
497 /* Priority or ordering values for providers. The idea is that there may be
498 * some pre-processing, followed by an external or remote dataplane,
499 * followed by the kernel, followed by some post-processing step (such as
500 * the fpm output stream.)
501 */
502 enum dplane_provider_prio {
503 DPLANE_PRIO_NONE = 0,
504 DPLANE_PRIO_PREPROCESS,
505 DPLANE_PRIO_PRE_KERNEL,
506 DPLANE_PRIO_KERNEL,
507 DPLANE_PRIO_POSTPROCESS,
508 DPLANE_PRIO_LAST
509 };
510
511 /* Flags values used during provider registration. */
512 #define DPLANE_PROV_FLAGS_DEFAULT 0x0
513
514 /* Provider will be spawning its own worker thread */
515 #define DPLANE_PROV_FLAG_THREADED 0x1
516
517
518 /* Provider registration: ordering or priority value, callbacks, and optional
519 * opaque data value. If 'prov_p', return the newly-allocated provider object
520 * on success.
521 */
522
523 /* Providers offer an entry-point for incoming work, called in the context of
524 * the dataplane pthread. The dataplane pthread enqueues any new work to the
525 * provider's 'inbound' queue, then calls the callback. The dataplane
526 * then checks the provider's outbound queue for completed work.
527 */
528
529 /*
530 * Providers can offer a 'start' callback; if present, the dataplane will
531 * call it when it is starting - when its pthread and event-scheduling
532 * thread_master are available.
533 */
534
535 /* Providers can offer an entry-point for shutdown and cleanup. This is called
536 * with 'early' during shutdown, to indicate that the dataplane subsystem
537 * is allowing work to move through the providers and finish.
538 * When called without 'early', the provider should release
539 * all resources (if it has any allocated).
540 */
541 int dplane_provider_register(const char *name,
542 enum dplane_provider_prio prio,
543 int flags,
544 int (*start_fp)(struct zebra_dplane_provider *),
545 int (*fp)(struct zebra_dplane_provider *),
546 int (*fini_fp)(struct zebra_dplane_provider *,
547 bool early),
548 void *data,
549 struct zebra_dplane_provider **prov_p);
550
551 /* Accessors for provider attributes */
552 const char *dplane_provider_get_name(const struct zebra_dplane_provider *prov);
553 uint32_t dplane_provider_get_id(const struct zebra_dplane_provider *prov);
554 void *dplane_provider_get_data(const struct zebra_dplane_provider *prov);
555 bool dplane_provider_is_threaded(const struct zebra_dplane_provider *prov);
556
557 /* Lock/unlock a provider's mutex - iff the provider was registered with
558 * the THREADED flag.
559 */
560 void dplane_provider_lock(struct zebra_dplane_provider *prov);
561 void dplane_provider_unlock(struct zebra_dplane_provider *prov);
562
563 /* Obtain thread_master for dataplane thread */
564 struct thread_master *dplane_get_thread_master(void);
565
566 /* Providers should (generally) limit number of updates per work cycle */
567 int dplane_provider_get_work_limit(const struct zebra_dplane_provider *prov);
568
569 /* Provider api to signal that work/events are available
570 * for the dataplane pthread.
571 */
572 int dplane_provider_work_ready(void);
573
574 /* Dequeue, maintain associated counter and locking */
575 struct zebra_dplane_ctx *dplane_provider_dequeue_in_ctx(
576 struct zebra_dplane_provider *prov);
577
578 /* Dequeue work to a list, maintain counter and locking, return count */
579 int dplane_provider_dequeue_in_list(struct zebra_dplane_provider *prov,
580 struct dplane_ctx_q *listp);
581
582 /* Enqueue completed work, maintain associated counter and locking */
583 void dplane_provider_enqueue_out_ctx(struct zebra_dplane_provider *prov,
584 struct zebra_dplane_ctx *ctx);
585
586 /* Enqueue a context directly to zebra main. */
587 void dplane_provider_enqueue_to_zebra(struct zebra_dplane_ctx *ctx);
588
589 /*
590 * Initialize the dataplane modules at zebra startup. This is currently called
591 * by the rib module. Zebra registers a results callback with the dataplane.
592 * The callback is called in the dataplane pthread context,
593 * so the expectation is that the contexts are queued for the zebra
594 * main pthread.
595 */
596 void zebra_dplane_init(int (*) (struct dplane_ctx_q *));
597
598 /*
599 * Start the dataplane pthread. This step needs to be run later than the
600 * 'init' step, in case zebra has fork-ed.
601 */
602 void zebra_dplane_start(void);
603
604 /* Finalize/cleanup apis, one called early as shutdown is starting,
605 * one called late at the end of zebra shutdown, and then one called
606 * from the zebra main pthread to stop the dplane pthread and
607 * free all resources.
608 *
609 * Zebra expects to try to clean up all vrfs and all routes during
610 * shutdown, so the dplane must be available until very late.
611 */
612 void zebra_dplane_pre_finish(void);
613 void zebra_dplane_finish(void);
614 void zebra_dplane_shutdown(void);
615
616 #ifdef __cplusplus
617 }
618 #endif
619
620 #endif /* _ZEBRA_DPLANE_H */