pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-sigtran/+/38647?usp=email )
Change subject: sigtran: Make osmo_ss7_asp_peer private ......................................................................
sigtran: Make osmo_ss7_asp_peer private
This struct object is only used internally so far, there's no need to make it public.
Change-Id: I6729cc599af3a799d89bc0514d223c84f2233a4b --- M include/osmocom/sigtran/osmo_ss7.h M src/Makefile.am M src/osmo_ss7_asp.c M src/osmo_ss7_asp_peer.c M src/osmo_ss7_vty.c M src/osmo_ss7_xua_srv.c M src/sccp_user.c M src/ss7_asp.h A src/ss7_asp_peer.h M src/ss7_internal.h 10 files changed, 67 insertions(+), 55 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran refs/changes/47/38647/1
diff --git a/include/osmocom/sigtran/osmo_ss7.h b/include/osmocom/sigtran/osmo_ss7.h index 2d45733..67f4e99 100644 --- a/include/osmocom/sigtran/osmo_ss7.h +++ b/include/osmocom/sigtran/osmo_ss7.h @@ -250,14 +250,6 @@ * SS7 Application Server Processes ***********************************************************************/
-struct osmo_ss7_asp_peer { - char *host[OSMO_SOCK_MAX_ADDRS]; - size_t host_cnt; - uint16_t port; - /* index in "hosts" array marking the SCTP Primary Address, -1 if no explicit Primary Address set */ - int idx_primary; -}; - enum osmo_ss7_asp_admin_state { /*! no SCTP association with peer */ OSMO_SS7_ASP_ADM_S_SHUTDOWN, @@ -284,16 +276,6 @@ /*! Accept SSNM even if ASP is in AS-INACTIVE state */ #define OSMO_SS7_ASP_QUIRK_SNM_INACTIVE 0x00000004
-int osmo_ss7_asp_peer_snprintf(char* buf, size_t buf_len, struct osmo_ss7_asp_peer *peer); -void osmo_ss7_asp_peer_init(struct osmo_ss7_asp_peer *peer); -int osmo_ss7_asp_peer_set_hosts(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, - const char *const*hosts, size_t host_cnt); -int osmo_ss7_asp_peer_set_hosts2(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, - 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/Makefile.am b/src/Makefile.am index 8071be8..1d09c0e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,6 +5,7 @@ noinst_HEADERS = \ sccp_internal.h \ ss7_asp.h \ + ss7_asp_peer.h \ ss7_internal.h \ ss7_link.h \ ss7_linkset.h \ diff --git a/src/osmo_ss7_asp.c b/src/osmo_ss7_asp.c index 1ee0f76..12a5d5f 100644 --- a/src/osmo_ss7_asp.c +++ b/src/osmo_ss7_asp.c @@ -410,16 +410,16 @@ * address are set on the remote side, IPv4 on the local * side must be set too */ if (ss7_ipv6_sctp_supported("::", true) && !(rem_has_v4 && !rem_has_v6)) - osmo_ss7_asp_peer_add_host(&asp->cfg.local, asp, "::"); + ss7_asp_peer_add_host(&asp->cfg.local, asp, "::"); else - osmo_ss7_asp_peer_add_host(&asp->cfg.local, asp, "0.0.0.0"); + ss7_asp_peer_add_host(&asp->cfg.local, asp, "0.0.0.0"); changed = true; } /* If no remote addr was set */ if (!asp->cfg.remote.host_cnt) { - osmo_ss7_asp_peer_add_host(&asp->cfg.remote, asp, "127.0.0.1"); + ss7_asp_peer_add_host(&asp->cfg.remote, asp, "127.0.0.1"); if (ss7_ipv6_sctp_supported("::1", false)) - osmo_ss7_asp_peer_add_host(&asp->cfg.remote, asp, "::1"); + ss7_asp_peer_add_host(&asp->cfg.remote, asp, "::1"); changed = true; } return changed; @@ -552,9 +552,9 @@ } rate_ctr_group_set_name(asp->ctrg, name); asp->inst = inst; - osmo_ss7_asp_peer_init(&asp->cfg.remote); + ss7_asp_peer_init(&asp->cfg.remote); asp->cfg.remote.port = remote_port; - osmo_ss7_asp_peer_init(&asp->cfg.local); + ss7_asp_peer_init(&asp->cfg.local); asp->cfg.local.port = local_port; asp->cfg.trans_proto = trans_proto; asp->cfg.proto = proto; @@ -617,8 +617,8 @@ uint8_t byte;
OSMO_ASSERT(ss7_initialized); - osmo_ss7_asp_peer_snprintf(bufloc, sizeof(bufloc), &asp->cfg.local); - osmo_ss7_asp_peer_snprintf(bufrem, sizeof(bufrem), &asp->cfg.remote); + ss7_asp_peer_snprintf(bufloc, sizeof(bufloc), &asp->cfg.local); + ss7_asp_peer_snprintf(bufrem, sizeof(bufrem), &asp->cfg.remote); LOGPASP(asp, DLSS7, LOGL_INFO, "Restarting ASP %s, r=%s<->l=%s\n", asp->cfg.name, bufrem, bufloc);
diff --git a/src/osmo_ss7_asp_peer.c b/src/osmo_ss7_asp_peer.c index 39a92b1..c31cdd9 100644 --- a/src/osmo_ss7_asp_peer.c +++ b/src/osmo_ss7_asp_peer.c @@ -37,6 +37,7 @@
#include <osmocom/sigtran/osmo_ss7.h>
+#include "ss7_asp_peer.h" #include "ss7_internal.h"
@@ -44,13 +45,13 @@ * SS7 Application Server Process peer ***********************************************************************/
-void osmo_ss7_asp_peer_init(struct osmo_ss7_asp_peer *peer) +void ss7_asp_peer_init(struct osmo_ss7_asp_peer *peer) { memset(peer, 0, sizeof(*peer)); peer->idx_primary = -1; }
-int osmo_ss7_asp_peer_snprintf(char *buf, size_t buf_len, struct osmo_ss7_asp_peer *peer) +int ss7_asp_peer_snprintf(char *buf, size_t buf_len, struct osmo_ss7_asp_peer *peer) { int len = 0, offset = 0, rem = buf_len; int ret, i; @@ -90,7 +91,7 @@ * \param[in] host_cnt Number of strings in hosts * \param[in] idx_primary Index in "hosts" array marking the SCTP Primary Address, -1 if no explicit Primary Address set * \returns 0 on success; negative otherwise */ -int osmo_ss7_asp_peer_set_hosts2(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *const*hosts, size_t host_cnt, int idx_primary) +int ss7_asp_peer_set_hosts2(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *const*hosts, size_t host_cnt, int idx_primary) { int i = 0;
@@ -118,9 +119,9 @@ * \param[in] hosts Array of strings containing IP addresses. * \param[in] host_cnt Number of strings in hosts * \returns 0 on success; negative otherwise */ -int osmo_ss7_asp_peer_set_hosts(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *const*hosts, size_t host_cnt) +int ss7_asp_peer_set_hosts(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *const*hosts, size_t host_cnt) { - return osmo_ss7_asp_peer_set_hosts2(peer, talloc_ctx, hosts, host_cnt, -1); + return ss7_asp_peer_set_hosts2(peer, talloc_ctx, hosts, host_cnt, -1); }
/* Is string formatted IPv4/v6 addr considered IN(6)ADDR_ANY? */ @@ -139,7 +140,7 @@ * \param[in] host string containing an IP address. * \param[in] is_primary_addr whether this IP address is to be added as SCTP Primary Address * \returns 0 on success; negative otherwise */ -int osmo_ss7_asp_peer_add_host2(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, +int ss7_asp_peer_add_host2(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *host, bool is_primary_addr) { int i; @@ -212,7 +213,7 @@ * \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 ss7_asp_peer_del_host(struct osmo_ss7_asp_peer *peer, const char *host) { int i; struct osmo_sockaddr_str addr_str; @@ -257,10 +258,10 @@ * \param[in] talloc_ctx talloc context used to allocate new address. * \param[in] host string containing an IP address. * \returns 0 on success; negative otherwise */ -int osmo_ss7_asp_peer_add_host(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, +int ss7_asp_peer_add_host(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *host) { - return osmo_ss7_asp_peer_add_host2(peer, talloc_ctx, host, false); + return ss7_asp_peer_add_host2(peer, talloc_ctx, host, false); }
bool ss7_asp_peer_match_host(const struct osmo_ss7_asp_peer *peer, const char *host, bool host_is_v6) diff --git a/src/osmo_ss7_vty.c b/src/osmo_ss7_vty.c index 8dd9a4f..482e2f8 100644 --- a/src/osmo_ss7_vty.c +++ b/src/osmo_ss7_vty.c @@ -751,7 +751,7 @@ int fd = xs->server ? osmo_stream_srv_link_get_fd(xs->server) : -1;
if (fd < 0) { - if (osmo_ss7_asp_peer_snprintf(buf, sizeof(buf), &xs->cfg.local) < 0) + if (ss7_asp_peer_snprintf(buf, sizeof(buf), &xs->cfg.local) < 0) snprintf(buf, sizeof(buf), "<error>"); } else { char hostbuf[OSMO_SOCK_MAX_ADDRS][INET6_ADDRSTRLEN]; @@ -965,7 +965,7 @@ 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) { + if (ss7_asp_peer_add_host2(&asp->cfg.local, asp, argv[0], is_primary) != 0) { vty_out(vty, "%% Failed adding host '%s' to set%s", argv[0], VTY_NEWLINE); return CMD_WARNING; } @@ -1027,7 +1027,7 @@ } }
- if (osmo_ss7_asp_peer_del_host(&asp->cfg.local, argv[0]) != 0) { + if (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; } @@ -1047,7 +1047,7 @@ int old_idx_primary = asp->cfg.remote.idx_primary; int rc;
- if (osmo_ss7_asp_peer_add_host2(&asp->cfg.remote, asp, argv[0], is_primary) != 0) { + if (ss7_asp_peer_add_host2(&asp->cfg.remote, asp, argv[0], is_primary) != 0) { vty_out(vty, "%% Failed adding host '%s' to set%s", argv[0], VTY_NEWLINE); return CMD_WARNING; } @@ -1084,7 +1084,7 @@ return CMD_WARNING; }
- if (osmo_ss7_asp_peer_del_host(&asp->cfg.remote, argv[0]) != 0) { + if (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; } @@ -1390,8 +1390,8 @@ if (!get_sockname_buf(buf_rem, sizeof(buf_rem), fd, trans_proto, false)) OSMO_STRLCPY_ARRAY(buf_rem, "<sockname-error>"); } else { - osmo_ss7_asp_peer_snprintf(buf_loc, sizeof(buf_loc), &asp->cfg.local); - osmo_ss7_asp_peer_snprintf(buf_rem, sizeof(buf_rem), &asp->cfg.remote); + ss7_asp_peer_snprintf(buf_loc, sizeof(buf_loc), &asp->cfg.local); + ss7_asp_peer_snprintf(buf_rem, sizeof(buf_rem), &asp->cfg.remote); }
vty_out(vty, "%-12s %-12s %-13s %-4s %-4s %-9s %-23s %-23s%s", diff --git a/src/osmo_ss7_xua_srv.c b/src/osmo_ss7_xua_srv.c index db1481b..4962bfd 100644 --- a/src/osmo_ss7_xua_srv.c +++ b/src/osmo_ss7_xua_srv.c @@ -148,10 +148,10 @@ asp->cfg.remote.port = atoi(portbuf); asp->dyn_allocated = true; asp->server = srv; - osmo_ss7_asp_peer_set_hosts(&asp->cfg.local, asp, + ss7_asp_peer_set_hosts(&asp->cfg.local, asp, (const char * const*)oxs->cfg.local.host, oxs->cfg.local.host_cnt); - osmo_ss7_asp_peer_set_hosts(&asp->cfg.remote, asp, + ss7_asp_peer_set_hosts(&asp->cfg.remote, asp, &hostbuf_ptr, 1); osmo_ss7_asp_restart(asp); } @@ -279,7 +279,7 @@ uint8_t byte; const char *proto = get_value_string(osmo_ss7_asp_protocol_vals, xs->cfg.proto);
- rc = osmo_ss7_asp_peer_snprintf(buf, sizeof(buf), &xs->cfg.local); + rc = ss7_asp_peer_snprintf(buf, sizeof(buf), &xs->cfg.local); if (rc < 0) { LOGP(DLSS7, LOGL_INFO, "Failed parsing %s Server osmo_ss7_asp_peer\n", proto); } else { @@ -316,7 +316,7 @@ int rc; OSMO_ASSERT(ss7_initialized);
- rc = osmo_ss7_asp_peer_set_hosts(&xs->cfg.local, xs, local_hosts, local_host_cnt); + rc = ss7_asp_peer_set_hosts(&xs->cfg.local, xs, local_hosts, local_host_cnt); if (rc < 0) return rc; return osmo_stream_srv_link_set_addrs(xs->server, (const char **)xs->cfg.local.host, xs->cfg.local.host_cnt); @@ -327,7 +327,7 @@ { int rc;
- rc = osmo_ss7_asp_peer_add_host(&xs->cfg.local, xs, local_host); + rc = ss7_asp_peer_add_host(&xs->cfg.local, xs, local_host); if (rc < 0) return rc; return osmo_stream_srv_link_set_addrs(xs->server, (const char **)xs->cfg.local.host, xs->cfg.local.host_cnt); @@ -338,7 +338,7 @@ { int rc;
- rc = osmo_ss7_asp_peer_del_host(&xs->cfg.local, local_host); + rc = ss7_asp_peer_del_host(&xs->cfg.local, local_host); if (rc < 0) return rc; return osmo_stream_srv_link_set_addrs(xs->server, (const char **)xs->cfg.local.host, xs->cfg.local.host_cnt); diff --git a/src/sccp_user.c b/src/sccp_user.c index 3604883..d364eb5 100644 --- a/src/sccp_user.c +++ b/src/sccp_user.c @@ -645,9 +645,9 @@ /* Ensure that the ASP we use is set to role ASP. */ asp->cfg.role = OSMO_SS7_ASP_ROLE_ASP; if (default_local_ip) - osmo_ss7_asp_peer_set_hosts(&asp->cfg.local, asp, &default_local_ip, 1); + ss7_asp_peer_set_hosts(&asp->cfg.local, asp, &default_local_ip, 1); if (default_remote_ip) - osmo_ss7_asp_peer_set_hosts(&asp->cfg.remote, asp, &default_remote_ip, 1); + ss7_asp_peer_set_hosts(&asp->cfg.remote, asp, &default_remote_ip, 1); /* Make sure proper defaults are applied if app didn't provide specific default values */ ss7_asp_set_default_peer_hosts(asp); asp->simple_client_allocated = true; @@ -853,11 +853,11 @@ oxs = ss7_xua_server_find2(ss7, asp->cfg.trans_proto, prot, local_port); if (!oxs) goto out_asp; - if (osmo_ss7_asp_peer_set_hosts(&asp->cfg.local, asp, + if (ss7_asp_peer_set_hosts(&asp->cfg.local, asp, (const char* const*)oxs->cfg.local.host, oxs->cfg.local.host_cnt) < 0) goto out_asp; - if (osmo_ss7_asp_peer_add_host(&asp->cfg.remote, asp, remote_ip) < 0) + if (ss7_asp_peer_add_host(&asp->cfg.remote, asp, remote_ip) < 0) goto out_asp; asp->cfg.is_server = true; asp->cfg.role = OSMO_SS7_ASP_ROLE_SG; diff --git a/src/ss7_asp.h b/src/ss7_asp.h index 170482a..374cce8 100644 --- a/src/ss7_asp.h +++ b/src/ss7_asp.h @@ -9,6 +9,7 @@
#include <osmocom/sigtran/osmo_ss7.h>
+#include "ss7_asp_peer.h" #include "ss7_internal.h"
/*********************************************************************** diff --git a/src/ss7_asp_peer.h b/src/ss7_asp_peer.h new file mode 100644 index 0000000..bdd9b56 --- /dev/null +++ b/src/ss7_asp_peer.h @@ -0,0 +1,30 @@ +#pragma once + +#include <stdint.h> +#include <stdbool.h> +#include <unistd.h> + +/*********************************************************************** + * SS7 ASP Peer + ***********************************************************************/ + +struct osmo_ss7_asp_peer { + char *host[OSMO_SOCK_MAX_ADDRS]; + size_t host_cnt; + uint16_t port; + /* index in "hosts" array marking the SCTP Primary Address, -1 if no explicit Primary Address set */ + int idx_primary; +}; + +int ss7_asp_peer_snprintf(char *buf, size_t buf_len, struct osmo_ss7_asp_peer *peer); +void ss7_asp_peer_init(struct osmo_ss7_asp_peer *peer); +int ss7_asp_peer_set_hosts(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, + const char *const*hosts, size_t host_cnt); +int ss7_asp_peer_set_hosts2(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, + const char *const*hosts, size_t host_cnt, int idx_primary); +int ss7_asp_peer_add_host(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *host); +int ss7_asp_peer_add_host2(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *host, bool is_primary_addr); +int ss7_asp_peer_del_host(struct osmo_ss7_asp_peer *peer, const char *host); + +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); diff --git a/src/ss7_internal.h b/src/ss7_internal.h index f326896..33d18a6 100644 --- a/src/ss7_internal.h +++ b/src/ss7_internal.h @@ -24,9 +24,6 @@ int ss7_asp_m3ua_tcp_srv_conn_rx_cb(struct osmo_stream_srv *conn, int res, struct msgb *msg); int ss7_asp_xua_srv_conn_closed_cb(struct osmo_stream_srv *srv);
-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); - int xua_tcp_segmentation_cb(struct msgb *msg);
enum ss7_as_ctr {