net: add device groups
Subsystems (2)
v3 cover net: add device groups
This patchset implements network device grouping and simple manipulation of groups. Netlink has been updated to provide group information and means of applying changes to members of a specific group via a single message.
The patchset has a corresponding one for iproute2, which implements the new functionality in userspace.
Some basic testing, using 1024 dummy network interfaces (all of them in group 0):
# time { for i in `seq 0 1023`; do ip l s dev dummy$i up; done }real 0m7.70s
user 0m0.36s
sys 0m4.85s
# time ip l s devgroup 0 up
real 0m0.14s
user 0m0.00s
sys 0m0.14s
# time { for i in `seq 0 1023`; do ip l s dev dummy$i mtu 2000; done }real 0m7.43s
user 0m0.48s
sys 0m4.72s
# time ip l s devgroup 0 mtu 2000
real 0m0.02s
user 0m0.00s
sys 0m0.02s
Improvement stems both from less user-kernel communication and from less processes being created.
Changes since version 2:
* fix net_device field type (should be int, not unsigned int).
* fix typo in commit message.
Changes since version 1:
* we avoid adding a new attribute type by using the following
convention: if no device name is specified, the interface index is negative, and there is a group specified, we change parameters for the whole group.
* the dummy module is no longer modified to include an initial group for the devices it creates. The user is responsible for moving them to a different group by means of the provided netlink interface.
Vlad Dogaru (2):
net_device: add support for network device groups
netlink: support setting devgroup parameters
include/linux/if_link.h | 1 + include/linux/netdevice.h | 7 +++++++ net/core/dev.c | 12 ++++++++++++ net/core/rtnetlink.c | 38 ++++++++++++++++++++++++++++++++++---- 4 files changed, 54 insertions(+), 4 deletions(-)
PATCH v3 1/2 net_device: add support for network device groups
Net devices can now be grouped, enabling simpler manipulation from userspace. This patch adds a group field to the net_device structure, as well as rtnetlink support to query and modify it.
--- include/linux/if_link.h | 1 + include/linux/netdevice.h | 7 +++++++ net/core/dev.c | 12 ++++++++++++ net/core/rtnetlink.c | 6 ++++++ 4 files changed, 26 insertions(+), 0 deletions(-)
include/linux/if_link.h +1 -0
@@ -135,6 +135,7 @@ enum {IFLA_VF_PORTS ,IFLA_PORT_SELF ,IFLA_AF_SPEC , +IFLA_GROUP ,/* Group the device belongs to */ __IFLA_MAX };
include/linux/netdevice.h +7 -0
@@ -75,6 +75,9 @@ struct wireless_dev;#define NET_RX_SUCCESS 0/* keep 'em coming, baby */ #define NET_RX_DROP 1/* packet dropped */ +/* Initial net device group. All devices belong to group 0 by default. */ +#define INIT_NETDEV_GROUP 0 +/* * Transmit return codes: transmit return codes originate from three different * namespaces:
@@ -1156,6 +1159,9 @@ struct net_device {/* phy device may attach itself for hardware timestamping */ struct phy_device *phydev; + +/* group the device belongs to */ +int group; };#define to_net_dev (d) container_of(d, struct net_device, dev)
@@ -1847,6 +1853,7 @@ extern int dev_set_alias(struct net_device *, const char *, size_t);extern int dev_change_net_namespace (struct net_device *,struct net *,const char *);extern int dev_set_mtu (struct net_device *,int ); +extern void dev_set_group (struct net_device *,int );extern int dev_set_mac_address (struct net_device *,struct sockaddr *); extern int dev_hard_start_xmit(struct sk_buff *skb,
net/core/dev.c +12 -0
@@ -4573,6 +4573,17 @@ int dev_set_mtu(struct net_device *dev, int new_mtu)EXPORT_SYMBOL (dev_set_mtu);/** +* dev_set_group - Change group this device belongs to +* @dev: device +* @new_group: group this device should belong to +*/ +void dev_set_group (struct net_device *dev,int new_group) +{ + dev->group = new_group; +} +EXPORT_SYMBOL (dev_set_group); + +/** * dev_set_mac_address - Change Media Access Control Address * @dev: device * @sa: new address
@@ -5698,6 +5709,7 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, dev->priv_flags =IFF_XMIT_DST_RELEASE ;setup (dev);strcpy (dev->name, name); + dev->group =INIT_NETDEV_GROUP ;return dev; free_pcpu:
net/core/rtnetlink.c +6 -0
@@ -868,6 +868,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, netif_running(dev) ? dev->operstate : IF_OPER_DOWN);NLA_PUT_U8 (skb,IFLA_LINKMODE , dev->link_mode);NLA_PUT_U32 (skb,IFLA_MTU , dev->mtu); +NLA_PUT_U32 (skb,IFLA_GROUP , dev->group);if (dev->ifindex != dev->iflink)NLA_PUT_U32 (skb,IFLA_LINK , dev->iflink);
@@ -1265,6 +1266,11 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm, modified =1 ; } +if (tb[IFLA_GROUP ]) { +dev_set_group (dev,nla_get_u32 (tb[IFLA_GROUP ])); + modified =1 ; + } +/* * Interface selected by interface index but interface * name provided implies that a name change has been
Signature · 1 line
1.7.1
Re: [PATCH v3 1/2] net_device: add support for network device groups
Quoted 5 lines · Vlad Dogaru
Net devices can now be grouped, enabling simpler manipulation from userspace. This patch adds a group field to the
net_devicestructure, as well as rtnetlink support to query and modify it.Signed-off-by Vlad Dogaru <[email protected]>
Good stuff.
cheers,
jamal
Re: [PATCH v3 1/2] net_device: add support for network device groups
In reply to Vlad DogaruFrom: Vlad Dogaru <[email protected]>
Date: Fri, 14 Jan 2011 11:38:30 +0200
Quoted 5 lines
Net devices can now be grouped, enabling simpler manipulation from userspace. This patch adds a group field to the
net_devicestructure, as well as rtnetlink support to query and modify it.Signed-off-by Vlad Dogaru <[email protected]>
Applied.
PATCH v3 2/2 netlink: support setting devgroup parameters
In reply to Vlad DogaruIf a rtnetlink request specifies a negative or zero ifindex and has no interface name attribute, but has a group attribute, then the chenges are made to all the interfaces belonging to the specified group.
--- net/core/rtnetlink.c | 32 ++++++++++++++++++++++++++++---- 1 files changed, 28 insertions(+), 4 deletions(-)
net/core/rtnetlink.c +28 -4
@@ -1558,6 +1558,24 @@ err: }EXPORT_SYMBOL (rtnl_create_link); +static int rtnl_group_changelink (struct net *net,int group, +struct ifinfomsg *ifm, +struct nlattr **tb) +{ +struct net_device *dev; +int err; + +for_each_netdev (net, dev) { +if (dev->group == group) { + err =do_setlink (dev, ifm, tb,NULL ,0 ); +if (err <0 ) +return err; + } + } + +return 0 ; +} +static int rtnl_newlink (struct sk_buff *skb,struct nlmsghdr *nlh,void *arg) {struct net *net =sock_net (skb->sk);
@@ -1585,10 +1603,16 @@ replay: ifm =nlmsg_data (nlh);if (ifm->ifi_index >0 ) dev =__dev_get_by_index (net, ifm->ifi_index); -else if (ifname[0 ]) - dev =__dev_get_by_name (net, ifname); -else - dev =NULL ; +else { +if (ifname[0 ]) + dev =__dev_get_by_name (net, ifname); +else if (tb[IFLA_GROUP ]) +return rtnl_group_changelink (net, +nla_get_u32 (tb[IFLA_GROUP ]), + ifm, tb); +else + dev =NULL ; + } err =validate_linkmsg (dev, tb);if (err <0 )
Signature · 1 line
1.7.1
Re: [PATCH v3 2/2] netlink: support setting devgroup parameters
Quoted 5 lines · Vlad Dogaru
If a rtnetlink request specifies a negative or zero ifindex and has no interface name attribute, but has a group attribute, then the chenges are made to all the interfaces belonging to the specified group.
Signed-off-by Vlad Dogaru <[email protected]>
cheers,
jamal
Re: [PATCH v3 2/2] netlink: support setting devgroup parameters
In reply to Vlad DogaruFrom: Vlad Dogaru <[email protected]>
Date: Fri, 14 Jan 2011 11:38:31 +0200
Quoted 5 lines
If a rtnetlink request specifies a negative or zero ifindex and has no interface name attribute, but has a group attribute, then the chenges are made to all the interfaces belonging to the specified group.
Signed-off-by Vlad Dogaru <[email protected]>
Applied.
Quoted 55 lines · On Fri, 14 Jan 2011 11:38:29 +0200 Vlad Dogaru <[email protected]> wrote:
This patchset implements network device grouping and simple manipulation of groups. Netlink has been updated to provide group information and means of applying changes to members of a specific group via a single message.
The patchset has a corresponding one for iproute2, which implements the new functionality in userspace.
Some basic testing, using 1024 dummy network interfaces (all of them in group 0):
# time { for i in `seq 0 1023`; do ip l s dev dummy$i up; done }real 0m7.70s
user 0m0.36s
sys 0m4.85s# time ip l s devgroup 0 upreal 0m0.14s
user 0m0.00s
sys 0m0.14s# time { for i in `seq 0 1023`; do ip l s dev dummy$i mtu 2000; done }real 0m7.43s
user 0m0.48s
sys 0m4.72s# time ip l s devgroup 0 mtu 2000real 0m0.02s
user 0m0.00s
sys 0m0.02sImprovement stems both from less user-kernel communication and from less processes being created.
Changes since version 2:
* fixnet_devicefield type (should be int, not unsigned int).
* fix typo in commit message.Changes since version 1:
* we avoid adding a new attribute type by using the following
convention: if no device name is specified, the interface index is negative, and there is a group specified, we change parameters for the whole group.
* the dummy module is no longer modified to include an initial group for the devices it creates. The user is responsible for moving them to a different group by means of the provided netlink interface.Vlad Dogaru (2):
net_device: add support for network device groups
netlink: support setting devgroup parameters
Quoted 5 lines
include/linux/if_link.h | 1 + include/linux/netdevice.h | 7 +++++++ net/core/dev.c | 12 ++++++++++++ net/core/rtnetlink.c | 38 ++++++++++++++++++++++++++++++++++---- 4 files changed, 54 insertions(+), 4 deletions(-)
What about a read/write sysfs interface as well?
/sys/class/net/eth0/devgroup
Not sure if numeric devgroup is best choice. Since this is more of a human interface parameter maybe it should be a string? Or have a translation in the utilities /etc/iproute2/devgroup?
Quoted 8 lines · Stephen Hemminger
Quoted 5 lines · On Fri, 14 Jan 2011 11:38:29 +0200 Vlad Dogaru <[email protected]> wrote:
This patchset implements network device grouping and simple manipulation of groups. Netlink has been updated to provide group information and means of applying changes to members of a specific group via a single message.
Quoted 5 lines
Quoted 2 lines
The patchset has a corresponding one for iproute2, which implements the new functionality in userspace.
What about a read/write sysfs interface as well?
/sys/class/net/eth0/devgroup
Oops, I overlooked that, probably because I've been testing in a virtual machine where the kernel has sysfs turned off -- less waiting for simple tests.
Quoted 3 lines
Not sure if numeric devgroup is best choice. Since this is more of a human interface parameter maybe it should be a string? Or have a translation in the utilities
/etc/iproute2/devgroup?
I didn't know about /etc/iproute2. I could add the devgroup file as you mention, seems like a good choice for userspace.
I'll update the patches with these, but it will probably take a few days, I have a few exams next week :)
Thanks for the suggestions,
Vlad