aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2016-04-07 12:27:11 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-04-12 10:15:02 -0400
commit714b170f895dfdc2f0d725ab110baf3dc14ef874 (patch)
tree173a97c9280642127eb102e9c5c19fad50b7493c /openbsc/src
parent7a301d357612347723e59c7f16a97227814d406e (diff)
NAT: allow allocating BSC in arbitrary order
Check for existing BSC before allocating new one. Track number of remaining BSCs on deallocation. Explicitly use BSC number in allocation function.
Diffstat (limited to 'openbsc/src')
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat_utils.c7
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat_vty.c14
2 files changed, 9 insertions, 12 deletions
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
index cc7d44287..37b01e314 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
@@ -155,14 +155,15 @@ struct bsc_connection *bsc_connection_alloc(struct bsc_nat *nat)
return con;
}
-struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token)
+struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token,
+ unsigned int number)
{
struct bsc_config *conf = talloc_zero(nat, struct bsc_config);
if (!conf)
return NULL;
conf->token = talloc_strdup(conf, token);
- conf->nr = nat->num_bsc;
+ conf->nr = number;
conf->nat = nat;
conf->max_endpoints = 32;
conf->paging_group = PAGIN_GROUP_UNASSIGNED;
@@ -205,6 +206,8 @@ void bsc_config_free(struct bsc_config *cfg)
llist_del(&cfg->entry);
rate_ctr_group_free(cfg->stats.ctrg);
talloc_free(cfg);
+ cfg->nat->num_bsc--;
+ OSMO_ASSERT(cfg->nat->num_bsc >= 0)
}
static void _add_lac(void *ctx, struct llist_head *list, int _lac)
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
index 5af6d9743..4348d6fb8 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
@@ -799,17 +799,11 @@ DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR",
"BSC configuration\n" "Identifier of the BSC\n")
{
int bsc_nr = atoi(argv[0]);
- struct bsc_config *bsc;
+ struct bsc_config *bsc = bsc_config_num(_nat, bsc_nr);
- if (bsc_nr > _nat->num_bsc) {
- vty_out(vty, "%% The next unused BSC number is %u%s",
- _nat->num_bsc, VTY_NEWLINE);
- return CMD_WARNING;
- } else if (bsc_nr == _nat->num_bsc) {
- /* allocate a new one */
- bsc = bsc_config_alloc(_nat, "unknown");
- } else
- bsc = bsc_config_num(_nat, bsc_nr);
+ /* allocate a new one */
+ if (!bsc)
+ bsc = bsc_config_alloc(_nat, "unknown", bsc_nr);
if (!bsc)
return CMD_WARNING;