tools/testing/selftests/bpf/progs/test_sockmap_change_tail.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/test_sockmap_change_tail.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/test_sockmap_change_tail.c- Extension
.c- Size
- 1085 bytes
- Lines
- 46
- 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
vmlinux.hbpf/bpf_helpers.h
Detected Declarations
function prog_skb_verdict
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2024 ByteDance */
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#ifndef PAGE_SIZE
#define PAGE_SIZE __PAGE_SIZE
#endif
#define BPF_SKB_MAX_LEN (PAGE_SIZE << 2)
struct {
__uint(type, BPF_MAP_TYPE_SOCKMAP);
__uint(max_entries, 1);
__type(key, int);
__type(value, int);
} sock_map_rx SEC(".maps");
long change_tail_ret = 1;
SEC("sk_skb")
int prog_skb_verdict(struct __sk_buff *skb)
{
char *data, *data_end;
bpf_skb_pull_data(skb, 1);
data = (char *)(unsigned long)skb->data;
data_end = (char *)(unsigned long)skb->data_end;
if (data + 1 > data_end)
return SK_PASS;
if (data[0] == 'T') { /* Trim the packet */
change_tail_ret = bpf_skb_change_tail(skb, skb->len - 1, 0);
return SK_PASS;
} else if (data[0] == 'G') { /* Grow the packet */
change_tail_ret = bpf_skb_change_tail(skb, skb->len + 1, 0);
return SK_PASS;
} else if (data[0] == 'E') { /* Error */
change_tail_ret = bpf_skb_change_tail(skb, BPF_SKB_MAX_LEN, 0);
return SK_PASS;
}
return SK_PASS;
}
char _license[] SEC("license") = "GPL";
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`.
- Detected declarations: `function prog_skb_verdict`.
- 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.