tools/testing/selftests/bpf/progs/xdpwall.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/xdpwall.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/progs/xdpwall.c
Extension
.c
Size
7914 bytes
Lines
365
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct v4_lpm_key {
	__u32 prefixlen;
	__u32 src;
};

struct v4_lpm_val {
	struct v4_lpm_key key;
	__u8 val;
};

struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__uint(max_entries, 16);
	__type(key, struct in6_addr);
	__type(value, bool);
} v6_addr_map SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_HASH);
	__uint(max_entries, 16);
	__type(key, __u32);
	__type(value, bool);
} v4_addr_map SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_LPM_TRIE);
	__uint(max_entries, 16);
	__uint(key_size, sizeof(struct v4_lpm_key));
	__uint(value_size, sizeof(struct v4_lpm_val));
	__uint(map_flags, BPF_F_NO_PREALLOC);
} v4_lpm_val_map SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__uint(max_entries, 16);
	__type(key, int);
	__type(value, __u8);
} tcp_port_map SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_ARRAY);
	__uint(max_entries, 16);
	__type(key, int);
	__type(value, __u16);
} udp_port_map SEC(".maps");

enum ip_type { V4 = 1, V6 = 2 };

struct fw_match_info {
	__u8 v4_src_ip_match;
	__u8 v6_src_ip_match;
	__u8 v4_src_prefix_match;
	__u8 v4_dst_prefix_match;
	__u8 tcp_dp_match;
	__u16 udp_sp_match;
	__u16 udp_dp_match;
	bool is_tcp;
	bool is_tcp_syn;
};

struct pkt_info {
	enum ip_type type;
	union {
		struct iphdr *ipv4;
		struct ipv6hdr *ipv6;
	} ip;
	int sport;
	int dport;
	__u16 trans_hdr_offset;
	__u8 proto;
	__u8 flags;
};

static __always_inline struct ethhdr *parse_ethhdr(void *data, void *data_end)
{
	struct ethhdr *eth = data;

	if (eth + 1 > data_end)
		return NULL;

	return eth;
}

static __always_inline __u8 filter_ipv6_addr(const struct in6_addr *ipv6addr)
{
	__u8 *leaf;

	leaf = bpf_map_lookup_elem(&v6_addr_map, ipv6addr);

	return leaf ? *leaf : 0;

Annotation

Implementation Notes