ip link: add support for network device groups
Subsystems (2)
v2 cover ip link: add support for network device groups
This patch series adds userspace support for network device groups. There is support for setting device groups, listing only interfaces of a specific group, and setting basic device parameters for all interfaces in a group.
The patches use the IFLA_GROUP attribute, for which I posted pathes in a different set.
Changes since version 1:
* a single attribute is used for both setting the group of a device and manipulating an entire group.
Vlad Dogaru (3):
ip link: add support for setting device groups ip link: support listing devices by group ip link: support setting device parameters by group
include/linux/if_link.h | 2 + include/linux/netdevice.h | 2 +- include/utils.h | 3 +- ip/ipaddress.c | 14 +++++++++++ ip/iplink.c | 55 +++++++++++++++++++++++++++++++++++++++++++- ip/link_veth.c | 3 +- 6 files changed, 74 insertions(+), 5 deletions(-)
PATCH v2 1/3 ip link: add support for setting device groups
Use the group keyword to specify what group the device should belong to:
ip link set dev eth0 group 1
--- include/linux/if_link.h | 2 ++ ip/iplink.c | 8 ++++++++ 2 files changed, 10 insertions(+), 0 deletions(-)
include/linux/if_link.h +2 -0
@@ -116,6 +116,8 @@ enum {IFLA_STATS64 ,IFLA_VF_PORTS ,IFLA_PORT_SELF , +IFLA_AF_SPEC , +IFLA_GROUP , __IFLA_MAX };
ip/iplink.c +8 -0
@@ -252,6 +252,7 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,int mtu =-1 ;int netns =-1 ;int vf =-1 ; +int group =-1 ; ret = argc;
@@ -297,6 +298,13 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,if (get_integer (&mtu, *argv,0 ))invarg ("Invalid \"mtu\" value\n" , *argv);addattr_l (&req->n,sizeof (*req),IFLA_MTU , &mtu,4 ); + }else if (strcmp (*argv,"group" ) ==0 ) { +NEXT_ARG (); +if (mtu !=-1 ) +duparg ("group" , *argv); +if (get_integer (&group, *argv,0 )) +invarg ("Invalid \"group\" value\n" , *argv); +addattr_l (&req->n,sizeof (*req),IFLA_GROUP , &group,4 ); }else if (strcmp (*argv,"netns" ) ==0 ) {NEXT_ARG ();if (netns !=-1 )
Signature · 1 line
1.7.1
PATCH v2 2/3 ip link: support listing devices by group
In reply to Vlad DogaruUser can specify device group to list by using the devgroup keyword:
ip link lst devgroup 1
If no group is specified, 0 is implied.
--- include/linux/netdevice.h | 2 +- ip/ipaddress.c | 14 ++++++++++++++ ip/iplink.c | 1 + 3 files changed, 16 insertions(+), 1 deletions(-)
include/linux/netdevice.h +1 -1
@@ -33,7 +33,7 @@#define MAX_ADDR_LEN 32/* Largest hardware address length */ - +#define INIT_NETDEV_GROUP 0/* Initial group net devices belong to */ /* Media selection options. */ enum {
ip/ipaddress.c +14 -0
@@ -49,6 +49,7 @@ static structchar *flushb;int flushp;int flushe; +int group; } filter;static int do_link;
@@ -246,6 +247,12 @@ int print_linkinfo(const struct sockaddr_nl *who, fnmatch(filter.label, RTA_DATA(tb[IFLA_IFNAME]), 0))return 0 ; +if (tb[IFLA_GROUP ]) { +int group = *(int *)RTA_DATA (tb[IFLA_GROUP ]); +if (group != filter.group) +return -1 ; + } +if (n->nlmsg_type ==RTM_DELLINK )fprintf (fp,"Deleted " );
@@ -718,9 +725,12 @@ static int ipaddr_list_or_flush(int argc, char **argv, int flush)if (filter.family ==AF_UNSPEC ) filter.family = preferred_family; + filter.group =INIT_NETDEV_GROUP ; +if (flush) {if (argc <=0 ) {fprintf (stderr,"Flush requires arguments.\n" ); +return -1 ; }if (filter.family ==AF_PACKET ) {
@@ -779,6 +789,10 @@ static int ipaddr_list_or_flush(int argc, char **argv, int flush) }else if (strcmp (*argv,"label" ) ==0 ) {NEXT_ARG (); filter.label = *argv; + }else if (strcmp (*argv,"devgroup" ) ==0 ) { +NEXT_ARG (); +if (get_integer (&filter.group, *argv,0 )) +invarg ("Invalid \"devgroup\" value\n" , *argv); }else {if (strcmp (*argv,"dev" ) ==0 ) {NEXT_ARG ();
ip/iplink.c +1 -0
@@ -66,6 +66,7 @@ void iplink_usage(void)fprintf (stderr," [ address LLADDR ]\n" );fprintf (stderr," [ broadcast LLADDR ]\n" );fprintf (stderr," [ mtu MTU ]\n" ); +fprintf (stderr," [ group GROUP ]\n" );fprintf (stderr," [ netns PID ]\n" );fprintf (stderr," [ alias NAME ]\n" );fprintf (stderr," [ vf NUM [ mac LLADDR ]\n" );
Signature · 1 line
1.7.1
PATCH v2 3/3 ip link: support setting device parameters by group
In reply to Vlad DogaruUsers can now modify basic device parameters with a single call. We use the devgroup keyword to specify the device group to work on. For instance, to take down all interfaces in group 1:
ip link set down devgroup 1
--- include/utils.h | 3 ++- ip/iplink.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- ip/link_veth.c | 3 ++- 3 files changed, 48 insertions(+), 4 deletions(-)
include/utils.h +2 -1
@@ -151,5 +151,6 @@ extern int makeargs(char *line, char *argv[], int maxargs);struct iplink_req ;int iplink_parse (int argc,char **argv,struct iplink_req *req, -char **name,char **type,char **link,char **dev); +char **name,char **type,char **link,char **dev, +int *devgroup);#endif /* __UTILS_H__ */
ip/iplink.c +44 -2
87 lines not on this page · raw message
ip/link_veth.c +2 -1
@@ -30,6 +30,7 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv,char *name, *type, *link, *dev;int err, len;struct rtattr * data; +int devgroup;if (strcmp (argv[0 ],"peer" ) !=0 ) {usage ();
@@ -42,7 +43,7 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv, hdr->nlmsg_len +=sizeof (struct ifinfomsg ); err =iplink_parse (argc -1 , argv +1 , (struct iplink_req *)hdr, - &name, &type, &link, &dev); + &name, &type, &link, &dev, &devgroup);if (err <0 )return err;
Signature · 1 line
1.7.1