tools/testing/selftests/net/txring_overwrite.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/txring_overwrite.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/txring_overwrite.c- Extension
.c- Size
- 3807 bytes
- Lines
- 180
- 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
arpa/inet.hassert.herror.herrno.hfcntl.hlinux/filter.hlinux/if_packet.hnet/ethernet.hnet/if.hnetinet/in.hnetinet/ip.hnetinet/udp.hpoll.hpthread.hsched.hsys/ioctl.hsys/mman.hsys/socket.hsys/time.hsys/types.hsys/utsname.hstdbool.hstdint.hstdio.hstdlib.hstring.hunistd.h
Detected Declarations
function build_packetfunction setup_rxfunction setup_txfunction send_pktfunction read_verify_pktfunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Verify that consecutive sends over packet tx_ring are mirrored
* with their original content intact.
*/
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <assert.h>
#include <error.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/filter.h>
#include <linux/if_packet.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <poll.h>
#include <pthread.h>
#include <sched.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
const int eth_off = TPACKET_HDRLEN - sizeof(struct sockaddr_ll);
const int cfg_frame_size = 1000;
static void build_packet(void *buffer, size_t blen, char payload_char)
{
struct udphdr *udph;
struct ethhdr *eth;
struct iphdr *iph;
size_t off = 0;
memset(buffer, 0, blen);
eth = buffer;
eth->h_proto = htons(ETH_P_IP);
off += sizeof(*eth);
iph = buffer + off;
iph->ttl = 8;
iph->ihl = 5;
iph->version = 4;
iph->saddr = htonl(INADDR_LOOPBACK);
iph->daddr = htonl(INADDR_LOOPBACK + 1);
iph->protocol = IPPROTO_UDP;
iph->tot_len = htons(blen - off);
iph->check = 0;
off += sizeof(*iph);
udph = buffer + off;
udph->dest = htons(8000);
udph->source = htons(8001);
udph->len = htons(blen - off);
udph->check = 0;
off += sizeof(*udph);
memset(buffer + off, payload_char, blen - off);
}
static int setup_rx(void)
{
int fdr;
fdr = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP));
if (fdr == -1)
error(1, errno, "socket r");
return fdr;
}
static int setup_tx(char **ring)
{
struct sockaddr_ll laddr = {};
struct tpacket_req req = {};
int fdt;
Annotation
- Immediate include surface: `arpa/inet.h`, `assert.h`, `error.h`, `errno.h`, `fcntl.h`, `linux/filter.h`, `linux/if_packet.h`, `net/ethernet.h`.
- Detected declarations: `function build_packet`, `function setup_rx`, `function setup_tx`, `function send_pkt`, `function read_verify_pkt`, `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.