This update consists of: - fixes to several existing tests - a test for regression introduced bytirimbinob9470c2760
("inet: kill smallest_size and smallest_port") - seccomp support for glibc 2.26 siginfo_t.h - fixes to kselftest framework and tests to run make O=dir use-case - fixes to silence unnecessary test output to de-clutter test results -----BEGIN PGP SIGNATURE----- iQIcBAABCAAGBQJZy7S7AAoJEAsCRMQNDUMcAt0P/iuR279yaBF3RVqHTyXsmr/t RO6k4uj4XLYKTrVnV/YTu5hLCGO9fPDhprMmrTqlAGclioEyMDtRTOWDDln4TNFh gehbXiOTVVHlLPCOXXRwvU+RsMppgi4O2WRTBK0dnTkBdl+sTLOl4iywGyqFPB11 O3oj1nNc8ruaxYoUMYwxiGCm1OATrngoSu/Y4mMhZPgT9MnCtZWDlg//kkrxQDHO UTD11zk17nBAOw2q4nw3I4un00tgN8RzIOfg9g47Az40LjWSG5c5oAgd/hArqeBv 7pCUR1PnNKTf0RujX0nfaoQQ+bOEXqpV9GmM67HLo8Q/5e4lYxWdmSdhItPS5qtS ZLo1lEMOuRH7+FCQuD236llhwKVMm/+R3jnXgdJcc+SupdGCmpzZ9P8rscX1g11R ZDZ9+k8XOA2p7ufxSIGFEILSovn0FUMneOd3Nhwk40R7cIvSiZh+V+Xzdb6Q1K9T NBVtH8qvRi5TyHSNwQCDF45fC6bCM80JxGcPToOguFsQTcUL6B0pG6xhxZG73+Ut br+Z5y+g+JLWLeGzaBjo4LnqFpeP6w4Jb8CCrqu8BussV3BToIFCJkGX6aOggow/ D3g03tGDeMjqFMYwn0ZCH5s5u9cicWUUC8CBvoCJp2UZaE/prsNNfRjZjfwYlrVj TvWPdPJtwjA/sdq/n2Hl =FUuY -----END PGP SIGNATURE----- Merge tag 'linux-kselftest-4.14-rc3-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest Pull kselftest fixes from Shuah Khan: "This update consists of: - fixes to several existing tests - a test for regression introduced byb9470c2760
("inet: kill smallest_size and smallest_port") - seccomp support for glibc 2.26 siginfo_t.h - fixes to kselftest framework and tests to run make O=dir use-case - fixes to silence unnecessary test output to de-clutter test results" * tag 'linux-kselftest-4.14-rc3-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (28 commits) selftests: timers: set-timer-lat: Fix hang when testing unsupported alarms selftests: timers: set-timer-lat: fix hang when std out/err are redirected selftests/memfd: correct run_tests.sh permission selftests/seccomp: Support glibc 2.26 siginfo_t.h selftests: futex: Makefile: fix for loops in targets to run silently selftests: Makefile: fix for loops in targets to run silently selftests: mqueue: Use full path to run tests from Makefile selftests: futex: copy sub-dir test scripts for make O=dir run selftests: lib.mk: copy test scripts and test files for make O=dir run selftests: sync: kselftest and kselftest-clean fail for make O=dir case selftests: sync: use TEST_CUSTOM_PROGS instead of TEST_PROGS selftests: lib.mk: add TEST_CUSTOM_PROGS to allow custom test run/install selftests: watchdog: fix to use TEST_GEN_PROGS and remove clean selftests: lib.mk: fix test executable status check to use full path selftests: Makefile: clear LDFLAGS for make O=dir use-case selftests: lib.mk: kselftest and kselftest-clean fail for make O=dir case Makefile: kselftest and kselftest-clean fail for make O=dir case selftests/net: msg_zerocopy enable build with older kernel headers selftests: actually run the various net selftests selftest: add a reuseaddr test ...
commit
225d3b6748
@ -0,0 +1,114 @@ |
||||
/*
|
||||
* Test for the regression introduced by |
||||
* |
||||
* b9470c27607b ("inet: kill smallest_size and smallest_port") |
||||
* |
||||
* If we open an ipv4 socket on a port with reuseaddr we shouldn't reset the tb |
||||
* when we open the ipv6 conterpart, which is what was happening previously. |
||||
*/ |
||||
#include <errno.h> |
||||
#include <error.h> |
||||
#include <arpa/inet.h> |
||||
#include <netinet/in.h> |
||||
#include <stdbool.h> |
||||
#include <stdio.h> |
||||
#include <sys/socket.h> |
||||
#include <sys/types.h> |
||||
#include <unistd.h> |
||||
|
||||
#define PORT 9999 |
||||
|
||||
int open_port(int ipv6, int any) |
||||
{ |
||||
int fd = -1; |
||||
int reuseaddr = 1; |
||||
int v6only = 1; |
||||
int addrlen; |
||||
int ret = -1; |
||||
struct sockaddr *addr; |
||||
int family = ipv6 ? AF_INET6 : AF_INET; |
||||
|
||||
struct sockaddr_in6 addr6 = { |
||||
.sin6_family = AF_INET6, |
||||
.sin6_port = htons(PORT), |
||||
.sin6_addr = in6addr_any |
||||
}; |
||||
struct sockaddr_in addr4 = { |
||||
.sin_family = AF_INET, |
||||
.sin_port = htons(PORT), |
||||
.sin_addr.s_addr = any ? htonl(INADDR_ANY) : inet_addr("127.0.0.1"), |
||||
}; |
||||
|
||||
|
||||
if (ipv6) { |
||||
addr = (struct sockaddr*)&addr6; |
||||
addrlen = sizeof(addr6); |
||||
} else { |
||||
addr = (struct sockaddr*)&addr4; |
||||
addrlen = sizeof(addr4); |
||||
} |
||||
|
||||
if ((fd = socket(family, SOCK_STREAM, IPPROTO_TCP)) < 0) { |
||||
perror("socket"); |
||||
goto out; |
||||
} |
||||
|
||||
if (ipv6 && setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&v6only, |
||||
sizeof(v6only)) < 0) { |
||||
perror("setsockopt IPV6_V6ONLY"); |
||||
goto out; |
||||
} |
||||
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, |
||||
sizeof(reuseaddr)) < 0) { |
||||
perror("setsockopt SO_REUSEADDR"); |
||||
goto out; |
||||
} |
||||
|
||||
if (bind(fd, addr, addrlen) < 0) { |
||||
perror("bind"); |
||||
goto out; |
||||
} |
||||
|
||||
if (any) |
||||
return fd; |
||||
|
||||
if (listen(fd, 1) < 0) { |
||||
perror("listen"); |
||||
goto out; |
||||
} |
||||
return fd; |
||||
out: |
||||
close(fd); |
||||
return ret; |
||||
} |
||||
|
||||
int main(void) |
||||
{ |
||||
int listenfd; |
||||
int fd1, fd2; |
||||
|
||||
fprintf(stderr, "Opening 127.0.0.1:%d\n", PORT); |
||||
listenfd = open_port(0, 0); |
||||
if (listenfd < 0) |
||||
error(1, errno, "Couldn't open listen socket"); |
||||
fprintf(stderr, "Opening INADDR_ANY:%d\n", PORT); |
||||
fd1 = open_port(0, 1); |
||||
if (fd1 >= 0) |
||||
error(1, 0, "Was allowed to create an ipv4 reuseport on a already bound non-reuseport socket"); |
||||
fprintf(stderr, "Opening in6addr_any:%d\n", PORT); |
||||
fd1 = open_port(1, 1); |
||||
if (fd1 < 0) |
||||
error(1, errno, "Couldn't open ipv6 reuseport"); |
||||
fprintf(stderr, "Opening INADDR_ANY:%d\n", PORT); |
||||
fd2 = open_port(0, 1); |
||||
if (fd2 >= 0) |
||||
error(1, 0, "Was allowed to create an ipv4 reuseport on a already bound non-reuseport socket"); |
||||
close(fd1); |
||||
fprintf(stderr, "Opening INADDR_ANY:%d after closing ipv6 socket\n", PORT); |
||||
fd1 = open_port(0, 1); |
||||
if (fd1 >= 0) |
||||
error(1, 0, "Was allowed to create an ipv4 reuseport on an already bound non-reuseport socket with no ipv6"); |
||||
fprintf(stderr, "Success"); |
||||
return 0; |
||||
} |
Loading…
Reference in new issue