aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-04-17 07:20:00 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-04-17 07:31:08 +0200
commit941839b3008a1bbd7f89180532f98a8303032ce3 (patch)
tree497c7f63b55f865c2a215bdcfc6a4794b5f88024
parent23a0e46f113cc362109970dbe26aba58b4a09f60 (diff)
nat: Move MSC ip address into the config..
The address can still be specified on the cli and it will overwrite the config in the config file.
-rw-r--r--openbsc/include/openbsc/bsc_nat.h2
-rw-r--r--openbsc/src/bsc-nat.cfg1
-rw-r--r--openbsc/src/nat/bsc_nat.c22
-rw-r--r--openbsc/src/nat/bsc_nat_utils.c8
-rw-r--r--openbsc/src/nat/bsc_nat_vty.c11
5 files changed, 37 insertions, 7 deletions
diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h
index 4ad54951d..3754f25f0 100644
--- a/openbsc/include/openbsc/bsc_nat.h
+++ b/openbsc/include/openbsc/bsc_nat.h
@@ -204,6 +204,7 @@ struct bsc_nat {
int mgcp_length;
/* msc things */
+ char *msc_ip;
int first_contact;
struct bsc_endpoint *bsc_endpoints;
@@ -223,6 +224,7 @@ struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token, unsi
struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num);
struct bsc_nat *bsc_nat_alloc(void);
struct bsc_connection *bsc_connection_alloc(struct bsc_nat *nat);
+void bsc_nat_set_msc_ip(struct bsc_nat *bsc, const char *ip);
void sccp_connection_destroy(struct sccp_connections *);
diff --git a/openbsc/src/bsc-nat.cfg b/openbsc/src/bsc-nat.cfg
index 181fd1b62..18b022753 100644
--- a/openbsc/src/bsc-nat.cfg
+++ b/openbsc/src/bsc-nat.cfg
@@ -7,6 +7,7 @@ line vty
no login
!
nat
+ msc ip 10.0.0.23
bsc 0
token zecke
location_area_code 3
diff --git a/openbsc/src/nat/bsc_nat.c b/openbsc/src/nat/bsc_nat.c
index 65e491dc2..f4180abb6 100644
--- a/openbsc/src/nat/bsc_nat.c
+++ b/openbsc/src/nat/bsc_nat.c
@@ -51,10 +51,10 @@
struct log_target *stderr_target;
static const char *config_file = "bsc-nat.cfg";
-static char *msc_address = "127.0.0.1";
static struct in_addr local_addr;
static struct bsc_msc_connection *msc_con;
static struct bsc_fd bsc_listen;
+static const char *msc_ip = NULL;
static struct bsc_nat *nat;
@@ -782,7 +782,7 @@ static void handle_options(int argc, char** argv)
log_set_print_timestamp(stderr_target, 1);
break;
case 'm':
- msc_address = strdup(optarg);
+ msc_ip = optarg;
break;
case 'l':
inet_aton(optarg, &local_addr);
@@ -815,10 +815,6 @@ int main(int argc, char** argv)
log_add_target(stderr_target);
log_set_all_filter(stderr_target, 1);
- /* parse options */
- local_addr.s_addr = INADDR_ANY;
- handle_options(argc, argv);
-
nat = bsc_nat_alloc();
if (!nat) {
fprintf(stderr, "Failed to allocate the BSC nat.\n");
@@ -826,6 +822,14 @@ int main(int argc, char** argv)
}
nat->mgcp_cfg = talloc_zero(nat, struct mgcp_config);
+ if (!nat->mgcp_cfg) {
+ fprintf(stderr, "Failed to allocate MGCP cfg.\n");
+ return -5;
+ }
+
+ /* parse options */
+ local_addr.s_addr = INADDR_ANY;
+ handle_options(argc, argv);
/* init vty and parse */
bsc_nat_vty_init(nat);
@@ -835,6 +839,10 @@ int main(int argc, char** argv)
return -3;
}
+ /* over rule the VTY config */
+ if (msc_ip)
+ bsc_nat_set_msc_ip(nat, msc_ip);
+
/* seed the PRNG */
srand(time(NULL));
@@ -845,7 +853,7 @@ int main(int argc, char** argv)
return -4;
/* connect to the MSC */
- msc_con = bsc_msc_create(msc_address, 5000);
+ msc_con = bsc_msc_create(nat->msc_ip, 5000);
if (!msc_con) {
fprintf(stderr, "Creating a bsc_msc_connection failed.\n");
exit(1);
diff --git a/openbsc/src/nat/bsc_nat_utils.c b/openbsc/src/nat/bsc_nat_utils.c
index 58f933742..21459c5e5 100644
--- a/openbsc/src/nat/bsc_nat_utils.c
+++ b/openbsc/src/nat/bsc_nat_utils.c
@@ -51,9 +51,17 @@ struct bsc_nat *bsc_nat_alloc(void)
nat->stats.bsc.reconn = counter_alloc("nat.bsc.conn");
nat->stats.bsc.auth_fail = counter_alloc("nat.bsc.auth_fail");
nat->stats.msc.reconn = counter_alloc("nat.msc.conn");
+ nat->msc_ip = talloc_strdup(nat, "127.0.0.1");
return nat;
}
+void bsc_nat_set_msc_ip(struct bsc_nat *nat, const char *ip)
+{
+ if (nat->msc_ip)
+ talloc_free(nat->msc_ip);
+ nat->msc_ip = talloc_strdup(nat, ip);
+}
+
struct bsc_connection *bsc_connection_alloc(struct bsc_nat *nat)
{
struct bsc_connection *con = talloc_zero(nat, struct bsc_connection);
diff --git a/openbsc/src/nat/bsc_nat_vty.c b/openbsc/src/nat/bsc_nat_vty.c
index f0adfaaeb..a91da7c4e 100644
--- a/openbsc/src/nat/bsc_nat_vty.c
+++ b/openbsc/src/nat/bsc_nat_vty.c
@@ -55,6 +55,7 @@ static int config_write_nat(struct vty *vty)
vty_out(vty, " imsi allow %s%s", _nat->imsi_allow, VTY_NEWLINE);
if (_nat->imsi_deny)
vty_out(vty, " insi deny %s%s", _nat->imsi_deny, VTY_NEWLINE);
+ vty_out(vty, " msc ip %s%s", _nat->msc_ip, VTY_NEWLINE);
return CMD_SUCCESS;
}
@@ -203,6 +204,15 @@ DEFUN(cfg_nat_imsi_deny,
return CMD_SUCCESS;
}
+DEFUN(cfg_nat_msc_ip,
+ cfg_nat_msc_ip_cmd,
+ "msc ip IP",
+ "Set the IP address of the MSC.")
+{
+ bsc_nat_set_msc_ip(_nat, argv[0]);
+ return CMD_SUCCESS;
+}
+
/* per BSC configuration */
DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure\n")
{
@@ -316,6 +326,7 @@ int bsc_nat_vty_init(struct bsc_nat *nat)
install_default(NAT_NODE);
install_element(NAT_NODE, &cfg_nat_imsi_allow_cmd);
install_element(NAT_NODE, &cfg_nat_imsi_deny_cmd);
+ install_element(NAT_NODE, &cfg_nat_msc_ip_cmd);
/* BSC subgroups */
install_element(NAT_NODE, &cfg_bsc_cmd);