net/batman-adv/fragmentation.c
Source file repositories/reference/linux-study-clean/net/batman-adv/fragmentation.c
File Facts
- System
- Linux kernel
- Corpus path
net/batman-adv/fragmentation.c- Extension
.c- Size
- 17501 bytes
- Lines
- 605
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source 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.
- 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
fragmentation.hmain.hlinux/atomic.hlinux/bug.hlinux/byteorder/generic.hlinux/errno.hlinux/etherdevice.hlinux/gfp.hlinux/if_ether.hlinux/jiffies.hlinux/lockdep.hlinux/minmax.hlinux/netdevice.hlinux/overflow.hlinux/skbuff.hlinux/slab.hlinux/spinlock.hlinux/string.huapi/linux/batadv_packet.hhard-interface.horiginator.hsend.h
Detected Declarations
function batadv_frag_clear_chainfunction hlist_for_each_entry_safefunction batadv_frag_purge_origfunction batadv_frag_size_limitfunction batadv_frag_init_chainfunction batadv_frag_insert_packetfunction batadv_frag_merge_packetsfunction batadv_skb_is_fragfunction batadv_frag_skb_bufferfunction batadv_frag_skb_fwdfunction batadv_frag_createfunction batadv_frag_send_packet
Annotated Snippet
if (!check_cb || check_cb(chain)) {
batadv_frag_clear_chain(&chain->fragment_list, true);
chain->size = 0;
}
spin_unlock_bh(&chain->lock);
}
}
/**
* batadv_frag_size_limit() - maximum possible size of packet to be fragmented
*
* Return: the maximum size of payload that can be fragmented.
*/
static size_t batadv_frag_size_limit(void)
{
size_t limit = BATADV_FRAG_MAX_FRAG_SIZE;
limit -= sizeof(struct batadv_frag_packet);
limit *= BATADV_FRAG_MAX_FRAGMENTS;
return limit;
}
/**
* batadv_frag_init_chain() - check and prepare fragment chain for new fragment
* @chain: chain in fragments table to init
* @seqno: sequence number of the received fragment
*
* Make chain ready for a fragment with sequence number "seqno". Delete existing
* entries if they have an "old" sequence number.
*
* Caller must hold chain->lock.
*
* Return: true if chain is empty and the caller can just insert the new
* fragment without searching for the right position.
*/
static bool batadv_frag_init_chain(struct batadv_frag_table_entry *chain,
u16 seqno)
{
lockdep_assert_held(&chain->lock);
if (chain->seqno == seqno)
return false;
if (!hlist_empty(&chain->fragment_list))
batadv_frag_clear_chain(&chain->fragment_list, true);
chain->size = 0;
chain->seqno = seqno;
return true;
}
/**
* batadv_frag_insert_packet() - insert a fragment into a fragment chain
* @orig_node: originator that the fragment was received from
* @skb: skb to insert
* @chain_out: list head to attach complete chains of fragments to
*
* Insert a new fragment into the reverse ordered chain in the right table
* entry. The hash table entry is cleared if "old" fragments exist in it.
*
* Return: true if skb is buffered, false on error. If the chain has all the
* fragments needed to merge the packet, the chain is moved to the passed head
* to avoid locking the chain in the table.
*/
static bool batadv_frag_insert_packet(struct batadv_orig_node *orig_node,
struct sk_buff *skb,
struct hlist_head *chain_out)
{
struct batadv_frag_table_entry *chain;
struct batadv_frag_list_entry *frag_entry_new = NULL, *frag_entry_curr;
struct batadv_frag_list_entry *frag_entry_last = NULL;
struct batadv_frag_packet *frag_packet;
u8 bucket;
u16 seqno, hdr_size = sizeof(struct batadv_frag_packet);
bool overflow = false;
bool ret = false;
size_t data_len;
/* Linearize packet to avoid linearizing 16 packets in a row when doing
* the later merge. Non-linear merge should be added to remove this
* linearization.
*/
if (skb_linearize(skb) < 0)
goto err;
frag_packet = (struct batadv_frag_packet *)skb->data;
data_len = skb->len - hdr_size;
Annotation
- Immediate include surface: `fragmentation.h`, `main.h`, `linux/atomic.h`, `linux/bug.h`, `linux/byteorder/generic.h`, `linux/errno.h`, `linux/etherdevice.h`, `linux/gfp.h`.
- Detected declarations: `function batadv_frag_clear_chain`, `function hlist_for_each_entry_safe`, `function batadv_frag_purge_orig`, `function batadv_frag_size_limit`, `function batadv_frag_init_chain`, `function batadv_frag_insert_packet`, `function batadv_frag_merge_packets`, `function batadv_skb_is_frag`, `function batadv_frag_skb_buffer`, `function batadv_frag_skb_fwd`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source 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.