aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo_ss7_asp_peer.c
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 /src/osmo_ss7_asp_peer.c
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
Diffstat (limited to 'src/osmo_ss7_asp_peer.c')
-rw-r--r--src/osmo_ss7_asp_peer.c59
1 files changed, 59 insertions, 0 deletions
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;
+}