[PATCH] osmo-bsc[master]: Make RSL connection attempts time out.

2018-02-13 Thread Stefan Sperling
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/6386

to look at the new patch set (#2).

Make RSL connection attempts time out.

If a BTS/TRX does not respond to the "IPA RSL Connect" command,
pretend that the BTS has sent a NACK for the connection.

To ensure that osmo_timer_del(&trx->rsl_connection_timeout) is not called
before this timer is initialized with osmo_timer_setup(), the E1 layer now
drops incoming RSL messages from a BTS/TRX in LOCKED administrative state.

We cancel the timeout if we receive an RSL Connect ACK or NACK from the BTS,
and if the underlying E1 link does down.

While here, add a missing message buffer free() in bts_isdn_sign_link().
The callers do not free it.

Change-Id: Ia72b65a0f15f47dcb8a6f944f6c3695a4a64b923
Related: OS#2716
---
M include/osmocom/bsc/gsm_data_shared.h
M src/libbsc/abis_nm.c
M src/libbsc/bts_ipaccess_nanobts.c
M src/libbsc/e1_config.c
4 files changed, 44 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/86/6386/2

diff --git a/include/osmocom/bsc/gsm_data_shared.h 
b/include/osmocom/bsc/gsm_data_shared.h
index e3e1389..b753e54 100644
--- a/include/osmocom/bsc/gsm_data_shared.h
+++ b/include/osmocom/bsc/gsm_data_shared.h
@@ -351,6 +351,9 @@
uint8_t rsl_tei;
struct e1inp_sign_link *rsl_link;
 
+   /* Timeout for initiating the RSL connection. */
+   struct osmo_timer_list rsl_connect_timeout;
+
/* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
struct e1inp_sign_link *oml_link;
 
diff --git a/src/libbsc/abis_nm.c b/src/libbsc/abis_nm.c
index 33af213..403b94c 100644
--- a/src/libbsc/abis_nm.c
+++ b/src/libbsc/abis_nm.c
@@ -2660,6 +2660,7 @@
DEBUGPC(DNM, "STREAM=0x%02x ",
*TLVP_VAL(&tp, NM_ATT_IPACC_STREAM_ID));
DEBUGPC(DNM, "\n");
+   osmo_timer_del(&sign_link->trx->rsl_connect_timeout);
break;
case NM_MT_IPACC_RSL_CONNECT_NACK:
LOGP(DNM, LOGL_ERROR, "RSL CONNECT NACK ");
@@ -2668,6 +2669,7 @@
abis_nm_nack_cause_name(*TLVP_VAL(&tp, 
NM_ATT_NACK_CAUSES)));
else
LOGPC(DNM, LOGL_ERROR, "\n");
+   osmo_timer_del(&sign_link->trx->rsl_connect_timeout);
break;
case NM_MT_IPACC_SET_NVATTR_ACK:
DEBUGPC(DNM, "SET NVATTR ACK\n");
@@ -2776,6 +2778,19 @@
attr_len);
 }
 
+static void rsl_connect_timeout(void *data)
+{
+   struct gsm_bts_trx *trx = data;
+   struct ipacc_ack_signal_data signal;
+
+   LOGP(DRSL, LOGL_NOTICE, "(bts=%d,trx=%d) RSL connection request timed 
out\n", trx->bts->nr, trx->nr);
+
+   /* Fake an RSL CONECT NACK message from the BTS. */
+   signal.trx = trx;
+   signal.msg_type = NM_MT_IPACC_RSL_CONNECT_NACK;
+   osmo_signal_dispatch(SS_NM, S_NM_IPACC_NACK, &signal);
+}
+
 int abis_nm_ipaccess_rsl_connect(struct gsm_bts_trx *trx,
 uint32_t ip, uint16_t port, uint8_t stream)
 {
@@ -2785,6 +2800,9 @@
NM_ATT_IPACC_DST_IP, 0, 0, 0, 0 };
 
