drivers/net/vrf.c
Source file repositories/reference/linux-study-clean/drivers/net/vrf.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/vrf.c- Extension
.c- Size
- 45640 bytes
- Lines
- 1970
- 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/ethtool.hlinux/module.hlinux/kernel.hlinux/netdevice.hlinux/etherdevice.hlinux/ip.hlinux/init.hlinux/moduleparam.hlinux/netfilter.hlinux/rtnetlink.hnet/rtnetlink.hlinux/u64_stats_sync.hlinux/hashtable.hlinux/spinlock_types.hlinux/inetdevice.hnet/arp.hnet/flow.hnet/ip.hnet/ip_fib.hnet/ip6_fib.hnet/ip6_route.hnet/route.hnet/addrconf.hnet/l3mdev.hnet/fib_rules.hnet/netdev_lock.hnet/sch_generic.hnet/netns/generic.hnet/netfilter/nf_conntrack.h
Detected Declarations
struct vrf_mapstruct vrf_map_elemstruct netns_vrfstruct net_vrffunction vrf_tx_errorfunction vrf_map_elem_get_vrf_ifindexfunction vrf_map_elem_freefunction vrf_map_elem_initfunction vrf_map_add_elemfunction vrf_map_del_elemfunction vrf_map_lockfunction vrf_map_unlockfunction vrf_map_register_devfunction vrf_map_unregister_devfunction vrf_ifindex_lookup_by_table_idfunction qdisc_tx_is_defaultfunction vrf_local_xmitfunction vrf_nf_set_untrackedfunction vrf_nf_reset_ctfunction vrf_ip6_local_outfunction vrf_process_v6_outboundfunction vrf_process_v6_outboundfunction vrf_ip_local_outfunction vrf_process_v4_outboundfunction is_ip_tx_framefunction vrf_xmitfunction vrf_finish_directfunction vrf_finish_output6function vrf_output6function vrf_output6_direct_finishfunction vrf_output6_directfunction vrf_ip6_out_direct_finishfunction vrf_rt6_releasefunction vrf_rt6_createfunction vrf_rt6_releasefunction vrf_finish_outputfunction vrf_outputfunction vrf_output_direct_finishfunction vrf_output_directfunction vrf_ip_out_direct_finishfunction vrf_rtable_releasefunction vrf_rtable_createfunction cycle_netdevfunction do_vrf_add_slavefunction vrf_add_slavefunction do_vrf_del_slavefunction vrf_del_slavefunction vrf_dev_uninit
Annotated Snippet
static const struct net_device_ops vrf_netdev_ops = {
.ndo_init = vrf_dev_init,
.ndo_uninit = vrf_dev_uninit,
.ndo_start_xmit = vrf_xmit,
.ndo_set_mac_address = eth_mac_addr,
.ndo_add_slave = vrf_add_slave,
.ndo_del_slave = vrf_del_slave,
};
static u32 vrf_fib_table(const struct net_device *dev)
{
struct net_vrf *vrf = netdev_priv(dev);
return vrf->tb_id;
}
static int vrf_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
{
kfree_skb(skb);
return 0;
}
static struct sk_buff *vrf_rcv_nfhook(u8 pf, unsigned int hook,
struct sk_buff *skb,
struct net_device *dev)
{
struct net *net = dev_net(dev);
if (nf_hook(pf, hook, net, NULL, skb, dev, NULL, vrf_rcv_finish) != 1)
skb = NULL; /* kfree_skb(skb) handled by nf code */
return skb;
}
static int vrf_prepare_mac_header(struct sk_buff *skb,
struct net_device *vrf_dev, u16 proto)
{
struct ethhdr *eth;
int err;
/* in general, we do not know if there is enough space in the head of
* the packet for hosting the mac header.
*/
err = skb_cow_head(skb, LL_RESERVED_SPACE(vrf_dev));
if (unlikely(err))
/* no space in the skb head */
return -ENOBUFS;
__skb_push(skb, ETH_HLEN);
eth = (struct ethhdr *)skb->data;
skb_reset_mac_header(skb);
skb_reset_mac_len(skb);
/* we set the ethernet destination and the source addresses to the
* address of the VRF device.
*/
ether_addr_copy(eth->h_dest, vrf_dev->dev_addr);
ether_addr_copy(eth->h_source, vrf_dev->dev_addr);
eth->h_proto = htons(proto);
/* the destination address of the Ethernet frame corresponds to the
* address set on the VRF interface; therefore, the packet is intended
* to be processed locally.
*/
skb->protocol = eth->h_proto;
skb->pkt_type = PACKET_HOST;
skb_postpush_rcsum(skb, skb->data, ETH_HLEN);
skb_pull_inline(skb, ETH_HLEN);
return 0;
}
/* prepare and add the mac header to the packet if it was not set previously.
* In this way, packet sniffers such as tcpdump can parse the packet correctly.
* If the mac header was already set, the original mac header is left
* untouched and the function returns immediately.
*/
static int vrf_add_mac_header_if_unset(struct sk_buff *skb,
struct net_device *vrf_dev,
u16 proto, struct net_device *orig_dev)
{
if (skb_mac_header_was_set(skb) && dev_has_header(orig_dev))
return 0;
return vrf_prepare_mac_header(skb, vrf_dev, proto);
}
Annotation
- Immediate include surface: `linux/ethtool.h`, `linux/module.h`, `linux/kernel.h`, `linux/netdevice.h`, `linux/etherdevice.h`, `linux/ip.h`, `linux/init.h`, `linux/moduleparam.h`.
- Detected declarations: `struct vrf_map`, `struct vrf_map_elem`, `struct netns_vrf`, `struct net_vrf`, `function vrf_tx_error`, `function vrf_map_elem_get_vrf_ifindex`, `function vrf_map_elem_free`, `function vrf_map_elem_init`, `function vrf_map_add_elem`, `function vrf_map_del_elem`.
- 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.