From owner-svn-src-head@freebsd.org Wed Feb 14 15:40:14 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0582CF086D9; Wed, 14 Feb 2018 15:40:14 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AF5597E67F; Wed, 14 Feb 2018 15:40:13 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id AA4CD11B47; Wed, 14 Feb 2018 15:40:13 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1EFeDFq059618; Wed, 14 Feb 2018 15:40:13 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1EFeDD6059615; Wed, 14 Feb 2018 15:40:13 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201802141540.w1EFeDD6059615@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Wed, 14 Feb 2018 15:40:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329264 - head/stand/libsa X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/libsa X-SVN-Commit-Revision: 329264 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Feb 2018 15:40:14 -0000 Author: kevans Date: Wed Feb 14 15:40:13 2018 New Revision: 329264 URL: https://svnweb.freebsd.org/changeset/base/329264 Log: libsa: Fix IP recv timeout readip() doesn't, at the moment, properly indicate to callers that it has timed out. One can tell that it's timed out if errno == EAGAIN when it returns, but this is not ideal. Restructure it a little bit to explicitly set errno to ETIMEDOUT if we've exhausted tleft. I found two places that care about where it timed out or not: sendrecv in net.c and sendrecv_tftp. Both are structured to pass smaller timeout values to readip while tracking a larger timeout. Neither of them were able to do this properly with readip not indicating ETIMEDOUT, so fix it. While here, straighten out the time (t/t1) usage in sendrecv_tftp. This would have manifested itself in periodic failures to NFS/TFTP boot for no apparent reason because MINTMO/MAXTMO were not actually being respected properly. Problems were not reported with NFS, only TFTP. Reported by: sbruno Reviewed by: sbruno, tsoome MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D14350 Modified: head/stand/libsa/ip.c head/stand/libsa/net.c head/stand/libsa/tftp.c Modified: head/stand/libsa/ip.c ============================================================================== --- head/stand/libsa/ip.c Wed Feb 14 15:14:20 2018 (r329263) +++ head/stand/libsa/ip.c Wed Feb 14 15:40:13 2018 (r329264) @@ -416,8 +416,13 @@ readip(struct iodesc *d, void **pkt, void **payload, t while ((getsecs() - t) < tleft) { errno = 0; ret = readipv4(d, pkt, payload, tleft, proto); + if (ret >= 0) + return (ret); + /* Bubble up the error if it wasn't successful */ if (errno != EAGAIN) - break; + return (-1); } - return (ret); + /* We've exhausted tleft; timeout */ + errno = ETIMEDOUT; + return (-1); } Modified: head/stand/libsa/net.c ============================================================================== --- head/stand/libsa/net.c Wed Feb 14 15:14:20 2018 (r329263) +++ head/stand/libsa/net.c Wed Feb 14 15:40:13 2018 (r329264) @@ -118,7 +118,7 @@ sendrecv(struct iodesc *d, /* Try to get a packet and process it. */ cc = (*rproc)(d, pkt, payload, tleft); /* Return on data, EOF or real error. */ - if (cc != -1 || errno != 0) + if (cc != -1 || (errno != 0 && errno != ETIMEDOUT)) return (cc); /* Timed out or didn't get the packet we're waiting for */ Modified: head/stand/libsa/tftp.c ============================================================================== --- head/stand/libsa/tftp.c Wed Feb 14 15:14:20 2018 (r329263) +++ head/stand/libsa/tftp.c Wed Feb 14 15:40:13 2018 (r329264) @@ -638,14 +638,20 @@ sendrecv_tftp(struct tftp_handle *h, if (cc == -1) { /* Error on transmit; wait before retrying */ while ((getsecs() - t1) < tleft); + t1 = getsecs(); continue; } + t = t1 = getsecs(); recvnext: + if ((getsecs() - t) > MAXTMO) { + errno = ETIMEDOUT; + return -1; + } /* Try to get a packet and process it. */ cc = (*rproc)(h, pkt, payload, tleft, rtype); /* Return on data, EOF or real error. */ - if (cc != -1 || errno != 0) + if (cc != -1 || (errno != 0 && errno != ETIMEDOUT)) return (cc); if ((getsecs() - t1) < tleft) { goto recvnext;