lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 28 Jun 2022 21:48:09 +0200
From:   Alexander Lobakin <alexandr.lobakin@...el.com>
To:     Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Andrii Nakryiko <andrii@...nel.org>
Cc:     Alexander Lobakin <alexandr.lobakin@...el.com>,
        Larysa Zaremba <larysa.zaremba@...el.com>,
        Michal Swiatkowski <michal.swiatkowski@...ux.intel.com>,
        Jesper Dangaard Brouer <hawk@...nel.org>,
        Björn Töpel <bjorn@...nel.org>,
        Magnus Karlsson <magnus.karlsson@...el.com>,
        Maciej Fijalkowski <maciej.fijalkowski@...el.com>,
        Jonathan Lemon <jonathan.lemon@...il.com>,
        Toke Hoiland-Jorgensen <toke@...hat.com>,
        Lorenzo Bianconi <lorenzo@...nel.org>,
        "David S. Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>,
        Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>,
        Jesse Brandeburg <jesse.brandeburg@...el.com>,
        John Fastabend <john.fastabend@...il.com>,
        Yajun Deng <yajun.deng@...ux.dev>,
        Willem de Bruijn <willemb@...gle.com>, bpf@...r.kernel.org,
        netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
        xdp-hints@...-project.net
Subject: [PATCH RFC bpf-next 49/52] libbpf: add LE <--> CPU conversion helpers

From: Larysa Zaremba <larysa.zaremba@...el.com>

XDP Generic metadata structure has fields of the explicit
Endianness, all 16, 32 and 64-bit wide.
To make it easier to access them, define __le{16,32,64} <--> cpu
helpers the same way it's done for the BEs.

Signed-off-by: Larysa Zaremba <larysa.zaremba@...el.com>
Signed-off-by: Alexander Lobakin <alexandr.lobakin@...el.com>
---
 tools/lib/bpf/bpf_endian.h | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tools/lib/bpf/bpf_endian.h b/tools/lib/bpf/bpf_endian.h
index b03db6aa3f14..35941e6f1d99 100644
--- a/tools/lib/bpf/bpf_endian.h
+++ b/tools/lib/bpf/bpf_endian.h
@@ -60,6 +60,18 @@
 # define __bpf_cpu_to_be64(x)		__builtin_bswap64(x)
 # define __bpf_constant_be64_to_cpu(x)	___bpf_swab64(x)
 # define __bpf_constant_cpu_to_be64(x)	___bpf_swab64(x)
+# define __bpf_le16_to_cpu(x)		(x)
+# define __bpf_cpu_to_le16(x)		(x)
+# define __bpf_constant_le16_to_cpu(x)	(x)
+# define __bpf_constant_cpu_to_le16(x)	(x)
+# define __bpf_le32_to_cpu(x)		(x)
+# define __bpf_cpu_to_le32(x)		(x)
+# define __bpf_constant_le32_to_cpu(x)	(x)
+# define __bpf_constant_cpu_to_le32(x)	(x)
+# define __bpf_le64_to_cpu(x)		(x)
+# define __bpf_cpu_to_le64(x)		(x)
+# define __bpf_constant_le64_to_cpu(x)	(x)
+# define __bpf_constant_cpu_to_le64(x)	(x)
 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 # define __bpf_ntohs(x)			(x)
 # define __bpf_htons(x)			(x)
@@ -73,6 +85,18 @@
 # define __bpf_cpu_to_be64(x)		(x)
 # define __bpf_constant_be64_to_cpu(x)  (x)
 # define __bpf_constant_cpu_to_be64(x)  (x)
+# define __bpf_le16_to_cpu(x)		__builtin_bswap16(x)
+# define __bpf_cpu_to_le16(x)		__builtin_bswap16(x)
+# define __bpf_constant_le16_to_cpu(x)	___bpf_swab16(x)
+# define __bpf_constant_cpu_to_le16(x)	___bpf_swab16(x)
+# define __bpf_le32_to_cpu(x)		__builtin_bswap32(x)
+# define __bpf_cpu_to_le32(x)		__builtin_bswap32(x)
+# define __bpf_constant_le32_to_cpu(x)	___bpf_swab32(x)
+# define __bpf_constant_cpu_to_le32(x)	___bpf_swab32(x)
+# define __bpf_le64_to_cpu(x)		__builtin_bswap64(x)
+# define __bpf_cpu_to_le64(x)		__builtin_bswap64(x)
+# define __bpf_constant_le64_to_cpu(x)	___bpf_swab64(x)
+# define __bpf_constant_cpu_to_le64(x)	___bpf_swab64(x)
 #else
 # error "Fix your compiler's __BYTE_ORDER__?!"
 #endif
@@ -87,5 +111,11 @@
 #define bpf_ntohl(x)			__bpf_endop(ntohl, x)
 #define bpf_cpu_to_be64(x)		__bpf_endop(cpu_to_be64, x)
 #define bpf_be64_to_cpu(x)		__bpf_endop(be64_to_cpu, x)
+#define bpf_cpu_to_le16(x)		__bpf_endop(cpu_to_le16, x)
+#define bpf_le16_to_cpu(x)		__bpf_endop(le16_to_cpu, x)
+#define bpf_cpu_to_le32(x)		__bpf_endop(cpu_to_le32, x)
+#define bpf_le32_to_cpu(x)		__bpf_endop(le32_to_cpu, x)
+#define bpf_cpu_to_le64(x)		__bpf_endop(cpu_to_le64, x)
+#define bpf_le64_to_cpu(x)		__bpf_endop(le64_to_cpu, x)
 
 #endif /* __BPF_ENDIAN__ */
-- 
2.36.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