Two misc BPF updates
Subsystems (3)
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
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
@@ -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
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.Signed-off-by Daniel Borkmann <[email protected]>--- ip/iplink_xdp.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)ip/iplink_xdp.c +2
-7@@ -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
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.Signed-off-by Daniel Borkmann <[email protected]>--- ip/iplink_xdp.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)ip/iplink_xdp.c +2
-3@@ -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 !
PATCH 2/2 bpf: dump error to the user when retrieving pinned prog fails
In reply to Daniel BorkmannI 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
@@ -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
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 failsip/iplink_xdp.c | 19 +++++++++++-------- lib/bpf.c | 12 +++++++++++- 2 files changed, 22 insertions(+), 9 deletions(-)
Holding off until Linus pulls net
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 failsip/iplink_xdp.c | 19 +++++++++++-------- lib/bpf.c | 12 +++++++++++- 2 files changed, 22 insertions(+), 9 deletions(-)
Applied thanks.