mesh: Add interface output filter
authorIsak Westin <isak.westin@hotmail.com>
Wed, 21 Sep 2022 11:16:28 +0000 (13:16 +0200)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:55 +0000 (14:55 +0530)
According to the mesh profile (3.4.5.2), if TTL is set to 1 for an
outgoing message, that message shall be dropped.

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
mesh/net.c

index 925155c..ad9ff15 100644 (file)
@@ -3065,6 +3065,13 @@ void mesh_net_send_seg(struct mesh_net *net, uint32_t net_key_id,
        uint8_t segO = (hdr >> SEGO_HDR_SHIFT) & SEG_MASK;
        uint8_t segN = (hdr >> SEGN_HDR_SHIFT) & SEG_MASK;
 
+       /*
+        * MshPRFv1.0.1 section 3.4.5.2, Interface output filter:
+        * If TTL is set to 1, message shall be dropped.
+        */
+       if (ttl == 1)
+               return;
+
        /* TODO: Only used for current POLLed segments to LPNs */
 
        l_debug("SEQ: %6.6x", seq + segO);
@@ -3133,6 +3140,13 @@ bool mesh_net_app_send(struct mesh_net *net, bool frnd_cred, uint16_t src,
                        (dst >= net->src_addr && dst <= net->last_addr))
                return true;
 
+       /*
+        * MshPRFv1.0.1 section 3.4.5.2, Interface output filter:
+        * If TTL is set to 1, message shall be dropped.
+        */
+       if (ttl == 1)
+               return true;
+
        /* Setup OTA Network send */
        payload = mesh_sar_new(msg_len);
        memcpy(payload->buf, msg, msg_len);
@@ -3204,6 +3218,13 @@ void mesh_net_ack_send(struct mesh_net *net, uint32_t net_key_id,
        uint8_t pkt_len;
        uint8_t pkt[30];
 
+       /*
+        * MshPRFv1.0.1 section 3.4.5.2, Interface output filter:
+        * If TTL is set to 1, message shall be dropped.
+        */
+       if (ttl == 1)
+               return;
+
        hdr = NET_OP_SEG_ACKNOWLEDGE << OPCODE_HDR_SHIFT;
        hdr |= rly << RELAY_HDR_SHIFT;
        hdr |= (seqZero & SEQ_ZERO_MASK) << SEQ_ZERO_HDR_SHIFT;
@@ -3262,6 +3283,13 @@ void mesh_net_transport_send(struct mesh_net *net, uint32_t net_key_id,
        if (*msg & 0xc0 || (9 + msg_len + 8 > 29))
                return;
 
+       /*
+        * MshPRFv1.0.1 section 3.4.5.2, Interface output filter:
+        * If TTL is set to 1, message shall be dropped.
+        */
+       if (ttl == 1)
+               return;
+
        /* Enqueue for Friend if forwardable and from us */
        if (!net_key_id && src >= net->src_addr && src <= net->last_addr) {
                uint32_t hdr = msg[0] << OPCODE_HDR_SHIFT;