]> git.proxmox.com Git - mirror_frr.git/blame - zebra/zebra_dplane.h
Merge pull request #3564 from chiragshah6/evpn_dev1
[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"
7cdb1a84
MS
28#include "zebra/zebra_ns.h"
29#include "zebra/rib.h"
30#include "zebra/zserv.h"
ea1c14f6 31
85a75f1e
MS
32/* Key netlink info from zebra ns */
33struct zebra_dplane_info {
34 ns_id_t ns_id;
35
36#if defined(HAVE_NETLINK)
7cdb1a84 37 struct nlsock nls;
85a75f1e
MS
38 bool is_cmd;
39#endif
40};
41
42/* Utility to fill in zns info from main zns struct */
43static inline void
44zebra_dplane_info_from_zns(struct zebra_dplane_info *zns_info,
45 const struct zebra_ns *zns, bool is_cmd)
46{
47 zns_info->ns_id = zns->ns_id;
48
49#if defined(HAVE_NETLINK)
50 zns_info->is_cmd = is_cmd;
51 if (is_cmd) {
7cdb1a84 52 zns_info->nls = zns->netlink_cmd;
85a75f1e 53 } else {
7cdb1a84 54 zns_info->nls = zns->netlink;
85a75f1e
MS
55 }
56#endif /* NETLINK */
57}
58
ea1c14f6
MS
59/*
60 * Result codes used when returning status back to the main zebra context.
61 */
62
63/*
64 * Philosophy Note:
65 *
66 * Flags being SET/UNSET do not belong in the South Bound
67 * Interface. This Setting belongs at the calling level
68 * because we can and will have multiple different interfaces
69 * and we will have potentially multiple different
70 * modules/filters to call. As such Setting/Unsetting
71 * success failure should be handled by the caller.
72 */
73enum zebra_dplane_status {
74 ZEBRA_DPLANE_STATUS_NONE = 0,
75 ZEBRA_DPLANE_INSTALL_SUCCESS,
76 ZEBRA_DPLANE_INSTALL_FAILURE,
77 ZEBRA_DPLANE_DELETE_SUCCESS,
78 ZEBRA_DPLANE_DELETE_FAILURE,
79
80};
81
82enum zebra_dplane_result {
83 ZEBRA_DPLANE_REQUEST_QUEUED,
84 ZEBRA_DPLANE_REQUEST_SUCCESS,
85 ZEBRA_DPLANE_REQUEST_FAILURE,
86};
87
7cdb1a84
MS
88/*
89 * API between the zebra dataplane system and the main zebra processing
90 * context.
91 */
92
93/*
94 * Enqueue a route install or update for the dataplane.
95 */
5709131c 96enum dplane_op_e {
7cdb1a84
MS
97 DPLANE_OP_NONE = 0,
98
99 /* Route update */
100 DPLANE_OP_ROUTE_INSTALL,
101 DPLANE_OP_ROUTE_UPDATE,
102 DPLANE_OP_ROUTE_DELETE,
103
5709131c 104};
7cdb1a84 105
7cdb1a84 106/*
25779064 107 * The dataplane context struct is used to exchange info between the main zebra
7cdb1a84
MS
108 * context and the dataplane module(s). If these are two independent pthreads,
109 * they cannot share existing global data structures safely.
110 */
7cdb1a84
MS
111
112/* Define a tailq list type for context blocks. The list is exposed/public,
113 * but the internal linkage in the context struct is private, so there
114 * are accessor apis that support enqueue and dequeue.
115 */
25779064 116TAILQ_HEAD(dplane_ctx_q, zebra_dplane_ctx);
7cdb1a84 117
7cdb1a84
MS
118/* Return a dataplane results context block after use; the caller's pointer will
119 * be cleared.
120 */
25779064 121void dplane_ctx_fini(struct zebra_dplane_ctx **pctx);
7cdb1a84 122
14b0bc8e 123/* Enqueue a context block to caller's tailq. This exists so that the
7cdb1a84
MS
124 * context struct can remain opaque.
125 */
25779064
MS
126void dplane_ctx_enqueue_tail(struct dplane_ctx_q *q,
127 const struct zebra_dplane_ctx *ctx);
7cdb1a84 128
c831033f
MS
129/* Append a list of context blocks to another list - again, just keeping
130 * the context struct opaque.
131 */
132void dplane_ctx_list_append(struct dplane_ctx_q *to_list,
133 struct dplane_ctx_q *from_list);
134
7cdb1a84 135/* Dequeue a context block from the head of caller's tailq */
68b375e0 136struct zebra_dplane_ctx *dplane_ctx_dequeue(struct dplane_ctx_q *q);
7cdb1a84
MS
137
138/*
139 * Accessors for information from the context object
140 */
25779064
MS
141enum zebra_dplane_result dplane_ctx_get_status(
142 const struct zebra_dplane_ctx *ctx);
c831033f
MS
143void dplane_ctx_set_status(struct zebra_dplane_ctx *ctx,
144 enum zebra_dplane_result status);
f183e380 145const char *dplane_res2str(enum zebra_dplane_result res);
7cdb1a84 146
25779064 147enum dplane_op_e dplane_ctx_get_op(const struct zebra_dplane_ctx *ctx);
5709131c 148const char *dplane_op2str(enum dplane_op_e op);
7cdb1a84 149
25779064 150const struct prefix *dplane_ctx_get_dest(const struct zebra_dplane_ctx *ctx);
7cdb1a84 151
c831033f
MS
152/* Retrieve last/current provider id */
153uint32_t dplane_ctx_get_provider(const struct zebra_dplane_ctx *ctx);
154
155/* Providers running before the kernel can control whether a kernel
156 * update should be done.
157 */
158void dplane_ctx_set_skip_kernel(struct zebra_dplane_ctx *ctx);
159bool dplane_ctx_is_skip_kernel(const struct zebra_dplane_ctx *ctx);
160
5709131c
MS
161/* Source prefix is a little special - use convention to return NULL
162 * to mean "no src prefix"
7cdb1a84 163 */
25779064
MS
164const struct prefix *dplane_ctx_get_src(const struct zebra_dplane_ctx *ctx);
165
166bool dplane_ctx_is_update(const struct zebra_dplane_ctx *ctx);
167uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx *ctx);
168uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx *ctx);
169vrf_id_t dplane_ctx_get_vrf(const struct zebra_dplane_ctx *ctx);
170int dplane_ctx_get_type(const struct zebra_dplane_ctx *ctx);
171int dplane_ctx_get_old_type(const struct zebra_dplane_ctx *ctx);
172afi_t dplane_ctx_get_afi(const struct zebra_dplane_ctx *ctx);
173safi_t dplane_ctx_get_safi(const struct zebra_dplane_ctx *ctx);
174uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx *ctx);
175route_tag_t dplane_ctx_get_tag(const struct zebra_dplane_ctx *ctx);
176route_tag_t dplane_ctx_get_old_tag(const struct zebra_dplane_ctx *ctx);
177uint16_t dplane_ctx_get_instance(const struct zebra_dplane_ctx *ctx);
178uint16_t dplane_ctx_get_old_instance(const struct zebra_dplane_ctx *ctx);
179uint32_t dplane_ctx_get_metric(const struct zebra_dplane_ctx *ctx);
180uint32_t dplane_ctx_get_old_metric(const struct zebra_dplane_ctx *ctx);
181uint32_t dplane_ctx_get_mtu(const struct zebra_dplane_ctx *ctx);
182uint32_t dplane_ctx_get_nh_mtu(const struct zebra_dplane_ctx *ctx);
183uint8_t dplane_ctx_get_distance(const struct zebra_dplane_ctx *ctx);
184uint8_t dplane_ctx_get_old_distance(const struct zebra_dplane_ctx *ctx);
185
186const struct nexthop_group *dplane_ctx_get_ng(
187 const struct zebra_dplane_ctx *ctx);
188const struct nexthop_group *dplane_ctx_get_old_ng(
189 const struct zebra_dplane_ctx *ctx);
190
191const struct zebra_dplane_info *dplane_ctx_get_ns(
192 const struct zebra_dplane_ctx *ctx);
7cdb1a84 193
4dfd7a02
MS
194/* Indicates zebra shutdown/exit is in progress. Some operations may be
195 * simplified or skipped during shutdown processing.
196 */
197bool dplane_is_in_shutdown(void);
198
7cdb1a84
MS
199/*
200 * Enqueue route change operations for the dataplane.
201 */
655d681a
MS
202enum zebra_dplane_result dplane_route_add(struct route_node *rn,
203 struct route_entry *re);
7cdb1a84 204
655d681a
MS
205enum zebra_dplane_result dplane_route_update(struct route_node *rn,
206 struct route_entry *re,
207 struct route_entry *old_re);
7cdb1a84 208
655d681a
MS
209enum zebra_dplane_result dplane_route_delete(struct route_node *rn,
210 struct route_entry *re);
7cdb1a84 211
91f16812
MS
212/* Retrieve the limit on the number of pending, unprocessed updates. */
213uint32_t dplane_get_in_queue_limit(void);
214
215/* Configure limit on the number of pending, queued updates. If 'unset', reset
216 * to default value.
217 */
218void dplane_set_in_queue_limit(uint32_t limit, bool set);
219
220/* Retrieve the current queue depth of incoming, unprocessed updates */
221uint32_t dplane_get_in_queue_len(void);
222
1d11b21f
MS
223/*
224 * Vty/cli apis
225 */
226int dplane_show_helper(struct vty *vty, bool detailed);
227int dplane_show_provs_helper(struct vty *vty, bool detailed);
228
229
230/*
c831033f 231 * Dataplane providers: modules that process or consume dataplane events.
1d11b21f
MS
232 */
233
c831033f
MS
234struct zebra_dplane_provider;
235
fe2c53d4 236/* Support string name for a dataplane provider */
7cdb1a84
MS
237#define DPLANE_PROVIDER_NAMELEN 64
238
239/* Priority or ordering values for providers. The idea is that there may be
240 * some pre-processing, followed by an external or remote dataplane,
241 * followed by the kernel, followed by some post-processing step (such as
242 * the fpm output stream.)
243 */
c831033f 244enum dplane_provider_prio {
7cdb1a84
MS
245 DPLANE_PRIO_NONE = 0,
246 DPLANE_PRIO_PREPROCESS,
247 DPLANE_PRIO_PRE_KERNEL,
248 DPLANE_PRIO_KERNEL,
249 DPLANE_PRIO_POSTPROCESS,
b8e0423d 250 DPLANE_PRIO_LAST
5709131c 251};
7cdb1a84 252
c831033f
MS
253/* Flags values used during provider registration. */
254#define DPLANE_PROV_FLAGS_DEFAULT 0x0
255
256/* Provider will be spawning its own worker thread */
257#define DPLANE_PROV_FLAG_THREADED 0x1
7cdb1a84 258
18c37974 259
c831033f 260/* Provider registration: ordering or priority value, callbacks, and optional
1ff8a248
MS
261 * opaque data value. If 'prov_p', return the newly-allocated provider object
262 * on success.
c831033f 263 */
4c206c8f
MS
264
265/* Providers offer an entry-point for incoming work, called in the context of
266 * the dataplane pthread. The dataplane pthread enqueues any new work to the
267 * provider's 'inbound' queue, then calls the callback. The dataplane
268 * then checks the provider's outbound queue for completed work.
269 */
270
271/* Providers offer an entry-point for shutdown and cleanup. This is called
272 * with 'early' during shutdown, to indicate that the dataplane subsystem
273 * is allowing work to move through the providers and finish.
274 * When called without 'early', the provider should release
275 * all resources (if it has any allocated).
276 */
7cdb1a84 277int dplane_provider_register(const char *name,
c831033f
MS
278 enum dplane_provider_prio prio,
279 int flags,
4c206c8f
MS
280 int (*fp)(struct zebra_dplane_provider *),
281 int (*fini_fp)(struct zebra_dplane_provider *,
282 bool early),
1ff8a248
MS
283 void *data,
284 struct zebra_dplane_provider **prov_p);
7cdb1a84 285
c831033f
MS
286/* Accessors for provider attributes */
287const char *dplane_provider_get_name(const struct zebra_dplane_provider *prov);
288uint32_t dplane_provider_get_id(const struct zebra_dplane_provider *prov);
289void *dplane_provider_get_data(const struct zebra_dplane_provider *prov);
290bool dplane_provider_is_threaded(const struct zebra_dplane_provider *prov);
291
ad6aad4d
MS
292/* Lock/unlock a provider's mutex - iff the provider was registered with
293 * the THREADED flag.
294 */
295void dplane_provider_lock(struct zebra_dplane_provider *prov);
296void dplane_provider_unlock(struct zebra_dplane_provider *prov);
297
298/* Obtain thread_master for dataplane thread */
299struct thread_master *dplane_get_thread_master(void);
300
301/* Providers should (generally) limit number of updates per work cycle */
c831033f
MS
302int dplane_provider_get_work_limit(const struct zebra_dplane_provider *prov);
303
304/* Provider api to signal that work/events are available
305 * for the dataplane pthread.
7cdb1a84 306 */
c831033f
MS
307int dplane_provider_work_ready(void);
308
309/* Dequeue, maintain associated counter and locking */
310struct zebra_dplane_ctx *dplane_provider_dequeue_in_ctx(
311 struct zebra_dplane_provider *prov);
312
313/* Dequeue work to a list, maintain counter and locking, return count */
314int dplane_provider_dequeue_in_list(struct zebra_dplane_provider *prov,
315 struct dplane_ctx_q *listp);
316
317/* Enqueue, maintain associated counter and locking */
318void dplane_provider_enqueue_out_ctx(struct zebra_dplane_provider *prov,
319 struct zebra_dplane_ctx *ctx);
7cdb1a84 320
7cdb1a84 321/*
1d11b21f 322 * Initialize the dataplane modules at zebra startup. This is currently called
4c206c8f
MS
323 * by the rib module. Zebra registers a results callback with the dataplane.
324 * The callback is called in the dataplane pthread context,
325 * so the expectation is that the contexts are queued for the zebra
326 * main pthread.
7cdb1a84 327 */
4c206c8f 328void zebra_dplane_init(int (*) (struct dplane_ctx_q *));
7cdb1a84 329
e5a60d82
MS
330/*
331 * Start the dataplane pthread. This step needs to be run later than the
332 * 'init' step, in case zebra has fork-ed.
333 */
334void zebra_dplane_start(void);
335
4dfd7a02
MS
336/* Finalize/cleanup apis, one called early as shutdown is starting,
337 * one called late at the end of zebra shutdown, and then one called
c831033f
MS
338 * from the zebra main pthread to stop the dplane pthread and
339 * free all resources.
4dfd7a02 340 *
1d11b21f
MS
341 * Zebra expects to try to clean up all vrfs and all routes during
342 * shutdown, so the dplane must be available until very late.
343 */
4dfd7a02 344void zebra_dplane_pre_finish(void);
1d11b21f 345void zebra_dplane_finish(void);
4dfd7a02 346void zebra_dplane_shutdown(void);
1d11b21f 347
ea1c14f6 348#endif /* _ZEBRA_DPLANE_H */