diff mbox series

[bpf,1/3] selftests/xsk: print correct payload for packet dump

Message ID 20221115080538.18503-2-magnus.karlsson@gmail.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series selftests/xsk: three small fixes | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 1 blamed authors not CCed: weqaar.janjua@gmail.com; 13 maintainers not CCed: sdf@google.com kpsingh@kernel.org mykolal@fb.com song@kernel.org haoluo@google.com weqaar.janjua@gmail.com linux-kselftest@vger.kernel.org yhs@fb.com shuah@kernel.org jolsa@kernel.org martin.lau@linux.dev andrii@kernel.org john.fastabend@gmail.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-PR fail PR summary
bpf/vmtest-bpf-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-VM_Test-7 success Logs for llvm-toolchain
bpf/vmtest-bpf-VM_Test-8 success Logs for set-matrix
bpf/vmtest-bpf-VM_Test-5 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-VM_Test-6 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-VM_Test-3 success Logs for build for aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-4 success Logs for build for s390x with gcc
bpf/vmtest-bpf-VM_Test-12 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-13 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-19 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-22 fail Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-24 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-27 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-29 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-32 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-34 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-37 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-9 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-10 success Logs for test_maps on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-14 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-15 success Logs for test_progs on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-17 fail Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-18 fail Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-20 success Logs for test_progs_no_alu32 on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-23 fail Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-25 success Logs for test_progs_no_alu32_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-28 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-30 success Logs for test_progs_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-33 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-35 success Logs for test_verifier on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-38 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-21 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-VM_Test-26 success Logs for test_progs_no_alu32_parallel on s390x with gcc
bpf/vmtest-bpf-VM_Test-31 success Logs for test_progs_parallel on s390x with gcc
bpf/vmtest-bpf-VM_Test-36 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-VM_Test-16 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-VM_Test-11 success Logs for test_maps on s390x with gcc

Commit Message

Magnus Karlsson Nov. 15, 2022, 8:05 a.m. UTC
From: Magnus Karlsson <magnus.karlsson@intel.com>

Print the correct payload when the packet dump option is selected. The
network to host conversion was forgotten and the payload was
erronously declared to be an int instead of an unsigned int. Changed
the loop index i too, as it does not need to be an int and was
declared on the same row.

The printout looks something like this after the fix:

DEBUG>> L2: dst mac: 000A569EEE62
DEBUG>> L2: src mac: 000A569EEE61
DEBUG>> L3: ip_hdr->ihl: 05
DEBUG>> L3: ip_hdr->saddr: 192.168.100.161
DEBUG>> L3: ip_hdr->daddr: 192.168.100.162
DEBUG>> L4: udp_hdr->src: 2121
DEBUG>> L4: udp_hdr->dst: 2020
DEBUG>> L5: payload: 4
---------------------------------------

Fixes: facb7cb2e909 ("selftests/bpf: Xsk selftests - SKB POLL, NOPOLL")
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
---
 tools/testing/selftests/bpf/xskxceiver.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Maciej Fijalkowski Nov. 15, 2022, 12:29 p.m. UTC | #1
On Tue, Nov 15, 2022 at 09:05:36AM +0100, Magnus Karlsson wrote:
> From: Magnus Karlsson <magnus.karlsson@intel.com>
> 
> Print the correct payload when the packet dump option is selected. The
> network to host conversion was forgotten and the payload was
> erronously declared to be an int instead of an unsigned int. Changed
> the loop index i too, as it does not need to be an int and was
> declared on the same row.
> 
> The printout looks something like this after the fix:
> 
> DEBUG>> L2: dst mac: 000A569EEE62
> DEBUG>> L2: src mac: 000A569EEE61
> DEBUG>> L3: ip_hdr->ihl: 05
> DEBUG>> L3: ip_hdr->saddr: 192.168.100.161
> DEBUG>> L3: ip_hdr->daddr: 192.168.100.162
> DEBUG>> L4: udp_hdr->src: 2121
> DEBUG>> L4: udp_hdr->dst: 2020
> DEBUG>> L5: payload: 4
> ---------------------------------------

Above would be helpful if previous output was included as well but not a
big deal i guess.

