From patchwork Tue Feb 23 16:56:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neels Hofmeyr X-Patchwork-Id: 587172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by ozlabs.org (Postfix) with ESMTP id DFDFE14033E for ; Wed, 24 Feb 2016 13:57:51 +1100 (AEDT) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 66A8C1A527; Wed, 24 Feb 2016 02:57:50 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from einhorn.in-berlin.de (einhorn.in-berlin.de [IPv6:2001:bf0:c000::1:8]) by lists.osmocom.org (Postfix) with ESMTP id 714181A503 for ; Wed, 24 Feb 2016 02:57:48 +0000 (UTC) X-Envelope-From: nhofmeyr@sysmocom.de X-Envelope-To: Received: from localhost (p4FC87F7E.dip0.t-ipconnect.de [79.200.127.126]) (authenticated bits=0) by einhorn.in-berlin.de (8.14.4/8.14.4/Debian-4) with ESMTP id u1O2vlWk010453 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 24 Feb 2016 03:57:48 +0100 Message-Id: <201602240257.u1O2vlWk010453@einhorn.in-berlin.de> From: Neels Hofmeyr Date: Wed, 24 Feb 2016 03:56:59 +0100Tue, 23 Feb 2016 15:10:33 +0100 Subject: [PATCH 5/6] enable ctrl bind config for various programs To: openbsc@lists.osmocom.org 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: , Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" Add ctrl_vty_init() calls and feed the ctrl_vty_get_bind_addr() return value to ctrl_interface_setup() in the following programs: osmo-bsc osmo-bsc_nat osmo-nitb osmo-sgsn For osmo-sgsn, move the control interface setup invocation below the config parsing, so that the ctrl_vty_get_bind_addr() can return the configured address. --- openbsc/include/openbsc/bsc_nat.h | 3 ++- openbsc/include/openbsc/ctrl.h | 3 ++- openbsc/include/openbsc/gprs_sgsn.h | 3 ++- openbsc/src/gprs/sgsn_ctrl.c | 5 +++-- openbsc/src/gprs/sgsn_main.c | 31 ++++++++++++++++++++----------- openbsc/src/libbsc/bsc_ctrl_lookup.c | 6 ++++-- openbsc/src/osmo-bsc/osmo_bsc_main.c | 10 +++++++++- openbsc/src/osmo-bsc_nat/bsc_nat.c | 9 ++++++++- openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c | 5 +++-- openbsc/src/osmo-nitb/bsc_hack.c | 10 +++++++++- 10 files changed, 62 insertions(+), 23 deletions(-) diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h index 027b6de..309adb1 100644 --- a/openbsc/include/openbsc/bsc_nat.h +++ b/openbsc/include/openbsc/bsc_nat.h @@ -423,7 +423,8 @@ void bsc_nat_num_rewr_entry_adapt(void *ctx, struct llist_head *head, const stru void bsc_nat_send_mgcp_to_msc(struct bsc_nat *bsc_nat, struct msgb *msg); void bsc_nat_handle_mgcp(struct bsc_nat *bsc, struct msgb *msg); -struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat, int port); +struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat, + const char *bind_addr, int port); void bsc_nat_ctrl_del_pending(struct bsc_cmd_list *pending); int bsc_nat_handle_ctrlif_msg(struct bsc_connection *bsc, struct msgb *msg); diff --git a/openbsc/include/openbsc/ctrl.h b/openbsc/include/openbsc/ctrl.h index 38fa054..c5ac210 100644 --- a/openbsc/include/openbsc/ctrl.h +++ b/openbsc/include/openbsc/ctrl.h @@ -1,3 +1,4 @@ #pragma once -struct ctrl_handle *bsc_controlif_setup(struct gsm_network *net, uint16_t port); +struct ctrl_handle *bsc_controlif_setup(struct gsm_network *net, + const char *bind_addr, uint16_t port); diff --git a/openbsc/include/openbsc/gprs_sgsn.h b/openbsc/include/openbsc/gprs_sgsn.h index 74f0735..49d5407 100644 --- a/openbsc/include/openbsc/gprs_sgsn.h +++ b/openbsc/include/openbsc/gprs_sgsn.h @@ -315,7 +315,8 @@ int sgsn_force_reattach_oldmsg(struct msgb *oldmsg); * ctrl interface related work */ struct gsm_network; -struct ctrl_handle *sgsn_controlif_setup(struct gsm_network *, uint16_t port); +struct ctrl_handle *sgsn_controlif_setup(struct gsm_network *, + const char *bind_addr, uint16_t port); int sgsn_ctrl_cmds_install(void); /* diff --git a/openbsc/src/gprs/sgsn_ctrl.c b/openbsc/src/gprs/sgsn_ctrl.c index eff94e0..0b40703 100644 --- a/openbsc/src/gprs/sgsn_ctrl.c +++ b/openbsc/src/gprs/sgsn_ctrl.c @@ -73,7 +73,8 @@ int sgsn_ctrl_cmds_install(void) return rc; } -struct ctrl_handle *sgsn_controlif_setup(struct gsm_network *net, uint16_t port) +struct ctrl_handle *sgsn_controlif_setup(struct gsm_network *net, + const char *bind_addr, uint16_t port) { - return ctrl_interface_setup(net, port, NULL); + return ctrl_interface_setup(net, bind_addr, port, NULL); } diff --git a/openbsc/src/gprs/sgsn_main.c b/openbsc/src/gprs/sgsn_main.c index b10b0b3..cb762b7 100644 --- a/openbsc/src/gprs/sgsn_main.c +++ b/openbsc/src/gprs/sgsn_main.c @@ -47,6 +47,8 @@ #include #include +#include + #include #include #include @@ -311,22 +313,12 @@ int main(int argc, char **argv) logging_vty_add_cmds(&gprs_log_info); osmo_stats_vty_add_cmds(&gprs_log_info); sgsn_vty_init(); + ctrl_vty_init(tall_bsc_ctx); handle_options(argc, argv); rate_ctr_init(tall_bsc_ctx); - ctrl = sgsn_controlif_setup(NULL, OSMO_CTRL_PORT_SGSN); - if (!ctrl) { - LOGP(DGPRS, LOGL_ERROR, "Failed to create CTRL interface.\n"); - exit(1); - } - - if (sgsn_ctrl_cmds_install() != 0) { - LOGP(DGPRS, LOGL_ERROR, "Failed to install CTRL commands.\n"); - exit(1); - } - gprs_ns_set_log_ss(DNS); bssgp_set_log_ss(DBSSGP); @@ -362,6 +354,23 @@ int main(int argc, char **argv) if (rc < 0) exit(1); + /* start control interface after reading config for + * ctrl_vty_get_bind_addr() */ + LOGP(DGPRS, LOGL_NOTICE, "CTRL at %s %d\n", + ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_SGSN); + ctrl = sgsn_controlif_setup(NULL, ctrl_vty_get_bind_addr(), + OSMO_CTRL_PORT_SGSN); + if (!ctrl) { + LOGP(DGPRS, LOGL_ERROR, "Failed to create CTRL interface.\n"); + exit(1); + } + + if (sgsn_ctrl_cmds_install() != 0) { + LOGP(DGPRS, LOGL_ERROR, "Failed to install CTRL commands.\n"); + exit(1); + } + + rc = sgsn_gtp_init(&sgsn_inst); if (rc) { LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on GTP socket\n"); diff --git a/openbsc/src/libbsc/bsc_ctrl_lookup.c b/openbsc/src/libbsc/bsc_ctrl_lookup.c index b504ccc..2a41c71 100644 --- a/openbsc/src/libbsc/bsc_ctrl_lookup.c +++ b/openbsc/src/libbsc/bsc_ctrl_lookup.c @@ -99,7 +99,9 @@ err_index: return -ERANGE; } -struct ctrl_handle *bsc_controlif_setup(struct gsm_network *net, uint16_t port) +struct ctrl_handle *bsc_controlif_setup(struct gsm_network *net, + const char *bind_addr, uint16_t port) { - return ctrl_interface_setup(net, port, bsc_ctrl_node_lookup); + return ctrl_interface_setup(net, bind_addr, port, + bsc_ctrl_node_lookup); } diff --git a/openbsc/src/osmo-bsc/osmo_bsc_main.c b/openbsc/src/osmo-bsc/osmo_bsc_main.c index 3806b24..3594a5b 100644 --- a/openbsc/src/osmo-bsc/osmo_bsc_main.c +++ b/openbsc/src/osmo-bsc/osmo_bsc_main.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -205,6 +206,7 @@ int main(int argc, char **argv) vty_init(&vty_info); bsc_vty_init(&log_info); bsc_msg_lst_vty_init(tall_bsc_ctx, &access_lists, BSC_NODE); + ctrl_vty_init(tall_bsc_ctx); INIT_LLIST_HEAD(&access_lists); @@ -225,7 +227,13 @@ int main(int argc, char **argv) } bsc_api_init(bsc_gsmnet, osmo_bsc_api()); - bsc_gsmnet->ctrl = bsc_controlif_setup(bsc_gsmnet, OSMO_CTRL_PORT_NITB_BSC); + /* start control interface after reading config for + * ctrl_vty_get_bind_addr() */ + LOGP(DNM, LOGL_NOTICE, "CTRL at %s %d\n", + ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_NITB_BSC); + bsc_gsmnet->ctrl = bsc_controlif_setup(bsc_gsmnet, + ctrl_vty_get_bind_addr(), + OSMO_CTRL_PORT_NITB_BSC); if (!bsc_gsmnet->ctrl) { fprintf(stderr, "Failed to init the control interface. Exiting.\n"); exit(1); diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat.c b/openbsc/src/osmo-bsc_nat/bsc_nat.c index e3dc10e..8404e41 100644 --- a/openbsc/src/osmo-bsc_nat/bsc_nat.c +++ b/openbsc/src/osmo-bsc_nat/bsc_nat.c @@ -52,6 +52,7 @@ #include #include #include +#include #include @@ -1618,6 +1619,7 @@ int main(int argc, char **argv) logging_vty_add_cmds(&log_info); osmo_stats_vty_add_cmds(&log_info); bsc_nat_vty_init(nat); + ctrl_vty_init(tall_bsc_ctx); /* parse options */ @@ -1661,7 +1663,12 @@ int main(int argc, char **argv) exit(1); } - nat->ctrl = bsc_nat_controlif_setup(nat, OSMO_CTRL_PORT_BSC_NAT); + /* start control interface after reading config for + * ctrl_vty_get_bind_addr() */ + LOGP(DNAT, LOGL_NOTICE, "CTRL at %s %d\n", + ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_BSC_NAT); + nat->ctrl = bsc_nat_controlif_setup(nat, ctrl_vty_get_bind_addr(), + OSMO_CTRL_PORT_BSC_NAT); if (!nat->ctrl) { fprintf(stderr, "Creating the control interface failed.\n"); exit(1); diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c b/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c index f3ca924..ec4243e 100644 --- a/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c +++ b/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c @@ -470,13 +470,14 @@ static int get_net_save_cmd(struct ctrl_cmd *cmd, void *data) return CTRL_CMD_ERROR; } -struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat, int port) +struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat, + const char *bind_addr, int port) { struct ctrl_handle *ctrl; int rc; - ctrl = bsc_controlif_setup(NULL, OSMO_CTRL_PORT_BSC_NAT); + ctrl = bsc_controlif_setup(NULL, bind_addr, OSMO_CTRL_PORT_BSC_NAT); if (!ctrl) { fprintf(stderr, "Failed to initialize the control interface. Exiting.\n"); return NULL; diff --git a/openbsc/src/osmo-nitb/bsc_hack.c b/openbsc/src/osmo-nitb/bsc_hack.c index 6f8da98..4bd03fc 100644 --- a/openbsc/src/osmo-nitb/bsc_hack.c +++ b/openbsc/src/osmo-nitb/bsc_hack.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -272,6 +273,7 @@ int main(int argc, char **argv) /* This needs to precede handle_options() */ vty_init(&vty_info); bsc_vty_init(&log_info); + ctrl_vty_init(tall_bsc_ctx); #ifdef BUILD_SMPP if (smpp_openbsc_init(tall_bsc_ctx, 0) < 0) @@ -295,7 +297,13 @@ int main(int argc, char **argv) #endif bsc_api_init(bsc_gsmnet, msc_bsc_api()); - bsc_gsmnet->ctrl = bsc_controlif_setup(bsc_gsmnet, OSMO_CTRL_PORT_NITB_BSC); + /* start control interface after reading config for + * ctrl_vty_get_bind_addr() */ + LOGP(DNM, LOGL_NOTICE, "CTRL at %s %d\n", + ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_NITB_BSC); + bsc_gsmnet->ctrl = bsc_controlif_setup(bsc_gsmnet, + ctrl_vty_get_bind_addr(), + OSMO_CTRL_PORT_NITB_BSC); if (!bsc_gsmnet->ctrl) { printf("Failed to initialize control interface. Exiting.\n"); return -1;