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/+/19851 )
Change subject: Validate correctly against IPv6 addresses in osmo_ss7_asp_peer_set_hosts()
......................................................................
Validate correctly against IPv6 addresses in osmo_ss7_asp_peer_set_hosts()
Change-Id: I18f3cc59149d478259d7afc456bdc5213c1406e5
---
M src/osmo_ss7.c
1 file changed, 38 insertions(+), 12 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/51/19851/1
diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c
index bae9904..6357be1 100644
--- a/src/osmo_ss7.c
+++ b/src/osmo_ss7.c
@@ -1137,6 +1137,24 @@
return 0;
}
+static inline bool host_is_ipv6(const char *host)
+{
+ return host && strchr(host, ':');
+}
+
+/* Expects an IPv6 address formatted string */
+static inline bool host_is_ipv4_anyaddr(const char *host)
+{
+ /* NULL addr is resolved as 0.0.0.0 (IPv4) by getaddrinfo(). */
+ return !host || !strcmp(host, "0.0.0.0");
+}
+
+/* Expects an IPv6 address formatted string (no NULL) */
+static inline bool host_is_ipv6_anyaddr(const char *host)
+{
+ return host && !strcmp(host, "::");
+}
+
/*! \brief Append (copy) address to a given ASP peer. Previous addresses are kept.
* \param[in] peer Application Server Process peer the address is appened to.
* \param[in] talloc_ctx talloc context used to allocate new address.
@@ -1146,23 +1164,31 @@
{
int i;
- bool new_is_any = !host || !strcmp(host, "0.0.0.0");
- bool iter_is_any;
+ bool new_is_v6 = host_is_ipv6(host);
+ bool new_is_any = host_is_ipv4_anyaddr(host) || host_is_ipv6_anyaddr(host);
+ bool iter_is_v6, iter_is_any;
if (peer->host_cnt >= ARRAY_SIZE(peer->host))
return -EINVAL;
- /* Makes no sense to have INET_ANY many times, or INET_ANY together with
- specific addresses: */
- if (new_is_any && peer->host_cnt != 0)
- return -EINVAL;
-
- /* Makes no sense to add specific address to set if INET_ANY is
- already set: */
- if (!new_is_any) {
+ if (new_is_any) {
+ /* Makes no sense to have INET_ANY many times, or INET_ANY together with
+ specific addresses: */
for (i = 0; i < peer->host_cnt; i++) {
- iter_is_any = !peer->host[i] ||
- !strcmp(peer->host[i], "0.0.0.0");
+ iter_is_v6 = host_is_ipv6(peer->host[i]);
+ if (new_is_v6 != iter_is_v6)
+ continue;
+ return -EINVAL;
+ }
+ } else {
+ /* Makes no sense to add specific address to set if INET_ANY is
+ already set: */
+ for (i = 0; i < peer->host_cnt; i++) {
+ iter_is_v6 = host_is_ipv6(peer->host[i]);
+ if (new_is_v6 != iter_is_v6)
+ continue;
+ iter_is_any = iter_is_v6 ? host_is_ipv6_anyaddr(peer->host[i])
+ : host_is_ipv4_anyaddr(peer->host[i]);
if (iter_is_any)
return -EINVAL;
}
--
To view, visit https://gerrit.osmocom.org/c/libosmo-sccp/+/19851
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Change-Id: I18f3cc59149d478259d7afc456bdc5213c1406e5
Gerrit-Change-Number: 19851
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/20200827/33d9ac20/attachment.htm>