Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net_device: add support for network device groups

Net devices can now be grouped, enabling simpler manipulation from
userspace. This patch adds a group field to the net_device structure, as
well as rtnetlink support to query and modify it.

Signed-off-by: Vlad Dogaru <ddvlad@rosedu.org>
Acked-by: Jamal Hadi Salim <hadi@cyberus.ca>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Vlad Dogaru and committed by
David S. Miller
cbda10fa 441c793a

+26
+1
include/linux/if_link.h
··· 135 135 IFLA_VF_PORTS, 136 136 IFLA_PORT_SELF, 137 137 IFLA_AF_SPEC, 138 + IFLA_GROUP, /* Group the device belongs to */ 138 139 __IFLA_MAX 139 140 }; 140 141
+7
include/linux/netdevice.h
··· 75 75 #define NET_RX_SUCCESS 0 /* keep 'em coming, baby */ 76 76 #define NET_RX_DROP 1 /* packet dropped */ 77 77 78 + /* Initial net device group. All devices belong to group 0 by default. */ 79 + #define INIT_NETDEV_GROUP 0 80 + 78 81 /* 79 82 * Transmit return codes: transmit return codes originate from three different 80 83 * namespaces: ··· 1156 1153 1157 1154 /* phy device may attach itself for hardware timestamping */ 1158 1155 struct phy_device *phydev; 1156 + 1157 + /* group the device belongs to */ 1158 + int group; 1159 1159 }; 1160 1160 #define to_net_dev(d) container_of(d, struct net_device, dev) 1161 1161 ··· 1850 1844 extern int dev_change_net_namespace(struct net_device *, 1851 1845 struct net *, const char *); 1852 1846 extern int dev_set_mtu(struct net_device *, int); 1847 + extern void dev_set_group(struct net_device *, int); 1853 1848 extern int dev_set_mac_address(struct net_device *, 1854 1849 struct sockaddr *); 1855 1850 extern int dev_hard_start_xmit(struct sk_buff *skb,
+12
net/core/dev.c
··· 4572 4572 EXPORT_SYMBOL(dev_set_mtu); 4573 4573 4574 4574 /** 4575 + * dev_set_group - Change group this device belongs to 4576 + * @dev: device 4577 + * @new_group: group this device should belong to 4578 + */ 4579 + void dev_set_group(struct net_device *dev, int new_group) 4580 + { 4581 + dev->group = new_group; 4582 + } 4583 + EXPORT_SYMBOL(dev_set_group); 4584 + 4585 + /** 4575 4586 * dev_set_mac_address - Change Media Access Control Address 4576 4587 * @dev: device 4577 4588 * @sa: new address ··· 5689 5678 dev->priv_flags = IFF_XMIT_DST_RELEASE; 5690 5679 setup(dev); 5691 5680 strcpy(dev->name, name); 5681 + dev->group = INIT_NETDEV_GROUP; 5692 5682 return dev; 5693 5683 5694 5684 free_pcpu:
+6
net/core/rtnetlink.c
··· 868 868 netif_running(dev) ? dev->operstate : IF_OPER_DOWN); 869 869 NLA_PUT_U8(skb, IFLA_LINKMODE, dev->link_mode); 870 870 NLA_PUT_U32(skb, IFLA_MTU, dev->mtu); 871 + NLA_PUT_U32(skb, IFLA_GROUP, dev->group); 871 872 872 873 if (dev->ifindex != dev->iflink) 873 874 NLA_PUT_U32(skb, IFLA_LINK, dev->iflink); ··· 1263 1262 err = dev_set_mtu(dev, nla_get_u32(tb[IFLA_MTU])); 1264 1263 if (err < 0) 1265 1264 goto errout; 1265 + modified = 1; 1266 + } 1267 + 1268 + if (tb[IFLA_GROUP]) { 1269 + dev_set_group(dev, nla_get_u32(tb[IFLA_GROUP])); 1266 1270 modified = 1; 1267 1271 } 1268 1272