Skip to contentSkip to conversation

Add missing types to bpftool, libbpf

PATCH Superseded Andrey Ignatov 3 participants 7 messages Apr 16, 2018 – Apr 17, 2018

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add missing types to bpftool, libbpf

Add support for various BPF prog types and attach types that have been added to kernel recently but not to bpftool or libbpf yet.

Andrey Ignatov (3):
bpftool: Add missing prog types and attach types
libbpf: Support guessing post_bind{4,6} progs
libbpf: Type functions for raw tracepoints

 tools/bpf/bpftool/cgroup.c | 19 ++++++++++++++++---
 tools/bpf/bpftool/prog.c   |  3 +++
 tools/lib/bpf/libbpf.c     |  8 ++++++++
 tools/lib/bpf/libbpf.h     |  2 ++
 4 files changed, 29 insertions(+), 3 deletions(-)
Signature · 1 line
2.9.5
#1 lore raw

PATCH 1/3 bpftool: Add missing prog types and attach types

Add missing prog types to bpftool prog and missing attach types to bpftool cgroup.

---
 tools/bpf/bpftool/cgroup.c | 19 ++++++++++++++++---
 tools/bpf/bpftool/prog.c   |  3 +++
 2 files changed, 19 insertions(+), 3 deletions(-)
tools/bpf/bpftool/cgroup.c +16 -3
index cae32a6..8689916 100644
@@ -16,15 +16,28 @@
 #define HELP_SPEC_ATTACH_FLAGS						\
 	"ATTACH_FLAGS := { multi | override }"
 
-#define HELP_SPEC_ATTACH_TYPES						\
-	"ATTACH_TYPE := { ingress | egress | sock_create | sock_ops | device }"
+#define HELP_SPEC_ATTACH_TYPES						       \
+	"       ATTACH_TYPE := { ingress | egress | sock_create |\n"	       \
+	"                        sock_ops | stream_parser |\n"		       \
+	"                        stream_verdict | device | msg_verdict |\n"    \
+	"                        bind4 | bind6 | connect4 | connect6 |\n"      \
+	"                        post_bind4 | post_bind6 }"
 
 static const char * const attach_type_strings[] = {
 	[BPF_CGROUP_INET_INGRESS] = "ingress",
 	[BPF_CGROUP_INET_EGRESS] = "egress",
 	[BPF_CGROUP_INET_SOCK_CREATE] = "sock_create",
 	[BPF_CGROUP_SOCK_OPS] = "sock_ops",
+	[BPF_SK_SKB_STREAM_PARSER] = "stream_parser",
+	[BPF_SK_SKB_STREAM_VERDICT] = "stream_verdict",
 	[BPF_CGROUP_DEVICE] = "device",
+	[BPF_SK_MSG_VERDICT] = "msg_verdict",
+	[BPF_CGROUP_INET4_BIND] = "bind4",
+	[BPF_CGROUP_INET6_BIND] = "bind6",
+	[BPF_CGROUP_INET4_CONNECT] = "connect4",
+	[BPF_CGROUP_INET6_CONNECT] = "connect6",
+	[BPF_CGROUP_INET4_POST_BIND] = "post_bind4",
+	[BPF_CGROUP_INET6_POST_BIND] = "post_bind6",
 	[__MAX_BPF_ATTACH_TYPE] = NULL,
 };
 
@@ -282,7 +295,7 @@ static int do_help(int argc, char **argv)
 		"       %s %s detach CGROUP ATTACH_TYPE PROG\n"
 		"       %s %s help\n"
 		"\n"
-		"       " HELP_SPEC_ATTACH_TYPES "\n"
+		HELP_SPEC_ATTACH_TYPES "\n"
 		"       " HELP_SPEC_ATTACH_FLAGS "\n"
 		"       " HELP_SPEC_PROGRAM "\n"
 		"       " HELP_SPEC_OPTIONS "\n"
