ss7_vty: Print actual connected port number in case of IPA server

In IPA, unlike M3UA/SUA, we often have clients connecting from
random/unknown ports. In such cases, the configured remote port is '0'.

Let's use getsockname to determine the actual source ip/port of the
connected client (if any) during "show ... asp"

Change-Id: I1327a46d0b74c572d2ad828a958090af53b9fa37
Closes: SYS#5429
This commit is contained in:
Harald Welte 2021-04-30 12:17:17 +02:00
parent 03e3b04234
commit 888d062068
1 changed files with 11 additions and 1 deletions

View File

@ -37,6 +37,8 @@
#include <osmocom/vty/telnet_interface.h>
#include <osmocom/vty/misc.h>
#include <osmocom/netif/stream.h>
#include <osmocom/sigtran/osmo_ss7.h>
#include <osmocom/sigtran/protocol/mtp.h>
@ -765,7 +767,15 @@ DEFUN(show_cs7_asp, show_cs7_asp_cmd,
vty_out(vty, "------------ ------------ ------------- ---- ----------------------- ----------%s", VTY_NEWLINE);
llist_for_each_entry(asp, &inst->asp_list, list) {
osmo_ss7_asp_peer_snprintf(buf, sizeof(buf), &asp->cfg.remote);
if (asp->cfg.proto == OSMO_SS7_ASP_PROT_IPA && asp->cfg.remote.port == 0 && asp->server) {
struct osmo_fd *ofd = osmo_stream_srv_get_ofd(asp->server);
char hostbuf[64];
char portbuf[16];
osmo_sock_get_ip_and_port(ofd->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 %-14s %-10s%s",
asp->cfg.name, "?",
asp->fi? osmo_fsm_inst_state_name(asp->fi) : "uninitialized",