diff mbox

[5/6] enable ctrl bind config for various programs

Message ID 1456343319-572-6-git-send-email-nhofmeyr@sysmocom.de
State Accepted
Headers show

Commit Message

Neels Hofmeyr Feb. 24, 2016, 7:48 p.m. UTC
Add ctrl_vty_init() calls and feed the ctrl_vty_get_bind_addr() return value to
ctrl_interface_setup() in the following programs:

  osmo-bsc
  osmo-bsc_nat
  osmo-nitb
  osmo-sgsn

For osmo-sgsn, move the control interface setup invocation below the config
parsing, so that the ctrl_vty_get_bind_addr() can return the configured
address.
---
 openbsc/include/openbsc/bsc_nat.h       |  3 ++-
 openbsc/include/openbsc/ctrl.h          |  3 ++-
 openbsc/include/openbsc/gprs_sgsn.h     |  3 ++-
 openbsc/src/gprs/sgsn_ctrl.c            |  5 +++--
 openbsc/src/gprs/sgsn_main.c            | 31 ++++++++++++++++++++-----------
 openbsc/src/libbsc/bsc_ctrl_lookup.c    |  6 ++++--
 openbsc/src/osmo-bsc/osmo_bsc_main.c    | 10 +++++++++-
 openbsc/src/osmo-bsc_nat/bsc_nat.c      |  9 ++++++++-
 openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c |  5 +++--
 openbsc/src/osmo-nitb/bsc_hack.c        | 10 +++++++++-
 10 files changed, 62 insertions(+), 23 deletions(-)
diff mbox

Patch

diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h
index 027b6de..309adb1 100644
--- a/openbsc/include/openbsc/bsc_nat.h
+++ b/openbsc/include/openbsc/bsc_nat.h
@@ -423,7 +423,8 @@  void bsc_nat_num_rewr_entry_adapt(void *ctx, struct llist_head *head, const stru
 void bsc_nat_send_mgcp_to_msc(struct bsc_nat *bsc_nat, struct msgb *msg);
 void bsc_nat_handle_mgcp(struct bsc_nat *bsc, struct msgb *msg);
 
-struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat, int port);
+struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat,
+					    const char *bind_addr, int port);
 void bsc_nat_ctrl_del_pending(struct bsc_cmd_list *pending);
 int bsc_nat_handle_ctrlif_msg(struct bsc_connection *bsc, struct msgb *msg);
 
diff --git a/openbsc/include/openbsc/ctrl.h b/openbsc/include/openbsc/ctrl.h
index 38fa054..c5ac210 100644
--- a/openbsc/include/openbsc/ctrl.h
+++ b/openbsc/include/openbsc/ctrl.h
@@ -1,3 +1,4 @@ 
 #pragma once
 
-struct ctrl_handle *bsc_controlif_setup(struct gsm_network *net, uint16_t port);
+struct ctrl_handle *bsc_controlif_setup(struct gsm_network *net,
+					const char *bind_addr, uint16_t port);
diff --git a/openbsc/include/openbsc/gprs_sgsn.h b/openbsc/include/openbsc/gprs_sgsn.h
index 74f0735..49d5407 100644
--- a/openbsc/include/openbsc/gprs_sgsn.h
+++ b/openbsc/include/openbsc/gprs_sgsn.h
@@ -315,7 +315,8 @@  int sgsn_force_reattach_oldmsg(struct msgb *oldmsg);
  * ctrl interface related work
  */
 struct gsm_network;
