From patchwork Fri Nov 2 19:08:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Malvika Gupta X-Patchwork-Id: 47767 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E21B85B3A; Fri, 2 Nov 2018 20:08:35 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.101.70]) by dpdk.org (Postfix) with ESMTP id 147485323 for ; Fri, 2 Nov 2018 20:08:35 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1BB70A78; Fri, 2 Nov 2018 12:08:34 -0700 (PDT) Received: from qc2400f-1.austin.arm.com (qc2400f-1.austin.arm.com [10.118.12.122]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B04CE3F71E; Fri, 2 Nov 2018 12:08:33 -0700 (PDT) From: Malvika Gupta To: konstantin.ananyev@intel.com Cc: dev@dpdk.org, gavin.hu@arm.com, honnappa.nagarahalli@arm.com, nd@arm.com, Malvika Gupta , Malvika Gupta Date: Fri, 2 Nov 2018 14:08:08 -0500 Message-Id: <20181102190808.16421-1-malvika.gupta@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180828204620.1862-1-Malvika.Gupta@arm.com> References: <20180828204620.1862-1-Malvika.Gupta@arm.com> Subject: [dpdk-dev] [PATCH v2] test/bpf: use hton instead of _builtin_bswap X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Malvika Gupta Convert host machine endianness to networking endianness for comparison of incoming packets with BPF filter Suggested-by: Brian Brooks Signed-off-by: Malvika Gupta Reviewed-by: Gavin Hu Reviewed-by: Konstantin Ananyev Acked-by: Honnappa Nagarahalli Acked-by: Konstantin Ananyev --- v2: * Correct compilation command in the comments for x86. * Added compilation command for ARM. --- test/bpf/t1.c | 14 +++++++++----- test/bpf/t3.c | 13 ++++++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/test/bpf/t1.c b/test/bpf/t1.c index 60f9434ab..3364b4f1e 100644 --- a/test/bpf/t1.c +++ b/test/bpf/t1.c @@ -20,32 +20,36 @@ * (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 #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..9ba34638a 100644 --- a/test/bpf/t3.c +++ b/test/bpf/t3.c @@ -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 @@ -17,6 +23,7 @@ #include #include #include "mbuf.h" +#include 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;