]> git.proxmox.com Git - mirror_frr.git/blame - zebra/zebra_dplane.h
isisd: implement the 'lsp-too-large' notification
[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"
27#include "lib/openbsd-queue.h"
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/* Provider's entry-point for incoming work, called in the context of the
254 * dataplane pthread. The dataplane pthread enqueues any new work to the
255 * provider's 'inbound' queue, then calls the callback. The dataplane
256 * then checks the provider's outbound queue.
257 */
258typedef int (*dplane_provider_process_fp)(struct zebra_dplane_provider *prov);
259
260/* Provider's entry-point for shutdown and cleanup. Called with 'early'
261 * during shutdown, to indicate that the dataplane subsystem is allowing
262 * work to move through the providers and finish. When called without 'early',
263 * the provider should release all resources (if it has any allocated).
264 */
265typedef int (*dplane_provider_fini_fp)(struct zebra_dplane_provider *prov,
266 bool early);
267
268/* Flags values used during provider registration. */
269#define DPLANE_PROV_FLAGS_DEFAULT 0x0
270
271/* Provider will be spawning its own worker thread */
272#define DPLANE_PROV_FLAG_THREADED 0x1
7cdb1a84 273
18c37974 274
c831033f
MS
275/* Provider registration: ordering or priority value, callbacks, and optional
276 * opaque data value.
277 */
7cdb1a84 278int dplane_provider_register(const char *name,
c831033f
MS
279 enum dplane_provider_prio prio,
280 int flags,
18c37974 281 dplane_provider_process_fp fp,
c831033f
MS
282 dplane_provider_fini_fp fini_fp,
283 void *data);
7cdb1a84 284
c831033f
MS
285/* Accessors for provider attributes */
286const char *dplane_provider_get_name(const struct zebra_dplane_provider *prov);
287uint32_t dplane_provider_get_id(const struct zebra_dplane_provider *prov);
288void *dplane_provider_get_data(const struct zebra_dplane_provider *prov);
289bool dplane_provider_is_threaded(const struct zebra_dplane_provider *prov);
290
ad6aad4d
MS
291/* Lock/unlock a provider's mutex - iff the provider was registered with
292 * the THREADED flag.
293 */
294void dplane_provider_lock(struct zebra_dplane_provider *prov);
295void dplane_provider_unlock(struct zebra_dplane_provider *prov);
296
297/* Obtain thread_master for dataplane thread */
298struct thread_master *dplane_get_thread_master(void);
299
300/* Providers should (generally) limit number of updates per work cycle */
c831033f
MS
301int dplane_provider_get_work_limit(const struct zebra_dplane_provider *prov);
302
303/* Provider api to signal that work/events are available
304 * for the dataplane pthread.
7cdb1a84 305 */
c831033f
MS
306int dplane_provider_work_ready(void);
307
308/* Dequeue, maintain associated counter and locking */
309struct zebra_dplane_ctx *dplane_provider_dequeue_in_ctx(
310 struct zebra_dplane_provider *prov);
311
312/* Dequeue work to a list, maintain counter and locking, return count */
313int dplane_provider_dequeue_in_list(struct zebra_dplane_provider *prov,
314 struct dplane_ctx_q *listp);
315
316/* Enqueue, maintain associated counter and locking */
317void dplane_provider_enqueue_out_ctx(struct zebra_dplane_provider *prov,
318 struct zebra_dplane_ctx *ctx);
7cdb1a84
MS
319
320/*
321 * Zebra registers a results callback with the dataplane. The callback is
c831033f
MS
322 * called in the dataplane pthread context, so the expectation is that the
323 * context is queued for the zebra main pthread or that processing
324 * is very limited.
7cdb1a84 325 */
c831033f
MS
326typedef int (*dplane_results_fp)(struct zebra_dplane_ctx *ctx);
327
7cdb1a84
MS
328int dplane_results_register(dplane_results_fp fp);
329
330/*
1d11b21f
MS
331 * Initialize the dataplane modules at zebra startup. This is currently called
332 * by the rib module.
7cdb1a84
MS
333 */
334void zebra_dplane_init(void);
335
e5a60d82
MS
336/*
337 * Start the dataplane pthread. This step needs to be run later than the
338 * 'init' step, in case zebra has fork-ed.
339 */
340void zebra_dplane_start(void);
341
4dfd7a02
MS
342/* Finalize/cleanup apis, one called early as shutdown is starting,
343 * one called late at the end of zebra shutdown, and then one called
c831033f
MS
344 * from the zebra main pthread to stop the dplane pthread and
345 * free all resources.
4dfd7a02 346 *
1d11b21f
MS
347 * Zebra expects to try to clean up all vrfs and all routes during
348 * shutdown, so the dplane must be available until very late.
349 */
4dfd7a02 350void zebra_dplane_pre_finish(void);
1d11b21f 351void zebra_dplane_finish(void);
4dfd7a02 352void zebra_dplane_shutdown(void);
1d11b21f 353
ea1c14f6 354#endif /* _ZEBRA_DPLANE_H */