net/core/dev_api.c

Source file repositories/reference/linux-study-clean/net/core/dev_api.c

File Facts

System
Linux kernel
Corpus path
net/core/dev_api.c
Extension
.c
Size
8979 bytes
Lines
386
Domain
Networking Core
Bucket
Sockets, Protocols, Packet Path, And Network Policy
Inferred role
Networking Core: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.

Dependency Surface

Detected Declarations

Annotated Snippet

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_promiscuity() - update promiscuity count on a device
 * @dev: device
 * @inc: modifier
 *
 * Add or remove promiscuity from a device. While the count in the device
 * remains above zero the interface remains promiscuous. Once it hits zero
 * the device reverts back to normal filtering operation. A negative inc
 * value is used to drop promiscuity on the device.
 * Return 0 if successful or a negative errno code on error.
 */
int dev_set_promiscuity(struct net_device *dev, int inc)
{
	int ret;

	netdev_lock_ops(dev);
	ret = netif_set_promiscuity(dev, inc);
	netif_rx_mode_sync(dev);
	netdev_unlock_ops(dev);

	return ret;
}
EXPORT_SYMBOL(dev_set_promiscuity);

/**
 * 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);
	netif_rx_mode_sync(dev);
	netdev_unlock_ops(dev);

Annotation

Implementation Notes