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