pespin has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmo-sccp/+/34612?usp=email )

Change subject: asp: Support removing local & remote addresses
......................................................................

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
---
M TODO-RELEASE
M include/osmocom/sigtran/osmo_ss7.h
M src/osmo_ss7_asp.c
M src/osmo_ss7_asp_peer.c
M src/osmo_ss7_vty.c
M src/ss7_internal.h
M tests/vty/ss7_asp_test.vty
7 files changed, 162 insertions(+), 2 deletions(-)

Approvals:
  laforge: Looks good to me, but someone else must approve
  Jenkins Builder: Verified
  pespin: Looks good to me, approved
  osmith: Looks good to me, but someone else must approve




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 @@
                                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 @@
        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 @@
        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 @@
        }
        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 @@
        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 @@
        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 @@
        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_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 @@
 ...
   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 @@
 ...
   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
 ...

--
To view, visit https://gerrit.osmocom.org/c/libosmo-sccp/+/34612?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Change-Id: I554aee92285bd72eb90c6daf47b37055cb3067aa
Gerrit-Change-Number: 34612
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pes...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <lafo...@osmocom.org>
Gerrit-Reviewer: osmith <osm...@sysmocom.de>
Gerrit-Reviewer: pespin <pes...@sysmocom.de>
Gerrit-MessageType: merged

Reply via email to