1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
|
// SPDX-License-Identifier: GPL-2.0-or-later
#include <linux/netdevice.h>
#include <net/netdev_lock.h>
#include "dev.h"
/**
* dev_change_name() - change name of a device
* @dev: device
* @newname: name (or format string) must be at least IFNAMSIZ
*
* Change name of a device, can pass format strings "eth%d".
* for wildcarding.
*
* Return: 0 on success, -errno on failure.
*/
int dev_change_name(struct net_device *dev, const char *newname)
{
int ret;
netdev_lock_ops(dev);
ret = netif_change_name(dev, newname);
netdev_unlock_ops(dev);
return ret;
}
/**
* dev_set_alias() - change ifalias of a device
* @dev: device
* @alias: name up to IFALIASZ
* @len: limit of bytes to copy from info
*
* Set ifalias for a device.
*
* Return: 0 on success, -errno on failure.
*/
int dev_set_alias(struct net_device *dev, const char *alias, size_t len)
{
int ret;
netdev_lock_ops(dev);
ret = netif_set_alias(dev, alias, len);
netdev_unlock_ops(dev);
return ret;
}
EXPORT_SYMBOL(dev_set_alias);
/**
* dev_change_flags() - change device settings
* @dev: device
* @flags: device state flags
* @extack: netlink extended ack
*
* Change settings on device based state flags. The flags are
* in the userspace exported format.
*
* Return: 0 on success, -errno on failure.
*/
int dev_change_flags(struct net_device *dev, unsigned int flags,
struct netlink_ext_ack *extack)
{
int ret;
netdev_lock_ops(dev);
ret = netif_change_flags(dev, flags, extack);
netdev_unlock_ops(dev);
return ret;
}
EXPORT_SYMBOL(dev_change_flags);
/**
* dev_set_group() - change group this device belongs to
* @dev: device
* @new_group: group this device should belong to
*/
void dev_set_group(struct net_device *dev, int new_group)
{
netdev_lock_ops(dev);
netif_set_group(dev, new_group);
netdev_unlock_ops(dev);
}
int dev_set_mac_address_user(struct net_device *dev, struct sockaddr *sa,
struct netlink_ext_ack *extack)
{
int ret;
down_write(&dev_addr_sem);
netdev_lock_ops(dev);
ret = netif_set_mac_address(dev, sa, extack);
netdev_unlock_ops(dev);
up_write(&dev_addr_sem);
return ret;
}
EXPORT_SYMBOL(dev_set_mac_address_user);
/**
* dev_change_net_namespace() - move device to different nethost namespace
* @dev: device
* @net: network namespace
* @pat: If not NULL name pattern to try if the current device name
* is already taken in the destination network namespace.
*
* This function shuts down a device interface and moves it
* to a new network namespace. On success 0 is returned, on
* a failure a netagive errno code is returned.
*
* Callers must hold the rtnl semaphore.
*
* Return: 0 on success, -errno on failure.
*/
int dev_change_net_namespace(struct net_device *dev, struct net *net,
const char *pat)
{
int ret;
netdev_lock_ops(dev);
ret = netif_change_net_namespace(dev, net, pat, 0, NULL);
netdev_unlock_ops(dev);
return ret;
}
EXPORT_SYMBOL_GPL(dev_change_net_namespace);
/**
* dev_change_carrier() - change device carrier
* @dev: device
* @new_carrier: new value
*
* Change device carrier
*
* Return: 0 on success, -errno on failure.
*/
int dev_change_carrier(struct net_device *dev, bool new_carrier)
{
int ret;
netdev_lock_ops(dev);
ret = netif_change_carrier(dev, new_carrier);
netdev_unlock_ops(dev);
return ret;
}
/**
* dev_change_tx_queue_len() - change TX queue length of a netdevice
* @dev: device
* @new_len: new tx queue length
*
* Return: 0 on success, -errno on failure.
*/
int dev_change_tx_queue_len(struct net_device *dev, unsigned long new_len)
{
int ret;
netdev_lock_ops(dev);
ret = netif_change_tx_queue_len(dev, new_len);
netdev_unlock_ops(dev);
return ret;
}
/**
* dev_change_proto_down() - set carrier according to proto_down
* @dev: device
* @proto_down: new value
*
* Return: 0 on success, -errno on failure.
*/
int dev_change_proto_down(struct net_device *dev, bool proto_down)
{
int ret;
netdev_lock_ops(dev);
ret = netif_change_proto_down(dev, proto_down);
netdev_unlock_ops(dev);
return ret;
}
/**
* dev_open() - prepare an interface for use
* @dev: device to open
* @extack: netlink extended ack
*
* Takes a device from down to up state. The device's private open
* function is invoked and then the multicast lists are loaded. Finally
* the device is moved into the up state and a %NETDEV_UP message is
* sent to the netdev notifier chain.
*
* Calling this function on an active interface is a nop. On a failure
* a negative errno code is returned.
*
* Return: 0 on success, -errno on failure.
*/
int dev_open(struct net_device *dev, struct netlink_ext_ack *extack)
{
int ret;
netdev_lock_ops(dev);
ret = netif_open(dev, extack);
netdev_unlock_ops(dev);
return ret;
}
EXPORT_SYMBOL(dev_open);
/**
* dev_close() - shutdown an interface
* @dev: device to shutdown
*
* This function moves an active device into down state. A
* %NETDEV_GOING_DOWN is sent to the netdev notifier chain. The device
* is then deactivated and finally a %NETDEV_DOWN is sent to the notifier
* chain.
*/
void dev_close(struct net_device *dev)
{
netdev_lock_ops(dev);
netif_close(dev);
netdev_unlock_ops(dev);
}
EXPORT_SYMBOL(dev_close);
int dev_eth_ioctl(struct net_device *dev,
struct ifreq *ifr, unsigned int cmd)
{
const struct net_device_ops *ops = dev->netdev_ops;
int ret = -ENODEV;
if (!ops->ndo_eth_ioctl)
return -EOPNOTSUPP;
netdev_lock_ops(dev);
if (netif_device_present(dev))
ret = ops->ndo_eth_ioctl(dev, ifr, cmd);
netdev_unlock_ops(dev);
return ret;
}
EXPORT_SYMBOL(dev_eth_ioctl);
int dev_set_mtu(struct net_device *dev, int new_mtu)
{
int ret;
netdev_lock_ops(dev);
ret = netif_set_mtu(dev, new_mtu);
netdev_unlock_ops(dev);
return ret;
}
EXPORT_SYMBOL(dev_set_mtu);
/**
* dev_disable_lro() - disable Large Receive Offload on a device
* @dev: device
*
* Disable Large Receive Offload (LRO) on a net device. Must be
* called under RTNL. This is needed if received packets may be
* forwarded to another interface.
*/
void dev_disable_lro(struct net_device *dev)
{
netdev_lock_ops(dev);
netif_disable_lro(dev);
netdev_unlock_ops(dev);
}
EXPORT_SYMBOL(dev_disable_lro);
/**
* dev_set_allmulti() - update allmulti count on a device
* @dev: device
* @inc: modifier
*
* Add or remove reception of all multicast frames to a device. While the
* count in the device remains above zero the interface remains listening
* to all interfaces. Once it hits zero the device reverts back to normal
* filtering operation. A negative @inc value is used to drop the counter
* when releasing a resource needing all multicasts.
*
* Return: 0 on success, -errno on failure.
*/
int dev_set_allmulti(struct net_device *dev, int inc)
{
int ret;
netdev_lock_ops(dev);
ret = netif_set_allmulti(dev, inc, true);
netdev_unlock_ops(dev);
return ret;
}
EXPORT_SYMBOL(dev_set_allmulti);
/**
* dev_set_mac_address() - change Media Access Control Address
* @dev: device
* @sa: new address
* @extack: netlink extended ack
*
* Change the hardware (MAC) address of the device
*
* Return: 0 on success, -errno on failure.
*/
int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa,
struct netlink_ext_ack *extack)
{
int ret;
netdev_lock_ops(dev);
ret = netif_set_mac_address(dev, sa, extack);
netdev_unlock_ops(dev);
return ret;
}
EXPORT_SYMBOL(dev_set_mac_address);
int dev_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf)
{
int ret;
netdev_lock_ops(dev);
ret = netif_xdp_propagate(dev, bpf);
netdev_unlock_ops(dev);
return ret;
}
EXPORT_SYMBOL_GPL(dev_xdp_propagate);
|