mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-12 07:37:31 -04:00
BACKPORT: inet: Extract helper for selecting socket from reuseport group
Prepare for calling into reuseport from __inet_lookup_listener as well. Change-Id: I55e2796888ca2bd56a1086292da90a3e3990a22d 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-4-jakub@cloudflare.com
This commit is contained in:
parent
6fc408d790
commit
3dfc07553c
2 changed files with 24 additions and 13 deletions
|
|
@ -252,6 +252,21 @@ static inline int compute_score(struct sock *sk, struct net *net,
|
|||
return score;
|
||||
}
|
||||
|
||||
static inline struct sock *lookup_reuseport(struct net *net, struct sock *sk,
|
||||
struct sk_buff *skb, int doff,
|
||||
__be32 saddr, __be16 sport,
|
||||
__be32 daddr, unsigned short hnum)
|
||||
{
|
||||
struct sock *reuse_sk = NULL;
|
||||
u32 phash;
|
||||
|
||||
if (sk->sk_reuseport) {
|
||||
phash = inet_ehashfn(net, daddr, hnum, saddr, sport);
|
||||
reuse_sk = reuseport_select_sock(sk, phash, skb, doff);
|
||||
}
|
||||
return reuse_sk;
|
||||
}
|
||||
|
||||
/*
|
||||
* Here are some nice properties to exploit here. The BSD API
|
||||
* does not allow a listening sock to specify the remote port nor the
|
||||
|
|
@ -271,21 +286,17 @@ static struct sock *inet_lhash2_lookup(struct net *net,
|
|||
struct inet_connection_sock *icsk;
|
||||
struct sock *sk, *result = NULL;
|
||||
int score, hiscore = 0;
|
||||
u32 phash = 0;
|
||||
|
||||
inet_lhash2_for_each_icsk_rcu(icsk, &ilb2->head) {
|
||||
sk = (struct sock *)icsk;
|
||||
score = compute_score(sk, net, hnum, daddr,
|
||||
dif, sdif, exact_dif);
|
||||
if (score > hiscore) {
|
||||
if (sk->sk_reuseport) {
|
||||
phash = inet_ehashfn(net, daddr, hnum,
|
||||
saddr, sport);
|
||||
result = reuseport_select_sock(sk, phash,
|
||||
skb, doff);
|
||||
if (result)
|
||||
return result;
|
||||
}
|
||||
result = lookup_reuseport(net, sk, skb, doff,
|
||||
saddr, sport, daddr, hnum);
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
result = sk;
|
||||
hiscore = score;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -409,10 +409,10 @@ static u32 udp_ehashfn(const struct net *net, const __be32 laddr,
|
|||
udp_ehash_secret + net_hash_mix(net));
|
||||
}
|
||||
|
||||
static inline struct sock *lookup_reuseport(struct net *net, struct sock *sk,
|
||||
struct sk_buff *skb,
|
||||
__be32 saddr, __be16 sport,
|
||||
__be32 daddr, unsigned short hnum)
|
||||
static struct sock *lookup_reuseport(struct net *net, struct sock *sk,
|
||||
struct sk_buff *skb,
|
||||
__be32 saddr, __be16 sport,
|
||||
__be32 daddr, unsigned short hnum)
|
||||
{
|
||||
struct sock *reuse_sk = NULL;
|
||||
u32 hash;
|
||||
|
|
|
|||
Loading…
Reference in a new issue