host/mesh: Remove outated RPL entry from persistent storage
This commit fixes a bug where outdated RPL entries might not be removed
properly from the persistent storage making those entries dead.
This is port of
@@ -32,6 +32,27 @@ static inline int rpl_idx(const struct bt_mesh_rpl *rpl)
return rpl - &replay_list[0];
}
+static void clear_rpl(struct bt_mesh_rpl *rpl)
+{
+ int err;
+ char path[18];
+
+ if (!rpl->src) {
+ return;
+ }
+
+ snprintk(path, sizeof(path), "bt_mesh/RPL/%x", rpl->src);
+ err = settings_save_one(path, NULL);
+ if (err) {
+ BT_ERR("Failed to clear RPL");
+ } else {
+ BT_DBG("Cleared RPL");
+ }
+
+ (void)memset(rpl, 0, sizeof(*rpl));
+ atomic_clear_bit(store, rpl_idx(rpl));
+}
+
static void schedule_rpl_store(struct bt_mesh_rpl *entry)
{
atomic_set_bit(store, rpl_idx(entry));
@@ -171,17 +192,20 @@ void bt_mesh_rpl_reset(void)
if (rpl->src) {
if (rpl->old_iv) {
+ if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
+ clear_rpl(rpl);
+ } else {
(void)memset(rpl, 0, sizeof(*rpl));
+ }
} else {
rpl->old_iv = true;
- }
-
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
schedule_rpl_store(rpl);
}
}
}
}
+}
static int rpl_set(int argc, char **argv, char *val)
{
@@ -246,6 +270,10 @@ static void store_rpl(struct bt_mesh_rpl *entry)
char *str;
int err;
+ if (!entry->src) {
+ return;
+ }
+
BT_DBG("src 0x%04x seq 0x%06x old_iv %u", entry->src,
(unsigned) entry->seq, entry->old_iv);
@@ -269,27 +297,6 @@ static void store_rpl(struct bt_mesh_rpl *entry)
}
}
-static void clear_rpl(struct bt_mesh_rpl *rpl)
-{
- int err;
- char path[18];
-
- if (!rpl->src) {
- return;
- }
-
- snprintk(path, sizeof(path), "bt_mesh/RPL/%x", rpl->src);
- err = settings_save_one(path, NULL);
- if (err) {
- BT_ERR("Failed to clear RPL");
- } else {
- BT_DBG("Cleared RPL");
- }
-
- (void)memset(rpl, 0, sizeof(*rpl));
- atomic_clear_bit(store, rpl_idx(rpl));
-}
-
static void store_pending_rpl(struct bt_mesh_rpl *rpl)
{
BT_DBG("");
