From patchwork Tue Nov 28 11:16:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13471021 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="G2Dxk8Qu" Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4656109; Tue, 28 Nov 2023 03:17:04 -0800 (PST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 819CCC0007; Tue, 28 Nov 2023 11:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1701170223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F+Ca0i6LS9EErxIJcnfDTMGUbmzhckltyA1nENhzjEE=; b=G2Dxk8Qur2PT0FS20ThRlbIYV8LVyg55LGKiLObgI6cZgEtEwHnNBMfrHkPS7YOq58W+UL zdWABnrVsoAuDYFlXZOi17fH+5iVeA/+NH9SEYu0ddDEVFhCYv8TaGnj2+lqDwXP3waPWH uEw1Qfe3uDTnmAewTRVr/wKGgTxFpoCqNTeC3cdP735QblUrilJPvuSp/mF1N7BJDmoUwH 03TbgzXLs4z2d9qaRhHsrAzHL/ia8qBYSkVE1JLPLD5+42on8HRx7AOTqnnjop3XZep8s0 C2HF8SlbXI6mj0bmpZSFPlPsHyN/0kTc6b0KN7IRU+Ji2QRmsoJ3TVJTaM9Rzg== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet , netdev@vger.kernel.org, Miquel Raynal Subject: [PATCH wpan-next 4/5] ieee802154: Avoid confusing changes after associating Date: Tue, 28 Nov 2023 12:16:54 +0100 Message-Id: <20231128111655.507479-5-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231128111655.507479-1-miquel.raynal@bootlin.com> References: <20231128111655.507479-1-miquel.raynal@bootlin.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com X-Patchwork-Delegate: kuba@kernel.org Once associated with any device, we are part of a PAN (with a specific PAN ID), and we are expected to be present on a particular channel. Let's avoid confusing other devices by preventing any PAN ID/channel change once associated. Signed-off-by: Miquel Raynal Acked-by: Stefan Schmidt Acked-by: Alexander Aring --- net/ieee802154/nl802154.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c index e4d290d0e0a0..5c73b5fcadc0 100644 --- a/net/ieee802154/nl802154.c +++ b/net/ieee802154/nl802154.c @@ -1087,6 +1087,15 @@ static int nl802154_set_pan_id(struct sk_buff *skb, struct genl_info *info) pan_id = nla_get_le16(info->attrs[NL802154_ATTR_PAN_ID]); + /* Only allow changing the PAN ID when the device has no more + * associations ongoing to avoid confusing peers. + */ + if (cfg802154_device_is_associated(wpan_dev)) { + NL_SET_ERR_MSG(info->extack, + "Existing associations, changing PAN ID forbidden"); + return -EINVAL; + } + return rdev_set_pan_id(rdev, wpan_dev, pan_id); } @@ -1113,20 +1122,17 @@ static int nl802154_set_short_addr(struct sk_buff *skb, struct genl_info *info) short_addr = nla_get_le16(info->attrs[NL802154_ATTR_SHORT_ADDR]); - /* TODO - * I am not sure about to check here on broadcast short_addr. - * Broadcast is a valid setting, comment from 802.15.4: - * A value of 0xfffe indicates that the device has - * associated but has not been allocated an address. A - * value of 0xffff indicates that the device does not - * have a short address. - * - * I think we should allow to set these settings but - * don't allow to allow socket communication with it. + /* The short address only has a meaning when part of a PAN, after a + * proper association procedure. However, we want to still offer the + * possibility to create static networks so changing the short address + * is only allowed when not already associated to other devices with + * the official handshake. */ - if (short_addr == cpu_to_le16(IEEE802154_ADDR_SHORT_UNSPEC) || - short_addr == cpu_to_le16(IEEE802154_ADDR_SHORT_BROADCAST)) + if (cfg802154_device_is_associated(wpan_dev)) { + NL_SET_ERR_MSG(info->extack, + "Existing associations, changing short address forbidden"); return -EINVAL; + } return rdev_set_short_addr(rdev, wpan_dev, short_addr); }