aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2023-10-02 12:00:17 +0200
committerpespin <pespin@sysmocom.de>2023-10-04 11:21:05 +0000
commitc5a4b772b103d441d0be714145269e17b5228621 (patch)
treed95f4a8bcda5c9a1d802c013e302da2c7baa6c4f
parent613e25305baf4fad177613e3cf6c6d1e815ea935 (diff)
asp: Support removing local & remote addresses
The local address is removed dynamically from the socket if it is already created. For remote addresses, it doesn't make any sense (and there's no API to do so) because the remote address list passed to it is only used at connect() time, when the socket is created. During the initial hanshake, the remote provides its own list of remote addresses. Related: OS#6077 Related: OS#4607 Depends: libosmocore.git Change-Id Ifc6e7d643c2a0c53f479bfd0d5c36d08c0c01953 Change-Id: I554aee92285bd72eb90c6daf47b37055cb3067aa
-rw-r--r--TODO-RELEASE2
-rw-r--r--include/osmocom/sigtran/osmo_ss7.h2
-rw-r--r--src/osmo_ss7_asp.c19
-rw-r--r--src/osmo_ss7_asp_peer.c59
-rw-r--r--src/osmo_ss7_vty.c57
-rw-r--r--src/ss7_internal.h2
-rw-r--r--tests/vty/ss7_asp_test.vty4
7 files changed, 143 insertions, 2 deletions
diff --git a/TODO-RELEASE b/TODO-RELEASE
index b1b533c..ae21a12 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -7,4 +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
+libosmocore >1.9.0 osmo_sock_multiaddr_{add,del}_local_addr() \ No newline at end of file
diff --git a/include/osmocom/sigtran/osmo_ss7.h b/include/osmocom/sigtran/osmo_ss7.h
index 98e1187..841c12b 100644
--- a/include/osmocom/sigtran/osmo_ss7.h
+++ b/include/osmocom/sigtran/osmo_ss7.h
@@ -471,6 +471,8 @@ int osmo_ss7_asp_peer_set_hosts2(struct osmo_ss7_asp_peer *peer, void *talloc_ct
const char *const*hosts, size_t host_cnt, int idx_primary);
int osmo_ss7_asp_peer_add_host(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *host);
int osmo_ss7_asp_peer_add_host2(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *host, bool is_primary_addr);
+int osmo_ss7_asp_peer_del_host(struct osmo_ss7_asp_peer *peer, const char *host);
+
struct osmo_ss7_asp *
osmo_ss7_asp_find_by_name(struct osmo_ss7_instance *inst, const char *name);
diff --git a/src/osmo_ss7_asp.c b/src/osmo_ss7_asp.c
index 68bd0ca..1ba0a43 100644
--- a/src/osmo_ss7_asp.c
+++ b/src/osmo_ss7_asp.c
@@ -187,6 +187,25 @@ int ss7_asp_apply_new_local_address(const struct osmo_ss7_asp *asp, unsigned int
return osmo_sock_multiaddr_add_local_addr(ofd->fd, &new_loc_addr, 1);
}
+int ss7_asp_apply_drop_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, "Remove 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_del_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_asp_peer.c b/src/osmo_ss7_asp_peer.c
index cf591d9..39a92b1 100644
--- a/src/osmo_ss7_asp_peer.c
+++ b/src/osmo_ss7_asp_peer.c
@@ -208,6 +208,50 @@ int osmo_ss7_asp_peer_add_host2(struct osmo_ss7_asp_peer *peer, void *talloc_ctx
return 0;
}
+/*! \brief Remove address from a given ASP peer.
+ * \param[in] peer Application Server Process peer the address is removed from.
+ * \param[in] host string containing an IP address.
+ * \returns 0 on success; negative otherwise */
+int osmo_ss7_asp_peer_del_host(struct osmo_ss7_asp_peer *peer, const char *host)
+{
+ int i;
+ struct osmo_sockaddr_str addr_str;
+ bool found = false;
+
+ if (osmo_sockaddr_str_from_str(&addr_str, host, 0) < 0)
+ return -EINVAL;
+
+ for (i = 0; i < peer->host_cnt; i++) {
+ if (strcmp(host, peer->host[i]) == 0) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ return -ENOENT;
+
+ /* If current primary points to addr being removed, unset it: */
+ if (peer->idx_primary == i)
+ peer->idx_primary = -1;
+ /* If it's after it, update it together with sliding done further below: */
+ else if (peer->idx_primary > i)
+ peer->idx_primary--;
+
+ /* Free addr to remove: */
+ TALLOC_FREE(peer->host[i]);
+
+ /* Move the rest of the array: */
+ for (; i < peer->host_cnt - 1; i++)
+ peer->host[i] = peer->host[i + 1];
+ peer->host[i] = NULL;
+
+ /* Update array size: */
+ peer->host_cnt--;
+
+ return 0;
+}
+
/*! \brief Append (copy) address to a given ASP peer. Previous addresses are kept.
* \param[in] peer Application Server Process peer the address is appended to.
* \param[in] talloc_ctx talloc context used to allocate new address.
@@ -233,3 +277,18 @@ bool ss7_asp_peer_match_host(const struct osmo_ss7_asp_peer *peer, const char *h
}
return false;
}
+
+/*! \brief Find the exact IP address match and return its index in the array
+ * \param[in] peer Application Server Process peer where the address is looked up.
+ * \param[in] host string containing an IP address.
+ * \returns >=0 on success containing the index of the host; negative otherwise */
+int ss7_asp_peer_find_host(const struct osmo_ss7_asp_peer *peer, const char *host)
+{
+ unsigned int i;
+
+ for (i = 0; i < peer->host_cnt; i++) {
+ if (strcmp(host, peer->host[i]) == 0)
+ return i;
+ }
+ return -1;
+}
diff --git a/src/osmo_ss7_vty.c b/src/osmo_ss7_vty.c
index f9c1ada..172893e 100644
--- a/src/osmo_ss7_vty.c
+++ b/src/osmo_ss7_vty.c
@@ -754,6 +754,39 @@ DEFUN_ATTR(asp_local_ip, asp_local_ip_cmd,
return CMD_SUCCESS;
}
+DEFUN_ATTR(asp_no_local_ip, asp_no_local_ip_cmd,
+ "no local-ip " VTY_IPV46_CMD,
+ NO_STR "Specify Local IP Address from which to contact ASP\n"
+ "Local IPv4 Address from which to contact of ASP\n"
+ "Local IPv6 Address from which to contact of ASP\n",
+ CMD_ATTR_NODE_EXIT)
+{
+ struct osmo_ss7_asp *asp = vty->index;
+ int idx = ss7_asp_peer_find_host(&asp->cfg.local, argv[0]);
+ int rc;
+
+ if (idx < 0) {
+ vty_out(vty, "%% Local address '%s' not found in set%s", argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (ss7_asp_is_started(asp)) {
+ if (asp->cfg.proto != OSMO_SS7_ASP_PROT_IPA) {
+ if ((rc = ss7_asp_apply_drop_local_address(asp, idx)) < 0) {
+ vty_out(vty, "%% Failed removing local address '%s' from existing socket%s", argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ vty_out(vty, "%% Local address '%s' removed from active socket connection%s", argv[0], VTY_NEWLINE);
+ }
+ }
+
+ if (osmo_ss7_asp_peer_del_host(&asp->cfg.local, argv[0]) != 0) {
+ vty_out(vty, "%% Failed deleting local address '%s' from set%s", argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ return CMD_SUCCESS;
+}
+
DEFUN_ATTR(asp_remote_ip, asp_remote_ip_cmd,
"remote-ip " VTY_IPV46_CMD " [primary]",
"Specify Remote IP Address of ASP\n"
@@ -789,6 +822,28 @@ DEFUN_ATTR(asp_remote_ip, asp_remote_ip_cmd,
return CMD_SUCCESS;
}
+DEFUN_ATTR(asp_no_remote_ip, asp_no_remote_ip_cmd,
+ "no remote-ip " VTY_IPV46_CMD,
+ NO_STR "Specify Remote IP Address of ASP\n"
+ "Remote IPv4 Address of ASP\n"
+ "Remote IPv6 Address of ASP\n",
+ CMD_ATTR_NODE_EXIT)
+{
+ struct osmo_ss7_asp *asp = vty->index;
+ int idx = ss7_asp_peer_find_host(&asp->cfg.remote, argv[0]);
+
+ if (idx < 0) {
+ vty_out(vty, "%% Remote address '%s' not found in set%s", argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (osmo_ss7_asp_peer_del_host(&asp->cfg.remote, argv[0]) != 0) {
+ vty_out(vty, "%% Failed deleting remote address '%s' from set%s", argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ return CMD_SUCCESS;
+}
+
DEFUN_ATTR(asp_qos_clas, asp_qos_class_cmd,
"qos-class <0-255>",
"Specify QoS Class of ASP\n"
@@ -2362,7 +2417,9 @@ static void vty_init_shared(void *ctx)
install_lib_element(L_CS7_NODE, &no_cs7_asp_cmd);
install_lib_element(L_CS7_ASP_NODE, &cfg_description_cmd);
install_lib_element(L_CS7_ASP_NODE, &asp_remote_ip_cmd);
+ install_lib_element(L_CS7_ASP_NODE, &asp_no_remote_ip_cmd);
install_lib_element(L_CS7_ASP_NODE, &asp_local_ip_cmd);
+ install_lib_element(L_CS7_ASP_NODE, &asp_no_local_ip_cmd);
install_lib_element(L_CS7_ASP_NODE, &asp_qos_class_cmd);
install_lib_element(L_CS7_ASP_NODE, &asp_role_cmd);
install_lib_element(L_CS7_ASP_NODE, &asp_sctp_role_cmd);
diff --git a/src/ss7_internal.h b/src/ss7_internal.h
index 438fca9..e2d78d8 100644
--- a/src/ss7_internal.h
+++ b/src/ss7_internal.h
@@ -28,8 +28,10 @@ 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);
+int ss7_asp_apply_drop_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);
+int ss7_asp_peer_find_host(const struct osmo_ss7_asp_peer *peer, const char *host);
bool ss7_xua_server_set_default_local_hosts(struct osmo_xua_server *oxs);
diff --git a/tests/vty/ss7_asp_test.vty b/tests/vty/ss7_asp_test.vty
index 09a3dba..dcea4ca 100644
--- a/tests/vty/ss7_asp_test.vty
+++ b/tests/vty/ss7_asp_test.vty
@@ -221,7 +221,9 @@ ss7_asp_vty_test(config-cs7-asp)# list
...
description .TEXT
remote-ip (A.B.C.D|X:X::X:X) [primary]
+ no remote-ip (A.B.C.D|X:X::X:X)
local-ip (A.B.C.D|X:X::X:X) [primary]
+ no local-ip (A.B.C.D|X:X::X:X)
qos-class <0-255>
role (sg|asp|ipsp)
sctp-role (client|server)
@@ -235,12 +237,12 @@ ss7_asp_vty_test(config-cs7-asp)# ?
...
description Save human-readable description of the object
remote-ip Specify Remote IP Address of ASP
+ no Negate a command or set its defaults
local-ip Specify Local IP Address from which to contact ASP
qos-class Specify QoS Class of ASP
role Specify the xUA role for this ASP
sctp-role Specify the SCTP role for this ASP
sctp-param Configure SCTP parameters
- no Negate a command or set its defaults
block Allows a SCTP Association with ASP, but doesn't let it become active
shutdown Terminates SCTP association; New associations will be rejected
...