]>
Commit | Line | Data |
---|---|---|
96fba48f | 1 | /* |
4ea96698 | 2 | * Copyright (c) 2009-2014, 2018 Nicira, Inc. |
96fba48f BP |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at: | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | ||
17 | #ifndef DPIF_PROVIDER_H | |
18 | #define DPIF_PROVIDER_H 1 | |
19 | ||
20 | /* Provider interface to dpifs, which provide an interface to an Open vSwitch | |
bc34d060 BP |
21 | * datapath. A datapath is a collection of physical or virtual ports that are |
22 | * exposed over OpenFlow as a single switch. Datapaths and the collections of | |
23 | * ports that they contain may be fixed or dynamic. */ | |
96fba48f | 24 | |
43253595 | 25 | #include "openflow/openflow.h" |
96fba48f | 26 | #include "dpif.h" |
43253595 | 27 | #include "util.h" |
96fba48f | 28 | |
1acb6baa BP |
29 | #ifdef __cplusplus |
30 | extern "C" { | |
31 | #endif | |
32 | ||
96fba48f BP |
33 | /* Open vSwitch datapath interface. |
34 | * | |
35 | * This structure should be treated as opaque by dpif implementations. */ | |
36 | struct dpif { | |
1acb6baa | 37 | const struct dpif_class *dpif_class; |
1a6f1e2a JG |
38 | char *base_name; |
39 | char *full_name; | |
96fba48f BP |
40 | uint8_t netflow_engine_type; |
41 | uint8_t netflow_engine_id; | |
6bea8526 | 42 | long long int current_ms; |
96fba48f BP |
43 | }; |
44 | ||
4ea96698 DB |
45 | struct dpif_ipf_status; |
46 | struct ipf_dump_ctx; | |
47 | ||
96fba48f BP |
48 | void dpif_init(struct dpif *, const struct dpif_class *, const char *name, |
49 | uint8_t netflow_engine_type, uint8_t netflow_engine_id); | |
999401aa JG |
50 | void dpif_uninit(struct dpif *dpif, bool close); |
51 | ||
96fba48f | 52 | static inline void dpif_assert_class(const struct dpif *dpif, |
1acb6baa | 53 | const struct dpif_class *dpif_class) |
96fba48f | 54 | { |
cb22974d | 55 | ovs_assert(dpif->dpif_class == dpif_class); |
96fba48f BP |
56 | } |
57 | ||
ac64794a BP |
58 | struct dpif_flow_dump { |
59 | struct dpif *dpif; | |
64bb477f | 60 | bool terse; /* If true, key/mask/actions may be omitted. */ |
ac64794a BP |
61 | }; |
62 | ||
63 | static inline void | |
64 | dpif_flow_dump_init(struct dpif_flow_dump *dump, const struct dpif *dpif) | |
65 | { | |
66 | dump->dpif = CONST_CAST(struct dpif *, dpif); | |
67 | } | |
68 | ||
69 | struct dpif_flow_dump_thread { | |
70 | struct dpif *dpif; | |
71 | }; | |
72 | ||
73 | static inline void | |
74 | dpif_flow_dump_thread_init(struct dpif_flow_dump_thread *thread, | |
75 | struct dpif_flow_dump *dump) | |
76 | { | |
77 | thread->dpif = dump->dpif; | |
78 | } | |
79 | ||
b77d9629 DDP |
80 | struct ct_dpif_dump_state; |
81 | struct ct_dpif_entry; | |
817a7657 | 82 | struct ct_dpif_tuple; |
1f161318 | 83 | struct ct_dpif_timeout_policy; |
b77d9629 | 84 | |
4ea96698 DB |
85 | /* 'dpif_ipf_proto_status' and 'dpif_ipf_status' are presently in |
86 | * sync with 'ipf_proto_status' and 'ipf_status', but more | |
87 | * generally represent a superset of present and future support. */ | |
88 | struct dpif_ipf_proto_status { | |
89 | uint64_t nfrag_accepted; | |
90 | uint64_t nfrag_completed_sent; | |
91 | uint64_t nfrag_expired_sent; | |
92 | uint64_t nfrag_too_small; | |
93 | uint64_t nfrag_overlap; | |
94 | uint64_t nfrag_purged; | |
95 | unsigned int min_frag_size; | |
96 | bool enabled; | |
97 | }; | |
98 | ||
99 | struct dpif_ipf_status { | |
100 | struct dpif_ipf_proto_status v4; | |
101 | struct dpif_ipf_proto_status v6; | |
102 | unsigned int nfrag; | |
103 | unsigned int nfrag_max; | |
104 | }; | |
105 | ||
96fba48f | 106 | /* Datapath interface class structure, to be defined by each implementation of |
f20279af | 107 | * a datapath interface. |
96fba48f BP |
108 | * |
109 | * These functions return 0 if successful or a positive errno value on failure, | |
110 | * except where otherwise noted. | |
111 | * | |
112 | * These functions are expected to execute synchronously, that is, to block as | |
113 | * necessary to obtain a result. Thus, they may not return EAGAIN or | |
114 | * EWOULDBLOCK or EINPROGRESS. We may relax this requirement in the future if | |
115 | * and when we encounter performance problems. */ | |
116 | struct dpif_class { | |
1a6f1e2a | 117 | /* Type of dpif in this class, e.g. "system", "netdev", etc. |
96fba48f | 118 | * |
1a6f1e2a JG |
119 | * One of the providers should supply a "system" type, since this is |
120 | * the type assumed if no type is specified when opening a dpif. */ | |
121 | const char *type; | |
96fba48f | 122 | |
f87c1357 IM |
123 | /* If 'true', datapath ports should be destroyed on ofproto destruction. |
124 | * | |
125 | * This is used by the vswitch at exit, so that it can clean any | |
126 | * datapaths that can not exist without it (e.g. netdev datapath). */ | |
127 | bool cleanup_required; | |
128 | ||
c8973eb6 DDP |
129 | /* Called when the dpif provider is registered, typically at program |
130 | * startup. Returning an error from this function will prevent any | |
131 | * datapath with this class from being created. | |
132 | * | |
133 | * This function may be set to null if a datapath class needs no | |
134 | * initialization at registration time. */ | |
135 | int (*init)(void); | |
136 | ||
2240af25 DDP |
137 | /* Enumerates the names of all known created datapaths (of class |
138 | * 'dpif_class'), if possible, into 'all_dps'. The caller has already | |
139 | * initialized 'all_dps' and other dpif classes might already have added | |
140 | * names to it. | |
d3d22744 BP |
141 | * |
142 | * This is used by the vswitch at startup, so that it can delete any | |
143 | * datapaths that are not configured. | |
144 | * | |
145 | * Some kinds of datapaths might not be practically enumerable, in which | |
146 | * case this function may be a null pointer. */ | |
2240af25 | 147 | int (*enumerate)(struct sset *all_dps, const struct dpif_class *dpif_class); |
d3d22744 | 148 | |
0aeaabc8 JP |
149 | /* Returns the type to pass to netdev_open() when a dpif of class |
150 | * 'dpif_class' has a port of type 'type', for a few special cases | |
151 | * when a netdev type differs from a port type. For example, when | |
152 | * using the userspace datapath, a port of type "internal" needs to | |
153 | * be opened as "tap". | |
154 | * | |
155 | * Returns either 'type' itself or a string literal, which must not | |
156 | * be freed. */ | |
157 | const char *(*port_open_type)(const struct dpif_class *dpif_class, | |
158 | const char *type); | |
159 | ||
1a6f1e2a JG |
160 | /* Attempts to open an existing dpif called 'name', if 'create' is false, |
161 | * or to open an existing dpif or create a new one, if 'create' is true. | |
96fba48f | 162 | * |
4a387741 BP |
163 | * 'dpif_class' is the class of dpif to open. |
164 | * | |
165 | * If successful, stores a pointer to the new dpif in '*dpifp', which must | |
166 | * have class 'dpif_class'. On failure there are no requirements on what | |
167 | * is stored in '*dpifp'. */ | |
168 | int (*open)(const struct dpif_class *dpif_class, | |
169 | const char *name, bool create, struct dpif **dpifp); | |
96fba48f BP |
170 | |
171 | /* Closes 'dpif' and frees associated memory. */ | |
172 | void (*close)(struct dpif *dpif); | |
173 | ||
174 | /* Attempts to destroy the dpif underlying 'dpif'. | |
175 | * | |
176 | * If successful, 'dpif' will not be used again except as an argument for | |
177 | * the 'close' member function. */ | |
1acb6baa | 178 | int (*destroy)(struct dpif *dpif); |
96fba48f | 179 | |
a36de779 PS |
180 | /* Performs periodic work needed by 'dpif', if any is necessary. |
181 | * Returns true if need to revalidate. */ | |
182 | bool (*run)(struct dpif *dpif); | |
640e1b20 BP |
183 | |
184 | /* Arranges for poll_block() to wake up if the "run" member function needs | |
185 | * to be called for 'dpif'. */ | |
186 | void (*wait)(struct dpif *dpif); | |
187 | ||
96fba48f | 188 | /* Retrieves statistics for 'dpif' into 'stats'. */ |
a8d9304d | 189 | int (*get_stats)(const struct dpif *dpif, struct dpif_dp_stats *stats); |
96fba48f | 190 | |
dcdcad68 PB |
191 | int (*set_features)(struct dpif *dpif, uint32_t user_features); |
192 | ||
232dfa4a | 193 | /* Adds 'netdev' as a new port in 'dpif'. If '*port_no' is not |
8eff7d8a | 194 | * ODPP_NONE, attempts to use that as the port's port number. |
232dfa4a JP |
195 | * |
196 | * If port is successfully added, sets '*port_no' to the new port's | |
197 | * port number. Returns EBUSY if caller attempted to choose a port | |
198 | * number, and it was in use. */ | |
c3827f61 | 199 | int (*port_add)(struct dpif *dpif, struct netdev *netdev, |
4e022ec0 | 200 | odp_port_t *port_no); |
96fba48f BP |
201 | |
202 | /* Removes port numbered 'port_no' from 'dpif'. */ | |
4e022ec0 | 203 | int (*port_del)(struct dpif *dpif, odp_port_t port_no); |
96fba48f | 204 | |
91364d18 IM |
205 | /* Refreshes configuration of 'dpif's port. The implementation might |
206 | * postpone applying the changes until run() is called. */ | |
207 | int (*port_set_config)(struct dpif *dpif, odp_port_t port_no, | |
208 | const struct smap *cfg); | |
209 | ||
4afba28d JP |
210 | /* Queries 'dpif' for a port with the given 'port_no' or 'devname'. |
211 | * If 'port' is not null, stores information about the port into | |
212 | * '*port' if successful. | |
4c738a8d | 213 | * |
0f6a066f DDP |
214 | * If the port doesn't exist, the provider must return ENODEV. Other |
215 | * error numbers means that something wrong happened and will be | |
216 | * treated differently by upper layers. | |
217 | * | |
4afba28d JP |
218 | * If 'port' is not null, the caller takes ownership of data in |
219 | * 'port' and must free it with dpif_port_destroy() when it is no | |
220 | * longer needed. */ | |
4e022ec0 | 221 | int (*port_query_by_number)(const struct dpif *dpif, odp_port_t port_no, |
4c738a8d | 222 | struct dpif_port *port); |
96fba48f | 223 | int (*port_query_by_name)(const struct dpif *dpif, const char *devname, |
4c738a8d | 224 | struct dpif_port *port); |
96fba48f | 225 | |
98403001 BP |
226 | /* Returns the Netlink PID value to supply in OVS_ACTION_ATTR_USERSPACE |
227 | * actions as the OVS_USERSPACE_ATTR_PID attribute's value, for use in | |
769b5034 | 228 | * flows whose packets arrived on port 'port_no'. |
98403001 | 229 | * |
9b56fe13 | 230 | * A 'port_no' of UINT32_MAX should be treated as a special case. The |
625b0720 BP |
231 | * implementation should return a reserved PID, not allocated to any port, |
232 | * that the client may use for special purposes. | |
233 | * | |
98403001 BP |
234 | * The return value only needs to be meaningful when DPIF_UC_ACTION has |
235 | * been enabled in the 'dpif''s listen mask, and it is allowed to change | |
236 | * when DPIF_UC_ACTION is disabled and then re-enabled. | |
237 | * | |
238 | * A dpif provider that doesn't have meaningful Netlink PIDs can use NULL | |
239 | * for this function. This is equivalent to always returning 0. */ | |
769b5034 | 240 | uint32_t (*port_get_pid)(const struct dpif *dpif, odp_port_t port_no); |
98403001 | 241 | |
b0ec0f27 BP |
242 | /* Attempts to begin dumping the ports in a dpif. On success, returns 0 |
243 | * and initializes '*statep' with any data needed for iteration. On | |
244 | * failure, returns a positive errno value. */ | |
245 | int (*port_dump_start)(const struct dpif *dpif, void **statep); | |
246 | ||
247 | /* Attempts to retrieve another port from 'dpif' for 'state', which was | |
248 | * initialized by a successful call to the 'port_dump_start' function for | |
4c738a8d | 249 | * 'dpif'. On success, stores a new dpif_port into 'port' and returns 0. |
b0ec0f27 BP |
250 | * Returns EOF if the end of the port table has been reached, or a positive |
251 | * errno value on error. This function will not be called again once it | |
252 | * returns nonzero once for a given iteration (but the 'port_dump_done' | |
4c738a8d BP |
253 | * function will be called afterward). |
254 | * | |
255 | * The dpif provider retains ownership of the data stored in 'port'. It | |
256 | * must remain valid until at least the next call to 'port_dump_next' or | |
257 | * 'port_dump_done' for 'state'. */ | |
b0ec0f27 | 258 | int (*port_dump_next)(const struct dpif *dpif, void *state, |
4c738a8d | 259 | struct dpif_port *port); |
b0ec0f27 BP |
260 | |
261 | /* Releases resources from 'dpif' for 'state', which was initialized by a | |
262 | * successful call to the 'port_dump_start' function for 'dpif'. */ | |
263 | int (*port_dump_done)(const struct dpif *dpif, void *state); | |
96fba48f | 264 | |
e9e28be3 BP |
265 | /* Polls for changes in the set of ports in 'dpif'. If the set of ports in |
266 | * 'dpif' has changed, then this function should do one of the | |
267 | * following: | |
268 | * | |
269 | * - Preferably: store the name of the device that was added to or deleted | |
270 | * from 'dpif' in '*devnamep' and return 0. The caller is responsible | |
271 | * for freeing '*devnamep' (with free()) when it no longer needs it. | |
272 | * | |
273 | * - Alternatively: return ENOBUFS, without indicating the device that was | |
274 | * added or deleted. | |
275 | * | |
276 | * Occasional 'false positives', in which the function returns 0 while | |
277 | * indicating a device that was not actually added or deleted or returns | |
278 | * ENOBUFS without any change, are acceptable. | |
279 | * | |
280 | * If the set of ports in 'dpif' has not changed, returns EAGAIN. May also | |
281 | * return other positive errno values to indicate that something has gone | |
282 | * wrong. */ | |
283 | int (*port_poll)(const struct dpif *dpif, char **devnamep); | |
284 | ||
285 | /* Arranges for the poll loop to wake up when 'port_poll' will return a | |
286 | * value other than EAGAIN. */ | |
287 | void (*port_poll_wait)(const struct dpif *dpif); | |
288 | ||
96fba48f BP |
289 | /* Deletes all flows from 'dpif' and clears all of its queues of received |
290 | * packets. */ | |
291 | int (*flow_flush)(struct dpif *dpif); | |
292 | ||
ac64794a | 293 | /* Flow dumping interface. |
e6cc0bab | 294 | * |
ac64794a BP |
295 | * This is the back-end for the flow dumping interface described in |
296 | * dpif.h. Please read the comments there first, because this code | |
297 | * closely follows it. | |
e6cc0bab | 298 | * |
ac64794a BP |
299 | * 'flow_dump_create' and 'flow_dump_thread_create' must always return an |
300 | * initialized and usable data structure and defer error return until | |
301 | * flow_dump_destroy(). This hasn't been a problem for the dpifs that | |
302 | * exist so far. | |
704a1e09 | 303 | * |
ac64794a BP |
304 | * 'flow_dump_create' and 'flow_dump_thread_create' must initialize the |
305 | * structures that they return with dpif_flow_dump_init() and | |
64bb477f JS |
306 | * dpif_flow_dump_thread_init(), respectively. |
307 | * | |
308 | * If 'terse' is true, then only UID and statistics will | |
7e8b7199 PB |
309 | * be returned in the dump. Otherwise, all fields will be returned. |
310 | * | |
a692410a GT |
311 | * If 'types' isn't null, dumps only the flows of the passed types. */ |
312 | struct dpif_flow_dump *(*flow_dump_create)( | |
313 | const struct dpif *dpif, | |
314 | bool terse, | |
315 | struct dpif_flow_dump_types *types); | |
ac64794a BP |
316 | int (*flow_dump_destroy)(struct dpif_flow_dump *dump); |
317 | ||
318 | struct dpif_flow_dump_thread *(*flow_dump_thread_create)( | |
319 | struct dpif_flow_dump *dump); | |
320 | void (*flow_dump_thread_destroy)(struct dpif_flow_dump_thread *thread); | |
321 | ||
322 | int (*flow_dump_next)(struct dpif_flow_dump_thread *thread, | |
323 | struct dpif_flow *flows, int max_flows); | |
6bc60024 BP |
324 | /* Executes each of the 'n_ops' operations in 'ops' on 'dpif', in the order |
325 | * in which they are specified, placing each operation's results in the | |
1a0c894a | 326 | * "output" members documented in comments and the 'error' member of each |
57924fc9 SB |
327 | * dpif_op. The offload_type argument tells the provider if 'ops' should |
328 | * be submitted to to a netdev (only offload) or to the kernel datapath | |
329 | * (never offload) or to both (offload if possible; software fallback). */ | |
330 | void (*operate)(struct dpif *dpif, struct dpif_op **ops, size_t n_ops, | |
331 | enum dpif_offload_type offload_type); | |
6bc60024 | 332 | |
a12b3ead BP |
333 | /* Enables or disables receiving packets with dpif_recv() for 'dpif'. |
334 | * Turning packet receive off and then back on is allowed to change Netlink | |
98403001 BP |
335 | * PID assignments (see ->port_get_pid()). The client is responsible for |
336 | * updating flows as necessary if it does this. */ | |
a12b3ead | 337 | int (*recv_set)(struct dpif *dpif, bool enable); |
96fba48f | 338 | |
1954e6bb AW |
339 | /* Refreshes the poll loops and Netlink sockets associated to each port, |
340 | * when the number of upcall handlers (upcall receiving thread) is changed | |
341 | * to 'n_handlers' and receiving packets for 'dpif' is enabled by | |
342 | * recv_set(). | |
343 | * | |
344 | * Since multiple upcall handlers can read upcalls simultaneously from | |
345 | * 'dpif', each port can have multiple Netlink sockets, one per upcall | |
346 | * handler. So, handlers_set() is responsible for the following tasks: | |
347 | * | |
348 | * When receiving upcall is enabled, extends or creates the | |
349 | * configuration to support: | |
350 | * | |
351 | * - 'n_handlers' Netlink sockets for each port. | |
352 | * | |
353 | * - 'n_handlers' poll loops, one for each upcall handler. | |
354 | * | |
355 | * - registering the Netlink sockets for the same upcall handler to | |
356 | * the corresponding poll loop. | |
357 | * */ | |
358 | int (*handlers_set)(struct dpif *dpif, uint32_t n_handlers); | |
359 | ||
d4f6865c DDP |
360 | /* Pass custom configuration options to the datapath. The implementation |
361 | * might postpone applying the changes until run() is called. */ | |
362 | int (*set_config)(struct dpif *dpif, const struct smap *other_config); | |
f2eee189 | 363 | |
aae51f53 | 364 | /* Translates OpenFlow queue ID 'queue_id' (in host byte order) into a |
abff858b | 365 | * priority value used for setting packet priority. */ |
aae51f53 BP |
366 | int (*queue_to_priority)(const struct dpif *dpif, uint32_t queue_id, |
367 | uint32_t *priority); | |
368 | ||
1954e6bb AW |
369 | /* Polls for an upcall from 'dpif' for an upcall handler. Since there |
370 | * can be multiple poll loops (see ->handlers_set()), 'handler_id' is | |
371 | * needed as index to identify the corresponding poll loop. If | |
372 | * successful, stores the upcall into '*upcall', using 'buf' for | |
373 | * storage. Should only be called if 'recv_set' has been used to enable | |
374 | * receiving packets from 'dpif'. | |
96fba48f | 375 | * |
da546e07 JR |
376 | * The implementation should point 'upcall->key' and 'upcall->userdata' |
377 | * (if any) into data in the caller-provided 'buf'. The implementation may | |
378 | * also use 'buf' for storing the data of 'upcall->packet'. If necessary | |
379 | * to make room, the implementation may reallocate the data in 'buf'. | |
380 | * | |
381 | * The caller owns the data of 'upcall->packet' and may modify it. If | |
382 | * packet's headroom is exhausted as it is manipulated, 'upcall->packet' | |
383 | * will be reallocated. This requires the data of 'upcall->packet' to be | |
837a88dc JR |
384 | * released with ofpbuf_uninit() before 'upcall' is destroyed. However, |
385 | * when an error is returned, the 'upcall->packet' may be uninitialized | |
386 | * and should not be released. | |
856081f6 BP |
387 | * |
388 | * This function must not block. If no upcall is pending when it is | |
389 | * called, it should return EAGAIN without blocking. */ | |
1954e6bb AW |
390 | int (*recv)(struct dpif *dpif, uint32_t handler_id, |
391 | struct dpif_upcall *upcall, struct ofpbuf *buf); | |
392 | ||
393 | /* Arranges for the poll loop for an upcall handler to wake up when 'dpif' | |
394 | * has a message queued to be received with the recv member functions. | |
395 | * Since there can be multiple poll loops (see ->handlers_set()), | |
396 | * 'handler_id' is needed as index to identify the corresponding poll loop. | |
397 | * */ | |
398 | void (*recv_wait)(struct dpif *dpif, uint32_t handler_id); | |
1ba530f4 BP |
399 | |
400 | /* Throws away any queued upcalls that 'dpif' currently has ready to | |
401 | * return. */ | |
402 | void (*recv_purge)(struct dpif *dpif); | |
6b31e073 | 403 | |
e4e74c3a AW |
404 | /* When 'dpif' is about to purge the datapath, the higher layer may want |
405 | * to be notified so that it could try reacting accordingly (e.g. grabbing | |
406 | * all flow stats before they are gone). | |
407 | * | |
408 | * Registers an upcall callback function with 'dpif'. This is only used | |
409 | * if 'dpif' needs to notify the purging of datapath. 'aux' is passed to | |
410 | * the callback on invocation. */ | |
411 | void (*register_dp_purge_cb)(struct dpif *, dp_purge_callback *, void *aux); | |
412 | ||
6b31e073 RW |
413 | /* For datapaths that run in userspace (i.e. dpif-netdev), threads polling |
414 | * for incoming packets can directly call upcall functions instead of | |
415 | * offloading packet processing to separate handler threads. Datapaths | |
416 | * that directly call upcall functions should use the functions below to | |
417 | * to register an upcall function and enable / disable upcalls. | |
418 | * | |
e4e74c3a | 419 | * Registers an upcall callback function with 'dpif'. This is only used |
623540e4 EJ |
420 | * if 'dpif' directly executes upcall functions. 'aux' is passed to the |
421 | * callback on invocation. */ | |
422 | void (*register_upcall_cb)(struct dpif *, upcall_callback *, void *aux); | |
6b31e073 RW |
423 | |
424 | /* Enables upcalls if 'dpif' directly executes upcall functions. */ | |
425 | void (*enable_upcall)(struct dpif *); | |
426 | ||
427 | /* Disables upcalls if 'dpif' directly executes upcall functions. */ | |
428 | void (*disable_upcall)(struct dpif *); | |
b5cbbcf6 AZ |
429 | |
430 | /* Get datapath version. Caller is responsible for freeing the string | |
431 | * returned. */ | |
432 | char *(*get_datapath_version)(void); | |
b77d9629 DDP |
433 | |
434 | /* Conntrack entry dumping interface. | |
435 | * | |
436 | * These functions are used by ct-dpif.c to provide a datapath-agnostic | |
9dcd5910 | 437 | * dumping interface to the connection trackers provided by the |
b77d9629 DDP |
438 | * datapaths. |
439 | * | |
440 | * ct_dump_start() should put in '*state' a pointer to a newly allocated | |
441 | * stucture that will be passed by the caller to ct_dump_next() and | |
442 | * ct_dump_done(). If 'zone' is not NULL, only the entries in '*zone' | |
443 | * should be dumped. | |
444 | * | |
445 | * ct_dump_next() should fill 'entry' with information from a connection | |
446 | * and prepare to dump the next one on a subsequest invocation. | |
447 | * | |
9dcd5910 | 448 | * ct_dump_done() should perform any cleanup necessary (including |
b77d9629 DDP |
449 | * deallocating the 'state' structure, if applicable). */ |
450 | int (*ct_dump_start)(struct dpif *, struct ct_dpif_dump_state **state, | |
ded30c74 | 451 | const uint16_t *zone, int *); |
9dcd5910 | 452 | int (*ct_dump_next)(struct dpif *, struct ct_dpif_dump_state *state, |
b77d9629 DDP |
453 | struct ct_dpif_entry *entry); |
454 | int (*ct_dump_done)(struct dpif *, struct ct_dpif_dump_state *state); | |
a0f7b6d5 | 455 | |
817a7657 YHW |
456 | /* Flushes the connection tracking tables. The arguments have the |
457 | * following behavior: | |
458 | * | |
459 | * - If both 'zone' and 'tuple' are NULL, flush all the conntrack | |
460 | * entries. | |
461 | * - If 'zone' is not NULL, and 'tuple' is NULL, flush all the | |
462 | * conntrack entries in '*zone'. | |
463 | * - If 'tuple' is not NULL, flush the conntrack entry specified by | |
464 | * 'tuple' in '*zone'. If 'zone' is NULL, use the default zone | |
465 | * (zone 0). */ | |
466 | int (*ct_flush)(struct dpif *, const uint16_t *zone, | |
467 | const struct ct_dpif_tuple *tuple); | |
c92339ad DB |
468 | /* Set max connections allowed. */ |
469 | int (*ct_set_maxconns)(struct dpif *, uint32_t maxconns); | |
470 | /* Get max connections allowed. */ | |
471 | int (*ct_get_maxconns)(struct dpif *, uint32_t *maxconns); | |
875075b3 DB |
472 | /* Get number of connections tracked. */ |
473 | int (*ct_get_nconns)(struct dpif *, uint32_t *nconns); | |
64207120 DB |
474 | /* Enable or disable TCP sequence checking. */ |
475 | int (*ct_set_tcp_seq_chk)(struct dpif *, bool enabled); | |
476 | /* Get the TCP sequence checking configuration. */ | |
477 | int (*ct_get_tcp_seq_chk)(struct dpif *, bool *enabled); | |
478 | ||
5dddf960 | 479 | |
cd015a11 YHW |
480 | /* Connection tracking per zone limit */ |
481 | ||
482 | /* Per zone conntrack limit sets the maximum allowed connections in zones | |
483 | * to provide resource isolation. If a per zone limit for a particular | |
484 | * zone is not available in the datapath, it defaults to the default | |
485 | * per zone limit. Initially, the default per zone limit is | |
486 | * unlimited (0). */ | |
487 | ||
488 | /* Sets the max connections allowed per zone according to 'zone_limits', | |
489 | * a list of 'struct ct_dpif_zone_limit' entries (the 'count' member | |
490 | * is not used when setting limits). If 'default_limit' is not NULL, | |
491 | * modifies the default limit to '*default_limit'. */ | |
492 | int (*ct_set_limits)(struct dpif *, const uint32_t *default_limit, | |
493 | const struct ovs_list *zone_limits); | |
494 | ||
495 | /* Looks up the default per zone limit and stores that in | |
496 | * 'default_limit'. Look up the per zone limits for all zones in | |
497 | * the 'zone_limits_in' list of 'struct ct_dpif_zone_limit' entries | |
498 | * (the 'limit' and 'count' members are not used), and stores the | |
499 | * reply that includes the zone, the per zone limit, and the number | |
500 | * of connections in the zone into 'zone_limits_out' list. */ | |
501 | int (*ct_get_limits)(struct dpif *, uint32_t *default_limit, | |
502 | const struct ovs_list *zone_limits_in, | |
503 | struct ovs_list *zone_limits_out); | |
504 | ||
505 | /* Deletes per zone limit of all zones specified in 'zone_limits', a | |
506 | * list of 'struct ct_dpif_zone_limit' entries. */ | |
507 | int (*ct_del_limits)(struct dpif *, const struct ovs_list *zone_limits); | |
508 | ||
1f161318 YHW |
509 | /* Connection tracking timeout policy */ |
510 | ||
511 | /* A connection tracking timeout policy contains a list of timeout | |
512 | * attributes that specify timeout values on various connection states. | |
513 | * In a datapath, the timeout policy is identified by a 4-byte unsigned | |
514 | * integer. Unsupported timeout attributes are ignored. When a | |
515 | * connection is committed it can be associated with a timeout | |
516 | * policy, or it defaults to the datapath's default timeout policy. */ | |
517 | ||
518 | /* Sets timeout policy '*tp' into the datapath. */ | |
519 | int (*ct_set_timeout_policy)(struct dpif *, | |
520 | const struct ct_dpif_timeout_policy *tp); | |
521 | /* Gets a timeout policy specified by tp_id and stores it into '*tp'. */ | |
522 | int (*ct_get_timeout_policy)(struct dpif *, uint32_t tp_id, | |
523 | struct ct_dpif_timeout_policy *tp); | |
524 | /* Deletes a timeout policy identified by 'tp_id'. */ | |
525 | int (*ct_del_timeout_policy)(struct dpif *, uint32_t tp_id); | |
526 | ||
527 | /* Conntrack timeout policy dumping interface. | |
528 | * | |
529 | * These functions provide a datapath-agnostic dumping interface | |
530 | * to the conntrack timeout policy provided by the datapaths. | |
531 | * | |
532 | * ct_timeout_policy_dump_start() should put in '*statep' a pointer to | |
533 | * a newly allocated structure that will be passed by the caller to | |
534 | * ct_timeout_policy_dump_next() and ct_timeout_policy_dump_done(). | |
535 | * | |
536 | * ct_timeout_policy_dump_next() attempts to retrieve another timeout | |
537 | * policy from 'dpif' for 'state', which was initialized by a successful | |
538 | * call to ct_timeout_policy_dump_start(). On success, stores a new | |
539 | * timeout policy into 'tp' and returns 0. Returns EOF if the last | |
540 | * timeout policy has been dumped, or a positive errno value on error. | |
541 | * This function will not be called again once it returns nonzero once | |
542 | * for a given iteration (but the ct_timeout_policy_dump_done() will | |
543 | * be called afterward). | |
544 | * | |
545 | * ct_timeout_policy_dump_done() should perform any cleanup necessary | |
546 | * (including deallocating the 'state' structure, if applicable). */ | |
547 | int (*ct_timeout_policy_dump_start)(struct dpif *, void **statep); | |
548 | int (*ct_timeout_policy_dump_next)(struct dpif *, void *state, | |
549 | struct ct_dpif_timeout_policy *tp); | |
550 | int (*ct_timeout_policy_dump_done)(struct dpif *, void *state); | |
551 | ||
187bb41f YHW |
552 | /* Gets timeout policy based on 'tp_id', 'dl_type' and 'nw_proto'. |
553 | * On success, returns 0, stores the timeout policy name in 'tp_name', | |
554 | * and sets 'is_generic'. 'is_generic' is false if the returned timeout | |
555 | * policy in the 'dpif' is specific to 'dl_type' and 'nw_proto' in the | |
556 | * datapath (e.g., the Linux kernel datapath). Sets 'is_generic' to | |
557 | * true, if the timeout policy supports all OVS supported L3/L4 | |
558 | * protocols. | |
559 | * | |
560 | * The caller is responsible for freeing 'tp_name'. */ | |
561 | int (*ct_get_timeout_policy_name)(struct dpif *, uint32_t tp_id, | |
562 | uint16_t dl_type, uint8_t nw_proto, | |
563 | char **tp_name, bool *is_generic); | |
564 | ||
4ea96698 DB |
565 | /* IP Fragmentation. */ |
566 | ||
567 | /* Disables or enables conntrack fragment reassembly. The default | |
568 | * setting is enabled. */ | |
569 | int (*ipf_set_enabled)(struct dpif *, bool v6, bool enabled); | |
570 | ||
571 | /* Set minimum fragment allowed. */ | |
572 | int (*ipf_set_min_frag)(struct dpif *, bool v6, uint32_t min_frag); | |
573 | ||
574 | /* Set maximum number of fragments tracked. */ | |
575 | int (*ipf_set_max_nfrags)(struct dpif *, uint32_t max_nfrags); | |
576 | ||
577 | /* Get fragmentation configuration status and counters. */ | |
578 | int (*ipf_get_status)(struct dpif *, | |
579 | struct dpif_ipf_status *dpif_ipf_status); | |
580 | ||
581 | /* The following 3 apis find and print ipf lists by creating a string | |
582 | * representation of the state of an ipf list, to which 'dump' is pointed | |
583 | * to. 'ipf_dump_start()' allocates memory for 'ipf_dump_ctx'. | |
584 | * 'ipf_dump_next()' finds the next ipf list and copies it's | |
585 | * characteristics to a string, which is freed by the caller. | |
586 | * 'ipf_dump_done()' frees the 'ipf_dump_ctx' that was allocated in | |
587 | * 'ipf_dump_start'. */ | |
588 | int (*ipf_dump_start)(struct dpif *, struct ipf_dump_ctx **ipf_dump_ctx); | |
589 | int (*ipf_dump_next)(struct dpif *, void *ipf_dump_ctx, char **dump); | |
590 | int (*ipf_dump_done)(struct dpif *, void *ipf_dump_ctx); | |
591 | ||
5dddf960 JR |
592 | /* Meters */ |
593 | ||
594 | /* Queries 'dpif' for supported meter features. | |
595 | * NULL pointer means no meter features are supported. */ | |
596 | void (*meter_get_features)(const struct dpif *, | |
597 | struct ofputil_meter_features *); | |
598 | ||
8101f03f JP |
599 | /* Adds or modifies the meter in 'dpif' with the given 'meter_id' |
600 | * and the configuration in 'config'. | |
5dddf960 | 601 | * |
8101f03f JP |
602 | * The meter id specified through 'config->meter_id' is ignored. */ |
603 | int (*meter_set)(struct dpif *, ofproto_meter_id meter_id, | |
5dddf960 JR |
604 | struct ofputil_meter_config *); |
605 | ||
606 | /* Queries 'dpif' for meter stats with the given 'meter_id'. Stores | |
607 | * maximum of 'n_bands' meter statistics, returning the number of band | |
608 | * stats returned in 'stats->n_bands' if successful. */ | |
609 | int (*meter_get)(const struct dpif *, ofproto_meter_id meter_id, | |
610 | struct ofputil_meter_stats *, uint16_t n_bands); | |
611 | ||
612 | /* Removes meter 'meter_id' from 'dpif'. Stores meter and band statistics | |
613 | * (for maximum of 'n_bands', returning the number of band stats returned | |
614 | * in 'stats->n_bands' if successful. 'stats' may be passed in as NULL if | |
615 | * no stats are needed, in which case 'n_bands' must be passed in as | |
616 | * zero. */ | |
617 | int (*meter_del)(struct dpif *, ofproto_meter_id meter_id, | |
618 | struct ofputil_meter_stats *, uint16_t n_bands); | |
96fba48f BP |
619 | }; |
620 | ||
93451a0a | 621 | extern const struct dpif_class dpif_netlink_class; |
72865317 | 622 | extern const struct dpif_class dpif_netdev_class; |
96fba48f | 623 | |
1acb6baa BP |
624 | #ifdef __cplusplus |
625 | } | |
626 | #endif | |
627 | ||
96fba48f | 628 | #endif /* dpif-provider.h */ |