mesh: Ignore beacons with IVU if IV already updated 10/234210/1
authorRafał Gajda <rafal.gajda@silvair.com>
Tue, 7 Apr 2020 09:32:51 +0000 (11:32 +0200)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Fri, 22 May 2020 04:23:43 +0000 (09:53 +0530)
When daemon receives beacon with IV=n+1, IVU=False it will
start sending messages with new IV and set sequence to 0.
However if daemon receives another beacon with IV=n+1, IVU=True it
will go back to sending messages with old IV=n (IVU set to True).
Because sequence number has been reset those messages will be dropped
by replay protection and node will lose communication.

Once IV is updated daemon should not go back to using the old value.

This patch adds beacon rejection if IV has already been updated.

Change-Id: I32a19c26d3fbbd7b281fdc4a12fa0dd369173517
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
mesh/net.c

index 2af538a..bd36e2d 100644 (file)
@@ -2694,6 +2694,10 @@ static void update_iv_ivu_state(struct mesh_net *net, uint32_t iv_index,
        /* If first beacon seen, accept without judgement */
        if (net->iv_upd_state == IV_UPD_INIT) {
                if (ivu) {
+                       /* Ignore beacons with IVU if IV already updated */
+                       if (iv_index == net->iv_index && !net->iv_update)
+                               return;
+
                        /* Other devices will be accepting old or new iv_index,
                         * but we don't know how far through update they are.
                         * Starting permissive state will allow us maximum
@@ -2715,6 +2719,10 @@ static void update_iv_ivu_state(struct mesh_net *net, uint32_t iv_index,
                        return;
                }
 
+               /* Ignore beacons with IVU if IV already updated */
+               if (iv_index == net->iv_index)
+                       return;
+
                if (!net->iv_update) {
                        l_info("iv_upd_state = IV_UPD_UPDATING");
                        net->iv_upd_state = IV_UPD_UPDATING;