tools/bpf/bpftool/feature.c
Source file repositories/reference/linux-study-clean/tools/bpf/bpftool/feature.c
File Facts
- System
- Linux kernel
- Corpus path
tools/bpf/bpftool/feature.c- Extension
.c- Size
- 31126 bytes
- Lines
- 1287
- 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
ctype.herrno.hfcntl.hstring.hunistd.hnet/if.hsys/capability.hsys/vfs.hlinux/filter.hlinux/limits.hbpf/bpf.hbpf/libbpf.hmain.h
Detected Declarations
enum probe_componentfunction grepfunction check_procfsfunction uppercasefunction print_bool_featurefunction print_kernel_optionfunction print_start_sectionfunction print_end_sectionfunction get_vendor_idfunction read_procfsfunction probe_unprivileged_disabledfunction probe_jit_enablefunction probe_jit_hardenfunction probe_jit_kallsymsfunction probe_jit_limitfunction probe_kernel_image_configfunction probe_bpf_syscallfunction probe_prog_load_ifindexfunction probe_prog_type_ifindexfunction probe_prog_typefunction probe_map_type_ifindexfunction probe_map_typefunction probe_helper_ifindexfunction probe_helper_for_progtypefunction probe_helpers_for_progtypefunction probe_misc_featurefunction commitfunction probe_bounded_loopsfunction probe_v2_isa_extensionfunction probe_v3_isa_extensionfunction probe_v4_isa_extensionfunction section_system_configfunction section_syscall_configfunction section_program_typesfunction section_map_typesfunction section_helpersfunction section_miscfunction handle_permsfunction do_probefunction do_list_builtinsfunction do_helpfunction do_feature
Annotated Snippet
if (!value) {
jsonw_null_field(json_wtr, name);
return;
}
errno = 0;
res = strtol(value, &endptr, 0);
if (!errno && *endptr == '\n')
jsonw_int_field(json_wtr, name, res);
else
jsonw_string_field(json_wtr, name, value);
} else if (define_prefix) {
if (value)
printf("#define %s%s %s\n", define_prefix,
name, value);
else
printf("/* %s%s is not set */\n", define_prefix, name);
} else {
if (value)
printf("%s is set to %s\n", name, value);
else
printf("%s is not set\n", name);
}
}
static void
print_start_section(const char *json_title, const char *plain_title,
const char *define_comment, const char *define_prefix)
{
if (json_output) {
jsonw_name(json_wtr, json_title);
jsonw_start_object(json_wtr);
} else if (define_prefix) {
printf("%s\n", define_comment);
} else {
printf("%s\n", plain_title);
}
}
static void print_end_section(void)
{
if (json_output)
jsonw_end_object(json_wtr);
else
printf("\n");
}
/* Probing functions */
static int get_vendor_id(int ifindex)
{
char ifname[IF_NAMESIZE], path[64], buf[8];
ssize_t len;
int fd;
if (!if_indextoname(ifindex, ifname))
return -1;
snprintf(path, sizeof(path), "/sys/class/net/%s/device/vendor", ifname);
fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return -1;
len = read(fd, buf, sizeof(buf));
close(fd);
if (len < 0)
return -1;
if (len >= (ssize_t)sizeof(buf))
return -1;
buf[len] = '\0';
return strtol(buf, NULL, 0);
}
static long read_procfs(const char *path)
{
char *endptr, *line = NULL;
size_t len = 0;
FILE *fd;
long res;
fd = fopen(path, "r");
if (!fd)
return -1;
res = getline(&line, &len, fd);
fclose(fd);
if (res < 0)
return -1;
Annotation
- Immediate include surface: `ctype.h`, `errno.h`, `fcntl.h`, `string.h`, `unistd.h`, `net/if.h`, `sys/capability.h`, `sys/vfs.h`.
- Detected declarations: `enum probe_component`, `function grep`, `function check_procfs`, `function uppercase`, `function print_bool_feature`, `function print_kernel_option`, `function print_start_section`, `function print_end_section`, `function get_vendor_id`, `function read_procfs`.
- 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.