net/batman-adv/tvlv.c
Source file repositories/reference/linux-study-clean/net/batman-adv/tvlv.c
File Facts
- System
- Linux kernel
- Corpus path
net/batman-adv/tvlv.c- Extension
.c- Size
- 20387 bytes
- Lines
- 689
- 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
main.hlinux/bug.hlinux/byteorder/generic.hlinux/container_of.hlinux/errno.hlinux/etherdevice.hlinux/gfp.hlinux/if_ether.hlinux/kref.hlinux/limits.hlinux/list.hlinux/lockdep.hlinux/log2.hlinux/netdevice.hlinux/pkt_sched.hlinux/rculist.hlinux/rcupdate.hlinux/skbuff.hlinux/slab.hlinux/spinlock.hlinux/stddef.hlinux/string.hlinux/types.huapi/linux/batadv_packet.horiginator.hsend.htvlv.h
Detected Declarations
function batadv_tvlv_handler_releasefunction batadv_tvlv_handler_putfunction batadv_tvlv_handler_getfunction batadv_tvlv_container_releasefunction batadv_tvlv_container_putfunction batadv_tvlv_container_getfunction hlist_for_each_entryfunction batadv_tvlv_container_list_sizefunction hlist_for_each_entryfunction batadv_tvlv_container_removefunction batadv_tvlv_container_unregisterfunction batadv_tvlv_container_registerfunction batadv_tvlv_realloc_packet_bufffunction batadv_tvlv_container_ogm_appendfunction hlist_for_each_entryfunction batadv_tvlv_call_handlerfunction batadv_tvlv_containers_processfunction batadv_tvlv_ogm_receivefunction batadv_tvlv_handler_registerfunction batadv_tvlv_handler_unregisterfunction batadv_tvlv_unicast_send
Annotated Snippet
if (newlen <= ogm_buff->capacity) {
ogm_buff->len = newlen;
return true;
}
return false;
}
memcpy(new_buff, ogm_buff->buf, ogm_buff->header_length);
kfree(ogm_buff->buf);
ogm_buff->buf = new_buff;
ogm_buff->len = newlen;
ogm_buff->capacity = newcapacity;
return true;
}
/**
* batadv_tvlv_container_ogm_append() - append tvlv container content to given
* OGM packet buffer
* @bat_priv: the bat priv with all the mesh interface information
* @ogm_buff: ogm packet buffer
*
* The ogm packet might be enlarged or shrunk depending on the current size
* and the size of the to-be-appended tvlv containers.
*
* Return: size of all appended tvlv containers in bytes (max U16_MAX), negative
* if operation failed
*/
int batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv,
struct batadv_ogm_buf *ogm_buff)
{
struct batadv_tvlv_container *tvlv;
struct batadv_tvlv_hdr *tvlv_hdr;
size_t tvlv_value_len;
void *tvlv_value;
int tvlv_len_ret;
bool ret;
spin_lock_bh(&bat_priv->tvlv.container_list_lock);
tvlv_value_len = batadv_tvlv_container_list_size(bat_priv);
if (tvlv_value_len > U16_MAX) {
tvlv_len_ret = -E2BIG;
goto end;
}
ret = batadv_tvlv_realloc_packet_buff(ogm_buff, tvlv_value_len);
if (!ret) {
tvlv_len_ret = -ENOMEM;
goto end;
}
tvlv_len_ret = tvlv_value_len;
if (!tvlv_value_len)
goto end;
tvlv_value = (u8 *)ogm_buff->buf + ogm_buff->header_length;
hlist_for_each_entry(tvlv, &bat_priv->tvlv.container_list, list) {
tvlv_hdr = tvlv_value;
tvlv_hdr->type = tvlv->tvlv_hdr.type;
tvlv_hdr->version = tvlv->tvlv_hdr.version;
tvlv_hdr->len = tvlv->tvlv_hdr.len;
tvlv_value = tvlv_hdr + 1;
memcpy(tvlv_value, tvlv + 1, ntohs(tvlv->tvlv_hdr.len));
tvlv_value = (u8 *)tvlv_value + ntohs(tvlv->tvlv_hdr.len);
}
end:
spin_unlock_bh(&bat_priv->tvlv.container_list_lock);
return tvlv_len_ret;
}
/**
* batadv_tvlv_call_handler() - parse the given tvlv buffer to call the
* appropriate handlers
* @bat_priv: the bat priv with all the mesh interface information
* @tvlv_handler: tvlv callback function handling the tvlv content
* @packet_type: indicates for which packet type the TVLV handler is called
* @orig_node: orig node emitting the ogm packet
* @skb: the skb the TVLV handler is called for
* @tvlv_value: tvlv content
* @tvlv_value_len: tvlv content length
*
* Return: success if the handler was not found or the return value of the
* handler callback.
*/
Annotation
- Immediate include surface: `main.h`, `linux/bug.h`, `linux/byteorder/generic.h`, `linux/container_of.h`, `linux/errno.h`, `linux/etherdevice.h`, `linux/gfp.h`, `linux/if_ether.h`.
- Detected declarations: `function batadv_tvlv_handler_release`, `function batadv_tvlv_handler_put`, `function batadv_tvlv_handler_get`, `function batadv_tvlv_container_release`, `function batadv_tvlv_container_put`, `function batadv_tvlv_container_get`, `function hlist_for_each_entry`, `function batadv_tvlv_container_list_size`, `function hlist_for_each_entry`, `function batadv_tvlv_container_remove`.
- 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.