Skip to content

Commit

Permalink
bpf: Fix IPv6 dport byte-order in bpf_sk_lookup
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
  • Loading branch information
joestringer authored and Alexei Starovoitov committed Oct 15, 2018
1 parent 8a615c6 commit 5ef0ae8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -4721,17 +4721,18 @@ static struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple,
} else {
struct in6_addr *src6 = (struct in6_addr *)&tuple->ipv6.saddr;
struct in6_addr *dst6 = (struct in6_addr *)&tuple->ipv6.daddr;
u16 hnum = ntohs(tuple->ipv6.dport);
int sdif = inet6_sdif(skb);

if (proto == IPPROTO_TCP)
sk = __inet6_lookup(net, &tcp_hashinfo, skb, 0,
src6, tuple->ipv6.sport,
dst6, tuple->ipv6.dport,
dst6, hnum,
dif, sdif, &refcounted);
else if (likely(ipv6_bpf_stub))
sk = ipv6_bpf_stub->udp6_lib_lookup(net,
src6, tuple->ipv6.sport,
dst6, tuple->ipv6.dport,
dst6, hnum,
dif, sdif,
&udp_table, skb);
#endif
Expand Down

0 comments on commit 5ef0ae8

Please sign in to comment.