Commit ce796e60 authored by Lorenz Bauer's avatar Lorenz Bauer Committed by Martin KaFai Lau

net: export inet_lookup_reuseport and inet6_lookup_reuseport

Rename the existing reuseport helpers for IPv4 and IPv6 so that they
can be invoked in the follow up commit. Export them so that building
DCCP and IPv6 as a module works.

No change in functionality.
Reviewed-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: default avatarLorenz Bauer <lmb@isovalent.com>
Link: https://lore.kernel.org/r/20230720-so-reuseport-v6-3-7021b683cdae@isovalent.comSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parent 67312adc
...@@ -48,6 +48,13 @@ struct sock *__inet6_lookup_established(struct net *net, ...@@ -48,6 +48,13 @@ struct sock *__inet6_lookup_established(struct net *net,
const u16 hnum, const int dif, const u16 hnum, const int dif,
const int sdif); const int sdif);
struct sock *inet6_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 *inet6_lookup_listener(struct net *net, struct sock *inet6_lookup_listener(struct net *net,
struct inet_hashinfo *hashinfo, struct inet_hashinfo *hashinfo,
struct sk_buff *skb, int doff, struct sk_buff *skb, int doff,
......
...@@ -379,6 +379,11 @@ struct sock *__inet_lookup_established(struct net *net, ...@@ -379,6 +379,11 @@ struct sock *__inet_lookup_established(struct net *net,
const __be32 daddr, const u16 hnum, const __be32 daddr, const u16 hnum,
const int dif, const int sdif); const int dif, const int sdif);
struct sock *inet_lookup_reuseport(struct net *net, struct sock *sk,
struct sk_buff *skb, int doff,
__be32 saddr, __be16 sport,
__be32 daddr, unsigned short hnum);
static inline struct sock * static inline struct sock *
inet_lookup_established(struct net *net, struct inet_hashinfo *hashinfo, inet_lookup_established(struct net *net, struct inet_hashinfo *hashinfo,
const __be32 saddr, const __be16 sport, const __be32 saddr, const __be16 sport,
......
...@@ -332,10 +332,10 @@ static inline int compute_score(struct sock *sk, struct net *net, ...@@ -332,10 +332,10 @@ 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 sock *inet_lookup_reuseport(struct net *net, struct sock *sk,
struct sk_buff *skb, int doff, struct sk_buff *skb, int doff,
__be32 saddr, __be16 sport, __be32 saddr, __be16 sport,
__be32 daddr, unsigned short hnum) __be32 daddr, unsigned short hnum)
{ {
struct sock *reuse_sk = NULL; struct sock *reuse_sk = NULL;
u32 phash; u32 phash;
...@@ -346,6 +346,7 @@ static inline struct sock *lookup_reuseport(struct net *net, struct sock *sk, ...@@ -346,6 +346,7 @@ static inline struct sock *lookup_reuseport(struct net *net, struct sock *sk,
} }
return reuse_sk; return reuse_sk;
} }
EXPORT_SYMBOL_GPL(inet_lookup_reuseport);
/* /*
* Here are some nice properties to exploit here. The BSD API * Here are some nice properties to exploit here. The BSD API
...@@ -369,8 +370,8 @@ static struct sock *inet_lhash2_lookup(struct net *net, ...@@ -369,8 +370,8 @@ static struct sock *inet_lhash2_lookup(struct net *net,
sk_nulls_for_each_rcu(sk, node, &ilb2->nulls_head) { sk_nulls_for_each_rcu(sk, node, &ilb2->nulls_head) {
score = compute_score(sk, net, hnum, daddr, dif, sdif); score = compute_score(sk, net, hnum, daddr, dif, sdif);
if (score > hiscore) { if (score > hiscore) {
result = lookup_reuseport(net, sk, skb, doff, result = inet_lookup_reuseport(net, sk, skb, doff,
saddr, sport, daddr, hnum); saddr, sport, daddr, hnum);
if (result) if (result)
return result; return result;
...@@ -399,7 +400,7 @@ static inline struct sock *inet_lookup_run_bpf(struct net *net, ...@@ -399,7 +400,7 @@ static inline struct sock *inet_lookup_run_bpf(struct net *net,
if (no_reuseport || IS_ERR_OR_NULL(sk)) if (no_reuseport || IS_ERR_OR_NULL(sk))
return sk; return sk;
reuse_sk = lookup_reuseport(net, sk, skb, doff, saddr, sport, daddr, hnum); reuse_sk = inet_lookup_reuseport(net, sk, skb, doff, saddr, sport, daddr, hnum);
if (reuse_sk) if (reuse_sk)
sk = reuse_sk; sk = reuse_sk;
return sk; return sk;
......
...@@ -111,12 +111,12 @@ static inline int compute_score(struct sock *sk, struct net *net, ...@@ -111,12 +111,12 @@ 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 sock *inet6_lookup_reuseport(struct net *net, struct sock *sk,
struct sk_buff *skb, int doff, struct sk_buff *skb, int doff,
const struct in6_addr *saddr, const struct in6_addr *saddr,
__be16 sport, __be16 sport,
const struct in6_addr *daddr, const struct in6_addr *daddr,
unsigned short hnum) unsigned short hnum)
{ {
struct sock *reuse_sk = NULL; struct sock *reuse_sk = NULL;
u32 phash; u32 phash;
...@@ -127,6 +127,7 @@ static inline struct sock *lookup_reuseport(struct net *net, struct sock *sk, ...@@ -127,6 +127,7 @@ static inline struct sock *lookup_reuseport(struct net *net, struct sock *sk,
} }
return reuse_sk; return reuse_sk;
} }
EXPORT_SYMBOL_GPL(inet6_lookup_reuseport);
/* 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,
...@@ -143,8 +144,8 @@ static struct sock *inet6_lhash2_lookup(struct net *net, ...@@ -143,8 +144,8 @@ static struct sock *inet6_lhash2_lookup(struct net *net,
sk_nulls_for_each_rcu(sk, node, &ilb2->nulls_head) { sk_nulls_for_each_rcu(sk, node, &ilb2->nulls_head) {
score = compute_score(sk, net, hnum, daddr, dif, sdif); score = compute_score(sk, net, hnum, daddr, dif, sdif);
if (score > hiscore) { if (score > hiscore) {
result = lookup_reuseport(net, sk, skb, doff, result = inet6_lookup_reuseport(net, sk, skb, doff,
saddr, sport, daddr, hnum); saddr, sport, daddr, hnum);
if (result) if (result)
return result; return result;
...@@ -175,7 +176,7 @@ static inline struct sock *inet6_lookup_run_bpf(struct net *net, ...@@ -175,7 +176,7 @@ static inline struct sock *inet6_lookup_run_bpf(struct net *net,
if (no_reuseport || IS_ERR_OR_NULL(sk)) if (no_reuseport || IS_ERR_OR_NULL(sk))
return sk; return sk;
reuse_sk = lookup_reuseport(net, sk, skb, doff, saddr, sport, daddr, hnum); reuse_sk = inet6_lookup_reuseport(net, sk, skb, doff, saddr, sport, daddr, hnum);
if (reuse_sk) if (reuse_sk)
sk = reuse_sk; sk = reuse_sk;
return sk; return sk;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment