tools/bpf/bpftool/net.c
Source file repositories/reference/linux-study-clean/tools/bpf/bpftool/net.c
File Facts
- System
- Linux kernel
- Corpus path
tools/bpf/bpftool/net.c- Extension
.c- Size
- 24739 bytes
- Lines
- 1048
- 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
errno.hfcntl.hstdlib.hstring.htime.hunistd.hbpf/bpf.hbpf/libbpf.hnet/if.hlinux/rtnetlink.hlinux/socket.hlinux/tc_act/tc_bpf.hsys/socket.hsys/stat.hsys/types.hbpf/nlattr.hmain.hnetlink_dumper.h
Detected Declarations
struct ip_devname_ifindexstruct bpf_netdev_tstruct tc_kind_handlestruct bpf_tcinfo_tstruct bpf_filter_tstruct bpf_attach_infoenum net_attach_typefunction parse_attach_typefunction netlink_openfunction netlink_recvfunction __dump_class_nlmsgfunction netlink_get_classfunction __dump_qdisc_nlmsgfunction netlink_get_qdiscfunction __dump_filter_nlmsgfunction netlink_get_filterfunction __dump_link_nlmsgfunction netlink_get_linkfunction dump_link_nlmsgfunction dump_class_qdisc_nlmsgfunction dump_filter_nlmsgfunction __show_dev_tc_bpf_namefunction __show_dev_tc_bpffunction show_dev_tc_bpffunction show_dev_tc_bpf_classicfunction query_flow_dissectorfunction net_parse_devfunction do_attach_detach_xdpfunction get_tcx_typefunction do_attach_tcxfunction do_detach_tcxfunction do_attachfunction do_detachfunction netfilter_link_comparfunction show_link_netfilterfunction do_showfunction do_helpfunction do_net
Annotated Snippet
struct ip_devname_ifindex {
char devname[64];
int ifindex;
};
struct bpf_netdev_t {
struct ip_devname_ifindex *devices;
int used_len;
int array_len;
int filter_idx;
};
struct tc_kind_handle {
char kind[64];
int handle;
};
struct bpf_tcinfo_t {
struct tc_kind_handle *handle_array;
int used_len;
int array_len;
bool is_qdisc;
};
struct bpf_filter_t {
const char *kind;
const char *devname;
int ifindex;
};
struct bpf_attach_info {
__u32 flow_dissector_id;
};
enum net_attach_type {
NET_ATTACH_TYPE_XDP,
NET_ATTACH_TYPE_XDP_GENERIC,
NET_ATTACH_TYPE_XDP_DRIVER,
NET_ATTACH_TYPE_XDP_OFFLOAD,
NET_ATTACH_TYPE_TCX_INGRESS,
NET_ATTACH_TYPE_TCX_EGRESS,
};
static const char * const attach_type_strings[] = {
[NET_ATTACH_TYPE_XDP] = "xdp",
[NET_ATTACH_TYPE_XDP_GENERIC] = "xdpgeneric",
[NET_ATTACH_TYPE_XDP_DRIVER] = "xdpdrv",
[NET_ATTACH_TYPE_XDP_OFFLOAD] = "xdpoffload",
[NET_ATTACH_TYPE_TCX_INGRESS] = "tcx_ingress",
[NET_ATTACH_TYPE_TCX_EGRESS] = "tcx_egress",
};
static const char * const attach_loc_strings[] = {
[BPF_TCX_INGRESS] = "tcx/ingress",
[BPF_TCX_EGRESS] = "tcx/egress",
[BPF_NETKIT_PRIMARY] = "netkit/primary",
[BPF_NETKIT_PEER] = "netkit/peer",
};
const size_t net_attach_type_size = ARRAY_SIZE(attach_type_strings);
static enum net_attach_type parse_attach_type(const char *str)
{
enum net_attach_type type;
for (type = 0; type < net_attach_type_size; type++) {
if (attach_type_strings[type] &&
is_prefix(str, attach_type_strings[type]))
return type;
}
return net_attach_type_size;
}
typedef int (*dump_nlmsg_t)(void *cookie, void *msg, struct nlattr **tb);
typedef int (*__dump_nlmsg_t)(struct nlmsghdr *nlmsg, dump_nlmsg_t, void *cookie);
static int netlink_open(__u32 *nl_pid)
{
struct sockaddr_nl sa;
socklen_t addrlen;
int one = 1, ret;
int sock;
memset(&sa, 0, sizeof(sa));
sa.nl_family = AF_NETLINK;
sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock < 0)
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `stdlib.h`, `string.h`, `time.h`, `unistd.h`, `bpf/bpf.h`, `bpf/libbpf.h`.
- Detected declarations: `struct ip_devname_ifindex`, `struct bpf_netdev_t`, `struct tc_kind_handle`, `struct bpf_tcinfo_t`, `struct bpf_filter_t`, `struct bpf_attach_info`, `enum net_attach_type`, `function parse_attach_type`, `function netlink_open`, `function netlink_recv`.
- 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.