aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2017-11-17 12:57:25 +0100
committerHarald Welte <laforge@gnumonks.org>2017-12-20 16:04:08 +0000
commit10d4815bb1b4b548ec0bc97611b2e7ac45e0ebc5 (patch)
tree9dd55111832b35ae1d9d71defbcb9bdf652befd4
parent6cd8d1243711f4de2f1314c7b87b972572cdec4e (diff)
ss7: Re-bind xUA server socket after setting new IP
In osmo-stp, cmd "local-ip" inside node "listen m3ua 2905" was actually not being applied, because the server was created + bound at "listen" command time using NULL as IP, and at "local-ip" time the IP was changed but the server was not re-bound using the new IP, so it kept listening at 0.0.0.0. With this patch, we defer binding the socket to "local-ip" cmd time, after the IP has been applied. As a result, if no "local-ip" command is provided, then the bind never happens, which means it is now mandatory that users of osmo_ss7_xua_server_create API not using osmo_ss7_xua_server_set_local_host call new provided API osmo_ss7_xua_server_bind. Another new API osmo_ss7_bind_all_instances is provided to easily make sure all servers are bound after configuration process. This is specially important for servers which doesn't contain the "local-ip" parameter. Users of osmo_sccp_simple_server API are not affected by this change, and they not requrie to call any new API. Furthermore, using osmo_ss7_xua_server_bind in VTY code ensures the xUA server is automatically bound to the new address if the operator changes the "local-ip" cmd at runtime. Related: OS#2647 Change-Id: I79738963d633bec70705ff159c5b2127cd498aa2
-rw-r--r--include/osmocom/sigtran/osmo_ss7.h5
-rw-r--r--src/osmo_ss7.c59
-rw-r--r--src/osmo_ss7_vty.c4
-rw-r--r--src/sccp_user.c5
-rw-r--r--stp/stp_main.c2
5 files changed, 66 insertions, 9 deletions
diff --git a/include/osmocom/sigtran/osmo_ss7.h b/include/osmocom/sigtran/osmo_ss7.h
index 71c2022..94d5e8a 100644
--- a/include/osmocom/sigtran/osmo_ss7.h
+++ b/include/osmocom/sigtran/osmo_ss7.h
@@ -108,6 +108,8 @@ osmo_ss7_instance_find_or_create(void *ctx, uint32_t id);
void osmo_ss7_instance_destroy(struct osmo_ss7_instance *inst);
int osmo_ss7_instance_set_pc_fmt(struct osmo_ss7_instance *inst,
uint8_t c0, uint8_t c1, uint8_t c2);
+int osmo_ss7_instance_bind(struct osmo_ss7_instance *inst);
+int osmo_ss7_bind_all_instances();
/***********************************************************************
* MTP Users (Users of MTP, such as SCCP or ISUP)
@@ -441,6 +443,9 @@ osmo_ss7_xua_server_create(struct osmo_ss7_instance *inst, enum osmo_ss7_asp_pro
uint16_t local_port, const char *local_host);
int
+osmo_ss7_xua_server_bind(struct osmo_xua_server *xs);
+
+int
osmo_ss7_xua_server_set_local_host(struct osmo_xua_server *xs, const char *local_host);
void osmo_ss7_xua_server_destroy(struct osmo_xua_server *xs);
diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c
index 86fb45c..7f82f6e 100644
--- a/src/osmo_ss7.c
+++ b/src/osmo_ss7.c
@@ -423,6 +423,42 @@ int osmo_ss7_instance_set_pc_fmt(struct osmo_ss7_instance *inst,
return 0;
}
+/*! \brief bind all xUA servers belonging to an SS7 Instance
+ * \param[in] inst SS7 Instance to apply the socket binding (and start listening)
+ * \returns 0 on success; negative value on error */
+int osmo_ss7_instance_bind(struct osmo_ss7_instance *inst)
+{
+ struct osmo_xua_server *oxs;
+ int rc = 0;
+
+ llist_for_each_entry(oxs, &inst->xua_servers, list) {
+ if (osmo_ss7_xua_server_bind(oxs) < 0) {
+ LOGSS7(inst, LOGL_ERROR, "Unable to bind xUA server %s:%u\n",
+ oxs->cfg.local.host, oxs->cfg.local.port);
+ rc = -1;
+ }
+ }
+ return rc;
+}
+
+/*! \brief bind all xUA servers on each of the stored SS7 instances
+ * \returns 0 on success; negative value on error */
+int osmo_ss7_bind_all_instances()
+{
+ OSMO_ASSERT(ss7_initialized);
+
+ struct osmo_ss7_instance *inst;
+ int rc = 0;
+
+ llist_for_each_entry(inst, &osmo_ss7_instances, list) {
+ if (osmo_ss7_instance_bind(inst) < 0 ) {
+ LOGSS7(inst, LOGL_ERROR, "Unable to bind all xUA servers in ss7 instance\n");
+ rc = -1;
+ }
+ }
+ return rc;
+}
+
/***********************************************************************
* MTP Users (Users of MTP, such as SCCP or ISUP)
***********************************************************************/
@@ -1745,7 +1781,7 @@ osmo_ss7_xua_server_find(struct osmo_ss7_instance *inst, enum osmo_ss7_asp_proto
return NULL;
}
-/*! \brief create a new xUA server listening to given ip/port
+/*! \brief create a new xUA server configured with given ip/port
* \param[in] ctx talloc allocation context
* \param[in] proto protocol (xUA variant) to use
* \param[in] local_port local SCTP port to bind/listen to
@@ -1757,7 +1793,6 @@ osmo_ss7_xua_server_create(struct osmo_ss7_instance *inst, enum osmo_ss7_asp_pro
uint16_t local_port, const char *local_host)
{
struct osmo_xua_server *oxs = talloc_zero(inst, struct osmo_xua_server);
- int rc;
OSMO_ASSERT(ss7_initialized);
if (!oxs)
@@ -1781,13 +1816,6 @@ osmo_ss7_xua_server_create(struct osmo_ss7_instance *inst, enum osmo_ss7_asp_pro
osmo_stream_srv_link_set_port(oxs->server, oxs->cfg.local.port);
osmo_stream_srv_link_set_proto(oxs->server, asp_proto_to_ip_proto(proto));
- rc = osmo_stream_srv_link_open(oxs->server);
- if (rc < 0) {
- osmo_stream_srv_link_destroy(oxs->server);
- oxs->server = NULL;
- talloc_free(oxs);
- }
-
oxs->inst = inst;
llist_add_tail(&oxs->list, &inst->xua_servers);
@@ -1798,6 +1826,19 @@ osmo_ss7_xua_server_create(struct osmo_ss7_instance *inst, enum osmo_ss7_asp_pro
return oxs;
}
+/*! \brief Set the xUA server to bind/listen to the currently configured ip/port
+ * \param[in] xs xUA server to operate
+ * \returns 0 on success, negative value on error.
+ */
+int
+osmo_ss7_xua_server_bind(struct osmo_xua_server *xs)
+{
+ LOGP(DLSS7, LOGL_INFO, "(Re)binding %s Server to %s:%u\n",
+ get_value_string(osmo_ss7_asp_protocol_vals, xs->cfg.proto),
+ xs->cfg.local.host, xs->cfg.local.port);
+ return osmo_stream_srv_link_open(xs->server);
+}
+
int
osmo_ss7_xua_server_set_local_host(struct osmo_xua_server *xs, const char *local_host)
{
diff --git a/src/osmo_ss7_vty.c b/src/osmo_ss7_vty.c
index 403a9ac..ea06b02 100644
--- a/src/osmo_ss7_vty.c
+++ b/src/osmo_ss7_vty.c
@@ -467,6 +467,10 @@ DEFUN(xua_local_ip, xua_local_ip_cmd,
struct osmo_xua_server *xs = vty->index;
osmo_ss7_xua_server_set_local_host(xs, argv[0]);
+ if (osmo_ss7_xua_server_bind(xs) < 0) {
+ vty_out(vty, "Unable to bind xUA server to IP %s%s", argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
return CMD_SUCCESS;
}
diff --git a/src/sccp_user.c b/src/sccp_user.c
index d9de8d7..cd89c88 100644
--- a/src/sccp_user.c
+++ b/src/sccp_user.c
@@ -521,6 +521,7 @@ osmo_sccp_simple_server_on_ss7_id(void *ctx, uint32_t ss7_id, uint32_t pc,
{
struct osmo_ss7_instance *ss7;
struct osmo_xua_server *xs;
+ int rc;
if (local_port < 0)
local_port = osmo_ss7_asp_protocol_port(prot);
@@ -535,6 +536,10 @@ osmo_sccp_simple_server_on_ss7_id(void *ctx, uint32_t ss7_id, uint32_t pc,
if (!xs)
goto out_ss7;
+ rc = osmo_ss7_xua_server_bind(xs);
+ if (rc < 0)
+ goto out_xs;
+
/* Allocate SCCP stack */
ss7->sccp = osmo_sccp_instance_create(ss7, NULL);
if (!ss7->sccp)
diff --git a/stp/stp_main.c b/stp/stp_main.c
index 69d26b5..3216101 100644
--- a/stp/stp_main.c
+++ b/stp/stp_main.c
@@ -183,6 +183,8 @@ int main(int argc, char **argv)
exit(1);
}
+ osmo_ss7_bind_all_instances();
+
rc = telnet_init_dynif(NULL, NULL, vty_get_bind_addr(), OSMO_VTY_PORT_STP);
if (rc < 0) {
perror("Erro binding VTY port\n");