Skip to contentSkip to conversation

Two misc BPF updates

PATCH In review Daniel Borkmann 3 participants 7 messages May 13, 2017 – May 31, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Two misc BPF updates

Requires header rebase with -net.

Thanks!

Daniel Borkmann (2):
bpf: update printing of generic xdp mode
bpf: dump error to the user when retrieving pinned prog fails

 ip/iplink_xdp.c | 19 +++++++++++--------
 lib/bpf.c       | 12 +++++++++++-
 2 files changed, 22 insertions(+), 9 deletions(-)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/2 bpf: update printing of generic xdp mode

Follow-up to d67b9cd28c1d ("xdp: refine xdp api with regards to generic xdp") in order to update the XDP dumping part.

---
 ip/iplink_xdp.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
ip/iplink_xdp.c +11 -8
index a1380ee..98503fa 100644
@@ -79,17 +79,20 @@ int xdp_parse(int *argc, char ***argv, struct iplink_req *req, bool generic)
 void xdp_dump(FILE *fp, struct rtattr *xdp)
 {
 	struct rtattr *tb[IFLA_XDP_MAX + 1];
-	__u32 flags = 0;
+	__u8 mode;
 
 	parse_rtattr_nested(tb, IFLA_XDP_MAX, xdp);
 
-	if (!tb[IFLA_XDP_ATTACHED] ||
-	    !rta_getattr_u8(tb[IFLA_XDP_ATTACHED]))
+	if (!tb[IFLA_XDP_ATTACHED])
 		return;
 
-	if (tb[IFLA_XDP_FLAGS])
-		flags = rta_getattr_u32(tb[IFLA_XDP_FLAGS]);
-
-	fprintf(fp, "xdp%s ",
-		flags & XDP_FLAGS_SKB_MODE ? "generic" : "");
+	mode = rta_getattr_u8(tb[IFLA_XDP_ATTACHED]);
+	if (mode == XDP_ATTACHED_NONE)
+		return;
+	else if (mode == XDP_ATTACHED_DRV)
+		fprintf(fp, "xdp ");
+	else if (mode == XDP_ATTACHED_SKB)
+		fprintf(fp, "xdpgeneric ");
+	else
+		fprintf(fp, "xdp[%u] ", mode);
 }
Signature · 1 line
1.9.3
#2 lore raw

Re: [PATCH iproute2 -master 1/2] bpf: update printing of generic xdp mode

Hello!

Quoted 30 lines · Daniel Borkmann

Follow-up to d67b9cd28c1d ("xdp: refine xdp api with regards to generic xdp") in order to update the XDP dumping part.

---
 ip/iplink_xdp.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
