laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-bts/+/10808 )

Change subject: GSMTAP: make remote host for Um logging configurable via VTY
......................................................................

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 <[email protected]>
---
M include/osmo-bts/bts.h
M src/common/main.c
M src/common/vty.c
3 files changed, 69 insertions(+), 10 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  daniel: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmo-bts/bts.h b/include/osmo-bts/bts.h
index 3adafcc..be0222d 100644
--- a/include/osmo-bts/bts.h
+++ b/include/osmo-bts/bts.h
@@ -346,6 +346,7 @@
        /* 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 38f517c..2503352 100644
--- a/src/common/main.c
+++ b/src/common/main.c
@@ -77,7 +77,6 @@
                "  -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 @@
                        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 @@
                }
        }

-        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 @@

        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 d60a2be..bbd33f8 100644
--- a/src/common/vty.c
+++ b/src/common/vty.c
@@ -315,6 +315,10 @@
                        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 @@
        "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 @@
        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);

--
To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/10808
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: I17676a21c4e0c9cbc88f2c5c53a39c6c6c473ca1
Gerrit-Change-Number: 10808
Gerrit-PatchSet: 4
Gerrit-Owner: neels <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <[email protected]>
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: neels <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-CC: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to