[MERGED] openbsc[master]: split bsc_bootstrap_network() in alloc and config

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Fri Dec 2 12:09:19 UTC 2016


Harald Welte has submitted this change and it was merged.

Change subject: split bsc_bootstrap_network() in alloc and config
......................................................................


split bsc_bootstrap_network() in alloc and config

For patch clarity, keep some code dup to be removed in a subsequent patch. In
the same sense don't change the fact that mncc_sock_init()'s return value is
ignored.

The global gsm_network instance 'bsc_gsmnet' is basically only used by the VTY,
and a future patch will "hide" that global in a vty .c file. In a nutshell, I
want to

- first allocate a gsm_network,
- then initialize the VTY passing the gsm_network pointer,
- and then read the config file using the initialized VTY.

So far, bsc_bootstrap_network() allocates the gsm_network and reads the config
file right away, which only works by sharing the extern bsc_gsmnet pointer,
which I would like to uncouple.

Change-Id: I480a09a31a79766ad07b627dd5238b7e37f3be7a
---
M openbsc/include/openbsc/bss.h
M openbsc/src/libbsc/bsc_init.c
M openbsc/src/osmo-bsc/osmo_bsc_main.c
M openbsc/src/osmo-nitb/bsc_hack.c
4 files changed, 33 insertions(+), 13 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/openbsc/include/openbsc/bss.h b/openbsc/include/openbsc/bss.h
index d73776f..9f16bf7 100644
--- a/openbsc/include/openbsc/bss.h
+++ b/openbsc/include/openbsc/bss.h
@@ -6,7 +6,8 @@
 struct msgb;
 
 /* start and stop network */
-extern int bsc_bootstrap_network(mncc_recv_cb_t mncc_recv, const char *cfg_file);
+extern int bsc_network_alloc(mncc_recv_cb_t mncc_recv);
+extern int bsc_network_configure(const char *cfg_file);
 extern int bsc_shutdown_net(struct gsm_network *net);
 
 /* register all supported BTS */
diff --git a/openbsc/src/libbsc/bsc_init.c b/openbsc/src/libbsc/bsc_init.c
index 917dd73..9e913d6 100644
--- a/openbsc/src/libbsc/bsc_init.c
+++ b/openbsc/src/libbsc/bsc_init.c
@@ -476,12 +476,8 @@
 	return 0;
 }
 
-int bsc_bootstrap_network(mncc_recv_cb_t mncc_recv, const char *config_file)
+int bsc_network_alloc(mncc_recv_cb_t mncc_recv)
 {
-	struct gsm_bts *bts;
-	int rc;
-
-	/* initialize our data structures */
 	bsc_gsmnet = bsc_network_init(tall_bsc_ctx, 1, 1, mncc_recv);
 	if (!bsc_gsmnet)
 		return -ENOMEM;
@@ -489,6 +485,14 @@
 	bsc_gsmnet->name_long = talloc_strdup(bsc_gsmnet, "OpenBSC");
 	bsc_gsmnet->name_short = talloc_strdup(bsc_gsmnet, "OpenBSC");
 
+	return 0;
+}
+
+int bsc_network_configure(const char *config_file)
+{
+	struct gsm_bts *bts;
+	int rc;
+
 	rc = vty_read_config_file(config_file, NULL);
 	if (rc < 0) {
 		LOGP(DNM, LOGL_FATAL, "Failed to parse the config file: '%s'\n", config_file);
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_main.c b/openbsc/src/osmo-bsc/osmo_bsc_main.c
index daab55b..b6b1ae1 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_main.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_main.c
@@ -220,8 +220,12 @@
 	/* initialize SCCP */
 	sccp_set_log_area(DSCCP);
 
-
-	rc = bsc_bootstrap_network(NULL, config_file);
+	rc = bsc_network_alloc(NULL);
+	if (rc) {
+		fprintf(stderr, "Allocation failed. exiting.\n");
+		exit(1);
+	}
+	rc = bsc_network_configure(config_file);
 	if (rc < 0) {
 		fprintf(stderr, "Bootstrapping the network failed. exiting.\n");
 		exit(1);
diff --git a/openbsc/src/osmo-nitb/bsc_hack.c b/openbsc/src/osmo-nitb/bsc_hack.c
index 552ab4f..ccd3b74 100644
--- a/openbsc/src/osmo-nitb/bsc_hack.c
+++ b/openbsc/src/osmo-nitb/bsc_hack.c
@@ -285,15 +285,26 @@
 
 	/* internal MNCC handler or MNCC socket? */
 	if (mncc_sock_path) {
-		rc = bsc_bootstrap_network(mncc_sock_from_cc, config_file);
-		if (rc >= 0)
-			mncc_sock_init(bsc_gsmnet, mncc_sock_path);
+		rc = bsc_network_alloc(mncc_sock_from_cc);
+		if (rc) {
+			fprintf(stderr, "Allocation failed. Exiting.\n");
+			exit(1);
+		}
+		mncc_sock_init(bsc_gsmnet, mncc_sock_path);
 	} else {
 		DEBUGP(DMNCC, "Using internal MNCC handler.\n");
-		rc = bsc_bootstrap_network(int_mncc_recv, config_file);
+		rc = bsc_network_alloc(int_mncc_recv);
+		if (rc) {
+			fprintf(stderr, "Allocation failed. Exiting.\n");
+			exit(1);
+		}
 	}
-	if (rc < 0)
+	rc = bsc_network_configure(config_file);
+	if (rc < 0) {
+		fprintf(stderr, "Reading config failed. Exiting.\n");
 		exit(1);
+	}
+
 #ifdef BUILD_SMPP
 	smpp_openbsc_start(bsc_gsmnet);
 #endif

-- 
To view, visit https://gerrit.osmocom.org/1140
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I480a09a31a79766ad07b627dd5238b7e37f3be7a
Gerrit-PatchSet: 8
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list