aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-09-02 15:42:08 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-09-03 15:33:29 +0200
commit5c5e942765d186e4a7979bc29d5b0eaf3f305e2a (patch)
treef7e495e94313ec68c2b3f6a4590c0c90dc82ebeb /openbsc/src
parente581cd18c1d89efdeb3015286b6c1d13c67cc75c (diff)
nat/vty: Allow to configure an optional local-call ip address
Diffstat (limited to 'openbsc/src')
-rw-r--r--openbsc/src/osmo-bsc_nat/Makefile.am3
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat_call_control.c37
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat_utils.c11
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat_vty.c38
4 files changed, 88 insertions, 1 deletions
diff --git a/openbsc/src/osmo-bsc_nat/Makefile.am b/openbsc/src/osmo-bsc_nat/Makefile.am
index aae6d6966..fae9786a8 100644
--- a/openbsc/src/osmo-bsc_nat/Makefile.am
+++ b/openbsc/src/osmo-bsc_nat/Makefile.am
@@ -7,7 +7,8 @@ bin_PROGRAMS = osmo-bsc_nat
osmo_bsc_nat_SOURCES = bsc_filter.c bsc_mgcp_utils.c bsc_nat.c bsc_nat_utils.c \
bsc_nat_vty.c bsc_sccp.c bsc_ussd.c bsc_nat_ctrl.c \
- bsc_nat_rewrite.c bsc_nat_filter.c bsc_nat_rewrite_trie.c
+ bsc_nat_rewrite.c bsc_nat_filter.c bsc_nat_rewrite_trie.c \
+ bsc_nat_call_control.c
osmo_bsc_nat_LDADD = $(top_builddir)/src/libcommon/libcommon.a \
$(top_builddir)/src/libmgcp/libmgcp.a \
$(top_builddir)/src/libbsc/libbsc.a \
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_call_control.c b/openbsc/src/osmo-bsc_nat/bsc_nat_call_control.c
new file mode 100644
index 000000000..163261e1b
--- /dev/null
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_call_control.c
@@ -0,0 +1,37 @@
+/* Local Call-Control Filter Code */
+/*
+ * (C) 2013 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2013 by On-Waves
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <openbsc/bsc_nat.h>
+#include <openbsc/bsc_msc.h>
+#include <openbsc/vty.h>
+
+#include <osmocom/core/talloc.h>
+
+void bsc_cc_update_msc_ip(struct bsc_nat *nat, const char *ip)
+{
+ if (ip) {
+ bsc_replace_string(nat, &nat->local_dest->ip, ip);
+ } else {
+ talloc_free(nat->local_dest->ip);
+ nat->local_dest->ip = NULL;
+ }
+}
+
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
index bc8c4c1f3..aa152d50e 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
@@ -89,6 +89,12 @@ struct bsc_nat *bsc_nat_alloc(void)
return NULL;
}
+ nat->local_dest = talloc_zero(nat, struct bsc_msc_dest);
+ if (!nat->local_dest) {
+ talloc_free(nat);
+ return NULL;
+ }
+
INIT_LLIST_HEAD(&nat->sccp_connections);
INIT_LLIST_HEAD(&nat->bsc_connections);
INIT_LLIST_HEAD(&nat->paging_groups);
@@ -101,6 +107,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->local_dests);
nat->stats.sccp.conn = osmo_counter_alloc("nat.sccp.conn");
nat->stats.sccp.calls = osmo_counter_alloc("nat.sccp.calls");
@@ -116,6 +123,10 @@ struct bsc_nat *bsc_nat_alloc(void)
nat->main_dest->ip = talloc_strdup(nat, "127.0.0.1");
nat->main_dest->port = 5000;
+ llist_add(&nat->local_dest->list, &nat->local_dests);
+ nat->local_dest->ip = NULL;
+ nat->local_dest->port = 0;
+
return nat;
}
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
index 1f1c1b552..76a0a7219 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
@@ -156,6 +156,12 @@ static int config_write_nat(struct vty *vty)
if (_nat->local_prefix)
vty_out(vty, " local-call prefix %s%s",
_nat->local_prefix, VTY_NEWLINE);
+ if (_nat->local_dest->ip) {
+ vty_out(vty, " local-call ip %s%s",
+ _nat->local_dest->ip, VTY_NEWLINE);
+ vty_out(vty, " local-call port %d%s",
+ _nat->local_dest->port, VTY_NEWLINE);
+ }
return CMD_SUCCESS;
}
@@ -802,6 +808,35 @@ DEFUN(cfg_nat_no_local_prefix,
return CMD_SUCCESS;
}
+DEFUN(cfg_nat_local_ip,
+ cfg_nat_local_ip_cmd,
+ "local-call ip A.B.C.D",
+ LOCAL_STR "Destination Address\n" IP_STR)
+{
+ bsc_cc_update_msc_ip(_nat, argv[0]);
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_nat_no_local_ip,
+ cfg_nat_no_local_ip_cmd,
+ "no local-call ip",
+ NO_STR LOCAL_STR "Destination Address\n")
+{
+ bsc_cc_update_msc_ip(_nat, NULL);
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_nat_local_port,
+ cfg_nat_local_port_cmd,
+ "local-call port <1-65500>",
+ LOCAL_STR
+ "Configure the port\n"
+ "Port number\n")
+{
+ _nat->local_dest->port = atoi(argv[0]);
+ return CMD_SUCCESS;
+}
+
#undef LOCAL_STR
/* per BSC configuration */
@@ -1269,6 +1304,9 @@ int bsc_nat_vty_init(struct bsc_nat *nat)
/* local call handling */
install_element(NAT_NODE, &cfg_nat_local_prefix_cmd);
install_element(NAT_NODE, &cfg_nat_no_local_prefix_cmd);
+ install_element(NAT_NODE, &cfg_nat_local_ip_cmd);
+ install_element(NAT_NODE, &cfg_nat_no_local_ip_cmd);
+ install_element(NAT_NODE, &cfg_nat_local_port_cmd);
install_element(NAT_NODE, &cfg_nat_pgroup_cmd);
install_element(NAT_NODE, &cfg_nat_no_pgroup_cmd);