diff options
author | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2013-09-02 15:42:08 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2013-09-03 15:33:29 +0200 |
commit | 5c5e942765d186e4a7979bc29d5b0eaf3f305e2a (patch) | |
tree | f7e495e94313ec68c2b3f6a4590c0c90dc82ebeb | |
parent | e581cd18c1d89efdeb3015286b6c1d13c67cc75c (diff) |
nat/vty: Allow to configure an optional local-call ip address
-rw-r--r-- | openbsc/include/openbsc/bsc_nat.h | 3 | ||||
-rw-r--r-- | openbsc/src/osmo-bsc_nat/Makefile.am | 3 | ||||
-rw-r--r-- | openbsc/src/osmo-bsc_nat/bsc_nat_call_control.c | 37 | ||||
-rw-r--r-- | openbsc/src/osmo-bsc_nat/bsc_nat_utils.c | 11 | ||||
-rw-r--r-- | openbsc/src/osmo-bsc_nat/bsc_nat_vty.c | 38 | ||||
-rw-r--r-- | openbsc/tests/vty_test_runner.py | 9 |
6 files changed, 100 insertions, 1 deletions
diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h index e25ee0054..b6a3781d0 100644 --- a/openbsc/include/openbsc/bsc_nat.h +++ b/openbsc/include/openbsc/bsc_nat.h @@ -325,6 +325,8 @@ struct bsc_nat { struct bsc_nat_ussd_con *ussd_con; /* Local Call-Control */ + struct llist_head local_dests; + struct bsc_msc_dest *local_dest; char *local_prefix; regex_t local_prefix_regexp; @@ -444,6 +446,7 @@ int bsc_ussd_init(struct bsc_nat *nat); int bsc_ussd_check(struct nat_sccp_connection *con, struct bsc_nat_parsed *parsed, struct msgb *msg); int bsc_ussd_close_connections(struct bsc_nat *nat); +void bsc_cc_update_msc_ip(struct bsc_nat *bsc, const char *ip); struct msgb *bsc_nat_rewrite_msg(struct bsc_nat *nat, struct msgb *msg, struct bsc_nat_parsed *, const char *imsi); /** paging group handling */ 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); diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py index 453e1acc7..1078d120f 100644 --- a/openbsc/tests/vty_test_runner.py +++ b/openbsc/tests/vty_test_runner.py @@ -369,12 +369,21 @@ class TestVTYNAT(TestVTYGenericBSC): self.assertTrue(res) def testLocalPrefix(self): + """This tests that these commands are present""" + self.vty.enable() self.vty.command("configure terminal") self.vty.command("nat") self.vty.verify("no local-call prefix", ['']) self.vty.verify("local-call prefix *232334", ['']) self.vty.verify("no local-call prefix", ['']) + self.vty.command("end") + + self.vty.command("configure terminal") + self.vty.command("nat") + self.vty.verify("local-call ip 10.23.24.7", ['']) + self.vty.verify("local-call port 4000", ['']) + self.vty.verify("no local-call ip", ['']) def add_nat_test(suite, workdir): |