Setting a recv buffer of (65535*2)+1 lets FreeBSD advertise a window of 65535<<2 (window scale 2, 256KB) in stead of 65535<<1 (window scale 1, 128KB). So FreeBSD is advertising a window bigger than the actual available receive space. When setting the buffer to 65535*2 exactly, the window scale option is set correctly. Fix: Haven't had time to look into it yet, sorry. How-To-Repeat: sysctl net.inet.tcp.recvspace=131071 Then set up a connection from the FreeBSD system to something else. FreeBSD will advertise a windowsize of 256KB, although there's only 1 byte more than 128KB available.
Responsible Changed From-To: freebsd-bugs->freebsd-net over to Networking experts
The following patch seems to fix the problem: diff -u netinet.orig/tcp_syncache.c netinet/tcp_syncache.c --- netinet.orig/tcp_syncache.c Sun Jul 24 15:26:14 2005 +++ netinet/tcp_syncache.c Sun Jul 24 15:26:56 2005 @@ -966,7 +966,7 @@ /* Compute proper scaling value from buffer space */ while (wscale < TCP_MAX_WINSHIFT && - (TCP_MAXWIN << wscale) < so->so_rcv.sb_hiwat) + (TCP_MAXWIN << (wscale + 1)) <= so->so_rcv.sb_hiwat) wscale++; sc->sc_request_r_scale = wscale; sc->sc_requested_s_scale = to->to_requested_s_scale; diff -u netinet.orig/tcp_usrreq.c netinet/tcp_usrreq.c --- netinet.orig/tcp_usrreq.c Sun Jul 24 15:26:14 2005 +++ netinet/tcp_usrreq.c Sun Jul 24 15:26:47 2005 @@ -888,7 +888,7 @@ /* Compute window scaling to request. */ while (tp->request_r_scale < TCP_MAX_WINSHIFT && - (TCP_MAXWIN << tp->request_r_scale) < so->so_rcv.sb_hiwat) + (TCP_MAXWIN << (tp->request_r_scale + 1)) <= so->so_rcv.sb_hiwat) tp->request_r_scale++; soisconnecting(so); @@ -950,7 +950,7 @@ /* Compute window scaling to request. */ while (tp->request_r_scale < TCP_MAX_WINSHIFT && - (TCP_MAXWIN << tp->request_r_scale) < so->so_rcv.sb_hiwat) + (TCP_MAXWIN << (tp->request_r_scale + 1)) <= so->so_rcv.sb_hiwat) tp->request_r_scale++; soisconnecting(so);
Responsible Changed From-To: freebsd-net->silby Chown to silby, who has recently been spending some quality time with TCP.
Reassign to the wild with permission of assignee. To submitter: is this report still valid?
Inspection of code appears to show that this problem has since been fixed. If I have mis-read the code please feel free to re-open.