[dpdk-dev] [PATCH] test/bpf: use hton instead of __builtin_bswap

Honnappa Nagarahalli Honnappa.Nagarahalli at arm.com
Tue Aug 28 22:58:35 CEST 2018



-----Original Message-----
From: Malvika Gupta <Malvika.Gupta at arm.com> 
Sent: Tuesday, August 28, 2018 3:46 PM
To: konstantin.ananyev at intel.com
Cc: dev at dpdk.org; Gavin Hu <Gavin.Hu at arm.com>; Honnappa Nagarahalli <Honnappa.Nagarahalli at arm.com>; Brian Brooks <Brian.Brooks at arm.com>; nd <nd at arm.com>; Malvika Gupta <Malvika.Gupta at arm.com>; Malvika Gupta <Malvika.Gupta at arm.com>
Subject: [PATCH] test/bpf: use hton instead of __builtin_bswap

Convert host machine endianness to networking endianness for comparison of incoming packets with BPF filter


Signed-off-by: Malvika Gupta <malvika.gupta at arm.com>
Reviewed-by: Gavin Hu <gavin.hu at arm.com>
Reviewed-by: Brian Brooks <brian.brooks at arm.com>
Suggested-by: Brian Brooks <brian.brooks at arm.com>
---
 test/bpf/t1.c | 7 ++++---
 test/bpf/t3.c | 3 ++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/test/bpf/t1.c b/test/bpf/t1.c index 60f9434ab..7943fcf34 100644
--- a/test/bpf/t1.c
+++ b/test/bpf/t1.c
@@ -28,24 +28,25 @@
 #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;
diff --git a/test/bpf/t3.c b/test/bpf/t3.c index 531b9cb8c..24298b7c7 100644
--- a/test/bpf/t3.c
+++ b/test/bpf/t3.c
@@ -17,6 +17,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 +30,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;
--
2.17.1

Compiled and tested.
Acked-by: Honnappa Nagarahalli <Honnappa.nagarahalli at arm.com>



More information about the dev mailing list