diff mbox

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

Message ID 3c90a0b9480c61746220636ed48320da53410b6f.1494635217.git.daniel@iogearbox.net
State Accepted, archived
Delegated to: stephen hemminger
Headers show

Commit Message

Daniel Borkmann May 13, 2017, 12:32 a.m. UTC
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 <daniel@iogearbox.net>
---
 ip/iplink_xdp.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

Comments

Sergei Shtylyov May 13, 2017, 9:01 a.m. UTC | #1
Hello!

On 5/13/2017 3:32 AM, Daniel Borkmann wrote:

> 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 <daniel@iogearbox.net>
> ---
>  ip/iplink_xdp.c | 19 +++++++++++--------
>  1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/ip/iplink_xdp.c b/ip/iplink_xdp.c
> index a1380ee..98503fa 100644
> --- a/ip/iplink_xdp.c
> +++ b/ip/iplink_xdp.c
> @@ -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);

    This is asking to be a *switch* statement.

[...]

MBR, Sergei
Daniel Borkmann May 13, 2017, 9:19 a.m. UTC | #2
On 05/13/2017 11:01 AM, Sergei Shtylyov wrote:
> On 5/13/2017 3:32 AM, Daniel Borkmann wrote:
>
>> 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 <daniel@iogearbox.net>
>> ---
>>  ip/iplink_xdp.c | 19 +++++++++++--------
>>  1 file changed, 11 insertions(+), 8 deletions(-)
>>
>> diff --git a/ip/iplink_xdp.c b/ip/iplink_xdp.c
>> index a1380ee..98503fa 100644
>> --- a/ip/iplink_xdp.c
>> +++ b/ip/iplink_xdp.c
>> @@ -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);
>
>     This is asking to be a *switch* statement.

The code is fine as-is, thank you !
diff mbox

Patch

diff --git a/ip/iplink_xdp.c b/ip/iplink_xdp.c
index a1380ee..98503fa 100644
--- a/ip/iplink_xdp.c
+++ b/ip/iplink_xdp.c
@@ -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);
 }