ip/iplink_xdp.c +2 -7
index a1380ee..98503fa 100644
@@ -79,17 +79,20 @@ int xdp_parse(int *argc, char ***argv, struct iplink_req *req, bool generic)
 void xdp_dump(FILE *fp, struct rtattr *xdp)
 {
 	struct rtattr *tb[IFLA_XDP_MAX + 1];
-	__u32 flags = 0;
+	__u8 mode;
 
 	parse_rtattr_nested(tb, IFLA_XDP_MAX, xdp);
 
-	if (!tb[IFLA_XDP_ATTACHED] ||
-	    !rta_getattr_u8(tb[IFLA_XDP_ATTACHED]))
+	if (!tb[IFLA_XDP_ATTACHED])
 		return;
 
-	if (tb[IFLA_XDP_FLAGS])
-		flags = rta_getattr_u32(tb[IFLA_XDP_FLAGS]);
-
-	fprintf(fp, "xdp%s ",

ip/iplink_xdp.c int xdp_parse(int *argc, char ***argv, struct iplink_req *req, bool generic) · line 97

Quoted 10 lines
ip/iplink_xdp.c +9 -1
-		flags & XDP_FLAGS_SKB_MODE ? "generic" : "");
+	mode = rta_getattr_u8(tb[IFLA_XDP_ATTACHED]);
+	if (mode == XDP_ATTACHED_NONE)
+		return;
+	else if (mode == XDP_ATTACHED_DRV)
+		fprintf(fp, "xdp ");
+	else if (mode == XDP_ATTACHED_SKB)
+		fprintf(fp, "xdpgeneric ");
+	else
+		fprintf(fp, "xdp[%u] ", mode);

This is asking to be a *switch* statement.

[...]

MBR, Sergei

#3 lore raw

Re: [PATCH iproute2 -master 1/2] bpf: update printing of generic xdp mode

Quoted 28 lines · Sergei Shtylyov
Quoted 26 lines · Daniel Borkmann

Follow-up to d67b9cd28c1d ("xdp: refine xdp api with regards to generic xdp") in order to update the XDP dumping part.

---
 ip/iplink_xdp.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
ip/iplink_xdp.c +2 -3
index a1380ee..98503fa 100644
@@ -79,17 +79,20 @@ int xdp_parse(int *argc, char ***argv, struct iplink_req *req, bool generic)
 void xdp_dump(FILE *fp, struct rtattr *xdp)
 {
     struct rtattr *tb[IFLA_XDP_MAX + 1];
-    __u32 flags = 0;
+    __u8 mode;
 
     parse_rtattr_nested(tb, IFLA_XDP_MAX, xdp);
 
-    if (!tb[IFLA_XDP_ATTACHED] ||
-        !rta_getattr_u8(tb[IFLA_XDP_ATTACHED]))
+    if (!tb[IFLA_XDP_ATTACHED])
         return;
 
Quoted 16 lines
Quoted 4 lines
ip/iplink_xdp.c +0 -4
-    if (tb[IFLA_XDP_FLAGS])
-        flags = rta_getattr_u32(tb[IFLA_XDP_FLAGS]);
-
-    fprintf(fp, "xdp%s ",

ip/iplink_xdp.c int xdp_parse(int *argc, char ***argv, struct iplink_req *req, bool generic) · line 97

Quoted 10 lines
ip/iplink_xdp.c +9 -1
-        flags & XDP_FLAGS_SKB_MODE ? "generic" : "");
+    mode = rta_getattr_u8(tb[IFLA_XDP_ATTACHED]);
+    if (mode == XDP_ATTACHED_NONE)
+        return;
+    else if (mode == XDP_ATTACHED_DRV)
+        fprintf(fp, "xdp ");
+    else if (mode == XDP_ATTACHED_SKB)
+        fprintf(fp, "xdpgeneric ");
+    else
+        fprintf(fp, "xdp[%u] ", mode);

This is asking to be a *switch* statement.

The code is fine as-is, thank you !

#4 lore raw

PATCH 2/2 bpf: dump error to the user when retrieving pinned prog fails

In reply to Daniel Borkmann

I noticed we currently don't dump an error message when a pinned program couldn't be retrieved, thus add a hint to the user.

---
 lib/bpf.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
lib/bpf.c +11 -1
index 04ee1ab..ae4d97d 100644
@@ -648,6 +648,16 @@ static int bpf_obj_get(const char *pathname, enum bpf_prog_type type)
 	return bpf(BPF_OBJ_GET, &attr, sizeof(attr));
 }
 
+static int bpf_obj_pinned(const char *pathname, enum bpf_prog_type type)
+{
+	int prog_fd = bpf_obj_get(pathname, type);
+
+	if (prog_fd < 0)
+		fprintf(stderr, "Couldn\'t retrieve pinned program \'%s\': %s\n",
+			pathname, strerror(errno));
+	return prog_fd;
+}
+
 enum bpf_mode {
 	CBPF_BYTECODE,
 	CBPF_FILE,
@@ -750,7 +760,7 @@ static int bpf_parse(enum bpf_prog_type *type, enum bpf_mode *mode,
 	else if (*mode == EBPF_OBJECT)
 		ret = bpf_obj_open(file, *type, section, verbose);
 	else if (*mode == EBPF_PINNED)
-		ret = bpf_obj_get(file, *type);
+		ret = bpf_obj_pinned(file, *type);
 	else
 		return -1;
 
Signature · 1 line
1.9.3
#5 lore raw
In reply to Daniel Borkmann
Quoted 4 lines · On Sat, 13 May 2017 02:32:33 +0200 Daniel Borkmann <[email protected]> wrote:

Requires header rebase with -net.

Thanks!

Quoted 8 lines

Daniel Borkmann (2):
bpf: update printing of generic xdp mode
bpf: dump error to the user when retrieving pinned prog fails

 ip/iplink_xdp.c | 19 +++++++++++--------
 lib/bpf.c       | 12 +++++++++++-
 2 files changed, 22 insertions(+), 9 deletions(-)

Holding off until Linus pulls net

#6 lore raw
In reply to Daniel Borkmann
Quoted 4 lines · On Sat, 13 May 2017 02:32:33 +0200 Daniel Borkmann <[email protected]> wrote:

Requires header rebase with -net.

Thanks!

Quoted 8 lines

Daniel Borkmann (2):
bpf: update printing of generic xdp mode
bpf: dump error to the user when retrieving pinned prog fails

 ip/iplink_xdp.c | 19 +++++++++++--------
 lib/bpf.c       | 12 +++++++++++-
 2 files changed, 22 insertions(+), 9 deletions(-)

Applied thanks.