aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-09-02 13:59:01 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-09-03 15:28:37 +0200
commite581cd18c1d89efdeb3015286b6c1d13c67cc75c (patch)
tree6b343ad442b49e6bb2e8ae8e91bd74185f75eee2
parent1b9902c1280b3b1092b726695142a09a1edcb154 (diff)
nat/vty: Implement setting the local-call prefix and generate the regexp
-rw-r--r--openbsc/include/openbsc/bsc_nat.h4
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat_vty.c40
-rw-r--r--openbsc/tests/vty_test_runner.py9
3 files changed, 53 insertions, 0 deletions
diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h
index 635b12541..e25ee0054 100644
--- a/openbsc/include/openbsc/bsc_nat.h
+++ b/openbsc/include/openbsc/bsc_nat.h
@@ -324,6 +324,10 @@ struct bsc_nat {
struct osmo_fd ussd_listen;
struct bsc_nat_ussd_con *ussd_con;
+ /* Local Call-Control */
+ char *local_prefix;
+ regex_t local_prefix_regexp;
+
/* for maintainenance */
int blocked;
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
index 72a68019b..1f1c1b552 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
@@ -153,6 +153,9 @@ static int config_write_nat(struct vty *vty)
write_pgroup_lst(vty, pgroup);
if (_nat->mgcp_ipa)
vty_out(vty, " use-msc-ipa-for-mgcp%s", VTY_NEWLINE);
+ if (_nat->local_prefix)
+ vty_out(vty, " local-call prefix %s%s",
+ _nat->local_prefix, VTY_NEWLINE);
return CMD_SUCCESS;
}
@@ -768,6 +771,39 @@ DEFUN(cfg_nat_use_ipa_for_mgcp,
return CMD_SUCCESS;
}
+#define LOCAL_STR "Locall Call Handling\n"
+
+DEFUN(cfg_nat_local_prefix,
+ cfg_nat_local_prefix_cmd,
+ "local-call prefix REGEXP",
+ LOCAL_STR "Prefix number\n" "Regular expression\n")
+{
+ int rc = gsm_parse_reg(_nat, &_nat->local_prefix_regexp,
+ &_nat->local_prefix, argc, argv);
+ if (rc != 0) {
+ vty_out(vty,
+ "%%setting the prefix failed.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_nat_no_local_prefix,
+ cfg_nat_no_local_prefix_cmd,
+ "no local-call prefix",
+ NO_STR LOCAL_STR "Prefix number\n")
+{
+ if (_nat->local_prefix) {
+ regfree(&_nat->local_prefix_regexp);
+ talloc_free(_nat->local_prefix);
+ _nat->local_prefix = NULL;
+ }
+
+ return CMD_SUCCESS;
+}
+
+#undef LOCAL_STR
+
/* per BSC configuration */
DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR",
"BSC configuration\n" "Identifier of the BSC\n")
@@ -1230,6 +1266,10 @@ int bsc_nat_vty_init(struct bsc_nat *nat)
install_element(NAT_NODE, &cfg_nat_prefix_trie_cmd);
install_element(NAT_NODE, &cfg_nat_no_prefix_trie_cmd);
+ /* 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_pgroup_cmd);
install_element(NAT_NODE, &cfg_nat_no_pgroup_cmd);
install_node(&pgroup_node, config_write_pgroup);
diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py
index ab9670ce0..453e1acc7 100644
--- a/openbsc/tests/vty_test_runner.py
+++ b/openbsc/tests/vty_test_runner.py
@@ -368,6 +368,15 @@ class TestVTYNAT(TestVTYGenericBSC):
res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
self.assertTrue(res)
+ def testLocalPrefix(self):
+ 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", [''])
+
+
def add_nat_test(suite, workdir):
if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
print("Skipping the NAT test")