Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp141328rwb; Tue, 4 Oct 2022 01:43:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7BXNHL7qEOCtE6qWTncXuB8NJ/qsfEBJBnJ0AIDn+LQptXrAQjmtro/KV2rkTXXFZolD88 X-Received: by 2002:a17:902:e80e:b0:178:2ecb:16bb with SMTP id u14-20020a170902e80e00b001782ecb16bbmr25801245plg.152.1664872989361; Tue, 04 Oct 2022 01:43:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664872989; cv=none; d=google.com; s=arc-20160816; b=h0HTph+/oZoAG/91YQ80IUaBx1MwRpLJGDtP+z8CSWNvwgyCA5q1lFGv7TO8fGDq0p tFV+f9E/ZhAeE6wCmogb7/BA4hh0acx7BFpsyls05D9D5AAX+AkEyMZHjuqhhKLS6VeT 6An9tAfNlQ5BzATkQnLRPeCqdQuHOQFIh8kR/uxrMnE4s6dnjDQJV3likZuH9m+WvNhO vJiAueGmrQFT/auY7giQTefk8uAc3o7OzwB3dGhk6aQetzxZinvYBhVmcEFhYYJ9yfty k3W2VB6HArvtf97ZW7SVyv3tlwQzzV4st3BFuBLho8XOP7xJy+WJVu6DmhxzVrB+qRMW HD8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=WcUPd02yCDRtWrSn4Rn4TbXG0uCFY5+JCpg0bYE9I54=; b=MchYBJ87oOU6Aqg56l0HKniBJjE8qny8y7/23MOJ+3w7EHczS5at7VupB0wfd910zM AToQwOEtZNCHrb962ZtoRGXUc1xSfEqQMBfqYx1Ly95H4UpNyEQEJMFI1BGCoQlKNkEv +QA5rsODyVyVu9cWZwd9c9lo8XPfN++DZbClH34Tgp6oOfuwxsmlmVUSVBRjXpzdZ3w2 RL/v8ZtB4uuRo2yje38m4pYwVzKqKLC/jeete4j+5H/D5+4xbCPYUhgWrpzb1IFfFWPC Bs2eJ5jqGkaXm9zBYBKg6vd0/xf9gTZ0TVpHvDm4YT4wGN10QWfRbdH90rIAwowCs5Oo oSKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w17-20020a170902d71100b001789fa8f90esi9760573ply.408.2022.10.04.01.42.09; Tue, 04 Oct 2022 01:43:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230149AbiJDIZ6 (ORCPT + 99 others); Tue, 4 Oct 2022 04:25:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230153AbiJDIZ5 (ORCPT ); Tue, 4 Oct 2022 04:25:57 -0400 Received: from voyager.loytec.com (voyager.loytec.com [88.198.4.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A77832252E for ; Tue, 4 Oct 2022 01:25:55 -0700 (PDT) Received: from 212-17-98-152.static.upcbusiness.at ([212.17.98.152] helo=lexx.office.loytec.com) by voyager.loytec.com with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ofdFR-0002H7-Jx for linux-bluetooth@vger.kernel.org; Tue, 04 Oct 2022 10:25:53 +0200 Received: from loytec-dev-vm.delta.corp ([10.101.25.21]) by lexx.office.loytec.com (8.15.2/8.15.2/Some OS 1.2.3-4.5) with ESMTP id 2948PkTd2433476; Tue, 4 Oct 2022 10:25:51 +0200 From: Isak Westin To: linux-bluetooth@vger.kernel.org Cc: Isak Westin Subject: [PATCH BlueZ 4/4] mesh: Always relay messages from Low Power nodes Date: Tue, 4 Oct 2022 10:25:30 +0200 Message-Id: <20221004082530.25719-5-isak.westin@loytec.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221004082530.25719-1-isak.westin@loytec.com> References: <20221004082530.25719-1-isak.westin@loytec.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 212.17.98.152 X-SA-Exim-Mail-From: isak.westin@loytec.com X-SA-Exim-Scanned: No (on voyager.loytec.com); SAEximRunCond expanded to false X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org If we receive a message from one of our Low Power nodes, which is encrypted using frendship credentials and where the destination is not us, we must relay that message using master credentials. See MshPRFv1.0.1 section 3.6.6.2. --- mesh/net.c | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/mesh/net.c b/mesh/net.c index 577121f30..a1b586a0b 100644 --- a/mesh/net.c +++ b/mesh/net.c @@ -1763,7 +1763,8 @@ not_for_friend: return true; } -static uint16_t key_id_to_net_idx(struct mesh_net *net, uint32_t net_key_id) +static uint16_t key_id_to_net_idx(struct mesh_net *net, + uint32_t net_key_id, bool *frnd) { struct mesh_subnet *subnet; struct mesh_friend *friend; @@ -1771,6 +1772,9 @@ static uint16_t key_id_to_net_idx(struct mesh_net *net, uint32_t net_key_id) if (!net) return NET_IDX_INVALID; + if (frnd) + *frnd = false; + subnet = l_queue_find(net->subnets, match_key_id, L_UINT_TO_PTR(net_key_id)); @@ -1780,8 +1784,12 @@ static uint16_t key_id_to_net_idx(struct mesh_net *net, uint32_t net_key_id) friend = l_queue_find(net->friends, match_friend_key_id, L_UINT_TO_PTR(net_key_id)); - if (friend) + if (friend) { + if (frnd) + *frnd = true; + return friend->net_idx; + } friend = l_queue_find(net->negotiations, match_friend_key_id, L_UINT_TO_PTR(net_key_id)); @@ -2078,7 +2086,7 @@ static bool ctl_received(struct mesh_net *net, uint32_t net_key_id, return false; print_packet("Rx-NET_OP_FRND_REQUEST", pkt, len); - net_idx = key_id_to_net_idx(net, net_key_id); + net_idx = key_id_to_net_idx(net, net_key_id, NULL); friend_request(net, net_idx, src, pkt[0], pkt[1], l_get_be32(pkt + 1) & 0xffffff, l_get_be16(pkt + 5), pkt[7], @@ -2269,7 +2277,8 @@ static void send_msg_pkt(struct mesh_net *net, uint8_t cnt, uint16_t interval, } static enum _relay_advice packet_received(void *user_data, - uint32_t net_key_id, uint32_t iv_index, + uint32_t net_key_id, uint16_t net_idx, + bool frnd, uint32_t iv_index, const void *data, uint8_t size, int8_t rssi) { struct mesh_net *net = user_data; @@ -2278,16 +2287,11 @@ static enum _relay_advice packet_received(void *user_data, uint8_t net_ttl, key_aid, net_segO, net_segN, net_opcode; uint32_t net_seq, cache_cookie; uint16_t net_src, net_dst, net_seqZero; - uint16_t net_idx; uint8_t packet[31]; bool net_ctl, net_segmented, net_szmic, net_relay; memcpy(packet + 2, data, size); - net_idx = key_id_to_net_idx(net, net_key_id); - if (net_idx == NET_IDX_INVALID) - return RELAY_NONE; - print_packet("RX: Network [clr] :", packet + 2, size); if (!mesh_crypto_packet_parse(packet + 2, size, &net_ctl, &net_ttl, @@ -2389,6 +2393,13 @@ static enum _relay_advice packet_received(void *user_data, return RELAY_DISALLOWED; } + /* + * Messages that are encrypted with friendship credentials + * should *always* be relayed + */ + if (frnd) + return RELAY_ALWAYS; + /* If relay not enable, or no more hops allowed */ if (!net->relay.enable || net_ttl < 0x02) return RELAY_NONE; @@ -2414,7 +2425,9 @@ static void net_rx(void *net_ptr, void *user_data) uint8_t *out; size_t out_size; uint32_t net_key_id; + uint16_t net_idx; int8_t rssi = 0; + bool frnd; bool ivi_net = !!(net->iv_index & 1); bool ivi_pkt = !!(data->data[0] & 0x80); @@ -2438,9 +2451,21 @@ static void net_rx(void *net_ptr, void *user_data) rssi = data->info->rssi; } - relay_advice = packet_received(net, net_key_id, iv_index, out, out_size, - rssi); + net_idx = key_id_to_net_idx(net, net_key_id, &frnd); + + if (net_idx == NET_IDX_INVALID) + return; + + relay_advice = packet_received(net, net_key_id, net_idx, frnd, + iv_index, out, out_size, rssi); if (relay_advice > data->relay_advice) { + /* + * If packet was encrypted with friendship credentials, + * relay it using master credentials + */ + if (frnd && !mesh_net_get_key(net, false, net_idx, &net_key_id)) + return; + data->iv_index = iv_index; data->relay_advice = relay_advice; data->net_key_id = net_key_id; -- 2.20.1