-struct ctrl_handle *sgsn_controlif_setup(struct gsm_network *, uint16_t port);
+struct ctrl_handle *sgsn_controlif_setup(struct gsm_network *,
+					 const char *bind_addr, uint16_t port);
 int sgsn_ctrl_cmds_install(void);
 
 /*
diff --git a/openbsc/src/gprs/sgsn_ctrl.c b/openbsc/src/gprs/sgsn_ctrl.c
index eff94e0..ccf5076 100644
--- a/openbsc/src/gprs/sgsn_ctrl.c
+++ b/openbsc/src/gprs/sgsn_ctrl.c
@@ -73,7 +73,8 @@  int sgsn_ctrl_cmds_install(void)
 	return rc;
 }
 
-struct ctrl_handle *sgsn_controlif_setup(struct gsm_network *net, uint16_t port)
+struct ctrl_handle *sgsn_controlif_setup(struct gsm_network *net,
+					 const char *bind_addr, uint16_t port)
 {
-	return ctrl_interface_setup(net, port, NULL);
+	return ctrl_interface_setup_dynip(net, bind_addr, port, NULL);
 }
diff --git a/openbsc/src/gprs/sgsn_main.c b/openbsc/src/gprs/sgsn_main.c
index b10b0b3..cb762b7 100644
--- a/openbsc/src/gprs/sgsn_main.c
+++ b/openbsc/src/gprs/sgsn_main.c
@@ -47,6 +47,8 @@ 
 #include <osmocom/vty/stats.h>
 #include <osmocom/vty/ports.h>
 
+#include <osmocom/ctrl/control_vty.h>
+
 #include <openbsc/signal.h>
 #include <openbsc/debug.h>
 #include <openbsc/vty.h>
@@ -311,22 +313,12 @@  int main(int argc, char **argv)
 	logging_vty_add_cmds(&gprs_log_info);
 	osmo_stats_vty_add_cmds(&gprs_log_info);
 	sgsn_vty_init();
+	ctrl_vty_init(tall_bsc_ctx);
 
 	handle_options(argc, argv);
 
 	rate_ctr_init(tall_bsc_ctx);
 
-	ctrl = sgsn_controlif_setup(NULL, OSMO_CTRL_PORT_SGSN);
-	if (!ctrl) {
-		LOGP(DGPRS, LOGL_ERROR, "Failed to create CTRL interface.\n");
-		exit(1);
-	}
-
-	if (sgsn_ctrl_cmds_install() != 0) {
-		LOGP(DGPRS, LOGL_ERROR, "Failed to install CTRL commands.\n");
-		exit(1);
-	}
-
 	gprs_ns_set_log_ss(DNS);
 	bssgp_set_log_ss(DBSSGP);
 
@@ -362,6 +354,23 @@  int main(int argc, char **argv)
 	if (rc < 0)
 		exit(1);
 
+	/* start control interface after reading config for
+	 * ctrl_vty_get_bind_addr() */
+	LOGP(DGPRS, LOGL_NOTICE, "CTRL at %s %d\n",
+	     ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_SGSN);
+	ctrl = sgsn_controlif_setup(NULL, ctrl_vty_get_bind_addr(),
+				    OSMO_CTRL_PORT_SGSN);
+	if (!ctrl) {
+		LOGP(DGPRS, LOGL_ERROR, "Failed to create CTRL interface.\n");
+		exit(1);
+	}
+
+	if (sgsn_ctrl_cmds_install() != 0) {
+		LOGP(DGPRS, LOGL_ERROR, "Failed to install CTRL commands.\n");
+		exit(1);
+	}
+
+
 	rc = sgsn_gtp_init(&sgsn_inst);
 	if (rc) {
 		LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on GTP socket\n");
diff --git a/openbsc/src/libbsc/bsc_ctrl_lookup.c b/openbsc/src/libbsc/bsc_ctrl_lookup.c
index b504ccc..a8a8cf5 100644
--- a/openbsc/src/libbsc/bsc_ctrl_lookup.c
+++ b/openbsc/src/libbsc/bsc_ctrl_lookup.c
@@ -99,7 +99,9 @@  err_index:
 	return -ERANGE;
 }
 
-struct ctrl_handle *bsc_controlif_setup(struct gsm_network *net, uint16_t port)
+struct ctrl_handle *bsc_controlif_setup(struct gsm_network *net,
+					const char *bind_addr, uint16_t port)
 {
-	return ctrl_interface_setup(net, port, bsc_ctrl_node_lookup);
+	return ctrl_interface_setup_dynip(net, bind_addr, port,
+					  bsc_ctrl_node_lookup);
 }
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_main.c b/openbsc/src/osmo-bsc/osmo_bsc_main.c
index 3806b24..3594a5b 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_main.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_main.c
@@ -32,6 +32,7 @@ 
 #include <osmocom/ctrl/control_cmd.h>
 #include <osmocom/ctrl/control_if.h>
 #include <osmocom/ctrl/ports.h>
+#include <osmocom/ctrl/control_vty.h>
 
 #include <osmocom/core/application.h>
 #include <osmocom/core/linuxlist.h>
@@ -205,6 +206,7 @@  int main(int argc, char **argv)
 	vty_init(&vty_info);
 	bsc_vty_init(&log_info);
 	bsc_msg_lst_vty_init(tall_bsc_ctx, &access_lists, BSC_NODE);
+	ctrl_vty_init(tall_bsc_ctx);
 
 	INIT_LLIST_HEAD(&access_lists);
 
@@ -225,7 +227,13 @@  int main(int argc, char **argv)
 	}
 	bsc_api_init(bsc_gsmnet, osmo_bsc_api());
 
