[PATCH BlueZ 8/9] net: packet_received: avoid unnecessary copying

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Since cca48f305b60 ("mesh: Fix Relaying for multiple nodes"), the packet
for relaying is assembled within send_relay_pkt(). So we do not need to
assemble a full packet within packet_received().

Additionally remove misleading initialization of 'msg' variable, the
value is assigned in all possible branches of
mesh_crypto_packet_parse().
---
 mesh/net.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/mesh/net.c b/mesh/net.c
index f26a63f178c2..1cf74c892ca0 100644
--- a/mesh/net.c
+++ b/mesh/net.c
@@ -2324,25 +2324,21 @@ static void send_msg_pkt(struct mesh_net *net, uint8_t cnt, uint16_t interval,
 	l_idle_oneshot(send_msg_pkt_oneshot, tx, NULL);
 }
 
-static enum _relay_advice packet_received(void *user_data,
+static enum _relay_advice packet_received(struct mesh_net *net,
 				uint32_t net_key_id, uint16_t net_idx,
 				bool frnd, uint32_t iv_index,
-				const void *data, uint8_t size, int8_t rssi)
+				const uint8_t *data, uint8_t size, int8_t rssi)
 {
-	struct mesh_net *net = user_data;
-	const uint8_t *msg = data;
+	const uint8_t *msg;
 	uint8_t app_msg_len;
 	uint8_t net_ttl, key_aid, net_segO, net_segN, net_opcode;
 	uint32_t net_seq, cache_cookie;
 	uint16_t net_src, net_dst, net_seqZero;
-	uint8_t packet[31];
 	bool net_ctl, net_segmented, net_szmic, net_relay;
 
-	memcpy(packet + 2, data, size);
-
-	print_packet("RX: Network [clr] :", packet + 2, size);
+	print_packet("RX: Network [clr] :", data, size);
 
-	if (!mesh_crypto_packet_parse(packet + 2, size, &net_ctl, &net_ttl,
+	if (!mesh_crypto_packet_parse(data, size, &net_ctl, &net_ttl,
 					&net_seq, &net_src, &net_dst,
 					&cache_cookie, &net_opcode,
 					&net_segmented, &key_aid, &net_szmic,
@@ -2418,7 +2414,7 @@ static enum _relay_advice packet_received(void *user_data,
 				if (net_ttl >= 2) {
 					friend_seg_rxed(net, iv_index, net_ttl,
 						net_seq, net_src, net_dst,
-						l_get_be32(packet + 2 + 9),
+						l_get_be32(data + 9),
 						msg, app_msg_len);
 				}
 			} else {
-- 
2.43.0





[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux