net/devlink/netlink.c
Source file repositories/reference/linux-study-clean/net/devlink/netlink.c
File Facts
- System
- Linux kernel
- Corpus path
net/devlink/netlink.c- Extension
.c- Size
- 10700 bytes
- Lines
- 413
- 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
net/genetlink.hnet/sock.hdevl_internal.h
Detected Declarations
struct devlink_nl_sock_privfunction devlink_nl_sock_priv_initfunction devlink_nl_sock_priv_destroyfunction devlink_nl_notify_filter_set_doitfunction devlink_obj_desc_matchfunction devlink_nl_notify_filterfunction devlink_nl_put_nested_handlefunction devlink_nl_msg_reply_and_newfunction devlink_get_from_attrs_lockfunction devlinks_xa_for_each_registered_getfunction __devlink_nl_pre_doitfunction devlink_nl_pre_doitfunction devlink_nl_pre_doit_portfunction devlink_nl_pre_doit_dev_lockfunction devlink_nl_pre_doit_port_optionalfunction __devlink_nl_post_doitfunction devlink_nl_post_doitfunction devlink_nl_post_doit_dev_lockfunction devlink_nl_inst_single_dumpitfunction devlink_nl_inst_iter_dumpitfunction devlink_nl_dumpit
Annotated Snippet
struct devlink_nl_sock_priv {
struct devlink_obj_desc __rcu *flt;
spinlock_t flt_lock; /* Protects flt. */
};
static void devlink_nl_sock_priv_init(void *priv)
{
struct devlink_nl_sock_priv *sk_priv = priv;
spin_lock_init(&sk_priv->flt_lock);
}
static void devlink_nl_sock_priv_destroy(void *priv)
{
struct devlink_nl_sock_priv *sk_priv = priv;
struct devlink_obj_desc *flt;
flt = rcu_dereference_protected(sk_priv->flt, true);
kfree_rcu(flt, rcu);
}
int devlink_nl_notify_filter_set_doit(struct sk_buff *skb,
struct genl_info *info)
{
struct devlink_nl_sock_priv *sk_priv;
struct nlattr **attrs = info->attrs;
struct devlink_obj_desc *flt;
size_t data_offset = 0;
size_t data_size = 0;
char *pos;
if (attrs[DEVLINK_ATTR_BUS_NAME])
data_size = size_add(data_size,
nla_len(attrs[DEVLINK_ATTR_BUS_NAME]) + 1);
if (attrs[DEVLINK_ATTR_DEV_NAME])
data_size = size_add(data_size,
nla_len(attrs[DEVLINK_ATTR_DEV_NAME]) + 1);
flt = kzalloc(size_add(sizeof(*flt), data_size), GFP_KERNEL);
if (!flt)
return -ENOMEM;
pos = (char *) flt->data;
if (attrs[DEVLINK_ATTR_BUS_NAME]) {
data_offset += nla_strscpy(pos,
attrs[DEVLINK_ATTR_BUS_NAME],
data_size) + 1;
flt->bus_name = pos;
pos += data_offset;
}
if (attrs[DEVLINK_ATTR_DEV_NAME]) {
nla_strscpy(pos, attrs[DEVLINK_ATTR_DEV_NAME],
data_size - data_offset);
flt->dev_name = pos;
}
if (attrs[DEVLINK_ATTR_INDEX]) {
flt->devlink_index = nla_get_uint(attrs[DEVLINK_ATTR_INDEX]);
flt->devlink_index_valid = true;
}
if (attrs[DEVLINK_ATTR_PORT_INDEX]) {
flt->port_index = nla_get_u32(attrs[DEVLINK_ATTR_PORT_INDEX]);
flt->port_index_valid = true;
}
/* Don't attach empty filter. */
if (!flt->bus_name && !flt->dev_name &&
!flt->devlink_index_valid && !flt->port_index_valid) {
kfree(flt);
flt = NULL;
}
sk_priv = genl_sk_priv_get(&devlink_nl_family, NETLINK_CB(skb).sk);
if (IS_ERR(sk_priv)) {
kfree(flt);
return PTR_ERR(sk_priv);
}
spin_lock(&sk_priv->flt_lock);
flt = rcu_replace_pointer(sk_priv->flt, flt,
lockdep_is_held(&sk_priv->flt_lock));
spin_unlock(&sk_priv->flt_lock);
kfree_rcu(flt, rcu);
return 0;
}
static bool devlink_obj_desc_match(const struct devlink_obj_desc *desc,
const struct devlink_obj_desc *flt)
{
if (desc->devlink_index_valid && flt->devlink_index_valid &&
Annotation
- Immediate include surface: `net/genetlink.h`, `net/sock.h`, `devl_internal.h`.
- Detected declarations: `struct devlink_nl_sock_priv`, `function devlink_nl_sock_priv_init`, `function devlink_nl_sock_priv_destroy`, `function devlink_nl_notify_filter_set_doit`, `function devlink_obj_desc_match`, `function devlink_nl_notify_filter`, `function devlink_nl_put_nested_handle`, `function devlink_nl_msg_reply_and_new`, `function devlink_get_from_attrs_lock`, `function devlinks_xa_for_each_registered_get`.
- 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.