net/sched/sch_frag.c
Source file repositories/reference/linux-study-clean/net/sched/sch_frag.c
File Facts
- System
- Linux kernel
- Corpus path
net/sched/sch_frag.c- Extension
.c- Size
- 4254 bytes
- Lines
- 161
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/if_vlan.hnet/netlink.hnet/sch_generic.hnet/pkt_sched.hnet/dst.hnet/ip.hnet/ip6_fib.hnet/ip6_route.h
Detected Declarations
struct sch_frag_datafunction sch_frag_xmitfunction sch_frag_prepare_fragfunction sch_frag_dst_get_mtufunction sch_fragmentfunction sch_frag_xmit_hookexport sch_frag_xmit_hook
Annotated Snippet
struct sch_frag_data {
unsigned long dst;
struct qdisc_skb_cb cb;
__be16 inner_protocol;
u16 vlan_tci;
__be16 vlan_proto;
unsigned int l2_len;
u8 l2_data[VLAN_ETH_HLEN];
int (*xmit)(struct sk_buff *skb);
local_lock_t bh_lock;
};
static DEFINE_PER_CPU(struct sch_frag_data, sch_frag_data_storage) = {
.bh_lock = INIT_LOCAL_LOCK(bh_lock),
};
static int sch_frag_xmit(struct net *net, struct sock *sk, struct sk_buff *skb)
{
struct sch_frag_data *data = this_cpu_ptr(&sch_frag_data_storage);
lockdep_assert_held(&data->bh_lock);
if (skb_cow_head(skb, data->l2_len) < 0) {
kfree_skb(skb);
return -ENOMEM;
}
__skb_dst_copy(skb, data->dst);
*qdisc_skb_cb(skb) = data->cb;
skb->inner_protocol = data->inner_protocol;
if (data->vlan_tci & VLAN_CFI_MASK)
__vlan_hwaccel_put_tag(skb, data->vlan_proto,
data->vlan_tci & ~VLAN_CFI_MASK);
else
__vlan_hwaccel_clear_tag(skb);
/* Reconstruct the MAC header. */
skb_push(skb, data->l2_len);
memcpy(skb->data, &data->l2_data, data->l2_len);
skb_postpush_rcsum(skb, skb->data, data->l2_len);
skb_reset_mac_header(skb);
return data->xmit(skb);
}
static void sch_frag_prepare_frag(struct sk_buff *skb,
int (*xmit)(struct sk_buff *skb))
{
unsigned int hlen = skb_network_offset(skb);
struct sch_frag_data *data;
data = this_cpu_ptr(&sch_frag_data_storage);
data->dst = skb->_skb_refdst;
data->cb = *qdisc_skb_cb(skb);
data->xmit = xmit;
data->inner_protocol = skb->inner_protocol;
if (skb_vlan_tag_present(skb))
data->vlan_tci = skb_vlan_tag_get(skb) | VLAN_CFI_MASK;
else
data->vlan_tci = 0;
data->vlan_proto = skb->vlan_proto;
data->l2_len = hlen;
memcpy(&data->l2_data, skb->data, hlen);
memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
skb_pull(skb, hlen);
}
static unsigned int
sch_frag_dst_get_mtu(const struct dst_entry *dst)
{
return dst->dev->mtu;
}
static struct dst_ops sch_frag_dst_ops = {
.family = AF_UNSPEC,
.mtu = sch_frag_dst_get_mtu,
};
static int sch_fragment(struct net *net, struct sk_buff *skb,
u16 mru, int (*xmit)(struct sk_buff *skb))
{
int ret = -1;
if (skb_network_offset(skb) > VLAN_ETH_HLEN) {
net_warn_ratelimited("L2 header too long to fragment\n");
goto err;
}
if (skb_protocol(skb, true) == htons(ETH_P_IP)) {
struct rtable sch_frag_rt = { 0 };
Annotation
- Immediate include surface: `linux/if_vlan.h`, `net/netlink.h`, `net/sch_generic.h`, `net/pkt_sched.h`, `net/dst.h`, `net/ip.h`, `net/ip6_fib.h`, `net/ip6_route.h`.
- Detected declarations: `struct sch_frag_data`, `function sch_frag_xmit`, `function sch_frag_prepare_frag`, `function sch_frag_dst_get_mtu`, `function sch_fragment`, `function sch_frag_xmit_hook`, `export sch_frag_xmit_hook`.
- 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.