tools/testing/selftests/net/netlink-dumps.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/netlink-dumps.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/netlink-dumps.c- Extension
.c- Size
- 5729 bytes
- Lines
- 264
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
fcntl.hstdio.hstring.hsys/socket.hsys/stat.hsys/syscall.hsys/types.hunistd.hlinux/genetlink.hlinux/neighbour.hlinux/netdevice.hlinux/netlink.hlinux/mqueue.hlinux/rtnetlink.hkselftest_harness.hynl.h
Detected Declarations
struct ext_ackenum get_ea_retfunction nl_get_extackfunction ynl_attr_for_each
Annotated Snippet
struct ext_ack {
int err;
__u32 attr_offs;
__u32 miss_type;
__u32 miss_nest;
const char *str;
};
enum get_ea_ret {
ERROR = -1,
NO_CTRL = 0,
FOUND_DONE,
FOUND_ERR,
FOUND_EXTACK,
};
static enum get_ea_ret
nl_get_extack(char *buf, size_t n, struct ext_ack *ea)
{
enum get_ea_ret ret = NO_CTRL;
const struct nlmsghdr *nlh;
const struct nlattr *attr;
ssize_t rem;
for (rem = n; rem > 0; NLMSG_NEXT(nlh, rem)) {
nlh = (struct nlmsghdr *)&buf[n - rem];
if (!NLMSG_OK(nlh, rem))
return ERROR;
if (nlh->nlmsg_type == NLMSG_ERROR)
ret = FOUND_ERR;
else if (nlh->nlmsg_type == NLMSG_DONE)
ret = FOUND_DONE;
else
continue;
ea->err = -*(int *)NLMSG_DATA(nlh);
if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS))
return ret;
ynl_attr_for_each(attr, nlh, sizeof(int)) {
switch (ynl_attr_type(attr)) {
case NLMSGERR_ATTR_OFFS:
ea->attr_offs = ynl_attr_get_u32(attr);
break;
case NLMSGERR_ATTR_MISS_TYPE:
ea->miss_type = ynl_attr_get_u32(attr);
break;
case NLMSGERR_ATTR_MISS_NEST:
ea->miss_nest = ynl_attr_get_u32(attr);
break;
case NLMSGERR_ATTR_MSG:
ea->str = ynl_attr_get_str(attr);
break;
}
}
return FOUND_EXTACK;
}
return ret;
}
static const struct {
struct nlmsghdr nlhdr;
struct ndmsg ndm;
struct nlattr ahdr;
__u32 val;
} dump_neigh_bad = {
.nlhdr = {
.nlmsg_len = sizeof(dump_neigh_bad),
.nlmsg_type = RTM_GETNEIGH,
.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP,
.nlmsg_seq = 1,
},
.ndm = {
.ndm_family = 123,
},
.ahdr = {
.nla_len = 4 + 4,
.nla_type = NDA_FLAGS_EXT,
},
.val = -1, // should fail MASK validation
};
TEST(dump_extack)
{
int netlink_sock;
Annotation
- Immediate include surface: `fcntl.h`, `stdio.h`, `string.h`, `sys/socket.h`, `sys/stat.h`, `sys/syscall.h`, `sys/types.h`, `unistd.h`.
- Detected declarations: `struct ext_ack`, `enum get_ea_ret`, `function nl_get_extack`, `function ynl_attr_for_each`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.