aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2023-12-07 19:24:47 +0100
committerPau Espin Pedrol <pespin@sysmocom.de>2023-12-12 16:07:46 +0100
commitc86bdae6f5bef99e9317bceb1d878441c2d1dc0b (patch)
tree2dbb803b99536bc17ad5a8672859d307f180e995
parent483894bfd15c84c9d09ea8a8b8010004aa9f4f36 (diff)
vty: Introduce show cs7 instance asp-remaddr
Depends: libosmocore.git Change-Id I3e1c84526b006baff435bbbca49dc6cf7d201cf5 Depends: libosmo-netif.git Change-Id I78a0bd8279a04f4011c7273e0f542981308e482f Related: SYS#6636 Change-Id: Ie5ac1d0ee74d2b977b1f5319cd88566df7994fd0
-rw-r--r--TODO-RELEASE2
-rw-r--r--src/osmo_ss7_vty.c180
-rw-r--r--tests/vty/ss7_asp_test.vty15
3 files changed, 192 insertions, 5 deletions
diff --git a/TODO-RELEASE b/TODO-RELEASE
index c7771bd..1913dc6 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -10,3 +10,5 @@
libosmocore >1.9.0 osmo_sock_multiaddr_{add,del}_local_addr()
libosmo-netif >1.4.0 osmo_stream_{srv,cli}_get_fd()
libosmocore >1.9.0 osmo_sock_multiaddr_get_ip_and_port(), osmo_multiaddr_ip_and_port_snprintf()
+libosmocore >1.9.0 osmo_sock_sctp_get_peer_addr_info()
+libosmo-netif >1.4.0 osmo_sctp_spinfo_state_str()
diff --git a/src/osmo_ss7_vty.c b/src/osmo_ss7_vty.c
index d6400ee..fe015d9 100644
--- a/src/osmo_ss7_vty.c
+++ b/src/osmo_ss7_vty.c
@@ -47,6 +47,13 @@
#include "sccp_internal.h"
#include "ss7_internal.h"
+#include <netinet/tcp.h>
+
+#ifdef HAVE_LIBSCTP
+#include <netinet/sctp.h>
+#include <osmocom/netif/sctp.h>
+#endif
+
#define XUA_VAR_STR "(sua|m3ua|ipa)"
#define XUA_VAR_HELP_STR \
@@ -54,6 +61,22 @@
"MTP3 User Adaptation\n" \
"IPA Multiplex (SCCP Lite)\n"
+/* netinet/tcp.h */
+static const struct value_string tcp_info_state_values[] = {
+ { TCP_ESTABLISHED, "ESTABLISHED" },
+ { TCP_SYN_SENT, "SYN_SENT" },
+ { TCP_SYN_RECV, "SYN_RECV" },
+ { TCP_FIN_WAIT1, "FIN_WAIT1" },
+ { TCP_FIN_WAIT2, "FIN_WAIT2" },
+ { TCP_TIME_WAIT, "TIME_WAIT" },
+ { TCP_CLOSE, "CLOSE" },
+ { TCP_CLOSE_WAIT, "CLOSE_WAIT" },
+ { TCP_LAST_ACK, "LAST_ACK" },
+ { TCP_LISTEN, "LISTEN" },
+ { TCP_CLOSING, "CLOSING" },
+ {}
+};
+
static const struct value_string asp_quirk_names[] = {
{ OSMO_SS7_ASP_QUIRK_NO_NOTIFY, "no_notify" },
{ OSMO_SS7_ASP_QUIRK_DAUD_IN_ASP, "daud_in_asp" },
@@ -1244,6 +1267,161 @@ DEFUN(show_cs7_asp_name, show_cs7_asp_name_cmd,
return show_asp(vty, id, asp_name);
}
+static void show_one_asp_remaddr_tcp(struct vty *vty, struct osmo_ss7_asp *asp)
+{
+ struct osmo_sockaddr osa = {};
+ struct tcp_info tcpi = {};
+ socklen_t len;
+ int fd, rc;
+
+ fd = ss7_asp_get_fd(asp);
+ if (fd < 0) {
+ vty_out(vty, "%-12s %-46s uninitialized%s", asp->cfg.name, "", VTY_NEWLINE);
+ return;
+ }
+
+ len = sizeof(osa.u.sas);
+ rc = getpeername(fd, &osa.u.sa, &len);
+
+ len = sizeof(tcpi);
+ rc = getsockopt(fd, SOL_TCP, TCP_INFO, &tcpi, &len);
+ if (rc < 0) {
+ char buf_err[128];
+ strerror_r(errno, buf_err, sizeof(buf_err));
+ vty_out(vty, "%-12s %-46s getsockopt(TCP_INFO) failed: %s%s",
+ asp->cfg.name, osmo_sockaddr_to_str(&osa), buf_err, VTY_NEWLINE);
+ return;
+ }
+
+ vty_out(vty, "%-12s %-46s TCP_%-19s %-8u %-8u %-8u %-8u%s",
+ asp->cfg.name,
+ osmo_sockaddr_to_str(&osa),
+ get_value_string(tcp_info_state_values, tcpi.tcpi_state),
+ tcpi.tcpi_snd_cwnd, tcpi.tcpi_rtt,
+ tcpi.tcpi_rto, tcpi.tcpi_pmtu,
+ VTY_NEWLINE);
+}
+
+#ifdef HAVE_LIBSCTP
+static void show_one_asp_remaddr_sctp(struct vty *vty, struct osmo_ss7_asp *asp)
+{
+ struct sctp_paddrinfo pinfo[OSMO_SOCK_MAX_ADDRS];
+ struct osmo_sockaddr osa = {};
+ size_t pinfo_cnt = ARRAY_SIZE(pinfo);
+ bool more_needed;
+ int fd, rc;
+ unsigned int i;
+
+ fd = ss7_asp_get_fd(asp);
+ if (fd < 0) {
+ vty_out(vty, "%-12s %-46s uninitialized%s", asp->cfg.name, "", VTY_NEWLINE);
+ return;
+ }
+
+ rc = osmo_sock_sctp_get_peer_addr_info(fd, &pinfo[0], &pinfo_cnt);
+ if (rc < 0) {
+ char buf_err[128];
+ strerror_r(errno, buf_err, sizeof(buf_err));
+ vty_out(vty, "%-12s %-46s getsockopt(SCTP_GET_PEER_ADDR_INFO) failed: %s%s", asp->cfg.name, "", buf_err, VTY_NEWLINE);
+ return;
+ }
+
+ more_needed = pinfo_cnt > ARRAY_SIZE(pinfo);
+ if (pinfo_cnt > ARRAY_SIZE(pinfo))
+ pinfo_cnt = ARRAY_SIZE(pinfo);
+
+ for (i = 0; i < pinfo_cnt; i++) {
+ osa.u.sas = pinfo[i].spinfo_address;
+ vty_out(vty, "%-12s %-46s SCTP_%-18s %-8u %-8u %-8u %-8u%s",
+ asp->cfg.name,
+ osmo_sockaddr_to_str(&osa),
+ osmo_sctp_spinfo_state_str(pinfo[i].spinfo_state),
+ pinfo[i].spinfo_cwnd, pinfo[i].spinfo_srtt,
+ pinfo[i].spinfo_rto, pinfo[i].spinfo_mtu,
+ VTY_NEWLINE);
+ }
+
+ if (more_needed)
+ vty_out(vty, "%-12s more address buffers needed!%s", asp->cfg.name, VTY_NEWLINE);
+}
+#endif
+
+static void show_one_asp_remaddr(struct vty *vty, struct osmo_ss7_asp *asp)
+{
+ int proto = ss7_asp_proto_to_ip_proto(asp->cfg.proto);
+
+ switch (proto) {
+ case IPPROTO_TCP:
+ show_one_asp_remaddr_tcp(vty, asp);
+ break;
+#ifdef HAVE_LIBSCTP
+ case IPPROTO_SCTP:
+ show_one_asp_remaddr_sctp(vty, asp);
+ break;
+#endif
+ default:
+ vty_out(vty, "%-12s %-46s unknown proto %u%s", asp->cfg.name, "", proto, VTY_NEWLINE);
+ break;
+ }
+}
+
+static int show_asp_remaddr(struct vty *vty, int id, const char *asp_name)
+{
+ struct osmo_ss7_instance *inst;
+ struct osmo_ss7_asp *asp = NULL;
+
+ inst = osmo_ss7_instance_find(id);
+ if (!inst) {
+ vty_out(vty, "No SS7 instance %d found%s", id, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (asp_name) {
+ asp = osmo_ss7_asp_find_by_name(inst, asp_name);
+ if (!asp) {
+ vty_out(vty, "No ASP %s found%s", asp_name, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+
+ vty_out(vty, "ASP Name Remote IP Address & Port State CWND SRTT RTO MTU%s", VTY_NEWLINE);
+ vty_out(vty, "------------ ---------------------------------------------- ----------------------- -------- -------- -------- --------%s", VTY_NEWLINE);
+
+ if (asp) {
+ show_one_asp_remaddr(vty, asp);
+ return CMD_SUCCESS;
+ }
+
+ llist_for_each_entry(asp, &inst->asp_list, list) {
+ show_one_asp_remaddr(vty, asp);
+ }
+ return CMD_SUCCESS;
+}
+
+DEFUN(show_cs7_asp_remaddr, show_cs7_asp_remaddr_cmd,
+ "show cs7 instance <0-15> asp-remaddr",
+ SHOW_STR CS7_STR INST_STR INST_STR
+ "Application Server Process (ASP) remote addresses information\n")
+{
+ int id = atoi(argv[0]);
+
+ return show_asp_remaddr(vty, id, NULL);
+}
+
+
+DEFUN(show_cs7_asp_remaddr_name, show_cs7_asp_remaddr_name_cmd,
+ "show cs7 instance <0-15> asp-remaddr name ASP_NAME",
+ SHOW_STR CS7_STR INST_STR INST_STR
+ "Application Server Process (ASP) remote addresses information\n"
+ "Lookup ASP with a given name\n"
+ "Name of the Application Server Process (ASP)\n")
+{
+ int id = atoi(argv[0]);
+ const char *asp_name = argv[1];
+
+ return show_asp_remaddr(vty, id, asp_name);
+}
+
static void write_one_asp(struct vty *vty, struct osmo_ss7_asp *asp, bool show_dyn_config)
{
int i;
@@ -2520,6 +2698,8 @@ static void vty_init_shared(void *ctx)
install_node(&asp_node, NULL);
install_lib_element_ve(&show_cs7_asp_cmd);
install_lib_element_ve(&show_cs7_asp_name_cmd);
+ install_lib_element_ve(&show_cs7_asp_remaddr_cmd);
+ install_lib_element_ve(&show_cs7_asp_remaddr_name_cmd);
install_lib_element(L_CS7_NODE, &cs7_asp_cmd);
install_lib_element(L_CS7_NODE, &no_cs7_asp_cmd);
install_lib_element(L_CS7_ASP_NODE, &cfg_description_cmd);
diff --git a/tests/vty/ss7_asp_test.vty b/tests/vty/ss7_asp_test.vty
index 35653cb..0c11d61 100644
--- a/tests/vty/ss7_asp_test.vty
+++ b/tests/vty/ss7_asp_test.vty
@@ -5,6 +5,8 @@ ss7_asp_vty_test> list
show cs7 config
show cs7 instance <0-15> asp
show cs7 instance <0-15> asp name ASP_NAME
+ show cs7 instance <0-15> asp-remaddr
+ show cs7 instance <0-15> asp-remaddr name ASP_NAME
show cs7 instance <0-15> as (active|all|m3ua|sua)
show cs7 instance <0-15> route
show cs7 instance <0-15> sccp addressbook
@@ -22,6 +24,8 @@ ss7_asp_vty_test# list
show cs7 config
show cs7 instance <0-15> asp
show cs7 instance <0-15> asp name ASP_NAME
+ show cs7 instance <0-15> asp-remaddr
+ show cs7 instance <0-15> asp-remaddr name ASP_NAME
show cs7 instance <0-15> as (active|all|m3ua|sua)
show cs7 instance <0-15> route
show cs7 instance <0-15> sccp addressbook
@@ -50,11 +54,12 @@ ss7_asp_vty_test# show cs7 instance ?
<0-15> An instance of the SS7 stack
ss7_asp_vty_test# show cs7 instance 0 ?
- users User Table
- asp Application Server Process (ASP)
- as Application Server (AS)
- route Routing Table
- sccp Signalling Connection Control Part
+ users User Table
+ asp Application Server Process (ASP)
+ asp-remaddr Application Server Process (ASP) remote addresses information
+ as Application Server (AS)
+ route Routing Table
+ sccp Signalling Connection Control Part
ss7_asp_vty_test# show cs7 instance 0 as ?
active Display all active ASs