tools/bpf/bpftool/prog.c +3 -0
index f7a8108..548adb9 100644
@@ -68,6 +68,9 @@ static const char * const prog_type_name[] = {
 	[BPF_PROG_TYPE_SOCK_OPS]	= "sock_ops",
 	[BPF_PROG_TYPE_SK_SKB]		= "sk_skb",
 	[BPF_PROG_TYPE_CGROUP_DEVICE]	= "cgroup_device",
+	[BPF_PROG_TYPE_SK_MSG]		= "sk_msg",
+	[BPF_PROG_TYPE_RAW_TRACEPOINT]	= "raw_tracepoint",
+	[BPF_PROG_TYPE_CGROUP_SOCK_ADDR] = "cgroup_sock_addr",
 };
 
 static void print_boot_time(__u64 nsecs, char *buf, unsigned int size)
Signature · 1 line
2.9.5
#2 lore raw

Re: [PATCH bpf-next 1/3] bpftool: Add missing prog types and attach types

Quoted 7 lines · Andrey Ignatov
tools/bpf/bpftool/cgroup.c +0 -0
index cae32a6..8689916 100644
@@ -16,15 +16,28 @@
 #define HELP_SPEC_ATTACH_FLAGS						\
 	"ATTACH_FLAGS := { multi | override }"

tools/bpf/bpftool/cgroup.c line 25

Quoted 10 lines
tools/bpf/bpftool/cgroup.c +6 -2
 
-#define HELP_SPEC_ATTACH_TYPES						\
-	"ATTACH_TYPE := { ingress | egress | sock_create | sock_ops | device }"
+#define HELP_SPEC_ATTACH_TYPES						       \
+	"       ATTACH_TYPE := { ingress | egress | sock_create |\n"	       \
+	"                        sock_ops | stream_parser |\n"		       \
+	"                        stream_verdict | device | msg_verdict |\n"    \
+	"                        bind4 | bind6 | connect4 | connect6 |\n"      \
+	"                        post_bind4 | post_bind6 }"
 

Would you mind updating the man page in Documentation/ as well?

Thanks!

#3 lore raw

Re: [PATCH bpf-next 1/3] bpftool: Add missing prog types and attach types

Jakub Kicinski <[email protected]> [Mon, 2018-04-16 16:53 -0700]:

Quoted 9 lines · Andrey Ignatov
Quoted 8 lines
tools/bpf/bpftool/cgroup.c +0 -0
index cae32a6..8689916 100644
@@ -16,15 +16,28 @@
 #define HELP_SPEC_ATTACH_FLAGS						\
 	"ATTACH_FLAGS := { multi | override }"
 
Quoted 11 lines

tools/bpf/bpftool/cgroup.c line 25

Quoted 9 lines
tools/bpf/bpftool/cgroup.c +6 -2
-#define HELP_SPEC_ATTACH_TYPES						\
-	"ATTACH_TYPE := { ingress | egress | sock_create | sock_ops | device }"
+#define HELP_SPEC_ATTACH_TYPES						       \
+	"       ATTACH_TYPE := { ingress | egress | sock_create |\n"	       \
+	"                        sock_ops | stream_parser |\n"		       \
+	"                        stream_verdict | device | msg_verdict |\n"    \
+	"                        bind4 | bind6 | connect4 | connect6 |\n"      \
+	"                        post_bind4 | post_bind6 }"
 

Would you mind updating the man page in Documentation/ as well?

Sure. Will update and send v2.

Signature · 1 line
Andrey Ignatov
#4 lore raw

Re: [PATCH bpf-next 1/3] bpftool: Add missing prog types and attach types

2018-04-16 16:57 UTC-0700 ~ Andrey Ignatov <[email protected]>

Quoted 22 lines

Jakub Kicinski <[email protected]> [Mon, 2018-04-16 16:53 -0700]:

Quoted 9 lines · Andrey Ignatov
Quoted 8 lines
tools/bpf/bpftool/cgroup.c +0 -0
index cae32a6..8689916 100644
@@ -16,15 +16,28 @@
 #define HELP_SPEC_ATTACH_FLAGS						\
 	"ATTACH_FLAGS := { multi | override }"
 
