summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2020-09-01 14:19:10 +0200
committerpespin <pespin@sysmocom.de>2020-09-04 10:55:12 +0000
commit44456920e567e67fb64cbfcac0c6842de6b03e78 (patch)
tree01f7fe05383528d80320dd8ae15d37eb5674586c
parentec3e7e43ab71856b40ca32b5645707de78e5aa56 (diff)
Fix default ASP local addr if remote addr contains only IPv4
Otherwise it would end up attempting to connect "::" -> "1.2.3.4" which would fail during osmo_sock_init2_multiaddr(). If local address is unset (default), but only IPv4 addresses are set on the remote, then one must use "0.0.0.0" instead. Change-Id: I33faf1291e9105bba2e816c01a6b4854cf13d5e0
-rw-r--r--src/osmo_ss7_vty.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/osmo_ss7_vty.c b/src/osmo_ss7_vty.c
index 109b94a..08e650e 100644
--- a/src/osmo_ss7_vty.c
+++ b/src/osmo_ss7_vty.c
@@ -29,6 +29,8 @@
#include <netdb.h>
#include <arpa/inet.h>
+#include <osmocom/core/sockaddr_str.h>
+
#include <osmocom/vty/vty.h>
#include <osmocom/vty/command.h>
#include <osmocom/vty/logging.h>
@@ -1842,8 +1844,18 @@ int osmo_ss7_vty_go_parent(struct vty *vty)
asp = vty->index;
/* If no local addr was set */
if (!asp->cfg.local.host_cnt) {
- /* "::" Covers both IPv4 and IPv6 */
- if (ipv6_sctp_supported("::", true))
+ bool rem_has_v4 = false, rem_has_v6 = false;
+ int i;
+ for (i = 0; i < asp->cfg.remote.host_cnt; i++) {
+ if (osmo_ip_str_type(asp->cfg.remote.host[i]) == AF_INET6)
+ rem_has_v6 = true;
+ else
+ rem_has_v4 = true;
+ }
+ /* "::" Covers both IPv4 and IPv6, but if only IPv4
+ * address are set on the remote side, IPv4 on the local
+ * side must be set too */
+ if (ipv6_sctp_supported("::", true) && !(rem_has_v4 && !rem_has_v6))
osmo_ss7_asp_peer_add_host(&asp->cfg.local, asp, "::");
else
osmo_ss7_asp_peer_add_host(&asp->cfg.local, asp, "0.0.0.0");