Change in libosmocore[master]: socket: Allow binding to :: (IPv6) and connecting to IPv4-only on the...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Fri Aug 28 12:33:33 UTC 2020


pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/19876 )


Change subject: socket: Allow binding to :: (IPv6) and connecting to IPv4-only on the remote
......................................................................

socket: Allow binding to :: (IPv6) and connecting to IPv4-only on the remote

sctp_bindx() fails if passed both "0.0.0.0" and "::", only "::" must
be passed instead, which covers both.
As a result, it is fine in this case and makes sense having only IPv6
formatted IPs in the local side (which actually also includes all IPv4
ones in th system) and IPv4-only addresses on the remote side.

Change-Id: I0b590113e5def20edcbcb098426b19cd504eabff
---
M src/socket.c
1 file changed, 17 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/76/19876/1

diff --git a/src/socket.c b/src/socket.c
index 1afbe6e..a5bbddf 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -443,6 +443,22 @@
 	}
 }
 
+/* Check whether there's an IPv6 with IN6ADDR_ANY_INIT ("::") */
+static bool addrinfo_has_in6addr_any(const struct addrinfo **result, size_t result_count)
+{
+	size_t host_idx;
+	struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
+
+	for (host_idx = 0; host_idx < result_count; host_idx++) {
+		if (result[host_idx]->ai_family != AF_INET6)
+			continue;
+		if (memcmp(&((struct sockaddr_in6 *)result[host_idx]->ai_addr)->sin6_addr,
+			   &in6addr_any, sizeof(in6addr_any)) == 0)
+			return true;
+	}
+	return false;
+}
+
 static int socket_helper_multiaddr(uint16_t family, uint16_t type, uint8_t proto, unsigned int flags)
 {
 	int sfd, on = 1;
@@ -577,6 +593,7 @@
 	}
 
 	if (((flags & OSMO_SOCK_F_BIND) && (flags & OSMO_SOCK_F_CONNECT)) &&
+	    !addrinfo_has_in6addr_any((const struct addrinfo **)res_loc, local_hosts_cnt) &&
 	    (loc_has_v4addr != rem_has_v4addr || loc_has_v6addr != rem_has_v6addr)) {
 		LOGP(DLGLOBAL, LOGL_ERROR, "Invalid v4 vs v6 in local vs remote addresses\n");
 		rc = -EINVAL;

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19876
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I0b590113e5def20edcbcb098426b19cd504eabff
Gerrit-Change-Number: 19876
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200828/1d1cbdc4/attachment.htm>


More information about the gerrit-log mailing list