From nobody@FreeBSD.org  Tue Feb 16 12:17:29 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 9732B1065670
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 16 Feb 2010 12:17:29 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 7BDD28FC16
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 16 Feb 2010 12:17:29 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o1GCHT3m094784
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 16 Feb 2010 12:17:29 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o1GCHTmx094783;
	Tue, 16 Feb 2010 12:17:29 GMT
	(envelope-from nobody)
Message-Id: <201002161217.o1GCHTmx094783@www.freebsd.org>
Date: Tue, 16 Feb 2010 12:17:29 GMT
From: Andrey Zonov <andrey.zonov@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [tcp] ignore set TCP_MAXSEG by setsockopt()
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         144000
>Category:       kern
>Synopsis:       [tcp] setting TCP_MAXSEG by setsockopt() does not seem to have any effect
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    andre
>State:          analyzed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Feb 16 12:20:02 UTC 2010
>Closed-Date:    
>Last-Modified:  Mon Jun 18 11:20:11 UTC 2012
>Originator:     Andrey Zonov
>Release:        7.2-STABLE, 8.0-STABLE
>Organization:
>Environment:
>Description:
After reading Stevens and man 4 tcp, i trying to set mss for connections
by setsockopt(TCP_MAXSEG), but it's not worked for me.

In Linux it's work fine.
>How-To-Repeat:
Compile test programs and look into tcpdump.


>Fix:


Patch attached with submission follows:

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <err.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>

static char buf[] = "test echo";

int
main(void)
{
	int s, maxseg;
	struct sockaddr_in serv;

	bzero(&serv, sizeof(serv));
	serv.sin_family = AF_INET;
	serv.sin_port = htons(5555);
	inet_pton(AF_INET, "localhost", &serv.sin_addr);

	s = socket(AF_INET, SOCK_STREAM, 0);

	maxseg = 300;
	if (setsockopt(s, IPPROTO_TCP, TCP_MAXSEG, (const void *) &maxseg, sizeof(maxseg)) != 0) {
		err(1, "setsockopt():");
	}

	if ((connect(s, (const struct sockaddr *) &serv, sizeof(serv))) == 0) {
		write(s, buf, 9);
	}
	close(s);

	exit(0);
}

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>

#define SIZE 4096

int
main(void)
{
	int s, s1, r;
	char buf[SIZE];
	struct sockaddr_in sin;

	s = socket(AF_INET, SOCK_STREAM, 0);

	bzero(&sin, sizeof(sin));
	sin.sin_family = AF_INET;
	sin.sin_port = htons(5555);

	bind(s, (const struct sockaddr *)&sin, sizeof(sin));

	listen(s, -1);

	s1 = accept(s, (struct sockaddr *) NULL, NULL);

	while ((r = read(s1, buf, SIZE)) > 0) {
		write(s1, buf, r);
	}
	close(s1);

	exit(0);
}

# tcpdump -pni lo0 port 5555
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo0, link-type NULL (BSD loopback), capture size 96 bytes
15:05:57.371757 IP 127.0.0.1.39043 > 127.0.0.1.5555: Flags [S], seq 2639122865, win 65535, options [mss 16344,nop,wscale 3,sackOK,TS val 27362 ecr 0], length 0
15:05:57.371900 IP 127.0.0.1.5555 > 127.0.0.1.39043: Flags [S.], seq 1718559353, ack 2639122866, win 65535, options [mss 16344,nop,wscale 3,sackOK,TS val 604177474 ecr 27362], length 0
15:05:57.371902 IP 127.0.0.1.39043 > 127.0.0.1.5555: Flags [.], ack 1, win 8960, options [nop,nop,TS val 27362 ecr 604177474], length 0
15:05:57.372005 IP 127.0.0.1.39043 > 127.0.0.1.5555: Flags [P.], ack 1, win 8960, options [nop,nop,TS val 27362 ecr 604177474], length 9
15:05:57.372081 IP 127.0.0.1.39043 > 127.0.0.1.5555: Flags [F.], seq 10, ack 1, win 8960, options [nop,nop,TS val 27362 ecr 604177474], length 0
15:05:57.372104 IP 127.0.0.1.5555 > 127.0.0.1.39043: Flags [.], ack 11, win 8958, options [nop,nop,TS val 604177474 ecr 27362], length 0
15:05:57.372263 IP 127.0.0.1.5555 > 127.0.0.1.39043: Flags [P.], ack 11, win 8960, options [nop,nop,TS val 604177474 ecr 27362], length 9
15:05:57.372265 IP 127.0.0.1.39043 > 127.0.0.1.5555: Flags [R], seq 2639122876, win 0, length 0


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Feb 16 12:43:48 UTC 2010 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=144000 

