From mboxrd@z Thu Jan 1 00:00:00 1970 From: Malvika Gupta Subject: [PATCH] test/bpf: use hton instead of __builtin_bswap Date: Tue, 28 Aug 2018 15:46:19 -0500 Message-ID: <20180828204620.1862-1-Malvika.Gupta@arm.com> Cc: dev@dpdk.org, gavin.hu@arm.com, honnappa.nagarahalli@arm.com, brian.brooks@arm.com, nd@arm.com, Malvika Gupta , Malvika Gupta To: konstantin.ananyev@intel.com Return-path: Received: from foss.arm.com (foss.arm.com [217.140.101.70]) by dpdk.org (Postfix) with ESMTP id A42082BB1 for ; Tue, 28 Aug 2018 22:47:08 +0200 (CEST) List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Convert host machine endianness to networking endianness for comparison of incoming packets with BPF filter Signed-off-by: Malvika Gupta Reviewed-by: Gavin Hu Reviewed-by: Brian Brooks Suggested-by: Brian Brooks --- 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 #include #include +#include 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 #include #include "mbuf.h" +#include 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