int attr_len = sizeof(attr);
+   int error;
+
+   osmo_timer_setup(&trx->rsl_connect_timeout, rsl_connect_timeout, trx);
 
ia.s_addr = htonl(ip);
attr[1] = stream;
@@ -2799,9 +2817,13 @@
DEBUGP(DNM, "ip.access RSL CONNECT IP=%s PORT=%u STREAM=0x%02x\n",
inet_ntoa(ia), port, stream);
 
-   return abis_nm_ipaccess_msg(trx->bts, NM_MT_IPACC_RSL_CONNECT,
-   NM_OC_BASEB_TRANSC, trx->bts->bts_nr,
-   trx->nr, 0xff, attr, attr_len);
+   error = abis_nm_ipaccess_msg(trx->bts, NM_MT_IPACC_RSL_CONNECT,
+NM_OC_BASEB_TRANSC, trx->bts->bts_nr,
+trx->nr, 0xff, attr, attr_len);
+   if (error == 0)
+   osmo_timer_schedule(&trx->rsl_connect_timeout, 60, 0);
+
+   return error;
 }
 
 /* restart / reboot an ip.access nanoBTS */
diff --git a/src/libbsc/bts_ipaccess_nanobts.c 
b/src/libbsc/bts_ipaccess_nanobts.c
index 03bb708..cf85961 100644
--- a/src/libbsc/bts_ipaccess_nanobts.c
+++ b/src/libbsc/bts_ipaccess_nanobts.c
@@ -470,15 +470,19 @@
 {
/* No matter what link went down, we close both signal links. */
struct e1inp_ts *ts = &line->ts[E1INP_SIGN_OML-1];
+   struct gsm_bts *bts = NULL;
struct e1inp_sign_link *link;
 
llist_for_each_entry(link, &ts->sign.sign_links, list) {
-   struct gsm_bts *bts = link->trx->bts;
-
-   ipaccess_drop_oml(bts);
-   /* Yes, we only use the first element of the list. */
-   break;
+   /* Get bts pointer from the first element of the list. */
+   if (bts == N

[PATCH] osmo-bsc[master]: Make RSL connection attempts time out.

2018-02-12 Thread Stefan Sperling

Review at  https://gerrit.osmocom.org/6386

Make RSL connection attempts time out.

If a BTS/TRX does not respond to the "IPA RSL Connect" command,
pretend that the BTS has sent a NACk for the connection.

This is a proof-of-concept which still has (at least) two problems:

1) It assumes that osmo_timer_del() can be called even if osmo_timer_setup()
   has not yet been called. This can happen in case we receive an RSL Connect
   ACK/NACK from a BTS even though we have not yet sent an RSL Connect.
   While this seems to work, it relies on private implementation details
   of the osmo_timer code.
   Fixing this would require moving osmo_timer_setup() somewhere else.
   A good candidate might be gsm_bts_trx_alloc(), however that function
   is in libcommon, which means the RSL connection timeout function
   would also have to move there (it is currently a symbol in libbsc).
   Can anyone suggest a nicer solution?

2) We cancel the timeout if we receive an RSL Connect ACK or NACK from
   the BTS, but surely there are other situations where we'd want to
   cancel it, such as if underlying state related to this BTS/TRX gets
   reset. Can anyone suggest a good opportunity in the code for
   cancelling the timeout in such cases?

Change-Id: Ia72b65a0f15f47dcb8a6f944f6c3695a4a64b923
Related: OS#2716
---
M include/osmocom/bsc/gsm_data_shared.h
M src/libbsc/abis_nm.c
2 files changed, 28 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/86/6386/1

diff --git a/include/osmocom/bsc/gsm_data_shared.h 
b/include/osmocom/bsc/gsm_data_shared.h
index e3e1389..b753e54 100644
--- a/include/osmocom/bsc/gsm_data_shared.h
+++ b/include/osmocom/bsc/gsm_data_shared.h
@@ -351,6 +351,9 @@
uint8_t rsl_tei;
struct e1inp_sign_link *rsl_link;
 
+   /* Timeout for initiating the RSL connection. */
+   struct osmo_timer_list rsl_connect_timeout;
+
/* Some BTS (specifically Ericsson RBS) have a per-TRX OML Link */
struct e1inp_sign_link *oml_link;
 
diff --git a/src/libbsc/abis_nm.c b/src/libbsc/abis_nm.c
index 33af213..a67add6 100644
--- a/src/libbsc/abis_nm.c
+++ b/src/libbsc/abis_nm.c
@@ -2660,6 +2660,7 @@
DEBUGPC(DNM, "STREAM=0x%02x ",
*TLVP_VAL(&tp, NM_ATT_IPACC_STREAM_ID));
DEBUGPC(DNM, "\n");
+   osmo_timer_del(&sign_link->trx->rsl_connect_timeout);
break;
case NM_MT_IPACC_RSL_CONNECT_NACK:
LOGP(DNM, LOGL_ERROR, "RSL CONNECT NACK ");
@@ -2668,6 +2669,7 @@
abis_nm_nack_cause_name(*TLVP_VAL(&tp, 
NM_ATT_NACK_CAUSES)));
else
LOGPC(DNM, LOGL_ERROR, "\n");
+   osmo_timer_del(&sign_link->trx->rsl_connect_timeout);
break;
case NM_MT_IPACC_SET_NVATTR_ACK:
DEBUGPC(DNM, "SET NVATTR ACK\n");
@@ -2776,6 +2778,19 @@
attr_len);
 }
 
