net/ipv4/inet_fragment.c
Source file repositories/reference/linux-study-clean/net/ipv4/inet_fragment.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/inet_fragment.c- Extension
.c- Size
- 18189 bytes
- Lines
- 700
- 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/list.hlinux/spinlock.hlinux/module.hlinux/timer.hlinux/mm.hlinux/random.hlinux/skbuff.hlinux/rtnetlink.hlinux/slab.hlinux/rhashtable.hnet/sock.hnet/inet_frag.hnet/inet_ecn.hnet/ip.hnet/ipv6.h
Detected Declarations
struct ipfrag_skb_cbfunction fragcb_clearfunction fragrun_append_to_lastfunction fragrun_createfunction inet_frags_initfunction inet_frags_finifunction inet_frags_free_cbfunction fqdir_free_fnfunction llist_for_each_entry_safefunction fqdir_work_fnfunction fqdir_initfunction inet_frag_wq_initfunction fqdir_pre_exitfunction fqdir_exitfunction inet_frag_killfunction inet_frag_destroy_rcufunction inet_frag_rbtree_purgefunction inet_frag_queue_flushfunction inet_frag_destroyfunction inet_frag_queue_insertfunction inet_frag_reasm_finishexport ip_frag_ecn_tableexport inet_frags_initexport inet_frags_finiexport fqdir_initexport fqdir_pre_exitexport fqdir_exitexport inet_frag_killexport inet_frag_queue_flushexport inet_frag_destroyexport inet_frag_findexport inet_frag_queue_insertexport inet_frag_reasm_prepareexport inet_frag_reasm_finishexport inet_frag_pull_head
Annotated Snippet
struct ipfrag_skb_cb {
union {
struct inet_skb_parm h4;
struct inet6_skb_parm h6;
};
struct sk_buff *next_frag;
int frag_run_len;
int ip_defrag_offset;
};
#define FRAG_CB(skb) ((struct ipfrag_skb_cb *)((skb)->cb))
static void fragcb_clear(struct sk_buff *skb)
{
RB_CLEAR_NODE(&skb->rbnode);
FRAG_CB(skb)->next_frag = NULL;
FRAG_CB(skb)->frag_run_len = skb->len;
}
/* Append skb to the last "run". */
static void fragrun_append_to_last(struct inet_frag_queue *q,
struct sk_buff *skb)
{
fragcb_clear(skb);
FRAG_CB(q->last_run_head)->frag_run_len += skb->len;
FRAG_CB(q->fragments_tail)->next_frag = skb;
q->fragments_tail = skb;
}
/* Create a new "run" with the skb. */
static void fragrun_create(struct inet_frag_queue *q, struct sk_buff *skb)
{
BUILD_BUG_ON(sizeof(struct ipfrag_skb_cb) > sizeof(skb->cb));
fragcb_clear(skb);
if (q->last_run_head)
rb_link_node(&skb->rbnode, &q->last_run_head->rbnode,
&q->last_run_head->rbnode.rb_right);
else
rb_link_node(&skb->rbnode, NULL, &q->rb_fragments.rb_node);
rb_insert_color(&skb->rbnode, &q->rb_fragments);
q->fragments_tail = skb;
q->last_run_head = skb;
}
/* Given the OR values of all fragments, apply RFC 3168 5.3 requirements
* Value : 0xff if frame should be dropped.
* 0 or INET_ECN_CE value, to be ORed in to final iph->tos field
*/
const u8 ip_frag_ecn_table[16] = {
/* at least one fragment had CE, and others ECT_0 or ECT_1 */
[IPFRAG_ECN_CE | IPFRAG_ECN_ECT_0] = INET_ECN_CE,
[IPFRAG_ECN_CE | IPFRAG_ECN_ECT_1] = INET_ECN_CE,
[IPFRAG_ECN_CE | IPFRAG_ECN_ECT_0 | IPFRAG_ECN_ECT_1] = INET_ECN_CE,
/* invalid combinations : drop frame */
[IPFRAG_ECN_NOT_ECT | IPFRAG_ECN_CE] = 0xff,
[IPFRAG_ECN_NOT_ECT | IPFRAG_ECN_ECT_0] = 0xff,
[IPFRAG_ECN_NOT_ECT | IPFRAG_ECN_ECT_1] = 0xff,
[IPFRAG_ECN_NOT_ECT | IPFRAG_ECN_ECT_0 | IPFRAG_ECN_ECT_1] = 0xff,
[IPFRAG_ECN_NOT_ECT | IPFRAG_ECN_CE | IPFRAG_ECN_ECT_0] = 0xff,
[IPFRAG_ECN_NOT_ECT | IPFRAG_ECN_CE | IPFRAG_ECN_ECT_1] = 0xff,
[IPFRAG_ECN_NOT_ECT | IPFRAG_ECN_CE | IPFRAG_ECN_ECT_0 | IPFRAG_ECN_ECT_1] = 0xff,
};
EXPORT_SYMBOL(ip_frag_ecn_table);
int inet_frags_init(struct inet_frags *f)
{
f->frags_cachep = kmem_cache_create(f->frags_cache_name, f->qsize, 0, 0,
NULL);
if (!f->frags_cachep)
return -ENOMEM;
refcount_set(&f->refcnt, 1);
init_completion(&f->completion);
return 0;
}
EXPORT_SYMBOL(inet_frags_init);
void inet_frags_fini(struct inet_frags *f)
{
if (refcount_dec_and_test(&f->refcnt))
complete(&f->completion);
wait_for_completion(&f->completion);
kmem_cache_destroy(f->frags_cachep);
f->frags_cachep = NULL;
Annotation
- Immediate include surface: `linux/list.h`, `linux/spinlock.h`, `linux/module.h`, `linux/timer.h`, `linux/mm.h`, `linux/random.h`, `linux/skbuff.h`, `linux/rtnetlink.h`.
- Detected declarations: `struct ipfrag_skb_cb`, `function fragcb_clear`, `function fragrun_append_to_last`, `function fragrun_create`, `function inet_frags_init`, `function inet_frags_fini`, `function inet_frags_free_cb`, `function fqdir_free_fn`, `function llist_for_each_entry_safe`, `function fqdir_work_fn`.
- 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.