From owner-svn-src-head@freebsd.org Tue Oct 23 13:38:41 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 C2001FD847E; Tue, 23 Oct 2018 13:38:40 +0000 (UTC) (envelope-from tsoome@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 652A07CB35; Tue, 23 Oct 2018 13:38:40 +0000 (UTC) (envelope-from tsoome@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 421B610969; Tue, 23 Oct 2018 13:38:40 +0000 (UTC) (envelope-from tsoome@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w9NDcegp031910; Tue, 23 Oct 2018 13:38:40 GMT (envelope-from tsoome@FreeBSD.org) Received: (from tsoome@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9NDceNX031909; Tue, 23 Oct 2018 13:38:40 GMT (envelope-from tsoome@FreeBSD.org) Message-Id: <201810231338.w9NDceNX031909@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: tsoome set sender to tsoome@FreeBSD.org using -f From: Toomas Soome Date: Tue, 23 Oct 2018 13:38:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339651 - head/stand/libsa X-SVN-Group: head X-SVN-Commit-Author: tsoome X-SVN-Commit-Paths: head/stand/libsa X-SVN-Commit-Revision: 339651 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.29 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: Tue, 23 Oct 2018 13:38:41 -0000 Author: tsoome Date: Tue Oct 23 13:38:39 2018 New Revision: 339651 URL: https://svnweb.freebsd.org/changeset/base/339651 Log: libsa: re-send ACK for older data packets in tftp In current tftp code we drop out-of-order packets; however, we should play nice and re-send ACK for older data packets we are receiving. This will hopefully stop server repeating those packets we already have received. Note we do not answer duplicates from "previous" session (that is, session with different port number), those will eventually time out. Differential Revision: https://reviews.freebsd.org/D17087 Modified: head/stand/libsa/tftp.c Modified: head/stand/libsa/tftp.c ============================================================================== --- head/stand/libsa/tftp.c Tue Oct 23 13:12:42 2018 (r339650) +++ head/stand/libsa/tftp.c Tue Oct 23 13:38:39 2018 (r339651) @@ -163,7 +163,7 @@ tftp_senderr(struct tftp_handle *h, u_short errcode, c } static void -tftp_sendack(struct tftp_handle *h) +tftp_sendack(struct tftp_handle *h, u_short block) { struct { u_char header[HEADER_SIZE]; @@ -173,7 +173,7 @@ tftp_sendack(struct tftp_handle *h) wbuf.t.th_opcode = htons((u_short) ACK); wtail = (char *) &wbuf.t.th_block; - wbuf.t.th_block = htons((u_short) h->currblock); + wbuf.t.th_block = htons(block); wtail += 2; sendudp(h->iodesc, &wbuf.t, wtail - (char *) &wbuf.t); @@ -205,9 +205,17 @@ recvtftp(struct iodesc *d, void **pkt, void **payload, case DATA: { int got; + if (htons(t->th_block) < (u_short) d->xid) { + /* + * Apparently our ACK was missed, re-send. + */ + tftp_sendack(h, htons(t->th_block)); + free(ptr); + return (-1); + } if (htons(t->th_block) != (u_short) d->xid) { /* - * Expected block? + * Packet from the future, drop this. */ free(ptr); return (-1); @@ -219,7 +227,7 @@ recvtftp(struct iodesc *d, void **pkt, void **payload, struct udphdr *uh; uh = (struct udphdr *) t - 1; d->destport = uh->uh_sport; - } /* else check uh_sport has not changed??? */ + } got = len - (t->th_data - (char *)t); *pkt = ptr; *payload = t; @@ -364,7 +372,7 @@ tftp_makereq(struct tftp_handle *h) h->islastblock = 0; if (res < h->tftp_blksize) { h->islastblock = 1; /* very short file */ - tftp_sendack(h); + tftp_sendack(h, h->currblock); } return (0); }