Bug 144000 - [tcp] setting TCP_MAXSEG by setsockopt() does not seem to have any effect
Summary: [tcp] setting TCP_MAXSEG by setsockopt() does not seem to have any effect
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 7.2-STABLE
Hardware: Any Any
: Normal Affects Only Me
Assignee: Gleb Smirnoff
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-16 12:20 UTC by Andrey Zonov
Modified: 2021-09-26 09:16 UTC (History)
2 users (show)

See Also:


Attachments
file.txt (2.58 KB, text/plain)
2010-02-16 12:20 UTC, Andrey Zonov
no flags Details
tcp_maxseg_r80-p1.patch.txt (4.30 KB, text/plain; charset=US-ASCII)
2010-02-25 08:49 UTC, Andrey Zonov
no flags Details
patch-4.diff (1.83 KB, patch)
2010-08-15 15:13 UTC, Andre Oppermann
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Zonov 2010-02-16 12:20:02 UTC
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.

Fix: Patch attached with submission follows:
How-To-Repeat: Compile test programs and look into tcpdump.
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2010-02-16 12:43:48 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-net

Over to maintainer(s).
Comment 2 Andrey Zonov 2010-02-25 08:49:00 UTC
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
Comment 3 John Baldwin freebsd_committer freebsd_triage 2010-03-24 20:24:39 UTC
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
Comment 4 Andrey Zonov 2010-03-26 21:59:19 UTC
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
Comment 5 Andre Oppermann freebsd_committer 2010-08-10 23:11:32 UTC
Responsible Changed
From-To: freebsd-net->andre

Take over.
Comment 6 Andre Oppermann freebsd_committer 2010-08-15 15:13:46 UTC
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
Comment 7 Andre Oppermann freebsd_committer 2010-08-15 15:13:58 UTC
State Changed
From-To: open->analyzed
Comment 8 Andrey Zonov 2010-09-24 14:08:19 UTC
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
Comment 9 Andrey Zonov 2012-02-10 08:42:08 UTC
Hi Andre,

Is there any chance to get a real fix for this problem or you're not 
interested in this?

-- 
Andrey Zonov
Comment 10 Gleb Smirnoff freebsd_committer 2012-06-18 12:15:45 UTC
  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.
Comment 11 Hiren Panchasara freebsd_committer 2015-07-31 21:10:31 UTC
(In reply to Gleb Smirnoff from comment #10)
Stumbled upon this while looking for something else but I also think YBSD patch from Peter is good and if we can, we should remove t_maxopd which will make room for t_usermss.
Gleb: assigning this to you for now. If you don't want it, feel free to punt it back to freebsd-net.
Comment 12 Hiren Panchasara freebsd_committer 2016-03-18 23:41:43 UTC
Now that t_maxopd is gone with r293284, we should update Peter's patch from yahoo and fix this.
Comment 13 Gleb Smirnoff freebsd_committer 2016-03-21 21:37:36 UTC
I guess that after r293284 the bug can be closed. The problem before r293284 was that TCP_MAXSEG socketoption was working with t_maxseg, while rest of the stack used t_maxopd.

I'm pretty sure that now TCP_MAXSEG works right as it is documented in tcp(4).
Comment 14 Hiren Panchasara freebsd_committer 2016-03-22 18:36:33 UTC
I think this is still now fixed. I tried a quick C program with 
setsockopt(listenfd, IPPROTO_TCP, TCP_MAXSEG, 1100, 4);
where call succeeded but mss is still the default (1460).
Comment 15 Gleb Smirnoff freebsd_committer 2016-03-22 19:16:40 UTC
The "listenfd" says that you are expecting inheritance of TCP_MAXSEG. AFAIU, the PR is not about that. AFAIU, the PR says that an established connection would ignore TCP_MAXSEG. And I'm pretty sure it is now fixed in head.

Inheritance of the MAXSEG is a separate issue to be discussed.
Comment 16 Hiren Panchasara freebsd_committer 2016-03-22 23:28:17 UTC
Linux supports changing MSS with setsockopt before and after establishing the connections.
FreeBSD only support that after connection is established. (I made sure that part works.) The patch from Peter would let us set in listen state also. Gleb suggested that we may be able to do this without adding extra variable to tcpcb. (Noting here for posterity so whoever wants to fix can pick it up)

We may probably want to make that very clear in our tcp(4) manpage that currently you can only change MSS after connection is established.
Comment 17 Gleb Smirnoff freebsd_committer 2017-06-09 07:57:58 UTC
Hiren,

let's make update on this bug. First, I think that original bug is fixed. Second, inheritance of t_maxseg from a listening socket is a separate issue, that should be looked at from scratch. That's why I want to close this bug. Third, now we have no constraints on modifying struct tcpcb.

Do you mind if I close it?
Comment 18 Hiren Panchasara freebsd_committer 2017-06-09 20:39:08 UTC
Sure, go ahead.