Skip to content

Commit 8a615c6

Browse files
joestringerAlexei Starovoitov
authored andcommitted
bpf: Allow sk_lookup with IPv6 module
This is a more complete fix than d71019b ("net: core: Fix build with CONFIG_IPV6=m"), so that IPv6 sockets may be looked up if the IPv6 module is loaded (not just if it's compiled in). Signed-off-by: Joe Stringer <joe@wand.net.nz> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent d04fb13 commit 8a615c6

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

include/net/addrconf.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ extern const struct ipv6_stub *ipv6_stub __read_mostly;
265265
struct ipv6_bpf_stub {
266266
int (*inet6_bind)(struct sock *sk, struct sockaddr *uaddr, int addr_len,
267267
bool force_bind_address_no_port, bool with_lock);
268+
struct sock *(*udp6_lib_lookup)(struct net *net,
269+
const struct in6_addr *saddr, __be16 sport,
270+
const struct in6_addr *daddr, __be16 dport,
271+
int dif, int sdif, struct udp_table *tbl,
272+
struct sk_buff *skb);
268273
};
269274
extern const struct ipv6_bpf_stub *ipv6_bpf_stub __read_mostly;
270275

net/core/filter.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4717,7 +4717,7 @@ static struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple,
47174717
sk = __udp4_lib_lookup(net, src4, tuple->ipv4.sport,
47184718
dst4, tuple->ipv4.dport,
47194719
dif, sdif, &udp_table, skb);
4720-
#if IS_REACHABLE(CONFIG_IPV6)
4720+
#if IS_ENABLED(CONFIG_IPV6)
47214721
} else {
47224722
struct in6_addr *src6 = (struct in6_addr *)&tuple->ipv6.saddr;
47234723
struct in6_addr *dst6 = (struct in6_addr *)&tuple->ipv6.daddr;
@@ -4728,10 +4728,12 @@ static struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple,
47284728
src6, tuple->ipv6.sport,
47294729
dst6, tuple->ipv6.dport,
47304730
dif, sdif, &refcounted);
4731-
else
4732-
sk = __udp6_lib_lookup(net, src6, tuple->ipv6.sport,
4733-
dst6, tuple->ipv6.dport,
4734-
dif, sdif, &udp_table, skb);
4731+
else if (likely(ipv6_bpf_stub))
4732+
sk = ipv6_bpf_stub->udp6_lib_lookup(net,
4733+
src6, tuple->ipv6.sport,
4734+
dst6, tuple->ipv6.dport,
4735+
dif, sdif,
4736+
&udp_table, skb);
47354737
#endif
47364738
}
47374739

net/ipv6/af_inet6.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ static const struct ipv6_stub ipv6_stub_impl = {
901901

902902
static const struct ipv6_bpf_stub ipv6_bpf_stub_impl = {
903903
.inet6_bind = __inet6_bind,
904+
.udp6_lib_lookup = __udp6_lib_lookup,
904905
};
905906

906907
static int __init inet6_init(void)

0 commit comments

Comments
 (0)