mirror of
git://git.yoctoproject.org/linux-yocto.git
synced 2025-07-07 22:35:42 +02:00
inet6: Extract helper for selecting socket from reuseport group
Prepare for calling into reuseport from inet6_lookup_listener as well. Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Andrii Nakryiko <andriin@fb.com> Link: https://lore.kernel.org/bpf/20200717103536.397595-6-jakub@cloudflare.com
This commit is contained in:
parent
1559b4aa1d
commit
5df6531292
|
@ -111,6 +111,23 @@ static inline int compute_score(struct sock *sk, struct net *net,
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct sock *lookup_reuseport(struct net *net, struct sock *sk,
|
||||||
|
struct sk_buff *skb, int doff,
|
||||||
|
const struct in6_addr *saddr,
|
||||||
|
__be16 sport,
|
||||||
|
const struct in6_addr *daddr,
|
||||||
|
unsigned short hnum)
|
||||||
|
{
|
||||||
|
struct sock *reuse_sk = NULL;
|
||||||
|
u32 phash;
|
||||||
|
|
||||||
|
if (sk->sk_reuseport) {
|
||||||
|
phash = inet6_ehashfn(net, daddr, hnum, saddr, sport);
|
||||||
|
reuse_sk = reuseport_select_sock(sk, phash, skb, doff);
|
||||||
|
}
|
||||||
|
return reuse_sk;
|
||||||
|
}
|
||||||
|
|
||||||
/* called with rcu_read_lock() */
|
/* called with rcu_read_lock() */
|
||||||
static struct sock *inet6_lhash2_lookup(struct net *net,
|
static struct sock *inet6_lhash2_lookup(struct net *net,
|
||||||
struct inet_listen_hashbucket *ilb2,
|
struct inet_listen_hashbucket *ilb2,
|
||||||
|
@ -123,21 +140,17 @@ static struct sock *inet6_lhash2_lookup(struct net *net,
|
||||||
struct inet_connection_sock *icsk;
|
struct inet_connection_sock *icsk;
|
||||||
struct sock *sk, *result = NULL;
|
struct sock *sk, *result = NULL;
|
||||||
int score, hiscore = 0;
|
int score, hiscore = 0;
|
||||||
u32 phash = 0;
|
|
||||||
|
|
||||||
inet_lhash2_for_each_icsk_rcu(icsk, &ilb2->head) {
|
inet_lhash2_for_each_icsk_rcu(icsk, &ilb2->head) {
|
||||||
sk = (struct sock *)icsk;
|
sk = (struct sock *)icsk;
|
||||||
score = compute_score(sk, net, hnum, daddr, dif, sdif,
|
score = compute_score(sk, net, hnum, daddr, dif, sdif,
|
||||||
exact_dif);
|
exact_dif);
|
||||||
if (score > hiscore) {
|
if (score > hiscore) {
|
||||||
if (sk->sk_reuseport) {
|
result = lookup_reuseport(net, sk, skb, doff,
|
||||||
phash = inet6_ehashfn(net, daddr, hnum,
|
saddr, sport, daddr, hnum);
|
||||||
saddr, sport);
|
if (result)
|
||||||
result = reuseport_select_sock(sk, phash,
|
return result;
|
||||||
skb, doff);
|
|
||||||
if (result)
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
result = sk;
|
result = sk;
|
||||||
hiscore = score;
|
hiscore = score;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user