Skip to content

Commit 7d1f12b

Browse files
author
Alexei Starovoitov
committed
Merge branch 'ipv6_sk_lookup_fixes'
Joe Stringer says: ==================== This series includes a couple of fixups for the IPv6 socket lookup helper, to make the API more consistent (always supply all arguments in network byte-order) and to allow its use when IPv6 is compiled as a module. ==================== Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2 parents d04fb13 + 5ef0ae8 commit 7d1f12b

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
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: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4717,21 +4717,24 @@ 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;
4724+
u16 hnum = ntohs(tuple->ipv6.dport);
47244725
int sdif = inet6_sdif(skb);
47254726

47264727
if (proto == IPPROTO_TCP)
47274728
sk = __inet6_lookup(net, &tcp_hashinfo, skb, 0,
47284729
src6, tuple->ipv6.sport,
4729-
dst6, tuple->ipv6.dport,
4730+
dst6, hnum,
47304731
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);
4732+
else if (likely(ipv6_bpf_stub))
4733+
sk = ipv6_bpf_stub->udp6_lib_lookup(net,
4734+
src6, tuple->ipv6.sport,
4735+
dst6, hnum,
4736+
dif, sdif,
4737+
&udp_table, skb);
47354738
#endif
47364739
}
47374740

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)