mirror of https://gitee.com/openkylin/linux.git
bpf: Allow sk_lookup with IPv6 module
This is a more complete fix than d71019b54b
("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>
This commit is contained in:
parent
d04fb13c9f
commit
8a615c6b03
|
@ -265,6 +265,11 @@ extern const struct ipv6_stub *ipv6_stub __read_mostly;
|
||||||
struct ipv6_bpf_stub {
|
struct ipv6_bpf_stub {
|
||||||
int (*inet6_bind)(struct sock *sk, struct sockaddr *uaddr, int addr_len,
|
int (*inet6_bind)(struct sock *sk, struct sockaddr *uaddr, int addr_len,
|
||||||
bool force_bind_address_no_port, bool with_lock);
|
bool force_bind_address_no_port, bool with_lock);
|
||||||
|
struct sock *(*udp6_lib_lookup)(struct net *net,
|
||||||
|
const struct in6_addr *saddr, __be16 sport,
|
||||||
|
const struct in6_addr *daddr, __be16 dport,
|
||||||
|
int dif, int sdif, struct udp_table *tbl,
|
||||||
|
struct sk_buff *skb);
|
||||||
};
|
};
|
||||||
extern const struct ipv6_bpf_stub *ipv6_bpf_stub __read_mostly;
|
extern const struct ipv6_bpf_stub *ipv6_bpf_stub __read_mostly;
|
||||||
|
|
||||||
|
|
|
@ -4717,7 +4717,7 @@ static struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple,
|
||||||
sk = __udp4_lib_lookup(net, src4, tuple->ipv4.sport,
|
sk = __udp4_lib_lookup(net, src4, tuple->ipv4.sport,
|
||||||
dst4, tuple->ipv4.dport,
|
dst4, tuple->ipv4.dport,
|
||||||
dif, sdif, &udp_table, skb);
|
dif, sdif, &udp_table, skb);
|
||||||
#if IS_REACHABLE(CONFIG_IPV6)
|
#if IS_ENABLED(CONFIG_IPV6)
|
||||||
} else {
|
} else {
|
||||||
struct in6_addr *src6 = (struct in6_addr *)&tuple->ipv6.saddr;
|
struct in6_addr *src6 = (struct in6_addr *)&tuple->ipv6.saddr;
|
||||||
struct in6_addr *dst6 = (struct in6_addr *)&tuple->ipv6.daddr;
|
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,
|
||||||
src6, tuple->ipv6.sport,
|
src6, tuple->ipv6.sport,
|
||||||
dst6, tuple->ipv6.dport,
|
dst6, tuple->ipv6.dport,
|
||||||
dif, sdif, &refcounted);
|
dif, sdif, &refcounted);
|
||||||
else
|
else if (likely(ipv6_bpf_stub))
|
||||||
sk = __udp6_lib_lookup(net, src6, tuple->ipv6.sport,
|
sk = ipv6_bpf_stub->udp6_lib_lookup(net,
|
||||||
dst6, tuple->ipv6.dport,
|
src6, tuple->ipv6.sport,
|
||||||
dif, sdif, &udp_table, skb);
|
dst6, tuple->ipv6.dport,
|
||||||
|
dif, sdif,
|
||||||
|
&udp_table, skb);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -901,6 +901,7 @@ static const struct ipv6_stub ipv6_stub_impl = {
|
||||||
|
|
||||||
static const struct ipv6_bpf_stub ipv6_bpf_stub_impl = {
|
static const struct ipv6_bpf_stub ipv6_bpf_stub_impl = {
|
||||||
.inet6_bind = __inet6_bind,
|
.inet6_bind = __inet6_bind,
|
||||||
|
.udp6_lib_lookup = __udp6_lib_lookup,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __init inet6_init(void)
|
static int __init inet6_init(void)
|
||||||
|
|
Loading…
Reference in New Issue