Quoted 11 lines

tools/bpf/bpftool/cgroup.c line 25

Quoted 9 lines
tools/bpf/bpftool/cgroup.c +6 -2
-#define HELP_SPEC_ATTACH_TYPES						\
-	"ATTACH_TYPE := { ingress | egress | sock_create | sock_ops | device }"
+#define HELP_SPEC_ATTACH_TYPES						       \
+	"       ATTACH_TYPE := { ingress | egress | sock_create |\n"	       \
+	"                        sock_ops | stream_parser |\n"		       \
+	"                        stream_verdict | device | msg_verdict |\n"    \
+	"                        bind4 | bind6 | connect4 | connect6 |\n"      \
+	"                        post_bind4 | post_bind6 }"
 

Would you mind updating the man page in Documentation/ as well?

Quoted 2 lines

Sure. Will update and send v2.

Hi Andrey,

In addition to the Documentation, there would also be the bash completion to update. The patch below should make it, please feel free to incorporate it to your changes if it seems alright to you. Otherwise I'll submit it as a follow-up.

Quentin

---

tools/bpf/bpftool/bash-completion/bpftool +5 -2
index 71cc5dec3685..dad9109c2800 100644
@@ -374,7 +374,8 @@ _bpftool()
                     ;;
                 attach|detach)
                     local ATTACH_TYPES='ingress egress sock_create sock_ops \
-                        device'
+                        stream_parser stream_verdict device msg_verdict bind4 \
+                        bind6 connect4 connect6 post_bind4 post_bind6'
                     local ATTACH_FLAGS='multi override'
                     local PROG_TYPE='id pinned tag'
                     case $prev in
@@ -382,7 +383,9 @@ _bpftool()
                             _filedir
                             return 0
                             ;;
-                        ingress|egress|sock_create|sock_ops|device)
+                        ingress|egress|sock_create|sock_ops|stream_parser|\
+                            stream_verdict|device|msg_verdict|bind4|bind6|\
+                            connect4|connect6|post_bind4|post_bind6)
                             COMPREPLY=( $( compgen -W "$PROG_TYPE" -- \
                                 "$cur" ) )
                             return 0
#5 lore raw

PATCH 2/3 libbpf: Support guessing post_bind{4,6} progs

In reply to Andrey Ignatov

libbpf can guess prog type and expected attach type based on section name. Add hints for "cgroup/post_bind4" and "cgroup/post_bind6" section names.

Existing "cgroup/sock" is not changed, i.e. expected_attach_type for it is not set to BPF_CGROUP_INET_SOCK_CREATE, for backward compatibility.

---
 tools/lib/bpf/libbpf.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/lib/bpf/libbpf.c +6 -0
