Skip to content

Commit df3f94a

Browse files
arndbborkmann
authored andcommitted
bpf: fix building without CONFIG_INET
The newly added TCP and UDP handling fails to link when CONFIG_INET is disabled: net/core/filter.o: In function `sk_lookup': filter.c:(.text+0x7ff8): undefined reference to `tcp_hashinfo' filter.c:(.text+0x7ffc): undefined reference to `tcp_hashinfo' filter.c:(.text+0x8020): undefined reference to `__inet_lookup_established' filter.c:(.text+0x8058): undefined reference to `__inet_lookup_listener' filter.c:(.text+0x8068): undefined reference to `udp_table' filter.c:(.text+0x8070): undefined reference to `udp_table' filter.c:(.text+0x808c): undefined reference to `__udp4_lib_lookup' net/core/filter.o: In function `bpf_sk_release': filter.c:(.text+0x82e8): undefined reference to `sock_gen_put' Wrap the related sections of code in #ifdefs for the config option. Furthermore, sk_lookup() should always have been marked 'static', this also avoids a warning about a missing prototype when building with 'make W=1'. Fixes: 6acc9b4 ("bpf: Add helper to retrieve socket in BPF") Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Joe Stringer <[email protected]> Acked-by: Song Liu <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent a2046de commit df3f94a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

net/core/filter.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4817,8 +4817,9 @@ static const struct bpf_func_proto bpf_lwt_seg6_adjust_srh_proto = {
48174817
};
48184818
#endif /* CONFIG_IPV6_SEG6_BPF */
48194819

4820-
struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple,
4821-
struct sk_buff *skb, u8 family, u8 proto)
4820+
#ifdef CONFIG_INET
4821+
static struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple,
4822+
struct sk_buff *skb, u8 family, u8 proto)
48224823
{
48234824
int dif = skb->dev->ifindex;
48244825
bool refcounted = false;
@@ -4951,6 +4952,7 @@ static const struct bpf_func_proto bpf_sk_release_proto = {
49514952
.ret_type = RET_INTEGER,
49524953
.arg1_type = ARG_PTR_TO_SOCKET,
49534954
};
4955+
#endif /* CONFIG_INET */
49544956

49554957
bool bpf_helper_changes_pkt_data(void *func)
49564958
{
@@ -5158,12 +5160,14 @@ tc_cls_act_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
51585160
case BPF_FUNC_skb_ancestor_cgroup_id:
51595161
return &bpf_skb_ancestor_cgroup_id_proto;
51605162
#endif
5163+
#ifdef CONFIG_INET
51615164
case BPF_FUNC_sk_lookup_tcp:
51625165
return &bpf_sk_lookup_tcp_proto;
51635166
case BPF_FUNC_sk_lookup_udp:
51645167
return &bpf_sk_lookup_udp_proto;
51655168
case BPF_FUNC_sk_release:
51665169
return &bpf_sk_release_proto;
5170+
#endif
51675171
default:
51685172
return bpf_base_func_proto(func_id);
51695173
}
@@ -5264,12 +5268,14 @@ sk_skb_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
52645268
return &bpf_sk_redirect_hash_proto;
52655269
case BPF_FUNC_get_local_storage:
52665270
return &bpf_get_local_storage_proto;
5271+
#ifdef CONFIG_INET
52675272
case BPF_FUNC_sk_lookup_tcp:
52685273
return &bpf_sk_lookup_tcp_proto;
52695274
case BPF_FUNC_sk_lookup_udp:
52705275
return &bpf_sk_lookup_udp_proto;
52715276
case BPF_FUNC_sk_release:
52725277
return &bpf_sk_release_proto;
5278+
#endif
52735279
default:
52745280
return bpf_base_func_proto(func_id);
52755281
}

0 commit comments

Comments
 (0)