aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Willmann <dwillmann@sysmocom.de>2017-09-08 03:49:26 +0200
committerDaniel Willmann <dwillmann@sysmocom.de>2017-09-08 03:49:26 +0200
commitb55d939e126aac15a434c55d0689ae4dfaf0ecfa (patch)
tree2d1bcc885fee1f83995973ae786999c3be7cda47
parent1e641a1690fec1e2fc3319460583490f147fd74d (diff)
osmo-bsc_nat: Modify nat init to work with multiple mgcp_configs
-rw-r--r--openbsc/include/openbsc/bsc_nat.h11
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c115
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat.c10
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat_utils.c1
4 files changed, 75 insertions, 62 deletions
diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h
index 568cbb981..42af7e912 100644
--- a/openbsc/include/openbsc/bsc_nat.h
+++ b/openbsc/include/openbsc/bsc_nat.h
@@ -260,7 +260,7 @@ struct bsc_nat {
int bsc_ip_dscp;
/* MGCP config */
- struct mgcp_config *mgcp_cfg;
+ struct llist_head mgcp_cfgs;
uint8_t mgcp_msg[4096];
int mgcp_length;
int mgcp_ipa;
@@ -276,8 +276,6 @@ struct bsc_nat {
int ping_timeout;
int pong_timeout;
- struct bsc_endpoint *bsc_endpoints;
-
/* filter */
char *acc_lst_name;
@@ -333,6 +331,11 @@ struct bsc_nat_ussd_con {
struct osmo_timer_list auth_timeout;
};
+struct mgcp_nat_config {
+ struct bsc_nat *nat;
+ struct bsc_endpoint *bsc_endpoints;
+};
+
/* create and init the structures */
struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token);
struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num);
@@ -389,7 +392,7 @@ int bsc_mgcp_assign_patch(struct nat_sccp_connection *, struct msgb *msg);
void bsc_mgcp_init(struct nat_sccp_connection *);
void bsc_mgcp_dlcx(struct nat_sccp_connection *);
void bsc_mgcp_free_endpoints(struct bsc_nat *nat);
-int bsc_mgcp_nat_init(struct bsc_nat *nat);
+int bsc_mgcp_nat_init(struct bsc_nat *nat, struct llist_head* cfgs);
struct nat_sccp_connection *bsc_mgcp_find_con(struct bsc_nat *, int endpoint_number);
struct msgb *bsc_mgcp_rewrite(char *input, int length, int endp, const char *ip,
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 8cad3e80f..d59275319 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;
@@ -1640,7 +1634,7 @@ int main(int argc, char **argv)
/* init vty and parse */
telnet_init(tall_bsc_ctx, NULL, OSMO_VTY_PORT_BSC_NAT);
- 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;
}
@@ -1653,7 +1647,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;
nat->ctrl = bsc_nat_controlif_setup(nat, 4250);
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
index 0997aa6f9..634f57963 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");