aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2023-09-29 20:10:52 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2023-10-02 13:15:51 +0200
commitf8aaa758529c4a1e14c297489b00dce3cb349f8e (patch)
tree33b1dd9ec96e8f3827b356329ca67526c3edb236
parent44cf7c8231198c92e4fc4fdbbd63bc79749d48df (diff)
asp: Support adding new local addresses after the ASP was started
-rw-r--r--TODO-RELEASE1
-rw-r--r--src/osmo_ss7_asp.c19
-rw-r--r--src/osmo_ss7_vty.c17
-rw-r--r--src/ss7_internal.h1
4 files changed, 37 insertions, 1 deletions
diff --git a/TODO-RELEASE b/TODO-RELEASE
index d0852fc..b1b533c 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -7,3 +7,4 @@
# If any interfaces have been added since the last public release: c:r:a + 1.
# If any interfaces have been removed or changed since the last public release: c:r:0.
#library what description / commit summary line
+libosmocore >1.9.0 osmo_sock_multiaddr_add_local_addr() \ No newline at end of file
diff --git a/src/osmo_ss7_asp.c b/src/osmo_ss7_asp.c
index f26e2e1..68bd0ca 100644
--- a/src/osmo_ss7_asp.c
+++ b/src/osmo_ss7_asp.c
@@ -168,6 +168,25 @@ static const struct rate_ctr_group_desc ss7_asp_rcgd = {
};
static unsigned int g_ss7_asp_rcg_idx;
+int ss7_asp_apply_new_local_address(const struct osmo_ss7_asp *asp, unsigned int loc_idx)
+{
+ const char *new_loc_addr;
+ struct osmo_fd *ofd;
+
+ OSMO_ASSERT(loc_idx < asp->cfg.local.host_cnt);
+ new_loc_addr = asp->cfg.local.host[loc_idx];
+
+ LOGPASP(asp, DLSS7, LOGL_INFO, "Add local address %s\n",
+ new_loc_addr);
+
+ if (asp->cfg.is_server)
+ ofd = osmo_stream_srv_get_ofd(asp->server);
+ else
+ ofd = osmo_stream_cli_get_ofd(asp->client);
+
+ return osmo_sock_multiaddr_add_local_addr(ofd->fd, &new_loc_addr, 1);
+}
+
int ss7_asp_apply_peer_primary_address(const struct osmo_ss7_asp *asp)
{
struct osmo_fd *ofd;
diff --git a/src/osmo_ss7_vty.c b/src/osmo_ss7_vty.c
index cdca10d..f9c1ada 100644
--- a/src/osmo_ss7_vty.c
+++ b/src/osmo_ss7_vty.c
@@ -715,6 +715,7 @@ DEFUN_ATTR(asp_local_ip, asp_local_ip_cmd,
struct osmo_ss7_asp *asp = vty->index;
bool is_primary = argc > 1;
int old_idx_primary = asp->cfg.local.idx_primary;
+ int old_host_count = asp->cfg.local.host_cnt;
int rc;
if (osmo_ss7_asp_peer_add_host2(&asp->cfg.local, asp, argv[0], is_primary) != 0) {
@@ -726,8 +727,21 @@ DEFUN_ATTR(asp_local_ip, asp_local_ip_cmd,
return CMD_SUCCESS;
if (asp->cfg.proto == OSMO_SS7_ASP_PROT_IPA)
return CMD_SUCCESS;
+ /* The SCTP socket is already created. */
- /* The SCTP socket is already created, dynamically apply the new primary if it changed: */
+ /* dynamically apply the new address if it was added to the set: */
+ if (asp->cfg.local.host_cnt > old_host_count) {
+ if ((rc = ss7_asp_apply_new_local_address(asp, asp->cfg.local.host_cnt - 1)) < 0) {
+ /* Failed, rollback changes: */
+ TALLOC_FREE(asp->cfg.local.host[asp->cfg.local.host_cnt - 1]);
+ asp->cfg.local.host_cnt--;
+ vty_out(vty, "%% Failed adding new local address '%s'%s", argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ vty_out(vty, "%% Local address '%s' added to the active socket bind set%s", argv[0], VTY_NEWLINE);
+ }
+
+ /* dynamically apply the new primary if it changed: */
if (is_primary && asp->cfg.local.idx_primary != old_idx_primary) {
if ((rc = ss7_asp_apply_peer_primary_address(asp)) < 0) {
/* Failed, rollback changes: */
@@ -735,6 +749,7 @@ DEFUN_ATTR(asp_local_ip, asp_local_ip_cmd,
vty_out(vty, "%% Failed announcing primary '%s' to peer%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
+ vty_out(vty, "%% Local address '%s' announced as primary to the peer on the active socket%s", argv[0], VTY_NEWLINE);
}
return CMD_SUCCESS;
}
diff --git a/src/ss7_internal.h b/src/ss7_internal.h
index ad71e83..438fca9 100644
--- a/src/ss7_internal.h
+++ b/src/ss7_internal.h
@@ -27,6 +27,7 @@ int ss7_asp_xua_srv_conn_cb(struct osmo_stream_srv *conn);
int ss7_asp_xua_srv_conn_closed_cb(struct osmo_stream_srv *srv);
int ss7_asp_apply_peer_primary_address(const struct osmo_ss7_asp *asp);
int ss7_asp_apply_primary_address(const struct osmo_ss7_asp *asp);
+int ss7_asp_apply_new_local_address(const struct osmo_ss7_asp *asp, unsigned int loc_idx);
bool ss7_asp_peer_match_host(const struct osmo_ss7_asp_peer *peer, const char *host, bool host_is_v6);