> 
> Fixes: facb7cb2e909 ("selftests/bpf: Xsk selftests - SKB POLL, NOPOLL")
> Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
> ---
>  tools/testing/selftests/bpf/xskxceiver.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
> index 681a5db80dae..51e693318b3f 100644
> --- a/tools/testing/selftests/bpf/xskxceiver.c
> +++ b/tools/testing/selftests/bpf/xskxceiver.c
> @@ -767,7 +767,7 @@ static void pkt_dump(void *pkt, u32 len)
>  	struct ethhdr *ethhdr;
>  	struct udphdr *udphdr;
>  	struct iphdr *iphdr;
> -	int payload, i;
> +	u32 payload, i;
>  
>  	ethhdr = pkt;
>  	iphdr = pkt + sizeof(*ethhdr);
> @@ -792,7 +792,7 @@ static void pkt_dump(void *pkt, u32 len)
>  	fprintf(stdout, "DEBUG>> L4: udp_hdr->src: %d\n", ntohs(udphdr->source));
>  	fprintf(stdout, "DEBUG>> L4: udp_hdr->dst: %d\n", ntohs(udphdr->dest));
>  	/*extract L5 frame */
> -	payload = *((uint32_t *)(pkt + PKT_HDR_SIZE));
> +	payload = ntohl(*((u32 *)(pkt + PKT_HDR_SIZE)));
>  
>  	fprintf(stdout, "DEBUG>> L5: payload: %d\n", payload);
>  	fprintf(stdout, "---------------------------------------\n");
> -- 
> 2.34.1
>
Magnus Karlsson Nov. 15, 2022, 12:40 p.m. UTC | #2
On Tue, Nov 15, 2022 at 1:29 PM Maciej Fijalkowski
<maciej.fijalkowski@intel.com> wrote:
>
> On Tue, Nov 15, 2022 at 09:05:36AM +0100, Magnus Karlsson wrote:
> > From: Magnus Karlsson <magnus.karlsson@intel.com>
> >
> > Print the correct payload when the packet dump option is selected. The
> > network to host conversion was forgotten and the payload was
> > erronously declared to be an int instead of an unsigned int. Changed
> > the loop index i too, as it does not need to be an int and was
> > declared on the same row.
> >
> > The printout looks something like this after the fix:
> >
> > DEBUG>> L2: dst mac: 000A569EEE62
> > DEBUG>> L2: src mac: 000A569EEE61
> > DEBUG>> L3: ip_hdr->ihl: 05
> > DEBUG>> L3: ip_hdr->saddr: 192.168.100.161
> > DEBUG>> L3: ip_hdr->daddr: 192.168.100.162
> > DEBUG>> L4: udp_hdr->src: 2121
> > DEBUG>> L4: udp_hdr->dst: 2020
> > DEBUG>> L5: payload: 4
> > ---------------------------------------
>
> Above would be helpful if previous output was included as well but not a
> big deal i guess.

It would not bring any value IMHO. The only difference is that the
"L5: payload" row is now showing the correct payload.

> >
> > Fixes: facb7cb2e909 ("selftests/bpf: Xsk selftests - SKB POLL, NOPOLL")
> > Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
> > ---
> >  tools/testing/selftests/bpf/xskxceiver.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
> > index 681a5db80dae..51e693318b3f 100644
> > --- a/tools/testing/selftests/bpf/xskxceiver.c
> > +++ b/tools/testing/selftests/bpf/xskxceiver.c
> > @@ -767,7 +767,7 @@ static void pkt_dump(void *pkt, u32 len)
> >       struct ethhdr *ethhdr;
> >       struct udphdr *udphdr;
> >       struct iphdr *iphdr;
> > -     int payload, i;
> > +     u32 payload, i;
> >
> >       ethhdr = pkt;
> >       iphdr = pkt + sizeof(*ethhdr);
> > @@ -792,7 +792,7 @@ static void pkt_dump(void *pkt, u32 len)
> >       fprintf(stdout, "DEBUG>> L4: udp_hdr->src: %d\n", ntohs(udphdr->source));
> >       fprintf(stdout, "DEBUG>> L4: udp_hdr->dst: %d\n", ntohs(udphdr->dest));
> >       /*extract L5 frame */
> > -     payload = *((uint32_t *)(pkt + PKT_HDR_SIZE));
> > +     payload = ntohl(*((u32 *)(pkt + PKT_HDR_SIZE)));
> >
> >       fprintf(stdout, "DEBUG>> L5: payload: %d\n", payload);
> >       fprintf(stdout, "---------------------------------------\n");
> > --
> > 2.34.1
> >
Maciej Fijalkowski Nov. 22, 2022, 10:42 a.m. UTC | #3
On Tue, Nov 15, 2022 at 01:40:48PM +0100, Magnus Karlsson wrote:
> On Tue, Nov 15, 2022 at 1:29 PM Maciej Fijalkowski
> <maciej.fijalkowski@intel.com> wrote:
> >
> > On Tue, Nov 15, 2022 at 09:05:36AM +0100, Magnus Karlsson wrote:
> > > From: Magnus Karlsson <magnus.karlsson@intel.com>
> > >
> > > Print the correct payload when the packet dump option is selected. The
> > > network to host conversion was forgotten and the payload was
> > > erronously declared to be an int instead of an unsigned int. Changed
> > > the loop index i too, as it does not need to be an int and was
> > > declared on the same row.
> > >
> > > The printout looks something like this after the fix:
> > >
> > > DEBUG>> L2: dst mac: 000A569EEE62
> > > DEBUG>> L2: src mac: 000A569EEE61
> > > DEBUG>> L3: ip_hdr->ihl: 05
> > > DEBUG>> L3: ip_hdr->saddr: 192.168.100.161
> > > DEBUG>> L3: ip_hdr->daddr: 192.168.100.162
> > > DEBUG>> L4: udp_hdr->src: 2121
> > > DEBUG>> L4: udp_hdr->dst: 2020
> > > DEBUG>> L5: payload: 4
> > > ---------------------------------------
> >
> > Above would be helpful if previous output was included as well but not a
> > big deal i guess.
> 
> It would not bring any value IMHO. The only difference is that the
> "L5: payload" row is now showing the correct payload.

