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