From owner-freebsd-net@FreeBSD.ORG Sat Apr 4 13:50:55 2009 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 58206106566C; Sat, 4 Apr 2009 13:50:55 +0000 (UTC) (envelope-from lists.br@gmail.com) Received: from yw-out-2324.google.com (yw-out-2324.google.com [74.125.46.29]) by mx1.freebsd.org (Postfix) with ESMTP id DA5EE8FC08; Sat, 4 Apr 2009 13:50:54 +0000 (UTC) (envelope-from lists.br@gmail.com) Received: by yw-out-2324.google.com with SMTP id 5so937881ywh.13 for ; Sat, 04 Apr 2009 06:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:from:to:cc :references:subject:date:mime-version:content-type:x-priority :x-msmail-priority:x-mailer:x-mimeole; bh=FCy2s6oTYy9DURkn7q+ZS9ok1C30yvlc/2JJq4e5bWM=; b=fEzBULV1XX6jpT11bhevfEVXW1Q5+0LrT11bk1H3T+z1OKgxf8DgvteaMsvYVxQTY7 Vso7+pdEIOOyJz07LMj8LAc6ukLuvPH6ump1jFLK/fQiWDIn4OWzJSuSXMui9eXoMGhp t/Bab1fCT9ROr+6jc2eCgzLESYYjeGiqezing= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:from:to:cc:references:subject:date:mime-version :content-type:x-priority:x-msmail-priority:x-mailer:x-mimeole; b=RwTH1JH94qblV1hNaa8JEK2ZzFNc/HOXwC6WPJvI8ONzFp709KqlzNNXWRUQUVbg67 4qlJN/xAL2Ry+ryvO7dUySbh/J3/WUWeHiLyG3V6KB2e4BpLxeawv488Ihb9NRlik6Eq k5+1ZXmvFYIY5ut+R7qxgM5VyNbLqddPA/yzI= Received: by 10.90.118.19 with SMTP id q19mr1452569agc.93.1238851327358; Sat, 04 Apr 2009 06:22:07 -0700 (PDT) Received: from adnote989 (201-42-151-145.dsl.telesp.net.br [201.42.151.145]) by mx.google.com with ESMTPS id 30sm4117257agc.49.2009.04.04.06.22.05 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 04 Apr 2009 06:22:06 -0700 (PDT) Message-ID: <3F89BC6021844DC58B956E5433650445@adnote989> From: "Luiz Otavio O Souza" To: "Julian Elischer" References: <3FD46C21A487490FB15B89E890790121@adnote989> <49d5c0de.E5bkeKr+p+fg4K00%perryh@pluto.rain.com> <64D5D9E633734200A603D067ED5A81E9@adnote989> <49D63315.6050108@elischer.org> Date: Sat, 4 Apr 2009 10:21:38 -0300 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_01BF_01C9B50F.239BA6B0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Mailman-Approved-At: Sat, 04 Apr 2009 15:55:17 +0000 Cc: Lawrence Stewart , freebsd-net@freebsd.org Subject: Re: Setting the mss for socket X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Apr 2009 13:50:55 -0000 This is a multi-part message in MIME format. ------=_NextPart_000_01BF_01C9B50F.239BA6B0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit > Luiz Otavio O Souza wrote: >>>> Is there a way to set the mss for a socket ? Like you can do >>>> in linux with setsockopt(TCP_MAXSEG) ? >>>> >>>> So i can set the maximum size of packets (or sort of) from a >>>> simple userland program. >>> >>> Depending on exactly what you need to accomplish, you may >>> find something useful in this thread from last August in >>> freebsd-questions@ >>> >>> setting the other end's TCP segment size >> >> Very informative thread, thanks. >> >> This thread show me that TCP_MAXSEG is implemented in freebsd but don't >> work. You can set the setsockopt(IPPROTO_TCP, TCP_MAXSEG), wich will set >> the >> tp->t_maxseg, but this value is recalculated at tcp_input, so in short, >> you >> cannot set the max segment size for a socket. >> >> I've posted a completly wrong patch (from style point-of-view - and using >> SOL_SOCKET instead of IPPROTO_TCP), but with that patch i'm able to set >> the >> mss in iperf. > > this thread shoud be in FreeBSD-net@ so tha the right people see it > many developers do not read hackers every day as it tends to overload > them. The above patch is a better fix for this, it fix the setsockopt(IPPROTO_TCP, TCP_MAXSEG), so iperf (and other userland programs) works by default. It's clear on code that tp->t_maxseg should not be changed, at least in this situation (it keeps the maximum mss for connection and it is used to calculate the tcp window scaling). tp->t_maxseg is also reseted to maxmtu (or rmx_mtu) at tcp_mss_update(). So here is the patch: http://loos.no-ip.org/downloads/mss-patch Thanks Luiz ------=_NextPart_000_01BF_01C9B50F.239BA6B0 Content-Type: text/plain; format=flowed; name="mss-patch.txt"; reply-type=response Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="mss-patch.txt" --- netinet/socketvar.h.orig 2009-04-03 22:29:34.000000000 -0300=0A= +++ netinet/socketvar.h 2009-04-03 22:29:44.000000000 -0300=0A= @@ -115,6 +115,7 @@=0A= char *so_accept_filter_str; /* saved user args */=0A= } *so_accf;=0A= int so_fibnum; /* routing domain for this socket */=0A= + int so_maxseg; /* maxseg this socket */=0A= };=0A= =0A= /*=0A= --- netinet/tcp_usrreq.c.orig 2009-04-03 22:24:53.000000000 -0300=0A= +++ netinet/tcp_usrreq.c 2009-04-03 23:26:35.000000000 -0300=0A= @@ -1352,9 +1352,8 @@=0A= return (error);=0A= =0A= INP_WLOCK_RECHECK(inp);=0A= - if (optval > 0 && optval <=3D tp->t_maxseg &&=0A= - optval + 40 >=3D V_tcp_minmss)=0A= - tp->t_maxseg =3D optval;=0A= + if (optval >=3D 40 && optval <=3D tp->t_maxseg)=0A= + so->so_maxseg =3D optval;=0A= else=0A= error =3D EINVAL;=0A= INP_WUNLOCK(inp);=0A= @@ -1389,7 +1388,10 @@=0A= error =3D sooptcopyout(sopt, &optval, sizeof optval);=0A= break;=0A= case TCP_MAXSEG:=0A= - optval =3D tp->t_maxseg;=0A= + if (so->so_maxseg)=0A= + optval =3D so->so_maxseg;=0A= + else=0A= + optval =3D tp->t_maxseg;=0A= INP_WUNLOCK(inp);=0A= error =3D sooptcopyout(sopt, &optval, sizeof optval);=0A= break;=0A= --- netinet/tcp_output.c.orig 2009-04-02 22:48:04.000000000 -0300=0A= +++ netinet/tcp_output.c 2009-04-03 23:28:07.000000000 -0300=0A= @@ -493,6 +493,11 @@=0A= }=0A= }=0A= =0A= + if (so->so_maxseg && len > so->so_maxseg) {=0A= + len =3D so->so_maxseg;=0A= + sendalot =3D 1;=0A= + }=0A= +=0A= if (sack_rxmit) {=0A= if (SEQ_LT(p->rxmit + len, tp->snd_una + so->so_snd.sb_cc))=0A= flags &=3D ~TH_FIN;=0A= @@ -518,6 +523,8 @@=0A= if (len) {=0A= if (len >=3D tp->t_maxseg)=0A= goto send;=0A= + if (so->so_maxseg && len >=3D so->so_maxseg)=0A= + goto send;=0A= /*=0A= * NOTE! on localhost connections an 'ack' from the remote=0A= * end may occur synchronously with the output and cause=0A= ------=_NextPart_000_01BF_01C9B50F.239BA6B0--