@@ -97,10 +97,13 @@ static int ipoib_changelink(struct net_device *dev, struct nlattr *tb[],
return ret;
}
-static int ipoib_new_child_link(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int ipoib_new_child_link(struct rtnl_newlink_params *params)
{
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct net *src_net = params->net;
+ struct nlattr **tb = params->tb;
struct net_device *pdev;
struct ipoib_dev_priv *ppriv;
u16 child_pkey;
@@ -3161,13 +3161,17 @@ static int amt_validate(struct nlattr *tb[], struct nlattr *data[],
return 0;
}
-static int amt_newlink(struct net *net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int amt_newlink(struct rtnl_newlink_params *params)
{
- struct amt_dev *amt = netdev_priv(dev);
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct nlattr **tb = params->tb;
+ struct net *net = params->net;
+ struct amt_dev *amt;
int err = -EINVAL;
+ amt = netdev_priv(dev);
amt->net = net;
amt->mode = nla_get_u32(data[IFLA_AMT_MODE]);
@@ -698,10 +698,13 @@ static void bareudp_dellink(struct net_device *dev, struct list_head *head)
unregister_netdevice_queue(dev, head);
}
-static int bareudp_newlink(struct net *net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int bareudp_newlink(struct rtnl_newlink_params *params)
{
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct nlattr **tb = params->tb;
+ struct net *net = params->net;
struct bareudp_conf conf;
int err;
@@ -564,10 +564,12 @@ static int bond_changelink(struct net_device *bond_dev, struct nlattr *tb[],
return 0;
}
-static int bond_newlink(struct net *src_net, struct net_device *bond_dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int bond_newlink(struct rtnl_newlink_params *params)
{
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *bond_dev = params->dev;
+ struct nlattr **data = params->data;
+ struct nlattr **tb = params->tb;
int err;
err = bond_changelink(bond_dev, tb, data, extack);
@@ -624,9 +624,7 @@ static int can_fill_xstats(struct sk_buff *skb, const struct net_device *dev)
return -EMSGSIZE;
}
-static int can_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int can_newlink(struct rtnl_newlink_params *params)
{
return -EOPNOTSUPP;
}
@@ -172,10 +172,13 @@ static void vxcan_setup(struct net_device *dev)
/* forward declaration for rtnl_create_link() */
static struct rtnl_link_ops vxcan_link_ops;
-static int vxcan_newlink(struct net *peer_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int vxcan_newlink(struct rtnl_newlink_params *params)
{
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct net *peer_net = params->net;
+ struct nlattr **tb = params->tb;
struct vxcan_priv *priv;
struct net_device *peer;
@@ -117,11 +117,14 @@ static void rmnet_unregister_bridge(struct rmnet_port *port)
rmnet_unregister_real_device(bridge_dev);
}
-static int rmnet_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int rmnet_newlink(struct rtnl_newlink_params *params)
{
u32 data_format = RMNET_FLAGS_INGRESS_DEAGGREGATION;
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct net *src_net = params->net;
+ struct nlattr **tb = params->tb;
struct net_device *real_dev;
int mode = RMNET_EPMODE_VND;
struct rmnet_endpoint *ep;
@@ -1614,10 +1614,13 @@ static void geneve_link_config(struct net_device *dev,
geneve_change_mtu(dev, ldev_mtu - info->options_len);
}
-static int geneve_newlink(struct net *net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int geneve_newlink(struct rtnl_newlink_params *params)
{
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct nlattr **tb = params->tb;
+ struct net *net = params->net;
struct geneve_config cfg = {
.df = GENEVE_DF_UNSET,
.use_udp6_rx_checksums = false,
@@ -1460,10 +1460,11 @@ static int gtp_create_sockets(struct gtp_dev *gtp, const struct nlattr *nla,
#define GTP_TH_MAXLEN (sizeof(struct udphdr) + sizeof(struct gtp0_header))
#define GTP_IPV6_MAXLEN (sizeof(struct ipv6hdr) + GTP_TH_MAXLEN)
-static int gtp_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int gtp_newlink(struct rtnl_newlink_params *params)
{
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct net *src_net = params->net;
unsigned int role = GTP_ROLE_GGSN;
struct gtp_dev *gtp;
struct gtp_net *gn;
@@ -166,9 +166,7 @@ struct ipvl_addr *ipvlan_addr_lookup(struct ipvl_port *port, void *lyr3h,
void *ipvlan_get_L3_hdr(struct ipvl_port *port, struct sk_buff *skb, int *type);
void ipvlan_count_rx(const struct ipvl_dev *ipvlan,
unsigned int len, bool success, bool mcast);
-int ipvlan_link_new(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack);
+int ipvlan_link_new(struct rtnl_newlink_params *params);
void ipvlan_link_delete(struct net_device *dev, struct list_head *head);
void ipvlan_link_setup(struct net_device *dev);
int ipvlan_link_register(struct rtnl_link_ops *ops);
@@ -532,16 +532,21 @@ static int ipvlan_nl_fillinfo(struct sk_buff *skb,
return ret;
}
-int ipvlan_link_new(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+int ipvlan_link_new(struct rtnl_newlink_params *params)
{
- struct ipvl_dev *ipvlan = netdev_priv(dev);
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct net *src_net = params->net;
+ struct nlattr **tb = params->tb;
+ struct ipvl_dev *ipvlan;
struct ipvl_port *port;
struct net_device *phy_dev;
int err;
u16 mode = IPVLAN_MODE_L3;
+ ipvlan = netdev_priv(dev);
+
if (!tb[IFLA_LINK])
return -EINVAL;
@@ -73,13 +73,13 @@ static void ipvtap_update_features(struct tap_dev *tap,
netdev_update_features(vlan->dev);
}
-static int ipvtap_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int ipvtap_newlink(struct rtnl_newlink_params *params)
{
- struct ipvtap_dev *vlantap = netdev_priv(dev);
+ struct net_device *dev = params->dev;
+ struct ipvtap_dev *vlantap;
int err;
+ vlantap = netdev_priv(dev);
INIT_LIST_HEAD(&vlantap->tap.queue_list);
/* Since macvlan supports all offloads by default, make
@@ -97,7 +97,7 @@ static int ipvtap_newlink(struct net *src_net, struct net_device *dev,
/* Don't put anything that may fail after macvlan_common_newlink
* because we can't undo what it does.
*/
- err = ipvlan_link_new(src_net, dev, tb, data, extack);
+ err = ipvlan_link_new(params);
if (err) {
netdev_rx_handler_unregister(dev);
return err;
@@ -4141,17 +4141,22 @@ static int macsec_add_dev(struct net_device *dev, sci_t sci, u8 icv_len)
static struct lock_class_key macsec_netdev_addr_lock_key;
-static int macsec_newlink(struct net *net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int macsec_newlink(struct rtnl_newlink_params *params)
{
- struct macsec_dev *macsec = macsec_priv(dev);
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct nlattr **tb = params->tb;
+ struct net *net = params->net;
rx_handler_func_t *rx_handler;
u8 icv_len = MACSEC_DEFAULT_ICV_LEN;
struct net_device *real_dev;
+ struct macsec_dev *macsec;
int err, mtu;
sci_t sci;
+ macsec = macsec_priv(dev);
+
if (!tb[IFLA_LINK])
return -EINVAL;
real_dev = __dev_get_by_index(net, nla_get_u32(tb[IFLA_LINK]));
@@ -1565,11 +1565,10 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
}
EXPORT_SYMBOL_GPL(macvlan_common_newlink);
-static int macvlan_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int macvlan_newlink(struct rtnl_newlink_params *params)
{
- return macvlan_common_newlink(src_net, dev, tb, data, extack);
+ return macvlan_common_newlink(params->net, params->dev, params->tb,
+ params->data, params->extack);
}
void macvlan_dellink(struct net_device *dev, struct list_head *head)
@@ -77,13 +77,13 @@ static void macvtap_update_features(struct tap_dev *tap,
netdev_update_features(vlan->dev);
}
-static int macvtap_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int macvtap_newlink(struct rtnl_newlink_params *params)
{
- struct macvtap_dev *vlantap = netdev_priv(dev);
+ struct net_device *dev = params->dev;
+ struct macvtap_dev *vlantap;
int err;
+ vlantap = netdev_priv(dev);
INIT_LIST_HEAD(&vlantap->tap.queue_list);
/* Since macvlan supports all offloads by default, make
@@ -105,7 +105,8 @@ static int macvtap_newlink(struct net *src_net, struct net_device *dev,
/* Don't put anything that may fail after macvlan_common_newlink
* because we can't undo what it does.
*/
- err = macvlan_common_newlink(src_net, dev, tb, data, extack);
+ err = macvlan_common_newlink(params->net, dev, params->tb, params->data,
+ params->extack);
if (err) {
netdev_rx_handler_unregister(dev);
return err;
@@ -327,10 +327,13 @@ static int netkit_validate(struct nlattr *tb[], struct nlattr *data[],
static struct rtnl_link_ops netkit_link_ops;
-static int netkit_new_link(struct net *peer_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int netkit_new_link(struct rtnl_newlink_params *params)
{
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct net *peer_net = params->net;
+ struct nlattr **tb = params->tb;
struct nlattr *peer_tb[IFLA_MAX + 1], **tbp = tb, *attr;
enum netkit_action policy_prim = NETKIT_PASS;
enum netkit_action policy_peer = NETKIT_PASS;
@@ -184,14 +184,15 @@ static int pfcp_add_sock(struct pfcp_dev *pfcp)
return PTR_ERR_OR_ZERO(pfcp->sock);
}
-static int pfcp_newlink(struct net *net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int pfcp_newlink(struct rtnl_newlink_params *params)
{
- struct pfcp_dev *pfcp = netdev_priv(dev);
+ struct net_device *dev = params->dev;
+ struct net *net = params->net;
+ struct pfcp_dev *pfcp;
struct pfcp_net *pn;
int err;
+ pfcp = netdev_priv(dev);
pfcp->net = net;
err = pfcp_add_sock(pfcp);
@@ -1303,10 +1303,12 @@ static int ppp_nl_validate(struct nlattr *tb[], struct nlattr *data[],
return 0;
}
-static int ppp_nl_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int ppp_nl_newlink(struct rtnl_newlink_params *params)
{
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct net *src_net = params->net;
+ struct nlattr **tb = params->tb;
struct ppp_config conf = {
.unit = -1,
.ifname_is_set = true,
@@ -2207,10 +2207,11 @@ static void team_setup(struct net_device *dev)
dev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX;
}
-static int team_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int team_newlink(struct rtnl_newlink_params *params)
{
+ struct net_device *dev = params->dev;
+ struct nlattr **tb = params->tb;
+
if (tb[IFLA_ADDRESS] == NULL)
eth_hw_addr_random(dev);
@@ -1765,10 +1765,13 @@ static int veth_init_queues(struct net_device *dev, struct nlattr *tb[])
return 0;
}
-static int veth_newlink(struct net *peer_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int veth_newlink(struct rtnl_newlink_params *params)
{
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct net *peer_net = params->net;
+ struct nlattr **tb = params->tb;
int err;
struct net_device *peer;
struct veth_priv *priv;
@@ -1677,16 +1677,19 @@ static void vrf_dellink(struct net_device *dev, struct list_head *head)
unregister_netdevice_queue(dev, head);
}
-static int vrf_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int vrf_newlink(struct rtnl_newlink_params *params)
{
- struct net_vrf *vrf = netdev_priv(dev);
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
struct netns_vrf *nn_vrf;
+ struct net_vrf *vrf;
bool *add_fib_rules;
struct net *net;
int err;
+ vrf = netdev_priv(dev);
+
if (!data || !data[IFLA_VRF_TABLE]) {
NL_SET_ERR_MSG(extack, "VRF table id is missing");
return -EINVAL;
@@ -4393,10 +4393,13 @@ static int vxlan_nl2conf(struct nlattr *tb[], struct nlattr *data[],
return 0;
}
-static int vxlan_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int vxlan_newlink(struct rtnl_newlink_params *params)
{
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct net *src_net = params->net;
+ struct nlattr **tb = params->tb;
struct vxlan_config conf;
int err;
@@ -307,13 +307,14 @@ static void wg_setup(struct net_device *dev)
wg->dev = dev;
}
-static int wg_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int wg_newlink(struct rtnl_newlink_params *params)
{
- struct wg_device *wg = netdev_priv(dev);
+ struct net_device *dev = params->dev;
+ struct net *src_net = params->net;
+ struct wg_device *wg;
int ret = -ENOMEM;
+ wg = netdev_priv(dev);
rcu_assign_pointer(wg->creating_net, src_net);
init_rwsem(&wg->static_identity.lock);
mutex_init(&wg->socket_update_lock);
@@ -519,13 +519,17 @@ static rx_handler_result_t virt_wifi_rx_handler(struct sk_buff **pskb)
}
/* Called with rtnl lock held. */
-static int virt_wifi_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int virt_wifi_newlink(struct rtnl_newlink_params *params)
{
- struct virt_wifi_netdev_priv *priv = netdev_priv(dev);
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct virt_wifi_netdev_priv *priv;
+ struct net *src_net = params->net;
+ struct nlattr **tb = params->tb;
int err;
+ priv = netdev_priv(dev);
+
if (!tb[IFLA_LINK])
return -EINVAL;
@@ -967,15 +967,20 @@ static struct net_device *wwan_rtnl_alloc(struct nlattr *tb[],
return dev;
}
-static int wwan_rtnl_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int wwan_rtnl_newlink(struct rtnl_newlink_params *params)
{
- struct wwan_device *wwandev = wwan_dev_get_by_parent(dev->dev.parent);
- u32 link_id = nla_get_u32(data[IFLA_WWAN_LINK_ID]);
- struct wwan_netdev_priv *priv = netdev_priv(dev);
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct wwan_netdev_priv *priv;
+ struct wwan_device *wwandev;
+ u32 link_id;
int ret;
+ wwandev = wwan_dev_get_by_parent(dev->dev.parent);
+ link_id = nla_get_u32(data[IFLA_WWAN_LINK_ID]);
+ priv = netdev_priv(dev);
+
if (IS_ERR(wwandev))
return PTR_ERR(wwandev);
@@ -1064,6 +1069,11 @@ static void wwan_create_default_link(struct wwan_device *wwandev,
struct net_device *dev;
struct nlmsghdr *nlh;
struct sk_buff *msg;
+ struct rtnl_newlink_params params = {
+ .net = &init_net,
+ .tb = tb,
+ .data = data,
+ };
/* Forge attributes required to create a WWAN netdev. We first
* build a netlink message and then parse it. This looks
@@ -1105,7 +1115,8 @@ static void wwan_create_default_link(struct wwan_device *wwandev,
if (WARN_ON(IS_ERR(dev)))
goto unlock;
- if (WARN_ON(wwan_rtnl_newlink(&init_net, dev, tb, data, NULL))) {
+ params.dev = dev;
+ if (WARN_ON(wwan_rtnl_newlink(¶ms))) {
free_netdev(dev);
goto unlock;
}
@@ -69,6 +69,46 @@ 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
+ * @dev: The net_device being created
+ * @tb: IFLA_* attributes
+ * @data: IFLA_INFO_DATA attributes
+ * @extack: Netlink extended ACK
+ */
+struct rtnl_newlink_params {
+ struct net *net;
+ struct net *src_net;
+ struct net *link_net;
+ struct net *peer_net;
+ struct net_device *dev;
+ struct nlattr **tb;
+ struct nlattr **data;
+ struct netlink_ext_ack *extack;
+};
+
+/* Get effective link netns from newlink params. Generally, this is link_net
+ * and falls back to src_net. But for compatibility, a driver may * choose to
+ * use dev_net(dev) instead.
+ */
+static inline struct net *rtnl_newlink_link_net(struct rtnl_newlink_params *p)
+{
+ return p->link_net ? : p->src_net;
+}
+
+/* Get peer netns from newlink params. Fallback to link netns if peer netns is
+ * not specified explicitly.
+ */
+static inline struct net *rtnl_newlink_peer_net(struct rtnl_newlink_params *p)
+{
+ return p->peer_net ? : rtnl_newlink_link_net(p);
+}
+
/**
* struct rtnl_link_ops - rtnetlink link operations
*
@@ -125,11 +165,7 @@ 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[],
- struct netlink_ext_ack *extack);
+ int (*newlink)(struct rtnl_newlink_params *params);
int (*changelink)(struct net_device *dev,
struct nlattr *tb[],
struct nlattr *data[],
@@ -135,16 +135,21 @@ static int vlan_changelink(struct net_device *dev, struct nlattr *tb[],
return 0;
}
-static int vlan_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int vlan_newlink(struct rtnl_newlink_params *params)
{
- struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct net *src_net = params->net;
+ struct nlattr **tb = params->tb;
struct net_device *real_dev;
+ struct vlan_dev_priv *vlan;
unsigned int max_mtu;
__be16 proto;
int err;
+ vlan = vlan_dev_priv(dev);
+
if (!data[IFLA_VLAN_ID]) {
NL_SET_ERR_MSG_MOD(extack, "VLAN id not specified");
return -EINVAL;
@@ -1063,22 +1063,20 @@ static int batadv_softif_validate(struct nlattr *tb[], struct nlattr *data[],
/**
* batadv_softif_newlink() - pre-initialize and register new batadv link
- * @src_net: the applicable net namespace
- * @dev: network device to register
- * @tb: IFLA_INFO_DATA netlink attributes
- * @data: enum batadv_ifla_attrs attributes
- * @extack: extended ACK report struct
+ * @params: rtnl newlink parameters
*
* Return: 0 if successful or error otherwise.
*/
-static int batadv_softif_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int batadv_softif_newlink(struct rtnl_newlink_params *params)
{
- struct batadv_priv *bat_priv = netdev_priv(dev);
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct batadv_priv *bat_priv;
const char *algo_name;
int err;
+ bat_priv = netdev_priv(dev);
+
if (data && data[IFLA_BATADV_ALGO_NAME]) {
algo_name = nla_data(data[IFLA_BATADV_ALGO_NAME]);
err = batadv_algo_select(bat_priv, algo_name);
@@ -1553,13 +1553,17 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
return 0;
}
-static int br_dev_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int br_dev_newlink(struct rtnl_newlink_params *params)
{
- struct net_bridge *br = netdev_priv(dev);
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct nlattr **tb = params->tb;
+ struct net_bridge *br;
int err;
+ br = netdev_priv(dev);
+
err = register_netdevice(dev);
if (err)
return err;
@@ -438,10 +438,10 @@ static void caif_netlink_parms(struct nlattr *data[],
}
}
-static int ipcaif_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int ipcaif_newlink(struct rtnl_newlink_params *params)
{
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
int ret;
struct chnl_net *caifdev;
ASSERT_RTNL();
@@ -3757,6 +3757,15 @@ static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm,
struct net_device *dev;
char ifname[IFNAMSIZ];
int err;
+ struct rtnl_newlink_params params = {
+ .net = net,
+ .src_net = net,
+ .link_net = link_net,
+ .peer_net = peer_net,
+ .tb = tb,
+ .data = data,
+ .extack = extack,
+ };
if (!ops->alloc && !ops->setup)
return -EOPNOTSUPP;
@@ -3776,14 +3785,15 @@ static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm,
}
dev->ifindex = ifm->ifi_index;
+ params.dev = dev;
if (link_net)
- net = link_net;
+ params.net = link_net;
if (peer_net)
- net = peer_net;
+ params.net = peer_net;
if (ops->newlink)
- err = ops->newlink(net, dev, tb, data, extack);
+ err = ops->newlink(¶ms);
else
err = register_netdevice(dev);
if (err < 0) {
@@ -29,10 +29,12 @@ static const struct nla_policy hsr_policy[IFLA_HSR_MAX + 1] = {
/* Here, it seems a netdevice has already been allocated for us, and the
* hsr_dev_setup routine has been executed. Nice!
*/
-static int hsr_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int hsr_newlink(struct rtnl_newlink_params *params)
{
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct net *src_net = params->net;
enum hsr_version proto_version;
unsigned char multicast_spec;
u8 proto = HSR_PROTOCOL_HSR;
@@ -129,10 +129,10 @@ static int lowpan_validate(struct nlattr *tb[], struct nlattr *data[],
return 0;
}
-static int lowpan_newlink(struct net *src_net, struct net_device *ldev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int lowpan_newlink(struct rtnl_newlink_params *params)
{
+ struct net_device *ldev = params->dev;
+ struct nlattr **tb = params->tb;
struct net_device *wdev;
int ret;
@@ -1389,10 +1389,11 @@ ipgre_newlink_encap_setup(struct net_device *dev, struct nlattr *data[])
return 0;
}
-static int ipgre_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int ipgre_newlink(struct rtnl_newlink_params *params)
{
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct nlattr **tb = params->tb;
struct ip_tunnel_parm_kern p;
__u32 fwmark = 0;
int err;
@@ -1407,10 +1408,11 @@ static int ipgre_newlink(struct net *src_net, struct net_device *dev,
return ip_tunnel_newlink(dev, tb, &p, fwmark);
}
-static int erspan_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int erspan_newlink(struct rtnl_newlink_params *params)
{
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct nlattr **tb = params->tb;
struct ip_tunnel_parm_kern p;
__u32 fwmark = 0;
int err;
@@ -1695,6 +1697,10 @@ struct net_device *gretap_fb_dev_create(struct net *net, const char *name,
LIST_HEAD(list_kill);
struct ip_tunnel *t;
int err;
+ struct rtnl_newlink_params params = {
+ .net = net,
+ .tb = tb,
+ };
memset(&tb, 0, sizeof(tb));
@@ -1707,7 +1713,8 @@ struct net_device *gretap_fb_dev_create(struct net *net, const char *name,
t = netdev_priv(dev);
t->collect_md = true;
- err = ipgre_newlink(net, dev, tb, NULL, NULL);
+ params.dev = dev;
+ err = ipgre_newlink(¶ms);
if (err < 0) {
free_netdev(dev);
return ERR_PTR(err);
@@ -575,11 +575,12 @@ static void vti_netlink_parms(struct nlattr *data[],
*fwmark = nla_get_u32(data[IFLA_VTI_FWMARK]);
}
-static int vti_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int vti_newlink(struct rtnl_newlink_params *params)
{
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
struct ip_tunnel_parm_kern parms;
+ struct nlattr **tb = params->tb;
__u32 fwmark = 0;
vti_netlink_parms(data, &parms, &fwmark);
@@ -436,15 +436,18 @@ static void ipip_netlink_parms(struct nlattr *data[],
*fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]);
}
-static int ipip_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int ipip_newlink(struct rtnl_newlink_params *params)
{
- struct ip_tunnel *t = netdev_priv(dev);
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct nlattr **tb = params->tb;
struct ip_tunnel_encap ipencap;
struct ip_tunnel_parm_kern p;
+ struct ip_tunnel *t;
__u32 fwmark = 0;
+ t = netdev_priv(dev);
+
if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
int err = ip_tunnel_encap_setup(t, &ipencap);
@@ -2005,15 +2005,19 @@ static int ip6gre_newlink_common(struct net *src_net, struct net_device *dev,
return err;
}
-static int ip6gre_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int ip6gre_newlink(struct rtnl_newlink_params *params)
{
- struct ip6_tnl *nt = netdev_priv(dev);
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct net *src_net = params->net;
+ struct nlattr **tb = params->tb;
struct net *net = dev_net(dev);
struct ip6gre_net *ign;
+ struct ip6_tnl *nt;
int err;
+ nt = netdev_priv(dev);
ip6gre_netlink_parms(data, &nt->parms);
ign = net_generic(net, ip6gre_net_id);
@@ -2241,15 +2245,19 @@ static void ip6erspan_tap_setup(struct net_device *dev)
netif_keep_dst(dev);
}
-static int ip6erspan_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int ip6erspan_newlink(struct rtnl_newlink_params *params)
{
- struct ip6_tnl *nt = netdev_priv(dev);
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct net *src_net = params->net;
+ struct nlattr **tb = params->tb;
struct net *net = dev_net(dev);
struct ip6gre_net *ign;
+ struct ip6_tnl *nt;
int err;
+ nt = netdev_priv(dev);
ip6gre_netlink_parms(data, &nt->parms);
ip6erspan_set_version(data, &nt->parms);
ign = net_generic(net, ip6gre_net_id);
@@ -2002,10 +2002,11 @@ static void ip6_tnl_netlink_parms(struct nlattr *data[],
parms->fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]);
}
-static int ip6_tnl_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int ip6_tnl_newlink(struct rtnl_newlink_params *params)
{
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct nlattr **tb = params->tb;
struct net *net = dev_net(dev);
struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
struct ip_tunnel_encap ipencap;
@@ -997,10 +997,10 @@ static void vti6_netlink_parms(struct nlattr *data[],
parms->fwmark = nla_get_u32(data[IFLA_VTI_FWMARK]);
}
-static int vti6_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int vti6_newlink(struct rtnl_newlink_params *params)
{
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
struct net *net = dev_net(dev);
struct ip6_tnl *nt;
@@ -1550,10 +1550,11 @@ static bool ipip6_netlink_6rd_parms(struct nlattr *data[],
}
#endif
-static int ipip6_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int ipip6_newlink(struct rtnl_newlink_params *params)
{
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
+ struct nlattr **tb = params->tb;
struct net *net = dev_net(dev);
struct ip_tunnel *nt;
struct ip_tunnel_encap ipencap;
@@ -814,10 +814,11 @@ static void xfrmi_netlink_parms(struct nlattr *data[],
parms->collect_md = true;
}
-static int xfrmi_newlink(struct net *src_net, struct net_device *dev,
- struct nlattr *tb[], struct nlattr *data[],
- struct netlink_ext_ack *extack)
+static int xfrmi_newlink(struct rtnl_newlink_params *params)
{
+ struct netlink_ext_ack *extack = params->extack;
+ struct net_device *dev = params->dev;
+ struct nlattr **data = params->data;
struct net *net = dev_net(dev);
struct xfrm_if_parms p = {};
struct xfrm_if *xi;
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. 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. To make the semantics more clear, two helper functions - rtnl_newlink_link_net() and rtnl_newlink_peer_net() - are provided for netns fallback logic. Peer netns falls back to link netns, and link netns falls back to source netns. In following patches, to prepare for creating link in target netns directly: - For device drivers that are aware of the old "src_net", the use of it are replace with one of the two helper functions. - And for those that takes dev_net() as link netns, we try params->link_net and then dev_net(), in order to maintain compatibility with the old behavior. Signed-off-by: Xiao Liang <shaw.leon@gmail.com> --- drivers/infiniband/ulp/ipoib/ipoib_netlink.c | 9 ++-- drivers/net/amt.c | 12 +++-- drivers/net/bareudp.c | 9 ++-- drivers/net/bonding/bond_netlink.c | 8 ++-- drivers/net/can/dev/netlink.c | 4 +- drivers/net/can/vxcan.c | 9 ++-- .../ethernet/qualcomm/rmnet/rmnet_config.c | 9 ++-- drivers/net/geneve.c | 9 ++-- drivers/net/gtp.c | 7 +-- drivers/net/ipvlan/ipvlan.h | 4 +- drivers/net/ipvlan/ipvlan_main.c | 13 ++++-- drivers/net/ipvlan/ipvtap.c | 10 ++-- drivers/net/macsec.c | 13 ++++-- drivers/net/macvlan.c | 7 ++- drivers/net/macvtap.c | 11 +++-- drivers/net/netkit.c | 9 ++-- drivers/net/pfcp.c | 9 ++-- drivers/net/ppp/ppp_generic.c | 8 ++-- drivers/net/team/team_core.c | 7 +-- drivers/net/veth.c | 9 ++-- drivers/net/vrf.c | 11 +++-- drivers/net/vxlan/vxlan_core.c | 9 ++-- drivers/net/wireguard/device.c | 9 ++-- drivers/net/wireless/virtual/virt_wifi.c | 12 +++-- drivers/net/wwan/wwan_core.c | 25 +++++++--- include/net/rtnetlink.h | 46 +++++++++++++++++-- net/8021q/vlan_netlink.c | 13 ++++-- net/batman-adv/soft-interface.c | 16 +++---- net/bridge/br_netlink.c | 12 +++-- net/caif/chnl_net.c | 6 +-- net/core/rtnetlink.c | 16 +++++-- net/hsr/hsr_netlink.c | 8 ++-- net/ieee802154/6lowpan/core.c | 6 +-- net/ipv4/ip_gre.c | 21 ++++++--- net/ipv4/ip_vti.c | 7 +-- net/ipv4/ipip.c | 11 +++-- net/ipv6/ip6_gre.c | 24 ++++++---- net/ipv6/ip6_tunnel.c | 7 +-- net/ipv6/ip6_vti.c | 6 +-- net/ipv6/sit.c | 7 +-- net/xfrm/xfrm_interface_core.c | 7 +-- 41 files changed, 296 insertions(+), 159 deletions(-)