[PATCH] rsl: fix the unaligned memory access

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/.

Nicolas J. Bouliane nicolas.bouliane at nutaq.com
Mon Apr 22 11:45:13 UTC 2013


From: "Nicolas J. Bouliane" <nicolas.bouliane at nutaq.com>

the armv5 can do 32bit/16bit reads only from the aligned address
use tlv.h macro to copy data to local variable

Signed-off-by: Nicolas J. Bouliane <nicolas.bouliane at nutaq.com>
---
 src/common/rsl.c |   32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/src/common/rsl.c b/src/common/rsl.c
index 9a50a33..4f28cb2 100644
--- a/src/common/rsl.c
+++ b/src/common/rsl.c
@@ -1089,7 +1089,6 @@ static int rsl_tx_ipac_XXcx_ack(struct gsm_lchan *lchan, int inc_pt2,
 {
 	struct msgb *msg;
 	uint8_t chan_nr = gsm_lchan2chan_nr(lchan);
-	uint32_t *att_ip;
 	const char *name;
 	struct in_addr ia;
 
@@ -1116,8 +1115,7 @@ static int rsl_tx_ipac_XXcx_ack(struct gsm_lchan *lchan, int inc_pt2,
 
 	/* locally bound IP */
 	msgb_v_put(msg, RSL_IE_IPAC_LOCAL_IP);
-	att_ip = (uint32_t *) msgb_put(msg, sizeof(uint32_t));
-	*att_ip = htonl(lchan->abis_ip.bound_ip);
+	msgb_put_u32(msg, lchan->abis_ip.bound_ip);
 
 	/* locally bound port */
 	msgb_tv16_put(msg, RSL_IE_IPAC_LOCAL_PORT,
@@ -1199,11 +1197,9 @@ static int tx_ipac_XXcx_nack(struct gsm_lchan *lchan, uint8_t cause,
 		return -ENOMEM;
 
 	if (inc_ipport) {
-		uint32_t *att_ip;
 		/* remote IP */
 		msgb_v_put(msg, RSL_IE_IPAC_REMOTE_IP);
-		att_ip = (uint32_t *) msgb_put(msg, sizeof(uint32_t));
-		*att_ip = htonl(lchan->abis_ip.connect_ip);
+		msgb_put_u32(msg, lchan->abis_ip.connect_ip);
 
 		/* remote port */
 		msgb_tv16_put(msg, RSL_IE_IPAC_REMOTE_PORT,
@@ -1248,8 +1244,8 @@ static int rsl_rx_ipac_XXcx(struct msgb *msg)
 	struct gsm_lchan *lchan = msg->lchan;
 	struct gsm_bts_role_bts *btsb = bts_role_bts(msg->lchan->ts->trx->bts);
 	const uint8_t *payload_type, *speech_mode, *payload_type2;
-	const uint32_t *connect_ip;
-	const uint16_t *connect_port;
+	uint32_t connect_ip = 0;
+	uint16_t connect_port = 0;
 	int rc, inc_ip_port = 0, port;
 	char *name;
 
@@ -1267,8 +1263,16 @@ static int rsl_rx_ipac_XXcx(struct msgb *msg)
 	speech_mode = TLVP_VAL(&tp, RSL_IE_IPAC_SPEECH_MODE);
 	payload_type = TLVP_VAL(&tp, RSL_IE_IPAC_RTP_PAYLOAD);
 	payload_type2 = TLVP_VAL(&tp, RSL_IE_IPAC_RTP_PAYLOAD2);
-	connect_ip = (uint32_t *) TLVP_VAL(&tp, RSL_IE_IPAC_REMOTE_IP);
-	connect_port = (uint16_t *) TLVP_VAL(&tp, RSL_IE_IPAC_REMOTE_PORT);
+
+	if (TLVP_PRESENT(&tp, RSL_IE_IPAC_REMOTE_IP))
+		connect_ip = tlvp_val32_unal(&tp, RSL_IE_IPAC_REMOTE_IP);
+	else
+		LOGP(DRSL, LOGL_NOTICE, "CRCX does not specify a remote IP\n");
+
+	if (TLVP_PRESENT(&tp, RSL_IE_IPAC_REMOTE_PORT))
+		connect_port = tlvp_val16_unal(&tp, RSL_IE_IPAC_REMOTE_PORT);
+	else
+		LOGP(DRSL, LOGL_NOTICE, "CRCX does not specify a remote port\n");
 
 	if (dch->c.msg_type == RSL_MT_IPAC_CRCX && connect_ip && connect_port)
 		inc_ip_port = 1;
@@ -1350,14 +1354,14 @@ static int rsl_rx_ipac_XXcx(struct msgb *msg)
 
 		/* Special rule: If connect_ip == 0.0.0.0, use RSL IP
 		 * address */
-		if (*connect_ip == 0) {
+		if (connect_ip == 0) {
 			struct ipabis_link *link =
 				lchan->ts->trx->rsl_link;
 			ia.s_addr = htonl(link->ip);
 		} else
-			ia.s_addr = *connect_ip;
+			ia.s_addr = connect_ip;
 		rc = osmo_rtp_socket_connect(lchan->abis_ip.rtp_socket,
-					     inet_ntoa(ia), ntohs(*connect_port));
+					     inet_ntoa(ia), ntohs(connect_port));
 		if (rc < 0) {
 			LOGP(DRSL, LOGL_ERROR,
 			     "%s Failed to connect RTP/RTCP sockets\n",
@@ -1370,7 +1374,7 @@ static int rsl_rx_ipac_XXcx(struct msgb *msg)
 		}
 		/* save IP address and port number */
 		lchan->abis_ip.connect_ip = ntohl(ia.s_addr);
-		lchan->abis_ip.connect_port = ntohs(*connect_port);
+		lchan->abis_ip.connect_port = ntohs(connect_port);
 
 	} else {
 		/* FIXME: discard all codec frames */
-- 
1.7.10.4





More information about the OpenBSC mailing list