]>
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" |
7597ac7b | 28 | #include "lib/vlan.h" |
7cdb1a84 MS |
29 | #include "zebra/zebra_ns.h" |
30 | #include "zebra/rib.h" | |
31 | #include "zebra/zserv.h" | |
0f461727 | 32 | #include "zebra/zebra_mpls.h" |
f820d025 | 33 | #include "zebra/zebra_nhg.h" |
ea1c14f6 | 34 | |
51e94aa7 EDP |
35 | #ifdef __cplusplus |
36 | extern "C" { | |
37 | #endif | |
38 | ||
85a75f1e MS |
39 | /* Key netlink info from zebra ns */ |
40 | struct zebra_dplane_info { | |
41 | ns_id_t ns_id; | |
42 | ||
43 | #if defined(HAVE_NETLINK) | |
7cdb1a84 | 44 | struct nlsock nls; |
85a75f1e MS |
45 | bool is_cmd; |
46 | #endif | |
47 | }; | |
48 | ||
49 | /* Utility to fill in zns info from main zns struct */ | |
50 | static inline void | |
51 | zebra_dplane_info_from_zns(struct zebra_dplane_info *zns_info, | |
52 | const struct zebra_ns *zns, bool is_cmd) | |
53 | { | |
54 | zns_info->ns_id = zns->ns_id; | |
55 | ||
56 | #if defined(HAVE_NETLINK) | |
57 | zns_info->is_cmd = is_cmd; | |
58 | if (is_cmd) { | |
7cdb1a84 | 59 | zns_info->nls = zns->netlink_cmd; |
85a75f1e | 60 | } else { |
7cdb1a84 | 61 | zns_info->nls = zns->netlink; |
85a75f1e MS |
62 | } |
63 | #endif /* NETLINK */ | |
64 | } | |
65 | ||
ea1c14f6 MS |
66 | /* |
67 | * Result codes used when returning status back to the main zebra context. | |
68 | */ | |
69 | ||
70 | /* | |
71 | * Philosophy Note: | |
72 | * | |
73 | * Flags being SET/UNSET do not belong in the South Bound | |
74 | * Interface. This Setting belongs at the calling level | |
75 | * because we can and will have multiple different interfaces | |
76 | * and we will have potentially multiple different | |
77 | * modules/filters to call. As such Setting/Unsetting | |
78 | * success failure should be handled by the caller. | |
79 | */ | |
80 | enum zebra_dplane_status { | |
81 | ZEBRA_DPLANE_STATUS_NONE = 0, | |
82 | ZEBRA_DPLANE_INSTALL_SUCCESS, | |
83 | ZEBRA_DPLANE_INSTALL_FAILURE, | |
84 | ZEBRA_DPLANE_DELETE_SUCCESS, | |
85 | ZEBRA_DPLANE_DELETE_FAILURE, | |
86 | ||
87 | }; | |
88 | ||
89 | enum zebra_dplane_result { | |
90 | ZEBRA_DPLANE_REQUEST_QUEUED, | |
91 | ZEBRA_DPLANE_REQUEST_SUCCESS, | |
92 | ZEBRA_DPLANE_REQUEST_FAILURE, | |
93 | }; | |
94 | ||
7cdb1a84 MS |
95 | /* |
96 | * API between the zebra dataplane system and the main zebra processing | |
97 | * context. | |
98 | */ | |
99 | ||
100 | /* | |
101 | * Enqueue a route install or update for the dataplane. | |
102 | */ | |
5709131c | 103 | enum dplane_op_e { |
7cdb1a84 MS |
104 | DPLANE_OP_NONE = 0, |
105 | ||
106 | /* Route update */ | |
107 | DPLANE_OP_ROUTE_INSTALL, | |
108 | DPLANE_OP_ROUTE_UPDATE, | |
109 | DPLANE_OP_ROUTE_DELETE, | |
54818e3b | 110 | DPLANE_OP_ROUTE_NOTIFY, |
7cdb1a84 | 111 | |
f820d025 SW |
112 | /* Nexthop update */ |
113 | DPLANE_OP_NH_INSTALL, | |
114 | DPLANE_OP_NH_UPDATE, | |
115 | DPLANE_OP_NH_DELETE, | |
116 | ||
16c628de MS |
117 | /* LSP update */ |
118 | DPLANE_OP_LSP_INSTALL, | |
119 | DPLANE_OP_LSP_UPDATE, | |
97d8d05a | 120 | DPLANE_OP_LSP_DELETE, |
104e3ad9 | 121 | DPLANE_OP_LSP_NOTIFY, |
97d8d05a MS |
122 | |
123 | /* Pseudowire update */ | |
124 | DPLANE_OP_PW_INSTALL, | |
125 | DPLANE_OP_PW_UNINSTALL, | |
cf363e1b MS |
126 | |
127 | /* System route notification */ | |
128 | DPLANE_OP_SYS_ROUTE_ADD, | |
129 | DPLANE_OP_SYS_ROUTE_DELETE, | |
a4a4802a MS |
130 | |
131 | /* Interface address update */ | |
132 | DPLANE_OP_ADDR_INSTALL, | |
133 | DPLANE_OP_ADDR_UNINSTALL, | |
7597ac7b MS |
134 | |
135 | /* MAC address update */ | |
136 | DPLANE_OP_MAC_INSTALL, | |
137 | DPLANE_OP_MAC_DELETE, | |
f2412b2d MS |
138 | |
139 | /* EVPN neighbor updates */ | |
140 | DPLANE_OP_NEIGH_INSTALL, | |
931fa60c | 141 | DPLANE_OP_NEIGH_UPDATE, |
f2412b2d | 142 | DPLANE_OP_NEIGH_DELETE, |
0bbd4ff4 MS |
143 | |
144 | /* EVPN VTEP updates */ | |
145 | DPLANE_OP_VTEP_ADD, | |
146 | DPLANE_OP_VTEP_DELETE, | |
60d8d43b JU |
147 | |
148 | /* Policy based routing rule update */ | |
149 | DPLANE_OP_RULE_ADD, | |
150 | DPLANE_OP_RULE_DELETE, | |
151 | DPLANE_OP_RULE_UPDATE, | |
d68e74b4 JU |
152 | |
153 | /* Link layer address discovery */ | |
154 | DPLANE_OP_NEIGH_DISCOVER, | |
5709131c | 155 | }; |
7cdb1a84 | 156 | |
931fa60c MS |
157 | /* |
158 | * The vxlan/evpn neighbor management code needs some values to use | |
159 | * when programming neighbor changes. Offer some platform-neutral values | |
160 | * here for use within the dplane apis and plugins. | |
161 | */ | |
162 | ||
163 | /* Neighbor cache flags */ | |
164 | #define DPLANE_NTF_EXT_LEARNED 0x01 | |
165 | #define DPLANE_NTF_ROUTER 0x02 | |
d68e74b4 | 166 | #define DPLANE_NTF_USE 0x04 |
931fa60c MS |
167 | |
168 | /* Neighbor cache states */ | |
169 | #define DPLANE_NUD_REACHABLE 0x01 | |
170 | #define DPLANE_NUD_STALE 0x02 | |
171 | #define DPLANE_NUD_NOARP 0x04 | |
172 | #define DPLANE_NUD_PROBE 0x08 | |
d68e74b4 | 173 | #define DPLANE_NUD_INCOMPLETE 0x10 |
931fa60c | 174 | |
f188e68e AK |
175 | /* MAC update flags - dplane_mac_info.update_flags */ |
176 | #define DPLANE_MAC_REMOTE (1 << 0) | |
177 | #define DPLANE_MAC_WAS_STATIC (1 << 1) | |
178 | #define DPLANE_MAC_SET_STATIC (1 << 2) | |
179 | #define DPLANE_MAC_SET_INACTIVE (1 << 3) | |
180 | ||
181 | /* Neigh update flags - dplane_neigh_info.update_flags */ | |
182 | #define DPLANE_NEIGH_REMOTE (1 << 0) | |
183 | #define DPLANE_NEIGH_WAS_STATIC (1 << 1) | |
184 | #define DPLANE_NEIGH_SET_STATIC (1 << 2) | |
185 | #define DPLANE_NEIGH_SET_INACTIVE (1 << 3) | |
186 | ||
cf363e1b MS |
187 | /* Enable system route notifications */ |
188 | void dplane_enable_sys_route_notifs(void); | |
189 | ||
7cdb1a84 | 190 | /* |
25779064 | 191 | * The dataplane context struct is used to exchange info between the main zebra |
7cdb1a84 MS |
192 | * context and the dataplane module(s). If these are two independent pthreads, |
193 | * they cannot share existing global data structures safely. | |
194 | */ | |
7cdb1a84 MS |
195 | |
196 | /* Define a tailq list type for context blocks. The list is exposed/public, | |
197 | * but the internal linkage in the context struct is private, so there | |
198 | * are accessor apis that support enqueue and dequeue. | |
199 | */ | |
25779064 | 200 | TAILQ_HEAD(dplane_ctx_q, zebra_dplane_ctx); |
7cdb1a84 | 201 | |
593e4eb1 MS |
202 | /* Allocate a context object */ |
203 | struct zebra_dplane_ctx *dplane_ctx_alloc(void); | |
204 | ||
f73a8467 MS |
205 | /* |
206 | * Reset an allocated context object for re-use. All internal allocations are | |
207 | * freed. | |
208 | */ | |
209 | void dplane_ctx_reset(struct zebra_dplane_ctx *ctx); | |
210 | ||
7cdb1a84 MS |
211 | /* Return a dataplane results context block after use; the caller's pointer will |
212 | * be cleared. | |
213 | */ | |
25779064 | 214 | void dplane_ctx_fini(struct zebra_dplane_ctx **pctx); |
7cdb1a84 | 215 | |
14b0bc8e | 216 | /* Enqueue a context block to caller's tailq. This exists so that the |
7cdb1a84 MS |
217 | * context struct can remain opaque. |
218 | */ | |
25779064 MS |
219 | void dplane_ctx_enqueue_tail(struct dplane_ctx_q *q, |
220 | const struct zebra_dplane_ctx *ctx); | |
7cdb1a84 | 221 | |
c831033f MS |
222 | /* Append a list of context blocks to another list - again, just keeping |
223 | * the context struct opaque. | |
224 | */ | |
225 | void dplane_ctx_list_append(struct dplane_ctx_q *to_list, | |
226 | struct dplane_ctx_q *from_list); | |
227 | ||
7cdb1a84 | 228 | /* Dequeue a context block from the head of caller's tailq */ |
68b375e0 | 229 | struct zebra_dplane_ctx *dplane_ctx_dequeue(struct dplane_ctx_q *q); |
7cdb1a84 MS |
230 | |
231 | /* | |
232 | * Accessors for information from the context object | |
233 | */ | |
25779064 MS |
234 | enum zebra_dplane_result dplane_ctx_get_status( |
235 | const struct zebra_dplane_ctx *ctx); | |
c831033f MS |
236 | void dplane_ctx_set_status(struct zebra_dplane_ctx *ctx, |
237 | enum zebra_dplane_result status); | |
f183e380 | 238 | const char *dplane_res2str(enum zebra_dplane_result res); |
7cdb1a84 | 239 | |
25779064 | 240 | enum dplane_op_e dplane_ctx_get_op(const struct zebra_dplane_ctx *ctx); |
593e4eb1 | 241 | void dplane_ctx_set_op(struct zebra_dplane_ctx *ctx, enum dplane_op_e op); |
5709131c | 242 | const char *dplane_op2str(enum dplane_op_e op); |
7cdb1a84 | 243 | |
25779064 | 244 | const struct prefix *dplane_ctx_get_dest(const struct zebra_dplane_ctx *ctx); |
593e4eb1 MS |
245 | void dplane_ctx_set_dest(struct zebra_dplane_ctx *ctx, |
246 | const struct prefix *dest); | |
7c7ef4a8 | 247 | const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx *ctx); |
fd563cc7 | 248 | void dplane_ctx_set_ifname(struct zebra_dplane_ctx *ctx, const char *ifname); |
7c7ef4a8 | 249 | ifindex_t dplane_ctx_get_ifindex(const struct zebra_dplane_ctx *ctx); |
7cdb1a84 | 250 | |
c831033f MS |
251 | /* Retrieve last/current provider id */ |
252 | uint32_t dplane_ctx_get_provider(const struct zebra_dplane_ctx *ctx); | |
253 | ||
254 | /* Providers running before the kernel can control whether a kernel | |
255 | * update should be done. | |
256 | */ | |
257 | void dplane_ctx_set_skip_kernel(struct zebra_dplane_ctx *ctx); | |
258 | bool dplane_ctx_is_skip_kernel(const struct zebra_dplane_ctx *ctx); | |
259 | ||
5709131c MS |
260 | /* Source prefix is a little special - use convention to return NULL |
261 | * to mean "no src prefix" | |
7cdb1a84 | 262 | */ |
25779064 | 263 | const struct prefix *dplane_ctx_get_src(const struct zebra_dplane_ctx *ctx); |
593e4eb1 | 264 | void dplane_ctx_set_src(struct zebra_dplane_ctx *ctx, const struct prefix *src); |
25779064 MS |
265 | |
266 | bool dplane_ctx_is_update(const struct zebra_dplane_ctx *ctx); | |
267 | uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx *ctx); | |
268 | uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx *ctx); | |
593e4eb1 | 269 | void dplane_ctx_set_vrf(struct zebra_dplane_ctx *ctx, vrf_id_t vrf); |
25779064 | 270 | vrf_id_t dplane_ctx_get_vrf(const struct zebra_dplane_ctx *ctx); |
0f461727 | 271 | |
0024a559 | 272 | bool dplane_ctx_is_from_notif(const struct zebra_dplane_ctx *ctx); |
9651af61 MS |
273 | void dplane_ctx_set_notif_provider(struct zebra_dplane_ctx *ctx, |
274 | uint32_t id); | |
0024a559 MS |
275 | uint32_t dplane_ctx_get_notif_provider(const struct zebra_dplane_ctx *ctx); |
276 | ||
0f461727 | 277 | /* Accessors for route update information */ |
593e4eb1 | 278 | void dplane_ctx_set_type(struct zebra_dplane_ctx *ctx, int type); |
25779064 MS |
279 | int dplane_ctx_get_type(const struct zebra_dplane_ctx *ctx); |
280 | int dplane_ctx_get_old_type(const struct zebra_dplane_ctx *ctx); | |
593e4eb1 | 281 | void dplane_ctx_set_afi(struct zebra_dplane_ctx *ctx, afi_t afi); |
25779064 | 282 | afi_t dplane_ctx_get_afi(const struct zebra_dplane_ctx *ctx); |
593e4eb1 | 283 | void dplane_ctx_set_safi(struct zebra_dplane_ctx *ctx, safi_t safi); |
25779064 | 284 | safi_t dplane_ctx_get_safi(const struct zebra_dplane_ctx *ctx); |
593e4eb1 | 285 | void dplane_ctx_set_table(struct zebra_dplane_ctx *ctx, uint32_t table); |
25779064 MS |
286 | uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx *ctx); |
287 | route_tag_t dplane_ctx_get_tag(const struct zebra_dplane_ctx *ctx); | |
6a91ae98 | 288 | void dplane_ctx_set_tag(struct zebra_dplane_ctx *ctx, route_tag_t tag); |
25779064 MS |
289 | route_tag_t dplane_ctx_get_old_tag(const struct zebra_dplane_ctx *ctx); |
290 | uint16_t dplane_ctx_get_instance(const struct zebra_dplane_ctx *ctx); | |
6a91ae98 | 291 | void dplane_ctx_set_instance(struct zebra_dplane_ctx *ctx, uint16_t instance); |
25779064 MS |
292 | uint16_t dplane_ctx_get_old_instance(const struct zebra_dplane_ctx *ctx); |
293 | uint32_t dplane_ctx_get_metric(const struct zebra_dplane_ctx *ctx); | |
294 | uint32_t dplane_ctx_get_old_metric(const struct zebra_dplane_ctx *ctx); | |
295 | uint32_t dplane_ctx_get_mtu(const struct zebra_dplane_ctx *ctx); | |
296 | uint32_t dplane_ctx_get_nh_mtu(const struct zebra_dplane_ctx *ctx); | |
297 | uint8_t dplane_ctx_get_distance(const struct zebra_dplane_ctx *ctx); | |
6a91ae98 | 298 | void dplane_ctx_set_distance(struct zebra_dplane_ctx *ctx, uint8_t distance); |
25779064 MS |
299 | uint8_t dplane_ctx_get_old_distance(const struct zebra_dplane_ctx *ctx); |
300 | ||
593e4eb1 | 301 | void dplane_ctx_set_nexthops(struct zebra_dplane_ctx *ctx, struct nexthop *nh); |
928f94a9 MS |
302 | void dplane_ctx_set_backup_nhg(struct zebra_dplane_ctx *ctx, |
303 | const struct nexthop_group *nhg); | |
1d48702e MS |
304 | |
305 | uint32_t dplane_ctx_get_nhg_id(const struct zebra_dplane_ctx *ctx); | |
25779064 MS |
306 | const struct nexthop_group *dplane_ctx_get_ng( |
307 | const struct zebra_dplane_ctx *ctx); | |
308 | const struct nexthop_group *dplane_ctx_get_old_ng( | |
309 | const struct zebra_dplane_ctx *ctx); | |
310 | ||
1d48702e MS |
311 | /* Backup nexthop information (list of nexthops) if present. */ |
312 | const struct nexthop_group * | |
313 | dplane_ctx_get_backup_ng(const struct zebra_dplane_ctx *ctx); | |
314 | const struct nexthop_group * | |
315 | dplane_ctx_get_old_backup_ng(const struct zebra_dplane_ctx *ctx); | |
316 | ||
f820d025 | 317 | /* Accessors for nexthop information */ |
0c8215cb SW |
318 | uint32_t dplane_ctx_get_nhe_id(const struct zebra_dplane_ctx *ctx); |
319 | afi_t dplane_ctx_get_nhe_afi(const struct zebra_dplane_ctx *ctx); | |
320 | vrf_id_t dplane_ctx_get_nhe_vrf_id(const struct zebra_dplane_ctx *ctx); | |
38e40db1 | 321 | int dplane_ctx_get_nhe_type(const struct zebra_dplane_ctx *ctx); |
0c8215cb SW |
322 | const struct nexthop_group * |
323 | dplane_ctx_get_nhe_ng(const struct zebra_dplane_ctx *ctx); | |
e22e8001 SW |
324 | const struct nh_grp * |
325 | dplane_ctx_get_nhe_nh_grp(const struct zebra_dplane_ctx *ctx); | |
326 | uint8_t dplane_ctx_get_nhe_nh_grp_count(const struct zebra_dplane_ctx *ctx); | |
f820d025 | 327 | |
0f461727 | 328 | /* Accessors for LSP information */ |
65f264cf MS |
329 | |
330 | /* Init the internal LSP data struct - necessary before adding to it. | |
331 | * If 'lsp' is non-NULL, info will be copied from it to the internal | |
332 | * context data area. | |
333 | */ | |
334 | int dplane_ctx_lsp_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op, | |
335 | zebra_lsp_t *lsp); | |
336 | ||
0f461727 | 337 | mpls_label_t dplane_ctx_get_in_label(const struct zebra_dplane_ctx *ctx); |
3ab54059 MS |
338 | void dplane_ctx_set_in_label(struct zebra_dplane_ctx *ctx, |
339 | mpls_label_t label); | |
0f461727 | 340 | uint8_t dplane_ctx_get_addr_family(const struct zebra_dplane_ctx *ctx); |
3ab54059 MS |
341 | void dplane_ctx_set_addr_family(struct zebra_dplane_ctx *ctx, |
342 | uint8_t family); | |
0f461727 | 343 | uint32_t dplane_ctx_get_lsp_flags(const struct zebra_dplane_ctx *ctx); |
3ab54059 MS |
344 | void dplane_ctx_set_lsp_flags(struct zebra_dplane_ctx *ctx, |
345 | uint32_t flags); | |
ee70f629 MS |
346 | const struct nhlfe_list_head *dplane_ctx_get_nhlfe_list( |
347 | const struct zebra_dplane_ctx *ctx); | |
cd4bb96f MS |
348 | const struct nhlfe_list_head *dplane_ctx_get_backup_nhlfe_list( |
349 | const struct zebra_dplane_ctx *ctx); | |
350 | ||
3ab54059 MS |
351 | zebra_nhlfe_t *dplane_ctx_add_nhlfe(struct zebra_dplane_ctx *ctx, |
352 | enum lsp_types_t lsp_type, | |
353 | enum nexthop_types_t nh_type, | |
963a9803 | 354 | const union g_addr *gate, |
3ab54059 | 355 | ifindex_t ifindex, |
5065db0a | 356 | uint8_t num_labels, |
ee70f629 | 357 | mpls_label_t *out_labels); |
3ab54059 | 358 | |
cd4bb96f MS |
359 | zebra_nhlfe_t *dplane_ctx_add_backup_nhlfe(struct zebra_dplane_ctx *ctx, |
360 | enum lsp_types_t lsp_type, | |
361 | enum nexthop_types_t nh_type, | |
963a9803 | 362 | const union g_addr *gate, |
cd4bb96f MS |
363 | ifindex_t ifindex, |
364 | uint8_t num_labels, | |
365 | mpls_label_t *out_labels); | |
366 | ||
81793ac1 MS |
367 | const zebra_nhlfe_t *dplane_ctx_get_best_nhlfe( |
368 | const struct zebra_dplane_ctx *ctx); | |
3ab54059 MS |
369 | const zebra_nhlfe_t *dplane_ctx_set_best_nhlfe(struct zebra_dplane_ctx *ctx, |
370 | zebra_nhlfe_t *nhlfe); | |
0f461727 MS |
371 | uint32_t dplane_ctx_get_lsp_num_ecmp(const struct zebra_dplane_ctx *ctx); |
372 | ||
d613b8e1 | 373 | /* Accessors for pseudowire information */ |
d613b8e1 MS |
374 | mpls_label_t dplane_ctx_get_pw_local_label(const struct zebra_dplane_ctx *ctx); |
375 | mpls_label_t dplane_ctx_get_pw_remote_label(const struct zebra_dplane_ctx *ctx); | |
376 | int dplane_ctx_get_pw_type(const struct zebra_dplane_ctx *ctx); | |
377 | int dplane_ctx_get_pw_af(const struct zebra_dplane_ctx *ctx); | |
378 | uint32_t dplane_ctx_get_pw_flags(const struct zebra_dplane_ctx *ctx); | |
379 | int dplane_ctx_get_pw_status(const struct zebra_dplane_ctx *ctx); | |
fd563cc7 | 380 | void dplane_ctx_set_pw_status(struct zebra_dplane_ctx *ctx, int status); |
16d69787 | 381 | const union g_addr *dplane_ctx_get_pw_dest( |
d613b8e1 MS |
382 | const struct zebra_dplane_ctx *ctx); |
383 | const union pw_protocol_fields *dplane_ctx_get_pw_proto( | |
384 | const struct zebra_dplane_ctx *ctx); | |
09cd307c MS |
385 | const struct nexthop_group *dplane_ctx_get_pw_nhg( |
386 | const struct zebra_dplane_ctx *ctx); | |
d613b8e1 | 387 | |
a4a4802a | 388 | /* Accessors for interface information */ |
a4a4802a MS |
389 | uint32_t dplane_ctx_get_intf_metric(const struct zebra_dplane_ctx *ctx); |
390 | /* Is interface addr p2p? */ | |
391 | bool dplane_ctx_intf_is_connected(const struct zebra_dplane_ctx *ctx); | |
392 | bool dplane_ctx_intf_is_secondary(const struct zebra_dplane_ctx *ctx); | |
990b0d09 | 393 | bool dplane_ctx_intf_is_broadcast(const struct zebra_dplane_ctx *ctx); |
a4a4802a MS |
394 | const struct prefix *dplane_ctx_get_intf_addr( |
395 | const struct zebra_dplane_ctx *ctx); | |
396 | bool dplane_ctx_intf_has_dest(const struct zebra_dplane_ctx *ctx); | |
397 | const struct prefix *dplane_ctx_get_intf_dest( | |
398 | const struct zebra_dplane_ctx *ctx); | |
399 | bool dplane_ctx_intf_has_label(const struct zebra_dplane_ctx *ctx); | |
400 | const char *dplane_ctx_get_intf_label(const struct zebra_dplane_ctx *ctx); | |
401 | ||
7597ac7b MS |
402 | /* Accessors for MAC information */ |
403 | vlanid_t dplane_ctx_mac_get_vlan(const struct zebra_dplane_ctx *ctx); | |
404 | bool dplane_ctx_mac_is_sticky(const struct zebra_dplane_ctx *ctx); | |
f188e68e | 405 | uint32_t dplane_ctx_mac_get_update_flags(const struct zebra_dplane_ctx *ctx); |
506efd37 | 406 | uint32_t dplane_ctx_mac_get_nhg_id(const struct zebra_dplane_ctx *ctx); |
7597ac7b MS |
407 | const struct ethaddr *dplane_ctx_mac_get_addr( |
408 | const struct zebra_dplane_ctx *ctx); | |
409 | const struct in_addr *dplane_ctx_mac_get_vtep_ip( | |
410 | const struct zebra_dplane_ctx *ctx); | |
478566d6 | 411 | ifindex_t dplane_ctx_mac_get_br_ifindex(const struct zebra_dplane_ctx *ctx); |
7597ac7b | 412 | |
931fa60c MS |
413 | /* Accessors for neighbor information */ |
414 | const struct ipaddr *dplane_ctx_neigh_get_ipaddr( | |
415 | const struct zebra_dplane_ctx *ctx); | |
416 | const struct ethaddr *dplane_ctx_neigh_get_mac( | |
417 | const struct zebra_dplane_ctx *ctx); | |
418 | uint32_t dplane_ctx_neigh_get_flags(const struct zebra_dplane_ctx *ctx); | |
419 | uint16_t dplane_ctx_neigh_get_state(const struct zebra_dplane_ctx *ctx); | |
f188e68e | 420 | uint32_t dplane_ctx_neigh_get_update_flags(const struct zebra_dplane_ctx *ctx); |
931fa60c | 421 | |
60d8d43b JU |
422 | /* Accessors for policy based routing rule information */ |
423 | int dplane_ctx_rule_get_sock(const struct zebra_dplane_ctx *ctx); | |
424 | int dplane_ctx_rule_get_unique(const struct zebra_dplane_ctx *ctx); | |
425 | int dplane_ctx_rule_get_seq(const struct zebra_dplane_ctx *ctx); | |
426 | uint32_t dplane_ctx_rule_get_priority(const struct zebra_dplane_ctx *ctx); | |
427 | uint32_t dplane_ctx_rule_get_old_priority(const struct zebra_dplane_ctx *ctx); | |
428 | uint32_t dplane_ctx_rule_get_table(const struct zebra_dplane_ctx *ctx); | |
429 | uint32_t dplane_ctx_rule_get_old_table(const struct zebra_dplane_ctx *ctx); | |
430 | uint32_t dplane_ctx_rule_get_filter_bm(const struct zebra_dplane_ctx *ctx); | |
431 | uint32_t dplane_ctx_rule_get_old_filter_bm(const struct zebra_dplane_ctx *ctx); | |
432 | uint32_t dplane_ctx_rule_get_fwmark(const struct zebra_dplane_ctx *ctx); | |
433 | uint32_t dplane_ctx_rule_get_old_fwmark(const struct zebra_dplane_ctx *ctx); | |
01f23aff WC |
434 | uint8_t dplane_ctx_rule_get_dsfield(const struct zebra_dplane_ctx *ctx); |
435 | uint8_t dplane_ctx_rule_get_old_dsfield(const struct zebra_dplane_ctx *ctx); | |
60d8d43b JU |
436 | const struct prefix * |
437 | dplane_ctx_rule_get_src_ip(const struct zebra_dplane_ctx *ctx); | |
438 | const struct prefix * | |
439 | dplane_ctx_rule_get_old_src_ip(const struct zebra_dplane_ctx *ctx); | |
440 | const struct prefix * | |
441 | dplane_ctx_rule_get_dst_ip(const struct zebra_dplane_ctx *ctx); | |
442 | const struct prefix * | |
443 | dplane_ctx_rule_get_old_dst_ip(const struct zebra_dplane_ctx *ctx); | |
444 | ||
0f461727 | 445 | /* Namespace info - esp. for netlink communication */ |
25779064 MS |
446 | const struct zebra_dplane_info *dplane_ctx_get_ns( |
447 | const struct zebra_dplane_ctx *ctx); | |
7cdb1a84 | 448 | |
4dfd7a02 MS |
449 | /* Indicates zebra shutdown/exit is in progress. Some operations may be |
450 | * simplified or skipped during shutdown processing. | |
451 | */ | |
452 | bool dplane_is_in_shutdown(void); | |
453 | ||
7cdb1a84 MS |
454 | /* |
455 | * Enqueue route change operations for the dataplane. | |
456 | */ | |
655d681a MS |
457 | enum zebra_dplane_result dplane_route_add(struct route_node *rn, |
458 | struct route_entry *re); | |
7cdb1a84 | 459 | |
655d681a MS |
460 | enum zebra_dplane_result dplane_route_update(struct route_node *rn, |
461 | struct route_entry *re, | |
462 | struct route_entry *old_re); | |
7cdb1a84 | 463 | |
655d681a MS |
464 | enum zebra_dplane_result dplane_route_delete(struct route_node *rn, |
465 | struct route_entry *re); | |
7cdb1a84 | 466 | |
cf363e1b MS |
467 | /* Notify the dplane when system/connected routes change */ |
468 | enum zebra_dplane_result dplane_sys_route_add(struct route_node *rn, | |
469 | struct route_entry *re); | |
470 | enum zebra_dplane_result dplane_sys_route_del(struct route_node *rn, | |
471 | struct route_entry *re); | |
472 | ||
188a00e0 MS |
473 | /* Update from an async notification, to bring other fibs up-to-date */ |
474 | enum zebra_dplane_result dplane_route_notif_update( | |
475 | struct route_node *rn, | |
476 | struct route_entry *re, | |
477 | enum dplane_op_e op, | |
478 | struct zebra_dplane_ctx *ctx); | |
479 | ||
f820d025 SW |
480 | |
481 | /* Forward ref of nhg_hash_entry */ | |
482 | struct nhg_hash_entry; | |
483 | /* | |
484 | * Enqueue a nexthop change operation for the dataplane. | |
485 | */ | |
486 | enum zebra_dplane_result dplane_nexthop_add(struct nhg_hash_entry *nhe); | |
487 | enum zebra_dplane_result dplane_nexthop_update(struct nhg_hash_entry *nhe); | |
488 | enum zebra_dplane_result dplane_nexthop_delete(struct nhg_hash_entry *nhe); | |
489 | ||
16c628de MS |
490 | /* |
491 | * Enqueue LSP change operations for the dataplane. | |
492 | */ | |
493 | enum zebra_dplane_result dplane_lsp_add(zebra_lsp_t *lsp); | |
494 | enum zebra_dplane_result dplane_lsp_update(zebra_lsp_t *lsp); | |
495 | enum zebra_dplane_result dplane_lsp_delete(zebra_lsp_t *lsp); | |
496 | ||
188a00e0 MS |
497 | /* Update or un-install resulting from an async notification */ |
498 | enum zebra_dplane_result dplane_lsp_notif_update(zebra_lsp_t *lsp, | |
499 | enum dplane_op_e op, | |
500 | struct zebra_dplane_ctx *ctx); | |
501 | ||
97d8d05a MS |
502 | /* |
503 | * Enqueue pseudowire operations for the dataplane. | |
504 | */ | |
505 | enum zebra_dplane_result dplane_pw_install(struct zebra_pw *pw); | |
506 | enum zebra_dplane_result dplane_pw_uninstall(struct zebra_pw *pw); | |
507 | ||
a4a4802a MS |
508 | /* |
509 | * Enqueue interface address changes for the dataplane. | |
510 | */ | |
511 | enum zebra_dplane_result dplane_intf_addr_set(const struct interface *ifp, | |
512 | const struct connected *ifc); | |
513 | enum zebra_dplane_result dplane_intf_addr_unset(const struct interface *ifp, | |
514 | const struct connected *ifc); | |
515 | ||
7597ac7b MS |
516 | /* |
517 | * Enqueue evpn mac operations for the dataplane. | |
518 | */ | |
f188e68e | 519 | enum zebra_dplane_result dplane_rem_mac_add(const struct interface *ifp, |
478566d6 | 520 | const struct interface *bridge_ifp, |
7597ac7b MS |
521 | vlanid_t vid, |
522 | const struct ethaddr *mac, | |
523 | struct in_addr vtep_ip, | |
506efd37 | 524 | bool sticky, |
f188e68e AK |
525 | uint32_t nhg_id, |
526 | bool was_static); | |
7597ac7b | 527 | |
f188e68e AK |
528 | enum zebra_dplane_result dplane_local_mac_add(const struct interface *ifp, |
529 | const struct interface *bridge_ifp, | |
530 | vlanid_t vid, | |
531 | const struct ethaddr *mac, | |
532 | bool sticky, | |
533 | uint32_t set_static, | |
534 | uint32_t set_inactive); | |
535 | ||
536 | enum zebra_dplane_result dplane_rem_mac_del(const struct interface *ifp, | |
478566d6 | 537 | const struct interface *bridge_ifp, |
7597ac7b MS |
538 | vlanid_t vid, |
539 | const struct ethaddr *mac, | |
540 | struct in_addr vtep_ip); | |
a4a4802a | 541 | |
f73a8467 MS |
542 | /* Helper api to init an empty or new context for a MAC update */ |
543 | void dplane_mac_init(struct zebra_dplane_ctx *ctx, | |
544 | const struct interface *ifp, | |
545 | const struct interface *br_ifp, | |
546 | vlanid_t vid, | |
547 | const struct ethaddr *mac, | |
548 | struct in_addr vtep_ip, | |
f188e68e | 549 | bool sticky, |
b169fd6f | 550 | uint32_t nhg_id, uint32_t update_flags); |
f73a8467 | 551 | |
f2412b2d MS |
552 | /* |
553 | * Enqueue evpn neighbor updates for the dataplane. | |
554 | */ | |
f188e68e AK |
555 | enum zebra_dplane_result dplane_rem_neigh_add(const struct interface *ifp, |
556 | const struct ipaddr *ip, | |
557 | const struct ethaddr *mac, | |
558 | uint32_t flags, bool was_static); | |
559 | enum zebra_dplane_result dplane_local_neigh_add(const struct interface *ifp, | |
f2412b2d MS |
560 | const struct ipaddr *ip, |
561 | const struct ethaddr *mac, | |
f188e68e AK |
562 | bool set_router, bool set_static, |
563 | bool set_inactive); | |
f188e68e | 564 | enum zebra_dplane_result dplane_rem_neigh_delete(const struct interface *ifp, |
931fa60c | 565 | const struct ipaddr *ip); |
f2412b2d | 566 | |
0bbd4ff4 MS |
567 | /* |
568 | * Enqueue evpn VTEP updates for the dataplane. | |
569 | */ | |
570 | enum zebra_dplane_result dplane_vtep_add(const struct interface *ifp, | |
571 | const struct in_addr *ip, | |
572 | vni_t vni); | |
573 | enum zebra_dplane_result dplane_vtep_delete(const struct interface *ifp, | |
574 | const struct in_addr *ip, | |
575 | vni_t vni); | |
576 | ||
d68e74b4 JU |
577 | /* |
578 | * Enqueue a neighbour discovery request for the dataplane. | |
579 | */ | |
580 | enum zebra_dplane_result dplane_neigh_discover(const struct interface *ifp, | |
581 | const struct ipaddr *ip); | |
582 | ||
f62e5480 JU |
583 | /* Forward ref of zebra_pbr_rule */ |
584 | struct zebra_pbr_rule; | |
585 | ||
586 | /* | |
587 | * Enqueue policy based routing rule for the dataplane. | |
588 | * It is possible that the user-defined sequence number and the one in the | |
589 | * forwarding plane may not coincide, hence the API requires a separate | |
590 | * rule priority - maps to preference/FRA_PRIORITY on Linux. | |
591 | */ | |
592 | enum zebra_dplane_result dplane_pbr_rule_add(struct zebra_pbr_rule *rule); | |
593 | enum zebra_dplane_result dplane_pbr_rule_delete(struct zebra_pbr_rule *rule); | |
594 | enum zebra_dplane_result | |
595 | dplane_pbr_rule_update(struct zebra_pbr_rule *old_rule, | |
596 | struct zebra_pbr_rule *new_rule); | |
597 | ||
018e77bc RZ |
598 | /* Encode route information into data plane context. */ |
599 | int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op, | |
600 | struct route_node *rn, struct route_entry *re); | |
0bbd4ff4 | 601 | |
981ca597 | 602 | /* Encode next hop information into data plane context. */ |
a2072e71 | 603 | int dplane_ctx_nexthop_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op, |
981ca597 RZ |
604 | struct nhg_hash_entry *nhe); |
605 | ||
91f16812 MS |
606 | /* Retrieve the limit on the number of pending, unprocessed updates. */ |
607 | uint32_t dplane_get_in_queue_limit(void); | |
608 | ||
609 | /* Configure limit on the number of pending, queued updates. If 'unset', reset | |
610 | * to default value. | |
611 | */ | |
612 | void dplane_set_in_queue_limit(uint32_t limit, bool set); | |
613 | ||
614 | /* Retrieve the current queue depth of incoming, unprocessed updates */ | |
615 | uint32_t dplane_get_in_queue_len(void); | |
616 | ||
1d11b21f MS |
617 | /* |
618 | * Vty/cli apis | |
619 | */ | |
620 | int dplane_show_helper(struct vty *vty, bool detailed); | |
621 | int dplane_show_provs_helper(struct vty *vty, bool detailed); | |
f26730e1 | 622 | int dplane_config_write_helper(struct vty *vty); |
1d11b21f | 623 | |
1d11b21f | 624 | /* |
c831033f | 625 | * Dataplane providers: modules that process or consume dataplane events. |
1d11b21f MS |
626 | */ |
627 | ||
c831033f MS |
628 | struct zebra_dplane_provider; |
629 | ||
fe2c53d4 | 630 | /* Support string name for a dataplane provider */ |
7cdb1a84 MS |
631 | #define DPLANE_PROVIDER_NAMELEN 64 |
632 | ||
633 | /* Priority or ordering values for providers. The idea is that there may be | |
634 | * some pre-processing, followed by an external or remote dataplane, | |
635 | * followed by the kernel, followed by some post-processing step (such as | |
636 | * the fpm output stream.) | |
637 | */ | |
c831033f | 638 | enum dplane_provider_prio { |
7cdb1a84 MS |
639 | DPLANE_PRIO_NONE = 0, |
640 | DPLANE_PRIO_PREPROCESS, | |
641 | DPLANE_PRIO_PRE_KERNEL, | |
642 | DPLANE_PRIO_KERNEL, | |
643 | DPLANE_PRIO_POSTPROCESS, | |
b8e0423d | 644 | DPLANE_PRIO_LAST |
5709131c | 645 | }; |
7cdb1a84 | 646 | |
c831033f MS |
647 | /* Flags values used during provider registration. */ |
648 | #define DPLANE_PROV_FLAGS_DEFAULT 0x0 | |
649 | ||
650 | /* Provider will be spawning its own worker thread */ | |
651 | #define DPLANE_PROV_FLAG_THREADED 0x1 | |
7cdb1a84 | 652 | |
c831033f | 653 | /* Provider registration: ordering or priority value, callbacks, and optional |
1ff8a248 MS |
654 | * opaque data value. If 'prov_p', return the newly-allocated provider object |
655 | * on success. | |
c831033f | 656 | */ |
4c206c8f MS |
657 | |
658 | /* Providers offer an entry-point for incoming work, called in the context of | |
659 | * the dataplane pthread. The dataplane pthread enqueues any new work to the | |
660 | * provider's 'inbound' queue, then calls the callback. The dataplane | |
661 | * then checks the provider's outbound queue for completed work. | |
662 | */ | |
663 | ||
1dd4ea8a MS |
664 | /* |
665 | * Providers can offer a 'start' callback; if present, the dataplane will | |
666 | * call it when it is starting - when its pthread and event-scheduling | |
667 | * thread_master are available. | |
668 | */ | |
669 | ||
670 | /* Providers can offer an entry-point for shutdown and cleanup. This is called | |
4c206c8f MS |
671 | * with 'early' during shutdown, to indicate that the dataplane subsystem |
672 | * is allowing work to move through the providers and finish. | |
673 | * When called without 'early', the provider should release | |
674 | * all resources (if it has any allocated). | |
675 | */ | |
7cdb1a84 | 676 | int dplane_provider_register(const char *name, |
c831033f MS |
677 | enum dplane_provider_prio prio, |
678 | int flags, | |
1dd4ea8a | 679 | int (*start_fp)(struct zebra_dplane_provider *), |
4c206c8f MS |
680 | int (*fp)(struct zebra_dplane_provider *), |
681 | int (*fini_fp)(struct zebra_dplane_provider *, | |
682 | bool early), | |
1ff8a248 MS |
683 | void *data, |
684 | struct zebra_dplane_provider **prov_p); | |
7cdb1a84 | 685 | |
c831033f MS |
686 | /* Accessors for provider attributes */ |
687 | const char *dplane_provider_get_name(const struct zebra_dplane_provider *prov); | |
688 | uint32_t dplane_provider_get_id(const struct zebra_dplane_provider *prov); | |
689 | void *dplane_provider_get_data(const struct zebra_dplane_provider *prov); | |
690 | bool dplane_provider_is_threaded(const struct zebra_dplane_provider *prov); | |
691 | ||
ad6aad4d MS |
692 | /* Lock/unlock a provider's mutex - iff the provider was registered with |
693 | * the THREADED flag. | |
694 | */ | |
695 | void dplane_provider_lock(struct zebra_dplane_provider *prov); | |
696 | void dplane_provider_unlock(struct zebra_dplane_provider *prov); | |
697 | ||
698 | /* Obtain thread_master for dataplane thread */ | |
699 | struct thread_master *dplane_get_thread_master(void); | |
700 | ||
701 | /* Providers should (generally) limit number of updates per work cycle */ | |
c831033f MS |
702 | int dplane_provider_get_work_limit(const struct zebra_dplane_provider *prov); |
703 | ||
704 | /* Provider api to signal that work/events are available | |
705 | * for the dataplane pthread. | |
7cdb1a84 | 706 | */ |
c831033f MS |
707 | int dplane_provider_work_ready(void); |
708 | ||
709 | /* Dequeue, maintain associated counter and locking */ | |
710 | struct zebra_dplane_ctx *dplane_provider_dequeue_in_ctx( | |
711 | struct zebra_dplane_provider *prov); | |
712 | ||
713 | /* Dequeue work to a list, maintain counter and locking, return count */ | |
714 | int dplane_provider_dequeue_in_list(struct zebra_dplane_provider *prov, | |
715 | struct dplane_ctx_q *listp); | |
716 | ||
593e4eb1 | 717 | /* Enqueue completed work, maintain associated counter and locking */ |
c831033f MS |
718 | void dplane_provider_enqueue_out_ctx(struct zebra_dplane_provider *prov, |
719 | struct zebra_dplane_ctx *ctx); | |
7cdb1a84 | 720 | |
593e4eb1 MS |
721 | /* Enqueue a context directly to zebra main. */ |
722 | void dplane_provider_enqueue_to_zebra(struct zebra_dplane_ctx *ctx); | |
723 | ||
7cdb1a84 | 724 | /* |
1d11b21f | 725 | * Initialize the dataplane modules at zebra startup. This is currently called |
4c206c8f MS |
726 | * by the rib module. Zebra registers a results callback with the dataplane. |
727 | * The callback is called in the dataplane pthread context, | |
728 | * so the expectation is that the contexts are queued for the zebra | |
729 | * main pthread. | |
7cdb1a84 | 730 | */ |
4c206c8f | 731 | void zebra_dplane_init(int (*) (struct dplane_ctx_q *)); |
7cdb1a84 | 732 | |
e5a60d82 MS |
733 | /* |
734 | * Start the dataplane pthread. This step needs to be run later than the | |
735 | * 'init' step, in case zebra has fork-ed. | |
736 | */ | |
737 | void zebra_dplane_start(void); | |
738 | ||
4dfd7a02 MS |
739 | /* Finalize/cleanup apis, one called early as shutdown is starting, |
740 | * one called late at the end of zebra shutdown, and then one called | |
c831033f MS |
741 | * from the zebra main pthread to stop the dplane pthread and |
742 | * free all resources. | |
4dfd7a02 | 743 | * |
1d11b21f MS |
744 | * Zebra expects to try to clean up all vrfs and all routes during |
745 | * shutdown, so the dplane must be available until very late. | |
746 | */ | |
4dfd7a02 | 747 | void zebra_dplane_pre_finish(void); |
1d11b21f | 748 | void zebra_dplane_finish(void); |
4dfd7a02 | 749 | void zebra_dplane_shutdown(void); |
1d11b21f | 750 | |
51e94aa7 EDP |
751 | #ifdef __cplusplus |
752 | } | |
753 | #endif | |
754 | ||
ea1c14f6 | 755 | #endif /* _ZEBRA_DPLANE_H */ |