The branch main has been updated by markj:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=63efd7f5ac6675b5a780adf52b91ee089d8b2665

commit 63efd7f5ac6675b5a780adf52b91ee089d8b2665
Author:     Mark Johnston <ma...@freebsd.org>
AuthorDate: 2025-01-27 22:23:08 +0000
Commit:     Mark Johnston <ma...@freebsd.org>
CommitDate: 2025-01-28 14:22:20 +0000

    socket tests: Add a test which calls listen() twice on an lb socket
    
    This exercises commit 06bf119f265c ("sockets/tcp: quick fix for
    regression with SO_REUSEPORT_LB")
    
    Reviewed by:    glebius
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   Stormshield
    Differential Revision:  https://reviews.freebsd.org/D48702
---
 tests/sys/netinet/so_reuseport_lb_test.c | 58 ++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/tests/sys/netinet/so_reuseport_lb_test.c 
b/tests/sys/netinet/so_reuseport_lb_test.c
index 3ce09fcf5794..09d8e0ce8f83 100644
--- a/tests/sys/netinet/so_reuseport_lb_test.c
+++ b/tests/sys/netinet/so_reuseport_lb_test.c
@@ -377,11 +377,69 @@ ATF_TC_BODY(concurrent_add, tc)
        }
 }
 
+/*
+ * Try calling listen(2) twice on a socket with SO_REUSEPORT_LB set.
+ */
+ATF_TC_WITHOUT_HEAD(double_listen_ipv4);
+ATF_TC_BODY(double_listen_ipv4, tc)
+{
+       struct sockaddr_in sin;
+       int error, s;
+
+       s = lb_listen_socket(PF_INET, 0);
+
+       memset(&sin, 0, sizeof(sin));
+       sin.sin_len = sizeof(sin);
+       sin.sin_family = AF_INET;
+       sin.sin_port = htons(0);
+       sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+       error = bind(s, (struct sockaddr *)&sin, sizeof(sin));
+       ATF_REQUIRE_MSG(error == 0, "bind() failed: %s", strerror(errno));
+
+       error = listen(s, 1);
+       ATF_REQUIRE_MSG(error == 0, "listen() failed: %s", strerror(errno));
+       error = listen(s, 2);
+       ATF_REQUIRE_MSG(error == 0, "listen() failed: %s", strerror(errno));
+
+       error = close(s);
+       ATF_REQUIRE_MSG(error == 0, "close() failed: %s", strerror(errno));
+}
+
+/*
+ * Try calling listen(2) twice on a socket with SO_REUSEPORT_LB set.
+ */
+ATF_TC_WITHOUT_HEAD(double_listen_ipv6);
+ATF_TC_BODY(double_listen_ipv6, tc)
+{
+       struct sockaddr_in6 sin6;
+       int error, s;
+
+       s = lb_listen_socket(PF_INET6, 0);
+
+       memset(&sin6, 0, sizeof(sin6));
+       sin6.sin6_len = sizeof(sin6);
+       sin6.sin6_family = AF_INET6;
+       sin6.sin6_port = htons(0);
+       sin6.sin6_addr = in6addr_loopback;
+       error = bind(s, (struct sockaddr *)&sin6, sizeof(sin6));
+       ATF_REQUIRE_MSG(error == 0, "bind() failed: %s", strerror(errno));
+
+       error = listen(s, 1);
+       ATF_REQUIRE_MSG(error == 0, "listen() failed: %s", strerror(errno));
+       error = listen(s, 2);
+       ATF_REQUIRE_MSG(error == 0, "listen() failed: %s", strerror(errno));
+
+       error = close(s);
+       ATF_REQUIRE_MSG(error == 0, "close() failed: %s", strerror(errno));
+}
+
 ATF_TP_ADD_TCS(tp)
 {
        ATF_TP_ADD_TC(tp, basic_ipv4);
        ATF_TP_ADD_TC(tp, basic_ipv6);
        ATF_TP_ADD_TC(tp, concurrent_add);
+       ATF_TP_ADD_TC(tp, double_listen_ipv4);
+       ATF_TP_ADD_TC(tp, double_listen_ipv6);
 
        return (atf_no_error());
 }

Reply via email to