aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWANG Cong <xiyou.wangcong@gmail.com>2015-03-24 14:53:31 -0400
committerDavid S. Miller <davem@davemloft.net>2015-03-24 15:00:01 -0400
commit66400d543072d6ff6f8df036e3f12f5c154c19cc (patch)
tree064dfdb1dcab5dc651bbaba6fc06978c86bc8c63
parent27ed44a5d6d88897002b75f53004d4c565a5aab6 (diff)
net: allow to delete a whole device group
With dev group, we can change a batch of net devices, so we should allow to delete them together too. Group 0 is not allowed to be deleted since it is the default group. Cc: Stephen Hemminger <stephen@networkplumber.org> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/core/rtnetlink.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index e7695104dbf0..b96ac2109c82 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1836,6 +1836,42 @@ errout:
1836 return err; 1836 return err;
1837} 1837}
1838 1838
1839static int rtnl_group_dellink(const struct net *net, int group)
1840{
1841 struct net_device *dev, *aux;
1842 LIST_HEAD(list_kill);
1843 bool found = false;
1844
1845 if (!group)
1846 return -EPERM;
1847
1848 for_each_netdev(net, dev) {
1849 if (dev->group == group) {
1850 const struct rtnl_link_ops *ops;
1851
1852 found = true;
1853 ops = dev->rtnl_link_ops;
1854 if (!ops || !ops->dellink)
1855 return -EOPNOTSUPP;
1856 }
1857 }
1858
1859 if (!found)
1860 return -ENODEV;
1861
1862 for_each_netdev_safe(net, dev, aux) {
1863 if (dev->group == group) {
1864 const struct rtnl_link_ops *ops;
1865
1866 ops = dev->rtnl_link_ops;
1867 ops->dellink(dev, &list_kill);
1868 }
1869 }
1870 unregister_netdevice_many(&list_kill);
1871
1872 return 0;
1873}
1874
1839static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh) 1875static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh)
1840{ 1876{
1841 struct net *net = sock_net(skb->sk); 1877 struct net *net = sock_net(skb->sk);
@@ -1859,6 +1895,8 @@ static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh)
1859 dev = __dev_get_by_index(net, ifm->ifi_index); 1895 dev = __dev_get_by_index(net, ifm->ifi_index);
1860 else if (tb[IFLA_IFNAME]) 1896 else if (tb[IFLA_IFNAME])
1861 dev = __dev_get_by_name(net, ifname); 1897 dev = __dev_get_by_name(net, ifname);
1898 else if (tb[IFLA_GROUP])
1899 return rtnl_group_dellink(net, nla_get_u32(tb[IFLA_GROUP]));
1862 else 1900 else
1863 return -EINVAL; 1901 return -EINVAL;
1864 1902