net: rtnetlink: support specifying device flags on device creation
Subsystems (2)
The following patches add support to specify the device flags (like UP) when creating a new device through rtnl_link. This requires to surpress netlink notifications until the device is fully configured in order to not confuse userspace when changing the flags fails and registration has to be undone. Once the device is configured, a single NEWLINK message with the full state is sent.
The individual patch changelogs describe the necessary changes in more detail.
drivers/net/veth.c | 15 +++-- include/linux/netdevice.h | 9 ++- include/net/rtnetlink.h | 2 + net/core/dev.c | 171 +++++++++++++++++++++++++++++---------------- net/core/rtnetlink.c | 59 ++++++++++++---- 5 files changed, 176 insertions(+), 80 deletions(-)
Patrick McHardy (4):
net: rtnetlink: ignore NETDEV_PRE_UP notifier in rtnetlink_event()
net: rtnetlink: handle rtnl_link netlink notifications manually
net: dev: support deferring device flag change notifications
net: rtnetlink: support specifying device flags on device creation
net 01/04: rtnetlink: ignore NETDEV_PRE_UP notifier in rtnetlink_event()
commit 140dcbaa692be4ce66e68624d438aed030184186
Author: Patrick McHardy <[email protected]> Date: Tue Feb 23 20:56:39 2010 +0100
net: rtnetlink: ignore NETDEV_PRE_UP notifier in rtnetlink_event()
Commit 3b8bcfd (net: introduce pre-up netdev notifier) added a new notifier which is run before a device is set UP for use by cfg80211.
The patch missed to add the new notifier to the ignore list in rtnetlink_event(), so we currently get an unnecessary netlink notification before a device is set UP.
net/core/rtnetlink.c +1 -0
@@ -1432,6 +1432,7 @@ static int rtnetlink_event(struct notifier_block *this, unsigned long event, voicase NETDEV_DOWN :rtmsg_ifinfo (RTM_NEWLINK , dev,IFF_UP |IFF_RUNNING );break ; +case NETDEV_PRE_UP :case NETDEV_POST_INIT :case NETDEV_REGISTER :case NETDEV_CHANGE :
net 02/04: rtnetlink: handle rtnl_link netlink notifications manually
In reply to Patrick McHardycommit d1a41c4805fd5850156668114d42d7a51964926a
Author: Patrick McHardy <[email protected]> Date: Wed Feb 24 13:52:52 2010 +0100
net: rtnetlink: handle rtnl_link netlink notifications manually
In order to support specifying device flags during device creation, we must be able to roll back device registration in case setting the flags fails without sending any notifications related to the device to userspace.
This patch changes rollback_registered_many() and register_netdevice() to manually send netlink notifications for devices not handled by rtnl_link and allows to defer notifications for devices handled by rtnl_link until setup is complete.
include/linux/netdevice.h +6 -1
@@ -924,7 +924,12 @@ struct net_device {NETREG_UNREGISTERED ,/* completed unregister todo */ NETREG_RELEASED ,/* called free_netdev */ NETREG_DUMMY ,/* dummy device for NAPI poll */ - } reg_state; + } reg_state:16; + +enum { +RTNL_LINK_INITIALIZED , +RTNL_LINK_INITIALIZING , + } rtnl_link_state:16;/* Called from unregister, can be used to call free_netdev */ void (*destructor)(struct net_device *dev);
net/core/dev.c +7 -1
@@ -4865,6 +4865,10 @@ static void rollback_registered_many(struct list_head *head)*/ call_netdevice_notifiers (NETDEV_UNREGISTER , dev); +if (!dev->rtnl_link_ops || + dev->rtnl_link_state ==RTNL_LINK_INITIALIZED ) +rtmsg_ifinfo (RTM_DELLINK , dev, ~0U ); +/* * Flush the unicast and multicast chains */
@@ -5091,7 +5095,9 @@ int register_netdevice(struct net_device *dev)* Prevent userspace races by waiting until the network * device is fully setup before sending notifications. */ -rtmsg_ifinfo (RTM_NEWLINK , dev, ~0U ); +if (!dev->rtnl_link_ops || + dev->rtnl_link_state ==RTNL_LINK_INITIALIZED ) +rtmsg_ifinfo (RTM_NEWLINK , dev, ~0U ); out:return ret;
net/core/rtnetlink.c +1 -3
@@ -1425,9 +1425,6 @@ static int rtnetlink_event(struct notifier_block *this, unsigned long event, voistruct net_device *dev = ptr;switch (event) { -case NETDEV_UNREGISTER : -rtmsg_ifinfo (RTM_DELLINK , dev, ~0U ); -break ;case NETDEV_UP :case NETDEV_DOWN :rtmsg_ifinfo (RTM_NEWLINK , dev,IFF_UP |IFF_RUNNING );
@@ -1437,6 +1434,7 @@ static int rtnetlink_event(struct notifier_block *this, unsigned long event, voicase NETDEV_REGISTER :case NETDEV_CHANGE :case NETDEV_GOING_DOWN : +case NETDEV_UNREGISTER :case NETDEV_UNREGISTER_BATCH :break ;default :
net 03/04: dev: support deferring device flag change notifications
In reply to Patrick McHardycommit 18c626db4551a23d1f848adafad41e44388b6c2f
Author: Patrick McHardy <[email protected]> Date: Wed Feb 24 15:51:55 2010 +0100
net: dev: support deferring device flag change notifications
Split dev_change_flags() into two functions: __dev_change_flags() to perform the actual changes and __dev_notify_flags() to invoke netdevice notifiers. This will be used by rtnl_link to defer netlink notifications until the device has been fully configured.
This changes ordering of some operations, in particular:
- netlink notifications are sent after all changes have been performed. As a side effect this surpresses one unnecessary netlink message when the IFF_UP and other flags are changed simultaneously.
- The NETDEV_UP/NETDEV_DOWN and NETDEV_CHANGE notifiers are invoked after all changes have been performed. Their relative is unchanged.
- net_dmaengine_put() is invoked before the NETDEV_DOWN notifier instead of afterwards. This should not make any difference since both RX and TX are already shut down at this point.
include/linux/netdevice.h +2 -0
@@ -1587,7 +1587,9 @@ extern int dev_valid_name(const char *name);extern int dev_ioctl (struct net *net,unsigned int cmd,void __user *);extern int dev_ethtool (struct net *net,struct ifreq *);extern unsigned dev_get_flags (const struct net_device *); +extern int __dev_change_flags (struct net_device *,unsigned int flags);extern int dev_change_flags (struct net_device *,unsigned ); +extern void __dev_notify_flags (struct net_device *,unsigned int old_flags);extern int dev_change_name (struct net_device *,const char *);extern int dev_set_alias (struct net_device *,const char *,size_t ); extern int dev_change_net_namespace(struct net_device *,
net/core/dev.c +104 -59
232 lines not on this page · raw message
net/core/rtnetlink.c +0 -2
@@ -1427,8 +1427,6 @@ static int rtnetlink_event(struct notifier_block *this, unsigned long event, voiswitch (event) {case NETDEV_UP :case NETDEV_DOWN : -rtmsg_ifinfo (RTM_NEWLINK , dev,IFF_UP |IFF_RUNNING ); -break ;case NETDEV_PRE_UP :case NETDEV_POST_INIT :case NETDEV_REGISTER :
net 04/04: rtnetlink: support specifying device flags on device creation
In reply to Patrick McHardycommit e8469ed959c373c2ff9e6f488aa5a14971aebe1f
Author: Patrick McHardy <[email protected]> Date: Tue Feb 23 20:41:30 2010 +0100
net: rtnetlink: support specifying device flags on device creation
Support specifying the initial device flags when creating a device though rtnl_link. Devices allocated by rtnl_create_link() are marked as INITIALIZING in order to surpress netlink registration notifications. To complete setup, rtnl_configure_link() must be called, which performs the device flag changes and invokes the deferred notifiers if everything went well.
Two examples:
# add macvlan to eth0
#
$ ip link add link eth0 up allmulticast on type macvlan
[LINK]11: macvlan0@eth0: <BROADCAST,MULTICAST,ALLMULTI,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/ether 26:f8:84:02:f9:2a brd ff:ff:ff:ff:ff:ff
[ROUTE]ff00::/8 dev macvlan0 table local metric 256 mtu 1500 advmss 1440 hoplimit 0 [ROUTE]fe80::/64 dev macvlan0 proto kernel metric 256 mtu 1500 advmss 1440 hoplimit 0
[LINK]11: macvlan0@eth0: <BROADCAST,MULTICAST,ALLMULTI,UP,LOWER_UP> mtu 1500
link/ether 26:f8:84:02:f9:2a
[ADDR]11: macvlan0 inet6 fe80::24f8:84ff:fe02:f92a/64 scope link
valid_lft forever preferred_lft forever
[ROUTE]local fe80::24f8:84ff:fe02:f92a via :: dev lo table local proto none metric 0 mtu 16436 advmss 16376 hoplimit 0 [ROUTE]default via fe80::215:e9ff:fef0:10f8 dev macvlan0 proto kernel metric 1024 mtu 1500 advmss 1440 hoplimit 0 [NEIGH]fe80::215:e9ff:fef0:10f8 dev macvlan0 lladdr 00:15:e9:f0:10:f8 router STALE [ROUTE]2001:6f8:974::/64 dev macvlan0 proto kernel metric 256 expires 0sec mtu 1500 advmss 1440 hoplimit 0 [PREFIX]prefix 2001:6f8:974::/64 dev macvlan0 onlink autoconf valid 14400 preferred 131084
[ADDR]11: macvlan0 inet6 2001:6f8:974:0:24f8:84ff:fe02:f92a/64 scope global dynamic
valid_lft 86399sec preferred_lft 14399sec
# add VLAN to eth1, eth1 is down
#
$ ip link add link eth1 up type vlan id 1000
RTNETLINK answers: Network is down
<no events>
drivers/net/veth.c +10 -5
@@ -333,19 +333,17 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,struct veth_priv *priv;char ifname[IFNAMSIZ ];struct nlattr *peer_tb[IFLA_MAX +1 ], **tbp; +struct ifinfomsg *ifmp;struct net *net;/* * create and register peer first -* -* struct ifinfomsg is at the head of VETH_INFO_PEER, but we -* skip it since no info from it is useful yet */ -if (data !=NULL && data[VETH_INFO_PEER ] !=NULL ) {struct nlattr *nla_peer; nla_peer = data[VETH_INFO_PEER ]; + ifmp =nla_data (nla_peer); err = nla_parse(peer_tb, IFLA_MAX, nla_data(nla_peer) + sizeof(struct ifinfomsg), nla_len(nla_peer) - sizeof(struct ifinfomsg),
@@ -358,8 +356,10 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,return err; tbp = peer_tb; - }else + }else { + ifmp =NULL ; tbp = tb; + }if (tbp[IFLA_IFNAME ])nla_strlcpy (ifname, tbp[IFLA_IFNAME ],IFNAMSIZ );
@@ -387,6 +387,10 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,netif_carrier_off (peer); + err =rtnl_configure_link (peer, ifmp); +if (err <0 ) + goto err_configure_peer; +/* * register dev last *
@@ -428,6 +432,7 @@ static int veth_newlink(struct net *src_net, struct net_device *dev, err_register_dev:/* nothing to do */ err_alloc_name: +err_configure_peer:unregister_netdevice (peer);return err;
include/net/rtnetlink.h +2 -0
@@ -87,6 +87,8 @@ extern void rtnl_link_unregister(struct rtnl_link_ops *ops);extern struct net *rtnl_link_get_net (struct net *src_net,struct nlattr *tb[]);extern struct net_device *rtnl_create_link (struct net *src_net,struct net *net,char *ifname,const struct rtnl_link_ops *ops,struct nlattr *tb[]); +extern int rtnl_configure_link (struct net_device *dev, +const struct ifinfomsg *ifm);extern const struct nla_policy ifla_policy[IFLA_MAX +1 ];#define MODULE_ALIAS_RTNL_LINK (kind) MODULE_ALIAS("rtnl-link-" kind)
net/core/rtnetlink.c +43 -9
90 lines not on this page · raw message
David Miller
maintainerFrom: Patrick McHardy <[email protected]>
Date: Fri, 26 Feb 2010 17:34:49 +0100 (MET)
Quoted 8 lines
The following patches add support to specify the device flags (like UP) when creating a new device through
rtnl_link. This requires to surpress netlink notifications until the device is fully configured in order to not confuse userspace when changing the flags fails and registration has to be undone. Once the device is configured, a single NEWLINK message with the full state is sent.The individual patch changelogs describe the necessary changes in more detail.
All applied, but two things:
1) This patch set was harder to review because there were no default initializations of the new enumeration you added to struct netdev.
I know RTNL_LINK_INITIALIZED is probably zero by C enumeration rules, and the zeroing out of new netdev objects gives us this, but I only figured that out after some time.
It deserved at least a commit message mention in patch #2.
2) I would really appreciate you forming your patch postings properly. I have to edit them every single time
You put the whole output of "git show" or "git format-patch" into your email body. That doesn't work, we don't want all of those commit ID etc. lines in there. It also causes every line of your commit messages to be indented by 4 spaces.
Your email body should just contain the unindented commit message and the signoffs, then the patch itself.
Your Subject lines are also not setup properly. Because the "net X/N:" thing isn't in [] brackets, it ends up in the commit message header lines when I feed your emails to "git am".
All of this could be avoided if you used git send-email but I realize that a lot of people dislike that for one reason or another (myself included), but if you're going to compose the emails by hand you ought to make it look the same (syntax wise) as what git send-email would have emitted.
Thanks!
Quoted 18 lines · David Miller
From: Patrick McHardy <[email protected]>
Date: Fri, 26 Feb 2010 17:34:49 +0100 (MET)Quoted 8 lines
The following patches add support to specify the device flags (like UP) when creating a new device through
rtnl_link. This requires to surpress netlink notifications until the device is fully configured in order to not confuse userspace when changing the flags fails and registration has to be undone. Once the device is configured, a single NEWLINK message with the full state is sent.The individual patch changelogs describe the necessary changes in more detail.
All applied, but two things:
1) This patch set was harder to review because there were no default initializations of the new enumeration you added to struct netdev.
Quoted 5 lines
I know
RTNL_LINK_INITIALIZEDis probably zero by C enumeration rules, and the zeroing out of new netdev objects gives us this, but I only figured that out after some time.It deserved at least a commit message mention in patch #2.
Agreed. The reason to use the value 0 for RTNL_LINK_INITIALIZED was that it avoids touching drivers that can register netdevices through non rtnl_link paths, like bonding, ifb or dummy.
Quoted 16 lines
2) I would really appreciate you forming your patch postings properly. I have to edit them every single time
You put the whole output of "git show" or "git format-patch" into your email body. That doesn't work, we don't want all of those commit ID etc. lines in there. It also causes every line of your commit messages to be indented by 4 spaces.
Your email body should just contain the unindented commit message and the signoffs, then the patch itself.
Your Subject lines are also not setup properly. Because the "net X/N:" thing isn't in [] brackets, it ends up in the commit message header lines when I feed your emails to "git am".
Quoted 5 lines
All of this could be avoided if you used git send-email but I realize that a lot of people dislike that for one reason or another (myself included), but if you're going to compose the emails by hand you ought to make it look the same (syntax wise) as what git send-email would have emitted.
I'll either switch to git-send-email or make sure my script works properly with git-am.