aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2018-09-06 15:21:19 +0200
committerlaforge <laforge@osmocom.org>2021-02-16 17:35:47 +0000
commitf8f806ff2a30c91b521d45cc373551d65ccd59f6 (patch)
tree99aa2c892b35fd5f340c40e96f5f730a67a626e4
parentdb403a4e3ef1cb809079faf3d9aa8c805c5ce874 (diff)
GSMTAP: make remote host for Um logging configurable via VTY
So far, the only way to configure GSMTAP Um logging is to use the cmdline argument '-i'. Let's deprecate it, and add a VTY command to allow setting the remote host from configuration file. The legacy '-i' option, if provided, overrides the configuration file option, and will also appear in 'write file'. Change-Id: I17676a21c4e0c9cbc88f2c5c53a39c6c6c473ca1 Tweaked by: Vadim Yanitskiy <vyanitskiy@sysmocom.de>
-rw-r--r--include/osmo-bts/bts.h1
-rw-r--r--src/common/main.c38
-rw-r--r--src/common/vty.c40
3 files changed, 69 insertions, 10 deletions
diff --git a/include/osmo-bts/bts.h b/include/osmo-bts/bts.h
index 3adafcc0..be0222d2 100644
--- a/include/osmo-bts/bts.h
+++ b/include/osmo-bts/bts.h
@@ -346,6 +346,7 @@ struct gsm_bts {
/* GSMTAP Um logging (disabled by default) */
struct {
struct gsmtap_inst *inst;
+ char *remote_host;
uint32_t sapi_mask;
uint8_t sapi_acch;
} gsmtap;
diff --git a/src/common/main.c b/src/common/main.c
index 38f517c2..25033525 100644
--- a/src/common/main.c
+++ b/src/common/main.c
@@ -77,7 +77,6 @@ static void print_help()
" -T --timestamp Prefix every log line with a timestamp\n"
" -V --version Print version information and exit\n"
" -e --log-level Set a global log-level\n"
- " -i --gsmtap-ip The destination IP used for GSMTAP.\n"
"\nVTY reference generation:\n"
" --vty-ref-mode MODE VTY reference generation mode (e.g. 'expert').\n"
" --vty-ref-xml Generate the VTY reference XML output and exit.\n"
@@ -186,6 +185,8 @@ static void handle_options(int argc, char **argv)
break;
case 'i':
gsmtap_ip = optarg;
+ fprintf(stderr, "Command line argument '-i' is deprecated, use VTY "
+ "parameter 'gsmtap-remote-host %s' instead.\n", gsmtap_ip);
break;
case 't':
fprintf(stderr, "Command line argument '-t' is deprecated and does nothing, "
@@ -320,15 +321,6 @@ int bts_main(int argc, char **argv)
}
}
- if (gsmtap_ip) {
- g_bts->gsmtap.inst = gsmtap_source_init(gsmtap_ip, GSMTAP_UDP_PORT, 1);
- if (g_bts->gsmtap.inst == NULL) {
- fprintf(stderr, "Failed during gsmtap_init()\n");
- exit(1);
- }
- gsmtap_source_add_sink(g_bts->gsmtap.inst);
- }
-
if (bts_init(g_bts) < 0) {
fprintf(stderr, "unable to open bts\n");
exit(1);
@@ -358,6 +350,32 @@ int bts_main(int argc, char **argv)
write_pid_file("osmo-bts");
+ /* Accept a GSMTAP host from VTY config, but a commandline option overrides that. */
+ if (gsmtap_ip != NULL) {
+ if (g_bts->gsmtap.remote_host != NULL) {
+ LOGP(DLGLOBAL, LOGL_NOTICE,
+ "Command line argument '-i %s' overrides "
+ "'gsmtap-remote-host %s' from the config file\n",
+ gsmtap_ip, g_bts->gsmtap.remote_host);
+ talloc_free(g_bts->gsmtap.remote_host);
+ }
+ g_bts->gsmtap.remote_host = talloc_strdup(g_bts, gsmtap_ip);
+ }
+
+ /* TODO: move this to gsm_bts_alloc() */
+ if (g_bts->gsmtap.remote_host != NULL) {
+ LOGP(DLGLOBAL, LOGL_NOTICE,
+ "Setting up GSMTAP Um forwarding to '%s:%u'\n",
+ g_bts->gsmtap.remote_host, GSMTAP_UDP_PORT);
+ g_bts->gsmtap.inst = gsmtap_source_init(g_bts->gsmtap.remote_host,
+ GSMTAP_UDP_PORT, 1);
+ if (g_bts->gsmtap.inst == NULL) {
+ fprintf(stderr, "Failed during gsmtap_source_init()\n");
+ exit(1);
+ }
+ gsmtap_source_add_sink(g_bts->gsmtap.inst);
+ }
+
bts_controlif_setup(g_bts, ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_BTS);
rc = telnet_init_dynif(tall_bts_ctx, NULL, vty_get_bind_addr(),
diff --git a/src/common/vty.c b/src/common/vty.c
index d60a2be9..bbd33f85 100644
--- a/src/common/vty.c
+++ b/src/common/vty.c
@@ -315,6 +315,10 @@ static void config_write_bts_single(struct vty *vty, const struct gsm_bts *bts)
bts->agch_queue.thresh_level, bts->agch_queue.low_level,
bts->agch_queue.high_level, VTY_NEWLINE);
+ if (bts->gsmtap.remote_host != NULL)
+ vty_out(vty, " gsmtap-remote-host %s%s",
+ bts->gsmtap.remote_host,
+ VTY_NEWLINE);
for (i = 0; i < sizeof(uint32_t) * 8; i++) {
if (bts->gsmtap.sapi_mask & ((uint32_t) 1 << i)) {
sapi_buf = get_value_string_or_null(gsmtap_sapi_names, i);
@@ -1826,6 +1830,40 @@ static struct gsm_lchan *resolve_lchan(const struct gsm_network *net,
"logical channel commands\n" \
"logical channel number\n"
+DEFUN(cfg_bts_gsmtap_remote_host,
+ cfg_bts_gsmtap_remote_host_cmd,
+ "gsmtap-remote-host [HOSTNAME]",
+ "Enable GSMTAP Um logging (see also 'gsmtap-sapi')\n"
+ "Remote IP address or hostname ('localhost' if omitted)\n")
+{
+ struct gsm_bts *bts = vty->index;
+
+ osmo_talloc_replace_string(bts, &bts->gsmtap.remote_host,
+ argc > 0 ? argv[0] : "localhost");
+
+ if (vty->type != VTY_FILE)
+ vty_out(vty, "%% This command requires restart%s", VTY_NEWLINE);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_bts_no_gsmtap_remote_host,
+ cfg_bts_no_gsmtap_remote_host_cmd,
+ "no gsmtap-remote-host",
+ NO_STR "Disable GSMTAP Um logging\n")
+{
+ struct gsm_bts *bts = vty->index;
+
+ if (bts->gsmtap.remote_host != NULL)
+ talloc_free(bts->gsmtap.remote_host);
+ bts->gsmtap.remote_host = NULL;
+
+ if (vty->type != VTY_FILE)
+ vty_out(vty, "%% This command requires restart%s", VTY_NEWLINE);
+
+ return CMD_SUCCESS;
+}
+
DEFUN(cfg_bts_gsmtap_sapi_all, cfg_bts_gsmtap_sapi_all_cmd,
"gsmtap-sapi (enable-all|disable-all)",
"Enable/disable sending of UL/DL messages over GSMTAP\n"
@@ -2237,6 +2275,8 @@ int bts_vty_init(void *ctx)
install_element(BTS_NODE, &cfg_bts_smscb_tgt_qlen_cmd);
install_element(BTS_NODE, &cfg_bts_smscb_qhyst_cmd);
+ install_element(BTS_NODE, &cfg_bts_gsmtap_remote_host_cmd);
+ install_element(BTS_NODE, &cfg_bts_no_gsmtap_remote_host_cmd);
install_element(BTS_NODE, &cfg_bts_gsmtap_sapi_all_cmd);
install_element(BTS_NODE, &cfg_bts_gsmtap_sapi_cmd);
install_element(BTS_NODE, &cfg_bts_no_gsmtap_sapi_cmd);