tools/testing/selftests/net/netfilter/udpclash.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/netfilter/udpclash.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/netfilter/udpclash.c- Extension
.c- Size
- 3585 bytes
- Lines
- 159
- 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
stdio.hstring.hstdlib.hunistd.harpa/inet.hsys/socket.hpthread.h
Detected Declarations
struct thread_argsfunction run_testfunction main
Annotated Snippet
struct thread_args {
const struct sockaddr_in *si_remote;
int sockfd;
};
static volatile int wait = 1;
static void *thread_main(void *varg)
{
const struct sockaddr_in *si_remote;
const struct thread_args *args = varg;
static const char msg[] = "foo";
si_remote = args->si_remote;
while (wait == 1)
;
if (sendto(args->sockfd, msg, strlen(msg), MSG_NOSIGNAL,
(struct sockaddr *)si_remote, sizeof(*si_remote)) < 0)
exit(111);
return varg;
}
static int run_test(int fd, const struct sockaddr_in *si_remote)
{
struct thread_args thread_args = {
.si_remote = si_remote,
.sockfd = fd,
};
pthread_t *tid = calloc(THREAD_COUNT, sizeof(pthread_t));
unsigned int repl_count = 0, timeout = 0;
int i;
if (!tid) {
perror("calloc");
return 1;
}
for (i = 0; i < THREAD_COUNT; i++) {
int err = pthread_create(&tid[i], NULL, &thread_main, &thread_args);
if (err != 0) {
perror("pthread_create");
exit(1);
}
}
wait = 0;
for (i = 0; i < THREAD_COUNT; i++)
pthread_join(tid[i], NULL);
while (repl_count < THREAD_COUNT) {
struct sockaddr_in si_repl;
socklen_t si_repl_len = sizeof(si_repl);
char repl[512];
ssize_t ret;
ret = recvfrom(fd, repl, sizeof(repl), MSG_NOSIGNAL,
(struct sockaddr *) &si_repl, &si_repl_len);
if (ret < 0) {
if (timeout++ > 5000) {
fputs("timed out while waiting for reply from thread\n", stderr);
break;
}
/* give reply time to pass though the stack */
usleep(1000);
continue;
}
if (si_repl_len != sizeof(*si_remote)) {
fprintf(stderr, "warning: reply has unexpected repl_len %d vs %d\n",
(int)si_repl_len, (int)sizeof(si_repl));
} else if (si_remote->sin_addr.s_addr != si_repl.sin_addr.s_addr ||
si_remote->sin_port != si_repl.sin_port) {
char a[64], b[64];
inet_ntop(AF_INET, &si_remote->sin_addr, a, sizeof(a));
inet_ntop(AF_INET, &si_repl.sin_addr, b, sizeof(b));
fprintf(stderr, "reply from wrong source: want %s:%d got %s:%d\n",
a, ntohs(si_remote->sin_port), b, ntohs(si_repl.sin_port));
}
repl_count++;
}
Annotation
- Immediate include surface: `stdio.h`, `string.h`, `stdlib.h`, `unistd.h`, `arpa/inet.h`, `sys/socket.h`, `pthread.h`.
- Detected declarations: `struct thread_args`, `function run_test`, `function main`.
- 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.