]> git.droids-corp.org - dpdk.git/commitdiff
test/bpf: use hton for endianness
authorMalvika Gupta <malvika.gupta@arm.com>
Fri, 2 Nov 2018 19:08:08 +0000 (14:08 -0500)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 13 Nov 2018 22:33:59 +0000 (23:33 +0100)
Convert host machine endianness to networking endianness for
comparison of incoming packets with BPF filter

Suggested-by: Brian Brooks <brian.brooks@arm.com>
Signed-off-by: Malvika Gupta <malvika.gupta@arm.com>
Reviewed-by: Gavin Hu <gavin.hu@arm.com>
Acked-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
test/bpf/t1.c
test/bpf/t3.c

index 60f9434abca1ac2290dd14f5ba147970b50f5156..3364b4f1e6b6c6f352504b8bf2bc3a8cec5a45a8 100644 (file)
  * (011) ret      #1
  * (012) ret      #0
  *
- * To compile:
- * clang -O2 -target bpf -c t1.c
+ * To compile on x86:
+ * clang -O2 -U __GNUC__ -target bpf -c t1.c
+ *
+ * To compile on ARM:
+ * clang -O2 -I/usr/include/aarch64-linux-gnu/ -target bpf -c t1.c
  */
 
 #include <stdint.h>
 #include <net/ethernet.h>
 #include <netinet/ip.h>
 #include <netinet/udp.h>
+#include <arpa/inet.h>
 
 uint64_t
 entry(void *pkt)
 {
        struct ether_header *ether_header = (void *)pkt;
 
-       if (ether_header->ether_type != __builtin_bswap16(0x0800))
+       if (ether_header->ether_type != htons(0x0800))
                return 0;
 
        struct iphdr *iphdr = (void *)(ether_header + 1);
        if (iphdr->protocol != 17 || (iphdr->frag_off & 0x1ffff) != 0 ||
-                       iphdr->daddr != __builtin_bswap32(0x1020304))
+                       iphdr->daddr != htonl(0x1020304))
                return 0;
 
        int hlen = iphdr->ihl * 4;
        struct udphdr *udphdr = (void *)iphdr + hlen;
 
-       if (udphdr->dest !=  __builtin_bswap16(5000))
+       if (udphdr->dest != htons(5000))
                return 0;
 
        return 1;
index 531b9cb8c4e115159c7855ae41e0391e77cd26e5..9ba34638a17f7ea671e3c826f5b2749142a2586e 100644 (file)
@@ -6,9 +6,15 @@
  * eBPF program sample.
  * Accepts pointer to struct rte_mbuf as an input parameter.
  * Dump the mbuf into stdout if it is an ARP packet (aka tcpdump 'arp').
- * To compile:
- * clang -O2 -I${RTE_SDK}/${RTE_TARGET}/include \
+ *
+ * To compile on x86:
+ * clang -O2 -U __GNUC__ -I${RTE_SDK}/${RTE_TARGET}/include \
  * -target bpf -Wno-int-to-void-pointer-cast -c t3.c
+ *
+ * To compile on ARM:
+ * clang -O2 -I/usr/include/aarch64-linux-gnu \
+ * -I${RTE_SDK}/${RTE_TARGET}/include -target bpf \
+ * -Wno-int-to-void-pointer-cast -c t3.c
  */
 
 #include <stdint.h>
@@ -17,6 +23,7 @@
 #include <net/ethernet.h>
 #include <rte_config.h>
 #include "mbuf.h"
+#include <arpa/inet.h>
 
 extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *, unsigned int);
 
@@ -29,7 +36,7 @@ entry(const void *pkt)
        mb = pkt;
        eth = rte_pktmbuf_mtod(mb, const struct ether_header *);
 
-       if (eth->ether_type == __builtin_bswap16(ETHERTYPE_ARP))
+       if (eth->ether_type == htons(ETHERTYPE_ARP))
                rte_pktmbuf_dump(stdout, mb, 64);
 
        return 1;