Ah okay then. I have already acked whole series, but just to make things
clear, I am okay with the current state of this patch:

Acked-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>

> 
> > >
> > > Fixes: facb7cb2e909 ("selftests/bpf: Xsk selftests - SKB POLL, NOPOLL")
> > > Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
> > > ---
> > >  tools/testing/selftests/bpf/xskxceiver.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
> > > index 681a5db80dae..51e693318b3f 100644
> > > --- a/tools/testing/selftests/bpf/xskxceiver.c
> > > +++ b/tools/testing/selftests/bpf/xskxceiver.c
> > > @@ -767,7 +767,7 @@ static void pkt_dump(void *pkt, u32 len)
> > >       struct ethhdr *ethhdr;
> > >       struct udphdr *udphdr;
> > >       struct iphdr *iphdr;
> > > -     int payload, i;
> > > +     u32 payload, i;
> > >
> > >       ethhdr = pkt;
> > >       iphdr = pkt + sizeof(*ethhdr);
> > > @@ -792,7 +792,7 @@ static void pkt_dump(void *pkt, u32 len)
> > >       fprintf(stdout, "DEBUG>> L4: udp_hdr->src: %d\n", ntohs(udphdr->source));
> > >       fprintf(stdout, "DEBUG>> L4: udp_hdr->dst: %d\n", ntohs(udphdr->dest));
> > >       /*extract L5 frame */
> > > -     payload = *((uint32_t *)(pkt + PKT_HDR_SIZE));
> > > +     payload = ntohl(*((u32 *)(pkt + PKT_HDR_SIZE)));
> > >
> > >       fprintf(stdout, "DEBUG>> L5: payload: %d\n", payload);
> > >       fprintf(stdout, "---------------------------------------\n");
> > > --
> > > 2.34.1
> > >
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
index 681a5db80dae..51e693318b3f 100644
--- a/tools/testing/selftests/bpf/xskxceiver.c
+++ b/tools/testing/selftests/bpf/xskxceiver.c
@@ -767,7 +767,7 @@  static void pkt_dump(void *pkt, u32 len)
 	struct ethhdr *ethhdr;
 	struct udphdr *udphdr;
 	struct iphdr *iphdr;
-	int payload, i;
+	u32 payload, i;
 
 	ethhdr = pkt;
 	iphdr = pkt + sizeof(*ethhdr);
@@ -792,7 +792,7 @@  static void pkt_dump(void *pkt, u32 len)
 	fprintf(stdout, "DEBUG>> L4: udp_hdr->src: %d\n", ntohs(udphdr->source));
 	fprintf(stdout, "DEBUG>> L4: udp_hdr->dst: %d\n", ntohs(udphdr->dest));
 	/*extract L5 frame */
-	payload = *((uint32_t *)(pkt + PKT_HDR_SIZE));
+	payload = ntohl(*((u32 *)(pkt + PKT_HDR_SIZE)));
 
 	fprintf(stdout, "DEBUG>> L5: payload: %d\n", payload);
 	fprintf(stdout, "---------------------------------------\n");