[net,1/1] net: tcp: Permit user set TCP_MAXSEG to default value

Submitted by Eric Dumazet on March 20, 2017, 10:45 p.m.

Details

Message ID 1490049947.16816.89.camel@edumazet-glaptop3.roam.corp.google.com
State RFC
Delegated to: David Miller
Headers show

Commit Message

Eric Dumazet March 20, 2017, 10:45 p.m.
On Tue, 2017-03-21 at 05:30 +0800, fgao@ikuai8.com wrote:
> From: Gao Feng <fgao@ikuai8.com>
> 
> When user_mss is zero, it means use the default value. But the current
> codes don't permit user set TCP_MAXSEG to the default value.
> It would return the -EINVAL when val is zero.
> 
> Signed-off-by: Gao Feng <fgao@ikuai8.com>
> ---
>  net/ipv4/tcp.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 1e319a5..dd5e8e2 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -2470,7 +2470,8 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
>  		/* Values greater than interface MTU won't take effect. However
>  		 * at the point when this call is done we typically don't yet
>  		 * know which interface is going to be used */
> -		if (val < TCP_MIN_MSS || val > MAX_TCP_WINDOW) {
> +		if (val < 0 || (val > 0 && val < TCP_MIN_MSS) ||
> +		    val > MAX_TCP_WINDOW) {
>  			err = -EINVAL;
>  			break;
>  		}

This is a convoluted way to express that val == 0 is accepted ...

What about :

Patch hide | download patch | download mbox

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 1e319a525d51b0b603a5ccc5143381c752b9f2c7..7db78d72896ac7c4befba5966704ed18ecbac409 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2469,8 +2469,9 @@  static int do_tcp_setsockopt(struct sock *sk, int level,
 	case TCP_MAXSEG:
 		/* Values greater than interface MTU won't take effect. However
 		 * at the point when this call is done we typically don't yet
-		 * know which interface is going to be used */
-		if (val < TCP_MIN_MSS || val > MAX_TCP_WINDOW) {
+		 * know which interface is going to be used.
+		 */
+		if (val && (val < TCP_MIN_MSS || val > MAX_TCP_WINDOW)) {
 			err = -EINVAL;
 			break;
 		}