Skip to content

Commit cbda10f

Browse files
ddvladdavem330
authored andcommitted
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 <[email protected]> Acked-by: Jamal Hadi Salim <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 441c793 commit cbda10f

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

include/linux/if_link.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ enum {
135135
IFLA_VF_PORTS,
136136
IFLA_PORT_SELF,
137137
IFLA_AF_SPEC,
138+
IFLA_GROUP, /* Group the device belongs to */
138139
__IFLA_MAX
139140
};
140141

include/linux/netdevice.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ struct wireless_dev;
7575
#define NET_RX_SUCCESS 0 /* keep 'em coming, baby */
7676
#define NET_RX_DROP 1 /* packet dropped */
7777

78+
/* Initial net device group. All devices belong to group 0 by default. */
79+
#define INIT_NETDEV_GROUP 0
80+
7881
/*
7982
* Transmit return codes: transmit return codes originate from three different
8083
* namespaces:
@@ -1153,6 +1156,9 @@ struct net_device {
11531156

11541157
/* phy device may attach itself for hardware timestamping */
11551158
struct phy_device *phydev;
1159+
1160+
/* group the device belongs to */
1161+
int group;
11561162
};
11571163
#define to_net_dev(d) container_of(d, struct net_device, dev)
11581164

@@ -1844,6 +1850,7 @@ extern int dev_set_alias(struct net_device *, const char *, size_t);
18441850
extern int dev_change_net_namespace(struct net_device *,
18451851
struct net *, const char *);
18461852
extern int dev_set_mtu(struct net_device *, int);
1853+
extern void dev_set_group(struct net_device *, int);
18471854
extern int dev_set_mac_address(struct net_device *,
18481855
struct sockaddr *);
18491856
extern int dev_hard_start_xmit(struct sk_buff *skb,

net/core/dev.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4571,6 +4571,17 @@ int dev_set_mtu(struct net_device *dev, int new_mtu)
45714571
}
45724572
EXPORT_SYMBOL(dev_set_mtu);
45734573

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+
45744585
/**
45754586
* dev_set_mac_address - Change Media Access Control Address
45764587
* @dev: device
@@ -5678,6 +5689,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
56785689
dev->priv_flags = IFF_XMIT_DST_RELEASE;
56795690
setup(dev);
56805691
strcpy(dev->name, name);
5692+
dev->group = INIT_NETDEV_GROUP;
56815693
return dev;
56825694

56835695
free_pcpu:

net/core/rtnetlink.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
868868
netif_running(dev) ? dev->operstate : IF_OPER_DOWN);
869869
NLA_PUT_U8(skb, IFLA_LINKMODE, dev->link_mode);
870870
NLA_PUT_U32(skb, IFLA_MTU, dev->mtu);
871+
NLA_PUT_U32(skb, IFLA_GROUP, dev->group);
871872

872873
if (dev->ifindex != dev->iflink)
873874
NLA_PUT_U32(skb, IFLA_LINK, dev->iflink);
@@ -1265,6 +1266,11 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
12651266
modified = 1;
12661267
}
12671268

1269+
if (tb[IFLA_GROUP]) {
1270+
dev_set_group(dev, nla_get_u32(tb[IFLA_GROUP]));
1271+
modified = 1;
1272+
}
1273+
12681274
/*
12691275
* Interface selected by interface index but interface
12701276
* name provided implies that a name change has been

0 commit comments

Comments
 (0)