samples: bpf: xdp1: remove duplicate code to find protocol
Subsystems (4)
PATCH 1/1 samples: bpf: xdp1: remove duplicate code to find protocol
The code to find h_vlan_encapsulated_proto is duplicated. Remove the extra block.
--- samples/bpf/xdp1_kern.c | 9 --------- 1 file changed, 9 deletions(-)
samples/bpf/xdp1_kern.c +0 -9
@@ -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;
Signature · 1 line
2.17.1
Quoted 14 lines · Muhammad Falak R Wani
The code to find
h_vlan_encapsulated_protois duplicated. Remove the extra block.Signed-off-by Muhammad Falak R Wani <[email protected]>--- samples/bpf/xdp1_kern.c | 9 --------- 1 file changed, 9 deletions(-)samples/bpf/xdp1_kern.c +0
-0@@ -57,15 +57,6 @@ int xdp_prog1(struct xdp_md *ctx)
samples/bpf/xdp1_kern.c int xdp_prog1(struct xdp_md *ctx) · line 67
Quoted 10 lines
samples/bpf/xdp1_kern.c +0
-8h_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.
Quoted 5 lines
samples/bpf/xdp1_kern.c +0
-1- }if (h_proto ==htons (ETH_P_8021Q ) || h_proto ==htons (ETH_P_8021AD )) {struct vlan_hdr *vhdr;
Quoted 20 lines · Yonghong Song
Quoted 16 lines · Muhammad Falak R Wani
The code to find
h_vlan_encapsulated_protois duplicated. Remove the extra block.Signed-off-by Muhammad Falak R Wani <[email protected]>--- samples/bpf/xdp1_kern.c | 9 --------- 1 file changed, 9 deletions(-)samples/bpf/xdp1_kern.c +0
-0@@ -57,15 +57,6 @@ int xdp_prog1(struct xdp_md *ctx) h_proto = eth->h_proto;
Quoted 17 lines
samples/bpf/xdp1_kern.c int xdp_prog1(struct xdp_md *ctx) · line 67
Quoted 8 lines
samples/bpf/xdp1_kern.c +0
-8-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_protoin the above line will be used in the below "if" condition.Quoted 5 lines
samples/bpf/xdp1_kern.c +0
-1- }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
Quoted 38 lines · Muhammad Falak Reyaz
Quoted 20 lines · Yonghong Song
Quoted 16 lines · Muhammad Falak R Wani
The code to find
h_vlan_encapsulated_protois duplicated. Remove the extra block.Signed-off-by Muhammad Falak R Wani <[email protected]>--- samples/bpf/xdp1_kern.c | 9 --------- 1 file changed, 9 deletions(-)samples/bpf/xdp1_kern.c +0
-0@@ -57,15 +57,6 @@ int xdp_prog1(struct xdp_md *ctx) h_proto = eth->h_proto;Quoted 17 lines
samples/bpf/xdp1_kern.c int xdp_prog1(struct xdp_md *ctx) · line 67
Quoted 8 lines
samples/bpf/xdp1_kern.c +0
-8-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_protoin the above line will be used in the below "if" condition.Quoted 5 lines
samples/bpf/xdp1_kern.c +0
-1- }if (h_proto ==htons (ETH_P_8021Q ) || h_proto ==htons (ETH_P_8021AD )) {struct vlan_hdr *vhdr;
Quoted 4 lines
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.
Quoted 3 lines
-mfrw