* [PATCH bpf-next] libbpf: make bpf_endian co-exist with vmlinux.h
@ 2020-06-30 2:05 Andrii Nakryiko
2020-06-30 3:09 ` Alexei Starovoitov
0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2020-06-30 2:05 UTC (permalink / raw)
To: bpf, netdev, ast, daniel; +Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko
Copy over few #defines from UAPI swab.h header to make all the rest of
bpf_endian.h work and not rely on any extra headers. This way it can be used
both with linux header includes, as well with a vmlinux.h. This has been
a frequent complaint from users, that need this header.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
tools/lib/bpf/bpf_endian.h | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/tools/lib/bpf/bpf_endian.h b/tools/lib/bpf/bpf_endian.h
index fbe28008450f..a4be8a70845c 100644
--- a/tools/lib/bpf/bpf_endian.h
+++ b/tools/lib/bpf/bpf_endian.h
@@ -2,8 +2,26 @@
#ifndef __BPF_ENDIAN__
#define __BPF_ENDIAN__
-#include <linux/stddef.h>
-#include <linux/swab.h>
+/* copied from include/uapi/linux/swab.h */
+#define ___constant_swab16(x) ((__u16)( \
+ (((__u16)(x) & (__u16)0x00ffU) << 8) | \
+ (((__u16)(x) & (__u16)0xff00U) >> 8)))
+
+#define ___constant_swab32(x) ((__u32)( \
+ (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
+ (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
+ (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
+ (((__u32)(x) & (__u32)0xff000000UL) >> 24)))
+
+#define ___constant_swab64(x) ((__u64)( \
+ (((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) | \
+ (((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) | \
+ (((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) | \
+ (((__u64)(x) & (__u64)0x00000000ff000000ULL) << 8) | \
+ (((__u64)(x) & (__u64)0x000000ff00000000ULL) >> 8) | \
+ (((__u64)(x) & (__u64)0x0000ff0000000000ULL) >> 24) | \
+ (((__u64)(x) & (__u64)0x00ff000000000000ULL) >> 40) | \
+ (((__u64)(x) & (__u64)0xff00000000000000ULL) >> 56)))
/* LLVM's BPF target selects the endianness of the CPU
* it compiles on, or the user specifies (bpfel/bpfeb),
--
2.24.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] libbpf: make bpf_endian co-exist with vmlinux.h
2020-06-30 2:05 [PATCH bpf-next] libbpf: make bpf_endian co-exist with vmlinux.h Andrii Nakryiko
@ 2020-06-30 3:09 ` Alexei Starovoitov
2020-06-30 3:35 ` Andrii Nakryiko
0 siblings, 1 reply; 3+ messages in thread
From: Alexei Starovoitov @ 2020-06-30 3:09 UTC (permalink / raw)
To: Andrii Nakryiko; +Cc: bpf, netdev, ast, daniel, andrii.nakryiko, kernel-team
On Mon, Jun 29, 2020 at 07:05:38PM -0700, Andrii Nakryiko wrote:
> Copy over few #defines from UAPI swab.h header to make all the rest of
> bpf_endian.h work and not rely on any extra headers. This way it can be used
> both with linux header includes, as well with a vmlinux.h. This has been
> a frequent complaint from users, that need this header.
>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> ---
> tools/lib/bpf/bpf_endian.h | 22 ++++++++++++++++++++--
> 1 file changed, 20 insertions(+), 2 deletions(-)
>
> diff --git a/tools/lib/bpf/bpf_endian.h b/tools/lib/bpf/bpf_endian.h
> index fbe28008450f..a4be8a70845c 100644
> --- a/tools/lib/bpf/bpf_endian.h
> +++ b/tools/lib/bpf/bpf_endian.h
> @@ -2,8 +2,26 @@
> #ifndef __BPF_ENDIAN__
> #define __BPF_ENDIAN__
>
> -#include <linux/stddef.h>
> -#include <linux/swab.h>
> +/* copied from include/uapi/linux/swab.h */
You cannot just copy due to different licenses.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] libbpf: make bpf_endian co-exist with vmlinux.h
2020-06-30 3:09 ` Alexei Starovoitov
@ 2020-06-30 3:35 ` Andrii Nakryiko
0 siblings, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2020-06-30 3:35 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: Andrii Nakryiko, bpf, Networking, Alexei Starovoitov,
Daniel Borkmann, Kernel Team
On Mon, Jun 29, 2020 at 8:09 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Mon, Jun 29, 2020 at 07:05:38PM -0700, Andrii Nakryiko wrote:
> > Copy over few #defines from UAPI swab.h header to make all the rest of
> > bpf_endian.h work and not rely on any extra headers. This way it can be used
> > both with linux header includes, as well with a vmlinux.h. This has been
> > a frequent complaint from users, that need this header.
> >
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> > ---
> > tools/lib/bpf/bpf_endian.h | 22 ++++++++++++++++++++--
> > 1 file changed, 20 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/lib/bpf/bpf_endian.h b/tools/lib/bpf/bpf_endian.h
> > index fbe28008450f..a4be8a70845c 100644
> > --- a/tools/lib/bpf/bpf_endian.h
> > +++ b/tools/lib/bpf/bpf_endian.h
> > @@ -2,8 +2,26 @@
> > #ifndef __BPF_ENDIAN__
> > #define __BPF_ENDIAN__
> >
> > -#include <linux/stddef.h>
> > -#include <linux/swab.h>
> > +/* copied from include/uapi/linux/swab.h */
>
> You cannot just copy due to different licenses.
Ah, I see. I was thinking that because it's from UAPI header it might
be ok. Alright, I'll try to re-implement it instead.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-06-30 3:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-30 2:05 [PATCH bpf-next] libbpf: make bpf_endian co-exist with vmlinux.h Andrii Nakryiko
2020-06-30 3:09 ` Alexei Starovoitov
2020-06-30 3:35 ` Andrii Nakryiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).