]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_dplane.h
isisd: implement 'max-area-addresses-mismatch' notification
[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/openbsd-queue.h"
28 #include "zebra/zebra_ns.h"
29 #include "zebra/rib.h"
30 #include "zebra/zserv.h"
31
32 /* Key netlink info from zebra ns */
33 struct zebra_dplane_info {
34 ns_id_t ns_id;
35
36 #if defined(HAVE_NETLINK)
37 struct nlsock nls;
38 bool is_cmd;
39 #endif
40 };
41
42 /* Utility to fill in zns info from main zns struct */
43 static inline void
44 zebra_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) {
52 zns_info->nls = zns->netlink_cmd;
53 } else {
54 zns_info->nls = zns->netlink;
55 }
56 #endif /* NETLINK */
57 }
58
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 */
73 enum 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
82 enum zebra_dplane_result {
83 ZEBRA_DPLANE_REQUEST_QUEUED,
84 ZEBRA_DPLANE_REQUEST_SUCCESS,
85 ZEBRA_DPLANE_REQUEST_FAILURE,
86 };
87
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 */
96 enum dplane_op_e {
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
104 };
105
106 /*
107 * The dataplane context struct is used to exchange info between the main zebra
108 * context and the dataplane module(s). If these are two independent pthreads,
109 * they cannot share existing global data structures safely.
110 */
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 */
116 TAILQ_HEAD(dplane_ctx_q, zebra_dplane_ctx);
117
118 /* Return a dataplane results context block after use; the caller's pointer will
119 * be cleared.
120 */
121 void dplane_ctx_fini(struct zebra_dplane_ctx **pctx);
122
123 /* Enqueue a context block to caller's tailq. This exists so that the
124 * context struct can remain opaque.
125 */
126 void dplane_ctx_enqueue_tail(struct dplane_ctx_q *q,
127 const struct zebra_dplane_ctx *ctx);
128
129 /* Append a list of context blocks to another list - again, just keeping
130 * the context struct opaque.
131 */
132 void dplane_ctx_list_append(struct dplane_ctx_q *to_list,
133 struct dplane_ctx_q *from_list);
134
135 /* Dequeue a context block from the head of caller's tailq */
136 struct zebra_dplane_ctx *dplane_ctx_dequeue(struct dplane_ctx_q *q);
137
138 /*
139 * Accessors for information from the context object
140 */
141 enum zebra_dplane_result dplane_ctx_get_status(
142 const struct zebra_dplane_ctx *ctx);
143 void dplane_ctx_set_status(struct zebra_dplane_ctx *ctx,
144 enum zebra_dplane_result status);
145 const char *dplane_res2str(enum zebra_dplane_result res);
146
147 enum dplane_op_e dplane_ctx_get_op(const struct zebra_dplane_ctx *ctx);
148 const char *dplane_op2str(enum dplane_op_e op);
149
150 const struct prefix *dplane_ctx_get_dest(const struct zebra_dplane_ctx *ctx);
151
152 /* Retrieve last/current provider id */
153 uint32_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 */
158 void dplane_ctx_set_skip_kernel(struct zebra_dplane_ctx *ctx);
159 bool dplane_ctx_is_skip_kernel(const struct zebra_dplane_ctx *ctx);
160
161 /* Source prefix is a little special - use convention to return NULL
162 * to mean "no src prefix"
163 */
164 const struct prefix *dplane_ctx_get_src(const struct zebra_dplane_ctx *ctx);
165
166 bool dplane_ctx_is_update(const struct zebra_dplane_ctx *ctx);
167 uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx *ctx);
168 uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx *ctx);
169 vrf_id_t dplane_ctx_get_vrf(const struct zebra_dplane_ctx *ctx);
170 int dplane_ctx_get_type(const struct zebra_dplane_ctx *ctx);
171 int dplane_ctx_get_old_type(const struct zebra_dplane_ctx *ctx);
172 afi_t dplane_ctx_get_afi(const struct zebra_dplane_ctx *ctx);
173 safi_t dplane_ctx_get_safi(const struct zebra_dplane_ctx *ctx);
174 uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx *ctx);
175 route_tag_t dplane_ctx_get_tag(const struct zebra_dplane_ctx *ctx);
176 route_tag_t dplane_ctx_get_old_tag(const struct zebra_dplane_ctx *ctx);
177 uint16_t dplane_ctx_get_instance(const struct zebra_dplane_ctx *ctx);
178 uint16_t dplane_ctx_get_old_instance(const struct zebra_dplane_ctx *ctx);
179 uint32_t dplane_ctx_get_metric(const struct zebra_dplane_ctx *ctx);
180 uint32_t dplane_ctx_get_old_metric(const struct zebra_dplane_ctx *ctx);
181 uint32_t dplane_ctx_get_mtu(const struct zebra_dplane_ctx *ctx);
182 uint32_t dplane_ctx_get_nh_mtu(const struct zebra_dplane_ctx *ctx);
183 uint8_t dplane_ctx_get_distance(const struct zebra_dplane_ctx *ctx);
184 uint8_t dplane_ctx_get_old_distance(const struct zebra_dplane_ctx *ctx);
185
186 const struct nexthop_group *dplane_ctx_get_ng(
187 const struct zebra_dplane_ctx *ctx);
188 const struct nexthop_group *dplane_ctx_get_old_ng(
189 const struct zebra_dplane_ctx *ctx);
190
191 const struct zebra_dplane_info *dplane_ctx_get_ns(
192 const struct zebra_dplane_ctx *ctx);
193
194 /* Indicates zebra shutdown/exit is in progress. Some operations may be
195 * simplified or skipped during shutdown processing.
196 */
197 bool dplane_is_in_shutdown(void);
198
199 /*
200 * Enqueue route change operations for the dataplane.
201 */
202 enum zebra_dplane_result dplane_route_add(struct route_node *rn,
203 struct route_entry *re);
204
205 enum zebra_dplane_result dplane_route_update(struct route_node *rn,
206 struct route_entry *re,
207 struct route_entry *old_re);
208
209 enum zebra_dplane_result dplane_route_delete(struct route_node *rn,
210 struct route_entry *re);
211
212 /* Retrieve the limit on the number of pending, unprocessed updates. */
213 uint32_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 */
218 void dplane_set_in_queue_limit(uint32_t limit, bool set);
219
220 /* Retrieve the current queue depth of incoming, unprocessed updates */
221 uint32_t dplane_get_in_queue_len(void);
222
223 /*
224 * Vty/cli apis
225 */
226 int dplane_show_helper(struct vty *vty, bool detailed);
227 int dplane_show_provs_helper(struct vty *vty, bool detailed);
228
229
230 /*
231 * Dataplane providers: modules that process or consume dataplane events.
232 */
233
234 struct zebra_dplane_provider;
235
236 /* Support string name for a dataplane provider */
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 */
244 enum dplane_provider_prio {
245 DPLANE_PRIO_NONE = 0,
246 DPLANE_PRIO_PREPROCESS,
247 DPLANE_PRIO_PRE_KERNEL,
248 DPLANE_PRIO_KERNEL,
249 DPLANE_PRIO_POSTPROCESS,
250 DPLANE_PRIO_LAST
251 };
252
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 */
258 typedef 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 */
265 typedef 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
273
274
275 /* Provider registration: ordering or priority value, callbacks, and optional
276 * opaque data value.
277 */
278 int dplane_provider_register(const char *name,
279 enum dplane_provider_prio prio,
280 int flags,
281 dplane_provider_process_fp fp,
282 dplane_provider_fini_fp fini_fp,
283 void *data);
284
285 /* Accessors for provider attributes */
286 const char *dplane_provider_get_name(const struct zebra_dplane_provider *prov);
287 uint32_t dplane_provider_get_id(const struct zebra_dplane_provider *prov);
288 void *dplane_provider_get_data(const struct zebra_dplane_provider *prov);
289 bool dplane_provider_is_threaded(const struct zebra_dplane_provider *prov);
290
291 /* Lock/unlock a provider's mutex - iff the provider was registered with
292 * the THREADED flag.
293 */
294 void dplane_provider_lock(struct zebra_dplane_provider *prov);
295 void dplane_provider_unlock(struct zebra_dplane_provider *prov);
296
297 /* Obtain thread_master for dataplane thread */
298 struct thread_master *dplane_get_thread_master(void);
299
300 /* Providers should (generally) limit number of updates per work cycle */
301 int 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.
305 */
306 int dplane_provider_work_ready(void);
307
308 /* Dequeue, maintain associated counter and locking */
309 struct 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 */
313 int dplane_provider_dequeue_in_list(struct zebra_dplane_provider *prov,
314 struct dplane_ctx_q *listp);
315
316 /* Enqueue, maintain associated counter and locking */
317 void dplane_provider_enqueue_out_ctx(struct zebra_dplane_provider *prov,
318 struct zebra_dplane_ctx *ctx);
319
320 /*
321 * Zebra registers a results callback with the dataplane. The callback is
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.
325 */
326 typedef int (*dplane_results_fp)(struct zebra_dplane_ctx *ctx);
327
328 int dplane_results_register(dplane_results_fp fp);
329
330 /*
331 * Initialize the dataplane modules at zebra startup. This is currently called
332 * by the rib module.
333 */
334 void zebra_dplane_init(void);
335
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 */
340 void zebra_dplane_start(void);
341
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
344 * from the zebra main pthread to stop the dplane pthread and
345 * free all resources.
346 *
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 */
350 void zebra_dplane_pre_finish(void);
351 void zebra_dplane_finish(void);
352 void zebra_dplane_shutdown(void);
353
354 #endif /* _ZEBRA_DPLANE_H */