tools/testing/selftests/net/lib/gro.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/lib/gro.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/lib/gro.c- Extension
.c- Size
- 60130 bytes
- Lines
- 1920
- 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.herrno.herror.hgetopt.hnet/ethernet.hnet/if.hlinux/filter.hlinux/if_packet.hlinux/if_pppox.hlinux/ipv6.hlinux/net_tstamp.hlinux/ppp_defs.hnetinet/in.hnetinet/ip.hnetinet/ip6.hnetinet/tcp.hstdbool.hstddef.hstdio.hstdarg.hstring.htime.hunistd.hkselftest.hksft.h
Detected Declarations
struct pppoe_ppp_hdrstruct pseudo_header6struct pseudo_header4struct tcp_option_tsstruct tcp_option_windowenum flush_id_casefunction max_payloadfunction calc_mssfunction num_large_pktfunction vlogfunction fill_pppoelayerfunction setup_sock_filterfunction strcmpfunction checksum_nofoldfunction checksum_foldfunction tcp_checksumfunction read_MACfunction fill_datalinklayerfunction fill_networklayerfunction fill_transportlayerfunction write_packetfunction create_packetfunction create_capacity_packetfunction send_capacityfunction set_flagsfunction send_flagsfunction send_data_pktsfunction send_largefunction send_ackfunction recompute_packetfunction tcp_write_optionsfunction add_standard_tcp_optionsfunction send_changed_checksumfunction send_changed_ip_checksumfunction send_changed_seqfunction send_changed_tsfunction send_diff_optfunction add_ipv4_ts_optionfunction add_ipv6_exthdrfunction fix_ip4_checksumfunction send_flush_id_casefunction send_ipv6_exthdrfunction send_ip_optionsfunction send_fragment4function send_changed_ttlfunction send_changed_tosfunction send_changed_ECNfunction send_fragment6
Annotated Snippet
struct pppoe_ppp_hdr {
struct pppoe_hdr eh;
__be16 proto;
} *ph = buf;
payload_len += sizeof(struct tcphdr);
ph->eh.type = 1;
ph->eh.ver = 1;
ph->eh.code = 0;
ph->eh.sid = htons(sid);
ph->eh.length = htons(payload_len + sizeof(ph->proto));
ph->proto = htons(proto == PF_INET ? PPP_IP : PPP_IPV6);
}
static void setup_sock_filter(int fd)
{
const int dport_off = tcp_offset + offsetof(struct tcphdr, dest);
const int ethproto_off = offsetof(struct ethhdr, h_proto);
int optlen = 0;
int ipproto_off, opt_ipproto_off;
if (proto == PF_INET)
ipproto_off = tcp_offset - sizeof(struct iphdr) +
offsetof(struct iphdr, protocol);
else
ipproto_off = tcp_offset - sizeof(struct ipv6hdr) +
offsetof(struct ipv6hdr, nexthdr);
/* Overridden later if exthdrs are used: */
opt_ipproto_off = ipproto_off;
if (strcmp(testname, "ip_opt") == 0) {
optlen = sizeof(struct ip_timestamp);
} else if (strcmp(testname, "ip_frag6") == 0 ||
strcmp(testname, "ip_v6ext_same") == 0 ||
strcmp(testname, "ip_v6ext_diff") == 0) {
BUILD_BUG_ON(sizeof(struct ip6_hbh) > MIN_EXTHDR_SIZE);
BUILD_BUG_ON(sizeof(struct ip6_dest) > MIN_EXTHDR_SIZE);
BUILD_BUG_ON(sizeof(struct ip6_frag) > MIN_EXTHDR_SIZE);
/* same size for HBH and Fragment extension header types */
optlen = MIN_EXTHDR_SIZE;
opt_ipproto_off = ETH_HLEN + sizeof(struct ipv6hdr)
+ offsetof(struct ip6_ext, ip6e_nxt);
}
/* this filter validates the following:
* - packet is IPv4/IPv6 according to the running test.
* - packet is TCP. Also handles the case of one extension header and then TCP.
* - checks the packet tcp dport equals to DPORT. Also handles the case of one
* extension header and then TCP.
*/
struct sock_filter filter[] = {
BPF_STMT(BPF_LD + BPF_H + BPF_ABS, ethproto_off),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ntohs(ethhdr_proto), 0, 9),
BPF_STMT(BPF_LD + BPF_B + BPF_ABS, ipproto_off),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_TCP, 2, 0),
BPF_STMT(BPF_LD + BPF_B + BPF_ABS, opt_ipproto_off),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_TCP, 0, 5),
BPF_STMT(BPF_LD + BPF_H + BPF_ABS, dport_off),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, DPORT, 2, 0),
BPF_STMT(BPF_LD + BPF_H + BPF_ABS, dport_off + optlen),
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, DPORT, 0, 1),
BPF_STMT(BPF_RET + BPF_K, 0xFFFFFFFF),
BPF_STMT(BPF_RET + BPF_K, 0),
};
struct sock_fprog bpf = {
.len = ARRAY_SIZE(filter),
.filter = filter,
};
if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &bpf, sizeof(bpf)) < 0)
error(1, errno, "error setting filter");
}
static uint32_t checksum_nofold(void *data, size_t len, uint32_t sum)
{
uint16_t *words = data;
int i;
for (i = 0; i < len / 2; i++)
sum += words[i];
if (len & 1)
sum += ((char *)data)[len - 1];
return sum;
}
static uint16_t checksum_fold(void *data, size_t len, uint32_t sum)
{
Annotation
- Immediate include surface: `arpa/inet.h`, `errno.h`, `error.h`, `getopt.h`, `net/ethernet.h`, `net/if.h`, `linux/filter.h`, `linux/if_packet.h`.
- Detected declarations: `struct pppoe_ppp_hdr`, `struct pseudo_header6`, `struct pseudo_header4`, `struct tcp_option_ts`, `struct tcp_option_window`, `enum flush_id_case`, `function max_payload`, `function calc_mss`, `function num_large_pkt`, `function vlog`.
- 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.