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

Change subject: vty: show cs7 instance asp: Print loc and rem addr retrieved 
from socket
......................................................................

vty: show cs7 instance asp: Print loc and rem addr retrieved from socket

Until now, we were in general printing the list of remote addresses that
were stored in config, because we didn't have an easy way to retrieve
the addresses from the socket. Since recently some libosmocore APIs make
that easy, so use them now.
If the socket is not yet created, then log the addrress list from the config.

Furthermore, take the chance to print now both local and remote
addresses.

Related: SYS#6636
Change-Id: I607e4c2dd37f07bf1c07c88681918184e92202ea
---
M src/osmo_ss7_asp.c
M src/osmo_ss7_vty.c
M src/ss7_internal.h
M tests/vty/ss7_asp_test.vty
4 files changed, 104 insertions(+), 46 deletions(-)

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




diff --git a/src/osmo_ss7_asp.c b/src/osmo_ss7_asp.c
index 55e5a29..f867ce5 100644
--- a/src/osmo_ss7_asp.c
+++ b/src/osmo_ss7_asp.c
@@ -1134,3 +1134,19 @@
 {
        return asp->cfg.proto;
 }
+
+/*! \brief Get the fd of a given ASP
+ *  \param[in] asp The ASP for which the fd is requested
+ *  \returns The fd of the ASP if acailable, negative otherwise
+ */
+int ss7_asp_get_fd(const struct osmo_ss7_asp *asp)
+{
+       if (asp->cfg.is_server) {
+               if (asp->server)
+                       return osmo_stream_srv_get_fd(asp->server);
+       } else {
+               if (asp->client)
+                       return osmo_stream_cli_get_fd(asp->client);
+       }
+       return -1;
+}
diff --git a/src/osmo_ss7_vty.c b/src/osmo_ss7_vty.c
index 39d5b3b..7350c13 100644
--- a/src/osmo_ss7_vty.c
+++ b/src/osmo_ss7_vty.c
@@ -1133,13 +1133,39 @@
        return buf;
 }

+/* Similar to osmo_sock_multiaddr_get_name_buf(), but aimed at listening 
sockets (only local part): */
+static char *get_sockname_buf(char *buf, size_t buf_len, int fd, int proto, 
bool local)
+{
+       char hostbuf[OSMO_SOCK_MAX_ADDRS][INET6_ADDRSTRLEN];
+       size_t num_hostbuf = ARRAY_SIZE(hostbuf);
+       char portbuf[6];
+       struct osmo_strbuf sb = { .buf = buf, .len = buf_len };
+       bool need_more_bufs;
+       int rc;
+
+       rc = osmo_sock_multiaddr_get_ip_and_port(fd, proto, &hostbuf[0][0],
+                                                &num_hostbuf, 
sizeof(hostbuf[0]),
+                                                portbuf, sizeof(portbuf), 
local);
+       if (rc < 0)
+               return NULL;
+
+       need_more_bufs = num_hostbuf > ARRAY_SIZE(hostbuf);
+       if (need_more_bufs)
+               num_hostbuf = ARRAY_SIZE(hostbuf);
+       OSMO_STRBUF_APPEND(sb, osmo_multiaddr_ip_and_port_snprintf,
+                          &hostbuf[0][0], num_hostbuf, sizeof(hostbuf[0]), 
portbuf);
+       if (need_more_bufs)
+               OSMO_STRBUF_PRINTF(sb, "<need-more-bufs!>");
+
+       return buf;
+}
+
 DEFUN(show_cs7_asp, show_cs7_asp_cmd,
        "show cs7 instance <0-15> asp",
        SHOW_STR CS7_STR INST_STR INST_STR "Application Server Process (ASP)\n")
 {
        struct osmo_ss7_instance *inst;
        struct osmo_ss7_asp *asp;
-       char buf[512];
        char as_buf[64];
        int id = atoi(argv[0]);

@@ -1149,28 +1175,32 @@
                return CMD_WARNING;
        }

