Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp1455572pxa; Fri, 28 Aug 2020 13:05:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyE7F3V3BKS5wdZ8Vwgpg+0oB2RgmyGquEOe3ZXkW9hXG7UY6x3+2wKGtlqwMCJPqw8P15M X-Received: by 2002:a17:906:2cc2:: with SMTP id r2mr375536ejr.482.1598645121902; Fri, 28 Aug 2020 13:05:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598645121; cv=none; d=google.com; s=arc-20160816; b=AY8rVL1aolbJLF2W55JwA/F/iLkN8bzXpQvxc391GdiSFaeoivHEwnYupY3HK5zAGQ L9iL4C8scsJaKAh/pq5eZhAkSdm6qHR3UZKEqNZ+hMkjAnlMOM6zRsKi8d/CzHcmiYrk 1zIMq+uILRLHLZWEM3uIANCwuC3HaX+GDXYxJzOTDbdxNBh0xBOvxKx+3oVhxOK6iTtb x1NBVhDYObhAQOgJN7O2J0TOibjQpowhwD+1H/ApPVbwWHGYMOlYEGi7q2nCAR875Geb sRjcflqTKElsLohvWT/hO6h9wTKv7CdfYaKG4AedMuUtOyuxqNijCmJLNF1PSCacueu6 gb5w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=rnEI4yWrLZcWXjQaYbE+NLcq82W7Tf6OPisOsjW+lW4=; b=I053Du9ITQyvhcWdGZChyDw5544HGiNcjPWv1QpJ77Y7GrGgAPYWbjSnaIFuXpwps6 nPeDe06ngBu2VP0mJOBaQWu84pZ04Q8Uw9ODa3LJBskQr2SZGKEKbzf1hRav04q0+S9c YPUO1j0NJeU3lFur8CEu1KJivoKnMu9AozSLtmLxC3wmAXiXIhsJ5bsjElNJuFlCCB3Z xadAydg1Gf4XgIA1/LoB9adf+4TAI87IYgyNdEZbgQGJzj0p1wZ9dY2gSB9k6DyuB33z I15e0lnlrqlaPvPoJIFYMEgK3jARWKvt523e/lE0E05IOAY7KxWNUv3VzMfMpPom4oli 5brw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id t24si71553edy.243.2020.08.28.13.04.42; Fri, 28 Aug 2020 13:05:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 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 S1726771AbgH1UEd (ORCPT + 99 others); Fri, 28 Aug 2020 16:04:33 -0400 Received: from mga17.intel.com ([192.55.52.151]:35423 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726460AbgH1UE3 (ORCPT ); Fri, 28 Aug 2020 16:04:29 -0400 IronPort-SDR: vzfp+r6dZ7oHVoeLKFMrc7Uf9M0Vc4eV8APpZQ2RMeh0Ru5ThPQFC8VTz/yV/tFqGPNQBtf+h9 om2wiA7g49rQ== X-IronPort-AV: E=McAfee;i="6000,8403,9727"; a="136799285" X-IronPort-AV: E=Sophos;i="5.76,364,1592895600"; d="scan'208";a="136799285" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Aug 2020 13:04:29 -0700 IronPort-SDR: vM/oqMEDzpPg24FWZfdvt3FTecPhIhN385LJV8l9F0IJpbJW0evTq/Luxd3EKcv3QLi4z6XQ5N ZjtQDd1fQHwQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,364,1592895600"; d="scan'208";a="300345422" Received: from rbuaba-mobl2.amr.corp.intel.com (HELO ingas-nuc1.intel.com) ([10.254.83.122]) by orsmga006.jf.intel.com with ESMTP; 28 Aug 2020 13:04:29 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ 1/2] mesh: Initialize RPL when creating or loading a node Date: Fri, 28 Aug 2020 13:04:26 -0700 Message-Id: <20200828200427.18753-2-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200828200427.18753-1-inga.stotland@intel.com> References: <20200828200427.18753-1-inga.stotland@intel.com> 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 either a new node is created or an existing node is loaded from storage, initialize RPL storage directory. Additionally, when an existing node configguration is read from storage, load saved RPL entries into the corresponding RPL lists. --- mesh/net.c | 14 +++++++------- mesh/net.h | 1 + mesh/node.c | 11 +++++++---- mesh/rpl.c | 29 ++++++++++++++++++++--------- mesh/rpl.h | 3 ++- 5 files changed, 37 insertions(+), 21 deletions(-) diff --git a/mesh/net.c b/mesh/net.c index 15d8f1c4b..83647d6ad 100644 --- a/mesh/net.c +++ b/mesh/net.c @@ -633,6 +633,7 @@ struct mesh_net *mesh_net_new(struct mesh_node *node) net->frnd_msgs = l_queue_new(); net->destinations = l_queue_new(); net->app_keys = l_queue_new(); + net->replay_cache = l_queue_new(); if (!nets) nets = l_queue_new(); @@ -2596,7 +2597,7 @@ static void update_iv_ivu_state(struct mesh_net *net, uint32_t iv_index, mesh_config_write_iv_index(cfg, iv_index, ivu); /* Cleanup Replay Protection List NVM */ - rpl_init(net->node, iv_index); + rpl_update(net->node, iv_index); } node_property_changed(net->node, "IVIndex"); @@ -3480,12 +3481,6 @@ bool net_msg_check_replay_cache(struct mesh_net *net, uint16_t src, if (!net || !net->node) return true; - if (!net->replay_cache) { - net->replay_cache = l_queue_new(); - rpl_init(net->node, net->iv_index); - rpl_get_list(net->node, net->replay_cache); - } - rpe = l_queue_find(net->replay_cache, match_replay_cache, L_UINT_TO_PTR(src)); @@ -3688,3 +3683,8 @@ int mesh_net_set_heartbeat_pub(struct mesh_net *net, uint16_t dst, /* TODO: Save to node config */ return MESH_STATUS_SUCCESS; } + +bool mesh_net_load_rpl(struct mesh_net *net) +{ + return rpl_get_list(net->node, net->replay_cache); +} diff --git a/mesh/net.h b/mesh/net.h index 253185e42..725054ce6 100644 --- a/mesh/net.h +++ b/mesh/net.h @@ -358,3 +358,4 @@ bool net_msg_check_replay_cache(struct mesh_net *net, uint16_t src, uint16_t crpl, uint32_t seq, uint32_t iv_index); void net_msg_add_replay_cache(struct mesh_net *net, uint16_t src, uint32_t seq, uint32_t iv_index); +bool mesh_net_load_rpl(struct mesh_net *net); diff --git a/mesh/node.c b/mesh/node.c index c564bdb91..f7ac5ff67 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -44,6 +44,7 @@ #include "mesh/dbus.h" #include "mesh/agent.h" #include "mesh/manager.h" +#include "mesh/rpl.h" #include "mesh/node.h" #define MESH_NODE_PATH_PREFIX "/node" @@ -399,7 +400,8 @@ static bool init_storage_dir(struct mesh_node *node) node->storage_dir = l_strdup(dir_name); - return true; + /* Initialize directory for storing RPL info */ + return rpl_init(node->storage_dir); } static void update_net_settings(struct mesh_node *node) @@ -470,6 +472,10 @@ static bool init_from_storage(struct mesh_config_node *db_node, mesh_net_set_iv_index(node->net, db_node->iv_index, db_node->iv_update); + /* Initialize directory for storing keyring and RPL info */ + if (!init_storage_dir(node) || !mesh_net_load_rpl(node->net)) + goto fail; + if (db_node->net_transmit) mesh_net_transmit_params_set(node->net, db_node->net_transmit->count, @@ -497,9 +503,6 @@ static bool init_from_storage(struct mesh_config_node *db_node, node->cfg = cfg; - /* Initialize directory for storing keyring info */ - init_storage_dir(node); - return true; fail: node_remove(node); diff --git a/mesh/rpl.c b/mesh/rpl.c index 5a667468e..792c52ad6 100644 --- a/mesh/rpl.c +++ b/mesh/rpl.c @@ -51,7 +51,7 @@ bool rpl_put_entry(struct mesh_node *node, uint16_t src, uint32_t iv_index, DIR *dir; int fd; - if (!node || !IS_UNICAST(src)) + if (!IS_UNICAST(src)) return false; node_path = node_get_storage_dir(node); @@ -100,7 +100,7 @@ void rpl_del_entry(struct mesh_node *node, uint16_t src) struct dirent *entry; DIR *dir; - if (!node || !IS_UNICAST(src)) + if (!IS_UNICAST(src)) return; node_path = node_get_storage_dir(node); @@ -205,12 +205,12 @@ bool rpl_get_list(struct mesh_node *node, struct l_queue *rpl_list) size_t len; DIR *dir; - if (!node || !rpl_list) + if (!rpl_list) return false; node_path = node_get_storage_dir(node); - len = strlen(node_path) + strlen(rpl_dir) + 14; + len = strlen(node_path) + strlen(rpl_dir) + 15; if (len > PATH_MAX) return false; @@ -241,7 +241,7 @@ bool rpl_get_list(struct mesh_node *node, struct l_queue *rpl_list) return true; } -void rpl_init(struct mesh_node *node, uint32_t cur) +void rpl_update(struct mesh_node *node, uint32_t cur) { uint32_t old = cur - 1; const char *node_path; @@ -249,12 +249,11 @@ void rpl_init(struct mesh_node *node, uint32_t cur) char path[PATH_MAX]; DIR *dir; - if (!node) - return; - node_path = node_get_storage_dir(node); + if (!node_path) + return; - if (strlen(node_path) + strlen(rpl_dir) + 10 >= PATH_MAX) + if (strlen(node_path) + strlen(rpl_dir) + 15 >= PATH_MAX) return; /* Make sure path exists */ @@ -287,3 +286,15 @@ void rpl_init(struct mesh_node *node, uint32_t cur) closedir(dir); } + +bool rpl_init(const char *node_path) +{ + char path[PATH_MAX]; + + if (strlen(node_path) + strlen(rpl_dir) + 15 >= PATH_MAX) + return false; + + snprintf(path, PATH_MAX, "%s%s", node_path, rpl_dir); + mkdir(path, 0755); + return true; +} diff --git a/mesh/rpl.h b/mesh/rpl.h index 17d2e3f05..2bbbdc9b9 100644 --- a/mesh/rpl.h +++ b/mesh/rpl.h @@ -27,4 +27,5 @@ bool rpl_put_entry(struct mesh_node *node, uint16_t src, uint32_t iv_index, uint32_t seq); void rpl_del_entry(struct mesh_node *node, uint16_t src); bool rpl_get_list(struct mesh_node *node, struct l_queue *rpl_list); -void rpl_init(struct mesh_node *node, uint32_t iv_index); +void rpl_update(struct mesh_node *node, uint32_t iv_index); +bool rpl_init(const char *node_path); -- 2.26.2