From patchwork Fri Jul 23 08:29:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 12395581 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2878FC43214 for ; Fri, 23 Jul 2021 08:30:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0CE5E60E77 for ; Fri, 23 Jul 2021 08:30:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234638AbhGWHtl (ORCPT ); Fri, 23 Jul 2021 03:49:41 -0400 Received: from pi.codeconstruct.com.au ([203.29.241.158]:34016 "EHLO codeconstruct.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234523AbhGWHtS (ORCPT ); Fri, 23 Jul 2021 03:49:18 -0400 Received: by codeconstruct.com.au (Postfix, from userid 10000) id 19D3821497; Fri, 23 Jul 2021 16:29:51 +0800 (AWST) From: Jeremy Kerr To: netdev@vger.kernel.org Cc: Matt Johnston , Andrew Jeffery Subject: [PATCH net-next v3 15/16] mctp: Allow MCTP on tun devices Date: Fri, 23 Jul 2021 16:29:31 +0800 Message-Id: <20210723082932.3570396-16-jk@codeconstruct.com.au> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210723082932.3570396-1-jk@codeconstruct.com.au> References: <20210723082932.3570396-1-jk@codeconstruct.com.au> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Matt Johnston Allowing TUN is useful for testing, to route packets to userspace or to tunnel between machines. Signed-off-by: Matt Johnston --- net/mctp/device.c | 7 +++++-- net/mctp/route.c | 13 ++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/net/mctp/device.c b/net/mctp/device.c index f82288157d62..95a95b41cc89 100644 --- a/net/mctp/device.c +++ b/net/mctp/device.c @@ -357,9 +357,12 @@ static int mctp_register(struct net_device *dev) if (rtnl_dereference(dev->mctp_ptr)) return 0; - /* only register specific types; MCTP-specific and loopback for now */ - if (dev->type != ARPHRD_MCTP && dev->type != ARPHRD_LOOPBACK) + /* only register specific types (inc. NONE for TUN devices) */ + if (!(dev->type == ARPHRD_MCTP || + dev->type == ARPHRD_LOOPBACK || + dev->type == ARPHRD_NONE)) { return 0; + } mdev = mctp_add_dev(dev); if (IS_ERR(mdev)) diff --git a/net/mctp/route.c b/net/mctp/route.c index 1265373552da..e161516c5266 100644 --- a/net/mctp/route.c +++ b/net/mctp/route.c @@ -806,13 +806,18 @@ static int mctp_pkttype_receive(struct sk_buff *skb, struct net_device *dev, struct net_device *orig_dev) { struct net *net = dev_net(dev); + struct mctp_dev *mdev; struct mctp_skb_cb *cb; struct mctp_route *rt; struct mctp_hdr *mh; - /* basic non-data sanity checks */ - if (dev->type != ARPHRD_MCTP) + rcu_read_lock(); + mdev = __mctp_dev_get(dev); + rcu_read_unlock(); + if (!mdev) { + /* basic non-data sanity checks */ goto err_drop; + } if (!pskb_may_pull(skb, sizeof(struct mctp_hdr))) goto err_drop; @@ -826,9 +831,7 @@ static int mctp_pkttype_receive(struct sk_buff *skb, struct net_device *dev, goto err_drop; cb = __mctp_cb(skb); - rcu_read_lock(); - cb->net = READ_ONCE(__mctp_dev_get(dev)->net); - rcu_read_unlock(); + cb->net = READ_ONCE(mdev->net); rt = mctp_route_lookup(net, cb->net, mh->dest); if (!rt)