net/8021q/vlan_core.c
Source file repositories/reference/linux-study-clean/net/8021q/vlan_core.c
File Facts
- System
- Linux kernel
- Corpus path
net/8021q/vlan_core.c- Extension
.c- Size
- 13096 bytes
- Lines
- 561
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/skbuff.hlinux/netdevice.hlinux/if_vlan.hlinux/netpoll.hlinux/export.hnet/gro.hvlan.h
Detected Declarations
struct vlan_vid_infofunction vlan_do_receivefunction vlan_dev_vlan_idfunction vlan_dev_vlan_protofunction vlan_group_freefunction vlan_info_freefunction vlan_info_rcu_freefunction vlan_hw_filter_capablefunction list_for_each_entryfunction vlan_add_rx_filter_infofunction vlan_kill_rx_filter_infofunction vlan_for_eachfunction list_for_each_entryfunction vlan_filter_push_vidsfunction list_for_each_entryfunction vlan_filter_drop_vidsfunction __vlan_vid_addfunction vlan_vid_addfunction __vlan_vid_delfunction vlan_vid_delfunction vlan_vids_add_by_devfunction list_for_each_entryfunction vlan_vids_del_by_devfunction list_for_each_entryfunction vlan_uses_devfunction list_for_each_entryfunction vlan_gro_completefunction vlan_offload_initmodule init vlan_offload_initexport __vlan_find_dev_deep_rcuexport vlan_dev_real_devexport vlan_dev_vlan_idexport vlan_dev_vlan_protoexport vlan_for_eachexport vlan_filter_push_vidsexport vlan_filter_drop_vidsexport vlan_vid_addexport vlan_vid_delexport vlan_vids_add_by_devexport vlan_vids_del_by_devexport vlan_uses_dev
Annotated Snippet
struct vlan_vid_info {
struct list_head list;
__be16 proto;
u16 vid;
int refcount;
};
static bool vlan_hw_filter_capable(const struct net_device *dev, __be16 proto)
{
if (proto == htons(ETH_P_8021Q) &&
dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
return true;
if (proto == htons(ETH_P_8021AD) &&
dev->features & NETIF_F_HW_VLAN_STAG_FILTER)
return true;
return false;
}
static struct vlan_vid_info *vlan_vid_info_get(struct vlan_info *vlan_info,
__be16 proto, u16 vid)
{
struct vlan_vid_info *vid_info;
list_for_each_entry(vid_info, &vlan_info->vid_list, list) {
if (vid_info->proto == proto && vid_info->vid == vid)
return vid_info;
}
return NULL;
}
static struct vlan_vid_info *vlan_vid_info_alloc(__be16 proto, u16 vid)
{
struct vlan_vid_info *vid_info;
vid_info = kzalloc_obj(struct vlan_vid_info);
if (!vid_info)
return NULL;
vid_info->proto = proto;
vid_info->vid = vid;
return vid_info;
}
static int vlan_add_rx_filter_info(struct net_device *dev, __be16 proto, u16 vid)
{
if (!vlan_hw_filter_capable(dev, proto))
return 0;
if (netif_device_present(dev))
return dev->netdev_ops->ndo_vlan_rx_add_vid(dev, proto, vid);
else
return -ENODEV;
}
static int vlan_kill_rx_filter_info(struct net_device *dev, __be16 proto, u16 vid)
{
if (!vlan_hw_filter_capable(dev, proto))
return 0;
if (netif_device_present(dev))
return dev->netdev_ops->ndo_vlan_rx_kill_vid(dev, proto, vid);
else
return -ENODEV;
}
int vlan_for_each(struct net_device *dev,
int (*action)(struct net_device *dev, int vid, void *arg),
void *arg)
{
struct vlan_vid_info *vid_info;
struct vlan_info *vlan_info;
struct net_device *vdev;
int ret;
ASSERT_RTNL();
vlan_info = rtnl_dereference(dev->vlan_info);
if (!vlan_info)
return 0;
list_for_each_entry(vid_info, &vlan_info->vid_list, list) {
vdev = vlan_group_get_device(&vlan_info->grp, vid_info->proto,
vid_info->vid);
ret = action(vdev, vid_info->vid, arg);
if (ret)
return ret;
}
return 0;
}
Annotation
- Immediate include surface: `linux/skbuff.h`, `linux/netdevice.h`, `linux/if_vlan.h`, `linux/netpoll.h`, `linux/export.h`, `net/gro.h`, `vlan.h`.
- Detected declarations: `struct vlan_vid_info`, `function vlan_do_receive`, `function vlan_dev_vlan_id`, `function vlan_dev_vlan_proto`, `function vlan_group_free`, `function vlan_info_free`, `function vlan_info_rcu_free`, `function vlan_hw_filter_capable`, `function list_for_each_entry`, `function vlan_add_rx_filter_info`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration 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.