tools/testing/selftests/net/lib/xdp_native.bpf.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/lib/xdp_native.bpf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/lib/xdp_native.bpf.c- Extension
.c- Size
- 15043 bytes
- Lines
- 686
- 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
stddef.hlinux/bpf.hlinux/in.hlinux/if_ether.hlinux/ip.hlinux/ipv6.hlinux/udp.hbpf/bpf_endian.hbpf/bpf_helpers.h
Detected Declarations
function minfunction record_statsfunction xdp_mode_passfunction xdp_mode_drop_handlerfunction swap_machdrfunction xdp_mode_tx_handlerfunction csum_fold_helperfunction csum_fold_udp_helperfunction xdp_adjst_tail_shrnk_datafunction xdp_adjst_tail_grow_datafunction xdp_adjst_tailfunction xdp_adjst_head_shrnk_datafunction xdp_adjst_head_grow_datafunction xdp_head_adjstfunction xdp_prog_commonfunction xdp_progfunction xdp_prog_frags
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <stddef.h>
#include <linux/bpf.h>
#include <linux/in.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/udp.h>
#include <bpf/bpf_endian.h>
#include <bpf/bpf_helpers.h>
#define MAX_ADJST_OFFSET 256
#define MAX_PAYLOAD_LEN 5000
#define MAX_HDR_LEN 64
extern int bpf_xdp_pull_data(struct xdp_md *xdp, __u32 len) __ksym __weak;
enum {
XDP_MODE = 0,
XDP_PORT = 1,
XDP_ADJST_OFFSET = 2,
XDP_ADJST_TAG = 3,
} xdp_map_setup_keys;
enum {
XDP_MODE_PASS = 0,
XDP_MODE_DROP = 1,
XDP_MODE_TX = 2,
XDP_MODE_TAIL_ADJST = 3,
XDP_MODE_HEAD_ADJST = 4,
} xdp_map_modes;
enum {
STATS_RX = 0,
STATS_PASS = 1,
STATS_DROP = 2,
STATS_TX = 3,
STATS_ABORT = 4,
} xdp_stats;
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 5);
__type(key, __u32);
__type(value, __s32);
} map_xdp_setup SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 5);
__type(key, __u32);
__type(value, __u64);
} map_xdp_stats SEC(".maps");
static __u32 min(__u32 a, __u32 b)
{
return a < b ? a : b;
}
static void record_stats(struct xdp_md *ctx, __u32 stat_type)
{
__u64 *count;
count = bpf_map_lookup_elem(&map_xdp_stats, &stat_type);
if (count)
__sync_fetch_and_add(count, 1);
}
static struct udphdr *filter_udphdr(struct xdp_md *ctx, __u16 port)
{
struct udphdr *udph = NULL;
void *data, *data_end;
struct ethhdr *eth;
int err;
err = bpf_xdp_pull_data(ctx, sizeof(*eth));
if (err)
return NULL;
data_end = (void *)(long)ctx->data_end;
data = eth = (void *)(long)ctx->data;
if (data + sizeof(*eth) > data_end)
return NULL;
if (eth->h_proto == bpf_htons(ETH_P_IP)) {
struct iphdr *iph;
Annotation
- Immediate include surface: `stddef.h`, `linux/bpf.h`, `linux/in.h`, `linux/if_ether.h`, `linux/ip.h`, `linux/ipv6.h`, `linux/udp.h`, `bpf/bpf_endian.h`.
- Detected declarations: `function min`, `function record_stats`, `function xdp_mode_pass`, `function xdp_mode_drop_handler`, `function swap_machdr`, `function xdp_mode_tx_handler`, `function csum_fold_helper`, `function csum_fold_udp_helper`, `function xdp_adjst_tail_shrnk_data`, `function xdp_adjst_tail_grow_data`.
- 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.