pespin has submitted this change. (
https://gerrit.osmocom.org/c/libosmo-netif/+/35287?usp=email )
Change subject: stream_srv_link: osmo_stream_srv_link_get_sockname() now returns the full
set of addresses
......................................................................
stream_srv_link: osmo_stream_srv_link_get_sockname() now returns the full set of
addresses
As a result, internal stream_srv_link logging will also show the whole
set of listening addresses. This is mostly fine since it mainly happens
only once, during connection accept(), and this way it provides full
view of where from and where to the client connected.
Depends: libosmocore.git Change-Id I18a0e1a652a3e8ef3e97154355eb1d07a14ef0bd
Related: SYS#5581
Change-Id: I216502a9aeafe638940f110bc9fddf2504b2ac3a
---
M src/stream_srv.c
1 file changed, 48 insertions(+), 12 deletions(-)
Approvals:
pespin: Looks good to me, approved
Jenkins Builder: Verified
fixeria: Looks good to me, but someone else must approve
diff --git a/src/stream_srv.c b/src/stream_srv.c
index 0dca10a..dbf8aed 100644
--- a/src/stream_srv.c
+++ b/src/stream_srv.c
@@ -85,7 +85,7 @@
struct osmo_stream_srv_link {
struct osmo_fd ofd;
char *name;
- char sockname[OSMO_SOCK_NAME_MAXLEN];
+ char sockname[OSMO_SOCK_MULTIADDR_PEER_STR_MAXLEN];
char *addr[OSMO_STREAM_MAX_ADDRS];
uint8_t addrcnt;
uint16_t port;
@@ -338,22 +338,42 @@
return link->data;
}
+/* Similar to osmo_sock_multiaddr_get_name_buf(), but aimed at listening sockets (only
local part): */
+static char *get_local_sockname_buf(char *buf, size_t buf_len, int fd, int proto)
+{
+ char hostbuf[OSMO_STREAM_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), true);
+ 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;
+}
+
/*! \brief Get description of the stream server link e. g. 127.0.0.1:1234
* \param[in] link Stream Server Link to examine
* \returns Link description or NULL in case of error */
char *osmo_stream_srv_link_get_sockname(const struct osmo_stream_srv_link *link)
{
- static char buf[INET6_ADDRSTRLEN + 6];
- int rc = osmo_sock_get_local_ip(link->ofd.fd, buf, INET6_ADDRSTRLEN);
- if (rc < 0)
+ static char buf[sizeof(link->sockname)];
+
+ if (!get_local_sockname_buf(buf, sizeof(buf), link->ofd.fd, link->proto))
return NULL;
-
- buf[strnlen(buf, INET6_ADDRSTRLEN + 6)] = ':';
-
- rc = osmo_sock_get_local_ip_port(link->ofd.fd, buf + strnlen(buf, INET6_ADDRSTRLEN +
6), 6);
- if (rc < 0)
- return NULL;
-
return buf;
}
@@ -443,7 +463,7 @@
return -EIO;
}
- OSMO_STRLCPY_ARRAY(link->sockname, osmo_stream_srv_link_get_sockname(link));
+ get_local_sockname_buf(link->sockname, sizeof(link->sockname), link->ofd.fd,
link->proto);
return 0;
}
--
To view, visit
https://gerrit.osmocom.org/c/libosmo-netif/+/35287?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I216502a9aeafe638940f110bc9fddf2504b2ac3a
Gerrit-Change-Number: 35287
Gerrit-PatchSet: 4
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged