From owner-svn-src-all@freebsd.org Thu Jun 8 05:12:12 2017 Return-Path: Delivered-To: svn-src-all@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 9947EBF5ED7; Thu, 8 Jun 2017 05:12:12 +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 75B20745D3; Thu, 8 Jun 2017 05:12:12 +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 v585CBaN093162; Thu, 8 Jun 2017 05:12:11 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v585CBRb093161; Thu, 8 Jun 2017 05:12:11 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201706080512.v585CBRb093161@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Thu, 8 Jun 2017 05:12:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r319683 - head/tools/regression/sockets/accf_data_attach X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Jun 2017 05:12:12 -0000 Author: glebius Date: Thu Jun 8 05:12:11 2017 New Revision: 319683 URL: https://svnweb.freebsd.org/changeset/base/319683 Log: Improve this unit test: make sure that the accept filter actually works. Before this test just checked scenario of setting and removing the accept filter at different states of the socket. Now it also checks that accept filter works: we connect to the server, and then check that we can't accept, then we send 1 byte of data and check again. 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 Jun 8 04:54:15 2017 (r319682) +++ head/tools/regression/sockets/accf_data_attach/accf_data_attach.c Thu Jun 8 05:12:11 2017 (r319683) @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -64,7 +65,7 @@ main(void) struct accept_filter_arg afa; struct sockaddr_in sin; socklen_t len; - int lso, ret; + int lso, so, i, ret; /* XXX: PLAIN_TEST_REQUIRE_MODULE "backport" for stable/9 */ const char *_mod_name = "accf_data"; @@ -76,7 +77,7 @@ main(void) } /* XXX: PLAIN_TEST_REQUIRE_MODULE for stable/9 */ - printf("1..11\n"); + printf("1..12\n"); /* * Step 0. Open socket(). @@ -103,6 +104,7 @@ main(void) /* * Step 2. Bind(). Ideally this will succeed. */ + setsockopt(lso, SOL_SOCKET, SO_REUSEADDR, &lso, sizeof(lso)); bzero(&sin, sizeof(sin)); sin.sin_len = sizeof(sin); sin.sin_family = AF_INET; @@ -203,24 +205,53 @@ main(void) printf("ok 10 - getsockopt\n"); /* - * Step 10: Remove accept filter. After removing the accept filter + * Step 10: Set listening socket to non blocking mode. Open + * connection to our listening socket and try to accept. Should + * no succeed. Write a byte of data and try again. Should accept. + */ + i = fcntl(lso, F_GETFL); + if (i < 0) + errx(-1, "not ok 11 - ioctl(F_GETFL): %s", strerror(errno)); + i |= O_NONBLOCK; + if (fcntl(lso, F_SETFL, i) != 0) + errx(-1, "not ok 11 - ioctl(F_SETFL): %s", strerror(errno)); + so = socket(PF_INET, SOCK_STREAM, 0); + if (so == -1) + errx(-1, "not ok 11 - socket: %s", strerror(errno)); + if (connect(so, (struct sockaddr *)&sin, sizeof(sin)) < 0) + errx(-1, "not ok 11 - connect %s", strerror(errno)); + if (accept(lso, NULL, 0) != -1 && errno != EWOULDBLOCK) + errx(-1, "not ok 11 - accept #1 %s", strerror(errno)); + if (write(so, "0", 1) != 1) + errx(-1, "not ok 11 - write %s", strerror(errno)); + /* + * XXXGL: ugly, but we need to make sure that our write reaches + * remote side of the socket. + */ + usleep(10000); + if (accept(lso, NULL, 0) < 1) + errx(-1, "not ok 11 - accept #2 %s", strerror(errno)); + printf("ok 11 - accept\n"); + + /* + * Step 11: 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 11 - setsockopt() after listen() " + errx(-1, "not ok 12 - 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 11 - getsockopt() after removing " + errx(-1, "not ok 12 - getsockopt() after removing " "the accept filter returns valid accept filter %s", afa.af_name); if (errno != EINVAL) - errx(-1, "not ok 11 - getsockopt() after removing the accept" + errx(-1, "not ok 12 - getsockopt() after removing the accept" "filter failed with %d (%s)", errno, strerror(errno)); - printf("ok 11 - setsockopt\n"); + printf("ok 12 - setsockopt\n"); close(lso); return (0);