-       vty_out(vty, "                                                          
        Current Primary Link%s", VTY_NEWLINE);
-       vty_out(vty, "ASP Name      AS Name       State          Type  Role  
SCTP Role  Remote Addresses%s", VTY_NEWLINE);
-       vty_out(vty, "------------  ------------  -------------  ----  ----  
---------  -----------------------%s", VTY_NEWLINE);
+       vty_out(vty, "ASP Name      AS Name       State          Type  Role  
SCTP Role  Local Addresses          Remote Addresses%s", VTY_NEWLINE);
+       vty_out(vty, "------------  ------------  -------------  ----  ----  
---------  -----------------------  -----------------------%s", VTY_NEWLINE);

        llist_for_each_entry(asp, &inst->asp_list, list) {
-               if (asp->cfg.proto == OSMO_SS7_ASP_PROT_IPA && 
asp->cfg.remote.port == 0 && asp->server) {
-                       int fd = osmo_stream_srv_get_fd(asp->server);
-                       char hostbuf[64];
-                       char portbuf[16];
-                       osmo_sock_get_ip_and_port(fd, hostbuf, sizeof(hostbuf),
-                                                 portbuf, sizeof(portbuf), 
false);
-                       snprintf(buf, sizeof(buf), "%s:%s", hostbuf, portbuf);
-               } else
-                       osmo_ss7_asp_peer_snprintf(buf, sizeof(buf), 
&asp->cfg.remote);
-               vty_out(vty, "%-12s  %-12s  %-13s  %-4s  %-4s  %-9s  %-23s%s",
+               char buf_loc[OSMO_SOCK_MULTIADDR_PEER_STR_MAXLEN];
+               char buf_rem[sizeof(buf_loc)];
+               int fd = ss7_asp_get_fd(asp);
+               if (fd > 0) {
+                       int proto = ss7_asp_proto_to_ip_proto(asp->cfg.proto);
+                       if (!get_sockname_buf(buf_loc, sizeof(buf_loc), fd, 
proto, true))
+                               OSMO_STRLCPY_ARRAY(buf_loc, "<sockname-error>");
+                       if (!get_sockname_buf(buf_rem, sizeof(buf_rem), fd, 
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);
+               }
+
+               vty_out(vty, "%-12s  %-12s  %-13s  %-4s  %-4s  %-9s  %-23s  
%-23s%s",
                        asp->cfg.name,
                        as_list_for_asp(asp, as_buf, sizeof(as_buf)),
                        asp->fi? osmo_fsm_inst_state_name(asp->fi) : 
"uninitialized",
                        get_value_string(osmo_ss7_asp_protocol_vals, 
asp->cfg.proto),
                        
osmo_str_tolower(get_value_string(osmo_ss7_asp_role_names, asp->cfg.role)),
                        asp->cfg.is_server ? "server" : "client",
-                       buf,
+                       buf_loc, buf_rem,
                        VTY_NEWLINE);
        }
        return CMD_SUCCESS;
diff --git a/src/ss7_internal.h b/src/ss7_internal.h
index e2d78d8..fd01ca4 100644
--- a/src/ss7_internal.h
+++ b/src/ss7_internal.h
@@ -19,6 +19,7 @@
                                   enum osmo_ss7_asp_protocol proto);
 bool ss7_asp_set_default_peer_hosts(struct osmo_ss7_asp *asp);
 bool ss7_asp_is_started(const struct osmo_ss7_asp *asp);
+int ss7_asp_get_fd(const struct osmo_ss7_asp *asp);
 struct osmo_ss7_asp *ss7_asp_find_by_socket_addr(int fd);

 int ss7_asp_proto_to_ip_proto(enum osmo_ss7_asp_protocol proto);
diff --git a/tests/vty/ss7_asp_test.vty b/tests/vty/ss7_asp_test.vty
index 73a13b5..a767552 100644
--- a/tests/vty/ss7_asp_test.vty
+++ b/tests/vty/ss7_asp_test.vty
@@ -256,27 +256,24 @@
 ss7_asp_vty_test(config-cs7-asp)# remote-ip 127.0.0.200
 ss7_asp_vty_test(config-cs7-asp)# local-ip 127.0.0.100
 ss7_asp_vty_test(config-cs7-asp)# do show cs7 instance 0 asp
-                                                                  Current 
Primary Link
-ASP Name      AS Name       State          Type  Role  SCTP Role  Remote 
Addresses
-------------  ------------  -------------  ----  ----  ---------  
-----------------------
-my-asp        ?             uninitialized  m3ua  sg    server     
127.0.0.200:12345
+ASP Name      AS Name       State          Type  Role  SCTP Role  Local 
Addresses          Remote Addresses
+------------  ------------  -------------  ----  ----  ---------  
-----------------------  -----------------------
+my-asp        ?             uninitialized  m3ua  sg    server     
127.0.0.100:54321        127.0.0.200:12345  
 ss7_asp_vty_test(config-cs7-asp)# remote-ip 127.0.0.201
 ss7_asp_vty_test(config-cs7-asp)# local-ip 127.0.0.101
 ss7_asp_vty_test(config-cs7-asp)# do show cs7 instance 0 asp
-                                                                  Current 
Primary Link
-ASP Name      AS Name       State          Type  Role  SCTP Role  Remote 
Addresses
-------------  ------------  -------------  ----  ----  ---------  
-----------------------
-my-asp        ?             uninitialized  m3ua  sg    server     
(127.0.0.200|127.0.0.201):12345
+ASP Name      AS Name       State          Type  Role  SCTP Role  Local 
Addresses          Remote Addresses
+------------  ------------  -------------  ----  ----  ---------  
-----------------------  -----------------------
+my-asp        ?             uninitialized  m3ua  sg    server     
(127.0.0.100|127.0.0.101):54321  (127.0.0.200|127.0.0.201):12345
 ss7_asp_vty_test(config-cs7-asp)# ! Mark as primary:
 ss7_asp_vty_test(config-cs7-asp)# remote-ip 127.0.0.201 primary
 ss7_asp_vty_test(config-cs7-asp)# ! 'local-ip 127.0.0.101 primary' cannot be 
tested here since output may be different based on sysctl available
 ss7_asp_vty_test(config-cs7-asp)# local-ip 127.0.0.101
 ...
 ss7_asp_vty_test(config-cs7-asp)# do show cs7 instance 0 asp
-                                                                  Current 
Primary Link
-ASP Name      AS Name       State          Type  Role  SCTP Role  Remote 
Addresses
-------------  ------------  -------------  ----  ----  ---------  
-----------------------
-my-asp        ?             uninitialized  m3ua  sg    server     
(127.0.0.200|127.0.0.201*):12345
+ASP Name      AS Name       State          Type  Role  SCTP Role  Local 
Addresses          Remote Addresses
+------------  ------------  -------------  ----  ----  ---------  
-----------------------  -----------------------
+my-asp        ?             uninitialized  m3ua  sg    server     
(127.0.0.100|127.0.0.101):54321  (127.0.0.200|127.0.0.201*):12345
 ss7_asp_vty_test(config-cs7-asp)# show running-config
 ...
   local-ip 127.0.0.100
@@ -289,10 +286,9 @@
 ss7_asp_vty_test(config-cs7-asp)# remote-ip 127.0.0.201
 ss7_asp_vty_test(config-cs7-asp)# local-ip 127.0.0.101
 ss7_asp_vty_test(config-cs7-asp)# do show cs7 instance 0 asp
-                                                                  Current 
Primary Link
-ASP Name      AS Name       State          Type  Role  SCTP Role  Remote 
Addresses
-------------  ------------  -------------  ----  ----  ---------  
-----------------------
-my-asp        ?             uninitialized  m3ua  sg    server     
(127.0.0.200|127.0.0.201):12345
+ASP Name      AS Name       State          Type  Role  SCTP Role  Local 
Addresses          Remote Addresses
+------------  ------------  -------------  ----  ----  ---------  
-----------------------  -----------------------
+my-asp        ?             uninitialized  m3ua  sg    server     
(127.0.0.100|127.0.0.101):54321  (127.0.0.200|127.0.0.201):12345
 ss7_asp_vty_test(config-cs7-asp)# show running-config
 ...
   local-ip 127.0.0.100
@@ -361,26 +357,23 @@
 ss7_asp_vty_test(config-cs7-as)# routing-key 0 3.2.1

 ss7_asp_vty_test(config-cs7-as)# do show cs7 instance 0 asp
-                                                                  Current 
Primary Link
-ASP Name      AS Name       State          Type  Role  SCTP Role  Remote 
Addresses
-------------  ------------  -------------  ----  ----  ---------  
-----------------------
-my-asp        my-ass        ASP_DOWN       m3ua  sg    server     
(127.0.0.200|127.0.0.201):12345
+ASP Name      AS Name       State          Type  Role  SCTP Role  Local 
Addresses          Remote Addresses
+------------  ------------  -------------  ----  ----  ---------  
-----------------------  -----------------------
+my-asp        my-ass        ASP_DOWN       m3ua  sg    server     
(127.0.0.100|127.0.0.101):54321  (127.0.0.200|127.0.0.201):12345

 ss7_asp_vty_test(config-cs7-as)# exit
 ss7_asp_vty_test(config-cs7)# do show cs7 instance 0 asp
-                                                                  Current 
Primary Link
-ASP Name      AS Name       State          Type  Role  SCTP Role  Remote 
Addresses
-------------  ------------  -------------  ----  ----  ---------  
-----------------------
-my-asp        my-ass        ASP_DOWN       m3ua  sg    server     
(127.0.0.200|127.0.0.201):12345
+ASP Name      AS Name       State          Type  Role  SCTP Role  Local 
Addresses          Remote Addresses
+------------  ------------  -------------  ----  ----  ---------  
-----------------------  -----------------------
+my-asp        my-ass        ASP_DOWN       m3ua  sg    server     
(127.0.0.100|127.0.0.101):54321  (127.0.0.200|127.0.0.201):12345

 ss7_asp_vty_test(config-cs7)# exit


 ss7_asp_vty_test(config)# do show cs7 instance 0 asp
-                                                                  Current 
Primary Link
-ASP Name      AS Name       State          Type  Role  SCTP Role  Remote 
Addresses
-------------  ------------  -------------  ----  ----  ---------  
-----------------------
-my-asp        my-ass        ASP_DOWN       m3ua  sg    server     
(127.0.0.200|127.0.0.201):12345
+ASP Name      AS Name       State          Type  Role  SCTP Role  Local 
Addresses          Remote Addresses
+------------  ------------  -------------  ----  ----  ---------  
-----------------------  -----------------------
+my-asp        my-ass        ASP_DOWN       m3ua  sg    server     
(127.0.0.100|127.0.0.101):54321  (127.0.0.200|127.0.0.201):12345

 ss7_asp_vty_test(config)# do show cs7 instance 0 as all
                           Routing    Routing Key                          Cic  
 Cic   Traffic
@@ -423,9 +416,8 @@
 ss7_asp_vty_test(config-cs7)# no asp my-asp

 ss7_asp_vty_test(config-cs7)# do show cs7 instance 0 asp
-                                                                  Current 
Primary Link
-ASP Name      AS Name       State          Type  Role  SCTP Role  Remote 
Addresses
-------------  ------------  -------------  ----  ----  ---------  
-----------------------
+ASP Name      AS Name       State          Type  Role  SCTP Role  Local 
Addresses          Remote Addresses
+------------  ------------  -------------  ----  ----  ---------  
-----------------------  -----------------------

 ss7_asp_vty_test(config-cs7)# do show cs7 instance 0 as all
                           Routing    Routing Key                          Cic  
 Cic   Traffic

--
To view, visit https://gerrit.osmocom.org/c/libosmo-sccp/+/35274?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: I607e4c2dd37f07bf1c07c88681918184e92202ea
Gerrit-Change-Number: 35274
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-CC: fixeria <[email protected]>
Gerrit-MessageType: merged

Reply via email to