mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-27 04:22:58 +00:00
rtnetlink: Pack newlink() params into struct
There are 4 net namespaces involved when creating links: - source netns - where the netlink socket resides, - target netns - where to put the device being created, - link netns - netns associated with the device (backend), - peer netns - netns of peer device. Currently, two nets are passed to newlink() callback - "src_net" parameter and "dev_net" (implicitly in net_device). They are set as follows, depending on netlink attributes in the request. +------------+-------------------+---------+---------+ | peer netns | IFLA_LINK_NETNSID | src_net | dev_net | +------------+-------------------+---------+---------+ | | absent | source | target | | absent +-------------------+---------+---------+ | | present | link | link | +------------+-------------------+---------+---------+ | | absent | peer | target | | present +-------------------+---------+---------+ | | present | peer | link | +------------+-------------------+---------+---------+ When IFLA_LINK_NETNSID is present, the device is created in link netns first and then moved to target netns. This has some side effects, including extra ifindex allocation, ifname validation and link events. These could be avoided if we create it in target netns from the beginning. On the other hand, the meaning of src_net parameter is ambiguous. It varies depending on how parameters are passed. It is the effective link (or peer netns) by design, but some drivers ignore it and use dev_net instead. To provide more netns context for drivers, this patch packs existing newlink() parameters, along with the source netns, link netns and peer netns, into a struct. The old "src_net" is renamed to "net" to avoid confusion with real source netns, and will be deprecated later. The use of src_net are converted to params->net trivially. Signed-off-by: Xiao Liang <shaw.leon@gmail.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com> Link: https://patch.msgid.link/20250219125039.18024-3-shaw.leon@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
committed by
Jakub Kicinski
parent
ec061546c6
commit
69c7be1b90
@@ -69,6 +69,25 @@ static inline int rtnl_msg_family(const struct nlmsghdr *nlh)
|
||||
return AF_UNSPEC;
|
||||
}
|
||||
|
||||
/**
|
||||
* struct rtnl_newlink_params - parameters of rtnl_link_ops::newlink()
|
||||
*
|
||||
* @net: Netns of interest
|
||||
* @src_net: Source netns of rtnetlink socket
|
||||
* @link_net: Link netns by IFLA_LINK_NETNSID, NULL if not specified
|
||||
* @peer_net: Peer netns
|
||||
* @tb: IFLA_* attributes
|
||||
* @data: IFLA_INFO_DATA attributes
|
||||
*/
|
||||
struct rtnl_newlink_params {
|
||||
struct net *net;
|
||||
struct net *src_net;
|
||||
struct net *link_net;
|
||||
struct net *peer_net;
|
||||
struct nlattr **tb;
|
||||
struct nlattr **data;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct rtnl_link_ops - rtnetlink link operations
|
||||
*
|
||||
@@ -125,10 +144,8 @@ struct rtnl_link_ops {
|
||||
struct nlattr *data[],
|
||||
struct netlink_ext_ack *extack);
|
||||
|
||||
int (*newlink)(struct net *src_net,
|
||||
struct net_device *dev,
|
||||
struct nlattr *tb[],
|
||||
struct nlattr *data[],
|
||||
int (*newlink)(struct net_device *dev,
|
||||
struct rtnl_newlink_params *params,
|
||||
struct netlink_ext_ack *extack);
|
||||
int (*changelink)(struct net_device *dev,
|
||||
struct nlattr *tb[],
|
||||
|
||||
Reference in New Issue
Block a user