Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Jeremy Kerr <jk@codeconstruct.com.au>
To: netdev@vger.kernel.org
Cc: Matt Johnston <matt@codeconstruct.com.au>,
	Andrew Jeffery <andrew@aj.id.au>
Subject: [PATCH net-next v3 15/16] mctp: Allow MCTP on tun devices
Date: Fri, 23 Jul 2021 16:29:31 +0800	[thread overview]
Message-ID: <20210723082932.3570396-16-jk@codeconstruct.com.au> (raw)
In-Reply-To: <20210723082932.3570396-1-jk@codeconstruct.com.au>

From: Matt Johnston <matt@codeconstruct.com.au>

Allowing TUN is useful for testing, to route packets to userspace or to
tunnel between machines.

Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
---
 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)
-- 
2.30.2


  parent reply	other threads:[~2021-07-23  8:30 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-23  8:29 [PATCH net-next v3 00/16] Add Management Component Transport Protocol support Jeremy Kerr
2021-07-23  8:29 ` [PATCH net-next v3 01/16] mctp: Add MCTP base Jeremy Kerr
2021-08-12  9:45   ` Geert Uytterhoeven
2021-08-12 11:15     ` Jeremy Kerr
2021-08-12 11:32       ` Geert Uytterhoeven
2021-10-03 21:08       ` Steven Rostedt
2021-07-23  8:29 ` [PATCH net-next v3 02/16] mctp: Add base socket/protocol definitions Jeremy Kerr
2021-07-23  8:29 ` [PATCH net-next v3 03/16] mctp: Add base packet definitions Jeremy Kerr
2021-07-23  8:29 ` [PATCH net-next v3 04/16] mctp: Add sockaddr_mctp to uapi Jeremy Kerr
2021-07-23  8:29 ` [PATCH net-next v3 05/16] mctp: Add initial driver infrastructure Jeremy Kerr
2021-07-23  8:29 ` [PATCH net-next v3 06/16] mctp: Add device handling and netlink interface Jeremy Kerr
2021-07-23  8:29 ` [PATCH net-next v3 07/16] mctp: Add initial routing framework Jeremy Kerr
2021-07-23  8:29 ` [PATCH net-next v3 08/16] mctp: Add netlink route management Jeremy Kerr
2021-07-23  8:29 ` [PATCH net-next v3 09/16] mctp: Add neighbour implementation Jeremy Kerr
2021-07-23  8:29 ` [PATCH net-next v3 10/16] mctp: Add neighbour netlink interface Jeremy Kerr
2021-07-23  8:29 ` [PATCH net-next v3 11/16] mctp: Populate socket implementation Jeremy Kerr
2021-07-23  8:29 ` [PATCH net-next v3 12/16] mctp: Implement message fragmentation & reassembly Jeremy Kerr
2021-07-23  8:29 ` [PATCH net-next v3 13/16] mctp: Add dest neighbour lladdr to route output Jeremy Kerr
2021-07-23  8:29 ` [PATCH net-next v3 14/16] mctp: Allow per-netns default networks Jeremy Kerr
2021-07-23  8:29 ` Jeremy Kerr [this message]
2021-07-23  8:29 ` [PATCH net-next v3 16/16] mctp: Add MCTP overview document Jeremy Kerr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210723082932.3570396-16-jk@codeconstruct.com.au \
    --to=jk@codeconstruct.com.au \
    --cc=andrew@aj.id.au \
    --cc=matt@codeconstruct.com.au \
    --cc=netdev@vger.kernel.org \
    --subject='Re: [PATCH net-next v3 15/16] mctp: Allow MCTP on tun devices' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).