net/netlink/genetlink.c
Source file repositories/reference/linux-study-clean/net/netlink/genetlink.c
File Facts
- System
- Linux kernel
- Corpus path
net/netlink/genetlink.c- Extension
.c- Size
- 46106 bytes
- Lines
- 2001
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/module.hlinux/kernel.hlinux/slab.hlinux/errno.hlinux/types.hlinux/socket.hlinux/string_helpers.hlinux/skbuff.hlinux/mutex.hlinux/bitmap.hlinux/rwsem.hlinux/idr.hnet/sock.hnet/genetlink.hgenetlink.h
Detected Declarations
struct genl_op_iterstruct genl_start_contextstruct ctrl_dump_policy_ctxfunction genl_lockfunction genl_unlockfunction genl_lock_allfunction genl_unlock_allfunction genl_op_lockfunction genl_op_unlockfunction genl_op_fill_in_reject_policyfunction genl_op_fill_in_reject_policy_splitfunction genl_op_from_fullfunction genl_get_cmd_fullfunction genl_op_from_smallfunction genl_get_cmd_smallfunction genl_op_from_splitfunction genl_get_cmd_splitfunction genl_cmd_full_to_splitfunction genl_get_cmdfunction genl_get_cmd_bothfunction genl_op_iter_initfunction genl_op_iter_nextfunction genl_op_iter_copyfunction genl_op_iter_idxfunction genl_allocate_reserve_groupsfunction genl_validate_assign_mc_groupsfunction for_each_net_rcufunction genl_unregister_mc_groupsfunction genl_split_op_checkfunction genl_validate_opsfunction genl_sk_priv_freefunction genl_sk_privs_allocfunction genl_sk_privs_freefunction genl_sk_priv_free_by_sockfunction genl_releasefunction ERR_PTRfunction ERR_PTRfunction genl_register_familyfunction genl_unregister_familyfunction genl_dumpit_info_freefunction genl_family_rcv_msg_attrs_parsefunction genl_family_rcv_msg_attrs_freefunction genl_startfunction genl_dumpitfunction genl_donefunction genl_family_rcv_msg_dumpitfunction genl_family_rcv_msg_doitfunction genl_header_check
Annotated Snippet
core_initcall(genl_init);
static int genlmsg_mcast(struct sk_buff *skb, u32 portid, unsigned long group)
{
struct sk_buff *tmp;
struct net *net, *prev = NULL;
bool delivered = false;
int err;
rcu_read_lock();
for_each_net_rcu(net) {
if (prev) {
tmp = skb_clone(skb, GFP_ATOMIC);
if (!tmp) {
err = -ENOMEM;
goto error;
}
err = nlmsg_multicast(prev->genl_sock, tmp,
portid, group, GFP_ATOMIC);
if (!err)
delivered = true;
else if (err != -ESRCH)
goto error;
}
prev = net;
}
err = nlmsg_multicast(prev->genl_sock, skb, portid, group, GFP_ATOMIC);
rcu_read_unlock();
if (!err)
delivered = true;
else if (err != -ESRCH)
return err;
return delivered ? 0 : -ESRCH;
error:
rcu_read_unlock();
kfree_skb(skb);
return err;
}
int genlmsg_multicast_allns(const struct genl_family *family,
struct sk_buff *skb, u32 portid,
unsigned int group)
{
if (WARN_ON_ONCE(group >= family->n_mcgrps)) {
kfree_skb(skb);
return -EINVAL;
}
group = family->mcgrp_offset + group;
return genlmsg_mcast(skb, portid, group);
}
EXPORT_SYMBOL(genlmsg_multicast_allns);
void genl_notify(const struct genl_family *family, struct sk_buff *skb,
struct genl_info *info, u32 group, gfp_t flags)
{
struct net *net = genl_info_net(info);
struct sock *sk = net->genl_sock;
if (WARN_ON_ONCE(group >= family->n_mcgrps)) {
kfree_skb(skb);
return;
}
group = family->mcgrp_offset + group;
nlmsg_notify(sk, skb, info->snd_portid, group,
nlmsg_report(info->nlhdr), flags);
}
EXPORT_SYMBOL(genl_notify);
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/slab.h`, `linux/errno.h`, `linux/types.h`, `linux/socket.h`, `linux/string_helpers.h`, `linux/skbuff.h`.
- Detected declarations: `struct genl_op_iter`, `struct genl_start_context`, `struct ctrl_dump_policy_ctx`, `function genl_lock`, `function genl_unlock`, `function genl_lock_all`, `function genl_unlock_all`, `function genl_op_lock`, `function genl_op_unlock`, `function genl_op_fill_in_reject_policy`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.