net/dsa/tag_8021q.c
Source file repositories/reference/linux-study-clean/net/dsa/tag_8021q.c
File Facts
- System
- Linux kernel
- Corpus path
net/dsa/tag_8021q.c- Extension
.c- Size
- 15812 bytes
- Lines
- 589
- 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.
- 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/if_vlan.hlinux/dsa/8021q.hport.hswitch.htag.htag_8021q.h
Detected Declarations
struct dsa_tag_8021q_vlanstruct dsa_8021q_contextfunction dsa_tag_8021q_bridge_vidfunction dsa_tag_8021q_standalone_vidfunction dsa_8021q_rx_switch_idfunction dsa_8021q_rx_source_portfunction dsa_tag_8021q_rx_vbidfunction vid_is_dsa_8021qfunction dsa_tag_8021q_vlan_findfunction dsa_port_do_tag_8021q_vlan_addfunction dsa_port_do_tag_8021q_vlan_delfunction dsa_port_tag_8021q_vlan_matchfunction dsa_switch_tag_8021q_vlan_addfunction dsa_switch_for_each_portfunction dsa_switch_tag_8021q_vlan_delfunction dsa_switch_for_each_portfunction dsa_tag_8021q_bridge_joinfunction dsa_tag_8021q_bridge_leavefunction dsa_tag_8021q_port_setupfunction dsa_tag_8021q_port_teardownfunction dsa_tag_8021q_setupfunction dsa_tag_8021q_teardownfunction dsa_tag_8021q_registerfunction dsa_tag_8021q_unregisterfunction list_for_each_entry_safefunction dsa_tag_8021q_find_port_by_vbidfunction dsa_tree_for_each_user_portfunction dsa_8021q_rcvexport dsa_tag_8021q_bridge_videxport dsa_tag_8021q_standalone_videxport dsa_8021q_rx_switch_idexport dsa_8021q_rx_source_portexport vid_is_dsa_8021qexport dsa_tag_8021q_bridge_joinexport dsa_tag_8021q_bridge_leaveexport dsa_tag_8021q_registerexport dsa_tag_8021q_unregisterexport dsa_8021q_xmitexport dsa_tag_8021q_find_userexport dsa_8021q_rcv
Annotated Snippet
struct dsa_tag_8021q_vlan {
struct list_head list;
int port;
u16 vid;
refcount_t refcount;
};
struct dsa_8021q_context {
struct dsa_switch *ds;
struct list_head vlans;
/* EtherType of RX VID, used for filtering on conduit interface */
__be16 proto;
};
u16 dsa_tag_8021q_bridge_vid(unsigned int bridge_num)
{
/* The VBID value of 0 is reserved for precise TX, but it is also
* reserved/invalid for the bridge_num, so all is well.
*/
return DSA_8021Q_RSV | DSA_8021Q_VBID(bridge_num);
}
EXPORT_SYMBOL_GPL(dsa_tag_8021q_bridge_vid);
/* Returns the VID that will be installed as pvid for this switch port, sent as
* tagged egress towards the CPU port and decoded by the rcv function.
*/
u16 dsa_tag_8021q_standalone_vid(const struct dsa_port *dp)
{
return DSA_8021Q_RSV | DSA_8021Q_SWITCH_ID(dp->ds->index) |
DSA_8021Q_PORT(dp->index);
}
EXPORT_SYMBOL_GPL(dsa_tag_8021q_standalone_vid);
/* Returns the decoded switch ID from the RX VID. */
int dsa_8021q_rx_switch_id(u16 vid)
{
return (vid & DSA_8021Q_SWITCH_ID_MASK) >> DSA_8021Q_SWITCH_ID_SHIFT;
}
EXPORT_SYMBOL_GPL(dsa_8021q_rx_switch_id);
/* Returns the decoded port ID from the RX VID. */
int dsa_8021q_rx_source_port(u16 vid)
{
return (vid & DSA_8021Q_PORT_MASK) >> DSA_8021Q_PORT_SHIFT;
}
EXPORT_SYMBOL_GPL(dsa_8021q_rx_source_port);
/* Returns the decoded VBID from the RX VID. */
static int dsa_tag_8021q_rx_vbid(u16 vid)
{
u16 vbid_hi = (vid & DSA_8021Q_VBID_HI_MASK) >> DSA_8021Q_VBID_HI_SHIFT;
u16 vbid_lo = (vid & DSA_8021Q_VBID_LO_MASK) >> DSA_8021Q_VBID_LO_SHIFT;
return (vbid_hi << 2) | vbid_lo;
}
bool vid_is_dsa_8021q(u16 vid)
{
u16 rsv = (vid & DSA_8021Q_RSV_MASK) >> DSA_8021Q_RSV_SHIFT;
return rsv == DSA_8021Q_RSV_VAL;
}
EXPORT_SYMBOL_GPL(vid_is_dsa_8021q);
static struct dsa_tag_8021q_vlan *
dsa_tag_8021q_vlan_find(struct dsa_8021q_context *ctx, int port, u16 vid)
{
struct dsa_tag_8021q_vlan *v;
list_for_each_entry(v, &ctx->vlans, list)
if (v->vid == vid && v->port == port)
return v;
return NULL;
}
static int dsa_port_do_tag_8021q_vlan_add(struct dsa_port *dp, u16 vid,
u16 flags)
{
struct dsa_8021q_context *ctx = dp->ds->tag_8021q_ctx;
struct dsa_switch *ds = dp->ds;
struct dsa_tag_8021q_vlan *v;
int port = dp->index;
int err;
/* No need to bother with refcounting for user ports */
if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp)))
return ds->ops->tag_8021q_vlan_add(ds, port, vid, flags);
v = dsa_tag_8021q_vlan_find(ctx, port, vid);
Annotation
- Immediate include surface: `linux/if_vlan.h`, `linux/dsa/8021q.h`, `port.h`, `switch.h`, `tag.h`, `tag_8021q.h`.
- Detected declarations: `struct dsa_tag_8021q_vlan`, `struct dsa_8021q_context`, `function dsa_tag_8021q_bridge_vid`, `function dsa_tag_8021q_standalone_vid`, `function dsa_8021q_rx_switch_id`, `function dsa_8021q_rx_source_port`, `function dsa_tag_8021q_rx_vbid`, `function vid_is_dsa_8021q`, `function dsa_tag_8021q_vlan_find`, `function dsa_port_do_tag_8021q_vlan_add`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
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.