tools/testing/selftests/net/icmp_rfc4884.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/icmp_rfc4884.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/icmp_rfc4884.c- Extension
.c- Size
- 17244 bytes
- Lines
- 680
- 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.herror.hlinux/errqueue.hlinux/icmp.hlinux/icmpv6.hlinux/in6.hlinux/ip.hlinux/ipv6.hnetinet/in.hnetinet/udp.hpoll.hsched.hstdbool.hstdint.hstdio.hstdlib.hsys/ioctl.hsys/socket.h../kselftest_harness.h
Detected Declarations
struct sockaddr_inetstruct ip_case_infofunction bringup_loopbackfunction csumfunction poll_errfunction set_addrfunction bind_and_setsockoptfunction build_rfc4884_extfunction build_orig_dgram_v4function build_orig_dgram_v6function build_icmpv4_pktfunction build_icmpv6_pktfunction check_rfc4884_offsetfunction ASSERT_EQfunction ASSERT_EQ
Annotated Snippet
struct sockaddr_inet {
union {
struct sockaddr_in6 v6;
struct sockaddr_in v4;
struct sockaddr sa;
};
socklen_t len;
};
struct ip_case_info {
int domain;
int level;
int opt1;
int opt2;
int proto;
int (*build_func)(uint8_t *buf, ssize_t buflen, bool with_ext,
int payload_len, bool bad_csum, bool bad_len,
bool smaller_len);
int min_payload;
};
static int bringup_loopback(void)
{
struct ifreq ifr = {
.ifr_name = "lo"
};
int fd;
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0)
return -1;
if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0)
goto err;
ifr.ifr_flags = ifr.ifr_flags | IFF_UP;
if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0)
goto err;
close(fd);
return 0;
err:
close(fd);
return -1;
}
static uint16_t csum(const void *buf, size_t len)
{
const uint8_t *data = buf;
uint32_t sum = 0;
while (len > 1) {
sum += (data[0] << 8) | data[1];
data += 2;
len -= 2;
}
if (len == 1)
sum += data[0] << 8;
while (sum >> 16)
sum = (sum & 0xFFFF) + (sum >> 16);
return ~sum & 0xFFFF;
}
static int poll_err(int fd)
{
struct pollfd pfd;
memset(&pfd, 0, sizeof(pfd));
pfd.fd = fd;
if (poll(&pfd, 1, 5000) != 1 || pfd.revents != POLLERR)
return -1;
return 0;
}
static void set_addr(struct sockaddr_inet *addr, int domain,
unsigned short port)
{
memset(addr, 0, sizeof(*addr));
switch (domain) {
case AF_INET:
addr->v4.sin_family = AF_INET;
addr->v4.sin_port = htons(port);
Annotation
- Immediate include surface: `arpa/inet.h`, `error.h`, `linux/errqueue.h`, `linux/icmp.h`, `linux/icmpv6.h`, `linux/in6.h`, `linux/ip.h`, `linux/ipv6.h`.
- Detected declarations: `struct sockaddr_inet`, `struct ip_case_info`, `function bringup_loopback`, `function csum`, `function poll_err`, `function set_addr`, `function bind_and_setsockopt`, `function build_rfc4884_ext`, `function build_orig_dgram_v4`, `function build_orig_dgram_v6`.
- 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.