]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_dplane.h
zebra: start dataplane layer work
[mirror_frr.git] / zebra / zebra_dplane.h
1 /*
2 * Zebra dataplane layer api interfaces.
3 * Copyright (c) 2018 Volta Networks, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #ifndef _ZEBRA_DPLANE_H
21 #define _ZEBRA_DPLANE_H 1
22
23 #include "lib/zebra.h"
24 #include "lib/prefix.h"
25 #include "lib/nexthop.h"
26 #include "lib/nexthop_group.h"
27 #include "lib/openbsd-queue.h"
28 #include "zebra/zebra_ns.h"
29 #include "zebra/rib.h"
30 #include "zebra/zserv.h"
31
32
33 /* Key netlink info from zebra ns */
34 struct zebra_dplane_info {
35 ns_id_t ns_id;
36
37 #if defined(HAVE_NETLINK)
38 struct nlsock nls;
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) {
53 zns_info->nls = zns->netlink_cmd;
54 } else {
55 zns_info->nls = zns->netlink;
56 }
57 #endif /* NETLINK */
58 }
59
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
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 */
97 typedef enum {
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
105 } dplane_op_e;
106
107 /*
108 * Enqueue a route removal for the dataplane.
109 */
110
111 /*
112 * Opaque context block used to exchange info between the main zebra
113 * context and the dataplane module(s). If these are two independent pthreads,
114 * they cannot share existing global data structures safely.
115 */
116 typedef struct zebra_dplane_ctx_s * dplane_ctx_h;
117
118 /* Define a tailq list type for context blocks. The list is exposed/public,
119 * but the internal linkage in the context struct is private, so there
120 * are accessor apis that support enqueue and dequeue.
121 */
122 TAILQ_HEAD(dplane_ctx_q_s, zebra_dplane_ctx_s);
123
124 /*
125 * Allocate an opaque context block, currently for a route update.
126 */
127 dplane_ctx_h dplane_ctx_alloc(void);
128
129 /* Return a dataplane results context block after use; the caller's pointer will
130 * be cleared.
131 */
132 void dplane_ctx_fini(dplane_ctx_h *pctx);
133
134 /* Enqueue a context block to caller's tailq. This just exists so that the
135 * context struct can remain opaque.
136 */
137 void dplane_ctx_enqueue_tail(struct dplane_ctx_q_s *q, dplane_ctx_h ctx);
138
139 /* Dequeue a context block from the head of caller's tailq */
140 void dplane_ctx_dequeue(struct dplane_ctx_q_s *q, dplane_ctx_h *ctxp);
141
142 /*
143 * Accessors for information from the context object
144 */
145 enum zebra_dplane_result dplane_ctx_get_status(const dplane_ctx_h ctx);
146
147 dplane_op_e dplane_ctx_get_op(const dplane_ctx_h ctx);
148 const char *dplane_op2str(dplane_op_e op);
149
150 const struct prefix *dplane_ctx_get_dest(const dplane_ctx_h ctx);
151
152 /* Source prefix is a little special - use convention like prefix-len of zero
153 * and all-zeroes address means "no src prefix"? or ... return NULL in that case?
154 */
155 const struct prefix *dplane_ctx_get_src(const dplane_ctx_h ctx);
156
157 bool dplane_ctx_is_update(const dplane_ctx_h ctx);
158 uint32_t dplane_ctx_get_seq(const dplane_ctx_h ctx);
159 uint32_t dplane_ctx_get_old_seq(const dplane_ctx_h ctx);
160 vrf_id_t dplane_ctx_get_vrf(const dplane_ctx_h ctx);
161 int dplane_ctx_get_type(const dplane_ctx_h ctx);
162 int dplane_ctx_get_old_type(const dplane_ctx_h ctx);
163 afi_t dplane_ctx_get_afi(const dplane_ctx_h ctx);
164 safi_t dplane_ctx_get_safi(const dplane_ctx_h ctx);
165 uint32_t dplane_ctx_get_table(const dplane_ctx_h ctx);
166 route_tag_t dplane_ctx_get_tag(const dplane_ctx_h ctx);
167 route_tag_t dplane_ctx_get_old_tag(const dplane_ctx_h ctx);
168 uint16_t dplane_ctx_get_instance(const dplane_ctx_h ctx);
169 uint16_t dplane_ctx_get_old_instance(const dplane_ctx_h ctx);
170 uint32_t dplane_ctx_get_metric(const dplane_ctx_h ctx);
171 uint32_t dplane_ctx_get_mtu(const dplane_ctx_h ctx);
172 uint32_t dplane_ctx_get_nh_mtu(const dplane_ctx_h ctx);
173 uint8_t dplane_ctx_get_distance(const dplane_ctx_h ctx);
174 uint8_t dplane_ctx_get_old_distance(const dplane_ctx_h ctx);
175
176 const struct nexthop_group *dplane_ctx_get_ng(const dplane_ctx_h ctx);
177 const struct zebra_dplane_info *dplane_ctx_get_ns(const dplane_ctx_h ctx);
178
179 /*
180 * Enqueue route change operations for the dataplane.
181 */
182 int dplane_route_add(struct route_node *rn,
183 struct route_entry *re);
184
185 int dplane_route_update(struct route_node *rn,
186 struct route_entry *re,
187 struct route_entry *old_re);
188
189 int dplane_route_delete(struct route_node *rn,
190 struct route_entry *re);
191
192 /* Opaque handle to a dataplane provider plugin */
193 typedef struct zebra_dplane_provider_s *dplane_provider_h;
194
195 #define DPLANE_PROVIDER_NAMELEN 64
196
197 /* Priority or ordering values for providers. The idea is that there may be
198 * some pre-processing, followed by an external or remote dataplane,
199 * followed by the kernel, followed by some post-processing step (such as
200 * the fpm output stream.)
201 */
202 typedef enum {
203 DPLANE_PRIO_NONE = 0,
204 DPLANE_PRIO_PREPROCESS,
205 DPLANE_PRIO_PRE_KERNEL,
206 DPLANE_PRIO_KERNEL,
207 DPLANE_PRIO_POSTPROCESS,
208 } dplane_provider_prio_e;
209
210 /* Provider's entry-point to process a context block */
211 typedef int (*dplane_provider_process_fp)(dplane_ctx_h ctx);
212
213 /* Provider registration */
214 int dplane_provider_register(const char *name,
215 dplane_provider_prio_e prio,
216 dplane_provider_process_fp fp);
217
218 /*
219 * Results are returned to zebra core via a callback
220 */
221 typedef int (*dplane_results_fp)(const dplane_ctx_h ctx);
222
223 /*
224 * Zebra registers a results callback with the dataplane. The callback is
225 * called in the dataplane thread context, so the expectation is that the
226 * context is queued (or that processing is very limited).
227 */
228 int dplane_results_register(dplane_results_fp fp);
229
230 /*
231 * Initialize the dataplane modules at zebra startup.
232 */
233 void zebra_dplane_init(void);
234
235 #endif /* _ZEBRA_DPLANE_H */