netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] iproute2: ip link: add support for network device groups
@ 2011-01-10 11:39 Vlad Dogaru
  2011-01-10 11:39 ` [PATCH 1/3] ip link: add support for setting " Vlad Dogaru
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Vlad Dogaru @ 2011-01-10 11:39 UTC (permalink / raw)
  To: netdev, netdev; +Cc: Vlad Dogaru, jamal, Octavian Purdila

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 and IFLA_FILTERGROUP messages, for which
I posted pathes in a different set.


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   |    3 ++
 include/linux/netdevice.h |    2 +-
 include/utils.h           |    3 +-
 ip/ipaddress.c            |   14 +++++++++++
 ip/iplink.c               |   54 +++++++++++++++++++++++++++++++++++++++++++-
 ip/link_veth.c            |    3 +-
 6 files changed, 74 insertions(+), 5 deletions(-)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] ip link: add support for setting device groups
  2011-01-10 11:39 [PATCH 0/3] iproute2: ip link: add support for network device groups Vlad Dogaru
@ 2011-01-10 11:39 ` Vlad Dogaru
  2011-01-10 11:39 ` [PATCH 2/3] ip link: support listing devices by group Vlad Dogaru
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Vlad Dogaru @ 2011-01-10 11:39 UTC (permalink / raw)
  To: netdev, netdev; +Cc: Vlad Dogaru, jamal, Octavian Purdila

Use the group keyword to specify what group the device should belong to:

  ip link set dev eth0 group 1

Signed-off-by: Vlad Dogaru <ddvlad@rosedu.org>
---
 include/linux/if_link.h |    2 ++
 ip/iplink.c             |    8 ++++++++
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/include/linux/if_link.h b/include/linux/if_link.h
index f5bb2dc..1d789dd 100644
--- a/include/linux/if_link.h
+++ b/include/linux/if_link.h
@@ -116,6 +116,8 @@ enum {
 	IFLA_STATS64,
 	IFLA_VF_PORTS,
 	IFLA_PORT_SELF,
+	IFLA_AF_SPEC,
+	IFLA_GROUP,
 	__IFLA_MAX
 };
 
diff --git a/ip/iplink.c b/ip/iplink.c
index cb2c4f5..a7bad2c 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -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)
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] ip link: support listing devices by group
  2011-01-10 11:39 [PATCH 0/3] iproute2: ip link: add support for network device groups Vlad Dogaru
  2011-01-10 11:39 ` [PATCH 1/3] ip link: add support for setting " Vlad Dogaru
