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.orgpespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-sccp/+/19769 )
Change subject: Fix finding ASP on IPv6 connections
......................................................................
Fix finding ASP on IPv6 connections
Change-Id: I09226a5cecc37dd4676acd61c2051befe5234cb3
---
M src/osmo_ss7.c
1 file changed, 36 insertions(+), 7 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/69/19769/1
diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c
index cdac27a..bae9904 100644
--- a/src/osmo_ss7.c
+++ b/src/osmo_ss7.c
@@ -1198,6 +1198,26 @@
}
}
+/* Converts string representation of v4-mappend-on-v6 IP addr to a pure IPv4 address.
+ * Example: ::ffff:172.18.19.200 => 172.18.19.200
+ */
+static void chop_v4_mapped_on_v6_prefix(char* buf)
+{
+ char *last_colon;
+ size_t len;
+ char *first_dot = strchr(buf, '.');
+
+ if (!first_dot)
+ return; /* Not an IPv4-mappend-on-v6 string representation, nothing to do */
+ last_colon = strrchr(buf, ':');
+ if (!last_colon)
+ return; /* pure IPv4 address, nothing to do */
+
+ len = strlen(last_colon + 1);
+ memmove(buf, last_colon + 1, len);
+ buf[len] = '\0';
+}
+
/*! \brief Find an ASP definition matching the local+remote IP/PORT of given fd
* \param[in] fd socket descriptor of given socket
* \returns SS7 ASP in case a matching one is found; NULL otherwise */
@@ -1205,7 +1225,7 @@
osmo_ss7_asp_find_by_socket_addr(int fd)
{
struct osmo_ss7_instance *inst;
- struct sockaddr sa_l, sa_r;
+ struct sockaddr_storage sa_l, sa_r;
socklen_t sa_len_l = sizeof(sa_l);
socklen_t sa_len_r = sizeof(sa_r);
char hostbuf_l[64], hostbuf_r[64];
@@ -1215,23 +1235,32 @@
OSMO_ASSERT(ss7_initialized);
/* convert local and remote IP to string */
- rc = getsockname(fd, &sa_l, &sa_len_l);
+ rc = getsockname(fd, (struct sockaddr*)&sa_l, &sa_len_l);
if (rc < 0)
return NULL;
- rc = getnameinfo(&sa_l, sa_len_l, hostbuf_l, sizeof(hostbuf_l),
+ rc = getnameinfo((struct sockaddr*)&sa_l, sa_len_l,
+ hostbuf_l, sizeof(hostbuf_l),
NULL, 0, NI_NUMERICHOST);
if (rc < 0)
return NULL;
- local_port = ntohs(get_in_port(&sa_l));
+ local_port = ntohs(get_in_port((struct sockaddr*)&sa_l));
- rc = getpeername(fd, &sa_r, &sa_len_r);
+ rc = getpeername(fd, (struct sockaddr*)&sa_r, &sa_len_r);
if (rc < 0)
return NULL;
- rc = getnameinfo(&sa_r, sa_len_r, hostbuf_r, sizeof(hostbuf_r),
+ rc = getnameinfo((struct sockaddr*)&sa_r, sa_len_r,
+ hostbuf_r, sizeof(hostbuf_r),
NULL, 0, NI_NUMERICHOST);
if (rc < 0)
return NULL;
- remote_port = ntohs(get_in_port(&sa_r));
+ remote_port = ntohs(get_in_port((struct sockaddr*)&sa_r));
+
+ /* If multi-home is used with both IPv4 and IPv6, then the socket is
+ * AF_INET6, and then returned IPv4 addresses are actually v6mapped ones.
+ * We need to convert them to IPv4 before matching.
+ */
+ chop_v4_mapped_on_v6_prefix(hostbuf_l);
+ chop_v4_mapped_on_v6_prefix(hostbuf_r);
/* check all instances for any ASP definition matching the
* address combination of local/remote ip/port */
--
To view, visit https://gerrit.osmocom.org/c/libosmo-sccp/+/19769
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Change-Id: I09226a5cecc37dd4676acd61c2051befe5234cb3
Gerrit-Change-Number: 19769
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/20200821/a6ae19d8/attachment.htm>