-	bsc_gsmnet->ctrl = bsc_controlif_setup(bsc_gsmnet, OSMO_CTRL_PORT_NITB_BSC);
+	/* start control interface after reading config for
+	 * ctrl_vty_get_bind_addr() */
+	LOGP(DNM, LOGL_NOTICE, "CTRL at %s %d\n",
+	     ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_NITB_BSC);
+	bsc_gsmnet->ctrl = bsc_controlif_setup(bsc_gsmnet,
+					       ctrl_vty_get_bind_addr(),
+					       OSMO_CTRL_PORT_NITB_BSC);
 	if (!bsc_gsmnet->ctrl) {
 		fprintf(stderr, "Failed to init the control interface. Exiting.\n");
 		exit(1);
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat.c b/openbsc/src/osmo-bsc_nat/bsc_nat.c
index 04c12e3..cdab406 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat.c
@@ -52,6 +52,7 @@ 
 #include <osmocom/ctrl/control_cmd.h>
 #include <osmocom/ctrl/control_if.h>
 #include <osmocom/ctrl/ports.h>
+#include <osmocom/ctrl/control_vty.h>
 
 #include <osmocom/crypt/auth.h>
 
@@ -1618,6 +1619,7 @@  int main(int argc, char **argv)
 	logging_vty_add_cmds(&log_info);
 	osmo_stats_vty_add_cmds(&log_info);
 	bsc_nat_vty_init(nat);
+	ctrl_vty_init(tall_bsc_ctx);
 
 
 	/* parse options */
@@ -1664,7 +1666,12 @@  int main(int argc, char **argv)
 		exit(1);
 	}
 
-	nat->ctrl = bsc_nat_controlif_setup(nat, OSMO_CTRL_PORT_BSC_NAT);
+	/* start control interface after reading config for
+	 * ctrl_vty_get_bind_addr() */
+	LOGP(DNAT, LOGL_NOTICE, "CTRL at %s %d\n",
+	     ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_BSC_NAT);
+	nat->ctrl = bsc_nat_controlif_setup(nat, ctrl_vty_get_bind_addr(),
+					    OSMO_CTRL_PORT_BSC_NAT);
 	if (!nat->ctrl) {
 		fprintf(stderr, "Creating the control interface failed.\n");
 		exit(1);
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c b/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c
index f3ca924..ec4243e 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c
@@ -470,13 +470,14 @@  static int get_net_save_cmd(struct ctrl_cmd *cmd, void *data)
 	return CTRL_CMD_ERROR;
 }
 
-struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat, int port)
+struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat,
+					    const char *bind_addr, int port)
 {
 	struct ctrl_handle *ctrl;
 	int rc;
 
 
-	ctrl = bsc_controlif_setup(NULL, OSMO_CTRL_PORT_BSC_NAT);
+	ctrl = bsc_controlif_setup(NULL, bind_addr, OSMO_CTRL_PORT_BSC_NAT);
 	if (!ctrl) {
 		fprintf(stderr, "Failed to initialize the control interface. Exiting.\n");
 		return NULL;
diff --git a/openbsc/src/osmo-nitb/bsc_hack.c b/openbsc/src/osmo-nitb/bsc_hack.c
index 6f8da98..4bd03fc 100644
--- a/openbsc/src/osmo-nitb/bsc_hack.c
+++ b/openbsc/src/osmo-nitb/bsc_hack.c
@@ -49,6 +49,7 @@ 
 #include <openbsc/rrlp.h>
 #include <osmocom/ctrl/control_if.h>
 #include <osmocom/ctrl/ports.h>
+#include <osmocom/ctrl/control_vty.h>
 #include <openbsc/ctrl.h>
 #include <openbsc/osmo_bsc_rf.h>
 #include <openbsc/smpp.h>
@@ -272,6 +273,7 @@  int main(int argc, char **argv)
 	/* This needs to precede handle_options() */
 	vty_init(&vty_info);
 	bsc_vty_init(&log_info);
+	ctrl_vty_init(tall_bsc_ctx);
 
 #ifdef BUILD_SMPP
 	if (smpp_openbsc_init(tall_bsc_ctx, 0) < 0)
@@ -295,7 +297,13 @@  int main(int argc, char **argv)
 #endif
 	bsc_api_init(bsc_gsmnet, msc_bsc_api());
 
-	bsc_gsmnet->ctrl = bsc_controlif_setup(bsc_gsmnet, OSMO_CTRL_PORT_NITB_BSC);
+	/* start control interface after reading config for
+	 * ctrl_vty_get_bind_addr() */
+	LOGP(DNM, LOGL_NOTICE, "CTRL at %s %d\n",
+	     ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_NITB_BSC);
+	bsc_gsmnet->ctrl = bsc_controlif_setup(bsc_gsmnet,
+					       ctrl_vty_get_bind_addr(),
+					       OSMO_CTRL_PORT_NITB_BSC);
 	if (!bsc_gsmnet->ctrl) {
 		printf("Failed to initialize control interface. Exiting.\n");
 		return -1;