All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <edumazet@google.com>
Cc: <davem@davemloft.net>, <eric.dumazet@gmail.com>,
	<jakub@cloudflare.com>, <kuba@kernel.org>,
	<netdev@vger.kernel.org>, <pabeni@redhat.com>,
	<kuniyu@amazon.com>
Subject: Re: [PATCH net-next 1/2] inet: returns a bool from inet_sk_get_local_port_range()
Date: Fri, 15 Dec 2023 10:50:58 +0900	[thread overview]
Message-ID: <20231215015058.38150-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20231214192939.1962891-2-edumazet@google.com>

From: Eric Dumazet <edumazet@google.com>
Date: Thu, 14 Dec 2023 19:29:38 +0000
> 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: Eric Dumazet <edumazet@google.com>

Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>


> ---
>  include/net/ip.h                |  2 +-
>  net/ipv4/inet_connection_sock.c | 21 ++++++++++++++++-----
>  2 files changed, 17 insertions(+), 6 deletions(-)
> 
> diff --git a/include/net/ip.h b/include/net/ip.h
> index b31be912489af8b01cc0393a27ffc80b086feaa0..de0c69c57e3cb7485e3d8473bc0b109e4280d2f6 100644
> --- a/include/net/ip.h
> +++ b/include/net/ip.h
> @@ -356,7 +356,7 @@ static inline void inet_get_local_port_range(const struct net *net, int *low, in
>  	*low = range & 0xffff;
>  	*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
>  static inline bool inet_is_local_reserved_port(struct net *net, unsigned short port)
> diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
> index 70be0f6fe879ea671bf6686b04edf32bf5e0d4b6..bd325b029dd12c9fad754ded266ae232ee7ec260 100644
> --- a/net/ipv4/inet_connection_sock.c
> +++ b/net/ipv4/inet_connection_sock.c
> @@ -117,16 +117,25 @@ bool inet_rcv_saddr_any(const struct sock *sk)
>  	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;
> +	bool local_range = false;
>  	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)) {
>  		sk_lo = sk_range & 0xffff;
>  		sk_hi = sk_range >> 16;
> @@ -135,10 +144,12 @@ void inet_sk_get_local_port_range(const struct sock *sk, int *low, int *high)
>  			lo = sk_lo;
>  		if (lo <= sk_hi && sk_hi <= hi)
>  			hi = sk_hi;
> +		local_range = true;
>  	}
>  
>  	*low = lo;
>  	*high = hi;
> +	return local_range;
>  }
>  EXPORT_SYMBOL(inet_sk_get_local_port_range);
>  
> -- 
> 2.43.0.472.g3155946c3a-goog

  reply	other threads:[~2023-12-15  1:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-14 19:29 [PATCH net-next 0/2] tcp/dccp: refine source port selection Eric Dumazet
2023-12-14 19:29 ` [PATCH net-next 1/2] inet: returns a bool from inet_sk_get_local_port_range() Eric Dumazet
2023-12-15  1:50   ` Kuniyuki Iwashima [this message]
2023-12-14 19:29 ` [PATCH net-next 2/2] tcp/dccp: change source port selection at connect() time Eric Dumazet
2023-12-15  1:58   ` Kuniyuki Iwashima
2023-12-15  2:26   ` Jason Xing
2023-12-16  2:10 ` [PATCH net-next 0/2] tcp/dccp: refine source port selection patchwork-bot+netdevbpf
2024-01-03 14:17 ` Jakub Sitnicki
2024-01-03 16:48   ` Eric Dumazet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231215015058.38150-1-kuniyu@amazon.com \
    --to=kuniyu@amazon.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=jakub@cloudflare.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.