Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp104247ybl; Thu, 9 Jan 2020 17:53:36 -0800 (PST) X-Google-Smtp-Source: APXvYqyWIRi0V6xdoDiBon04y9bUziGR0lV1cFo252TdezJ56dEa5jLoqR3x5f/P0846a2w2nhN/ X-Received: by 2002:aca:a849:: with SMTP id r70mr420301oie.28.1578621216468; Thu, 09 Jan 2020 17:53:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578621216; cv=none; d=google.com; s=arc-20160816; b=NJM2rx9QBUoSlVZzP1hPuXz8FoWq6Yyhl2RK930TvX8hq7R4j7gpRYEjrLKHo1l/rY qYGXLnvfA1DMFMrFL8pSCdgSirlMcjCMXF+mvmbQRRPIKBNxTAbeBaNhqB1IsmrDHUyE Qv/1/03Vs0toE2cwUOUVqwhehiuKikojfBWyHta6eXnUYtyuxuXRYx6CWMTFqocRqUj4 ZRHLmwH0CNX/5eKOmkRTiTUARDDi5C4GQVD1cqnRkvhoM9gff27S76UkTwbkJIBNFxqd 6C8B36GmQLaf/vHOC/AB6pzGsxG0klBhI98k2pVh7UGe0rHNMYN9NqYPLuQp1Pzv1EnG kJvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=y5OAPMwgtCDSRyQHO23x78WFMKLHw9MmgE4eXLNJxEY=; b=fB4cTqmYC0KFYeiLK00ntI6VdHFtXlRJwSH0rCWjxim9cDp7oQNqVhaI8v08LntKzj ousZYuCQrJMCqn3hBZFWBtizGA10S++h9B+spdLmZU6tR37YHS4ZE2bUFDgpbxOojHfU rFZocl5nveDyg2LS9ttgpDsd/l1aT87qF1+dGYKwhcPbJUAk6O3Z8XLVUtX7YGOgYmzx Vyc+HHNfuB+OcD9D89l+ceDgCtBMQi2Zl3eRgHQzBQgNW6LSRf3LDtG4hknIb2RV2Ss+ dDOarOopo9dumZnfyTXJtoLbHm2wyI3D6tFtpVRJWWngaFK4EruKa+wgAge14bBert/g QB5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a12si184511oie.87.2020.01.09.17.53.22; Thu, 09 Jan 2020 17:53:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730596AbgAJBxV (ORCPT + 99 others); Thu, 9 Jan 2020 20:53:21 -0500 Received: from mga04.intel.com ([192.55.52.120]:13798 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730359AbgAJBxV (ORCPT ); Thu, 9 Jan 2020 20:53:21 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jan 2020 17:53:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,414,1571727600"; d="scan'208";a="229621287" Received: from ingas-nuc1.sea.intel.com ([10.254.104.252]) by fmsmga001.fm.intel.com with ESMTP; 09 Jan 2020 17:53:21 -0800 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ] tools/mesh: Remove node's appkeys when deleting a netkey Date: Thu, 9 Jan 2020 17:53:20 -0800 Message-Id: <20200110015320.2160-1-inga.stotland@intel.com> X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org When a netkey is deleted from a remote node, all the appkeys bound to this netkey are expected to be deleted as well. This fixes app_key queue manipulation to avoid issues caused by modifying the queue while iterating over it: instead of iteration over all the entries, find a first bound key, delete it, find next... and so on, until there are no bound keys left in the app_keys queue. --- tools/mesh/remote.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tools/mesh/remote.c b/tools/mesh/remote.c index 25e8d23f8..533d59b28 100644 --- a/tools/mesh/remote.c +++ b/tools/mesh/remote.c @@ -2,7 +2,7 @@ * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2019 Intel Corporation. All rights reserved. + * Copyright (C) 2019-2020 Intel Corporation. All rights reserved. * * * This library is free software; you can redistribute it and/or @@ -81,6 +81,14 @@ static bool match_node_addr(const void *a, const void *b) return false; } +static bool match_bound_key(const void *a, const void *b) +{ + uint16_t app_idx = L_PTR_TO_UINT(a); + uint16_t net_idx = L_PTR_TO_UINT(b); + + return (net_idx == keys_get_bound_key(app_idx)); +} + bool remote_add_node(const uint8_t uuid[16], uint16_t unicast, uint8_t ele_cnt, uint16_t net_idx) { @@ -123,7 +131,7 @@ bool remote_add_net_key(uint16_t addr, uint16_t net_idx) bool remote_del_net_key(uint16_t addr, uint16_t net_idx) { struct remote_node *rmt; - const struct l_queue_entry *l; + void *data; rmt = l_queue_find(nodes, match_node_addr, L_UINT_TO_PTR(addr)); if (!rmt) @@ -132,13 +140,14 @@ bool remote_del_net_key(uint16_t addr, uint16_t net_idx) if (!l_queue_remove(rmt->net_keys, L_UINT_TO_PTR(net_idx))) return false; - for (l = l_queue_get_entries(rmt->app_keys); l; l = l->next) { - uint16_t app_idx = (uint16_t) L_PTR_TO_UINT(l->data); + data = l_queue_remove_if(rmt->app_keys, match_bound_key, + L_UINT_TO_PTR(net_idx)); + while (data) { + uint16_t app_idx = (uint16_t) L_PTR_TO_UINT(data); - if (net_idx == keys_get_bound_key(app_idx)) { - l_queue_remove(rmt->app_keys, L_UINT_TO_PTR(app_idx)); - mesh_db_node_app_key_del(rmt->unicast, app_idx); - } + mesh_db_node_app_key_del(rmt->unicast, app_idx); + data = l_queue_remove_if(rmt->app_keys, match_bound_key, + L_UINT_TO_PTR(net_idx)); } return true; -- 2.21.1