From: Andrey Zonov <andrey.zonov@gmail.com>
To: bug-followup@FreeBSD.org, jhb@freebsd.org
Cc:  
Subject: Re: kern/144000: [tcp] ignore set TCP_MAXSEG by setsockopt()
Date: Thu, 25 Feb 2010 11:49:00 +0300

 --00151758b020ad57aa048068da47
 Content-Type: text/plain; charset=ISO-8859-1
 
 I have found patch at [1] and adapted for 8.0-p1
 
 jhb, why you not added this patch in HEAD?
 
 
 [1] http://people.freebsd.org/~jhb/patches/tcp_maxseg.patch
 
 
 -- 
 Andrey Zonov
 
 --00151758b020ad57aa048068da47
 Content-Type: text/plain; charset=US-ASCII; name="tcp_maxseg_r80-p1.patch.txt"
 Content-Disposition: attachment; filename="tcp_maxseg_r80-p1.patch.txt"
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_g63b7nu60
 
 LS0tIHN5cy9uZXRpbmV0L3RjcF9pbnB1dC5jLm9yaWcJMjAwOS0xMi0xNiAxNToxMjo0My4wMDAw
 MDAwMDAgKzAzMDAKKysrIHN5cy9uZXRpbmV0L3RjcF9pbnB1dC5jCTIwMTAtMDItMjQgMTc6MDk6
 MjkuMDAwMDAwMDAwICswMzAwCkBAIC0zMTIyLDYgKzMxMjIsMTIgQEAKIAkJcmV0dXJuOwogCX0K
 IAorCWlmICh0cC0+dF91c2VybXNzKSB7CisJCWlmIChtYXhtdHUgPiAodHAtPnRfdXNlcm1zcyAr
 IG1pbl9wcm90b2gpKQorCQkJbWF4bXR1ID0gdHAtPnRfdXNlcm1zcyArIG1pbl9wcm90b2g7CisJ
 CWlmIChvZmZlciA+IHRwLT50X3VzZXJtc3MpCisJCQlvZmZlciA9IHRwLT50X3VzZXJtc3M7CisJ
 fQogCS8qIFdoYXQgaGF2ZSB3ZSBnb3Q/ICovCiAJc3dpdGNoIChvZmZlcikgewogCQljYXNlIDA6
 Ci0tLSBzeXMvbmV0aW5ldC90Y3Bfb3V0cHV0LmMub3JpZwkyMDA5LTEyLTE2IDE1OjEyOjQ0LjAw
 MDAwMDAwMCArMDMwMAorKysgc3lzL25ldGluZXQvdGNwX291dHB1dC5jCTIwMTAtMDItMjQgMTc6
 MDk6MjkuMDAwMDAwMDAwICswMzAwCkBAIC02NTksNiArNjU5LDggQEAKIAkJaWYgKGZsYWdzICYg
 VEhfU1lOKSB7CiAJCQl0cC0+c25kX254dCA9IHRwLT5pc3M7CiAJCQl0by50b19tc3MgPSB0Y3Bf
 bXNzb3B0KCZ0cC0+dF9pbnBjYi0+aW5wX2luYyk7CisJCQlpZiAodHAtPnRfdXNlcm1zcyAmJiB0
 by50b19tc3MgPiB0cC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0+c29fc3RhdGUgJiBTU19JU0NPTk5F
 Q1RFRCkgPT0gMCkKKwkJCQlvcHR2YWwgPSB0cC0+dF91c2VybXNzOworCQkJZWxzZQorCQkJCW9w
 dHZhbCA9IHRwLT50X21heHNlZzsKIAkJCUlOUF9XVU5MT0NLKGlucCk7CiAJCQllcnJvciA9IHNv
 b3B0Y29weW91dChzb3B0LCAmb3B0dmFsLCBzaXplb2Ygb3B0dmFsKTsKIAkJCWJyZWFrOwotLS0g
 c3lzL25ldGluZXQvdGNwX3Zhci5oLm9yaWcJMjAwOS0xMi0xNiAxNToxMjo0NC4wMDAwMDAwMDAg
 KzAzMDAKKysrIHN5cy9uZXRpbmV0L3RjcF92YXIuaAkyMDEwLTAyLTI0IDE3OjM5OjAwLjAwMDAw
 MDAwMCArMDMwMApAQCAtMjAzLDYgKzIwMyw3IEBACiAJaW50CXRfaXNwYXJlOwkJLyogZXhwbGlj
 aXQgcGFkIGZvciA2NGJpdCBhbGlnbm1lbnQgKi8KIAl2b2lkCSp0X3BzcGFyZTJbNl07CQkvKiAy
 IENDIC8gNCBUQkQgKi8KIAl1aW50NjRfdCBfcGFkWzEyXTsJCS8qIDcgVVRPLCA1IFRCRCAoMS0y
 IENDL1JUVD8pICovCisJdV9pbnQJdF91c2VybXNzOwkJLyogVXNlciByZXF1ZXN0ZWQgdF9tYXhz
 ZWcgKi8KIH07CiAKIC8qCg==
 --00151758b020ad57aa048068da47--

