Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Aug 2017 20:52:03 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
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
Message-ID:  <201708242052.v7OKq3kk080943@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201708242052.v7OKq3kk080943>