@ 2011-01-10 11:39 ` Vlad Dogaru
  2011-01-10 11:39 ` [PATCH 3/3] ip link: support setting device parameters " Vlad Dogaru
  2011-01-10 16:47 ` [PATCH 0/3] iproute2: ip link: add support for network device groups Stephen Hemminger
  3 siblings, 0 replies; 6+ messages in thread
From: Vlad Dogaru @ 2011-01-10 11:39 UTC (permalink / raw)
  To: netdev, netdev; +Cc: Vlad Dogaru, jamal, Octavian Purdila

User can specify device group to list by using the devgroup keyword:

	ip link lst devgroup 1

If no group is specified, 0 is implied.

Signed-off-by: Vlad Dogaru <ddvlad@rosedu.org>
---
 include/linux/netdevice.h |    2 +-
 ip/ipaddress.c            |   14 ++++++++++++++
 ip/iplink.c               |    1 +
 3 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index bec4e23..ad2e34d 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -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 {
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index a775ecd..66e4350 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -49,6 +49,7 @@ static struct
 	char *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();
diff --git a/ip/iplink.c b/ip/iplink.c
index a7bad2c..c0378e7 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -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");
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] ip link: support setting device parameters by group
  2011-01-10 11:39 [PATCH 0/3] iproute2: ip link: add support for network device groups Vlad Dogaru
  2011-01-10 11:39 ` [PATCH 1/3] ip link: add support for setting " Vlad Dogaru
  2011-01-10 11:39 ` [PATCH 2/3] ip link: support listing devices by group Vlad Dogaru
@ 2011-01-10 11:39 ` Vlad Dogaru
  2011-01-10 16:47 ` [PATCH 0/3] iproute2: ip link: add support for network device groups Stephen Hemminger
  3 siblings, 0 replies; 6+ messages in thread
From: Vlad Dogaru @ 2011-01-10 11:39 UTC (permalink / raw)
  To: netdev, netdev; +Cc: Vlad Dogaru, jamal, Octavian Purdila

Users 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

This also allows merging device groups; the command below will move
all interfaces in group 1 to the default group (0).

	ip link set group 0 devgroup 1

Signed-off-by: Vlad Dogaru <ddvlad@rosedu.org>
---
 include/linux/if_link.h |    1 +
 include/utils.h         |    3 ++-
 ip/iplink.c             |   45 +++++++++++++++++++++++++++++++++++++++++++--
 ip/link_veth.c          |    3 ++-
 4 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/include/linux/if_link.h b/include/linux/if_link.h
index 1d789dd..9286bbd 100644
--- a/include/linux/if_link.h
+++ b/include/linux/if_link.h
@@ -118,6 +118,7 @@ enum {
 	IFLA_PORT_SELF,
 	IFLA_AF_SPEC,
 	IFLA_GROUP,
+	IFLA_FILTERGROUP,
 	__IFLA_MAX
 };
 
diff --git a/include/utils.h b/include/utils.h
index 3da6998..f9d4931 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -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__ */
diff --git a/ip/iplink.c b/ip/iplink.c
index c0378e7..cd05a33 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -245,7 +245,8 @@ int iplink_parse_vf(int vf, int *argcp, char ***argvp,
 
 
 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)
 {
 	int ret, len;
 	char abuf[32];
@@ -256,6 +257,7 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
 	int group = -1;
 
 	ret = argc;
+	*devgroup = -1; /* Not set. */
 
 	while (argc > 0) {
 		if (strcmp(*argv, "up") == 0) {
@@ -395,6 +397,20 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
 		} else {
 			if (strcmp(*argv, "dev") == 0) {
 				NEXT_ARG();
+				if (*dev)
+					duparg2("dev", *argv);
+				*dev = *argv;
+				argc--; argv++;
+				continue;
+			}
+			if (matches(*argv, "devgroup") == 0) {
+				NEXT_ARG();
+				if (*devgroup != -1)
+					duparg("devgroup", *argv);
+				if (get_integer(devgroup, *argv, 0))
+					invarg("Invalid \"devgroup\" value\n", *argv);
+				argc--; argv++;
+				continue;
 			}
 			if (matches(*argv, "help") == 0)
 				usage();
@@ -405,6 +421,11 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
 		argc--; argv++;
 	}
 
+	if (*dev && (*devgroup != -1)) {
+		fprintf(stderr, "dev and devgroup cannot be both be present.\n");
+		exit(-1);
+	}
+
 	return ret - argc;
 }
 
@@ -415,6 +436,7 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
 	char *name = NULL;
 	char *link = NULL;
 	char *type = NULL;
+	int devgroup;
 	struct link_util *lu = NULL;
 	struct iplink_req req;
 	int ret;
@@ -426,12 +448,31 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
 	req.n.nlmsg_type = cmd;
 	req.i.ifi_family = preferred_family;
 
-	ret = iplink_parse(argc, argv, &req, &name, &type, &link, &dev);
+	ret = iplink_parse(argc, argv, &req, &name, &type, &link, &dev, &devgroup);
 	if (ret < 0)
 		return ret;
 
 	argc -= ret;
 	argv += ret;
+
+	if (devgroup != -1) {
+		if (argc) {
+			fprintf(stderr, "Garbage instead of arguments \"%s ...\". "
+					"Try \"ip link help\".\n", *argv);
+			return -1;
+		}
+		if (flags & NLM_F_CREATE) {
+			fprintf(stderr, "devgroup cannot be used when "
+					"creating devices.\n");
+			return -1;
+		}
+
+		addattr32(&req.n, sizeof(req), IFLA_FILTERGROUP, devgroup);
+		if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0)
+			exit(2);
+		return 0;
+	}
+
 	ll_init_map(&rth);
 
 	if (type) {
diff --git a/ip/link_veth.c b/ip/link_veth.c
index 9f5e871..06974e7 100644
--- a/ip/link_veth.c
+++ b/ip/link_veth.c
@@ -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;
 
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] iproute2: ip link: add support for network device groups
  2011-01-10 11:39 [PATCH 0/3] iproute2: ip link: add support for network device groups Vlad Dogaru
                   ` (2 preceding siblings ...)
  2011-01-10 11:39 ` [PATCH 3/3] ip link: support setting device parameters " Vlad Dogaru
@ 2011-01-10 16:47 ` Stephen Hemminger
  2011-01-11 12:38   ` jamal
  3 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2011-01-10 16:47 UTC (permalink / raw)
  To: Vlad Dogaru; +Cc: netdev, jamal, Octavian Purdila

On Mon, 10 Jan 2011 13:39:16 +0200
Vlad Dogaru <ddvlad@rosedu.org> wrote:

> 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 and IFLA_FILTERGROUP messages, for which
> I posted pathes in a different set.
> 
> 
> 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   |    3 ++
>  include/linux/netdevice.h |    2 +-
>  include/utils.h           |    3 +-
>  ip/ipaddress.c            |   14 +++++++++++
>  ip/iplink.c               |   54 +++++++++++++++++++++++++++++++++++++++++++-
>  ip/link_veth.c            |    3 +-
>  6 files changed, 74 insertions(+), 5 deletions(-)

I like the idea, but I wonder if we should take it farther?
Should it be hierarchal tree of groups?
Should slave devices (ppp, vlan, etc) be automatically assigned
to group of parent?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] iproute2: ip link: add support for network device groups
  2011-01-10 16:47 ` [PATCH 0/3] iproute2: ip link: add support for network device groups Stephen Hemminger
@ 2011-01-11 12:38   ` jamal
  0 siblings, 0 replies; 6+ messages in thread
From: jamal @ 2011-01-11 12:38 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Vlad Dogaru, netdev, Octavian Purdila

On Mon, 2011-01-10 at 08:47 -0800, Stephen Hemminger wrote:

> I like the idea, but I wonder if we should take it farther?
> Should it be hierarchal tree of groups?
> Should slave devices (ppp, vlan, etc) be automatically assigned
> to group of parent?

I think that would be treading into policy land.
The whole point is that the admin sets this value (just like the
skb->mark) and specifies how it is to be used.

cheers,
jamal


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-01-11 12:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-10 11:39 [PATCH 0/3] iproute2: ip link: add support for network device groups Vlad Dogaru
2011-01-10 11:39 ` [PATCH 1/3] ip link: add support for setting " Vlad Dogaru
2011-01-10 11:39 ` [PATCH 2/3] ip link: support listing devices by group Vlad Dogaru
2011-01-10 11:39 ` [PATCH 3/3] ip link: support setting device parameters " Vlad Dogaru
2011-01-10 16:47 ` [PATCH 0/3] iproute2: ip link: add support for network device groups Stephen Hemminger
2011-01-11 12:38   ` jamal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).