drivers/net/macvlan.c
Source file repositories/reference/linux-study-clean/drivers/net/macvlan.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/macvlan.c- Extension
.c- Size
- 50023 bytes
- Lines
- 1904
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/types.hlinux/module.hlinux/init.hlinux/errno.hlinux/slab.hlinux/string.hlinux/rculist.hlinux/notifier.hlinux/netdevice.hlinux/etherdevice.hlinux/net_tstamp.hlinux/ethtool.hlinux/if_arp.hlinux/if_vlan.hlinux/if_link.hlinux/if_macvlan.hlinux/hash.hlinux/workqueue.hnet/netdev_lock.hnet/rtnetlink.hnet/xfrm.hlinux/netpoll.hlinux/phy.h
Detected Declarations
struct macvlan_portstruct macvlan_source_entrystruct macvlan_skb_cbfunction macvlan_passthrufunction macvlan_set_passthrufunction macvlan_addr_changefunction macvlan_set_addr_changefunction macvlan_clear_addr_changefunction macvlan_eth_hashfunction hlist_for_each_entry_rcufunction hlist_for_each_entry_rcufunction macvlan_hash_add_sourcefunction macvlan_hash_addfunction macvlan_hash_del_sourcefunction macvlan_hash_delfunction macvlan_hash_change_addrfunction macvlan_addr_busyfunction macvlan_broadcast_onefunction macvlan_hash_mixfunction mc_hashfunction macvlan_broadcastfunction hash_for_each_rcufunction macvlan_multicast_rxfunction macvlan_process_broadcastfunction macvlan_broadcast_enqueuefunction macvlan_flush_sourcesfunction macvlan_forward_source_onefunction macvlan_forward_sourcefunction hlist_for_each_entry_rcufunction macvlan_handle_framefunction macvlan_queue_xmitfunction macvlan_netpoll_send_skbfunction macvlan_start_xmitfunction macvlan_hard_headerfunction macvlan_openfunction macvlan_stopfunction macvlan_sync_addressfunction macvlan_set_mac_addressfunction macvlan_change_rx_flagsfunction macvlan_compute_filterfunction netdev_for_each_mc_addrfunction macvlan_recompute_bc_filterfunction macvlan_set_mac_listsfunction update_port_bc_cutofffunction macvlan_change_mtufunction macvlan_hwtstamp_getfunction macvlan_hwtstamp_setfunction macvlan_set_lockdep_class
Annotated Snippet
static const struct net_device_ops macvlan_netdev_ops = {
.ndo_init = macvlan_init,
.ndo_uninit = macvlan_uninit,
.ndo_open = macvlan_open,
.ndo_stop = macvlan_stop,
.ndo_start_xmit = macvlan_start_xmit,
.ndo_change_mtu = macvlan_change_mtu,
.ndo_fix_features = macvlan_fix_features,
.ndo_change_rx_flags = macvlan_change_rx_flags,
.ndo_set_mac_address = macvlan_set_mac_address,
.ndo_set_rx_mode = macvlan_set_mac_lists,
.ndo_get_stats64 = macvlan_dev_get_stats64,
.ndo_validate_addr = eth_validate_addr,
.ndo_vlan_rx_add_vid = macvlan_vlan_rx_add_vid,
.ndo_vlan_rx_kill_vid = macvlan_vlan_rx_kill_vid,
.ndo_fdb_add = macvlan_fdb_add,
.ndo_fdb_del = macvlan_fdb_del,
.ndo_fdb_dump = ndo_dflt_fdb_dump,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = macvlan_dev_poll_controller,
.ndo_netpoll_setup = macvlan_dev_netpoll_setup,
.ndo_netpoll_cleanup = macvlan_dev_netpoll_cleanup,
#endif
.ndo_get_iflink = macvlan_dev_get_iflink,
.ndo_features_check = passthru_features_check,
.ndo_hwtstamp_get = macvlan_hwtstamp_get,
.ndo_hwtstamp_set = macvlan_hwtstamp_set,
};
static void macvlan_dev_free(struct net_device *dev)
{
struct macvlan_dev *vlan = netdev_priv(dev);
/* Get rid of the macvlan's reference to lowerdev */
netdev_put(vlan->lowerdev, &vlan->dev_tracker);
}
void macvlan_common_setup(struct net_device *dev)
{
ether_setup(dev);
/* ether_setup() has set dev->min_mtu to ETH_MIN_MTU. */
dev->max_mtu = ETH_MAX_MTU;
dev->priv_flags &= ~IFF_TX_SKB_SHARING;
netif_keep_dst(dev);
dev->priv_flags |= IFF_UNICAST_FLT;
dev->change_proto_down = true;
dev->netdev_ops = &macvlan_netdev_ops;
dev->needs_free_netdev = true;
dev->priv_destructor = macvlan_dev_free;
dev->header_ops = &macvlan_hard_header_ops;
dev->ethtool_ops = &macvlan_ethtool_ops;
}
EXPORT_SYMBOL_GPL(macvlan_common_setup);
static void macvlan_setup(struct net_device *dev)
{
macvlan_common_setup(dev);
dev->priv_flags |= IFF_NO_QUEUE;
}
static int macvlan_port_create(struct net_device *dev)
{
struct macvlan_port *port;
unsigned int i;
int err;
if (dev->type != ARPHRD_ETHER || dev->flags & IFF_LOOPBACK)
return -EINVAL;
if (netdev_is_rx_handler_busy(dev))
return -EBUSY;
port = kzalloc_obj(*port);
if (port == NULL)
return -ENOMEM;
port->dev = dev;
ether_addr_copy(port->perm_addr, dev->dev_addr);
INIT_LIST_HEAD(&port->vlans);
for (i = 0; i < MACVLAN_HASH_SIZE; i++)
INIT_HLIST_HEAD(&port->vlan_hash[i]);
for (i = 0; i < MACVLAN_HASH_SIZE; i++)
INIT_HLIST_HEAD(&port->vlan_source_hash[i]);
port->bc_queue_len_used = 0;
port->bc_cutoff = 1;
skb_queue_head_init(&port->bc_queue);
INIT_WORK(&port->bc_work, macvlan_process_broadcast);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/types.h`, `linux/module.h`, `linux/init.h`, `linux/errno.h`, `linux/slab.h`, `linux/string.h`, `linux/rculist.h`.
- Detected declarations: `struct macvlan_port`, `struct macvlan_source_entry`, `struct macvlan_skb_cb`, `function macvlan_passthru`, `function macvlan_set_passthru`, `function macvlan_addr_change`, `function macvlan_set_addr_change`, `function macvlan_clear_addr_change`, `function macvlan_eth_hash`, `function hlist_for_each_entry_rcu`.
- 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.
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.