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