// SPDX-License-Identifier: GPL-2.0-or-later12#include <linux/netdevice.h>3#include <net/netdev_lock.h>45#include "dev.h"67/**8* dev_change_name() - change name of a device9* @dev: device10* @newname: name (or format string) must be at least IFNAMSIZ11*12* Change name of a device, can pass format strings "eth%d".13* for wildcarding.14*15* Return: 0 on success, -errno on failure.16*/17int dev_change_name(struct net_device *dev, const char *newname)18{19int ret;2021netdev_lock_ops(dev);22ret = netif_change_name(dev, newname);23netdev_unlock_ops(dev);2425return ret;26}2728/**29* dev_set_alias() - change ifalias of a device30* @dev: device31* @alias: name up to IFALIASZ32* @len: limit of bytes to copy from info33*34* Set ifalias for a device.35*36* Return: 0 on success, -errno on failure.37*/38int dev_set_alias(struct net_device *dev, const char *alias, size_t len)39{40int ret;4142netdev_lock_ops(dev);43ret = netif_set_alias(dev, alias, len);44netdev_unlock_ops(dev);4546return ret;47}48EXPORT_SYMBOL(dev_set_alias);4950/**51* dev_change_flags() - change device settings52* @dev: device53* @flags: device state flags54* @extack: netlink extended ack55*56* Change settings on device based state flags. The flags are57* in the userspace exported format.58*59* Return: 0 on success, -errno on failure.60*/61int dev_change_flags(struct net_device *dev, unsigned int flags,62struct netlink_ext_ack *extack)63{64int ret;6566netdev_lock_ops(dev);67ret = netif_change_flags(dev, flags, extack);68netdev_unlock_ops(dev);6970return ret;71}72EXPORT_SYMBOL(dev_change_flags);7374/**75* dev_set_group() - change group this device belongs to76* @dev: device77* @new_group: group this device should belong to78*/79void dev_set_group(struct net_device *dev, int new_group)80{81netdev_lock_ops(dev);82netif_set_group(dev, new_group);83netdev_unlock_ops(dev);84}8586int dev_set_mac_address_user(struct net_device *dev,87struct sockaddr_storage *ss,88struct netlink_ext_ack *extack)89{90int ret;9192down_write(&dev_addr_sem);93netdev_lock_ops(dev);94ret = netif_set_mac_address(dev, ss, extack);95netdev_unlock_ops(dev);96up_write(&dev_addr_sem);9798return ret;99}100EXPORT_SYMBOL(dev_set_mac_address_user);101102/**103* dev_change_net_namespace() - move device to different nethost namespace104* @dev: device105* @net: network namespace106* @pat: If not NULL name pattern to try if the current device name107* is already taken in the destination network namespace.108*109* This function shuts down a device interface and moves it110* to a new network namespace. On success 0 is returned, on111* a failure a netagive errno code is returned.112*113* Callers must hold the rtnl semaphore.114*115* Return: 0 on success, -errno on failure.116*/117int dev_change_net_namespace(struct net_device *dev, struct net *net,118const char *pat)119{120return __dev_change_net_namespace(dev, net, pat, 0, NULL);121}122EXPORT_SYMBOL_GPL(dev_change_net_namespace);123124/**125* dev_change_carrier() - change device carrier126* @dev: device127* @new_carrier: new value128*129* Change device carrier130*131* Return: 0 on success, -errno on failure.132*/133int dev_change_carrier(struct net_device *dev, bool new_carrier)134{135int ret;136137netdev_lock_ops(dev);138ret = netif_change_carrier(dev, new_carrier);139netdev_unlock_ops(dev);140141return ret;142}143144/**145* dev_change_tx_queue_len() - change TX queue length of a netdevice146* @dev: device147* @new_len: new tx queue length148*149* Return: 0 on success, -errno on failure.150*/151int dev_change_tx_queue_len(struct net_device *dev, unsigned long new_len)152{153int ret;154155netdev_lock_ops(dev);156ret = netif_change_tx_queue_len(dev, new_len);157netdev_unlock_ops(dev);158159return ret;160}161162/**163* dev_change_proto_down() - set carrier according to proto_down164* @dev: device165* @proto_down: new value166*167* Return: 0 on success, -errno on failure.168*/169int dev_change_proto_down(struct net_device *dev, bool proto_down)170{171int ret;172173netdev_lock_ops(dev);174ret = netif_change_proto_down(dev, proto_down);175netdev_unlock_ops(dev);176177return ret;178}179180/**181* dev_open() - prepare an interface for use182* @dev: device to open183* @extack: netlink extended ack184*185* Takes a device from down to up state. The device's private open186* function is invoked and then the multicast lists are loaded. Finally187* the device is moved into the up state and a %NETDEV_UP message is188* sent to the netdev notifier chain.189*190* Calling this function on an active interface is a nop. On a failure191* a negative errno code is returned.192*193* Return: 0 on success, -errno on failure.194*/195int dev_open(struct net_device *dev, struct netlink_ext_ack *extack)196{197int ret;198199netdev_lock_ops(dev);200ret = netif_open(dev, extack);201netdev_unlock_ops(dev);202203return ret;204}205EXPORT_SYMBOL(dev_open);206207/**208* dev_close() - shutdown an interface209* @dev: device to shutdown210*211* This function moves an active device into down state. A212* %NETDEV_GOING_DOWN is sent to the netdev notifier chain. The device213* is then deactivated and finally a %NETDEV_DOWN is sent to the notifier214* chain.215*/216void dev_close(struct net_device *dev)217{218netdev_lock_ops(dev);219netif_close(dev);220netdev_unlock_ops(dev);221}222EXPORT_SYMBOL(dev_close);223224int dev_eth_ioctl(struct net_device *dev,225struct ifreq *ifr, unsigned int cmd)226{227const struct net_device_ops *ops = dev->netdev_ops;228int ret = -ENODEV;229230if (!ops->ndo_eth_ioctl)231return -EOPNOTSUPP;232233netdev_lock_ops(dev);234if (netif_device_present(dev))235ret = ops->ndo_eth_ioctl(dev, ifr, cmd);236netdev_unlock_ops(dev);237238return ret;239}240EXPORT_SYMBOL(dev_eth_ioctl);241242int dev_set_mtu(struct net_device *dev, int new_mtu)243{244int ret;245246netdev_lock_ops(dev);247ret = netif_set_mtu(dev, new_mtu);248netdev_unlock_ops(dev);249250return ret;251}252EXPORT_SYMBOL(dev_set_mtu);253254/**255* dev_disable_lro() - disable Large Receive Offload on a device256* @dev: device257*258* Disable Large Receive Offload (LRO) on a net device. Must be259* called under RTNL. This is needed if received packets may be260* forwarded to another interface.261*/262void dev_disable_lro(struct net_device *dev)263{264netdev_lock_ops(dev);265netif_disable_lro(dev);266netdev_unlock_ops(dev);267}268EXPORT_SYMBOL(dev_disable_lro);269270/**271* dev_set_promiscuity() - update promiscuity count on a device272* @dev: device273* @inc: modifier274*275* Add or remove promiscuity from a device. While the count in the device276* remains above zero the interface remains promiscuous. Once it hits zero277* the device reverts back to normal filtering operation. A negative inc278* value is used to drop promiscuity on the device.279* Return 0 if successful or a negative errno code on error.280*/281int dev_set_promiscuity(struct net_device *dev, int inc)282{283int ret;284285netdev_lock_ops(dev);286ret = netif_set_promiscuity(dev, inc);287netdev_unlock_ops(dev);288289return ret;290}291EXPORT_SYMBOL(dev_set_promiscuity);292293/**294* dev_set_allmulti() - update allmulti count on a device295* @dev: device296* @inc: modifier297*298* Add or remove reception of all multicast frames to a device. While the299* count in the device remains above zero the interface remains listening300* to all interfaces. Once it hits zero the device reverts back to normal301* filtering operation. A negative @inc value is used to drop the counter302* when releasing a resource needing all multicasts.303*304* Return: 0 on success, -errno on failure.305*/306307int dev_set_allmulti(struct net_device *dev, int inc)308{309int ret;310311netdev_lock_ops(dev);312ret = netif_set_allmulti(dev, inc, true);313netdev_unlock_ops(dev);314315return ret;316}317EXPORT_SYMBOL(dev_set_allmulti);318319/**320* dev_set_mac_address() - change Media Access Control Address321* @dev: device322* @ss: new address323* @extack: netlink extended ack324*325* Change the hardware (MAC) address of the device326*327* Return: 0 on success, -errno on failure.328*/329int dev_set_mac_address(struct net_device *dev, struct sockaddr_storage *ss,330struct netlink_ext_ack *extack)331{332int ret;333334netdev_lock_ops(dev);335ret = netif_set_mac_address(dev, ss, extack);336netdev_unlock_ops(dev);337338return ret;339}340EXPORT_SYMBOL(dev_set_mac_address);341342int dev_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf)343{344int ret;345346netdev_lock_ops(dev);347ret = netif_xdp_propagate(dev, bpf);348netdev_unlock_ops(dev);349350return ret;351}352EXPORT_SYMBOL_GPL(dev_xdp_propagate);353354/**355* netdev_state_change() - device changes state356* @dev: device to cause notification357*358* Called to indicate a device has changed state. This function calls359* the notifier chains for netdev_chain and sends a NEWLINK message360* to the routing socket.361*/362void netdev_state_change(struct net_device *dev)363{364netdev_lock_ops(dev);365netif_state_change(dev);366netdev_unlock_ops(dev);367}368EXPORT_SYMBOL(netdev_state_change);369370int dev_set_threaded(struct net_device *dev,371enum netdev_napi_threaded threaded)372{373int ret;374375netdev_lock(dev);376ret = netif_set_threaded(dev, threaded);377netdev_unlock(dev);378379return ret;380}381EXPORT_SYMBOL(dev_set_threaded);382383384