[PATCH 4/8] bsc/nat: Fix the structure of the identity request message

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Holger Hans Peter Freyther holger at freyther.de
Mon Jun 15 09:55:38 UTC 2015


From: Holger Hans Peter Freyther <holger at moiji-mobile.com>

Unfortunately the basic structure of the response is broken.
There is a two byte length followed by data. The concept of
a 'tag' happens to be the first byte of the data.

This means we want to write strlen of the token, then we
want to write the NUL and then we need to account for the
tag in front.

Introduce a flag if the new or old format should be used.
This will allow to have new BSCs talk to old NATs without
an additional change. In the long run we can clean that up.
---
 openbsc/include/openbsc/bsc_msc.h   |  2 +-
 openbsc/src/libbsc/bsc_msc.c        | 17 +++++++++++++++--
 openbsc/src/osmo-bsc/osmo_bsc_msc.c |  2 +-
 openbsc/src/osmo-bsc_nat/bsc_nat.c  | 15 +++++++++++----
 4 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/openbsc/include/openbsc/bsc_msc.h b/openbsc/include/openbsc/bsc_msc.h
index 763bae5..2eec163 100644
--- a/openbsc/include/openbsc/bsc_msc.h
+++ b/openbsc/include/openbsc/bsc_msc.h
@@ -60,6 +60,6 @@ void bsc_msc_schedule_connect(struct bsc_msc_connection *);
 
 void bsc_msc_lost(struct bsc_msc_connection *);
 
-struct msgb *bsc_msc_id_get_resp(const char *token);
+struct msgb *bsc_msc_id_get_resp(int fixed, const char *token);
 
 #endif
diff --git a/openbsc/src/libbsc/bsc_msc.c b/openbsc/src/libbsc/bsc_msc.c
index a24efab..fc4530c 100644
--- a/openbsc/src/libbsc/bsc_msc.c
+++ b/openbsc/src/libbsc/bsc_msc.c
@@ -276,7 +276,7 @@ void bsc_msc_schedule_connect(struct bsc_msc_connection *con)
 	osmo_timer_schedule(&con->reconnect_timer, 5, 0);
 }
 
-struct msgb *bsc_msc_id_get_resp(const char *token)
+struct msgb *bsc_msc_id_get_resp(int fixed, const char *token)
 {
 	struct msgb *msg;
 
@@ -291,8 +291,21 @@ struct msgb *bsc_msc_id_get_resp(const char *token)
 		return NULL;
 	}
 
+	/*
+	 * The situation is bizarre. The encoding doesn't follow the
+	 * TLV structure. It is more like a LV and old versions had
+	 * it wrong but we want new versions to old servers so we
+	 * introduce the quirk here.
+	 */
 	msg->l2h = msgb_v_put(msg, IPAC_MSGT_ID_RESP);
-	msgb_l16tv_put(msg, strlen(token) + 1,
+	if (fixed) {
+		msgb_put_u8(msg, 0);
+		msgb_put_u8(msg, strlen(token) + 2);
+		msgb_tv_fixed_put(msg, IPAC_IDTAG_UNITNAME, strlen(token) + 1, (uint8_t *) token);
+	} else {
+		msgb_l16tv_put(msg, strlen(token) + 1,
 			IPAC_IDTAG_UNITNAME, (uint8_t *) token);
+	}
+
 	return msg;
 }
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_msc.c b/openbsc/src/osmo-bsc/osmo_bsc_msc.c
index 129b23e..5127ca8 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_msc.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_msc.c
@@ -456,7 +456,7 @@ static void send_id_get_response(struct osmo_msc_data *data, int fd)
 	struct msc_signal_data sig;
 	struct msgb *msg;
 
-	msg = bsc_msc_id_get_resp(data->bsc_token);
+	msg = bsc_msc_id_get_resp(0, data->bsc_token);
 	if (!msg)
 		return;
 	msc_queue_write(data->msc_con, msg, IPAC_PROTO_IPACCESS);
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat.c b/openbsc/src/osmo-bsc_nat/bsc_nat.c
index 9216654..841262c 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat.c
@@ -357,7 +357,7 @@ static void initialize_msc_if_needed(struct bsc_msc_connection *msc_con)
 
 static void send_id_get_response(struct bsc_msc_connection *msc_con)
 {
-	struct msgb *msg = bsc_msc_id_get_resp(nat->token);
+	struct msgb *msg = bsc_msc_id_get_resp(0, nat->token);
 	if (!msg)
 		return;
 
@@ -960,7 +960,7 @@ static void ipaccess_auth_bsc(struct tlv_parsed *tvp, struct bsc_connection *bsc
 {
 	struct bsc_config *conf;
 	const char *token = (const char *) TLVP_VAL(tvp, IPAC_IDTAG_UNITNAME);
-	const int len = TLVP_LEN(tvp, IPAC_IDTAG_UNITNAME);
+	int len = TLVP_LEN(tvp, IPAC_IDTAG_UNITNAME);
 
 	if (bsc->cfg) {
 		LOGP(DNAT, LOGL_ERROR, "Reauth on fd %d bsc nr %d\n",
@@ -980,11 +980,18 @@ static void ipaccess_auth_bsc(struct tlv_parsed *tvp, struct bsc_connection *bsc
 		return;
 	}
 
+	/*
+	 * New systems have fixed the structure of the message but
+	 * we need to support old ones too.
+	 */
+	if (len >= 2 && token[len - 2] == '\0')
+		len -= 1;
+
 	conf = bsc_config_by_token(bsc->nat, token, len);
 	if (!conf) {
 		LOGP(DNAT, LOGL_ERROR,
-			"No bsc found for token '%s' on fd: %d.\n", token,
-			bsc->write_queue.bfd.fd);
+			"No bsc found for token '%s' len %d on fd: %d.\n", token,
+			bsc->write_queue.bfd.fd, len);
 		bsc_close_connection(bsc);
 		return;
 	}
-- 
2.3.5




More information about the OpenBSC mailing list