stats: Make net config optional
To support reporters without network configuration, this commit
introduces the have_net_config flag to provide corresponding error
messages.
Sponsored-by: On-Waves ehf
diff --git a/include/osmocom/core/stats.h b/include/osmocom/core/stats.h
index ed461dd..9ee9f10 100644
--- a/include/osmocom/core/stats.h
+++ b/include/osmocom/core/stats.h
@@ -32,6 +32,8 @@
enum stats_reporter_type type;
char *name;
+ unsigned int have_net_config : 1;
+
/* config */
int enabled;
char *name_prefix;
diff --git a/src/stats.c b/src/stats.c
index 8faed89..6189cb3 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -166,6 +166,9 @@
struct sockaddr_in *sock_addr = (struct sockaddr_in *)&srep->dest_addr;
struct in_addr inaddr;
+ if (!srep->have_net_config)
+ return -ENOTSUP;
+
OSMO_ASSERT(addr != NULL);
rc = inet_pton(AF_INET, addr, &inaddr);
@@ -186,6 +189,9 @@
{
struct sockaddr_in *sock_addr = (struct sockaddr_in *)&srep->dest_addr;
+ if (!srep->have_net_config)
+ return -ENOTSUP;
+
srep->dest_port = port;
sock_addr->sin_port = htons(port);
@@ -198,6 +204,9 @@
struct sockaddr_in *sock_addr = (struct sockaddr_in *)&srep->bind_addr;
struct in_addr inaddr;
+ if (!srep->have_net_config)
+ return -ENOTSUP;
+
if (addr) {
rc = inet_pton(AF_INET, addr, &inaddr);
if (rc <= 0)
@@ -218,6 +227,9 @@
int stats_reporter_set_mtu(struct stats_reporter *srep, int mtu)
{
+ if (!srep->have_net_config)
+ return -ENOTSUP;
+
if (mtu < 0)
return -EINVAL;
@@ -296,6 +308,8 @@
struct stats_reporter *srep;
srep = stats_reporter_alloc(STATS_REPORTER_STATSD, name);
+ srep->have_net_config = 1;
+
return srep;
}
diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c
index 0911fbb..18ad283 100644
--- a/src/vty/stats_vty.c
+++ b/src/vty/stats_vty.c
@@ -281,18 +281,21 @@
vty_out(vty, " disable%s", VTY_NEWLINE);
- if (srep->dest_addr_str)
- vty_out(vty, " remote-ip %s%s",
- srep->dest_addr_str, VTY_NEWLINE);
- if (srep->dest_port)
- vty_out(vty, " remote-port %d%s",
- srep->dest_port, VTY_NEWLINE);
- if (srep->bind_addr_str)
- vty_out(vty, " local-ip %s%s",
- srep->bind_addr_str, VTY_NEWLINE);
- if (srep->mtu)
- vty_out(vty, " mtu %d%s",
- srep->mtu, VTY_NEWLINE);
+ if (srep->have_net_config) {
+ if (srep->dest_addr_str)
+ vty_out(vty, " remote-ip %s%s",
+ srep->dest_addr_str, VTY_NEWLINE);
+ if (srep->dest_port)
+ vty_out(vty, " remote-port %d%s",
+ srep->dest_port, VTY_NEWLINE);
+ if (srep->bind_addr_str)
+ vty_out(vty, " local-ip %s%s",
+ srep->bind_addr_str, VTY_NEWLINE);
+ if (srep->mtu)
+ vty_out(vty, " mtu %d%s",
+ srep->mtu, VTY_NEWLINE);
+ }
+
if (srep->name_prefix && *srep->name_prefix)
vty_out(vty, " prefix %s%s",
srep->name_prefix, VTY_NEWLINE);