linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] samples: bpf: xdp1: remove duplicate code to find protocol
@ 2021-08-08 12:24 Muhammad Falak R Wani
  2021-08-08 16:53 ` Yonghong Song
  0 siblings, 1 reply; 4+ messages in thread
From: Muhammad Falak R Wani @ 2021-08-08 12:24 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: bpf, netdev, KP Singh, Yonghong Song, Song Liu, Martin KaFai Lau,
	John Fastabend, Jesper Dangaard Brouer, Jakub Kicinski,
	David S . Miller, linux-kernel, Muhammad Falak R Wani

The code to find h_vlan_encapsulated_proto is duplicated.
Remove the extra block.

Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
---
 samples/bpf/xdp1_kern.c | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/samples/bpf/xdp1_kern.c b/samples/bpf/xdp1_kern.c
index 34b64394ed9c..a35e064d7726 100644
--- a/samples/bpf/xdp1_kern.c
+++ b/samples/bpf/xdp1_kern.c
@@ -57,15 +57,6 @@ int xdp_prog1(struct xdp_md *ctx)
 
 	h_proto = eth->h_proto;
 
-	if (h_proto == htons(ETH_P_8021Q) || h_proto == htons(ETH_P_8021AD)) {
-		struct vlan_hdr *vhdr;
-
-		vhdr = data + nh_off;
-		nh_off += sizeof(struct vlan_hdr);
-		if (data + nh_off > data_end)
-			return rc;
-		h_proto = vhdr->h_vlan_encapsulated_proto;
-	}
 	if (h_proto == htons(ETH_P_8021Q) || h_proto == htons(ETH_P_8021AD)) {
 		struct vlan_hdr *vhdr;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] samples: bpf: xdp1: remove duplicate code to find protocol
  2021-08-08 12:24 [PATCH] samples: bpf: xdp1: remove duplicate code to find protocol Muhammad Falak R Wani
@ 2021-08-08 16:53 ` Yonghong Song
  2021-08-08 17:19   ` Muhammad Falak Reyaz
  0 siblings, 1 reply; 4+ messages in thread
From: Yonghong Song @ 2021-08-08 16:53 UTC (permalink / raw)
  To: Muhammad Falak R Wani, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko
  Cc: bpf, netdev, KP Singh, Song Liu, Martin KaFai Lau,
	John Fastabend, Jesper Dangaard Brouer, Jakub Kicinski,
	David S . Miller, linux-kernel



On 8/8/21 5:24 AM, Muhammad Falak R Wani wrote:
> The code to find h_vlan_encapsulated_proto is duplicated.
> Remove the extra block.
> 
> Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
> ---
>   samples/bpf/xdp1_kern.c | 9 ---------
>   1 file changed, 9 deletions(-)
> 
> diff --git a/samples/bpf/xdp1_kern.c b/samples/bpf/xdp1_kern.c
> index 34b64394ed9c..a35e064d7726 100644
> --- a/samples/bpf/xdp1_kern.c
> +++ b/samples/bpf/xdp1_kern.c
> @@ -57,15 +57,6 @@ int xdp_prog1(struct xdp_md *ctx)
>   
>   	h_proto = eth->h_proto;
>   
> -	if (h_proto == htons(ETH_P_8021Q) || h_proto == htons(ETH_P_8021AD)) {
> -		struct vlan_hdr *vhdr;
> -
> -		vhdr = data + nh_off;
> -		nh_off += sizeof(struct vlan_hdr);
> -		if (data + nh_off > data_end)
> -			return rc;
> -		h_proto = vhdr->h_vlan_encapsulated_proto;

No. This is not a duplicate. The h_proto in the above line will be used
in the below "if" condition.

> -	}
>   	if (h_proto == htons(ETH_P_8021Q) || h_proto == htons(ETH_P_8021AD)) {
>   		struct vlan_hdr *vhdr;
>   
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] samples: bpf: xdp1: remove duplicate code to find protocol
  2021-08-08 16:53 ` Yonghong Song
@ 2021-08-08 17:19   ` Muhammad Falak Reyaz
  2021-08-09  0:01     ` Yonghong Song
  0 siblings, 1 reply; 4+ messages in thread
From: Muhammad Falak Reyaz @ 2021-08-08 17:19 UTC (permalink / raw)
  To: Yonghong Song
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, bpf,
	open list:NETWORKING DRIVERS, KP Singh, Song Liu,
	Martin KaFai Lau, John Fastabend, Jesper Dangaard Brouer,
	Jakub Kicinski, David S . Miller, open list

