From owner-svn-src-head@freebsd.org Thu Aug 24 20:52:04 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 01E15DE7F89; Thu, 24 Aug 2017 20:52:04 +0000 (UTC) (envelope-from glebius@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 mx1.freebsd.org (Postfix) with ESMTPS id CF93D65C91; Thu, 24 Aug 2017 20:52:03 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v7OKq3Kl080944; Thu, 24 Aug 2017 20:52:03 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v7OKq3kk080943; Thu, 24 Aug 2017 20:52:03 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201708242052.v7OKq3kk080943@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Thu, 24 Aug 2017 20:52:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r322858 - head/tools/regression/sockets/accf_data_attach X-SVN-Group: head X-SVN-Commit-Author: glebius X-SVN-Commit-Paths: head/tools/regression/sockets/accf_data_attach X-SVN-Commit-Revision: 322858 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.23 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: Thu, 24 Aug 2017 20:52:04 -0000 Author: glebius Date: Thu Aug 24 20:52:02 2017 New Revision: 322858 URL: https://svnweb.freebsd.org/changeset/base/322858 Log: Add a test case for a connection on accept queue that is reset before it is accepted. In that case accept(2) shall return ECONNABORTED. Accept filters provide help with easily replicating that case. Modified: head/tools/regression/sockets/accf_data_attach/accf_data_attach.c Modified: head/tools/regression/sockets/accf_data_attach/accf_data_attach.c ============================================================================== --- head/tools/regression/sockets/accf_data_attach/accf_data_attach.c Thu Aug 24 20:51:16 2017 (r322857) +++ head/tools/regression/sockets/accf_data_attach/accf_data_attach.c Thu Aug 24 20:52:02 2017 (r322858) @@ -64,6 +64,7 @@ main(void) { struct accept_filter_arg afa; struct sockaddr_in sin; + struct linger linger; socklen_t len; int lso, so, i, ret; @@ -231,8 +232,32 @@ main(void) usleep(10000); if (accept(lso, NULL, 0) < 1) errx(-1, "not ok 11 - accept #2 %s", strerror(errno)); + if (close(so) != 0) + errx(-1, "not ok 11 - close(): %s", strerror(errno)); printf("ok 11 - accept\n"); + /* + * Step 12: reset connection before accept filter allows it. + * In this case the connection must make it to the listen + * queue, but with ECONNABORTED code. + */ + so = socket(PF_INET, SOCK_STREAM, 0); + if (so == -1) + errx(-1, "not ok 12 - socket: %s", strerror(errno)); + if (connect(so, (struct sockaddr *)&sin, sizeof(sin)) < 0) + errx(-1, "not ok 12 - connect %s", strerror(errno)); + linger.l_onoff = 1; + linger.l_linger = 0; + ret = setsockopt(so, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger)); + if (ret != 0) + errx(-1, "not ok 12 - setsockopt(SO_LINGER) failed with %d " + "(%s)", errno, strerror(errno)); + if (close(so) != 0) + errx(-1, "not ok 12 - close(): %s", strerror(errno)); + if (accept(lso, NULL, 0) != -1 && errno != ECONNABORTED) + errx(-1, "not ok 12 - accept #3 %s", strerror(errno)); + printf("ok 12 - accept\n"); + #if 1 /* * XXXGL: this doesn't belong to the test itself, but is known @@ -242,31 +267,33 @@ main(void) */ so = socket(PF_INET, SOCK_STREAM, 0); if (so == -1) - errx(-1, "not ok 12 - socket: %s", strerror(errno)); + errx(-1, "not ok 13 - socket: %s", strerror(errno)); if (connect(so, (struct sockaddr *)&sin, sizeof(sin)) < 0) - errx(-1, "not ok 12 - connect %s", strerror(errno)); + errx(-1, "not ok 13 - connect %s", strerror(errno)); #endif /* - * Step 11: Remove accept filter. After removing the accept filter + * Step 12: Remove accept filter. After removing the accept filter * getsockopt() should fail with EINVAL. */ ret = setsockopt(lso, SOL_SOCKET, SO_ACCEPTFILTER, NULL, 0); if (ret != 0) - errx(-1, "not ok 12 - setsockopt() after listen() " + errx(-1, "not ok 13 - setsockopt() after listen() " "failed with %d (%s)", errno, strerror(errno)); bzero(&afa, sizeof(afa)); len = sizeof(afa); ret = getsockopt(lso, SOL_SOCKET, SO_ACCEPTFILTER, &afa, &len); if (ret == 0) - errx(-1, "not ok 12 - getsockopt() after removing " + errx(-1, "not ok 13 - getsockopt() after removing " "the accept filter returns valid accept filter %s", afa.af_name); if (errno != EINVAL) - errx(-1, "not ok 12 - getsockopt() after removing the accept" + errx(-1, "not ok 13 - getsockopt() after removing the accept" "filter failed with %d (%s)", errno, strerror(errno)); - printf("ok 12 - setsockopt\n"); + if (close(lso) != 0) + errx(-1, "not ok 13 - close() of listening socket: %s", + strerror(errno)); + printf("ok 13 - setsockopt\n"); - close(lso); return (0); }