selftests/bpf: use __bpf_constant_htons in test_prog.c
authorStanislav Fomichev <sdf@google.com>
Wed, 12 Dec 2018 03:20:52 +0000 (19:20 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 12 Dec 2018 23:33:07 +0000 (15:33 -0800)
For some reason, my older GCC (< 4.8) isn't smart enough to optimize the
!__builtin_constant_p() branch in bpf_htons, I see:
  error: implicit declaration of function '__builtin_bswap16'

Let's use __bpf_constant_htons as suggested by Daniel Borkmann.

I tried to use simple htons, but it produces the following:
  test_progs.c:54:17: error: braced-group within expression allowed only
  inside a function
    .eth.h_proto = htons(ETH_P_IP),

Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/test_progs.c

index 26f1fdf3e2bfaef8c419920e90a4378a766ad625..126fc624290d22b4d834b475356de2226dbea3a8 100644 (file)
@@ -51,10 +51,10 @@ static struct {
        struct iphdr iph;
        struct tcphdr tcp;
 } __packed pkt_v4 = {
-       .eth.h_proto = bpf_htons(ETH_P_IP),
+       .eth.h_proto = __bpf_constant_htons(ETH_P_IP),
        .iph.ihl = 5,
        .iph.protocol = 6,
-       .iph.tot_len = bpf_htons(MAGIC_BYTES),
+       .iph.tot_len = __bpf_constant_htons(MAGIC_BYTES),
        .tcp.urg_ptr = 123,
 };
 
@@ -64,9 +64,9 @@ static struct {
        struct ipv6hdr iph;
        struct tcphdr tcp;
 } __packed pkt_v6 = {
-       .eth.h_proto = bpf_htons(ETH_P_IPV6),
+       .eth.h_proto = __bpf_constant_htons(ETH_P_IPV6),
        .iph.nexthdr = 6,
-       .iph.payload_len = bpf_htons(MAGIC_BYTES),
+       .iph.payload_len = __bpf_constant_htons(MAGIC_BYTES),
        .tcp.urg_ptr = 123,
 };