tools/testing/selftests/net/af_unix/diag_uid.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/af_unix/diag_uid.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/af_unix/diag_uid.c- Extension
.c- Size
- 3517 bytes
- Lines
- 178
- 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
sched.hunistd.hlinux/netlink.hlinux/rtnetlink.hlinux/sock_diag.hlinux/unix_diag.hsys/socket.hsys/stat.hsys/types.hsys/un.hkselftest_harness.h
Detected Declarations
function send_requestfunction render_responsefunction receive_response
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright Amazon.com Inc. or its affiliates. */
#define _GNU_SOURCE
#include <sched.h>
#include <unistd.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/sock_diag.h>
#include <linux/unix_diag.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/un.h>
#include "kselftest_harness.h"
FIXTURE(diag_uid)
{
int netlink_fd;
int unix_fd;
__u32 inode;
__u64 cookie;
};
FIXTURE_VARIANT(diag_uid)
{
int unshare;
int udiag_show;
};
FIXTURE_VARIANT_ADD(diag_uid, uid)
{
.unshare = 0,
.udiag_show = UDIAG_SHOW_UID
};
FIXTURE_VARIANT_ADD(diag_uid, uid_unshare)
{
.unshare = CLONE_NEWUSER,
.udiag_show = UDIAG_SHOW_UID
};
FIXTURE_SETUP(diag_uid)
{
struct stat file_stat;
socklen_t optlen;
int ret;
if (variant->unshare)
ASSERT_EQ(unshare(variant->unshare), 0);
self->netlink_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG);
ASSERT_NE(self->netlink_fd, -1);
self->unix_fd = socket(AF_UNIX, SOCK_STREAM, 0);
ASSERT_NE(self->unix_fd, -1);
ret = fstat(self->unix_fd, &file_stat);
ASSERT_EQ(ret, 0);
self->inode = file_stat.st_ino;
optlen = sizeof(self->cookie);
ret = getsockopt(self->unix_fd, SOL_SOCKET, SO_COOKIE, &self->cookie, &optlen);
ASSERT_EQ(ret, 0);
}
FIXTURE_TEARDOWN(diag_uid)
{
close(self->netlink_fd);
close(self->unix_fd);
}
int send_request(struct __test_metadata *_metadata,
FIXTURE_DATA(diag_uid) *self,
const FIXTURE_VARIANT(diag_uid) *variant)
{
struct {
struct nlmsghdr nlh;
struct unix_diag_req udr;
} req = {
.nlh = {
.nlmsg_len = sizeof(req),
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
.nlmsg_flags = NLM_F_REQUEST
},
.udr = {
.sdiag_family = AF_UNIX,
Annotation
- Immediate include surface: `sched.h`, `unistd.h`, `linux/netlink.h`, `linux/rtnetlink.h`, `linux/sock_diag.h`, `linux/unix_diag.h`, `sys/socket.h`, `sys/stat.h`.
- Detected declarations: `function send_request`, `function render_response`, `function receive_response`.
- 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.