From: John Baldwin <jhb@freebsd.org>
To: Andrey Zonov <andrey.zonov@gmail.com>
Cc: bug-followup@freebsd.org
Subject: Re: kern/144000: [tcp] ignore set TCP_MAXSEG by setsockopt()
Date: Wed, 24 Mar 2010 16:24:39 -0400

 On Thursday 25 February 2010 3:49:00 am Andrey Zonov wrote:
 > I have found patch at [1] and adapted for 8.0-p1
 > 
 > jhb, why you not added this patch in HEAD?
 > 
 > 
 > [1] http://people.freebsd.org/~jhb/patches/tcp_maxseg.patch
 
 Actually, can you try this simpler patch instead:
 
 Index: tcp_input.c
 ===================================================================
 --- tcp_input.c (revision 205624)
 +++ tcp_input.c (working copy)
 @@ -3100,12 +3100,10 @@
  #ifdef INET6
         if (isipv6) {
                 maxmtu = tcp_maxmtu6(&inp->inp_inc, mtuflags);
 -               tp->t_maxopd = tp->t_maxseg = V_tcp_v6mssdflt;
         } else
  #endif
         {
                 maxmtu = tcp_maxmtu(&inp->inp_inc, mtuflags);
 -               tp->t_maxopd = tp->t_maxseg = V_tcp_mssdflt;
         }
 
         /*
 
 -- 
 John Baldwin

From: Andrey Zonov <andrey.zonov@gmail.com>
To: John Baldwin <jhb@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: kern/144000: [tcp] ignore set TCP_MAXSEG by setsockopt()
Date: Sat, 27 Mar 2010 00:59:19 +0300

 For 7/8-stable not helped me.
 
 John Baldwin ?????:
 > On Thursday 25 February 2010 3:49:00 am Andrey Zonov wrote:
 >   
 >> I have found patch at [1] and adapted for 8.0-p1
 >>
 >> jhb, why you not added this patch in HEAD?
 >>
 >>
 >> [1] http://people.freebsd.org/~jhb/patches/tcp_maxseg.patch
 >>     
 >
 > Actually, can you try this simpler patch instead:
 >
 > Index: tcp_input.c
 > ===================================================================
 > --- tcp_input.c (revision 205624)
 > +++ tcp_input.c (working copy)
 > @@ -3100,12 +3100,10 @@
 >  #ifdef INET6
 >         if (isipv6) {
 >                 maxmtu = tcp_maxmtu6(&inp->inp_inc, mtuflags);
 > -               tp->t_maxopd = tp->t_maxseg = V_tcp_v6mssdflt;
 >         } else
 >  #endif
 >         {
 >                 maxmtu = tcp_maxmtu(&inp->inp_inc, mtuflags);
 > -               tp->t_maxopd = tp->t_maxseg = V_tcp_mssdflt;
 >         }
 >
 >         /*
 >
 >   
 
 -- 
 Andrey Zonov
 
Responsible-Changed-From-To: freebsd-net->andre 
Responsible-Changed-By: andre 
Responsible-Changed-When: Tue Aug 10 22:11:32 UTC 2010 
Responsible-Changed-Why:  
Take over. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=144000 
State-Changed-From-To: open->analyzed 
State-Changed-By: andre 
State-Changed-When: Sun Aug 15 14:13:58 UTC 2010 
State-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=144000 

From: Andre Oppermann <andre@freebsd.org>
To: andrey.zonov@gmail.com
Cc: jhb@freebsd.org, bug-followup@freebsd.org
Subject: Re: kern/144000: [tcp] setting TCP_MAXSEG by setsockopt() does not
 seem to have any effect
Date: Sun, 15 Aug 2010 16:13:46 +0200

 This is a multi-part message in MIME format.
 --------------030907040506060202080909
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit
 
 Andrey
 
 please test the attached patch.  It allows the MSS to be set
 either before or after a connection has been established. It
 does not allow the mss to be set on listen sockets and their
 values are not inherited on inbound connections.  This is my
 understanding form the Linux man page.
 
 -- 
 Andre
 
 --------------030907040506060202080909
 Content-Type: text/plain;
  name="patch-4.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="patch-4.diff"
 
 Index: netinet/tcp_usrreq.c
 ===================================================================
 --- netinet/tcp_usrreq.c	(revision 211333)
 +++ netinet/tcp_usrreq.c	(working copy)
 @@ -1340,10 +1340,21 @@
  				return (error);
  
  			INP_WLOCK_RECHECK(inp);
 -			if (optval > 0 && optval <= tp->t_maxseg &&
 -			    optval + 40 >= V_tcp_minmss)
 -				tp->t_maxseg = optval;
 -			else
 +			if (optval > 0 && optval <= tp->t_maxopd &&
 +			    optval + sizeof(struct tcpiphdr) >= V_tcp_minmss) {
 +				switch (tp->t_state) {
 +				case TCPS_CLOSED:
 +					tp->t_maxopd = optval;
 +					break;
 +				case TCPS_ESTABLISHED:
 +					tcp_mss_update(tp, optval, NULL, NULL);
 +					break;
 +				default:
 +					error = EINVAL;
 +				}
 +				if (!error)
 +					tp->t_flags |= TF_USRMAXSEG;
 +			} else
  				error = EINVAL;
  			INP_WUNLOCK(inp);
  			break;
 Index: netinet/tcp_output.c
 ===================================================================
 --- netinet/tcp_output.c	(revision 211333)
 +++ netinet/tcp_output.c	(working copy)
 @@ -663,6 +690,8 @@
  		if (flags & TH_SYN) {
  			tp->snd_nxt = tp->iss;
  			to.to_mss = tcp_mssopt(&tp->t_inpcb->inp_inc);
 +			if (tp->t_flags & TF_USRMAXSEG)
 +				to.to_mss = min(to.to_mss, tp->t_maxopd);
  			to.to_flags |= TOF_MSS;
  		}
  		/* Window scaling. */
 Index: netinet/tcp_var.h
 ===================================================================
 --- netinet/tcp_var.h	(revision 211333)
 +++ netinet/tcp_var.h	(working copy)
 @@ -221,6 +221,7 @@
  #define	TF_NEEDSYN	0x000400	/* send SYN (implicit state) */
  #define	TF_NEEDFIN	0x000800	/* send FIN (implicit state) */
  #define	TF_NOPUSH	0x001000	/* don't push */
 +#define	TF_USRMAXSEG	0x002000	/* user set mss */
  #define	TF_MORETOCOME	0x010000	/* More data to be appended to sock */
  #define	TF_LQ_OVERFLOW	0x020000	/* listen queue overflow */
  #define	TF_LASTIDLE	0x040000	/* connection was previously idle */
 
 --------------030907040506060202080909--

