bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf] selftests/bpf: fix sendmsg6_prog on s390
@ 2019-07-19  9:06 Ilya Leoshkevich
  2019-07-19 16:21 ` Andrey Ignatov
  2019-07-22 14:23 ` Daniel Borkmann
  0 siblings, 2 replies; 3+ messages in thread
From: Ilya Leoshkevich @ 2019-07-19  9:06 UTC (permalink / raw)
  To: bpf, netdev; +Cc: gor, heiko.carstens, rdna, Ilya Leoshkevich

"sendmsg6: rewrite IP & port (C)" fails on s390, because the code in
sendmsg_v6_prog() assumes that (ctx->user_ip6[0] & 0xFFFF) refers to
leading IPv6 address digits, which is not the case on big-endian
machines.

Since checking bitwise operations doesn't seem to be the point of the
test, replace two short comparisons with a single int comparison.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 tools/testing/selftests/bpf/progs/sendmsg6_prog.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/progs/sendmsg6_prog.c b/tools/testing/selftests/bpf/progs/sendmsg6_prog.c
index 5aeaa284fc47..a68062820410 100644
--- a/tools/testing/selftests/bpf/progs/sendmsg6_prog.c
+++ b/tools/testing/selftests/bpf/progs/sendmsg6_prog.c
@@ -41,8 +41,7 @@ int sendmsg_v6_prog(struct bpf_sock_addr *ctx)
 	}
 
 	/* Rewrite destination. */
-	if ((ctx->user_ip6[0] & 0xFFFF) == bpf_htons(0xFACE) &&
-	     ctx->user_ip6[0] >> 16 == bpf_htons(0xB00C)) {
+	if (ctx->user_ip6[0] == bpf_htonl(0xFACEB00C)) {
 		ctx->user_ip6[0] = bpf_htonl(DST_REWRITE_IP6_0);
 		ctx->user_ip6[1] = bpf_htonl(DST_REWRITE_IP6_1);
 		ctx->user_ip6[2] = bpf_htonl(DST_REWRITE_IP6_2);
-- 
2.21.0


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

* Re: [PATCH bpf] selftests/bpf: fix sendmsg6_prog on s390
  2019-07-19  9:06 [PATCH bpf] selftests/bpf: fix sendmsg6_prog on s390 Ilya Leoshkevich
@ 2019-07-19 16:21 ` Andrey Ignatov
  2019-07-22 14:23 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Andrey Ignatov @ 2019-07-19 16:21 UTC (permalink / raw)
  To: Ilya Leoshkevich; +Cc: bpf, netdev, gor, heiko.carstens

Ilya Leoshkevich <iii@linux.ibm.com> [Fri, 2019-07-19 02:07 -0700]:
> "sendmsg6: rewrite IP & port (C)" fails on s390, because the code in
> sendmsg_v6_prog() assumes that (ctx->user_ip6[0] & 0xFFFF) refers to
> leading IPv6 address digits, which is not the case on big-endian
> machines.
> 
> Since checking bitwise operations doesn't seem to be the point of the
> test, replace two short comparisons with a single int comparison.
> 
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>

Acked-by: Andrey Ignatov <rdna@fb.com>

IIRC I did it this way to test 16bit loads from C program, but such
loads are already tested by asm prog in test_sock_addr.c.

Thanks for the fix!

> ---
>  tools/testing/selftests/bpf/progs/sendmsg6_prog.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/progs/sendmsg6_prog.c b/tools/testing/selftests/bpf/progs/sendmsg6_prog.c
> index 5aeaa284fc47..a68062820410 100644
> --- a/tools/testing/selftests/bpf/progs/sendmsg6_prog.c
> +++ b/tools/testing/selftests/bpf/progs/sendmsg6_prog.c
> @@ -41,8 +41,7 @@ int sendmsg_v6_prog(struct bpf_sock_addr *ctx)
>  	}
>  
>  	/* Rewrite destination. */
> -	if ((ctx->user_ip6[0] & 0xFFFF) == bpf_htons(0xFACE) &&
> -	     ctx->user_ip6[0] >> 16 == bpf_htons(0xB00C)) {
> +	if (ctx->user_ip6[0] == bpf_htonl(0xFACEB00C)) {
>  		ctx->user_ip6[0] = bpf_htonl(DST_REWRITE_IP6_0);
>  		ctx->user_ip6[1] = bpf_htonl(DST_REWRITE_IP6_1);
>  		ctx->user_ip6[2] = bpf_htonl(DST_REWRITE_IP6_2);
> -- 
> 2.21.0
> 

-- 
Andrey Ignatov

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

* Re: [PATCH bpf] selftests/bpf: fix sendmsg6_prog on s390
  2019-07-19  9:06 [PATCH bpf] selftests/bpf: fix sendmsg6_prog on s390 Ilya Leoshkevich
  2019-07-19 16:21 ` Andrey Ignatov
@ 2019-07-22 14:23 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2019-07-22 14:23 UTC (permalink / raw)
  To: Ilya Leoshkevich, bpf, netdev; +Cc: gor, heiko.carstens, rdna

On 7/19/19 11:06 AM, Ilya Leoshkevich wrote:
> "sendmsg6: rewrite IP & port (C)" fails on s390, because the code in
> sendmsg_v6_prog() assumes that (ctx->user_ip6[0] & 0xFFFF) refers to
> leading IPv6 address digits, which is not the case on big-endian
> machines.
> 
> Since checking bitwise operations doesn't seem to be the point of the
> test, replace two short comparisons with a single int comparison.
> 
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>

Applied, thanks!

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

end of thread, other threads:[~2019-07-22 14:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-19  9:06 [PATCH bpf] selftests/bpf: fix sendmsg6_prog on s390 Ilya Leoshkevich
2019-07-19 16:21 ` Andrey Ignatov
2019-07-22 14:23 ` Daniel Borkmann

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).