]> git.proxmox.com Git - ovs.git/blob - lib/netdev-provider.h
netdev: Add support multiqueue recv.
[ovs.git] / lib / netdev-provider.h
1 /*
2 * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
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 NETDEV_PROVIDER_H
18 #define NETDEV_PROVIDER_H 1
19
20 /* Generic interface to network devices. */
21
22 #include "netdev.h"
23 #include "list.h"
24 #include "shash.h"
25 #include "smap.h"
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 /* A network device (e.g. an Ethernet device).
32 *
33 * Network device implementations may read these members but should not modify
34 * them. */
35 struct netdev {
36 /* The following do not change during the lifetime of a struct netdev. */
37 char *name; /* Name of network device. */
38 const struct netdev_class *netdev_class; /* Functions to control
39 this device. */
40
41 /* The following are protected by 'netdev_mutex' (internal to netdev.c). */
42 int n_rxq;
43 int ref_cnt; /* Times this devices was opened. */
44 struct shash_node *node; /* Pointer to element in global map. */
45 struct list saved_flags_list; /* Contains "struct netdev_saved_flags". */
46 };
47
48 const char *netdev_get_type(const struct netdev *);
49 const struct netdev_class *netdev_get_class(const struct netdev *);
50 const char *netdev_get_name(const struct netdev *);
51 struct netdev *netdev_from_name(const char *name);
52 void netdev_get_devices(const struct netdev_class *,
53 struct shash *device_list);
54
55 /* A data structure for capturing packets received by a network device.
56 *
57 * Network device implementations may read these members but should not modify
58 * them.
59 *
60 * None of these members change during the lifetime of a struct netdev_rxq. */
61 struct netdev_rxq {
62 struct netdev *netdev; /* Owns a reference to the netdev. */
63 int queue_id;
64 };
65
66 struct netdev *netdev_rxq_get_netdev(const struct netdev_rxq *);
67
68 /* Network device class structure, to be defined by each implementation of a
69 * network device.
70 *
71 * These functions return 0 if successful or a positive errno value on failure,
72 * except where otherwise noted.
73 *
74 *
75 * Data Structures
76 * ===============
77 *
78 * These functions work primarily with two different kinds of data structures:
79 *
80 * - "struct netdev", which represents a network device.
81 *
82 * - "struct netdev_rxq", which represents a handle for capturing packets
83 * received on a network device
84 *
85 * Each of these data structures contains all of the implementation-independent
86 * generic state for the respective concept, called the "base" state. None of
87 * them contains any extra space for implementations to use. Instead, each
88 * implementation is expected to declare its own data structure that contains
89 * an instance of the generic data structure plus additional
90 * implementation-specific members, called the "derived" state. The
91 * implementation can use casts or (preferably) the CONTAINER_OF macro to
92 * obtain access to derived state given only a pointer to the embedded generic
93 * data structure.
94 *
95 *
96 * Life Cycle
97 * ==========
98 *
99 * Four stylized functions accompany each of these data structures:
100 *
101 * "alloc" "construct" "destruct" "dealloc"
102 * ------------ ---------------- --------------- --------------
103 * netdev ->alloc ->construct ->destruct ->dealloc
104 * netdev_rxq ->rxq_alloc ->rxq_construct ->rxq_destruct ->rxq_dealloc
105 *
106 * Any instance of a given data structure goes through the following life
107 * cycle:
108 *
109 * 1. The client calls the "alloc" function to obtain raw memory. If "alloc"
110 * fails, skip all the other steps.
111 *
112 * 2. The client initializes all of the data structure's base state. If this
113 * fails, skip to step 7.
114 *
115 * 3. The client calls the "construct" function. The implementation
116 * initializes derived state. It may refer to the already-initialized
117 * base state. If "construct" fails, skip to step 6.
118 *
119 * 4. The data structure is now initialized and in use.
120 *
121 * 5. When the data structure is no longer needed, the client calls the
122 * "destruct" function. The implementation uninitializes derived state.
123 * The base state has not been uninitialized yet, so the implementation
124 * may still refer to it.
125 *
126 * 6. The client uninitializes all of the data structure's base state.
127 *
128 * 7. The client calls the "dealloc" to free the raw memory. The
129 * implementation must not refer to base or derived state in the data
130 * structure, because it has already been uninitialized.
131 *
132 * If netdev support multi-queue IO then netdev->construct should set initialize
133 * netdev->n_rxq to number of queues.
134 *
135 * Each "alloc" function allocates and returns a new instance of the respective
136 * data structure. The "alloc" function is not given any information about the
137 * use of the new data structure, so it cannot perform much initialization.
138 * Its purpose is just to ensure that the new data structure has enough room
139 * for base and derived state. It may return a null pointer if memory is not
140 * available, in which case none of the other functions is called.
141 *
142 * Each "construct" function initializes derived state in its respective data
143 * structure. When "construct" is called, all of the base state has already
144 * been initialized, so the "construct" function may refer to it. The
145 * "construct" function is allowed to fail, in which case the client calls the
146 * "dealloc" function (but not the "destruct" function).
147 *
148 * Each "destruct" function uninitializes and frees derived state in its
149 * respective data structure. When "destruct" is called, the base state has
150 * not yet been uninitialized, so the "destruct" function may refer to it. The
151 * "destruct" function is not allowed to fail.
152 *
153 * Each "dealloc" function frees raw memory that was allocated by the the
154 * "alloc" function. The memory's base and derived members might not have ever
155 * been initialized (but if "construct" returned successfully, then it has been
156 * "destruct"ed already). The "dealloc" function is not allowed to fail.
157 *
158 *
159 * Device Change Notification
160 * ==========================
161 *
162 * Minimally, implementations are required to report changes to netdev flags,
163 * features, ethernet address or carrier through connectivity_seq. Changes to
164 * other properties are allowed to cause notification through this interface,
165 * although implementations should try to avoid this. connectivity_seq_get()
166 * can be used to acquire a reference to the struct seq. The interface is
167 * described in detail in seq.h. */
168 struct netdev_class {
169 /* Type of netdevs in this class, e.g. "system", "tap", "gre", etc.
170 *
171 * One of the providers should supply a "system" type, since this is
172 * the type assumed if no type is specified when opening a netdev.
173 * The "system" type corresponds to an existing network device on
174 * the system. */
175 const char *type;
176
177 /* ## ------------------- ## */
178 /* ## Top-Level Functions ## */
179 /* ## ------------------- ## */
180
181 /* Called when the netdev provider is registered, typically at program
182 * startup. Returning an error from this function will prevent any network
183 * device in this class from being opened.
184 *
185 * This function may be set to null if a network device class needs no
186 * initialization at registration time. */
187 int (*init)(void);
188
189 /* Performs periodic work needed by netdevs of this class. May be null if
190 * no periodic work is necessary. */
191 void (*run)(void);
192
193 /* Arranges for poll_block() to wake up if the "run" member function needs
194 * to be called. Implementations are additionally required to wake
195 * whenever something changes in any of its netdevs which would cause their
196 * ->change_seq() function to change its result. May be null if nothing is
197 * needed here. */
198 void (*wait)(void);
199
200 /* ## ---------------- ## */
201 /* ## netdev Functions ## */
202 /* ## ---------------- ## */
203
204 /* Life-cycle functions for a netdev. See the large comment above on
205 * struct netdev_class. */
206 struct netdev *(*alloc)(void);
207 int (*construct)(struct netdev *);
208 void (*destruct)(struct netdev *);
209 void (*dealloc)(struct netdev *);
210
211 /* Fetches the device 'netdev''s configuration, storing it in 'args'.
212 * The caller owns 'args' and pre-initializes it to an empty smap.
213 *
214 * If this netdev class does not have any configuration options, this may
215 * be a null pointer. */
216 int (*get_config)(const struct netdev *netdev, struct smap *args);
217
218 /* Changes the device 'netdev''s configuration to 'args'.
219 *
220 * If this netdev class does not support configuration, this may be a null
221 * pointer. */
222 int (*set_config)(struct netdev *netdev, const struct smap *args);
223
224 /* Returns the tunnel configuration of 'netdev'. If 'netdev' is
225 * not a tunnel, returns null.
226 *
227 * If this function would always return null, it may be null instead. */
228 const struct netdev_tunnel_config *
229 (*get_tunnel_config)(const struct netdev *netdev);
230
231 /* Sends the buffer on 'netdev'.
232 * Returns 0 if successful, otherwise a positive errno value. Returns
233 * EAGAIN without blocking if the packet cannot be queued immediately.
234 * Returns EMSGSIZE if a partial packet was transmitted or if the packet
235 * is too big or too small to transmit on the device.
236 *
237 * To retain ownership of 'buffer' caller can set may_steal to false.
238 *
239 * The network device is expected to maintain a packet transmission queue,
240 * so that the caller does not ordinarily have to do additional queuing of
241 * packets.
242 *
243 * May return EOPNOTSUPP if a network device does not implement packet
244 * transmission through this interface. This function may be set to null
245 * if it would always return EOPNOTSUPP anyhow. (This will prevent the
246 * network device from being usefully used by the netdev-based "userspace
247 * datapath". It will also prevent the OVS implementation of bonding from
248 * working properly over 'netdev'.) */
249 int (*send)(struct netdev *netdev, struct ofpbuf *buffer, bool may_steal);
250
251 /* Registers with the poll loop to wake up from the next call to
252 * poll_block() when the packet transmission queue for 'netdev' has
253 * sufficient room to transmit a packet with netdev_send().
254 *
255 * The network device is expected to maintain a packet transmission queue,
256 * so that the caller does not ordinarily have to do additional queuing of
257 * packets. Thus, this function is unlikely to ever be useful.
258 *
259 * May be null if not needed, such as for a network device that does not
260 * implement packet transmission through the 'send' member function. */
261 void (*send_wait)(struct netdev *netdev);
262
263 /* Sets 'netdev''s Ethernet address to 'mac' */
264 int (*set_etheraddr)(struct netdev *netdev, const uint8_t mac[6]);
265
266 /* Retrieves 'netdev''s Ethernet address into 'mac'.
267 *
268 * This address will be advertised as 'netdev''s MAC address through the
269 * OpenFlow protocol, among other uses. */
270 int (*get_etheraddr)(const struct netdev *netdev, uint8_t mac[6]);
271
272 /* Retrieves 'netdev''s MTU into '*mtup'.
273 *
274 * The MTU is the maximum size of transmitted (and received) packets, in
275 * bytes, not including the hardware header; thus, this is typically 1500
276 * bytes for Ethernet devices.
277 *
278 * If 'netdev' does not have an MTU (e.g. as some tunnels do not), then
279 * this function should return EOPNOTSUPP. This function may be set to
280 * null if it would always return EOPNOTSUPP. */
281 int (*get_mtu)(const struct netdev *netdev, int *mtup);
282
283 /* Sets 'netdev''s MTU to 'mtu'.
284 *
285 * If 'netdev' does not have an MTU (e.g. as some tunnels do not), then
286 * this function should return EOPNOTSUPP. This function may be set to
287 * null if it would always return EOPNOTSUPP. */
288 int (*set_mtu)(const struct netdev *netdev, int mtu);
289
290 /* Returns the ifindex of 'netdev', if successful, as a positive number.
291 * On failure, returns a negative errno value.
292 *
293 * The desired semantics of the ifindex value are a combination of those
294 * specified by POSIX for if_nametoindex() and by SNMP for ifIndex. An
295 * ifindex value should be unique within a host and remain stable at least
296 * until reboot. SNMP says an ifindex "ranges between 1 and the value of
297 * ifNumber" but many systems do not follow this rule anyhow.
298 *
299 * This function may be set to null if it would always return -EOPNOTSUPP.
300 */
301 int (*get_ifindex)(const struct netdev *netdev);
302
303 /* Sets 'carrier' to true if carrier is active (link light is on) on
304 * 'netdev'.
305 *
306 * May be null if device does not provide carrier status (will be always
307 * up as long as device is up).
308 */
309 int (*get_carrier)(const struct netdev *netdev, bool *carrier);
310
311 /* Returns the number of times 'netdev''s carrier has changed since being
312 * initialized.
313 *
314 * If null, callers will assume the number of carrier resets is zero. */
315 long long int (*get_carrier_resets)(const struct netdev *netdev);
316
317 /* Forces ->get_carrier() to poll 'netdev''s MII registers for link status
318 * instead of checking 'netdev''s carrier. 'netdev''s MII registers will
319 * be polled once ever 'interval' milliseconds. If 'netdev' does not
320 * support MII, another method may be used as a fallback. If 'interval' is
321 * less than or equal to zero, reverts ->get_carrier() to its normal
322 * behavior.
323 *
324 * Most network devices won't support this feature and will set this
325 * function pointer to NULL, which is equivalent to returning EOPNOTSUPP.
326 */
327 int (*set_miimon_interval)(struct netdev *netdev, long long int interval);
328
329 /* Retrieves current device stats for 'netdev' into 'stats'.
330 *
331 * A network device that supports some statistics but not others, it should
332 * set the values of the unsupported statistics to all-1-bits
333 * (UINT64_MAX). */
334 int (*get_stats)(const struct netdev *netdev, struct netdev_stats *);
335
336 /* Sets the device stats for 'netdev' to 'stats'.
337 *
338 * Most network devices won't support this feature and will set this
339 * function pointer to NULL, which is equivalent to returning EOPNOTSUPP.
340 *
341 * Some network devices might only allow setting their stats to 0. */
342 int (*set_stats)(struct netdev *netdev, const struct netdev_stats *);
343
344 /* Stores the features supported by 'netdev' into each of '*current',
345 * '*advertised', '*supported', and '*peer'. Each value is a bitmap of
346 * NETDEV_F_* bits.
347 *
348 * This function may be set to null if it would always return EOPNOTSUPP.
349 */
350 int (*get_features)(const struct netdev *netdev,
351 enum netdev_features *current,
352 enum netdev_features *advertised,
353 enum netdev_features *supported,
354 enum netdev_features *peer);
355
356 /* Set the features advertised by 'netdev' to 'advertise', which is a
357 * set of NETDEV_F_* bits.
358 *
359 * This function may be set to null for a network device that does not
360 * support configuring advertisements. */
361 int (*set_advertisements)(struct netdev *netdev,
362 enum netdev_features advertise);
363
364 /* Attempts to set input rate limiting (policing) policy, such that up to
365 * 'kbits_rate' kbps of traffic is accepted, with a maximum accumulative
366 * burst size of 'kbits' kb.
367 *
368 * This function may be set to null if policing is not supported. */
369 int (*set_policing)(struct netdev *netdev, unsigned int kbits_rate,
370 unsigned int kbits_burst);
371
372 /* Adds to 'types' all of the forms of QoS supported by 'netdev', or leaves
373 * it empty if 'netdev' does not support QoS. Any names added to 'types'
374 * should be documented as valid for the "type" column in the "QoS" table
375 * in vswitchd/vswitch.xml (which is built as ovs-vswitchd.conf.db(8)).
376 *
377 * Every network device must support disabling QoS with a type of "", but
378 * this function must not add "" to 'types'.
379 *
380 * The caller is responsible for initializing 'types' (e.g. with
381 * sset_init()) before calling this function. The caller retains ownership
382 * of 'types'.
383 *
384 * May be NULL if 'netdev' does not support QoS at all. */
385 int (*get_qos_types)(const struct netdev *netdev, struct sset *types);
386
387 /* Queries 'netdev' for its capabilities regarding the specified 'type' of
388 * QoS. On success, initializes 'caps' with the QoS capabilities.
389 *
390 * Should return EOPNOTSUPP if 'netdev' does not support 'type'. May be
391 * NULL if 'netdev' does not support QoS at all. */
392 int (*get_qos_capabilities)(const struct netdev *netdev,
393 const char *type,
394 struct netdev_qos_capabilities *caps);
395
396 /* Queries 'netdev' about its currently configured form of QoS. If
397 * successful, stores the name of the current form of QoS into '*typep'
398 * and any details of configuration as string key-value pairs in
399 * 'details'.
400 *
401 * A '*typep' of "" indicates that QoS is currently disabled on 'netdev'.
402 *
403 * The caller initializes 'details' before calling this function. The
404 * caller takes ownership of the string key-values pairs added to
405 * 'details'.
406 *
407 * The netdev retains ownership of '*typep'.
408 *
409 * '*typep' will be one of the types returned by netdev_get_qos_types() for
410 * 'netdev'. The contents of 'details' should be documented as valid for
411 * '*typep' in the "other_config" column in the "QoS" table in
412 * vswitchd/vswitch.xml (which is built as ovs-vswitchd.conf.db(8)).
413 *
414 * May be NULL if 'netdev' does not support QoS at all. */
415 int (*get_qos)(const struct netdev *netdev,
416 const char **typep, struct smap *details);
417
418 /* Attempts to reconfigure QoS on 'netdev', changing the form of QoS to
419 * 'type' with details of configuration from 'details'.
420 *
421 * On error, the previous QoS configuration is retained.
422 *
423 * When this function changes the type of QoS (not just 'details'), this
424 * also resets all queue configuration for 'netdev' to their defaults
425 * (which depend on the specific type of QoS). Otherwise, the queue
426 * configuration for 'netdev' is unchanged.
427 *
428 * 'type' should be "" (to disable QoS) or one of the types returned by
429 * netdev_get_qos_types() for 'netdev'. The contents of 'details' should
430 * be documented as valid for the given 'type' in the "other_config" column
431 * in the "QoS" table in vswitchd/vswitch.xml (which is built as
432 * ovs-vswitchd.conf.db(8)).
433 *
434 * May be NULL if 'netdev' does not support QoS at all. */
435 int (*set_qos)(struct netdev *netdev,
436 const char *type, const struct smap *details);
437
438 /* Queries 'netdev' for information about the queue numbered 'queue_id'.
439 * If successful, adds that information as string key-value pairs to
440 * 'details'. Returns 0 if successful, otherwise a positive errno value.
441 *
442 * Should return EINVAL if 'queue_id' is greater than or equal to the
443 * number of supported queues (as reported in the 'n_queues' member of
444 * struct netdev_qos_capabilities by 'get_qos_capabilities').
445 *
446 * The caller initializes 'details' before calling this function. The
447 * caller takes ownership of the string key-values pairs added to
448 * 'details'.
449 *
450 * The returned contents of 'details' should be documented as valid for the
451 * given 'type' in the "other_config" column in the "Queue" table in
452 * vswitchd/vswitch.xml (which is built as ovs-vswitchd.conf.db(8)).
453 */
454 int (*get_queue)(const struct netdev *netdev,
455 unsigned int queue_id, struct smap *details);
456
457 /* Configures the queue numbered 'queue_id' on 'netdev' with the key-value
458 * string pairs in 'details'. The contents of 'details' should be
459 * documented as valid for the given 'type' in the "other_config" column in
460 * the "Queue" table in vswitchd/vswitch.xml (which is built as
461 * ovs-vswitchd.conf.db(8)). Returns 0 if successful, otherwise a positive
462 * errno value. On failure, the given queue's configuration should be
463 * unmodified.
464 *
465 * Should return EINVAL if 'queue_id' is greater than or equal to the
466 * number of supported queues (as reported in the 'n_queues' member of
467 * struct netdev_qos_capabilities by 'get_qos_capabilities'), or if
468 * 'details' is invalid for the type of queue.
469 *
470 * This function does not modify 'details', and the caller retains
471 * ownership of it.
472 *
473 * May be NULL if 'netdev' does not support QoS at all. */
474 int (*set_queue)(struct netdev *netdev,
475 unsigned int queue_id, const struct smap *details);
476
477 /* Attempts to delete the queue numbered 'queue_id' from 'netdev'.
478 *
479 * Should return EINVAL if 'queue_id' is greater than or equal to the
480 * number of supported queues (as reported in the 'n_queues' member of
481 * struct netdev_qos_capabilities by 'get_qos_capabilities'). Should
482 * return EOPNOTSUPP if 'queue_id' is valid but may not be deleted (e.g. if
483 * 'netdev' has a fixed set of queues with the current QoS mode).
484 *
485 * May be NULL if 'netdev' does not support QoS at all, or if all of its
486 * QoS modes have fixed sets of queues. */
487 int (*delete_queue)(struct netdev *netdev, unsigned int queue_id);
488
489 /* Obtains statistics about 'queue_id' on 'netdev'. Fills 'stats' with the
490 * queue's statistics. May set individual members of 'stats' to all-1-bits
491 * if the statistic is unavailable.
492 *
493 * May be NULL if 'netdev' does not support QoS at all. */
494 int (*get_queue_stats)(const struct netdev *netdev, unsigned int queue_id,
495 struct netdev_queue_stats *stats);
496
497 /* Attempts to begin dumping the queues in 'netdev'. On success, returns 0
498 * and initializes '*statep' with any data needed for iteration. On
499 * failure, returns a positive errno value.
500 *
501 * May be NULL if 'netdev' does not support QoS at all. */
502 int (*queue_dump_start)(const struct netdev *netdev, void **statep);
503
504 /* Attempts to retrieve another queue from 'netdev' for 'state', which was
505 * initialized by a successful call to the 'queue_dump_start' function for
506 * 'netdev'. On success, stores a queue ID into '*queue_id' and fills
507 * 'details' with the configuration of the queue with that ID. Returns EOF
508 * if the last queue has been dumped, or a positive errno value on error.
509 * This function will not be called again once it returns nonzero once for
510 * a given iteration (but the 'queue_dump_done' function will be called
511 * afterward).
512 *
513 * The caller initializes and clears 'details' before calling this
514 * function. The caller takes ownership of the string key-values pairs
515 * added to 'details'.
516 *
517 * The returned contents of 'details' should be documented as valid for the
518 * given 'type' in the "other_config" column in the "Queue" table in
519 * vswitchd/vswitch.xml (which is built as ovs-vswitchd.conf.db(8)).
520 *
521 * May be NULL if 'netdev' does not support QoS at all. */
522 int (*queue_dump_next)(const struct netdev *netdev, void *state,
523 unsigned int *queue_id, struct smap *details);
524
525 /* Releases resources from 'netdev' for 'state', which was initialized by a
526 * successful call to the 'queue_dump_start' function for 'netdev'.
527 *
528 * May be NULL if 'netdev' does not support QoS at all. */
529 int (*queue_dump_done)(const struct netdev *netdev, void *state);
530
531 /* Iterates over all of 'netdev''s queues, calling 'cb' with the queue's
532 * ID, its statistics, and the 'aux' specified by the caller. The order of
533 * iteration is unspecified, but (when successful) each queue must be
534 * visited exactly once.
535 *
536 * 'cb' will not modify or free the statistics passed in. */
537 int (*dump_queue_stats)(const struct netdev *netdev,
538 void (*cb)(unsigned int queue_id,
539 struct netdev_queue_stats *,
540 void *aux),
541 void *aux);
542
543 /* If 'netdev' has an assigned IPv4 address, sets '*address' to that
544 * address and '*netmask' to the associated netmask.
545 *
546 * The following error values have well-defined meanings:
547 *
548 * - EADDRNOTAVAIL: 'netdev' has no assigned IPv4 address.
549 *
550 * - EOPNOTSUPP: No IPv4 network stack attached to 'netdev'.
551 *
552 * This function may be set to null if it would always return EOPNOTSUPP
553 * anyhow. */
554 int (*get_in4)(const struct netdev *netdev, struct in_addr *address,
555 struct in_addr *netmask);
556
557 /* Assigns 'addr' as 'netdev''s IPv4 address and 'mask' as its netmask. If
558 * 'addr' is INADDR_ANY, 'netdev''s IPv4 address is cleared.
559 *
560 * This function may be set to null if it would always return EOPNOTSUPP
561 * anyhow. */
562 int (*set_in4)(struct netdev *netdev, struct in_addr addr,
563 struct in_addr mask);
564
565 /* If 'netdev' has an assigned IPv6 address, sets '*in6' to that address.
566 *
567 * The following error values have well-defined meanings:
568 *
569 * - EADDRNOTAVAIL: 'netdev' has no assigned IPv6 address.
570 *
571 * - EOPNOTSUPP: No IPv6 network stack attached to 'netdev'.
572 *
573 * This function may be set to null if it would always return EOPNOTSUPP
574 * anyhow. */
575 int (*get_in6)(const struct netdev *netdev, struct in6_addr *in6);
576
577 /* Adds 'router' as a default IP gateway for the TCP/IP stack that
578 * corresponds to 'netdev'.
579 *
580 * This function may be set to null if it would always return EOPNOTSUPP
581 * anyhow. */
582 int (*add_router)(struct netdev *netdev, struct in_addr router);
583
584 /* Looks up the next hop for 'host'. If successful, stores the next hop
585 * gateway's address (0 if 'host' is on a directly connected network) in
586 * '*next_hop' and a copy of the name of the device to reach 'host' in
587 * '*netdev_name', and returns 0. The caller is responsible for freeing
588 * '*netdev_name' (by calling free()).
589 *
590 * This function may be set to null if it would always return EOPNOTSUPP
591 * anyhow. */
592 int (*get_next_hop)(const struct in_addr *host, struct in_addr *next_hop,
593 char **netdev_name);
594
595 /* Retrieves driver information of the device.
596 *
597 * Populates 'smap' with key-value pairs representing the status of the
598 * device. 'smap' is a set of key-value string pairs representing netdev
599 * type specific information. For more information see
600 * ovs-vswitchd.conf.db(5).
601 *
602 * The caller is responsible for destroying 'smap' and its data.
603 *
604 * This function may be set to null if it would always return EOPNOTSUPP
605 * anyhow. */
606 int (*get_status)(const struct netdev *netdev, struct smap *smap);
607
608 /* Looks up the ARP table entry for 'ip' on 'netdev' and stores the
609 * corresponding MAC address in 'mac'. A return value of ENXIO, in
610 * particular, indicates that there is no ARP table entry for 'ip' on
611 * 'netdev'.
612 *
613 * This function may be set to null if it would always return EOPNOTSUPP
614 * anyhow. */
615 int (*arp_lookup)(const struct netdev *netdev, ovs_be32 ip,
616 uint8_t mac[6]);
617
618 /* Retrieves the current set of flags on 'netdev' into '*old_flags'. Then,
619 * turns off the flags that are set to 1 in 'off' and turns on the flags
620 * that are set to 1 in 'on'. (No bit will be set to 1 in both 'off' and
621 * 'on'; that is, off & on == 0.)
622 *
623 * This function may be invoked from a signal handler. Therefore, it
624 * should not do anything that is not signal-safe (such as logging). */
625 int (*update_flags)(struct netdev *netdev, enum netdev_flags off,
626 enum netdev_flags on, enum netdev_flags *old_flags);
627
628 /* ## -------------------- ## */
629 /* ## netdev_rxq Functions ## */
630 /* ## -------------------- ## */
631
632 /* If a particular netdev class does not support receiving packets, all these
633 * function pointers must be NULL. */
634
635 /* Life-cycle functions for a netdev_rxq. See the large comment above on
636 * struct netdev_class. */
637 struct netdev_rxq *(*rxq_alloc)(void);
638 int (*rxq_construct)(struct netdev_rxq *);
639 void (*rxq_destruct)(struct netdev_rxq *);
640 void (*rxq_dealloc)(struct netdev_rxq *);
641
642 /* Attempts to receive batch of packets from 'rx' and place array of pointers
643 * into '*pkt'. netdev is responsible for allocating buffers.
644 * '*cnt' points to packet count for given batch. Once packets are returned
645 * to caller, netdev should give up ownership of ofpbuf data.
646 *
647 * Implementations should allocate buffer with DP_NETDEV_HEADROOM headroom
648 * and add a VLAN header which is obtained out-of-band to the packet.
649 *
650 * Caller is expected to pass array of size MAX_RX_BATCH.
651 * This function may be set to null if it would always return EOPNOTSUPP
652 * anyhow. */
653 int (*rxq_recv)(struct netdev_rxq *rx, struct ofpbuf **pkt, int *cnt);
654
655 /* Registers with the poll loop to wake up from the next call to
656 * poll_block() when a packet is ready to be received with netdev_rxq_recv()
657 * on 'rx'. */
658 void (*rxq_wait)(struct netdev_rxq *rx);
659
660 /* Discards all packets waiting to be received from 'rx'. */
661 int (*rxq_drain)(struct netdev_rxq *rx);
662 };
663
664 int netdev_register_provider(const struct netdev_class *);
665 int netdev_unregister_provider(const char *type);
666
667 extern const struct netdev_class netdev_linux_class;
668 extern const struct netdev_class netdev_internal_class;
669 extern const struct netdev_class netdev_tap_class;
670 #if defined(__FreeBSD__) || defined(__NetBSD__)
671 extern const struct netdev_class netdev_bsd_class;
672 #endif
673
674 #ifdef __cplusplus
675 }
676 #endif
677
678 #endif /* netdev.h */