mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-12 03:29:06 +08:00
tools: bpftool: print netfilter link info
Dump protocol family, hook and priority value:
$ bpftool link
2: netfilter prog 14
ip input prio -128
pids install(3264)
5: netfilter prog 14
ip6 forward prio 21
pids a.out(3387)
9: netfilter prog 14
ip prerouting prio 123
pids a.out(5700)
10: netfilter prog 14
ip input prio 21
pids test2(5701)
v2: Quentin Monnet suggested to also add 'bpftool net' support:
$ bpftool net
xdp:
tc:
flow_dissector:
netfilter:
ip prerouting prio 21 prog_id 14
ip input prio -128 prog_id 14
ip input prio 21 prog_id 14
ip forward prio 21 prog_id 14
ip output prio 21 prog_id 14
ip postrouting prio 21 prog_id 14
'bpftool net' only dumps netfilter link type, links are sorted by protocol
family, hook and priority.
v5: fix bpf ci failure: libbpf needs small update to prog_type_name[]
and probe_prog_load helper.
v4: don't fail with -EOPNOTSUPP in libbpf probe_prog_load, update
prog_type_name[] with "netfilter" entry (bpf ci)
v3: fix bpf.h copy, 'reserved' member was removed (Alexei)
use p_err, not fprintf (Quentin)
Suggested-by: Quentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/bpf/eeeaac99-9053-90c2-aa33-cc1ecb1ae9ca@isovalent.com/
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Link: https://lore.kernel.org/r/20230421170300.24115-6-fw@strlen.de
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Müller <deso@posteo.net>
This commit is contained in:
committed by
Andrii Nakryiko
parent
3f591a6610
commit
1c9aa4791a
@@ -986,6 +986,7 @@ enum bpf_prog_type {
|
|||||||
BPF_PROG_TYPE_LSM,
|
BPF_PROG_TYPE_LSM,
|
||||||
BPF_PROG_TYPE_SK_LOOKUP,
|
BPF_PROG_TYPE_SK_LOOKUP,
|
||||||
BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */
|
BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */
|
||||||
|
BPF_PROG_TYPE_NETFILTER,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum bpf_attach_type {
|
enum bpf_attach_type {
|
||||||
@@ -1050,6 +1051,7 @@ enum bpf_link_type {
|
|||||||
BPF_LINK_TYPE_PERF_EVENT = 7,
|
BPF_LINK_TYPE_PERF_EVENT = 7,
|
||||||
BPF_LINK_TYPE_KPROBE_MULTI = 8,
|
BPF_LINK_TYPE_KPROBE_MULTI = 8,
|
||||||
BPF_LINK_TYPE_STRUCT_OPS = 9,
|
BPF_LINK_TYPE_STRUCT_OPS = 9,
|
||||||
|
BPF_LINK_TYPE_NETFILTER = 10,
|
||||||
|
|
||||||
MAX_BPF_LINK_TYPE,
|
MAX_BPF_LINK_TYPE,
|
||||||
};
|
};
|
||||||
@@ -1560,6 +1562,12 @@ union bpf_attr {
|
|||||||
*/
|
*/
|
||||||
__u64 cookie;
|
__u64 cookie;
|
||||||
} tracing;
|
} tracing;
|
||||||
|
struct {
|
||||||
|
__u32 pf;
|
||||||
|
__u32 hooknum;
|
||||||
|
__s32 priority;
|
||||||
|
__u32 flags;
|
||||||
|
} netfilter;
|
||||||
};
|
};
|
||||||
} link_create;
|
} link_create;
|
||||||
|
|
||||||
@@ -6410,6 +6418,12 @@ struct bpf_link_info {
|
|||||||
struct {
|
struct {
|
||||||
__u32 map_id;
|
__u32 map_id;
|
||||||
} struct_ops;
|
} struct_ops;
|
||||||
|
struct {
|
||||||
|
__u32 pf;
|
||||||
|
__u32 hooknum;
|
||||||
|
__s32 priority;
|
||||||
|
__u32 flags;
|
||||||
|
} netfilter;
|
||||||
};
|
};
|
||||||
} __attribute__((aligned(8)));
|
} __attribute__((aligned(8)));
|
||||||
|
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ static const char * const link_type_name[] = {
|
|||||||
[BPF_LINK_TYPE_PERF_EVENT] = "perf_event",
|
[BPF_LINK_TYPE_PERF_EVENT] = "perf_event",
|
||||||
[BPF_LINK_TYPE_KPROBE_MULTI] = "kprobe_multi",
|
[BPF_LINK_TYPE_KPROBE_MULTI] = "kprobe_multi",
|
||||||
[BPF_LINK_TYPE_STRUCT_OPS] = "struct_ops",
|
[BPF_LINK_TYPE_STRUCT_OPS] = "struct_ops",
|
||||||
|
[BPF_LINK_TYPE_NETFILTER] = "netfilter",
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char * const map_type_name[] = {
|
static const char * const map_type_name[] = {
|
||||||
@@ -201,6 +202,7 @@ static const char * const prog_type_name[] = {
|
|||||||
[BPF_PROG_TYPE_LSM] = "lsm",
|
[BPF_PROG_TYPE_LSM] = "lsm",
|
||||||
[BPF_PROG_TYPE_SK_LOOKUP] = "sk_lookup",
|
[BPF_PROG_TYPE_SK_LOOKUP] = "sk_lookup",
|
||||||
[BPF_PROG_TYPE_SYSCALL] = "syscall",
|
[BPF_PROG_TYPE_SYSCALL] = "syscall",
|
||||||
|
[BPF_PROG_TYPE_NETFILTER] = "netfilter",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __base_pr(enum libbpf_print_level level, const char *format,
|
static int __base_pr(enum libbpf_print_level level, const char *format,
|
||||||
@@ -8710,6 +8712,7 @@ static const struct bpf_sec_def section_defs[] = {
|
|||||||
SEC_DEF("struct_ops+", STRUCT_OPS, 0, SEC_NONE),
|
SEC_DEF("struct_ops+", STRUCT_OPS, 0, SEC_NONE),
|
||||||
SEC_DEF("struct_ops.s+", STRUCT_OPS, 0, SEC_SLEEPABLE),
|
SEC_DEF("struct_ops.s+", STRUCT_OPS, 0, SEC_SLEEPABLE),
|
||||||
SEC_DEF("sk_lookup", SK_LOOKUP, BPF_SK_LOOKUP, SEC_ATTACHABLE),
|
SEC_DEF("sk_lookup", SK_LOOKUP, BPF_SK_LOOKUP, SEC_ATTACHABLE),
|
||||||
|
SEC_DEF("netfilter", NETFILTER, 0, SEC_NONE),
|
||||||
};
|
};
|
||||||
|
|
||||||
static size_t custom_sec_def_cnt;
|
static size_t custom_sec_def_cnt;
|
||||||
|
|||||||
@@ -180,6 +180,7 @@ static int probe_prog_load(enum bpf_prog_type prog_type,
|
|||||||
case BPF_PROG_TYPE_SK_REUSEPORT:
|
case BPF_PROG_TYPE_SK_REUSEPORT:
|
||||||
case BPF_PROG_TYPE_FLOW_DISSECTOR:
|
case BPF_PROG_TYPE_FLOW_DISSECTOR:
|
||||||
case BPF_PROG_TYPE_CGROUP_SYSCTL:
|
case BPF_PROG_TYPE_CGROUP_SYSCTL:
|
||||||
|
case BPF_PROG_TYPE_NETFILTER:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|||||||
Reference in New Issue
Block a user