diff options
author | Ilya Leoshkevich <iii@linux.ibm.com> | 2019-07-17 08:26:20 -0400 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2019-07-18 16:54:54 -0400 |
commit | 59fd3486c3dd5678bc2fcac75e14466775465c3e (patch) | |
tree | df87ef00abde3fb744409429765eae6cd55f6622 | |
parent | 01a0f9e4496d9f54e06abb71bf9f56c617ef8c24 (diff) |
selftests/bpf: fix test_xdp_noinline on s390
test_xdp_noinline fails on s390 due to a handful of endianness issues.
Use ntohs for parsing eth_proto.
Replace bswaps with ntohs/htons.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Acked-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r-- | tools/testing/selftests/bpf/progs/test_xdp_noinline.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/tools/testing/selftests/bpf/progs/test_xdp_noinline.c b/tools/testing/selftests/bpf/progs/test_xdp_noinline.c index dad8a7e33eaa..e88d7b9d65ab 100644 --- a/tools/testing/selftests/bpf/progs/test_xdp_noinline.c +++ b/tools/testing/selftests/bpf/progs/test_xdp_noinline.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/tcp.h> | 14 | #include <linux/tcp.h> |
15 | #include <linux/udp.h> | 15 | #include <linux/udp.h> |
16 | #include "bpf_helpers.h" | 16 | #include "bpf_helpers.h" |
17 | #include "bpf_endian.h" | ||
17 | 18 | ||
18 | static __u32 rol32(__u32 word, unsigned int shift) | 19 | static __u32 rol32(__u32 word, unsigned int shift) |
19 | { | 20 | { |
@@ -305,7 +306,7 @@ bool encap_v6(struct xdp_md *xdp, struct ctl_value *cval, | |||
305 | ip6h->nexthdr = IPPROTO_IPV6; | 306 | ip6h->nexthdr = IPPROTO_IPV6; |
306 | ip_suffix = pckt->flow.srcv6[3] ^ pckt->flow.port16[0]; | 307 | ip_suffix = pckt->flow.srcv6[3] ^ pckt->flow.port16[0]; |
307 | ip6h->payload_len = | 308 | ip6h->payload_len = |
308 | __builtin_bswap16(pkt_bytes + sizeof(struct ipv6hdr)); | 309 | bpf_htons(pkt_bytes + sizeof(struct ipv6hdr)); |
309 | ip6h->hop_limit = 4; | 310 | ip6h->hop_limit = 4; |
310 | 311 | ||
311 | ip6h->saddr.in6_u.u6_addr32[0] = 1; | 312 | ip6h->saddr.in6_u.u6_addr32[0] = 1; |
@@ -322,7 +323,7 @@ bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval, | |||
322 | struct real_definition *dst, __u32 pkt_bytes) | 323 | struct real_definition *dst, __u32 pkt_bytes) |
323 | { | 324 | { |
324 | 325 | ||
325 | __u32 ip_suffix = __builtin_bswap16(pckt->flow.port16[0]); | 326 | __u32 ip_suffix = bpf_ntohs(pckt->flow.port16[0]); |
326 | struct eth_hdr *new_eth; | 327 | struct eth_hdr *new_eth; |
327 | struct eth_hdr *old_eth; | 328 | struct eth_hdr *old_eth; |
328 | __u16 *next_iph_u16; | 329 | __u16 *next_iph_u16; |
@@ -352,7 +353,7 @@ bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval, | |||
352 | iph->protocol = IPPROTO_IPIP; | 353 | iph->protocol = IPPROTO_IPIP; |
353 | iph->check = 0; | 354 | iph->check = 0; |
354 | iph->tos = 1; | 355 | iph->tos = 1; |
355 | iph->tot_len = __builtin_bswap16(pkt_bytes + sizeof(struct iphdr)); | 356 | iph->tot_len = bpf_htons(pkt_bytes + sizeof(struct iphdr)); |
356 | /* don't update iph->daddr, since it will overwrite old eth_proto | 357 | /* don't update iph->daddr, since it will overwrite old eth_proto |
357 | * and multiple iterations of bpf_prog_run() will fail | 358 | * and multiple iterations of bpf_prog_run() will fail |
358 | */ | 359 | */ |
@@ -639,7 +640,7 @@ static int process_l3_headers_v6(struct packet_description *pckt, | |||
639 | iph_len = sizeof(struct ipv6hdr); | 640 | iph_len = sizeof(struct ipv6hdr); |
640 | *protocol = ip6h->nexthdr; | 641 | *protocol = ip6h->nexthdr; |
641 | pckt->flow.proto = *protocol; | 642 | pckt->flow.proto = *protocol; |
642 | *pkt_bytes = __builtin_bswap16(ip6h->payload_len); | 643 | *pkt_bytes = bpf_ntohs(ip6h->payload_len); |
643 | off += iph_len; | 644 | off += iph_len; |
644 | if (*protocol == 45) { | 645 | if (*protocol == 45) { |
645 | return XDP_DROP; | 646 | return XDP_DROP; |
@@ -671,7 +672,7 @@ static int process_l3_headers_v4(struct packet_description *pckt, | |||
671 | return XDP_DROP; | 672 | return XDP_DROP; |
672 | *protocol = iph->protocol; | 673 | *protocol = iph->protocol; |
673 | pckt->flow.proto = *protocol; | 674 | pckt->flow.proto = *protocol; |
674 | *pkt_bytes = __builtin_bswap16(iph->tot_len); | 675 | *pkt_bytes = bpf_ntohs(iph->tot_len); |
675 | off += 20; | 676 | off += 20; |
676 | if (iph->frag_off & 65343) | 677 | if (iph->frag_off & 65343) |
677 | return XDP_DROP; | 678 | return XDP_DROP; |
@@ -808,10 +809,10 @@ int balancer_ingress(struct xdp_md *ctx) | |||
808 | nh_off = sizeof(struct eth_hdr); | 809 | nh_off = sizeof(struct eth_hdr); |
809 | if (data + nh_off > data_end) | 810 | if (data + nh_off > data_end) |
810 | return XDP_DROP; | 811 | return XDP_DROP; |
811 | eth_proto = eth->eth_proto; | 812 | eth_proto = bpf_ntohs(eth->eth_proto); |
812 | if (eth_proto == 8) | 813 | if (eth_proto == ETH_P_IP) |
813 | return process_packet(data, nh_off, data_end, 0, ctx); | 814 | return process_packet(data, nh_off, data_end, 0, ctx); |
814 | else if (eth_proto == 56710) | 815 | else if (eth_proto == ETH_P_IPV6) |
815 | return process_packet(data, nh_off, data_end, 1, ctx); | 816 | return process_packet(data, nh_off, data_end, 1, ctx); |
816 | else | 817 | else |
817 | return XDP_DROP; | 818 | return XDP_DROP; |