diff mbox

[3/3] netlink: support setting devgroup parameters

Message ID 1294659524-22509-4-git-send-email-ddvlad@rosedu.org
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Vlad Dogaru Jan. 10, 2011, 11:38 a.m. UTC
Add a new type of message, IFLA_FILTERGROUP, which, if present in a
userspace request, specifies that parameters should be changed for all
devices in the group.

Signed-off-by: Vlad Dogaru <ddvlad@rosedu.org>
---
 include/linux/if_link.h |    1 +
 net/core/rtnetlink.c    |   22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)

Comments

jamal Jan. 10, 2011, 1:14 p.m. UTC | #1
Nice - short and sweet.

IMO: I dont think you need this new attribute, IFLA_GROUP
should suffice...
You can use the trick that if a <=0 ifindex is specified,
and no name is passed but a GROUP is passed, then we
operate on the group i.e something like:

        if (ifm->ifi_index > 0)
                dev = __dev_get_by_index(net, ifm->ifi_index);
        else {
                if (tb[IFLA_IFNAME])
                     dev = __dev_get_by_name(net, ifname);
                else if (tb[IFLA_GROUP])
                     new/get/set/del specific stuff..
                else
                   return -EINVAL;
       }


cheers,
jamal

On Mon, 2011-01-10 at 13:38 +0200, Vlad Dogaru wrote:
> Add a new type of message, IFLA_FILTERGROUP, which, if present in a
> userspace request, specifies that parameters should be changed for all
> devices in the group.
> 


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Vlad Dogaru Jan. 11, 2011, 12:13 p.m. UTC | #2
On Mon, Jan 10, 2011 at 08:14:33AM -0500, jamal wrote:
> 
> Nice - short and sweet.
> 
> IMO: I dont think you need this new attribute, IFLA_GROUP
> should suffice...
> You can use the trick that if a <=0 ifindex is specified,
> and no name is passed but a GROUP is passed, then we
> operate on the group i.e something like:
> 
>         if (ifm->ifi_index > 0)
>                 dev = __dev_get_by_index(net, ifm->ifi_index);
>         else {
>                 if (tb[IFLA_IFNAME])
>                      dev = __dev_get_by_name(net, ifname);
>                 else if (tb[IFLA_GROUP])
>                      new/get/set/del specific stuff..
>                 else
>                    return -EINVAL;
>        }

That sounds like a good idea, but, by using the same attribute,
userspace won't be able to change the group of all the interfaces in a
group, i.e. no more
	ip l set group 1 devgroup 0

However, I'm not sure that the use case above would be very common.

Vlad
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
jamal Jan. 11, 2011, 12:40 p.m. UTC | #3
On Tue, 2011-01-11 at 14:13 +0200, Vlad Dogaru wrote:

> 
> That sounds like a good idea, but, by using the same attribute,
> userspace won't be able to change the group of all the interfaces in a
> group, i.e. no more
> 	ip l set group 1 devgroup 0
> 
> However, I'm not sure that the use case above would be very common.

I think for the simple case we have been discussing this goes beyond
that. So maybe to KISS defer this to a later time.

cheers,
jamal

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/linux/if_link.h b/include/linux/if_link.h
index f4a2e6b..1bbacf9 100644
--- a/include/linux/if_link.h
+++ b/include/linux/if_link.h
@@ -136,6 +136,7 @@  enum {
 	IFLA_PORT_SELF,
 	IFLA_AF_SPEC,
 	IFLA_GROUP,		/* Group the device belongs to */
+	IFLA_FILTERGROUP,	/* Set parameters for a specific device group */
 	__IFLA_MAX
 };
 
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 012b0f0..8d7af8c 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -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);
@@ -1587,6 +1605,10 @@  replay:
 		dev = __dev_get_by_index(net, ifm->ifi_index);
 	else if (ifname[0])
 		dev = __dev_get_by_name(net, ifname);
+	else if (tb[IFLA_FILTERGROUP])
+		return rtnl_group_changelink(net,
+				nla_get_u32(tb[IFLA_FILTERGROUP]),
+				ifm, tb);
 	else
 		dev = NULL;