From e575ce69ce3f973e0dd0157acc8853e5ccbe9330 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 11 May 2010 19:07:39 +0800 Subject: nat: Print the MSC status with a new vty command. --- openbsc/include/openbsc/bsc_nat.h | 1 + openbsc/src/nat/bsc_nat.c | 29 ++++++++++++++--------------- openbsc/src/nat/bsc_nat_vty.c | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h index 2d5e2287e..4be7e3a67 100644 --- a/openbsc/include/openbsc/bsc_nat.h +++ b/openbsc/include/openbsc/bsc_nat.h @@ -213,6 +213,7 @@ struct bsc_nat { char *msc_ip; int msc_port; int first_contact; + struct bsc_msc_connection *msc_con; /* timeouts */ int auth_timeout; diff --git a/openbsc/src/nat/bsc_nat.c b/openbsc/src/nat/bsc_nat.c index 5b2184ad2..625622b83 100644 --- a/openbsc/src/nat/bsc_nat.c +++ b/openbsc/src/nat/bsc_nat.c @@ -53,7 +53,6 @@ struct log_target *stderr_target; static const char *config_file = "bsc-nat.cfg"; static struct in_addr local_addr; -static struct bsc_msc_connection *msc_con; static struct bsc_fd bsc_listen; static const char *msc_ip = NULL; @@ -92,7 +91,7 @@ int gsm0408_rcvmsg(struct msgb *msg, u_int8_t link_id) static void queue_for_msc(struct bsc_msc_connection *con, struct msgb *msg) { - if (write_queue_enqueue(&msc_con->write_queue, msg) != 0) { + if (write_queue_enqueue(&nat->msc_con->write_queue, msg) != 0) { LOGP(DINP, LOGL_ERROR, "Failed to enqueue the write.\n"); msgb_free(msg); } @@ -207,7 +206,7 @@ static void nat_send_rlsd(struct sccp_connections *conn) ipaccess_prepend_header(msg, IPAC_PROTO_SCCP); - queue_for_msc(msc_con, msg); + queue_for_msc(nat->msc_con, msg); } static void nat_send_rlc(struct sccp_source_reference *src, @@ -230,7 +229,7 @@ static void nat_send_rlc(struct sccp_source_reference *src, ipaccess_prepend_header(msg, IPAC_PROTO_SCCP); - queue_for_msc(msc_con, msg); + queue_for_msc(nat->msc_con, msg); } static void send_mgcp_reset(struct bsc_connection *bsc) @@ -253,7 +252,7 @@ static void initialize_msc_if_needed() return; nat->first_contact = 1; - msc_send_reset(msc_con); + msc_send_reset(nat->msc_con); } /* @@ -423,7 +422,7 @@ static void msc_send_reset(struct bsc_msc_connection *msc_con) msg->l2h = msgb_put(msg, sizeof(reset)); memcpy(msg->l2h, reset, msgb_l2len(msg)); - queue_for_msc(msc_con, msg); + queue_for_msc(nat->msc_con, msg); LOGP(DMSC, LOGL_NOTICE, "Scheduled GSM0808 reset msg for the MSC.\n"); } @@ -440,7 +439,7 @@ static int ipaccess_msc_read_cb(struct bsc_fd *bfd) else LOGP(DNAT, LOGL_ERROR, "Failed to parse ip access message: %d\n", error); - bsc_msc_lost(msc_con); + bsc_msc_lost(nat->msc_con); return -1; } @@ -627,7 +626,7 @@ static int forward_sccp_to_msc(struct bsc_connection *bsc, struct msgb *msg) } /* send the non-filtered but maybe modified msg */ - queue_for_msc(msc_con, msg); + queue_for_msc(nat->msc_con, msg); talloc_free(parsed); return 0; @@ -736,7 +735,7 @@ static int ipaccess_listen_bsc_cb(struct bsc_fd *bfd, unsigned int what) /* * if we are not connected to a msc... just close the socket */ - if (!msc_con->is_connected) { + if (!nat->msc_con->is_connected) { LOGP(DNAT, LOGL_NOTICE, "Disconnecting BSC due lack of MSC connection.\n"); close(fd); return 0; @@ -961,16 +960,16 @@ int main(int argc, char** argv) return -4; /* connect to the MSC */ - msc_con = bsc_msc_create(nat->msc_ip, nat->msc_port); - if (!msc_con) { + nat->msc_con = bsc_msc_create(nat->msc_ip, nat->msc_port); + if (!nat->msc_con) { fprintf(stderr, "Creating a bsc_msc_connection failed.\n"); exit(1); } - msc_con->connection_loss = msc_connection_was_lost; - msc_con->write_queue.read_cb = ipaccess_msc_read_cb; - msc_con->write_queue.write_cb = ipaccess_msc_write_cb;; - bsc_msc_connect(msc_con); + nat->msc_con->connection_loss = msc_connection_was_lost; + nat->msc_con->write_queue.read_cb = ipaccess_msc_read_cb; + nat->msc_con->write_queue.write_cb = ipaccess_msc_write_cb;; + bsc_msc_connect(nat->msc_con); /* wait for the BSC */ if (listen_for_bsc(&bsc_listen, &local_addr, 5000) < 0) { diff --git a/openbsc/src/nat/bsc_nat_vty.c b/openbsc/src/nat/bsc_nat_vty.c index ff6a5ecc0..79b784998 100644 --- a/openbsc/src/nat/bsc_nat_vty.c +++ b/openbsc/src/nat/bsc_nat_vty.c @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -181,6 +182,22 @@ DEFUN(show_stats, return CMD_SUCCESS; } +DEFUN(show_msc, + show_msc_cmd, + "show msc connection", + SHOW_STR "Show the status of the MSC connection.") +{ + if (!_nat->msc_con) { + vty_out(vty, "The MSC is not yet configured.\n"); + return CMD_WARNING; + } + + vty_out(vty, "MSC on %s:%d is connected: %d%s\n", + _nat->msc_con->ip, _nat->msc_con->port, + _nat->msc_con->is_connected, VTY_NEWLINE); + return CMD_SUCCESS; +} + DEFUN(close_bsc, close_bsc_cmd, "close bsc connection BSC_NR", @@ -406,6 +423,7 @@ int bsc_nat_vty_init(struct bsc_nat *nat) install_element(VIEW_NODE, &show_bsc_cfg_cmd); install_element(VIEW_NODE, &show_stats_cmd); install_element(VIEW_NODE, &close_bsc_cmd); + install_element(VIEW_NODE, &show_msc_cmd); openbsc_vty_add_cmds(); -- cgit v1.2.3