On Mon, Aug 17, 2015 at 08:26:21PM +0200, Alexander Bluhm wrote: > When running my pf regression tests, I triggered netcat hanging in > write(2). This is bit strange as poll(2) should check that the socket > is writeable.
Disregard the netstat diff, fix poll(2) in the kernel instead. bluhm Index: netinet/tcp_usrreq.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_usrreq.c,v retrieving revision 1.126 diff -u -p -r1.126 tcp_usrreq.c --- netinet/tcp_usrreq.c 15 Jul 2015 22:16:42 -0000 1.126 +++ netinet/tcp_usrreq.c 18 Aug 2015 19:57:48 -0000 @@ -980,6 +980,14 @@ tcp_update_sndspace(struct tcpcb *tp) nmax = MIN(sb_max, so->so_snd.sb_wat + tp->snd_max - tp->snd_una); + /* a writable socket must be preserved because of poll(2) semantics */ + if (sbspace(&so->so_snd) >= so->so_snd.sb_lowat) { + if (nmax < so->so_snd.sb_cc + so->so_snd.sb_lowat) + nmax = so->so_snd.sb_cc + so->so_snd.sb_lowat; + if (nmax * 2 < so->so_snd.sb_mbcnt + so->so_snd.sb_lowat) + nmax = (so->so_snd.sb_mbcnt+so->so_snd.sb_lowat+1) / 2; + } + /* round to MSS boundary */ nmax = roundup(nmax, tp->t_maxseg); @@ -1011,6 +1019,11 @@ tcp_update_rcvspace(struct tcpcb *tp) nmax = MIN(sb_max, so->so_rcv.sb_hiwat + tcp_autorcvbuf_inc); } + + /* a readable socket must be preserved because of poll(2) semantics */ + if (so->so_rcv.sb_cc >= so->so_rcv.sb_lowat && + nmax < so->so_snd.sb_lowat) + nmax = so->so_snd.sb_lowat; if (nmax == so->so_rcv.sb_hiwat) return;