From: Patrick McHardy Date: Wed, 23 May 2007 00:00:01 +0000 (-0700) Subject: [RTNETLINK]: Allow changing of subsets of netdevice flags in rtnl_setlink X-Git-Tag: v2.6.22-rc3~90^2~1 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83b496e928dbd38104bfb107230cc88751b09d89;p=linux-2.6 [RTNETLINK]: Allow changing of subsets of netdevice flags in rtnl_setlink rtnl_setlink doesn't allow to change subsets of the flags, just to override the set entirely by a new one. This means that for simply setting a device up or down userspace first needs to query the current flags, change it and send the changed flags back, which is racy and needlessly complicated. Mask the flags using ifi_change since this is what it is intended for. For backwards compatibility treat ifi_change == 0 as ~0 (even though it seems quite unlikely that anyone has been using this so far). Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 8c971a2efe..1a6c5b9d41 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -689,8 +689,15 @@ static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) } - if (ifm->ifi_flags) - dev_change_flags(dev, ifm->ifi_flags); + if (ifm->ifi_flags || ifm->ifi_change) { + unsigned int flags = ifm->ifi_flags; + + /* bugwards compatibility: ifi_change == 0 is treated as ~0 */ + if (ifm->ifi_change) + flags = (flags & ifm->ifi_change) | + (dev->flags & ~ifm->ifi_change); + dev_change_flags(dev, flags); + } if (tb[IFLA_TXQLEN]) dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);