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 14/16] mctp: Allow per-netns default networks
Date: Fri, 23 Jul 2021 16:29:30 +0800 [thread overview]
Message-ID: <20210723082932.3570396-15-jk@codeconstruct.com.au> (raw)
In-Reply-To: <20210723082932.3570396-1-jk@codeconstruct.com.au>
From: Matt Johnston <matt@codeconstruct.com.au>
Currently we have a compile-time default network
(MCTP_INITIAL_DEFAULT_NET). This change introduces a default_net field
on the net namespace, allowing future configuration for new interfaces.
Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
---
include/net/mctp.h | 4 ++++
include/net/netns/mctp.h | 3 +++
include/uapi/linux/mctp.h | 1 -
net/mctp/af_mctp.c | 3 +++
net/mctp/device.c | 2 +-
net/mctp/route.c | 14 ++++++++++++++
6 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/include/net/mctp.h b/include/net/mctp.h
index 350facde2ceb..9528dbffbaf7 100644
--- a/include/net/mctp.h
+++ b/include/net/mctp.h
@@ -37,6 +37,8 @@ struct mctp_hdr {
#define MCTP_HEADER_MAXLEN 4
+#define MCTP_INITIAL_DEFAULT_NET 1
+
static inline bool mctp_address_ok(mctp_eid_t eid)
{
return eid >= 8 && eid < 255;
@@ -189,6 +191,8 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,
struct sk_buff *skb, mctp_eid_t daddr, u8 req_tag);
/* routing <--> device interface */
+unsigned int mctp_default_net(struct net *net);
+int mctp_default_net_set(struct net *net, unsigned int index);
int mctp_route_add(struct mctp_dev *mdev, mctp_eid_t daddr_start,
unsigned int daddr_extent, unsigned int mtu, bool is_local);
int mctp_route_remove(struct mctp_dev *mdev, mctp_eid_t daddr_start,
diff --git a/include/net/netns/mctp.h b/include/net/netns/mctp.h
index 14ae6d37e52a..acedef12a35e 100644
--- a/include/net/netns/mctp.h
+++ b/include/net/netns/mctp.h
@@ -25,6 +25,9 @@ struct netns_mctp {
spinlock_t keys_lock;
struct hlist_head keys;
+ /* MCTP network */
+ unsigned int default_net;
+
/* neighbour table */
struct mutex neigh_lock;
struct list_head neighbours;
diff --git a/include/uapi/linux/mctp.h b/include/uapi/linux/mctp.h
index a9d8edb3402b..52b54d13f385 100644
--- a/include/uapi/linux/mctp.h
+++ b/include/uapi/linux/mctp.h
@@ -26,7 +26,6 @@ struct sockaddr_mctp {
};
#define MCTP_NET_ANY 0x0
-#define MCTP_NET_DEFAULT 0x0
#define MCTP_ADDR_NULL 0x00
#define MCTP_ADDR_ANY 0xff
diff --git a/net/mctp/af_mctp.c b/net/mctp/af_mctp.c
index 9ca836df19d0..84f722d31fd7 100644
--- a/net/mctp/af_mctp.c
+++ b/net/mctp/af_mctp.c
@@ -94,6 +94,9 @@ static int mctp_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
if (!capable(CAP_NET_RAW))
return -EACCES;
+ if (addr->smctp_network == MCTP_NET_ANY)
+ addr->smctp_network = mctp_default_net(sock_net(sk));
+
rt = mctp_route_lookup(sock_net(sk), addr->smctp_network,
addr->smctp_addr.s_addr);
if (!rt)
diff --git a/net/mctp/device.c b/net/mctp/device.c
index 89befc208c27..f82288157d62 100644
--- a/net/mctp/device.c
+++ b/net/mctp/device.c
@@ -267,7 +267,7 @@ static struct mctp_dev *mctp_add_dev(struct net_device *dev)
spin_lock_init(&mdev->addrs_lock);
- mdev->net = MCTP_INITIAL_DEFAULT_NET;
+ mdev->net = mctp_default_net(dev_net(dev));
/* associate to net_device */
rcu_assign_pointer(dev->mctp_ptr, mdev);
diff --git a/net/mctp/route.c b/net/mctp/route.c
index b5b3e991046a..1265373552da 100644
--- a/net/mctp/route.c
+++ b/net/mctp/route.c
@@ -432,6 +432,19 @@ static struct mctp_route *mctp_route_alloc(void)
return rt;
}
+unsigned int mctp_default_net(struct net *net)
+{
+ return READ_ONCE(net->mctp.default_net);
+}
+
+int mctp_default_net_set(struct net *net, unsigned int index)
+{
+ if (index == 0)
+ return -EINVAL;
+ WRITE_ONCE(net->mctp.default_net, index);
+ return 0;
+}
+
/* tag management */
static void mctp_reserve_tag(struct net *net, struct mctp_sk_key *key,
struct mctp_sock *msk)
@@ -1038,6 +1051,7 @@ static int __net_init mctp_routes_net_init(struct net *net)
mutex_init(&ns->bind_lock);
INIT_HLIST_HEAD(&ns->keys);
spin_lock_init(&ns->keys_lock);
+ WARN_ON(mctp_default_net_set(net, MCTP_INITIAL_DEFAULT_NET));
return 0;
}
--
2.30.2
next prev 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 ` Jeremy Kerr [this message]
2021-07-23 8:29 ` [PATCH net-next v3 15/16] mctp: Allow MCTP on tun devices Jeremy Kerr
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-15-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 14/16] mctp: Allow per-netns default networks' \
/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).