From: Andrey Zonov <andrey.zonov@gmail.com>
To: Andre Oppermann <andre@freebsd.org>
Cc: jhb@freebsd.org, bug-followup@freebsd.org
Subject: Re: kern/144000: [tcp] setting TCP_MAXSEG by setsockopt() does not
 seem to have any effect
Date: Fri, 24 Sep 2010 17:08:19 +0400

 Hi,
 
 This patch works as you say, only for outbound connections and it's bad...
 I don't know which man you read, but in ubuntu-10.04 I can set MSS for
 both of types connections inbound and outbound. This patch also may
 not set MSS more than net.inet.tcp.mssdflt and less than
 net.inet.tcp.minmss.
 
 2010/8/15 Andre Oppermann <andre@freebsd.org>:
 > Andrey
 >
 > please test the attached patch. =A0It allows the MSS to be set
 > either before or after a connection has been established. It
 > does not allow the mss to be set on listen sockets and their
 > values are not inherited on inbound connections. =A0This is my
 > understanding form the Linux man page.
 >
 > --
 > Andre
 >
 
 
 
 --=20
 Andrey Zonov

From: Andrey Zonov <andrey@zonov.org>
To: bug-followup@FreeBSD.org, andrey.zonov@gmail.com
Cc:  
Subject: Re: kern/144000: [tcp] setting TCP_MAXSEG by setsockopt() does not
 seem to have any effect
