* [PATCH bpf-next v3] libbpf: fix compilation errors on ubuntu 16.04
@ 2021-07-12 19:20 Yonghong Song
2021-07-12 19:25 ` John Fastabend
2021-07-12 19:26 ` Daniel Borkmann
0 siblings, 2 replies; 4+ messages in thread
From: Yonghong Song @ 2021-07-12 19:20 UTC (permalink / raw)
To: bpf
Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
kernel-team, Kumar Kartikeya Dwivedi
libbpf is used as a submodule in bcc.
When importing latest libbpf repo in bcc, I observed the
following compilation errors when compiling on ubuntu 16.04.
.../netlink.c:416:23: error: ‘TC_H_CLSACT’ undeclared (first use in this function)
*parent = TC_H_MAKE(TC_H_CLSACT,
^
.../netlink.c:418:9: error: ‘TC_H_MIN_INGRESS’ undeclared (first use in this function)
TC_H_MIN_INGRESS : TC_H_MIN_EGRESS);
^
.../netlink.c:418:28: error: ‘TC_H_MIN_EGRESS’ undeclared (first use in this function)
TC_H_MIN_INGRESS : TC_H_MIN_EGRESS);
^
.../netlink.c: In function ‘__get_tc_info’:
.../netlink.c:522:11: error: ‘TCA_BPF_ID’ undeclared (first use in this function)
if (!tbb[TCA_BPF_ID])
^
In ubuntu 16.04, TCA_BPF_* enumerator looks like below
enum {
TCA_BPF_UNSPEC,
TCA_BPF_ACT,
...
TCA_BPF_NAME,
TCA_BPF_FLAGS,
__TCA_BPF_MAX,
};
#define TCA_BPF_MAX (__TCA_BPF_MAX - 1)
while in latest bpf-next, the enumerator looks like
enum {
TCA_BPF_UNSPEC,
...
TCA_BPF_FLAGS,
TCA_BPF_FLAGS_GEN,
TCA_BPF_TAG,
TCA_BPF_ID,
__TCA_BPF_MAX,
};
In this patch, TCA_BPF_ID is defined as a macro with proper value and this
works regardless of whether TCA_BPF_ID is defined in uapi header or not.
TCA_BPF_MAX is also adjusted in a similar way.
Fixes: 715c5ce454a6 ("libbpf: Add low level TC-BPF management API")
Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Yonghong Song <yhs@fb.com>
---
tools/lib/bpf/netlink.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
Changelog:
v2 -> v3:
- define/redefine TCA_BPF_MAX based on latest uapi header.
this enables to remove the v2 check "TCA_BPF_MAX < TCA_BPF_ID"
in __get_tc_info() which may cause -EOPNOTSUPP error
if the library is compiled in old system and used in
newer system.
v1 -> v2:
- gcc 8.3 doesn't like macro condition
(__TCA_BPF_MAX - 1) <= 10
where __TCA_BPF_MAX is an enumerator value.
So define TCA_BPF_ID macro without macro condition.
diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c
index 39f25e09b51e..37cb6b50f4b3 100644
--- a/tools/lib/bpf/netlink.c
+++ b/tools/lib/bpf/netlink.c
@@ -22,6 +22,29 @@
#define SOL_NETLINK 270
#endif
+#ifndef TC_H_CLSACT
+#define TC_H_CLSACT TC_H_INGRESS
+#endif
+
+#ifndef TC_H_MIN_INGRESS
+#define TC_H_MIN_INGRESS 0xFFF2U
+#endif
+
+#ifndef TC_H_MIN_EGRESS
+#define TC_H_MIN_EGRESS 0xFFF3U
+#endif
+
+/* TCA_BPF_ID is an enumerator value in uapi/linux/pkt_cls.h.
+ * Declare it as a macro here so old system can still work
+ * without TCA_BPF_ID defined in pkt_cls.h.
+ */
+#define TCA_BPF_ID 11
+
+#ifdef TCA_BPF_MAX
+#undef TCA_BPF_MAX
+#endif
+#define TCA_BPF_MAX 11
+
typedef int (*libbpf_dump_nlmsg_t)(void *cookie, void *msg, struct nlattr **tb);
typedef int (*__dump_nlmsg_t)(struct nlmsghdr *nlmsg, libbpf_dump_nlmsg_t,
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH bpf-next v3] libbpf: fix compilation errors on ubuntu 16.04
2021-07-12 19:20 [PATCH bpf-next v3] libbpf: fix compilation errors on ubuntu 16.04 Yonghong Song
@ 2021-07-12 19:25 ` John Fastabend
2021-07-12 19:26 ` Daniel Borkmann
1 sibling, 0 replies; 4+ messages in thread
From: John Fastabend @ 2021-07-12 19:25 UTC (permalink / raw)
To: Yonghong Song, bpf
Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
kernel-team, Kumar Kartikeya Dwivedi
Yonghong Song wrote:
> libbpf is used as a submodule in bcc.
> When importing latest libbpf repo in bcc, I observed the
> following compilation errors when compiling on ubuntu 16.04.
> .../netlink.c:416:23: error: ‘TC_H_CLSACT’ undeclared (first use in this function)
> *parent = TC_H_MAKE(TC_H_CLSACT,
> ^
> .../netlink.c:418:9: error: ‘TC_H_MIN_INGRESS’ undeclared (first use in this function)
> TC_H_MIN_INGRESS : TC_H_MIN_EGRESS);
> ^
> .../netlink.c:418:28: error: ‘TC_H_MIN_EGRESS’ undeclared (first use in this function)
> TC_H_MIN_INGRESS : TC_H_MIN_EGRESS);
> ^
> .../netlink.c: In function ‘__get_tc_info’:
> .../netlink.c:522:11: error: ‘TCA_BPF_ID’ undeclared (first use in this function)
> if (!tbb[TCA_BPF_ID])
> ^
>
> In ubuntu 16.04, TCA_BPF_* enumerator looks like below
> enum {
> TCA_BPF_UNSPEC,
> TCA_BPF_ACT,
> ...
> TCA_BPF_NAME,
> TCA_BPF_FLAGS,
> __TCA_BPF_MAX,
> };
> #define TCA_BPF_MAX (__TCA_BPF_MAX - 1)
> while in latest bpf-next, the enumerator looks like
> enum {
> TCA_BPF_UNSPEC,
> ...
> TCA_BPF_FLAGS,
> TCA_BPF_FLAGS_GEN,
> TCA_BPF_TAG,
> TCA_BPF_ID,
> __TCA_BPF_MAX,
> };
>
> In this patch, TCA_BPF_ID is defined as a macro with proper value and this
> works regardless of whether TCA_BPF_ID is defined in uapi header or not.
> TCA_BPF_MAX is also adjusted in a similar way.
>
> Fixes: 715c5ce454a6 ("libbpf: Add low level TC-BPF management API")
> Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> Signed-off-by: Yonghong Song <yhs@fb.com>
> ---
Looks better thanks. Now even compiling on systems with out of date
uapi headers should be fine and running on newer kernels will still
work as expected. Thanks.
Acked-by: John Fastabend <john.fastabend@gmail.com>
> diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c
> index 39f25e09b51e..37cb6b50f4b3 100644
> --- a/tools/lib/bpf/netlink.c
> +++ b/tools/lib/bpf/netlink.c
> @@ -22,6 +22,29 @@
> #define SOL_NETLINK 270
> #endif
>
> +#ifndef TC_H_CLSACT
> +#define TC_H_CLSACT TC_H_INGRESS
> +#endif
> +
> +#ifndef TC_H_MIN_INGRESS
> +#define TC_H_MIN_INGRESS 0xFFF2U
> +#endif
> +
> +#ifndef TC_H_MIN_EGRESS
> +#define TC_H_MIN_EGRESS 0xFFF3U
> +#endif
> +
> +/* TCA_BPF_ID is an enumerator value in uapi/linux/pkt_cls.h.
> + * Declare it as a macro here so old system can still work
> + * without TCA_BPF_ID defined in pkt_cls.h.
> + */
> +#define TCA_BPF_ID 11
I guess compiler is smart enough to see TCA_BPF_ID is the
same value as in headers so it wont throw a redefined warning.
> +
> +#ifdef TCA_BPF_MAX
> +#undef TCA_BPF_MAX
> +#endif
> +#define TCA_BPF_MAX 11
> +
> typedef int (*libbpf_dump_nlmsg_t)(void *cookie, void *msg, struct nlattr **tb);
>
> typedef int (*__dump_nlmsg_t)(struct nlmsghdr *nlmsg, libbpf_dump_nlmsg_t,
> --
> 2.30.2
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next v3] libbpf: fix compilation errors on ubuntu 16.04
2021-07-12 19:20 [PATCH bpf-next v3] libbpf: fix compilation errors on ubuntu 16.04 Yonghong Song
2021-07-12 19:25 ` John Fastabend
@ 2021-07-12 19:26 ` Daniel Borkmann
2021-07-12 20:29 ` Yonghong Song
1 sibling, 1 reply; 4+ messages in thread
From: Daniel Borkmann @ 2021-07-12 19:26 UTC (permalink / raw)
To: Yonghong Song, bpf
Cc: Alexei Starovoitov, Andrii Nakryiko, kernel-team,
Kumar Kartikeya Dwivedi
On 7/12/21 9:20 PM, Yonghong Song wrote:
> libbpf is used as a submodule in bcc.
> When importing latest libbpf repo in bcc, I observed the
> following compilation errors when compiling on ubuntu 16.04.
> .../netlink.c:416:23: error: ‘TC_H_CLSACT’ undeclared (first use in this function)
> *parent = TC_H_MAKE(TC_H_CLSACT,
> ^
> .../netlink.c:418:9: error: ‘TC_H_MIN_INGRESS’ undeclared (first use in this function)
> TC_H_MIN_INGRESS : TC_H_MIN_EGRESS);
> ^
> .../netlink.c:418:28: error: ‘TC_H_MIN_EGRESS’ undeclared (first use in this function)
> TC_H_MIN_INGRESS : TC_H_MIN_EGRESS);
> ^
> .../netlink.c: In function ‘__get_tc_info’:
> .../netlink.c:522:11: error: ‘TCA_BPF_ID’ undeclared (first use in this function)
> if (!tbb[TCA_BPF_ID])
> ^
>
> In ubuntu 16.04, TCA_BPF_* enumerator looks like below
> enum {
> TCA_BPF_UNSPEC,
> TCA_BPF_ACT,
> ...
> TCA_BPF_NAME,
> TCA_BPF_FLAGS,
> __TCA_BPF_MAX,
> };
> #define TCA_BPF_MAX (__TCA_BPF_MAX - 1)
> while in latest bpf-next, the enumerator looks like
> enum {
> TCA_BPF_UNSPEC,
> ...
> TCA_BPF_FLAGS,
> TCA_BPF_FLAGS_GEN,
> TCA_BPF_TAG,
> TCA_BPF_ID,
> __TCA_BPF_MAX,
> };
>
> In this patch, TCA_BPF_ID is defined as a macro with proper value and this
> works regardless of whether TCA_BPF_ID is defined in uapi header or not.
> TCA_BPF_MAX is also adjusted in a similar way.
>
> Fixes: 715c5ce454a6 ("libbpf: Add low level TC-BPF management API")
> Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> Signed-off-by: Yonghong Song <yhs@fb.com>
> ---
> tools/lib/bpf/netlink.c | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
> Changelog:
> v2 -> v3:
> - define/redefine TCA_BPF_MAX based on latest uapi header.
> this enables to remove the v2 check "TCA_BPF_MAX < TCA_BPF_ID"
> in __get_tc_info() which may cause -EOPNOTSUPP error
> if the library is compiled in old system and used in
> newer system.
>
> v1 -> v2:
> - gcc 8.3 doesn't like macro condition
> (__TCA_BPF_MAX - 1) <= 10
> where __TCA_BPF_MAX is an enumerator value.
> So define TCA_BPF_ID macro without macro condition.
>
> diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c
> index 39f25e09b51e..37cb6b50f4b3 100644
> --- a/tools/lib/bpf/netlink.c
> +++ b/tools/lib/bpf/netlink.c
> @@ -22,6 +22,29 @@
> #define SOL_NETLINK 270
> #endif
>
> +#ifndef TC_H_CLSACT
> +#define TC_H_CLSACT TC_H_INGRESS
> +#endif
> +
> +#ifndef TC_H_MIN_INGRESS
> +#define TC_H_MIN_INGRESS 0xFFF2U
> +#endif
> +
> +#ifndef TC_H_MIN_EGRESS
> +#define TC_H_MIN_EGRESS 0xFFF3U
> +#endif
> +
> +/* TCA_BPF_ID is an enumerator value in uapi/linux/pkt_cls.h.
> + * Declare it as a macro here so old system can still work
> + * without TCA_BPF_ID defined in pkt_cls.h.
> + */
> +#define TCA_BPF_ID 11
> +
> +#ifdef TCA_BPF_MAX
> +#undef TCA_BPF_MAX
> +#endif
> +#define TCA_BPF_MAX 11
> +
> typedef int (*libbpf_dump_nlmsg_t)(void *cookie, void *msg, struct nlattr **tb);
>
> typedef int (*__dump_nlmsg_t)(struct nlmsghdr *nlmsg, libbpf_dump_nlmsg_t,
>
See 49a249c38726 ("tools/bpftool: copy a few net uapi headers to tools directory").
If this is not included from tools/lib/bpf/ then it would need fixing from Makefile
side.
Thanks,
Daniel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next v3] libbpf: fix compilation errors on ubuntu 16.04
2021-07-12 19:26 ` Daniel Borkmann
@ 2021-07-12 20:29 ` Yonghong Song
0 siblings, 0 replies; 4+ messages in thread
From: Yonghong Song @ 2021-07-12 20:29 UTC (permalink / raw)
To: Daniel Borkmann, bpf
Cc: Alexei Starovoitov, Andrii Nakryiko, kernel-team,
Kumar Kartikeya Dwivedi
On 7/12/21 12:26 PM, Daniel Borkmann wrote:
> On 7/12/21 9:20 PM, Yonghong Song wrote:
>> libbpf is used as a submodule in bcc.
>> When importing latest libbpf repo in bcc, I observed the
>> following compilation errors when compiling on ubuntu 16.04.
>> .../netlink.c:416:23: error: ‘TC_H_CLSACT’ undeclared (first use in
>> this function)
>> *parent = TC_H_MAKE(TC_H_CLSACT,
>> ^
>> .../netlink.c:418:9: error: ‘TC_H_MIN_INGRESS’ undeclared (first
>> use in this function)
>> TC_H_MIN_INGRESS : TC_H_MIN_EGRESS);
>> ^
>> .../netlink.c:418:28: error: ‘TC_H_MIN_EGRESS’ undeclared (first
>> use in this function)
>> TC_H_MIN_INGRESS : TC_H_MIN_EGRESS);
>> ^
>> .../netlink.c: In function ‘__get_tc_info’:
>> .../netlink.c:522:11: error: ‘TCA_BPF_ID’ undeclared (first use in
>> this function)
>> if (!tbb[TCA_BPF_ID])
>> ^
>>
>> In ubuntu 16.04, TCA_BPF_* enumerator looks like below
>> enum {
>> TCA_BPF_UNSPEC,
>> TCA_BPF_ACT,
>> ...
>> TCA_BPF_NAME,
>> TCA_BPF_FLAGS,
>> __TCA_BPF_MAX,
>> };
>> #define TCA_BPF_MAX (__TCA_BPF_MAX - 1)
>> while in latest bpf-next, the enumerator looks like
>> enum {
>> TCA_BPF_UNSPEC,
>> ...
>> TCA_BPF_FLAGS,
>> TCA_BPF_FLAGS_GEN,
>> TCA_BPF_TAG,
>> TCA_BPF_ID,
>> __TCA_BPF_MAX,
>> };
>>
>> In this patch, TCA_BPF_ID is defined as a macro with proper value and
>> this
>> works regardless of whether TCA_BPF_ID is defined in uapi header or not.
>> TCA_BPF_MAX is also adjusted in a similar way.
>>
>> Fixes: 715c5ce454a6 ("libbpf: Add low level TC-BPF management API")
>> Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>
>> Signed-off-by: Yonghong Song <yhs@fb.com>
>> ---
>> tools/lib/bpf/netlink.c | 23 +++++++++++++++++++++++
>> 1 file changed, 23 insertions(+)
>>
>> Changelog:
>> v2 -> v3:
>> - define/redefine TCA_BPF_MAX based on latest uapi header.
>> this enables to remove the v2 check "TCA_BPF_MAX < TCA_BPF_ID"
>> in __get_tc_info() which may cause -EOPNOTSUPP error
>> if the library is compiled in old system and used in
>> newer system.
>> v1 -> v2:
>> - gcc 8.3 doesn't like macro condition
>> (__TCA_BPF_MAX - 1) <= 10
>> where __TCA_BPF_MAX is an enumerator value.
>> So define TCA_BPF_ID macro without macro condition.
>>
>> diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c
>> index 39f25e09b51e..37cb6b50f4b3 100644
>> --- a/tools/lib/bpf/netlink.c
>> +++ b/tools/lib/bpf/netlink.c
>> @@ -22,6 +22,29 @@
>> #define SOL_NETLINK 270
>> #endif
>> +#ifndef TC_H_CLSACT
>> +#define TC_H_CLSACT TC_H_INGRESS
>> +#endif
>> +
>> +#ifndef TC_H_MIN_INGRESS
>> +#define TC_H_MIN_INGRESS 0xFFF2U
>> +#endif
>> +
>> +#ifndef TC_H_MIN_EGRESS
>> +#define TC_H_MIN_EGRESS 0xFFF3U
>> +#endif
>> +
>> +/* TCA_BPF_ID is an enumerator value in uapi/linux/pkt_cls.h.
>> + * Declare it as a macro here so old system can still work
>> + * without TCA_BPF_ID defined in pkt_cls.h.
>> + */
>> +#define TCA_BPF_ID 11
>> +
>> +#ifdef TCA_BPF_MAX
>> +#undef TCA_BPF_MAX
>> +#endif
>> +#define TCA_BPF_MAX 11
>> +
>> typedef int (*libbpf_dump_nlmsg_t)(void *cookie, void *msg, struct
>> nlattr **tb);
>> typedef int (*__dump_nlmsg_t)(struct nlmsghdr *nlmsg,
>> libbpf_dump_nlmsg_t,
>>
>
> See 49a249c38726 ("tools/bpftool: copy a few net uapi headers to tools
> directory").
> If this is not included from tools/lib/bpf/ then it would need fixing
> from Makefile
> side.
Thanks, Daniel. Yes, the pkt_cls.h and pkt_sched.h are in kernel
tools/include/uapi/linux directory. But these two files are not
in libbpf repo and hence system header files are used.
I will submit a patch to libbpf to fix the issue.
>
> Thanks,
> Daniel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-07-12 20:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-12 19:20 [PATCH bpf-next v3] libbpf: fix compilation errors on ubuntu 16.04 Yonghong Song
2021-07-12 19:25 ` John Fastabend
2021-07-12 19:26 ` Daniel Borkmann
2021-07-12 20:29 ` Yonghong Song
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.