Linux-Bluetooth Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH BlueZ] tools/mesh: Remove node's appkeys when deleting a netkey
@ 2020-01-10  1:53 Inga Stotland
  2020-01-14 14:42 ` Gix, Brian
  0 siblings, 1 reply; 2+ messages in thread
From: Inga Stotland @ 2020-01-10  1:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, Inga Stotland

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH BlueZ] tools/mesh: Remove node's appkeys when deleting a netkey
  2020-01-10  1:53 [PATCH BlueZ] tools/mesh: Remove node's appkeys when deleting a netkey Inga Stotland
@ 2020-01-14 14:42 ` Gix, Brian
  0 siblings, 0 replies; 2+ messages in thread
From: Gix, Brian @ 2020-01-14 14:42 UTC (permalink / raw)
  To: linux-bluetooth, Stotland, Inga

Applied
On Thu, 2020-01-09 at 17:53 -0800, Inga Stotland wrote:
> 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;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-10  1:53 [PATCH BlueZ] tools/mesh: Remove node's appkeys when deleting a netkey Inga Stotland
2020-01-14 14:42 ` Gix, Brian

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org
	public-inbox-index linux-bluetooth

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git