On Sun, Aug 8, 2021 at 10:23 PM Yonghong Song <yhs@fb.com> wrote:
>
>
>
> On 8/8/21 5:24 AM, Muhammad Falak R Wani wrote:
> > The code to find h_vlan_encapsulated_proto is duplicated.
> > Remove the extra block.
> >
> > Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
> > ---
> >   samples/bpf/xdp1_kern.c | 9 ---------
> >   1 file changed, 9 deletions(-)
> >
> > diff --git a/samples/bpf/xdp1_kern.c b/samples/bpf/xdp1_kern.c
> > index 34b64394ed9c..a35e064d7726 100644
> > --- a/samples/bpf/xdp1_kern.c
> > +++ b/samples/bpf/xdp1_kern.c
> > @@ -57,15 +57,6 @@ int xdp_prog1(struct xdp_md *ctx)
> >
> >       h_proto = eth->h_proto;
> >
> > -     if (h_proto == htons(ETH_P_8021Q) || h_proto == htons(ETH_P_8021AD)) {
> > -             struct vlan_hdr *vhdr;
> > -
> > -             vhdr = data + nh_off;
> > -             nh_off += sizeof(struct vlan_hdr);
> > -             if (data + nh_off > data_end)
> > -                     return rc;
> > -             h_proto = vhdr->h_vlan_encapsulated_proto;
>
> No. This is not a duplicate. The h_proto in the above line will be used
> in the below "if" condition.
>
> > -     }
> >       if (h_proto == htons(ETH_P_8021Q) || h_proto == htons(ETH_P_8021AD)) {
> >               struct vlan_hdr *vhdr;
> >
> >
Apologies :(
I now realize, it could be double vlan encapsulated.
Would it make sense to add an explicit comment for newbies like me ?
I can send a patch, if it is okay.

-mfrw

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] samples: bpf: xdp1: remove duplicate code to find protocol
  2021-08-08 17:19   ` Muhammad Falak Reyaz
@ 2021-08-09  0:01     ` Yonghong Song
  0 siblings, 0 replies; 4+ messages in thread
From: Yonghong Song @ 2021-08-09  0:01 UTC (permalink / raw)
  To: Muhammad Falak Reyaz
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, bpf,
	open list:NETWORKING DRIVERS, KP Singh, Song Liu,
	Martin KaFai Lau, John Fastabend, Jesper Dangaard Brouer,
	Jakub Kicinski, David S . Miller, open list



On 8/8/21 10:19 AM, Muhammad Falak Reyaz wrote:
> On Sun, Aug 8, 2021 at 10:23 PM Yonghong Song <yhs@fb.com> wrote:
>>
>>
>>
>> On 8/8/21 5:24 AM, Muhammad Falak R Wani wrote:
>>> The code to find h_vlan_encapsulated_proto is duplicated.
>>> Remove the extra block.
>>>
>>> Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
>>> ---
>>>    samples/bpf/xdp1_kern.c | 9 ---------
>>>    1 file changed, 9 deletions(-)
>>>
>>> diff --git a/samples/bpf/xdp1_kern.c b/samples/bpf/xdp1_kern.c
>>> index 34b64394ed9c..a35e064d7726 100644
>>> --- a/samples/bpf/xdp1_kern.c
>>> +++ b/samples/bpf/xdp1_kern.c
>>> @@ -57,15 +57,6 @@ int xdp_prog1(struct xdp_md *ctx)
>>>
>>>        h_proto = eth->h_proto;
>>>
>>> -     if (h_proto == htons(ETH_P_8021Q) || h_proto == htons(ETH_P_8021AD)) {
>>> -             struct vlan_hdr *vhdr;
>>> -
>>> -             vhdr = data + nh_off;
>>> -             nh_off += sizeof(struct vlan_hdr);
>>> -             if (data + nh_off > data_end)
>>> -                     return rc;
>>> -             h_proto = vhdr->h_vlan_encapsulated_proto;
>>
>> No. This is not a duplicate. The h_proto in the above line will be used
>> in the below "if" condition.
>>
>>> -     }
>>>        if (h_proto == htons(ETH_P_8021Q) || h_proto == htons(ETH_P_8021AD)) {
>>>                struct vlan_hdr *vhdr;
>>>
>>>
> Apologies :(
> I now realize, it could be double vlan encapsulated.
> Would it make sense to add an explicit comment for newbies like me ?
> I can send a patch, if it is okay.

This is not the first time people sending a patch trying to remove this
"duplicated" code. I think it is okay to send a patch with comments to 
say this is intended to handle nested vlan, so we can save everybody's 
time. Thanks.

> 
> -mfrw
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-09  0:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-08 12:24 [PATCH] samples: bpf: xdp1: remove duplicate code to find protocol Muhammad Falak R Wani
2021-08-08 16:53 ` Yonghong Song
2021-08-08 17:19   ` Muhammad Falak Reyaz
2021-08-09  0:01     ` Yonghong Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).