31
31
/* A network device (e.g. an Ethernet device).
33
* This structure should be treated as opaque by network device
33
* Network device implementations should treat this structure as opaque. */
36
35
char *name; /* Name of network device. */
37
36
const struct netdev_class *netdev_class; /* Functions to control
39
38
int ref_cnt; /* Times this devices was opened. */
40
39
struct shash_node *node; /* Pointer to element in global map. */
40
struct list saved_flags_list; /* Contains "struct netdev_saved_flags". */
43
void netdev_dev_init(struct netdev_dev *, const char *name,
44
const struct netdev_class *);
45
void netdev_dev_uninit(struct netdev_dev *, bool destroy);
46
const char *netdev_dev_get_type(const struct netdev_dev *);
47
const struct netdev_class *netdev_dev_get_class(const struct netdev_dev *);
48
const char *netdev_dev_get_name(const struct netdev_dev *);
49
struct netdev_dev *netdev_dev_from_name(const char *name);
50
void netdev_dev_get_devices(const struct netdev_class *,
51
struct shash *device_list);
43
void netdev_init(struct netdev *, const char *name,
44
const struct netdev_class *);
45
void netdev_uninit(struct netdev *, bool destroy);
46
const char *netdev_get_type(const struct netdev *);
47
const struct netdev_class *netdev_get_class(const struct netdev *);
48
const char *netdev_get_name(const struct netdev *);
49
struct netdev *netdev_from_name(const char *name);
50
void netdev_get_devices(const struct netdev_class *,
51
struct shash *device_list);
53
static inline void netdev_dev_assert_class(const struct netdev_dev *netdev_dev,
53
static inline void netdev_assert_class(const struct netdev *netdev,
54
54
const struct netdev_class *class_)
56
ovs_assert(netdev_dev->netdev_class == class_);
59
/* A instance of an open network device.
61
* This structure should be treated as opaque by network device
64
struct netdev_dev *netdev_dev; /* Parent netdev_dev. */
65
struct list node; /* Element in global list. */
67
enum netdev_flags save_flags; /* Initial device flags. */
68
enum netdev_flags changed_flags; /* Flags that we changed. */
71
void netdev_init(struct netdev *, struct netdev_dev *);
72
void netdev_uninit(struct netdev *, bool close);
73
struct netdev_dev *netdev_get_dev(const struct netdev *);
75
static inline void netdev_assert_class(const struct netdev *netdev,
76
const struct netdev_class *netdev_class)
78
netdev_dev_assert_class(netdev_get_dev(netdev), netdev_class);
56
ovs_assert(netdev->netdev_class == class_);
81
59
/* Network device class structure, to be defined by each implementation of a
112
90
void (*wait)(void);
114
92
/* Attempts to create a network device named 'name' in 'netdev_class'. On
115
* success sets 'netdev_devp' to the newly created device. */
93
* success sets 'netdevp' to the newly created device. */
116
94
int (*create)(const struct netdev_class *netdev_class, const char *name,
117
struct netdev_dev **netdev_devp);
95
struct netdev **netdevp);
119
/* Destroys 'netdev_dev'.
121
99
* Netdev devices maintain a reference count that is incremented on
122
* netdev_open() and decremented on netdev_close(). If 'netdev_dev'
100
* netdev_open() and decremented on netdev_close(). If 'netdev'
123
101
* has a non-zero reference count, then this function will not be
125
void (*destroy)(struct netdev_dev *netdev_dev);
103
void (*destroy)(struct netdev *netdev);
127
/* Fetches the device 'netdev_dev''s configuration, storing it in 'args'.
105
/* Fetches the device 'netdev''s configuration, storing it in 'args'.
128
106
* The caller owns 'args' and pre-initializes it to an empty smap.
130
108
* If this netdev class does not have any configuration options, this may
131
109
* be a null pointer. */
132
int (*get_config)(struct netdev_dev *netdev_dev, struct smap *args);
110
int (*get_config)(const struct netdev *netdev, struct smap *args);
134
/* Changes the device 'netdev_dev''s configuration to 'args'.
112
/* Changes the device 'netdev''s configuration to 'args'.
136
114
* If this netdev class does not support configuration, this may be a null
138
int (*set_config)(struct netdev_dev *netdev_dev, const struct smap *args);
116
int (*set_config)(struct netdev *netdev, const struct smap *args);
140
/* Returns the tunnel configuration of 'netdev_dev'. If 'netdev_dev' is
118
/* Returns the tunnel configuration of 'netdev'. If 'netdev' is
141
119
* not a tunnel, returns null.
143
121
* If this function would always return null, it may be null instead. */
144
122
const struct netdev_tunnel_config *
145
(*get_tunnel_config)(const struct netdev_dev *netdev_dev);
147
/* Attempts to open a network device. On success, sets 'netdevp'
148
* to the new network device. */
149
int (*open)(struct netdev_dev *netdev_dev, struct netdev **netdevp);
151
/* Closes 'netdev'. */
152
void (*close)(struct netdev *netdev);
154
/* ## ----------------- ## */
155
/* ## Receiving Packets ## */
156
/* ## ----------------- ## */
158
/* The network provider interface is mostly used for inspecting and configuring
159
* device "metadata", not for sending and receiving packets directly. It may
160
* be impractical to implement these functions on some operating systems and
161
* hardware. These functions may all be NULL in such cases.
163
* (However, the "dpif-netdev" implementation, which is the easiest way to
164
* integrate Open vSwitch with a new operating system or hardware, does require
165
* the ability to receive packets.) */
167
/* Attempts to set up 'netdev' for receiving packets with ->recv().
168
* Returns 0 if successful, otherwise a positive errno value. Return
123
(*get_tunnel_config)(const struct netdev *netdev);
125
/* Attempts to open a netdev_rx for receiving packets from 'netdev'.
126
* Returns 0 if successful, otherwise a positive errno value. Returns
169
127
* EOPNOTSUPP to indicate that the network device does not implement packet
170
128
* reception through this interface. This function may be set to null if
171
129
* it would always return EOPNOTSUPP anyhow. (This will prevent the
172
130
* network device from being usefully used by the netdev-based "userspace
174
int (*listen)(struct netdev *netdev);
176
/* Attempts to receive a packet from 'netdev' into the 'size' bytes in
177
* 'buffer'. If successful, returns the number of bytes in the received
178
* packet, otherwise a negative errno value. Returns -EAGAIN immediately
179
* if no packet is ready to be received.
181
* Returns -EMSGSIZE, and discards the packet, if the received packet is
182
* longer than 'size' bytes.
184
* This function can only be expected to return a packet if ->listen() has
185
* been called successfully.
187
* May be null if not needed, such as for a network device that does not
188
* implement packet reception through the 'recv' member function. */
189
int (*recv)(struct netdev *netdev, void *buffer, size_t size);
191
/* Registers with the poll loop to wake up from the next call to
192
* poll_block() when a packet is ready to be received with netdev_recv() on
195
* May be null if not needed, such as for a network device that does not
196
* implement packet reception through the 'recv' member function. */
197
void (*recv_wait)(struct netdev *netdev);
199
/* Discards all packets waiting to be received from 'netdev'.
201
* May be null if not needed, such as for a network device that does not
202
* implement packet reception through the 'recv' member function. */
203
int (*drain)(struct netdev *netdev);
133
* On success, the implementation must set '*rxp' to a 'netdev_rx' for
134
* 'netdev' that it has already initialized (with netdev_rx_init()). */
135
int (*rx_open)(struct netdev *netdev, struct netdev_rx **rxp);
205
137
/* Sends the 'size'-byte packet in 'buffer' on 'netdev'. Returns 0 if
206
138
* successful, otherwise a positive errno value. Returns EAGAIN without
207
139
* blocking if the packet cannot be queued immediately. Returns EMSGSIZE
593
525
* change, although implementations should try to avoid this. */
594
526
unsigned int (*change_seq)(const struct netdev *netdev);
529
/* A data structure for capturing packets received by a network device.
531
* This structure should be treated as opaque by network device
532
* implementations. */
534
const struct netdev_rx_class *rx_class;
535
struct netdev *netdev;
538
void netdev_rx_init(struct netdev_rx *, struct netdev *,
539
const struct netdev_rx_class *);
540
void netdev_rx_uninit(struct netdev_rx *);
541
struct netdev *netdev_rx_get_netdev(const struct netdev_rx *);
543
struct netdev_rx_class {
545
void (*destroy)(struct netdev_rx *rx);
547
/* Attempts to receive a packet from 'rx' into the 'size' bytes in
548
* 'buffer'. If successful, returns the number of bytes in the received
549
* packet, otherwise a negative errno value. Returns -EAGAIN immediately
550
* if no packet is ready to be received.
552
* Must return -EMSGSIZE, and discard the packet, if the received packet
553
* is longer than 'size' bytes. */
554
int (*recv)(struct netdev_rx *rx, void *buffer, size_t size);
556
/* Registers with the poll loop to wake up from the next call to
557
* poll_block() when a packet is ready to be received with netdev_rx_recv()
559
void (*wait)(struct netdev_rx *rx);
561
/* Discards all packets waiting to be received from 'rx'. */
562
int (*drain)(struct netdev_rx *rx);
565
static inline void netdev_rx_assert_class(const struct netdev_rx *rx,
566
const struct netdev_rx_class *class_)
568
ovs_assert(rx->rx_class == class_);
597
571
int netdev_register_provider(const struct netdev_class *);
598
572
int netdev_unregister_provider(const char *type);