From 96d348efbf29888f5ef923251c7d51d45a897c0b Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Fri, 28 Aug 2020 13:02:41 +0200 Subject: Fix change in ss7 server default listen addr, keeps backward-compatibility behavior Previous commit changed the default bind/listen address of the server from NULL (0.0.0.0) to 127.0.0.1, hence breaking some setups where no "local-ip" was defined and hence from then on were only listening on localhost by default. Let's instead bind to "::" if IPv6 is available, which covers any IPv6 and/or IPv4 address. If not available, keep binding to 0.0.0.0. Similarly, if IPv6 is available set default remote to both ::1 and 127.0.0.1 to allow it working against processes listening on IPv4 or IPv6 addresses. Change-Id: Id4718267df2390f70cec519042dc12bac0cd2876 --- src/osmo_ss7_vty.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/osmo_ss7_vty.c b/src/osmo_ss7_vty.c index 4591156..3035844 100644 --- a/src/osmo_ss7_vty.c +++ b/src/osmo_ss7_vty.c @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -1801,6 +1802,32 @@ static void write_one_cs7(struct vty *vty, struct osmo_ss7_instance *inst, bool osmo_sccp_vty_write_cs7_node(vty, " ", inst->sccp); } +static bool ipv6_sctp_supported(const char *host, bool bind) +{ + int rc; + struct addrinfo hints; + struct addrinfo *result; + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_INET6; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_NUMERICHOST; + hints.ai_protocol = 0; /* Any protocol */ + + if (bind) /* For wildcard IP address */ + hints.ai_flags |= AI_PASSIVE; + + /* man getaddrinfo: Either node or service, but not both, may be NULL. */ + OSMO_ASSERT(host); + rc = getaddrinfo(host, NULL, &hints, &result); + if (rc != 0) { + LOGP(DLSS7, LOGL_NOTICE, "Default IPv6 address %s not supported: %s\n", + host, gai_strerror(rc)); + return false; + } else { + freeaddrinfo(result); + return true; + } +} int osmo_ss7_vty_go_parent(struct vty *vty) { @@ -1814,11 +1841,19 @@ int osmo_ss7_vty_go_parent(struct vty *vty) case L_CS7_ASP_NODE: asp = vty->index; /* If no local addr was set */ - if (!asp->cfg.local.host_cnt) - osmo_ss7_asp_peer_add_host(&asp->cfg.local, asp, "localhost"); + if (!asp->cfg.local.host_cnt) { + /* "::" Covers both IPv4 and IPv6 */ + if (ipv6_sctp_supported("::", true)) + 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"); + } /* If no remote addr was set */ - if (!asp->cfg.remote.host_cnt) - osmo_ss7_asp_peer_add_host(&asp->cfg.remote, asp, "localhost"); + if (!asp->cfg.remote.host_cnt) { + osmo_ss7_asp_peer_add_host(&asp->cfg.remote, asp, "127.0.0.1"); + if (ipv6_sctp_supported("::1", false)) + osmo_ss7_asp_peer_add_host(&asp->cfg.remote, asp, "::1"); + } osmo_ss7_asp_restart(asp); vty->node = L_CS7_NODE; vty->index = asp->inst; -- cgit v1.2.3