Skip to content

Commit

Permalink
mctp: Allow MCTP on tun devices
Browse files Browse the repository at this point in the history
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Matt Johnston authored and David S. Miller committed Sep 29, 2021
1 parent 7c2dcfa commit f364dd7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
7 changes: 5 additions & 2 deletions net/mctp/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,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))
Expand Down
13 changes: 8 additions & 5 deletions net/mctp/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,13 +821,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;
Expand All @@ -841,9 +846,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)
Expand Down

0 comments on commit f364dd7

Please sign in to comment.