diff options
author | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2016-02-10 23:42:17 +0100 |
---|---|---|
committer | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2016-03-03 16:19:09 +0100 |
commit | 5e47b1a1d370c187c776b29c5958f167519e94d7 (patch) | |
tree | 109151df31be3ebfb242d3345f82a0475b44a4cc /openbsc/src/libbsc | |
parent | b9e5403ef46171f58390757d002a756bd9d2d202 (diff) |
mscplit: try to clarify root talloc ctx and global gsm_network.
The aim is to allow osmo-cscn to pass its own root talloc context and
global gsm_network struct instance cleanly. This may stir up some old and
dusty globals, but I hope it's for the better, since not all is a BSC.
To ensure that a global gsm_network pointer for the bsc_vty is set, have it as
argument to bsc_vty_init(). The vty configuration commands are added only after
bsc_vty_init(), which are needed to configure the network struct. So split up
the bsc_bootstrap_network() function into bsc_network_init() to allocate a
gsm_struct, and bsc_network_configure() to read the config file once the vty
commands are in place. In this way, no global bsc_gsmnet pointer is needed for
the bsc vty. The atomic super glue is dissolved and osmo-cscn will be allowed
to have a different name for it.
Admitted, it's still called the bsc_vty, but a split thereof is probably coming
soon, because the CSCN doesn't want any of the BSC nor BTS specific vty
commands.
Diffstat (limited to 'openbsc/src/libbsc')
-rw-r--r-- | openbsc/src/libbsc/abis_nm_vty.c | 4 | ||||
-rw-r--r-- | openbsc/src/libbsc/abis_om2000_vty.c | 4 | ||||
-rw-r--r-- | openbsc/src/libbsc/bsc_init.c | 22 | ||||
-rw-r--r-- | openbsc/src/libbsc/bsc_vty.c | 26 | ||||
-rw-r--r-- | openbsc/src/libbsc/bts_ipaccess_nanobts.c | 1 | ||||
-rw-r--r-- | openbsc/src/libbsc/net_init.c | 8 |
6 files changed, 36 insertions, 29 deletions
diff --git a/openbsc/src/libbsc/abis_nm_vty.c b/openbsc/src/libbsc/abis_nm_vty.c index a14e5c2f4..6ec0a4a21 100644 --- a/openbsc/src/libbsc/abis_nm_vty.c +++ b/openbsc/src/libbsc/abis_nm_vty.c @@ -94,7 +94,7 @@ DEFUN(oml_class_inst, oml_class_inst_cmd, struct oml_node_state *oms; int bts_nr = atoi(argv[0]); - bts = gsm_bts_num(bsc_gsmnet, bts_nr); + bts = gsm_bts_num(gsmnet_from_vty(vty), bts_nr); if (!bts) { vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE); return CMD_WARNING; @@ -128,7 +128,7 @@ DEFUN(oml_classnum_inst, oml_classnum_inst_cmd, struct oml_node_state *oms; int bts_nr = atoi(argv[0]); - bts = gsm_bts_num(bsc_gsmnet, bts_nr); + bts = gsm_bts_num(gsmnet_from_vty(vty), bts_nr); if (!bts) { vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE); return CMD_WARNING; diff --git a/openbsc/src/libbsc/abis_om2000_vty.c b/openbsc/src/libbsc/abis_om2000_vty.c index 8325e29a7..72422a1d5 100644 --- a/openbsc/src/libbsc/abis_om2000_vty.c +++ b/openbsc/src/libbsc/abis_om2000_vty.c @@ -82,7 +82,7 @@ DEFUN(om2k_class_inst, om2k_class_inst_cmd, struct oml_node_state *oms; int bts_nr = atoi(argv[0]); - bts = gsm_bts_num(bsc_gsmnet, bts_nr); + bts = gsm_bts_num(gsmnet_from_vty(vty), bts_nr); if (!bts) { vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE); return CMD_WARNING; @@ -122,7 +122,7 @@ DEFUN(om2k_classnum_inst, om2k_classnum_inst_cmd, struct oml_node_state *oms; int bts_nr = atoi(argv[0]); - bts = gsm_bts_num(bsc_gsmnet, bts_nr); + bts = gsm_bts_num(gsmnet_from_vty(vty), bts_nr); if (!bts) { vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE); return CMD_WARNING; diff --git a/openbsc/src/libbsc/bsc_init.c b/openbsc/src/libbsc/bsc_init.c index 859d9998f..3ec3aa837 100644 --- a/openbsc/src/libbsc/bsc_init.c +++ b/openbsc/src/libbsc/bsc_init.c @@ -472,24 +472,24 @@ static int bootstrap_bts(struct gsm_bts *bts) return 0; } -int bsc_bootstrap_network(int (*mncc_recv)(struct gsm_network *, struct msgb *), - const char *config_file) +int bsc_network_init(mncc_recv_cb_t mncc_recv) { - struct telnet_connection dummy_conn; - struct gsm_bts *bts; - int rc; - - /* initialize our data structures */ - bsc_gsmnet = gsm_network_init(1, 1, mncc_recv); + bsc_gsmnet = gsm_network_init(tall_bsc_ctx, 1, 1, mncc_recv); if (!bsc_gsmnet) return -ENOMEM; bsc_gsmnet->name_long = talloc_strdup(bsc_gsmnet, "OpenBSC"); bsc_gsmnet->name_short = talloc_strdup(bsc_gsmnet, "OpenBSC"); - /* our vty command code expects vty->priv to point to a telnet_connection */ - dummy_conn.priv = bsc_gsmnet; - rc = vty_read_config_file(config_file, &dummy_conn); + 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); return rc; diff --git a/openbsc/src/libbsc/bsc_vty.c b/openbsc/src/libbsc/bsc_vty.c index 418e43549..29de16ca0 100644 --- a/openbsc/src/libbsc/bsc_vty.c +++ b/openbsc/src/libbsc/bsc_vty.c @@ -130,19 +130,21 @@ struct cmd_node ts_node = { 1, }; -extern struct gsm_network *bsc_gsmnet; +static struct gsm_network *vty_global_gsm_network = 0; struct gsm_network *gsmnet_from_vty(struct vty *v) { /* In case we read from the config file, the vty->priv cannot * point to a struct telnet_connection, and thus conn->priv - * will not point to the gsm_network structure */ -#if 0 - struct telnet_connection *conn = v->priv; - return (struct gsm_network *) conn->priv; -#else - return bsc_gsmnet; -#endif + * will not point to the gsm_network structure. + * It can't hurt to force callers to continue to pass the vty instance + * to this function, in case we'd like to retrieve the global + * gsm_network instance from the vty at some point in the future. But + * until then, just return the global pointer, which should have been + * initialized by bsc_vty_init(). + */ + OSMO_ASSERT(vty_global_gsm_network); + return vty_global_gsm_network; } static int dummy_config_write(struct vty *v) @@ -3620,7 +3622,7 @@ DEFUN(smscb_cmd, smscb_cmd_cmd, uint8_t buf[88]; int rc; - bts = gsm_bts_num(bsc_gsmnet, bts_nr); + bts = gsm_bts_num(vty_global_gsm_network, bts_nr); if (!bts) { vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE); return CMD_WARNING; @@ -3671,7 +3673,7 @@ DEFUN(pdch_act, pdch_act_cmd, int ts_nr = atoi(argv[2]); int activate; - bts = gsm_bts_num(bsc_gsmnet, bts_nr); + bts = gsm_bts_num(vty_global_gsm_network, bts_nr); if (!bts) { vty_out(vty, "%% No such BTS (%d)%s", bts_nr, VTY_NEWLINE); return CMD_WARNING; @@ -3710,8 +3712,10 @@ DEFUN(pdch_act, pdch_act_cmd, extern int bsc_vty_init_extra(void); extern const char *openbsc_copyright; -int bsc_vty_init(const struct log_info *cat) +int bsc_vty_init(const struct log_info *cat, struct gsm_network *network) { + vty_global_gsm_network = network; + cfg_ts_pchan_cmd.string = vty_cmd_string_from_valstr(tall_bsc_ctx, gsm_pchant_names, diff --git a/openbsc/src/libbsc/bts_ipaccess_nanobts.c b/openbsc/src/libbsc/bts_ipaccess_nanobts.c index dfb5a45bc..ee356b82c 100644 --- a/openbsc/src/libbsc/bts_ipaccess_nanobts.c +++ b/openbsc/src/libbsc/bts_ipaccess_nanobts.c @@ -39,6 +39,7 @@ #include <osmocom/abis/ipaccess.h> #include <osmocom/core/logging.h> #include <openbsc/ipaccess.h> +#include <openbsc/vty.h> extern struct gsm_network *bsc_gsmnet; diff --git a/openbsc/src/libbsc/net_init.c b/openbsc/src/libbsc/net_init.c index 3b5f4f906..9aba4a0b7 100644 --- a/openbsc/src/libbsc/net_init.c +++ b/openbsc/src/libbsc/net_init.c @@ -21,12 +21,14 @@ #include <openbsc/osmo_msc_data.h> #include <openbsc/gsm_subscriber.h> -struct gsm_network *gsm_network_init(uint16_t country_code, uint16_t network_code, - int (*mncc_recv)(struct gsm_network *, struct msgb *)) +struct gsm_network *gsm_network_init(void *ctx, + uint16_t country_code, + uint16_t network_code, + mncc_recv_cb_t mncc_recv) { struct gsm_network *net; - net = talloc_zero(tall_bsc_ctx, struct gsm_network); + net = talloc_zero(ctx, struct gsm_network); if (!net) return NULL; |