mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-04 04:02:26 +00:00
mctp: Allow per-netns default networks
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> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
26ab3fcaf2
commit
03f2bbc4ee
@ -37,6 +37,8 @@ struct mctp_hdr {
|
|||||||
|
|
||||||
#define MCTP_HEADER_MAXLEN 4
|
#define MCTP_HEADER_MAXLEN 4
|
||||||
|
|
||||||
|
#define MCTP_INITIAL_DEFAULT_NET 1
|
||||||
|
|
||||||
static inline bool mctp_address_ok(mctp_eid_t eid)
|
static inline bool mctp_address_ok(mctp_eid_t eid)
|
||||||
{
|
{
|
||||||
return eid >= 8 && eid < 255;
|
return eid >= 8 && eid < 255;
|
||||||
|
@ -25,6 +25,9 @@ struct netns_mctp {
|
|||||||
spinlock_t keys_lock;
|
spinlock_t keys_lock;
|
||||||
struct hlist_head keys;
|
struct hlist_head keys;
|
||||||
|
|
||||||
|
/* MCTP network */
|
||||||
|
unsigned int default_net;
|
||||||
|
|
||||||
/* neighbour table */
|
/* neighbour table */
|
||||||
struct mutex neigh_lock;
|
struct mutex neigh_lock;
|
||||||
struct list_head neighbours;
|
struct list_head neighbours;
|
||||||
|
@ -26,7 +26,6 @@ struct sockaddr_mctp {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define MCTP_NET_ANY 0x0
|
#define MCTP_NET_ANY 0x0
|
||||||
#define MCTP_NET_DEFAULT 0x0
|
|
||||||
|
|
||||||
#define MCTP_ADDR_NULL 0x00
|
#define MCTP_ADDR_NULL 0x00
|
||||||
#define MCTP_ADDR_ANY 0xff
|
#define MCTP_ADDR_ANY 0xff
|
||||||
|
@ -94,6 +94,9 @@ static int mctp_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
|
|||||||
if (!capable(CAP_NET_RAW))
|
if (!capable(CAP_NET_RAW))
|
||||||
return -EACCES;
|
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,
|
rt = mctp_route_lookup(sock_net(sk), addr->smctp_network,
|
||||||
addr->smctp_addr.s_addr);
|
addr->smctp_addr.s_addr);
|
||||||
if (!rt)
|
if (!rt)
|
||||||
|
@ -267,7 +267,7 @@ static struct mctp_dev *mctp_add_dev(struct net_device *dev)
|
|||||||
|
|
||||||
spin_lock_init(&mdev->addrs_lock);
|
spin_lock_init(&mdev->addrs_lock);
|
||||||
|
|
||||||
mdev->net = MCTP_INITIAL_DEFAULT_NET;
|
mdev->net = mctp_default_net(dev_net(dev));
|
||||||
|
|
||||||
/* associate to net_device */
|
/* associate to net_device */
|
||||||
rcu_assign_pointer(dev->mctp_ptr, mdev);
|
rcu_assign_pointer(dev->mctp_ptr, mdev);
|
||||||
|
@ -433,6 +433,19 @@ static struct mctp_route *mctp_route_alloc(void)
|
|||||||
return rt;
|
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 */
|
/* tag management */
|
||||||
static void mctp_reserve_tag(struct net *net, struct mctp_sk_key *key,
|
static void mctp_reserve_tag(struct net *net, struct mctp_sk_key *key,
|
||||||
struct mctp_sock *msk)
|
struct mctp_sock *msk)
|
||||||
@ -1045,6 +1058,7 @@ static int __net_init mctp_routes_net_init(struct net *net)
|
|||||||
mutex_init(&ns->bind_lock);
|
mutex_init(&ns->bind_lock);
|
||||||
INIT_HLIST_HEAD(&ns->keys);
|
INIT_HLIST_HEAD(&ns->keys);
|
||||||
spin_lock_init(&ns->keys_lock);
|
spin_lock_init(&ns->keys_lock);
|
||||||
|
WARN_ON(mctp_default_net_set(net, MCTP_INITIAL_DEFAULT_NET));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user