tools/testing/selftests/bpf/test_tag.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/test_tag.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/test_tag.c- Extension
.c- Size
- 4419 bytes
- Lines
- 207
- 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
stdint.hstdio.hstdlib.hctype.htime.herrno.hunistd.hstring.hsched.hlimits.hassert.hsys/socket.hlinux/filter.hlinux/bpf.hlinux/if_alg.hbpf/bpf.h../../../include/linux/filter.htesting_helpers.h
Detected Declarations
function bpf_gen_imm_progfunction bpf_gen_map_progfunction bpf_try_load_progfunction __hex2binfunction hex2binfunction tag_from_fdinfofunction tag_from_algfunction tag_dumpfunction tag_exit_reportfunction do_testfunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <sched.h>
#include <limits.h>
#include <assert.h>
#include <sys/socket.h>
#include <linux/filter.h>
#include <linux/bpf.h>
#include <linux/if_alg.h>
#include <bpf/bpf.h>
#include "../../../include/linux/filter.h"
#include "testing_helpers.h"
static struct bpf_insn prog[BPF_MAXINSNS];
static void bpf_gen_imm_prog(unsigned int insns, int fd_map)
{
int i;
srand(time(NULL));
for (i = 0; i < insns; i++)
prog[i] = BPF_ALU64_IMM(BPF_MOV, i % BPF_REG_10, rand());
prog[i - 1] = BPF_EXIT_INSN();
}
static void bpf_gen_map_prog(unsigned int insns, int fd_map)
{
int i, j = 0;
for (i = 0; i + 1 < insns; i += 2) {
struct bpf_insn tmp[] = {
BPF_LD_MAP_FD(j++ % BPF_REG_10, fd_map)
};
memcpy(&prog[i], tmp, sizeof(tmp));
}
if (insns % 2 == 0)
prog[insns - 2] = BPF_ALU64_IMM(BPF_MOV, i % BPF_REG_10, 42);
prog[insns - 1] = BPF_EXIT_INSN();
}
static int bpf_try_load_prog(int insns, int fd_map,
void (*bpf_filler)(unsigned int insns,
int fd_map))
{
int fd_prog;
bpf_filler(insns, fd_map);
fd_prog = bpf_test_load_program(BPF_PROG_TYPE_SCHED_CLS, prog, insns, "", 0,
NULL, 0);
assert(fd_prog > 0);
if (fd_map > 0)
bpf_filler(insns, 0);
return fd_prog;
}
static int __hex2bin(char ch)
{
if ((ch >= '0') && (ch <= '9'))
return ch - '0';
ch = tolower(ch);
if ((ch >= 'a') && (ch <= 'f'))
return ch - 'a' + 10;
return -1;
}
static int hex2bin(uint8_t *dst, const char *src, size_t count)
{
while (count--) {
int hi = __hex2bin(*src++);
int lo = __hex2bin(*src++);
if ((hi < 0) || (lo < 0))
return -1;
*dst++ = (hi << 4) | lo;
}
return 0;
}
Annotation
- Immediate include surface: `stdint.h`, `stdio.h`, `stdlib.h`, `ctype.h`, `time.h`, `errno.h`, `unistd.h`, `string.h`.
- Detected declarations: `function bpf_gen_imm_prog`, `function bpf_gen_map_prog`, `function bpf_try_load_prog`, `function __hex2bin`, `function hex2bin`, `function tag_from_fdinfo`, `function tag_from_alg`, `function tag_dump`, `function tag_exit_report`, `function do_test`.
- 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.