Date: Fri, 10 Feb 2012 12:42:08 +0400

 Hi Andre,
 
 Is there any chance to get a real fix for this problem or you're not 
 interested in this?
 
 -- 
 Andrey Zonov
 

From: Gleb Smirnoff <glebius@FreeBSD.org>
To: Andrey Zonov <andrey.zonov@gmail.com>, andre@FreeBSD.org
Cc: bug-followup@FreeBSD.org
Subject: kern/144000: [tcp] setting TCP_MAXSEG by setsockopt() does not seem
 to have any effect
Date: Mon, 18 Jun 2012 15:15:45 +0400

   Hello,
 
   some thoughts on this PR follows.
 
   First, we've got two fields in the tcpcb representing almost same:
 the t_maxseg and t_maxopd. It seems to me that a constant equation is
 (almost) always true:
 
 	tp->t_maxseg = t_maxopd - delta
 
 , where delta is constant for given tp.
   Looking into the past, I've found that t_maxopd was introduced
 with T/TCP. Before that the TCP stack worked fine without t_maxopd,
 although there already were TCP options in the stack, thus t_maxseg
 wasn't equal to (mtu - min_proto_header).
   Later, when T/TCP was removed from the stack, t_maxopd left here,
 since was used widely.
 
   Second, looking at patches from Andre for kern/144000 and the one by
 Peter to YBSD, I like the latter. But it requires growing of struct tcpcb.
 However, if we transform all the code that uses t_maxopd to use t_maxseg,
 then we've got a spare field for t_usermss.
 
   Your opinion?
 
 -- 
 Totus tuus, Glebius.
>Unformatted:
