Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: bpf: Use bpf_endian.h in test_xdp.c

This fixes the testcase on big-endian.

Signed-off-by: David S. Miller <davem@davemloft.net>

+8 -9
+8 -9
tools/testing/selftests/bpf/test_xdp.c
··· 17 17 #include <linux/pkt_cls.h> 18 18 #include <sys/socket.h> 19 19 #include "bpf_helpers.h" 20 + #include "bpf_endian.h" 20 21 #include "test_iptunnel_common.h" 21 22 22 - #define htons __builtin_bswap16 23 - #define ntohs __builtin_bswap16 24 23 int _version SEC("version") = 1; 25 24 26 25 struct bpf_map_def SEC("maps") rxcnt = { ··· 103 104 vip.family = AF_INET; 104 105 vip.daddr.v4 = iph->daddr; 105 106 vip.dport = dport; 106 - payload_len = ntohs(iph->tot_len); 107 + payload_len = bpf_ntohs(iph->tot_len); 107 108 108 109 tnl = bpf_map_lookup_elem(&vip2tnl, &vip); 109 110 /* It only does v4-in-v4 */ ··· 125 126 iph + 1 > data_end) 126 127 return XDP_DROP; 127 128 128 - set_ethhdr(new_eth, old_eth, tnl, htons(ETH_P_IP)); 129 + set_ethhdr(new_eth, old_eth, tnl, bpf_htons(ETH_P_IP)); 129 130 130 131 iph->version = 4; 131 132 iph->ihl = sizeof(*iph) >> 2; ··· 133 134 iph->protocol = IPPROTO_IPIP; 134 135 iph->check = 0; 135 136 iph->tos = 0; 136 - iph->tot_len = htons(payload_len + sizeof(*iph)); 137 + iph->tot_len = bpf_htons(payload_len + sizeof(*iph)); 137 138 iph->daddr = tnl->daddr.v4; 138 139 iph->saddr = tnl->saddr.v4; 139 140 iph->ttl = 8; ··· 194 195 ip6h + 1 > data_end) 195 196 return XDP_DROP; 196 197 197 - set_ethhdr(new_eth, old_eth, tnl, htons(ETH_P_IPV6)); 198 + set_ethhdr(new_eth, old_eth, tnl, bpf_htons(ETH_P_IPV6)); 198 199 199 200 ip6h->version = 6; 200 201 ip6h->priority = 0; 201 202 memset(ip6h->flow_lbl, 0, sizeof(ip6h->flow_lbl)); 202 - ip6h->payload_len = htons(ntohs(payload_len) + sizeof(*ip6h)); 203 + ip6h->payload_len = bpf_htons(bpf_ntohs(payload_len) + sizeof(*ip6h)); 203 204 ip6h->nexthdr = IPPROTO_IPV6; 204 205 ip6h->hop_limit = 8; 205 206 memcpy(ip6h->saddr.s6_addr32, tnl->saddr.v6, sizeof(tnl->saddr.v6)); ··· 223 224 224 225 h_proto = eth->h_proto; 225 226 226 - if (h_proto == htons(ETH_P_IP)) 227 + if (h_proto == bpf_htons(ETH_P_IP)) 227 228 return handle_ipv4(xdp); 228 - else if (h_proto == htons(ETH_P_IPV6)) 229 + else if (h_proto == bpf_htons(ETH_P_IPV6)) 229 230 230 231 return handle_ipv6(xdp); 231 232 else