This may seem like overkill for a mere const char * config item, but it makes
the Control interface VTY commands reusable in any main() scope (inspired by
libosmo-abis' VTY config).
Add API functions ctrl_vty_init() and ctrl_vty_get_bind_addr(), in new files
src/ctrl/control_vty.c and include/osmocom/ctrl/control_vty.h, compiled and/or
installed dependent on ENABLE_VTY.
Using these functions allows configuring a static const char* with the VTY
commands
ctrl
bind A.B.C.D
which callers shall subsequently use to bind the Control interface to a
specific local interface address, by passing the return value of
ctrl_vty_get_bind_addr() to control_interface_setup().
Add CTRL_NODE to enum node_type, "eating" RESERVED4_NODE to heed that comment
on avoiding ABI changes.
---
include/Makefile.am | 3 +-
include/osmocom/ctrl/control_vty.h | 9 ++++
include/osmocom/vty/command.h | 3 +-
src/ctrl/Makefile.am | 4 ++
src/ctrl/control_vty.c | 90 ++++++++++++++++++++++++++++++++++++++
5 files changed, 107 insertions(+), 2 deletions(-)
create mode 100644 include/osmocom/ctrl/control_vty.h
create mode 100644 src/ctrl/control_vty.c
diff --git a/include/Makefile.am b/include/Makefile.am
index a965fb9..ac22ee6 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -117,7 +117,8 @@ nobase_include_HEADERS += \
osmocom/vty/telnet_interface.h \
osmocom/vty/vector.h \
osmocom/vty/vty.h \
- osmocom/vty/ports.h
+ osmocom/vty/ports.h \
+ osmocom/ctrl/control_vty.h
endif
noinst_HEADERS = \
diff --git a/include/osmocom/ctrl/control_vty.h b/include/osmocom/ctrl/control_vty.h
new file mode 100644
index 0000000..d0ef69f
--- /dev/null
+++ b/include/osmocom/ctrl/control_vty.h
@@ -0,0 +1,9 @@
+#pragma once
+
+/* Add the 'ctrl' section to VTY, containing the 'bind' command. */
+int ctrl_vty_init(void *ctx);
+
+/* Obtain the IP address configured by the 'ctrl'/'bind A.B.C.D' VTY command.
+ * This should be fed to ctrl_interface_setup() once the configuration has been
+ * read. */
+const char *ctrl_vty_get_bind_addr(void);
diff --git a/include/osmocom/vty/command.h b/include/osmocom/vty/command.h
index 2078e1b..937d2f8 100644
--- a/include/osmocom/vty/command.h
+++ b/include/osmocom/vty/command.h
@@ -84,6 +84,8 @@ enum node_type {
L_NS_NODE, /*!< \brief NS node in libosmo-gb. */
L_BSSGP_NODE, /*!< \brief BSSGP node in libosmo-gb. */
+ CTRL_NODE, /*!< \brief Control interface node. */
+
/*
* When adding new nodes to the libosmocore project, these nodes can be
* used to avoid ABI changes for unrelated projects.
@@ -91,7 +93,6 @@ enum node_type {
RESERVED1_NODE, /*!< \brief Reserved for later extensions */
RESERVED2_NODE, /*!< \brief Reserved for later extensions */
RESERVED3_NODE, /*!< \brief Reserved for later extensions */
- RESERVED4_NODE, /*!< \brief Reserved for later extensions */
_LAST_OSMOVTY_NODE
};
diff --git a/src/ctrl/Makefile.am b/src/ctrl/Makefile.am
index e6ccafb..b4a3da4 100644
--- a/src/ctrl/Makefile.am
+++ b/src/ctrl/Makefile.am
@@ -13,3 +13,7 @@ libosmoctrl_la_LIBADD = \
$(top_builddir)/src/libosmocore.la \
$(top_builddir)/src/gsm/libosmogsm.la \
$(top_builddir)/src/vty/libosmovty.la
+
+if ENABLE_VTY
+libosmoctrl_la_SOURCES += control_vty.c
+endif
diff --git a/src/ctrl/control_vty.c b/src/ctrl/control_vty.c
new file mode 100644
index 0000000..7df53b8
--- /dev/null
+++ b/src/ctrl/control_vty.c
@@ -0,0 +1,90 @@
+/* VTY configuration for Control interface
+ *
+ * (C) 2016 by sysmocom s.m.f.c GmbH <info(a)sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <stdlib.h>
+#include <talloc.h>
+#include <osmocom/ctrl/control_vty.h>
+#include <osmocom/vty/command.h>
+
+static void *ctrl_vty_ctx = NULL;
+static const char *ctrl_vty_bind_addr = NULL;
+
+DEFUN(cfg_ctrl_bind_addr,
+ cfg_ctrl_bind_addr_cmd,
+ "bind A.B.C.D",
+ "Set bind address to listen for Control connections\n"
+ "Local IP address (default 127.0.0.1)\n")
+{
+ if (ctrl_vty_bind_addr) {
+ talloc_free((void*)ctrl_vty_bind_addr);
+ ctrl_vty_bind_addr = NULL;
+ }
+ ctrl_vty_bind_addr = talloc_strdup(ctrl_vty_ctx, argv[0]);
+ return CMD_SUCCESS;
+}
+
+const char *ctrl_vty_get_bind_addr(void)
+{
+ if (!ctrl_vty_bind_addr)
+ return "127.0.0.1";
+ return ctrl_vty_bind_addr;
+}
+
+struct cmd_node ctrl_node = {
+ CTRL_NODE,
+ "%s(config-ctrl)# ",
+ 1,
+};
+
+DEFUN(cfg_ctrl,
+ cfg_ctrl_cmd,
+ "ctrl", "Configure the Control Interface")
+{
+ vty->index = NULL;
+ vty->node = CTRL_NODE;
+
+ return CMD_SUCCESS;
+}
+
+static int config_write_ctrl(struct vty *vty)
+{
+ /* So far there's only one element. Omit the entire section if the bind
+ * element is omitted. */
+ if (!ctrl_vty_bind_addr)
+ return CMD_SUCCESS;
+
+ vty_out(vty, "ctrl%s", VTY_NEWLINE);
+ vty_out(vty, " bind %s%s", ctrl_vty_bind_addr, VTY_NEWLINE);
+
+ return CMD_SUCCESS;
+}
+
+int ctrl_vty_init(void *ctx)
+{
+ ctrl_vty_ctx = ctx;
+ install_element(CONFIG_NODE, &cfg_ctrl_cmd);
+ install_node(&ctrl_node, config_write_ctrl);
+
+ install_element(CTRL_NODE, &cfg_ctrl_bind_addr_cmd);
+ return 0;
+}
+
--
2.1.4
These patches eradicate some of the easier-to-fix compiler warnings I keep
seeing in almost every dev cycle. I'd be glad to have them on master.
One of them is an actual error, ignoring return values.
Neels Hofmeyr (3):
bsc_nat: fail if VTY telnet port cannot be bound, clarify comment
ipaccess_rcvmsg: fix returncode, add partial write warning
gsm340_rx_tpdu: comment-out two unused vars
openbsc/src/ipaccess/ipaccess-proxy.c | 8 +++++++-
openbsc/src/libmsc/gsm_04_11.c | 7 +++++--
openbsc/src/osmo-bsc_nat/bsc_nat.c | 7 +++++--
3 files changed, 17 insertions(+), 5 deletions(-)
--
2.1.4
This time SMPP is included. Here is the abridged complete overview:
Following the previous patch sets for libosmo-abis and libosmocore, this patch
set allows configuring ALL of osmo-nitb's local IP addresses and makes it
possible to run several osmo-nitb processes alongside each other.
(1) Abis/IP (from the libosmo-abis patch)
In the config file, have:
e1_input
ipa bind 10.9.8.7
(2) telnet VTY (prepared by libosmocore patch set)
In the config file, have:
line vty
bind 10.9.8.7
(3) ctrl interface (prepared by libosmocore patch set)
In the config file, have:
ctrl
bind 10.9.8.7
(4) MNCC socket
In addition to the old -m option with a fixed socket path, you may now
supply a cmdline argument with explicit path:
-M /path/to/socket/file
(5) SMPP SMSC
In the config file, have:
smpp
local-tcp 10.9.8.7 2775
Neels Hofmeyr (6):
enable telnet VTY bind address config for various programs
osmo-nitb: add -M to pass specific MNCC socket path
osmo-nitb: cosmetic: rename to rf_ctrl_path, following mncc_sock_path
osmo-nitb: be strict about cmdline args
enable ctrl bind config for various programs
smpp: refactor initialization, add bind address
openbsc/include/openbsc/bsc_nat.h | 3 +-
openbsc/include/openbsc/ctrl.h | 3 +-
openbsc/include/openbsc/gprs_sgsn.h | 3 +-
openbsc/include/openbsc/mncc.h | 2 +-
openbsc/include/openbsc/smpp.h | 4 +-
openbsc/src/gprs/gb_proxy_main.c | 12 +++--
openbsc/src/gprs/gtphub_main.c | 11 ++--
openbsc/src/gprs/sgsn_ctrl.c | 5 +-
openbsc/src/gprs/sgsn_main.c | 42 ++++++++++-----
openbsc/src/libbsc/bsc_ctrl_lookup.c | 6 ++-
openbsc/src/libbsc/bsc_init.c | 6 ++-
openbsc/src/libmsc/mncc_sock.c | 9 ++--
openbsc/src/libmsc/smpp_openbsc.c | 43 +++++++++------
openbsc/src/libmsc/smpp_smsc.c | 93 ++++++++++++++++++++++++---------
openbsc/src/libmsc/smpp_smsc.h | 7 ++-
openbsc/src/libmsc/smpp_vty.c | 75 +++++++++++++++++++++-----
openbsc/src/osmo-bsc/osmo_bsc_main.c | 10 +++-
openbsc/src/osmo-bsc_mgcp/mgcp_main.c | 6 ++-
openbsc/src/osmo-bsc_nat/bsc_nat.c | 22 ++++++--
openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c | 5 +-
openbsc/src/osmo-nitb/bsc_hack.c | 43 ++++++++++-----
21 files changed, 298 insertions(+), 112 deletions(-)
--
2.1.4
Following the previous patch sets for libosmo-abis and libosmocore, this patch
set allows configuring almost all of the osmo-nitb IP addresses. The goal is to
allow several osmo-nitb processes to run alongside each other.
(1) Abis/IP (from the libosmo-abis patch)
in the config file, have:
e1_input
ipa bind 10.9.8.7
(2) telnet VTY (prepared by libosmocore patch set)
in the config file, have:
line vty
bind 127.0.0.99
(3) ctrl interface (prepared by libosmocore patch set)
in the config file, have:
ctrl
bind 127.0.0.99
(4) MNCC socket
In addition to the old -m option with a fixed socket path, you may now
supply a cmdline argument with explicit path:
-M /path/to/socket/file
(5) still TODO: SMPP SMSC
libsmpp34 is still listening on 0.0.0.0:2775, requires a change in libsmpp34.
Will follow in a subsequent patch.
Neels Hofmeyr (6):
enable telnet VTY bind address config for various programs
osmo-nitb: add -M to pass specific MNCC socket path
osmo-nitb: cosmetic: rename to rf_ctrl_path, following mncc_sock_path
osmo-nitb: be strict about cmdline args
enable ctrl bind config for various programs
bsc_nat: fail if VTY telnet port cannot be bound
openbsc/include/openbsc/bsc_nat.h | 3 ++-
openbsc/include/openbsc/ctrl.h | 3 ++-
openbsc/include/openbsc/gprs_sgsn.h | 3 ++-
openbsc/include/openbsc/mncc.h | 2 +-
openbsc/src/gprs/gb_proxy_main.c | 12 ++++++----
openbsc/src/gprs/gtphub_main.c | 11 ++++++---
openbsc/src/gprs/sgsn_ctrl.c | 5 ++--
openbsc/src/gprs/sgsn_main.c | 42 ++++++++++++++++++++++-----------
openbsc/src/libbsc/bsc_ctrl_lookup.c | 6 +++--
openbsc/src/libbsc/bsc_init.c | 6 ++++-
openbsc/src/libmsc/mncc_sock.c | 9 +++----
openbsc/src/osmo-bsc/osmo_bsc_main.c | 10 +++++++-
openbsc/src/osmo-bsc_mgcp/mgcp_main.c | 6 ++++-
openbsc/src/osmo-bsc_nat/bsc_nat.c | 21 ++++++++++++++---
openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c | 5 ++--
openbsc/src/osmo-nitb/bsc_hack.c | 39 ++++++++++++++++++++----------
16 files changed, 130 insertions(+), 53 deletions(-)
--
2.1.4
FYI, Rusty's CCAN contains some interesting option parsing code released
under GPLv2+, i.e. compatible to libosmocore:
Usage is explained in
https://github.com/rustyrussell/ccan/blob/master/ccan/opt/_info
It seems rather small and simple, and permits the subsequent addition of
options, i.e. some shared code can register options, and other parts of
the code can register even more options to it (like our libraries, or
bts-specific code in osmo-bts, ...)
I have more pressing things on my todo list than convert this now, but
as there was some discussion regarding gengetopt here recently, I
thought I might point out an alternative.
We might also look into the LGPL 2.1+ CCAN htable
https://github.com/rustyrussell/ccan/blob/master/ccan/htable/_info
as a possible replacement for those areas where our linear llist
iterations should turn out to be problematic.
Regards,
Harald
--
- Harald Welte <laforge(a)gnumonks.org> http://laforge.gnumonks.org/
============================================================================
"Privacy in residential applications is a desirable marketing option."
(ETSI EN 300 175-7 Ch. A6)