index 5922443..0fcc447 100644
@@ -1859,6 +1859,9 @@ static void bpf_program__set_expected_attach_type(struct bpf_program *prog,
 
 #define BPF_PROG_SEC(string, ptype) BPF_PROG_SEC_FULL(string, ptype, 0)
 
+#define BPF_S_PROG_SEC(string, ptype) \
+	BPF_PROG_SEC_FULL(string, BPF_PROG_TYPE_CGROUP_SOCK, ptype)
+
 #define BPF_SA_PROG_SEC(string, ptype) \
 	BPF_PROG_SEC_FULL(string, BPF_PROG_TYPE_CGROUP_SOCK_ADDR, ptype)
 
@@ -1889,10 +1892,13 @@ static const struct {
 	BPF_SA_PROG_SEC("cgroup/bind6",	BPF_CGROUP_INET6_BIND),
 	BPF_SA_PROG_SEC("cgroup/connect4", BPF_CGROUP_INET4_CONNECT),
 	BPF_SA_PROG_SEC("cgroup/connect6", BPF_CGROUP_INET6_CONNECT),
+	BPF_S_PROG_SEC("cgroup/post_bind4", BPF_CGROUP_INET4_POST_BIND),
+	BPF_S_PROG_SEC("cgroup/post_bind6", BPF_CGROUP_INET6_POST_BIND),
 };
 
 #undef BPF_PROG_SEC
 #undef BPF_PROG_SEC_FULL
+#undef BPF_S_PROG_SEC
 #undef BPF_SA_PROG_SEC
 
 static int bpf_program__identify_section(struct bpf_program *prog)
Signature · 1 line
2.9.5
#6 lore raw

PATCH 3/3 libbpf: Type functions for raw tracepoints

In reply to Andrey Ignatov

Add missing pieces for BPF_PROG_TYPE_RAW_TRACEPOINT in libbpf:
* is- and set- functions;
* support guessing prog type.

---
 tools/lib/bpf/libbpf.c | 2 ++
 tools/lib/bpf/libbpf.h | 2 ++
 2 files changed, 4 insertions(+)
tools/lib/bpf/libbpf.c +2 -0
index 0fcc447..3d35bac 100644
@@ -1845,6 +1845,7 @@ BPF_PROG_TYPE_FNS(kprobe, BPF_PROG_TYPE_KPROBE);
 BPF_PROG_TYPE_FNS(sched_cls, BPF_PROG_TYPE_SCHED_CLS);
 BPF_PROG_TYPE_FNS(sched_act, BPF_PROG_TYPE_SCHED_ACT);
 BPF_PROG_TYPE_FNS(tracepoint, BPF_PROG_TYPE_TRACEPOINT);
+BPF_PROG_TYPE_FNS(raw_tracepoint, BPF_PROG_TYPE_RAW_TRACEPOINT);
 BPF_PROG_TYPE_FNS(xdp, BPF_PROG_TYPE_XDP);
 BPF_PROG_TYPE_FNS(perf_event, BPF_PROG_TYPE_PERF_EVENT);
 
@@ -1877,6 +1878,7 @@ static const struct {
 	BPF_PROG_SEC("classifier",	BPF_PROG_TYPE_SCHED_CLS),
 	BPF_PROG_SEC("action",		BPF_PROG_TYPE_SCHED_ACT),
 	BPF_PROG_SEC("tracepoint/",	BPF_PROG_TYPE_TRACEPOINT),
+	BPF_PROG_SEC("raw_tracepoint/",	BPF_PROG_TYPE_RAW_TRACEPOINT),
 	BPF_PROG_SEC("xdp",		BPF_PROG_TYPE_XDP),
 	BPF_PROG_SEC("perf_event",	BPF_PROG_TYPE_PERF_EVENT),
 	BPF_PROG_SEC("cgroup/skb",	BPF_PROG_TYPE_CGROUP_SKB),
tools/lib/bpf/libbpf.h +2 -0
index a3a62a5..8b24248 100644
@@ -185,6 +185,7 @@ int bpf_program__nth_fd(struct bpf_program *prog, int n);
  */
 int bpf_program__set_socket_filter(struct bpf_program *prog);
 int bpf_program__set_tracepoint(struct bpf_program *prog);
+int bpf_program__set_raw_tracepoint(struct bpf_program *prog);
 int bpf_program__set_kprobe(struct bpf_program *prog);
 int bpf_program__set_sched_cls(struct bpf_program *prog);
 int bpf_program__set_sched_act(struct bpf_program *prog);
@@ -194,6 +195,7 @@ void bpf_program__set_type(struct bpf_program *prog, enum bpf_prog_type type);
 
 bool bpf_program__is_socket_filter(struct bpf_program *prog);
 bool bpf_program__is_tracepoint(struct bpf_program *prog);
+bool bpf_program__is_raw_tracepoint(struct bpf_program *prog);
 bool bpf_program__is_kprobe(struct bpf_program *prog);
 bool bpf_program__is_sched_cls(struct bpf_program *prog);
 bool bpf_program__is_sched_act(struct bpf_program *prog);
Signature · 1 line
2.9.5