summaryrefslogtreecommitdiff
path: root/mesh/model.c
diff options
context:
space:
mode:
authorBrian Gix <brian.gix@intel.com>2020-01-30 10:59:24 -0800
committerBrian Gix <brian.gix@intel.com>2020-01-31 10:15:08 -0800
commitda429de905ed87f7d530ca29284aedfad848f227 (patch)
treeaab7add25ec49d0e667390761943b6af31e2343f /mesh/model.c
parent8457e6a3ad147c1167862f148cbbf281d879e874 (diff)
downloadbluez-da429de905ed87f7d530ca29284aedfad848f227.tar.gz
mesh: Re-arrange replay protection check and add
Re-arranged for efficiency. Replay Protection was set up as an atomic check-and-add operation. Now we check the message early so we can discard it without taking further action, and only add it to the RPL once fully verified that it was authorized and addressed to us.
Diffstat (limited to 'mesh/model.c')
-rw-r--r--mesh/model.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/mesh/model.c b/mesh/model.c
index 92a00496c..072972fda 100644
--- a/mesh/model.c
+++ b/mesh/model.c
@@ -964,10 +964,12 @@ bool mesh_model_rx(struct mesh_node *node, bool szmict, uint32_t seq0,
/* Unicast and not addressed to us */
return false;
- clear_text = l_malloc(size);
- if (!clear_text)
+ /* Don't process if already in RPL */
+ crpl = node_get_crpl(node);
+ if (net_msg_check_replay_cache(net, src, crpl, seq, iv_index))
return false;
+ clear_text = l_malloc(size);
forward.data = clear_text;
/*
@@ -995,16 +997,6 @@ bool mesh_model_rx(struct mesh_node *node, bool szmict, uint32_t seq0,
goto done;
}
- /* print_packet("Clr Rx (pre-cache-check)", clear_text, size - 4); */
-
- crpl = node_get_crpl(node);
-
- if (net_msg_in_replay_cache(net, (uint16_t) decrypt_idx, src,
- crpl, seq, iv_index)) {
- result = true;
- goto done;
- }
-
print_packet("Clr Rx", clear_text, size - (szmict ? 8 : 4));
forward.virt = decrypt_virt;
@@ -1073,7 +1065,7 @@ bool mesh_model_rx(struct mesh_node *node, bool szmict, uint32_t seq0,
* Either the message has been processed internally or
* has been passed on to an external model.
*/
- result = forward.has_dst | forward.done;
+ result |= forward.has_dst | forward.done;
/* If the message was to unicast address, we are done */
if (!is_subscription && ele_idx == i)
@@ -1088,8 +1080,13 @@ bool mesh_model_rx(struct mesh_node *node, bool szmict, uint32_t seq0,
break;
}
+ /* If message has been handled by us, add to RPL */
+ if (result)
+ net_msg_add_replay_cache(net, src, seq, iv_index);
+
done:
l_free(clear_text);
+
return result;
}