diff options
author | Daniel Willmann <dwillmann@sysmocom.de> | 2017-09-08 03:49:26 +0200 |
---|---|---|
committer | Daniel Willmann <dwillmann@sysmocom.de> | 2018-01-30 18:59:28 +0100 |
commit | 63223f35e8fe25bbdd690ab9e91ac9474c538772 (patch) | |
tree | 1d66c81d4608a9c539f551cd065c4cc737c5cf4b /openbsc/src/osmo-bsc_nat | |
parent | 3f734d27a556be774e86c07534593390095e3595 (diff) |
osmo-bsc_nat: Modify nat init to work with multiple mgcp_configs
Change-Id: I53ac858952ee15f897160b3a32483c5c91b862f6
Diffstat (limited to 'openbsc/src/osmo-bsc_nat')
-rw-r--r-- | openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c | 115 | ||||
-rw-r--r-- | openbsc/src/osmo-bsc_nat/bsc_nat.c | 10 | ||||
-rw-r--r-- | openbsc/src/osmo-bsc_nat/bsc_nat_utils.c | 1 |
3 files changed, 68 insertions, 58 deletions
diff --git a/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c b/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c index 1130c63d5..e360fbb16 100644 --- a/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c +++ b/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c @@ -556,10 +556,10 @@ static int bsc_mgcp_policy_cb(struct mgcp_trunk_config *tcfg, int endpoint, int /* Allocate a Osmux circuit ID */ if (state == MGCP_ENDP_CRCX) { - if (nat->mgcp_cfg->osmux && sccp->bsc->cfg->osmux) { + if (tcfg->cfg->osmux && sccp->bsc->cfg->osmux) { osmux_allocate_cid(mgcp_endp); if (mgcp_endp->osmux.allocated_cid < 0 && - nat_osmux_only(nat->mgcp_cfg, sccp->bsc->cfg)) { + nat_osmux_only(tcfg->cfg, sccp->bsc->cfg)) { LOGP(DMGCP, LOGL_ERROR, "Rejecting usage of endpoint\n"); return MGCP_POLICY_REJECT; @@ -1081,77 +1081,92 @@ static int init_mgcp_socket(struct bsc_nat *nat, struct mgcp_config *cfg) return 0; } -int bsc_mgcp_nat_init(struct bsc_nat *nat) +int bsc_mgcp_nat_init(struct bsc_nat *nat, struct llist_head *cfgs) { - struct mgcp_config *cfg = nat->mgcp_cfg; + struct mgcp_config *cfg; + struct mgcp_nat_config *mgcp_nat; - if (!cfg->call_agent_addr) { - LOGP(DMGCP, LOGL_ERROR, "The BSC nat requires the call agent ip to be set.\n"); - return -1; - } + llist_for_each_entry(cfg, cfgs, entry) { + if (!cfg->call_agent_addr) { + LOGP(DMGCP, LOGL_ERROR, "The BSC nat requires the call agent ip to be set.\n"); + return -1; + } - if (cfg->bts_ip) { - LOGP(DMGCP, LOGL_ERROR, "Do not set the BTS ip for the nat.\n"); - return -1; - } + if (cfg->bts_ip) { + LOGP(DMGCP, LOGL_ERROR, "Do not set the BTS ip for the nat.\n"); + return -1; + } - /* initialize the MGCP socket */ - if (!nat->mgcp_ipa) { - int rc = init_mgcp_socket(nat, cfg); - if (rc != 0) - return rc; - } + /* initialize the MGCP socket */ + if (!nat->mgcp_ipa) { + int rc = init_mgcp_socket(nat, cfg); + if (rc != 0) + return rc; + } - /* some more MGCP config handling */ - cfg->data = nat; - cfg->policy_cb = bsc_mgcp_policy_cb; - cfg->trunk.force_realloc = 1; + /* Create a user structure to keep bsc_endpoints per mgcp + * config */ + mgcp_nat = talloc_zero(cfg, struct mgcp_nat_config); + if (!mgcp_nat) + return -1; - if (cfg->bts_ip) - talloc_free(cfg->bts_ip); - cfg->bts_ip = ""; + mgcp_nat->nat = nat; + cfg->data = mgcp_nat; - nat->bsc_endpoints = talloc_zero_array(nat, - struct bsc_endpoint, - cfg->trunk.number_endpoints + 1); - if (!nat->bsc_endpoints) { - LOGP(DMGCP, LOGL_ERROR, "Failed to allocate nat endpoints\n"); - close(cfg->gw_fd.bfd.fd); - cfg->gw_fd.bfd.fd = -1; - return -1; - } + /* some more MGCP config handling */ + cfg->policy_cb = bsc_mgcp_policy_cb; + cfg->trunk.force_realloc = 1; - if (mgcp_reset_transcoder(cfg) < 0) { - LOGP(DMGCP, LOGL_ERROR, "Failed to send packet to the transcoder.\n"); - talloc_free(nat->bsc_endpoints); - nat->bsc_endpoints = NULL; - close(cfg->gw_fd.bfd.fd); - cfg->gw_fd.bfd.fd = -1; - return -1; - } + if (cfg->bts_ip) + talloc_free(cfg->bts_ip); + cfg->bts_ip = ""; + + mgcp_nat->bsc_endpoints = talloc_zero_array(nat, + struct bsc_endpoint, + cfg->trunk.number_endpoints + 1); + if (!mgcp_nat->bsc_endpoints) { + LOGP(DMGCP, LOGL_ERROR, "Failed to allocate nat endpoints\n"); + close(cfg->gw_fd.bfd.fd); + cfg->gw_fd.bfd.fd = -1; + return -1; + } + if (mgcp_reset_transcoder(cfg) < 0) { + LOGP(DMGCP, LOGL_ERROR, "Failed to send packet to the transcoder.\n"); + talloc_free(mgcp_nat->bsc_endpoints); + mgcp_nat->bsc_endpoints = NULL; + close(cfg->gw_fd.bfd.fd); + cfg->gw_fd.bfd.fd = -1; + return -1; + } + } return 0; } void bsc_mgcp_clear_endpoints_for(struct bsc_connection *bsc) { + struct mgcp_config *mgcp_cfg; + struct mgcp_nat_config *mgcp_nat; struct rate_ctr *ctr = NULL; int i; if (bsc->cfg) ctr = &bsc->cfg->stats.ctrg->ctr[BCFG_CTR_DROPPED_CALLS]; - for (i = 1; i < bsc->nat->mgcp_cfg->trunk.number_endpoints; ++i) { - struct bsc_endpoint *bsc_endp = &bsc->nat->bsc_endpoints[i]; + llist_for_each_entry(mgcp_cfg, &bsc->nat->mgcp_cfgs, entry) { + mgcp_nat = mgcp_cfg->data; + for (i = 1; i < mgcp_cfg->trunk.number_endpoints; ++i) { + struct bsc_endpoint *bsc_endp = &mgcp_nat->bsc_endpoints[i]; - if (bsc_endp->bsc != bsc) - continue; + if (bsc_endp->bsc != bsc) + continue; - if (ctr) - rate_ctr_inc(ctr); + if (ctr) + rate_ctr_inc(ctr); - bsc_mgcp_free_endpoint(bsc->nat, i); - mgcp_release_endp(&bsc->nat->mgcp_cfg->trunk.endpoints[i]); + bsc_mgcp_free_endpoint(mgcp_cfg, i); + mgcp_release_endp(&mgcp_cfg->trunk.endpoints[i]); + } } } diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat.c b/openbsc/src/osmo-bsc_nat/bsc_nat.c index e2471874f..89f99064d 100644 --- a/openbsc/src/osmo-bsc_nat/bsc_nat.c +++ b/openbsc/src/osmo-bsc_nat/bsc_nat.c @@ -1615,12 +1615,6 @@ int main(int argc, char **argv) return -4; } - nat->mgcp_cfg = mgcp_config_alloc(); - if (!nat->mgcp_cfg) { - fprintf(stderr, "Failed to allocate MGCP cfg.\n"); - return -5; - } - /* We need to add mode-set for amr codecs */ nat->sdp_ensure_amr_mode_set = 1; @@ -1642,7 +1636,7 @@ int main(int argc, char **argv) osmo_stats_init(tall_bsc_ctx); /* init vty and parse */ - if (mgcp_parse_config(config_file, nat->mgcp_cfg, MGCP_BSC_NAT) < 0) { + if (mgcp_parse_config(config_file, &nat->mgcp_cfgs, MGCP_BSC_NAT) < 0) { fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); return -3; } @@ -1662,7 +1656,7 @@ int main(int argc, char **argv) /* * Setup the MGCP code.. */ - if (bsc_mgcp_nat_init(nat) != 0) + if (bsc_mgcp_nat_init(nat, &nat->mgcp_cfgs) != 0) return -4; /* start control interface after reading config for diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c index 5ab5fb38b..dda679472 100644 --- a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c +++ b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c @@ -87,6 +87,7 @@ struct bsc_nat *bsc_nat_alloc(void) INIT_LLIST_HEAD(&nat->tpdest_match); INIT_LLIST_HEAD(&nat->sms_clear_tp_srr); INIT_LLIST_HEAD(&nat->sms_num_rewr); + INIT_LLIST_HEAD(&nat->mgcp_cfgs); nat->stats.sccp.conn = osmo_counter_alloc("nat.sccp.conn"); nat->stats.sccp.calls = osmo_counter_alloc("nat.sccp.calls"); |