Skip to content

Commit 5ef0ae8

Browse files
joestringerAlexei Starovoitov
authored andcommitted
bpf: Fix IPv6 dport byte-order in bpf_sk_lookup
Commit 6acc9b4 ("bpf: Add helper to retrieve socket in BPF") mistakenly passed the destination port in network byte-order to the IPv6 TCP/UDP socket lookup functions, which meant that BPF writers would need to either manually swap the byte-order of this field or otherwise IPv6 sockets could not be located via this helper. Fix the issue by swapping the byte-order appropriately in the helper. This also makes the API more consistent with the IPv4 version. Fixes: 6acc9b4 ("bpf: Add helper to retrieve socket in BPF") Signed-off-by: Joe Stringer <joe@wand.net.nz> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 8a615c6 commit 5ef0ae8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

net/core/filter.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4721,17 +4721,18 @@ static struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple,
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);
47314732
else if (likely(ipv6_bpf_stub))
47324733
sk = ipv6_bpf_stub->udp6_lib_lookup(net,
47334734
src6, tuple->ipv6.sport,
4734-
dst6, tuple->ipv6.dport,
4735+
dst6, hnum,
47354736
dif, sdif,
47364737
&udp_table, skb);
47374738
#endif

0 commit comments

Comments
 (0)