tools/bpf/bpftool/common.c
Source file repositories/reference/linux-study-clean/tools/bpf/bpftool/common.c
File Facts
- System
- Linux kernel
- Corpus path
tools/bpf/bpftool/common.c- Extension
.c- Size
- 27682 bytes
- Lines
- 1305
- 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
assert.hctype.herrno.hfcntl.hftw.hlibgen.hmntent.hstdbool.hstdio.hstdlib.hstring.hunistd.hnet/if.hsys/mount.hsys/resource.hsys/stat.hsys/vfs.hsys/utsname.hlinux/filter.hlinux/limits.hlinux/magic.hlinux/unistd.hbpf/bpf.hbpf/hashmap.hbpf/libbpf.hbpf/btf.hzlib.hmain.h
Detected Declarations
function p_errfunction p_infofunction is_bpffsfunction known_to_need_rlimitfunction set_max_rlimitfunction mnt_fsfunction mount_tracefsfunction open_obj_pinnedfunction open_obj_pinned_anyfunction create_and_mount_bpffs_dirfunction mount_bpffs_for_filefunction do_pin_fdfunction do_pin_anyfunction get_prog_full_namefunction get_fd_typefunction print_data_jsonfunction print_hex_data_jsonfunction do_build_table_cbfunction build_pinned_obj_tablefunction delete_pinned_obj_tablefunction get_page_sizefunction get_possible_cpusfunction ifindex_to_name_nsfunction read_sysfs_hex_intfunction read_sysfs_netdev_hex_intfunction ifindex_to_archfunction print_dev_plainfunction print_dev_jsonfunction parse_u32_argfunction __printffunction prog_fd_by_nametagfunction prog_parse_fdsfunction prog_parse_fdfunction map_fd_by_namefunction map_parse_fdsfunction map_parse_fdfunction map_parse_fd_and_infofunction hash_fn_for_key_as_idfunction equal_fn_for_key_as_idfunction pathname_concatfunction read_next_kernel_config_optionfunction read_kernel_config
Annotated Snippet
case BPF_CGROUP_INET_SOCK_CREATE: return "sock_create";
case BPF_CGROUP_INET_SOCK_RELEASE: return "sock_release";
case BPF_CGROUP_SOCK_OPS: return "sock_ops";
case BPF_CGROUP_DEVICE: return "device";
case BPF_CGROUP_INET4_BIND: return "bind4";
case BPF_CGROUP_INET6_BIND: return "bind6";
case BPF_CGROUP_INET4_CONNECT: return "connect4";
case BPF_CGROUP_INET6_CONNECT: return "connect6";
case BPF_CGROUP_INET4_POST_BIND: return "post_bind4";
case BPF_CGROUP_INET6_POST_BIND: return "post_bind6";
case BPF_CGROUP_INET4_GETPEERNAME: return "getpeername4";
case BPF_CGROUP_INET6_GETPEERNAME: return "getpeername6";
case BPF_CGROUP_INET4_GETSOCKNAME: return "getsockname4";
case BPF_CGROUP_INET6_GETSOCKNAME: return "getsockname6";
case BPF_CGROUP_UDP4_SENDMSG: return "sendmsg4";
case BPF_CGROUP_UDP6_SENDMSG: return "sendmsg6";
case BPF_CGROUP_SYSCTL: return "sysctl";
case BPF_CGROUP_UDP4_RECVMSG: return "recvmsg4";
case BPF_CGROUP_UDP6_RECVMSG: return "recvmsg6";
case BPF_CGROUP_GETSOCKOPT: return "getsockopt";
case BPF_CGROUP_SETSOCKOPT: return "setsockopt";
case BPF_TRACE_RAW_TP: return "raw_tp";
case BPF_TRACE_FENTRY: return "fentry";
case BPF_TRACE_FEXIT: return "fexit";
case BPF_MODIFY_RETURN: return "mod_ret";
case BPF_TRACE_FSESSION: return "fsession";
case BPF_SK_REUSEPORT_SELECT: return "sk_skb_reuseport_select";
case BPF_SK_REUSEPORT_SELECT_OR_MIGRATE: return "sk_skb_reuseport_select_or_migrate";
default: return libbpf_bpf_attach_type_str(t);
}
}
int pathname_concat(char *buf, int buf_sz, const char *path,
const char *name)
{
int len;
len = snprintf(buf, buf_sz, "%s/%s", path, name);
if (len < 0)
return -EINVAL;
if (len >= buf_sz)
return -ENAMETOOLONG;
return 0;
}
static bool read_next_kernel_config_option(gzFile file, char *buf, size_t n,
char **value)
{
char *sep;
while (gzgets(file, buf, n)) {
if (strncmp(buf, "CONFIG_", 7))
continue;
sep = strchr(buf, '=');
if (!sep)
continue;
/* Trim ending '\n' */
buf[strlen(buf) - 1] = '\0';
/* Split on '=' and ensure that a value is present. */
*sep = '\0';
if (!sep[1])
continue;
*value = sep + 1;
return true;
}
return false;
}
int read_kernel_config(const struct kernel_config_option *requested_options,
size_t num_options, char **out_values,
const char *define_prefix)
{
struct utsname utsn;
char path[PATH_MAX];
gzFile file = NULL;
char buf[4096];
char *value;
size_t i;
int ret = 0;
if (!requested_options || !out_values || num_options == 0)
return -1;
if (!uname(&utsn)) {
Annotation
- Immediate include surface: `assert.h`, `ctype.h`, `errno.h`, `fcntl.h`, `ftw.h`, `libgen.h`, `mntent.h`, `stdbool.h`.
- Detected declarations: `function p_err`, `function p_info`, `function is_bpffs`, `function known_to_need_rlimit`, `function set_max_rlimit`, `function mnt_fs`, `function mount_tracefs`, `function open_obj_pinned`, `function open_obj_pinned_any`, `function create_and_mount_bpffs_dir`.
- 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.