Commit 41db7626 authored by Eric Dumazet's avatar Eric Dumazet Committed by Jakub Kicinski

inet: returns a bool from inet_sk_get_local_port_range()

Change inet_sk_get_local_port_range() to return a boolean,
telling the callers if the port range was provided by
IP_LOCAL_PORT_RANGE socket option.

Adds documentation while we are at it.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Reviewed-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
Link: https://lore.kernel.org/r/20231214192939.1962891-2-edumazet@google.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 758a8d5b
...@@ -356,7 +356,7 @@ static inline void inet_get_local_port_range(const struct net *net, int *low, in ...@@ -356,7 +356,7 @@ static inline void inet_get_local_port_range(const struct net *net, int *low, in
*low = range & 0xffff; *low = range & 0xffff;
*high = range >> 16; *high = range >> 16;
} }
void inet_sk_get_local_port_range(const struct sock *sk, int *low, int *high); bool inet_sk_get_local_port_range(const struct sock *sk, int *low, int *high);
#ifdef CONFIG_SYSCTL #ifdef CONFIG_SYSCTL
static inline bool inet_is_local_reserved_port(struct net *net, unsigned short port) static inline bool inet_is_local_reserved_port(struct net *net, unsigned short port)
......
...@@ -117,16 +117,25 @@ bool inet_rcv_saddr_any(const struct sock *sk) ...@@ -117,16 +117,25 @@ bool inet_rcv_saddr_any(const struct sock *sk)
return !sk->sk_rcv_saddr; return !sk->sk_rcv_saddr;
} }
void inet_sk_get_local_port_range(const struct sock *sk, int *low, int *high) /**
* inet_sk_get_local_port_range - fetch ephemeral ports range
* @sk: socket
* @low: pointer to low port
* @high: pointer to high port
*
* Fetch netns port range (/proc/sys/net/ipv4/ip_local_port_range)
* Range can be overridden if socket got IP_LOCAL_PORT_RANGE option.
* Returns true if IP_LOCAL_PORT_RANGE was set on this socket.
*/
bool inet_sk_get_local_port_range(const struct sock *sk, int *low, int *high)
{ {
const struct inet_sock *inet = inet_sk(sk);
const struct net *net = sock_net(sk);
int lo, hi, sk_lo, sk_hi; int lo, hi, sk_lo, sk_hi;
bool local_range = false;
u32 sk_range; u32 sk_range;
inet_get_local_port_range(net, &lo, &hi); inet_get_local_port_range(sock_net(sk), &lo, &hi);
sk_range = READ_ONCE(inet->local_port_range); sk_range = READ_ONCE(inet_sk(sk)->local_port_range);
if (unlikely(sk_range)) { if (unlikely(sk_range)) {
sk_lo = sk_range & 0xffff; sk_lo = sk_range & 0xffff;
sk_hi = sk_range >> 16; sk_hi = sk_range >> 16;
...@@ -135,10 +144,12 @@ void inet_sk_get_local_port_range(const struct sock *sk, int *low, int *high) ...@@ -135,10 +144,12 @@ void inet_sk_get_local_port_range(const struct sock *sk, int *low, int *high)
lo = sk_lo; lo = sk_lo;
if (lo <= sk_hi && sk_hi <= hi) if (lo <= sk_hi && sk_hi <= hi)
hi = sk_hi; hi = sk_hi;
local_range = true;
} }
*low = lo; *low = lo;
*high = hi; *high = hi;
return local_range;
} }
EXPORT_SYMBOL(inet_sk_get_local_port_range); EXPORT_SYMBOL(inet_sk_get_local_port_range);
......
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