From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 8533E2862 for ; Tue, 4 Sep 2018 15:56:32 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Sep 2018 06:56:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,329,1531810800"; d="scan'208";a="80758679" Received: from irsmsx104.ger.corp.intel.com ([163.33.3.159]) by orsmga003.jf.intel.com with ESMTP; 04 Sep 2018 06:56:29 -0700 Received: from irsmsx156.ger.corp.intel.com (10.108.20.68) by IRSMSX104.ger.corp.intel.com (163.33.3.159) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 4 Sep 2018 14:56:28 +0100 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.54]) by IRSMSX156.ger.corp.intel.com ([169.254.3.37]) with mapi id 14.03.0319.002; Tue, 4 Sep 2018 14:56:28 +0100 From: "Ananyev, Konstantin" To: Malvika Gupta CC: "dev@dpdk.org" , "gavin.hu@arm.com" , "honnappa.nagarahalli@arm.com" , "brian.brooks@arm.com" , "nd@arm.com" Thread-Topic: [PATCH] test/bpf: use hton instead of __builtin_bswap Thread-Index: AQHUPxBTKpHBSGr7KUCFrtgAI8miMaTgLLtQ Date: Tue, 4 Sep 2018 13:56:27 +0000 Message-ID: <2601191342CEEE43887BDE71AB977258EA9511E7@irsmsx105.ger.corp.intel.com> References: <20180828204620.1862-1-Malvika.Gupta@arm.com> In-Reply-To: <20180828204620.1862-1-Malvika.Gupta@arm.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNDkxMDcyYzAtNmIwNS00YjI4LWFiMzQtNzE3NmM2NTkyODc0IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiXC92bThhd0pcL0NMRnltM1wvTU1HMUswbkk0dWx2NEhlemQ3NGlIQmQ1XC96VWRMVTBDSnJTSVFjUmxVcEZqSDMrTnUifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] 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: , X-List-Received-Date: Tue, 04 Sep 2018 13:56:33 -0000 Hi, >=20 > Convert host machine endianness to networking endianness for > comparison of incoming packets with BPF filter >=20 >=20 > 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(-) >=20 > 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 >=20 > uint64_t > entry(void *pkt) > { > struct ether_header *ether_header =3D (void *)pkt; >=20 > - if (ether_header->ether_type !=3D __builtin_bswap16(0x0800)) > + if (ether_header->ether_type !=3D htons(0x0800)) Which version of clang do you use? With my one I get: $ clang -O2 -target bpf -c t1.c t1.c:37:34: error: couldn't allocate output register for constraint 'r' if (ether_header->ether_type !=3D ntohs(0x0800)) ^ /usr/include/netinet/in.h:402:21: note: expanded from macro 'ntohs' # define ntohs(x) __bswap_16 (x) ^ /usr/include/bits/byteswap-16.h:31:14: note: expanded from macro '__bswap_1= 6' __asm__ ("rorw $8, %w0" =20 With '-O0' it compiles ok. $ clang -v clang version 4.0.1 (tags/RELEASE_401/final) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /usr/bin Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/7 Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/7 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/7 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Selected multilib: .;@m64 Konstantin > return 0; >=20 > struct iphdr *iphdr =3D (void *)(ether_header + 1); > if (iphdr->protocol !=3D 17 || (iphdr->frag_off & 0x1ffff) !=3D 0 || > - iphdr->daddr !=3D __builtin_bswap32(0x1020304)) > + iphdr->daddr !=3D htonl(0x1020304)) > return 0; >=20 > int hlen =3D iphdr->ihl * 4; > struct udphdr *udphdr =3D (void *)iphdr + hlen; >=20 > - if (udphdr->dest !=3D __builtin_bswap16(5000)) > + if (udphdr->dest !=3D htons(5000)) > return 0; >=20 > 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 >=20 > extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *, unsigned i= nt); >=20 > @@ -29,7 +30,7 @@ entry(const void *pkt) > mb =3D pkt; > eth =3D rte_pktmbuf_mtod(mb, const struct ether_header *); >=20 > - if (eth->ether_type =3D=3D __builtin_bswap16(ETHERTYPE_ARP)) > + if (eth->ether_type =3D=3D htons(ETHERTYPE_ARP)) > rte_pktmbuf_dump(stdout, mb, 64); >=20 > return 1; > -- > 2.17.1