Skip to contentSkip to conversation

mesh: fix node default TTL

PATCH Applied Aurelien Jarno 2 participants 2 messages Nov 11, 2019 – Nov 19, 2019 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mesh: fix node default TTL

There is a confusion between the node default TTL (section 4.2.7) and the publish TTL (section 4.2.2.5):

- The node default TTL can only take values 0x00, and 0x02 to 0x7f. The value 0xff is not prohibited.
- The publish TTL can take values 0x00 to 0x7f, as well as 0xff which means use the node default TTL.

Currently the default node TTL is set to 0xff (DEFAULT_TTL), and read_default_ttl() also allows such a value. This patch fixes that to use 0x7f (TTL_MASK) as the default value instead.

Note that the code handling OP_CONFIG_DEFAULT_TTL_SET correctly use 0x7f (TTL_MASK) for the upper allowed limit.

---
 mesh/mesh-config-json.c | 2 +-
 mesh/node.c             | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
mesh/mesh-config-json.c +1 -1
index b2cff6824..5ca2961b0 100644
@@ -358,7 +358,7 @@ static bool read_default_ttl(json_object *jobj, uint8_t *ttl)
 	if (!val && errno == EINVAL)
 		return false;
 
-	if (val < 0 || val == 1 || val > DEFAULT_TTL)
+	if (val < 0 || val == 1 || val > TTL_MASK)
 		return false;
 
 	*ttl = (uint8_t) val;
mesh/node.c +2 -2
index e23f32dd1..5dcffe6f7 100644
@@ -672,7 +672,7 @@ struct l_queue *node_get_element_models(struct mesh_node *node,
 uint8_t node_default_ttl_get(struct mesh_node *node)
 {
 	if (!node)
-		return DEFAULT_TTL;
+		return TTL_MASK;
 	return node->ttl;
 }
 
@@ -1352,7 +1352,7 @@ static void set_defaults(struct mesh_node *node)
 	node->friend = MESH_MODE_UNSUPPORTED;
 	node->beacon = MESH_MODE_DISABLED;
 	node->relay.mode = MESH_MODE_DISABLED;
-	node->ttl = DEFAULT_TTL;
+	node->ttl = TTL_MASK;
 	node->seq_number = DEFAULT_SEQUENCE_NUMBER;
 
 	/* Add configuration server model on primary element */
Signature · 1 line
2.24.0
Applied
#1 lore raw

Applied, Thanks

Quoted 54 lines · Aurelien Jarno

There is a confusion between the node default TTL (section 4.2.7) and the publish TTL (section 4.2.2.5):

- The node default TTL can only take values 0x00, and 0x02 to 0x7f. The value 0xff is not prohibited.
- The publish TTL can take values 0x00 to 0x7f, as well as 0xff which means use the node default TTL.

Currently the default node TTL is set to 0xff (DEFAULT_TTL), and read_default_ttl() also allows such a value. This patch fixes that to use 0x7f (TTL_MASK) as the default value instead.

Note that the code handling OP_CONFIG_DEFAULT_TTL_SET correctly use 0x7f (TTL_MASK) for the upper allowed limit.

---
 mesh/mesh-config-json.c | 2 +-
 mesh/node.c             | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
mesh/mesh-config-json.c +1 -1
index b2cff6824..5ca2961b0 100644
@@ -358,7 +358,7 @@ static bool read_default_ttl(json_object *jobj, uint8_t *ttl)
 	if (!val && errno == EINVAL)
 		return false;
 
-	if (val < 0 || val == 1 || val > DEFAULT_TTL)
+	if (val < 0 || val == 1 || val > TTL_MASK)
 		return false;
 
 	*ttl = (uint8_t) val;
mesh/node.c +2 -2
index e23f32dd1..5dcffe6f7 100644
@@ -672,7 +672,7 @@ struct l_queue *node_get_element_models(struct mesh_node *node,
 uint8_t node_default_ttl_get(struct mesh_node *node)
 {
 	if (!node)
-		return DEFAULT_TTL;
+		return TTL_MASK;
 	return node->ttl;
 }
 
@@ -1352,7 +1352,7 @@ static void set_defaults(struct mesh_node *node)
 	node->friend = MESH_MODE_UNSUPPORTED;
 	node->beacon = MESH_MODE_DISABLED;
 	node->relay.mode = MESH_MODE_DISABLED;
-	node->ttl = DEFAULT_TTL;
+	node->ttl = TTL_MASK;
 	node->seq_number = DEFAULT_SEQUENCE_NUMBER;
 
 	/* Add configuration server model on primary element */