From cd895377ca919cf9e40e261ffb0f0f799ea4581d Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 29 Mar 2010 08:04:09 +0200 Subject: [PATCH] nat: Handle MSC disconnect by closing all NAT connections When we disconnect from the MSC handle it by pushing the problem to our connected clients. We will simply close all connections, reject all new BSC connections and attempt to reconnect to the MSC. --- openbsc/src/nat/bsc_nat.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/openbsc/src/nat/bsc_nat.c b/openbsc/src/nat/bsc_nat.c index db2d60532..6d45ac0f0 100644 --- a/openbsc/src/nat/bsc_nat.c +++ b/openbsc/src/nat/bsc_nat.c @@ -59,6 +59,7 @@ static struct bsc_fd bsc_listen; static struct bsc_nat *nat; static void bsc_write(struct bsc_connection *bsc, const u_int8_t *data, unsigned int length); +static void remove_bsc_connection(struct bsc_connection *connection); static struct bsc_nat *bsc_nat_alloc(void) { @@ -422,8 +423,13 @@ exit: static void msc_connection_was_lost(struct bsc_msc_connection *con) { - LOGP(DMSC, LOGL_FATAL, "Lost the connection.\n"); - exit(0); + struct bsc_connection *bsc, *tmp; + + LOGP(DMSC, LOGL_ERROR, "Closing all connections downstream.\n"); + llist_for_each_entry_safe(bsc, tmp, &nat->bsc_connections, list_entry) + remove_bsc_connection(bsc); + + bsc_msc_schedule_connect(con); } static int ipaccess_msc_read_cb(struct bsc_fd *bfd) @@ -669,6 +675,14 @@ static int ipaccess_listen_bsc_cb(struct bsc_fd *bfd, unsigned int what) return ret; } + /* + * if we are not connected to a msc... just close the socket + */ + if (!msc_con->is_connected) { + LOGP(DNAT, LOGL_NOTICE, "Disconnecting BSC due lack of MSC connection.\n"); + return 0; + } + /* todo... do something with the connection */ /* todo... use GNUtls to see if we want to trust this as a BTS */