diff mbox series

[bpf-next] bpf, netns: Fix build without CONFIG_INET

Message ID 20200721100716.720477-1-jakub@cloudflare.com
State Accepted
Delegated to: BPF Maintainers
Headers show
Series [bpf-next] bpf, netns: Fix build without CONFIG_INET | expand

Commit Message

Jakub Sitnicki July 21, 2020, 10:07 a.m. UTC
When CONFIG_NET is set but CONFIG_INET isn't, build fails with:

  ld: kernel/bpf/net_namespace.o: in function `netns_bpf_attach_type_unneed':
  kernel/bpf/net_namespace.c:32: undefined reference to `bpf_sk_lookup_enabled'
  ld: kernel/bpf/net_namespace.o: in function `netns_bpf_attach_type_need':
  kernel/bpf/net_namespace.c:43: undefined reference to `bpf_sk_lookup_enabled'

This is because without CONFIG_INET bpf_sk_lookup_enabled symbol is not
available. Wrap references to bpf_sk_lookup_enabled with preprocessor
conditionals.

Fixes: 1559b4aa1db4 ("inet: Run SK_LOOKUP BPF program on socket lookup")
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
---
 kernel/bpf/net_namespace.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Randy Dunlap July 21, 2020, 2 p.m. UTC | #1
On 7/21/20 3:07 AM, Jakub Sitnicki wrote:
> When CONFIG_NET is set but CONFIG_INET isn't, build fails with:
> 
>   ld: kernel/bpf/net_namespace.o: in function `netns_bpf_attach_type_unneed':
>   kernel/bpf/net_namespace.c:32: undefined reference to `bpf_sk_lookup_enabled'
>   ld: kernel/bpf/net_namespace.o: in function `netns_bpf_attach_type_need':
>   kernel/bpf/net_namespace.c:43: undefined reference to `bpf_sk_lookup_enabled'
> 
> This is because without CONFIG_INET bpf_sk_lookup_enabled symbol is not
> available. Wrap references to bpf_sk_lookup_enabled with preprocessor
> conditionals.
> 
> Fixes: 1559b4aa1db4 ("inet: Run SK_LOOKUP BPF program on socket lookup")
> Reported-by: Randy Dunlap <rdunlap@infradead.org>
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>

Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested

Thanks.

> ---
>  kernel/bpf/net_namespace.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/kernel/bpf/net_namespace.c b/kernel/bpf/net_namespace.c
> index 4e1bcaa2c3cb..71405edd667c 100644
> --- a/kernel/bpf/net_namespace.c
> +++ b/kernel/bpf/net_namespace.c
> @@ -28,9 +28,11 @@ DEFINE_MUTEX(netns_bpf_mutex);
>  static void netns_bpf_attach_type_unneed(enum netns_bpf_attach_type type)
>  {
>  	switch (type) {
> +#ifdef CONFIG_INET
>  	case NETNS_BPF_SK_LOOKUP:
>  		static_branch_dec(&bpf_sk_lookup_enabled);
>  		break;
> +#endif
>  	default:
>  		break;
>  	}
> @@ -39,9 +41,11 @@ static void netns_bpf_attach_type_unneed(enum netns_bpf_attach_type type)
>  static void netns_bpf_attach_type_need(enum netns_bpf_attach_type type)
>  {
>  	switch (type) {
> +#ifdef CONFIG_INET
>  	case NETNS_BPF_SK_LOOKUP:
>  		static_branch_inc(&bpf_sk_lookup_enabled);
>  		break;
> +#endif
>  	default:
>  		break;
>  	}
>
Alexei Starovoitov July 21, 2020, 4:14 p.m. UTC | #2
On Tue, Jul 21, 2020 at 7:01 AM Randy Dunlap <rdunlap@infradead.org> wrote:
>
> On 7/21/20 3:07 AM, Jakub Sitnicki wrote:
> > When CONFIG_NET is set but CONFIG_INET isn't, build fails with:
> >
> >   ld: kernel/bpf/net_namespace.o: in function `netns_bpf_attach_type_unneed':
> >   kernel/bpf/net_namespace.c:32: undefined reference to `bpf_sk_lookup_enabled'
> >   ld: kernel/bpf/net_namespace.o: in function `netns_bpf_attach_type_need':
> >   kernel/bpf/net_namespace.c:43: undefined reference to `bpf_sk_lookup_enabled'
> >
> > This is because without CONFIG_INET bpf_sk_lookup_enabled symbol is not
> > available. Wrap references to bpf_sk_lookup_enabled with preprocessor
> > conditionals.
> >
> > Fixes: 1559b4aa1db4 ("inet: Run SK_LOOKUP BPF program on socket lookup")
> > Reported-by: Randy Dunlap <rdunlap@infradead.org>
> > Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> > Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
>
> Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested

Applied. Thanks
diff mbox series

Patch

diff --git a/kernel/bpf/net_namespace.c b/kernel/bpf/net_namespace.c
index 4e1bcaa2c3cb..71405edd667c 100644
--- a/kernel/bpf/net_namespace.c
+++ b/kernel/bpf/net_namespace.c
@@ -28,9 +28,11 @@  DEFINE_MUTEX(netns_bpf_mutex);
 static void netns_bpf_attach_type_unneed(enum netns_bpf_attach_type type)
 {
 	switch (type) {
+#ifdef CONFIG_INET
 	case NETNS_BPF_SK_LOOKUP:
 		static_branch_dec(&bpf_sk_lookup_enabled);
 		break;
+#endif
 	default:
 		break;
 	}
@@ -39,9 +41,11 @@  static void netns_bpf_attach_type_unneed(enum netns_bpf_attach_type type)
 static void netns_bpf_attach_type_need(enum netns_bpf_attach_type type)
 {
 	switch (type) {
+#ifdef CONFIG_INET
 	case NETNS_BPF_SK_LOOKUP:
 		static_branch_inc(&bpf_sk_lookup_enabled);
 		break;
+#endif
 	default:
 		break;
 	}