drivers/net/veth.c
Source file repositories/reference/linux-study-clean/drivers/net/veth.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/veth.c- Extension
.c- Size
- 48398 bytes
- Lines
- 2011
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/netdevice.hlinux/slab.hlinux/ethtool.hlinux/etherdevice.hlinux/u64_stats_sync.hnet/rtnetlink.hnet/dst.hnet/netdev_lock.hnet/xfrm.hnet/xdp.hlinux/veth.hlinux/module.hlinux/bpf.hlinux/filter.hlinux/ptr_ring.hlinux/bpf_trace.hlinux/net_tstamp.hlinux/skbuff_ref.hnet/page_pool/helpers.h
Detected Declarations
struct veth_statsstruct veth_rq_statsstruct veth_rqstruct veth_privstruct veth_xdp_tx_bqstruct veth_q_stat_descstruct veth_xdp_bufffunction veth_get_link_ksettingsfunction veth_get_drvinfofunction veth_get_stringsfunction veth_get_sset_countfunction veth_get_page_pool_statsfunction veth_get_ethtool_statsfunction veth_get_channelsfunction veth_is_xdp_framefunction veth_ptr_freefunction __veth_xdp_flushfunction napi_schedule_prepfunction veth_xdp_rxfunction veth_forward_skbfunction veth_skb_is_eligible_for_grofunction veth_xmitfunction veth_stats_rxfunction veth_get_stats64function veth_set_multicast_listfunction veth_xdp_xmitfunction veth_ndo_xdp_xmitfunction veth_xdp_flush_bqfunction veth_xdp_flushfunction veth_xdp_txfunction veth_xdp_rcv_bulk_skbfunction veth_xdp_getfunction veth_convert_skb_to_xdp_bufffunction veth_xdp_rcvfunction veth_pollfunction veth_create_page_poolfunction __veth_napi_enable_rangefunction __veth_napi_enablefunction veth_napi_del_rangefunction veth_napi_delfunction veth_gro_requestedfunction veth_enable_xdp_rangefunction veth_disable_xdp_rangefunction veth_enable_xdpfunction veth_disable_xdpfunction veth_napi_enable_rangefunction veth_napi_enablefunction veth_disable_range_safe
Annotated Snippet
static const struct net_device_ops veth_netdev_ops = {
.ndo_init = veth_dev_init,
.ndo_open = veth_open,
.ndo_stop = veth_close,
.ndo_start_xmit = veth_xmit,
.ndo_get_stats64 = veth_get_stats64,
.ndo_set_rx_mode = veth_set_multicast_list,
.ndo_set_mac_address = eth_mac_addr,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = veth_poll_controller,
#endif
.ndo_get_iflink = veth_get_iflink,
.ndo_fix_features = veth_fix_features,
.ndo_set_features = veth_set_features,
.ndo_features_check = passthru_features_check,
.ndo_set_rx_headroom = veth_set_rx_headroom,
.ndo_bpf = veth_xdp,
.ndo_xdp_xmit = veth_ndo_xdp_xmit,
.ndo_get_peer_dev = veth_peer_dev,
};
static const struct xdp_metadata_ops veth_xdp_metadata_ops = {
.xmo_rx_timestamp = veth_xdp_rx_timestamp,
.xmo_rx_hash = veth_xdp_rx_hash,
.xmo_rx_vlan_tag = veth_xdp_rx_vlan_tag,
};
#define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HW_CSUM | \
NETIF_F_RXCSUM | NETIF_F_SCTP_CRC | NETIF_F_HIGHDMA | \
NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ENCAP_ALL | \
NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX | \
NETIF_F_HW_VLAN_STAG_TX | NETIF_F_HW_VLAN_STAG_RX )
static void veth_setup(struct net_device *dev)
{
ether_setup(dev);
dev->priv_flags &= ~IFF_TX_SKB_SHARING;
dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
dev->priv_flags |= IFF_NO_QUEUE;
dev->priv_flags |= IFF_PHONY_HEADROOM;
dev->priv_flags |= IFF_DISABLE_NETPOLL;
dev->lltx = true;
dev->netdev_ops = &veth_netdev_ops;
dev->xdp_metadata_ops = &veth_xdp_metadata_ops;
dev->ethtool_ops = &veth_ethtool_ops;
dev->features |= VETH_FEATURES;
dev->vlan_features = dev->features &
~(NETIF_F_HW_VLAN_CTAG_TX |
NETIF_F_HW_VLAN_STAG_TX |
NETIF_F_HW_VLAN_CTAG_RX |
NETIF_F_HW_VLAN_STAG_RX);
dev->needs_free_netdev = true;
dev->priv_destructor = veth_dev_free;
dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
dev->max_mtu = ETH_MAX_MTU;
dev->hw_features = VETH_FEATURES;
dev->hw_enc_features = VETH_FEATURES;
dev->mpls_features = NETIF_F_HW_CSUM | NETIF_F_GSO_SOFTWARE;
netif_set_tso_max_size(dev, GSO_MAX_SIZE);
}
/*
* netlink interface
*/
static int veth_validate(struct nlattr *tb[], struct nlattr *data[],
struct netlink_ext_ack *extack)
{
if (tb[IFLA_ADDRESS]) {
if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
return -EINVAL;
if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
return -EADDRNOTAVAIL;
}
if (tb[IFLA_MTU]) {
if (!is_valid_veth_mtu(nla_get_u32(tb[IFLA_MTU])))
return -EINVAL;
}
return 0;
}
static struct rtnl_link_ops veth_link_ops;
static void veth_disable_gro(struct net_device *dev)
{
dev->features &= ~NETIF_F_GRO;
dev->wanted_features &= ~NETIF_F_GRO;
Annotation
- Immediate include surface: `linux/netdevice.h`, `linux/slab.h`, `linux/ethtool.h`, `linux/etherdevice.h`, `linux/u64_stats_sync.h`, `net/rtnetlink.h`, `net/dst.h`, `net/netdev_lock.h`.
- Detected declarations: `struct veth_stats`, `struct veth_rq_stats`, `struct veth_rq`, `struct veth_priv`, `struct veth_xdp_tx_bq`, `struct veth_q_stat_desc`, `struct veth_xdp_buff`, `function veth_get_link_ksettings`, `function veth_get_drvinfo`, `function veth_get_strings`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.