diff options
author | Alexander Couzens <lynxis@fe80.eu> | 2020-06-03 00:28:02 +0200 |
---|---|---|
committer | laforge <laforge@osmocom.org> | 2020-08-06 16:41:20 +0000 |
commit | 2c962f5de1eeea119cfac7d9d92db31c570353b9 (patch) | |
tree | 429dd7361c365bb86c37e5dfe947156a8f20bdd5 /tests/socket/socket_test.c | |
parent | 6300aff3b2d56d3565a63cf7fc2f888a8ef615cb (diff) |
osmo_sock_init2: improve support for AF_UNSPEC
osmo_sock_init2 abstract two calls of getaddrinfo into one.
While there aren't problems with AF_INET or AF_INET6. When using
AF_UNSPEC there are corner cases when this fails. E.g. calling
local_host with "" and remote_host with an IPv6 only address results in
setting up a local socket with AF_INET while trying to connect from there towards
AF_INET6 will most likely fail.
To prevent such cases with AF_UNSPEC, search prio calling any syscalls if local and remote site
supports AF_INET or AF_INET6. In case both supported, prefer AF_INET6
Change-Id: I397c633931fd00d4f083955a3c49a40fb002d766
Diffstat (limited to 'tests/socket/socket_test.c')
-rw-r--r-- | tests/socket/socket_test.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/socket/socket_test.c b/tests/socket/socket_test.c index 37e02819..e68243c6 100644 --- a/tests/socket/socket_test.c +++ b/tests/socket/socket_test.c @@ -120,6 +120,27 @@ static int test_sockinit2(void) * FreeBSD 10 or 11 VM at home */ OSMO_ASSERT(!strncmp(name, "(r=127.0.0.1:53<->l=127.0.0.1", 29)); #endif + + printf("Checking osmo_sock_init2(AF_UNSPEC) must fail on mixed IPv4 & IPv6\n"); + fd = osmo_sock_init2(AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, "127.0.0.1", 0, "::1", 53, + OSMO_SOCK_F_BIND|OSMO_SOCK_F_CONNECT); + OSMO_ASSERT(fd < 0); + + printf("Checking osmo_sock_init2(AF_UNSPEC) must fail on mixed IPv6 & IPv4\n"); + fd = osmo_sock_init2(AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, "::1", 0, "127.0.0.1", 53, + OSMO_SOCK_F_BIND|OSMO_SOCK_F_CONNECT); + OSMO_ASSERT(fd < 0); + + printf("Checking osmo_sock_init2(AF_UNSPEC) BIND + CONNECT on IPv4\n"); + fd = osmo_sock_init2(AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, "127.0.0.1", 0, "127.0.0.1", 53, + OSMO_SOCK_F_BIND|OSMO_SOCK_F_CONNECT); + OSMO_ASSERT(fd >= 0); + + printf("Checking osmo_sock_init2(AF_UNSPEC) BIND + CONNECT on IPv6\n"); + fd = osmo_sock_init2(AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, "::1", 0, "::1", 53, + OSMO_SOCK_F_BIND|OSMO_SOCK_F_CONNECT); + OSMO_ASSERT(fd >= 0); + talloc_free(name); return 0; |