+static void rsl_connect_timeout(void *data)
+{
+   struct gsm_bts_trx *trx = data;
+   struct ipacc_ack_signal_data signal;
+
+   LOGP(DRSL, LOGL_NOTICE, "(bts=%d,trx=%d) RSL connection request timed 
out\n", trx->bts->nr, trx->nr);
+
+   /* Fake an RSL CONECT NACK message from the BTS. */
+   signal.trx = trx;
+   signal.msg_type = NM_MT_IPACC_RSL_CONNECT_NACK;
+   osmo_signal_dispatch(SS_NM, S_NM_IPACC_NACK, &signal);
+}
+
 int abis_nm_ipaccess_rsl_connect(struct gsm_bts_trx *trx,
 uint32_t ip, uint16_t port, uint8_t stream)
 {
@@ -2785,6 +2800,7 @@
NM_ATT_IPACC_DST_IP, 0, 0, 0, 0 };
 
int attr_len = sizeof(attr);
+   int error;
 
ia.s_addr = htonl(ip);
attr[1] = stream;
@@ -2799,9 +2815,15 @@
DEBUGP(DNM, "ip.access RSL CONNECT IP=%s PORT=%u STREAM=0x%02x\n",
inet_ntoa(ia), port, stream);
 
-   return abis_nm_ipaccess_msg(trx->bts, NM_MT_IPACC_RSL_CONNECT,
-   NM_OC_BASEB_TRANSC, trx->bts->bts_nr,
-   trx->nr, 0xff, attr, attr_len);
+   error = abis_nm_ipaccess_msg(trx->bts, NM_MT_IPACC_RSL_CONNECT,
+NM_OC_BASEB_TRANSC, trx->bts->bts_nr,
+trx->nr, 0xff, attr, attr_len);
+   if (error == 0) {
+   osmo_timer_setup(&trx->rsl_connect_timeout, 
rsl_connect_timeout, trx);
+   osmo_timer_schedule(&trx->rsl_connect_timeout, 60, 0);
+   }
+
+   return error;
 }
 
 /* restart / reboot an ip.access nanoBTS */

-- 
To view, visit https://gerrit.osmocom.org/6386
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia72b65a0f15f47dcb8a6f944f6c3695a4a64b923
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Owner: Stefan Sperling