From patchwork Thu Mar 31 15:37:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max X-Patchwork-Id: 604200 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (lists.osmocom.org [IPv6:2a01:4f8:191:444b::2:7]) by ozlabs.org (Postfix) with ESMTP id 3qbTDp3P4Hz9sdt for ; Fri, 1 Apr 2016 02:38:05 +1100 (AEDT) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id D396B1C71A; Thu, 31 Mar 2016 15:38:03 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from mail.sysmocom.de (mail.sysmocom.de [IPv6:2a01:4f8:191:444c::2:4]) by lists.osmocom.org (Postfix) with ESMTP id DA3B01C70B for ; Thu, 31 Mar 2016 15:38:01 +0000 (UTC) Received: from mail.sysmocom.de (mail.sysmocom.de [144.76.43.93]) by mail.sysmocom.de (Postfix) with ESMTP id 084A3196BB9; Thu, 31 Mar 2016 15:37:31 +0000 (UTC) Received: from pbell.local (ip5b418565.dynamic.kabel-deutschland.de [91.65.133.101]) by mail.sysmocom.de (Postfix) with ESMTPSA id 984A0196BB8; Thu, 31 Mar 2016 15:37:30 +0000 (UTC) From: msuraev@sysmocom.de To: openbsc@lists.osmocom.org Subject: [PATCH] NAT: move BSC config into separate file Date: Thu, 31 Mar 2016 17:37:29 +0200 Message-Id: <1459438649-28463-1-git-send-email-msuraev@sysmocom.de> X-Mailer: git-send-email 2.8.0 X-Virus-Scanned: ClamAV using ClamSMTP X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Development of OpenBSC, OsmoBSC, OsmoNITB, OsmoCSCN" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Max Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" From: Max Introduce new configuration option bscs-config-file which includes BSC configuration from the given file. Both absolute and relative (to the main config file) paths are supported. Add 'show bsc-config' command to display current BSC configuration. Note: it is still possible to have BSC configuration in the main file (provided proper index number is used) and in runtime but BSC configuration is no longer saved automatically. The management of included configuration file is left to external tools. Update configuration examples. Fixes: OS#1669 --- openbsc/doc/examples/osmo-bsc_nat/bscs.config | 13 ++++++++ openbsc/doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg | 8 +---- openbsc/include/openbsc/bsc_nat.h | 5 ++++ openbsc/osmoappdesc.py | 3 ++ openbsc/src/osmo-bsc_nat/bsc_nat.c | 5 +++- openbsc/src/osmo-bsc_nat/bsc_nat_vty.c | 35 +++++++++++++++++++++- 6 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 openbsc/doc/examples/osmo-bsc_nat/bscs.config diff --git a/openbsc/doc/examples/osmo-bsc_nat/bscs.config b/openbsc/doc/examples/osmo-bsc_nat/bscs.config new file mode 100644 index 0000000..a10a565 --- /dev/null +++ b/openbsc/doc/examples/osmo-bsc_nat/bscs.config @@ -0,0 +1,13 @@ +nat + bsc 0 + token lol + location_area_code 1234 + description bsc + max-endpoints 32 + paging forbidden 0 + bsc 1 + token what + location_area_code 5678 + description bsc + max-endpoints 32 + paging forbidden 0 diff --git a/openbsc/doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg b/openbsc/doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg index 737d104..2e00bc2 100644 --- a/openbsc/doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg +++ b/openbsc/doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg @@ -62,11 +62,5 @@ nat timeout ping 20 timeout pong 5 ip-dscp 0 + bscs-config-file bscs.config access-list bla imsi-allow ^11$ - - bsc 0 - token bla - location_area_code 1234 - description bsc - max-endpoints 32 - paging forbidden 0 diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h index 309adb1..ff7f1dd 100644 --- a/openbsc/include/openbsc/bsc_nat.h +++ b/openbsc/include/openbsc/bsc_nat.h @@ -264,6 +264,11 @@ struct bsc_nat { struct bsc_endpoint *bsc_endpoints; + /* path to file with BSC config */ + char *include_file; + char *include_path; + char *include_base; + /* filter */ char *acc_lst_name; diff --git a/openbsc/osmoappdesc.py b/openbsc/osmoappdesc.py index 76f03fc..d10ecae 100644 --- a/openbsc/osmoappdesc.py +++ b/openbsc/osmoappdesc.py @@ -26,6 +26,9 @@ nitb_e1_configs = [ "doc/examples/osmo-nitb/rbs2308/openbsc.cfg" ] +copy_files = [ + "doc/examples/osmo-bsc_nat/bscs.config" +] app_configs = { "osmo-bsc": ["doc/examples/osmo-bsc/osmo-bsc.cfg"], diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat.c b/openbsc/src/osmo-bsc_nat/bsc_nat.c index cacb919..54f5189 100644 --- a/openbsc/src/osmo-bsc_nat/bsc_nat.c +++ b/openbsc/src/osmo-bsc_nat/bsc_nat.c @@ -34,6 +34,7 @@ #include #include #include +#include #define _GNU_SOURCE #include @@ -1626,6 +1627,8 @@ int main(int argc, char **argv) local_addr.s_addr = INADDR_ANY; handle_options(argc, argv); + nat->include_base = dirname(talloc_strdup(tall_bsc_ctx, config_file)); + rate_ctr_init(tall_bsc_ctx); osmo_stats_init(tall_bsc_ctx); @@ -1651,7 +1654,7 @@ int main(int argc, char **argv) /* seed the PRNG */ srand(time(NULL)); - + LOGP(DNAT, LOGL_NOTICE, "BSCs configured from %s\n", nat->include_path); /* * Setup the MGCP code.. diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c index cd8293c..6c50e29 100644 --- a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c +++ b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c @@ -96,6 +96,8 @@ static int config_write_nat(struct vty *vty) vty_out(vty, " timeout auth %d%s", _nat->auth_timeout, VTY_NEWLINE); vty_out(vty, " timeout ping %d%s", _nat->ping_timeout, VTY_NEWLINE); vty_out(vty, " timeout pong %d%s", _nat->pong_timeout, VTY_NEWLINE); + if (_nat->include_file) + vty_out(vty, " bscs-config-file %s%s", _nat->include_file, VTY_NEWLINE); if (_nat->token) vty_out(vty, " token %s%s", _nat->token, VTY_NEWLINE); vty_out(vty, " ip-dscp %d%s", _nat->bsc_ip_dscp, VTY_NEWLINE); @@ -181,6 +183,12 @@ static int config_write_bsc(struct vty *vty) return CMD_SUCCESS; } +DEFUN(show_bscs, show_bscs_cmd, "show bsc-config", + SHOW_STR "Show configured BSCs\n" + "Both from included file and vty\n") +{ + return config_write_bsc(vty); +} DEFUN(show_sccp, show_sccp_cmd, "show sccp connections", SHOW_STR "Display information about SCCP\n" @@ -487,6 +495,29 @@ DEFUN(cfg_nat_acc_lst_name, return CMD_SUCCESS; } +DEFUN(cfg_nat_include, + cfg_nat_include_cmd, + "bscs-config-file NAME", + "Set the filename of the BSC configuration to include.\n" + "The filename to be included.") +{ + const char *conf = argv[0]; + + if ('/' == conf[0]) + bsc_replace_string(_nat, &_nat->include_path, conf); + else + _nat->include_path = talloc_asprintf(_nat, "%s/%s", _nat->include_base, conf); + + if (vty_read_config_file(_nat->include_path, NULL) < 0) { + vty_out(vty, "Failed to parse the config file %s%s", + _nat->include_path, + VTY_NEWLINE); + return CMD_WARNING; + } + bsc_replace_string(_nat, &_nat->include_file, conf); + return CMD_SUCCESS; +} + DEFUN(cfg_nat_no_acc_lst_name, cfg_nat_no_acc_lst_name_cmd, "no access-list-name", @@ -1176,6 +1207,7 @@ int bsc_nat_vty_init(struct bsc_nat *nat) install_element_ve(&show_msc_cmd); install_element_ve(&test_regex_cmd); install_element_ve(&show_bsc_mgcp_cmd); + install_element_ve(&show_bscs_cmd); install_element_ve(&show_bar_lst_cmd); install_element_ve(&show_prefix_tree_cmd); install_element_ve(&show_ussd_connection_cmd); @@ -1197,6 +1229,7 @@ int bsc_nat_vty_init(struct bsc_nat *nat) install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd); install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd); install_element(NAT_NODE, &cfg_nat_no_acc_lst_name_cmd); + install_element(NAT_NODE, &cfg_nat_include_cmd); install_element(NAT_NODE, &cfg_nat_imsi_black_list_fn_cmd); install_element(NAT_NODE, &cfg_nat_no_imsi_black_list_fn_cmd); install_element(NAT_NODE, &cfg_nat_ussd_lst_name_cmd); @@ -1233,7 +1266,7 @@ int bsc_nat_vty_init(struct bsc_nat *nat) /* BSC subgroups */ install_element(NAT_NODE, &cfg_bsc_cmd); - install_node(&bsc_node, config_write_bsc); + install_node(&bsc_node, NULL); vty_install_default(NAT_BSC_NODE); install_element(NAT_BSC_NODE, &cfg_bsc_token_cmd); install_element(NAT_BSC_NODE, &cfg_bsc_auth_key_cmd);