]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_dplane.h
zebra: let /32 host route with same IP cross VRF
[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/queue.h"
28 #include "lib/vlan.h"
29 #include "zebra/zebra_ns.h"
30 #include "zebra/rib.h"
31 #include "zebra/zserv.h"
32 #include "zebra/zebra_mpls.h"
33 #include "zebra/zebra_nhg.h"
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 /* Key netlink info from zebra ns */
40 struct zebra_dplane_info {
41 ns_id_t ns_id;
42
43 #if defined(HAVE_NETLINK)
44 int sock;
45 int seq;
46 bool is_cmd;
47 #endif
48 };
49
50 /* Utility to fill in zns info from main zns struct */
51 static inline void
52 zebra_dplane_info_from_zns(struct zebra_dplane_info *zns_info,
53 const struct zebra_ns *zns, bool is_cmd)
54 {
55 zns_info->ns_id = zns->ns_id;
56
57 #if defined(HAVE_NETLINK)
58 zns_info->is_cmd = is_cmd;
59 if (is_cmd) {
60 zns_info->sock = zns->netlink_cmd.sock;
61 zns_info->seq = zns->netlink_cmd.seq;
62 } else {
63 zns_info->sock = zns->netlink.sock;
64 zns_info->seq = zns->netlink.seq;
65 }
66 #endif /* NETLINK */
67 }
68
69 /*
70 * Notify dplane when namespaces are enabled and disabled. The dplane
71 * needs to start and stop reading incoming events from the ns.
72 */
73 void zebra_dplane_ns_enable(struct zebra_ns *zns, bool enabled);
74
75 /*
76 * Result codes used when returning status back to the main zebra context.
77 */
78
79 /*
80 * Philosophy Note:
81 *
82 * Flags being SET/UNSET do not belong in the South Bound
83 * Interface. This Setting belongs at the calling level
84 * because we can and will have multiple different interfaces
85 * and we will have potentially multiple different
86 * modules/filters to call. As such Setting/Unsetting
87 * success failure should be handled by the caller.
88 */
89 enum zebra_dplane_status {
90 ZEBRA_DPLANE_STATUS_NONE = 0,
91 ZEBRA_DPLANE_INSTALL_SUCCESS,
92 ZEBRA_DPLANE_INSTALL_FAILURE,
93 ZEBRA_DPLANE_DELETE_SUCCESS,
94 ZEBRA_DPLANE_DELETE_FAILURE,
95
96 };
97
98 enum zebra_dplane_result {
99 ZEBRA_DPLANE_REQUEST_QUEUED,
100 ZEBRA_DPLANE_REQUEST_SUCCESS,
101 ZEBRA_DPLANE_REQUEST_FAILURE,
102 };
103
104 /*
105 * API between the zebra dataplane system and the main zebra processing
106 * context.
107 */
108
109 /*
110 * Operations that the dataplane can process.
111 */
112 enum dplane_op_e {
113 DPLANE_OP_NONE = 0,
114
115 /* Route update */
116 DPLANE_OP_ROUTE_INSTALL,
117 DPLANE_OP_ROUTE_UPDATE,
118 DPLANE_OP_ROUTE_DELETE,
119 DPLANE_OP_ROUTE_NOTIFY,
120
121 /* Nexthop update */
122 DPLANE_OP_NH_INSTALL,
123 DPLANE_OP_NH_UPDATE,
124 DPLANE_OP_NH_DELETE,
125
126 /* LSP update */
127 DPLANE_OP_LSP_INSTALL,
128 DPLANE_OP_LSP_UPDATE,
129 DPLANE_OP_LSP_DELETE,
130 DPLANE_OP_LSP_NOTIFY,
131
132 /* Pseudowire update */
133 DPLANE_OP_PW_INSTALL,
134 DPLANE_OP_PW_UNINSTALL,
135
136 /* System route notification */
137 DPLANE_OP_SYS_ROUTE_ADD,
138 DPLANE_OP_SYS_ROUTE_DELETE,
139
140 /* Interface address update */
141 DPLANE_OP_ADDR_INSTALL,
142 DPLANE_OP_ADDR_UNINSTALL,
143
144 /* MAC address update */
145 DPLANE_OP_MAC_INSTALL,
146 DPLANE_OP_MAC_DELETE,
147
148 /* EVPN neighbor updates */
149 DPLANE_OP_NEIGH_INSTALL,
150 DPLANE_OP_NEIGH_UPDATE,
151 DPLANE_OP_NEIGH_DELETE,
152
153 /* EVPN VTEP updates */
154 DPLANE_OP_VTEP_ADD,
155 DPLANE_OP_VTEP_DELETE,
156
157 /* Policy based routing rule update */
158 DPLANE_OP_RULE_ADD,
159 DPLANE_OP_RULE_DELETE,
160 DPLANE_OP_RULE_UPDATE,
161
162 /* Link layer address discovery */
163 DPLANE_OP_NEIGH_DISCOVER,
164
165 /* bridge port update */
166 DPLANE_OP_BR_PORT_UPDATE,
167
168 /* Policy based routing iptable update */
169 DPLANE_OP_IPTABLE_ADD,
170 DPLANE_OP_IPTABLE_DELETE,
171
172 /* Policy based routing ipset update */
173 DPLANE_OP_IPSET_ADD,
174 DPLANE_OP_IPSET_DELETE,
175 DPLANE_OP_IPSET_ENTRY_ADD,
176 DPLANE_OP_IPSET_ENTRY_DELETE,
177
178 /* LINK LAYER IP address update */
179 DPLANE_OP_NEIGH_IP_INSTALL,
180 DPLANE_OP_NEIGH_IP_DELETE,
181
182 DPLANE_OP_NEIGH_TABLE_UPDATE,
183 DPLANE_OP_GRE_SET,
184
185 /* Incoming interface address events */
186 DPLANE_OP_INTF_ADDR_ADD,
187 DPLANE_OP_INTF_ADDR_DEL,
188
189 /* Incoming interface config events */
190 DPLANE_OP_INTF_NETCONFIG,
191 };
192
193 /*
194 * The vxlan/evpn neighbor management code needs some values to use
195 * when programming neighbor changes. Offer some platform-neutral values
196 * here for use within the dplane apis and plugins.
197 */
198
199 /* Neighbor cache flags */
200 #define DPLANE_NTF_EXT_LEARNED 0x01
201 #define DPLANE_NTF_ROUTER 0x02
202 #define DPLANE_NTF_USE 0x04
203
204 /* Neighbor cache states */
205 #define DPLANE_NUD_REACHABLE 0x01
206 #define DPLANE_NUD_STALE 0x02
207 #define DPLANE_NUD_NOARP 0x04
208 #define DPLANE_NUD_PROBE 0x08
209 #define DPLANE_NUD_INCOMPLETE 0x10
210 #define DPLANE_NUD_PERMANENT 0x20
211 #define DPLANE_NUD_FAILED 0x40
212
213 /* MAC update flags - dplane_mac_info.update_flags */
214 #define DPLANE_MAC_REMOTE (1 << 0)
215 #define DPLANE_MAC_WAS_STATIC (1 << 1)
216 #define DPLANE_MAC_SET_STATIC (1 << 2)
217 #define DPLANE_MAC_SET_INACTIVE (1 << 3)
218
219 /* Neigh update flags - dplane_neigh_info.update_flags */
220 #define DPLANE_NEIGH_REMOTE (1 << 0)
221 #define DPLANE_NEIGH_WAS_STATIC (1 << 1)
222 #define DPLANE_NEIGH_SET_STATIC (1 << 2)
223 #define DPLANE_NEIGH_SET_INACTIVE (1 << 3)
224 #define DPLANE_NEIGH_NO_EXTENSION (1 << 4)
225
226 #define DPLANE_BR_PORT_NON_DF (1 << 0)
227
228 /* Definitions for the dplane 'netconf' apis, corresponding to the netlink
229 * NETCONF api.
230 * Sadly, netlink sends incremental updates, so its messages may contain
231 * just a single changed attribute, and not necessarily
232 * a complete snapshot of the attributes.
233 */
234 enum dplane_netconf_status_e {
235 DPLANE_NETCONF_STATUS_UNKNOWN = 0,
236 DPLANE_NETCONF_STATUS_ENABLED,
237 DPLANE_NETCONF_STATUS_DISABLED
238 };
239
240 /* Some special ifindex values that may be part of the dplane netconf api. */
241 #define DPLANE_NETCONF_IFINDEX_ALL -1
242 #define DPLANE_NETCONF_IFINDEX_DEFAULT -2
243
244 /* Enable system route notifications */
245 void dplane_enable_sys_route_notifs(void);
246
247 /*
248 * The dataplane context struct is used to exchange info between the main zebra
249 * context and the dataplane module(s). If these are two independent pthreads,
250 * they cannot share existing global data structures safely.
251 */
252
253 /* Define a tailq list type for context blocks. The list is exposed/public,
254 * but the internal linkage in the context struct is private, so there
255 * are accessor apis that support enqueue and dequeue.
256 */
257 TAILQ_HEAD(dplane_ctx_q, zebra_dplane_ctx);
258
259 /* Declare a type for (optional) extended interface info objects. */
260 TAILQ_HEAD(dplane_intf_extra_q, dplane_intf_extra);
261
262 /* Allocate a context object */
263 struct zebra_dplane_ctx *dplane_ctx_alloc(void);
264
265 /*
266 * Reset an allocated context object for re-use. All internal allocations are
267 * freed.
268 */
269 void dplane_ctx_reset(struct zebra_dplane_ctx *ctx);
270
271 /*
272 * Allow zebra code to walk the queue of pending contexts, evaluate each one
273 * using a callback function. The caller can supply an optional void* arg also.
274 * If the function returns 'true', the context will be dequeued and freed
275 * without being processed.
276 */
277 int dplane_clean_ctx_queue(bool (*context_cb)(struct zebra_dplane_ctx *ctx,
278 void *arg), void *val);
279
280 /* Return a dataplane results context block after use; the caller's pointer will
281 * be cleared.
282 */
283 void dplane_ctx_fini(struct zebra_dplane_ctx **pctx);
284
285 /* Enqueue a context block to caller's tailq. This exists so that the
286 * context struct can remain opaque.
287 */
288 void dplane_ctx_enqueue_tail(struct dplane_ctx_q *q,
289 const struct zebra_dplane_ctx *ctx);
290
291 /* Append a list of context blocks to another list - again, just keeping
292 * the context struct opaque.
293 */
294 void dplane_ctx_list_append(struct dplane_ctx_q *to_list,
295 struct dplane_ctx_q *from_list);
296
297 /* Dequeue a context block from the head of caller's tailq */
298 struct zebra_dplane_ctx *dplane_ctx_dequeue(struct dplane_ctx_q *q);
299 struct zebra_dplane_ctx *dplane_ctx_get_head(struct dplane_ctx_q *q);
300
301 /*
302 * Accessors for information from the context object
303 */
304 enum zebra_dplane_result dplane_ctx_get_status(
305 const struct zebra_dplane_ctx *ctx);
306 void dplane_ctx_set_status(struct zebra_dplane_ctx *ctx,
307 enum zebra_dplane_result status);
308 const char *dplane_res2str(enum zebra_dplane_result res);
309
310 enum dplane_op_e dplane_ctx_get_op(const struct zebra_dplane_ctx *ctx);
311 void dplane_ctx_set_op(struct zebra_dplane_ctx *ctx, enum dplane_op_e op);
312 const char *dplane_op2str(enum dplane_op_e op);
313
314 const struct prefix *dplane_ctx_get_dest(const struct zebra_dplane_ctx *ctx);
315 void dplane_ctx_set_dest(struct zebra_dplane_ctx *ctx,
316 const struct prefix *dest);
317 const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx *ctx);
318 void dplane_ctx_set_ifname(struct zebra_dplane_ctx *ctx, const char *ifname);
319 ifindex_t dplane_ctx_get_ifindex(const struct zebra_dplane_ctx *ctx);
320 void dplane_ctx_set_ifindex(struct zebra_dplane_ctx *ctx, ifindex_t ifindex);
321
322 /* Retrieve last/current provider id */
323 uint32_t dplane_ctx_get_provider(const struct zebra_dplane_ctx *ctx);
324
325 /* Providers running before the kernel can control whether a kernel
326 * update should be done.
327 */
328 void dplane_ctx_set_skip_kernel(struct zebra_dplane_ctx *ctx);
329 bool dplane_ctx_is_skip_kernel(const struct zebra_dplane_ctx *ctx);
330
331 /* Source prefix is a little special - use convention to return NULL
332 * to mean "no src prefix"
333 */
334 const struct prefix *dplane_ctx_get_src(const struct zebra_dplane_ctx *ctx);
335 void dplane_ctx_set_src(struct zebra_dplane_ctx *ctx, const struct prefix *src);
336
337 bool dplane_ctx_is_update(const struct zebra_dplane_ctx *ctx);
338 uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx *ctx);
339 uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx *ctx);
340 void dplane_ctx_set_vrf(struct zebra_dplane_ctx *ctx, vrf_id_t vrf);
341 vrf_id_t dplane_ctx_get_vrf(const struct zebra_dplane_ctx *ctx);
342
343 /* In some paths we have only a namespace id */
344 void dplane_ctx_set_ns_id(struct zebra_dplane_ctx *ctx, ns_id_t nsid);
345 ns_id_t dplane_ctx_get_ns_id(const struct zebra_dplane_ctx *ctx);
346
347 bool dplane_ctx_is_from_notif(const struct zebra_dplane_ctx *ctx);
348 void dplane_ctx_set_notif_provider(struct zebra_dplane_ctx *ctx,
349 uint32_t id);
350 uint32_t dplane_ctx_get_notif_provider(const struct zebra_dplane_ctx *ctx);
351
352 /* Accessors for route update information */
353 void dplane_ctx_set_type(struct zebra_dplane_ctx *ctx, int type);
354 int dplane_ctx_get_type(const struct zebra_dplane_ctx *ctx);
355 int dplane_ctx_get_old_type(const struct zebra_dplane_ctx *ctx);
356 void dplane_ctx_set_afi(struct zebra_dplane_ctx *ctx, afi_t afi);
357 afi_t dplane_ctx_get_afi(const struct zebra_dplane_ctx *ctx);
358 void dplane_ctx_set_safi(struct zebra_dplane_ctx *ctx, safi_t safi);
359 safi_t dplane_ctx_get_safi(const struct zebra_dplane_ctx *ctx);
360 void dplane_ctx_set_table(struct zebra_dplane_ctx *ctx, uint32_t table);
361 uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx *ctx);
362 route_tag_t dplane_ctx_get_tag(const struct zebra_dplane_ctx *ctx);
363 void dplane_ctx_set_tag(struct zebra_dplane_ctx *ctx, route_tag_t tag);
364 route_tag_t dplane_ctx_get_old_tag(const struct zebra_dplane_ctx *ctx);
365 uint16_t dplane_ctx_get_instance(const struct zebra_dplane_ctx *ctx);
366 void dplane_ctx_set_instance(struct zebra_dplane_ctx *ctx, uint16_t instance);
367 uint16_t dplane_ctx_get_old_instance(const struct zebra_dplane_ctx *ctx);
368 uint32_t dplane_ctx_get_metric(const struct zebra_dplane_ctx *ctx);
369 uint32_t dplane_ctx_get_old_metric(const struct zebra_dplane_ctx *ctx);
370 uint32_t dplane_ctx_get_mtu(const struct zebra_dplane_ctx *ctx);
371 uint32_t dplane_ctx_get_nh_mtu(const struct zebra_dplane_ctx *ctx);
372 uint8_t dplane_ctx_get_distance(const struct zebra_dplane_ctx *ctx);
373 void dplane_ctx_set_distance(struct zebra_dplane_ctx *ctx, uint8_t distance);
374 uint8_t dplane_ctx_get_old_distance(const struct zebra_dplane_ctx *ctx);
375
376 void dplane_ctx_set_nexthops(struct zebra_dplane_ctx *ctx, struct nexthop *nh);
377 void dplane_ctx_set_backup_nhg(struct zebra_dplane_ctx *ctx,
378 const struct nexthop_group *nhg);
379
380 uint32_t dplane_ctx_get_nhg_id(const struct zebra_dplane_ctx *ctx);
381 const struct nexthop_group *dplane_ctx_get_ng(
382 const struct zebra_dplane_ctx *ctx);
383 const struct nexthop_group *dplane_ctx_get_old_ng(
384 const struct zebra_dplane_ctx *ctx);
385
386 /* Optional extra info about interfaces in nexthops - a plugin must enable
387 * this extra info.
388 */
389 const struct dplane_intf_extra *
390 dplane_ctx_get_intf_extra(const struct zebra_dplane_ctx *ctx);
391
392 const struct dplane_intf_extra *
393 dplane_ctx_intf_extra_next(const struct zebra_dplane_ctx *ctx,
394 const struct dplane_intf_extra *ptr);
395
396 vrf_id_t dplane_intf_extra_get_vrfid(const struct dplane_intf_extra *ptr);
397 uint32_t dplane_intf_extra_get_ifindex(const struct dplane_intf_extra *ptr);
398 uint32_t dplane_intf_extra_get_flags(const struct dplane_intf_extra *ptr);
399 uint32_t dplane_intf_extra_get_status(const struct dplane_intf_extra *ptr);
400
401 /* Backup nexthop information (list of nexthops) if present. */
402 const struct nexthop_group *
403 dplane_ctx_get_backup_ng(const struct zebra_dplane_ctx *ctx);
404 const struct nexthop_group *
405 dplane_ctx_get_old_backup_ng(const struct zebra_dplane_ctx *ctx);
406
407 /* Accessors for nexthop information */
408 uint32_t dplane_ctx_get_nhe_id(const struct zebra_dplane_ctx *ctx);
409 uint32_t dplane_ctx_get_old_nhe_id(const struct zebra_dplane_ctx *ctx);
410 afi_t dplane_ctx_get_nhe_afi(const struct zebra_dplane_ctx *ctx);
411 vrf_id_t dplane_ctx_get_nhe_vrf_id(const struct zebra_dplane_ctx *ctx);
412 int dplane_ctx_get_nhe_type(const struct zebra_dplane_ctx *ctx);
413 const struct nexthop_group *
414 dplane_ctx_get_nhe_ng(const struct zebra_dplane_ctx *ctx);
415 const struct nh_grp *
416 dplane_ctx_get_nhe_nh_grp(const struct zebra_dplane_ctx *ctx);
417 uint8_t dplane_ctx_get_nhe_nh_grp_count(const struct zebra_dplane_ctx *ctx);
418
419 /* Accessors for LSP information */
420
421 /* Init the internal LSP data struct - necessary before adding to it.
422 * If 'lsp' is non-NULL, info will be copied from it to the internal
423 * context data area.
424 */
425 int dplane_ctx_lsp_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
426 struct zebra_lsp *lsp);
427
428 mpls_label_t dplane_ctx_get_in_label(const struct zebra_dplane_ctx *ctx);
429 void dplane_ctx_set_in_label(struct zebra_dplane_ctx *ctx,
430 mpls_label_t label);
431 uint8_t dplane_ctx_get_addr_family(const struct zebra_dplane_ctx *ctx);
432 void dplane_ctx_set_addr_family(struct zebra_dplane_ctx *ctx,
433 uint8_t family);
434 uint32_t dplane_ctx_get_lsp_flags(const struct zebra_dplane_ctx *ctx);
435 void dplane_ctx_set_lsp_flags(struct zebra_dplane_ctx *ctx,
436 uint32_t flags);
437 const struct nhlfe_list_head *dplane_ctx_get_nhlfe_list(
438 const struct zebra_dplane_ctx *ctx);
439 const struct nhlfe_list_head *dplane_ctx_get_backup_nhlfe_list(
440 const struct zebra_dplane_ctx *ctx);
441
442 struct zebra_nhlfe *dplane_ctx_add_nhlfe(struct zebra_dplane_ctx *ctx,
443 enum lsp_types_t lsp_type,
444 enum nexthop_types_t nh_type,
445 const union g_addr *gate,
446 ifindex_t ifindex, uint8_t num_labels,
447 mpls_label_t *out_labels);
448
449 struct zebra_nhlfe *dplane_ctx_add_backup_nhlfe(
450 struct zebra_dplane_ctx *ctx, enum lsp_types_t lsp_type,
451 enum nexthop_types_t nh_type, const union g_addr *gate,
452 ifindex_t ifindex, uint8_t num_labels, mpls_label_t *out_labels);
453
454 const struct zebra_nhlfe *
455 dplane_ctx_get_best_nhlfe(const struct zebra_dplane_ctx *ctx);
456 const struct zebra_nhlfe *
457 dplane_ctx_set_best_nhlfe(struct zebra_dplane_ctx *ctx,
458 struct zebra_nhlfe *nhlfe);
459 uint32_t dplane_ctx_get_lsp_num_ecmp(const struct zebra_dplane_ctx *ctx);
460
461 /* Accessors for pseudowire information */
462 mpls_label_t dplane_ctx_get_pw_local_label(const struct zebra_dplane_ctx *ctx);
463 mpls_label_t dplane_ctx_get_pw_remote_label(const struct zebra_dplane_ctx *ctx);
464 int dplane_ctx_get_pw_type(const struct zebra_dplane_ctx *ctx);
465 int dplane_ctx_get_pw_af(const struct zebra_dplane_ctx *ctx);
466 uint32_t dplane_ctx_get_pw_flags(const struct zebra_dplane_ctx *ctx);
467 int dplane_ctx_get_pw_status(const struct zebra_dplane_ctx *ctx);
468 void dplane_ctx_set_pw_status(struct zebra_dplane_ctx *ctx, int status);
469 const union g_addr *dplane_ctx_get_pw_dest(
470 const struct zebra_dplane_ctx *ctx);
471 const union pw_protocol_fields *dplane_ctx_get_pw_proto(
472 const struct zebra_dplane_ctx *ctx);
473 const struct nexthop_group *dplane_ctx_get_pw_nhg(
474 const struct zebra_dplane_ctx *ctx);
475 const struct nexthop_group *
476 dplane_ctx_get_pw_primary_nhg(const struct zebra_dplane_ctx *ctx);
477 const struct nexthop_group *
478 dplane_ctx_get_pw_backup_nhg(const struct zebra_dplane_ctx *ctx);
479
480 /* Accessors for interface information */
481 uint32_t dplane_ctx_get_intf_metric(const struct zebra_dplane_ctx *ctx);
482 void dplane_ctx_set_intf_metric(struct zebra_dplane_ctx *ctx, uint32_t metric);
483 /* Is interface addr p2p? */
484 bool dplane_ctx_intf_is_connected(const struct zebra_dplane_ctx *ctx);
485 void dplane_ctx_intf_set_connected(struct zebra_dplane_ctx *ctx);
486 bool dplane_ctx_intf_is_secondary(const struct zebra_dplane_ctx *ctx);
487 void dplane_ctx_intf_set_secondary(struct zebra_dplane_ctx *ctx);
488 bool dplane_ctx_intf_is_broadcast(const struct zebra_dplane_ctx *ctx);
489 void dplane_ctx_intf_set_broadcast(struct zebra_dplane_ctx *ctx);
490 const struct prefix *dplane_ctx_get_intf_addr(
491 const struct zebra_dplane_ctx *ctx);
492 void dplane_ctx_set_intf_addr(struct zebra_dplane_ctx *ctx,
493 const struct prefix *p);
494 bool dplane_ctx_intf_has_dest(const struct zebra_dplane_ctx *ctx);
495 const struct prefix *dplane_ctx_get_intf_dest(
496 const struct zebra_dplane_ctx *ctx);
497 void dplane_ctx_set_intf_dest(struct zebra_dplane_ctx *ctx,
498 const struct prefix *p);
499 bool dplane_ctx_intf_has_label(const struct zebra_dplane_ctx *ctx);
500 const char *dplane_ctx_get_intf_label(const struct zebra_dplane_ctx *ctx);
501 void dplane_ctx_set_intf_label(struct zebra_dplane_ctx *ctx, const char *label);
502
503 /* Accessors for MAC information */
504 vlanid_t dplane_ctx_mac_get_vlan(const struct zebra_dplane_ctx *ctx);
505 bool dplane_ctx_mac_is_sticky(const struct zebra_dplane_ctx *ctx);
506 uint32_t dplane_ctx_mac_get_update_flags(const struct zebra_dplane_ctx *ctx);
507 uint32_t dplane_ctx_mac_get_nhg_id(const struct zebra_dplane_ctx *ctx);
508 const struct ethaddr *dplane_ctx_mac_get_addr(
509 const struct zebra_dplane_ctx *ctx);
510 const struct in_addr *dplane_ctx_mac_get_vtep_ip(
511 const struct zebra_dplane_ctx *ctx);
512 ifindex_t dplane_ctx_mac_get_br_ifindex(const struct zebra_dplane_ctx *ctx);
513
514 /* Accessors for neighbor information */
515 const struct ipaddr *dplane_ctx_neigh_get_ipaddr(
516 const struct zebra_dplane_ctx *ctx);
517 const struct ethaddr *dplane_ctx_neigh_get_mac(
518 const struct zebra_dplane_ctx *ctx);
519 const struct ipaddr *
520 dplane_ctx_neigh_get_link_ip(const struct zebra_dplane_ctx *ctx);
521 uint32_t dplane_ctx_neigh_get_flags(const struct zebra_dplane_ctx *ctx);
522 uint16_t dplane_ctx_neigh_get_state(const struct zebra_dplane_ctx *ctx);
523 uint32_t dplane_ctx_neigh_get_update_flags(const struct zebra_dplane_ctx *ctx);
524
525 /* Accessors for policy based routing rule information */
526 int dplane_ctx_rule_get_sock(const struct zebra_dplane_ctx *ctx);
527 int dplane_ctx_rule_get_unique(const struct zebra_dplane_ctx *ctx);
528 int dplane_ctx_rule_get_seq(const struct zebra_dplane_ctx *ctx);
529 const char *dplane_ctx_rule_get_ifname(const struct zebra_dplane_ctx *ctx);
530 uint32_t dplane_ctx_rule_get_priority(const struct zebra_dplane_ctx *ctx);
531 uint32_t dplane_ctx_rule_get_old_priority(const struct zebra_dplane_ctx *ctx);
532 uint32_t dplane_ctx_rule_get_table(const struct zebra_dplane_ctx *ctx);
533 uint32_t dplane_ctx_rule_get_old_table(const struct zebra_dplane_ctx *ctx);
534 uint32_t dplane_ctx_rule_get_filter_bm(const struct zebra_dplane_ctx *ctx);
535 uint32_t dplane_ctx_rule_get_old_filter_bm(const struct zebra_dplane_ctx *ctx);
536 uint32_t dplane_ctx_rule_get_fwmark(const struct zebra_dplane_ctx *ctx);
537 uint32_t dplane_ctx_rule_get_old_fwmark(const struct zebra_dplane_ctx *ctx);
538 uint8_t dplane_ctx_rule_get_dsfield(const struct zebra_dplane_ctx *ctx);
539 uint8_t dplane_ctx_rule_get_old_dsfield(const struct zebra_dplane_ctx *ctx);
540 uint8_t dplane_ctx_rule_get_ipproto(const struct zebra_dplane_ctx *ctx);
541 uint8_t dplane_ctx_rule_get_old_ipproto(const struct zebra_dplane_ctx *ctx);
542 const struct prefix *
543 dplane_ctx_rule_get_src_ip(const struct zebra_dplane_ctx *ctx);
544 const struct prefix *
545 dplane_ctx_rule_get_old_src_ip(const struct zebra_dplane_ctx *ctx);
546 const struct prefix *
547 dplane_ctx_rule_get_dst_ip(const struct zebra_dplane_ctx *ctx);
548 const struct prefix *
549 dplane_ctx_rule_get_old_dst_ip(const struct zebra_dplane_ctx *ctx);
550 /* Accessors for policy based routing iptable information */
551 struct zebra_pbr_iptable;
552 void dplane_ctx_get_pbr_iptable(const struct zebra_dplane_ctx *ctx,
553 struct zebra_pbr_iptable *table);
554 struct zebra_pbr_ipset;
555 void dplane_ctx_get_pbr_ipset(const struct zebra_dplane_ctx *ctx,
556 struct zebra_pbr_ipset *ipset);
557 struct zebra_pbr_ipset_entry;
558 void dplane_ctx_get_pbr_ipset_entry(const struct zebra_dplane_ctx *ctx,
559 struct zebra_pbr_ipset_entry *entry);
560 /* Accessors for bridge port information */
561 uint32_t dplane_ctx_get_br_port_flags(const struct zebra_dplane_ctx *ctx);
562 uint32_t
563 dplane_ctx_get_br_port_sph_filter_cnt(const struct zebra_dplane_ctx *ctx);
564 const struct in_addr *
565 dplane_ctx_get_br_port_sph_filters(const struct zebra_dplane_ctx *ctx);
566 uint32_t
567 dplane_ctx_get_br_port_backup_nhg_id(const struct zebra_dplane_ctx *ctx);
568
569 /* Accessors for neighbor table information */
570 uint8_t dplane_ctx_neightable_get_family(const struct zebra_dplane_ctx *ctx);
571 uint32_t
572 dplane_ctx_neightable_get_app_probes(const struct zebra_dplane_ctx *ctx);
573 uint32_t
574 dplane_ctx_neightable_get_mcast_probes(const struct zebra_dplane_ctx *ctx);
575 uint32_t
576 dplane_ctx_neightable_get_ucast_probes(const struct zebra_dplane_ctx *ctx);
577
578 /* Accessor for GRE set */
579 uint32_t
580 dplane_ctx_gre_get_link_ifindex(const struct zebra_dplane_ctx *ctx);
581 unsigned int
582 dplane_ctx_gre_get_mtu(const struct zebra_dplane_ctx *ctx);
583 const struct zebra_l2info_gre *
584 dplane_ctx_gre_get_info(const struct zebra_dplane_ctx *ctx);
585
586 /* Interface netconf info */
587 ifindex_t dplane_ctx_get_netconf_ifindex(const struct zebra_dplane_ctx *ctx);
588 ns_id_t dplane_ctx_get_netconf_ns_id(const struct zebra_dplane_ctx *ctx);
589 void dplane_ctx_set_netconf_ifindex(struct zebra_dplane_ctx *ctx,
590 ifindex_t ifindex);
591 void dplane_ctx_set_netconf_ns_id(struct zebra_dplane_ctx *ctx, ns_id_t ns_id);
592 enum dplane_netconf_status_e
593 dplane_ctx_get_netconf_mpls(const struct zebra_dplane_ctx *ctx);
594 enum dplane_netconf_status_e
595 dplane_ctx_get_netconf_mcast(const struct zebra_dplane_ctx *ctx);
596 void dplane_ctx_set_netconf_mpls(struct zebra_dplane_ctx *ctx,
597 enum dplane_netconf_status_e val);
598 void dplane_ctx_set_netconf_mcast(struct zebra_dplane_ctx *ctx,
599 enum dplane_netconf_status_e val);
600
601 /* Namespace fd info - esp. for netlink communication */
602 const struct zebra_dplane_info *dplane_ctx_get_ns(
603 const struct zebra_dplane_ctx *ctx);
604 int dplane_ctx_get_ns_sock(const struct zebra_dplane_ctx *ctx);
605
606 /* Indicates zebra shutdown/exit is in progress. Some operations may be
607 * simplified or skipped during shutdown processing.
608 */
609 bool dplane_is_in_shutdown(void);
610
611 /*
612 * Enqueue route change operations for the dataplane.
613 */
614 enum zebra_dplane_result dplane_route_add(struct route_node *rn,
615 struct route_entry *re);
616
617 enum zebra_dplane_result dplane_route_update(struct route_node *rn,
618 struct route_entry *re,
619 struct route_entry *old_re);
620
621 enum zebra_dplane_result dplane_route_delete(struct route_node *rn,
622 struct route_entry *re);
623
624 /* Notify the dplane when system/connected routes change */
625 enum zebra_dplane_result dplane_sys_route_add(struct route_node *rn,
626 struct route_entry *re);
627 enum zebra_dplane_result dplane_sys_route_del(struct route_node *rn,
628 struct route_entry *re);
629
630 /* Update from an async notification, to bring other fibs up-to-date */
631 enum zebra_dplane_result dplane_route_notif_update(
632 struct route_node *rn,
633 struct route_entry *re,
634 enum dplane_op_e op,
635 struct zebra_dplane_ctx *ctx);
636
637 /*
638 * Enqueue bridge port changes for the dataplane.
639 */
640 enum zebra_dplane_result dplane_br_port_update(
641 const struct interface *ifp, bool non_df, uint32_t sph_filter_cnt,
642 const struct in_addr *sph_filters, uint32_t backup_nhg_id);
643
644 /* Forward ref of nhg_hash_entry */
645 struct nhg_hash_entry;
646 /*
647 * Enqueue a nexthop change operation for the dataplane.
648 */
649 enum zebra_dplane_result dplane_nexthop_add(struct nhg_hash_entry *nhe);
650 enum zebra_dplane_result dplane_nexthop_update(struct nhg_hash_entry *nhe);
651 enum zebra_dplane_result dplane_nexthop_delete(struct nhg_hash_entry *nhe);
652
653 /*
654 * Enqueue LSP change operations for the dataplane.
655 */
656 enum zebra_dplane_result dplane_lsp_add(struct zebra_lsp *lsp);
657 enum zebra_dplane_result dplane_lsp_update(struct zebra_lsp *lsp);
658 enum zebra_dplane_result dplane_lsp_delete(struct zebra_lsp *lsp);
659
660 /* Update or un-install resulting from an async notification */
661 enum zebra_dplane_result dplane_lsp_notif_update(struct zebra_lsp *lsp,
662 enum dplane_op_e op,
663 struct zebra_dplane_ctx *ctx);
664
665 /*
666 * Enqueue pseudowire operations for the dataplane.
667 */
668 enum zebra_dplane_result dplane_pw_install(struct zebra_pw *pw);
669 enum zebra_dplane_result dplane_pw_uninstall(struct zebra_pw *pw);
670
671 /*
672 * Enqueue interface address changes for the dataplane.
673 */
674 enum zebra_dplane_result dplane_intf_addr_set(const struct interface *ifp,
675 const struct connected *ifc);
676 enum zebra_dplane_result dplane_intf_addr_unset(const struct interface *ifp,
677 const struct connected *ifc);
678
679 /*
680 * Link layer operations for the dataplane.
681 */
682 enum zebra_dplane_result dplane_neigh_ip_update(enum dplane_op_e op,
683 const struct interface *ifp,
684 struct ipaddr *link_ip,
685 struct ipaddr *ip,
686 uint32_t ndm_state,
687 int protocol);
688
689 /*
690 * Enqueue evpn mac operations for the dataplane.
691 */
692 enum zebra_dplane_result dplane_rem_mac_add(const struct interface *ifp,
693 const struct interface *bridge_ifp,
694 vlanid_t vid,
695 const struct ethaddr *mac,
696 struct in_addr vtep_ip,
697 bool sticky,
698 uint32_t nhg_id,
699 bool was_static);
700
701 enum zebra_dplane_result dplane_local_mac_add(const struct interface *ifp,
702 const struct interface *bridge_ifp,
703 vlanid_t vid,
704 const struct ethaddr *mac,
705 bool sticky,
706 uint32_t set_static,
707 uint32_t set_inactive);
708
709 enum zebra_dplane_result
710 dplane_local_mac_del(const struct interface *ifp,
711 const struct interface *bridge_ifp, vlanid_t vid,
712 const struct ethaddr *mac);
713
714 enum zebra_dplane_result dplane_rem_mac_del(const struct interface *ifp,
715 const struct interface *bridge_ifp,
716 vlanid_t vid,
717 const struct ethaddr *mac,
718 struct in_addr vtep_ip);
719
720 /* Helper api to init an empty or new context for a MAC update */
721 void dplane_mac_init(struct zebra_dplane_ctx *ctx,
722 const struct interface *ifp,
723 const struct interface *br_ifp,
724 vlanid_t vid,
725 const struct ethaddr *mac,
726 struct in_addr vtep_ip,
727 bool sticky,
728 uint32_t nhg_id, uint32_t update_flags);
729
730 /*
731 * Enqueue evpn neighbor updates for the dataplane.
732 */
733 enum zebra_dplane_result dplane_rem_neigh_add(const struct interface *ifp,
734 const struct ipaddr *ip,
735 const struct ethaddr *mac,
736 uint32_t flags, bool was_static);
737 enum zebra_dplane_result dplane_local_neigh_add(const struct interface *ifp,
738 const struct ipaddr *ip,
739 const struct ethaddr *mac,
740 bool set_router, bool set_static,
741 bool set_inactive);
742 enum zebra_dplane_result dplane_rem_neigh_delete(const struct interface *ifp,
743 const struct ipaddr *ip);
744
745 /*
746 * Enqueue evpn VTEP updates for the dataplane.
747 */
748 enum zebra_dplane_result dplane_vtep_add(const struct interface *ifp,
749 const struct in_addr *ip,
750 vni_t vni);
751 enum zebra_dplane_result dplane_vtep_delete(const struct interface *ifp,
752 const struct in_addr *ip,
753 vni_t vni);
754
755 /*
756 * Enqueue a neighbour discovery request for the dataplane.
757 */
758 enum zebra_dplane_result dplane_neigh_discover(const struct interface *ifp,
759 const struct ipaddr *ip);
760
761 /*
762 * Enqueue a neighbor table parameter set
763 */
764 enum zebra_dplane_result dplane_neigh_table_update(const struct interface *ifp,
765 const uint8_t family,
766 const uint32_t app_probes,
767 const uint32_t ucast_probes,
768 const uint32_t mcast_probes);
769
770 /*
771 * Enqueue a GRE set
772 */
773 enum zebra_dplane_result
774 dplane_gre_set(struct interface *ifp, struct interface *ifp_link,
775 unsigned int mtu, const struct zebra_l2info_gre *gre_info);
776
777 /* Forward ref of zebra_pbr_rule */
778 struct zebra_pbr_rule;
779
780 /*
781 * Enqueue policy based routing rule for the dataplane.
782 * It is possible that the user-defined sequence number and the one in the
783 * forwarding plane may not coincide, hence the API requires a separate
784 * rule priority - maps to preference/FRA_PRIORITY on Linux.
785 */
786 enum zebra_dplane_result dplane_pbr_rule_add(struct zebra_pbr_rule *rule);
787 enum zebra_dplane_result dplane_pbr_rule_delete(struct zebra_pbr_rule *rule);
788 enum zebra_dplane_result
789 dplane_pbr_rule_update(struct zebra_pbr_rule *old_rule,
790 struct zebra_pbr_rule *new_rule);
791 /* iptable */
792 enum zebra_dplane_result
793 dplane_pbr_iptable_add(struct zebra_pbr_iptable *iptable);
794 enum zebra_dplane_result
795 dplane_pbr_iptable_delete(struct zebra_pbr_iptable *iptable);
796
797 /* ipset */
798 struct zebra_pbr_ipset;
799 enum zebra_dplane_result dplane_pbr_ipset_add(struct zebra_pbr_ipset *ipset);
800 enum zebra_dplane_result dplane_pbr_ipset_delete(struct zebra_pbr_ipset *ipset);
801
802 /* ipset entry */
803 struct zebra_pbr_ipset_entry;
804 enum zebra_dplane_result
805 dplane_pbr_ipset_entry_add(struct zebra_pbr_ipset_entry *ipset);
806 enum zebra_dplane_result
807 dplane_pbr_ipset_entry_delete(struct zebra_pbr_ipset_entry *ipset);
808
809 /* Encode route information into data plane context. */
810 int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
811 struct route_node *rn, struct route_entry *re);
812
813 /* Encode next hop information into data plane context. */
814 int dplane_ctx_nexthop_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
815 struct nhg_hash_entry *nhe);
816
817 /* Retrieve the limit on the number of pending, unprocessed updates. */
818 uint32_t dplane_get_in_queue_limit(void);
819
820 /* Configure limit on the number of pending, queued updates. If 'unset', reset
821 * to default value.
822 */
823 void dplane_set_in_queue_limit(uint32_t limit, bool set);
824
825 /* Retrieve the current queue depth of incoming, unprocessed updates */
826 uint32_t dplane_get_in_queue_len(void);
827
828 /*
829 * Vty/cli apis
830 */
831 int dplane_show_helper(struct vty *vty, bool detailed);
832 int dplane_show_provs_helper(struct vty *vty, bool detailed);
833 int dplane_config_write_helper(struct vty *vty);
834
835 /*
836 * Dataplane providers: modules that process or consume dataplane events.
837 */
838
839 struct zebra_dplane_provider;
840
841 /* Support string name for a dataplane provider */
842 #define DPLANE_PROVIDER_NAMELEN 64
843
844 /* Priority or ordering values for providers. The idea is that there may be
845 * some pre-processing, followed by an external or remote dataplane,
846 * followed by the kernel, followed by some post-processing step (such as
847 * the fpm output stream.)
848 */
849 enum dplane_provider_prio {
850 DPLANE_PRIO_NONE = 0,
851 DPLANE_PRIO_PREPROCESS,
852 DPLANE_PRIO_PRE_KERNEL,
853 DPLANE_PRIO_KERNEL,
854 DPLANE_PRIO_POSTPROCESS,
855 DPLANE_PRIO_LAST
856 };
857
858 /* Flags values used during provider registration. */
859 #define DPLANE_PROV_FLAGS_DEFAULT 0x0
860
861 /* Provider will be spawning its own worker thread */
862 #define DPLANE_PROV_FLAG_THREADED 0x1
863
864 /* Provider registration: ordering or priority value, callbacks, and optional
865 * opaque data value. If 'prov_p', return the newly-allocated provider object
866 * on success.
867 */
868
869 /* Providers offer an entry-point for incoming work, called in the context of
870 * the dataplane pthread. The dataplane pthread enqueues any new work to the
871 * provider's 'inbound' queue, then calls the callback. The dataplane
872 * then checks the provider's outbound queue for completed work.
873 */
874
875 /*
876 * Providers can offer a 'start' callback; if present, the dataplane will
877 * call it when it is starting - when its pthread and event-scheduling
878 * thread_master are available.
879 */
880
881 /* Providers can offer an entry-point for shutdown and cleanup. This is called
882 * with 'early' during shutdown, to indicate that the dataplane subsystem
883 * is allowing work to move through the providers and finish.
884 * When called without 'early', the provider should release
885 * all resources (if it has any allocated).
886 */
887 int dplane_provider_register(const char *name,
888 enum dplane_provider_prio prio,
889 int flags,
890 int (*start_fp)(struct zebra_dplane_provider *),
891 int (*fp)(struct zebra_dplane_provider *),
892 int (*fini_fp)(struct zebra_dplane_provider *,
893 bool early),
894 void *data,
895 struct zebra_dplane_provider **prov_p);
896
897 /* Accessors for provider attributes */
898 const char *dplane_provider_get_name(const struct zebra_dplane_provider *prov);
899 uint32_t dplane_provider_get_id(const struct zebra_dplane_provider *prov);
900 void *dplane_provider_get_data(const struct zebra_dplane_provider *prov);
901 bool dplane_provider_is_threaded(const struct zebra_dplane_provider *prov);
902
903 /* Lock/unlock a provider's mutex - iff the provider was registered with
904 * the THREADED flag.
905 */
906 void dplane_provider_lock(struct zebra_dplane_provider *prov);
907 void dplane_provider_unlock(struct zebra_dplane_provider *prov);
908
909 /* Obtain thread_master for dataplane thread */
910 struct thread_master *dplane_get_thread_master(void);
911
912 /* Providers should (generally) limit number of updates per work cycle */
913 int dplane_provider_get_work_limit(const struct zebra_dplane_provider *prov);
914
915 /* Provider api to signal that work/events are available
916 * for the dataplane pthread.
917 */
918 int dplane_provider_work_ready(void);
919
920 /* Dequeue, maintain associated counter and locking */
921 struct zebra_dplane_ctx *dplane_provider_dequeue_in_ctx(
922 struct zebra_dplane_provider *prov);
923
924 /* Dequeue work to a list, maintain counter and locking, return count */
925 int dplane_provider_dequeue_in_list(struct zebra_dplane_provider *prov,
926 struct dplane_ctx_q *listp);
927
928 /* Current completed work queue length */
929 uint32_t dplane_provider_out_ctx_queue_len(struct zebra_dplane_provider *prov);
930
931 /* Enqueue completed work, maintain associated counter and locking */
932 void dplane_provider_enqueue_out_ctx(struct zebra_dplane_provider *prov,
933 struct zebra_dplane_ctx *ctx);
934
935 /* Enqueue a context directly to zebra main. */
936 void dplane_provider_enqueue_to_zebra(struct zebra_dplane_ctx *ctx);
937
938 /* Enable collection of extra info about interfaces in route updates;
939 * this allows a provider/plugin to see some extra info in route update
940 * context objects.
941 */
942 void dplane_enable_intf_extra_info(void);
943
944 /*
945 * Initialize the dataplane modules at zebra startup. This is currently called
946 * by the rib module. Zebra registers a results callback with the dataplane.
947 * The callback is called in the dataplane pthread context,
948 * so the expectation is that the contexts are queued for the zebra
949 * main pthread.
950 */
951 void zebra_dplane_init(int (*) (struct dplane_ctx_q *));
952
953 /*
954 * Start the dataplane pthread. This step needs to be run later than the
955 * 'init' step, in case zebra has fork-ed.
956 */
957 void zebra_dplane_start(void);
958
959 /* Finalize/cleanup apis, one called early as shutdown is starting,
960 * one called late at the end of zebra shutdown, and then one called
961 * from the zebra main pthread to stop the dplane pthread and
962 * free all resources.
963 *
964 * Zebra expects to try to clean up all vrfs and all routes during
965 * shutdown, so the dplane must be available until very late.
966 */
967 void zebra_dplane_pre_finish(void);
968 void zebra_dplane_finish(void);
969 void zebra_dplane_shutdown(void);
970
971 #ifdef __cplusplus
972 }
973 #endif
974
975 #endif /* _ZEBRA_DPLANE_H */