@@ -1248,6 +1248,7 @@ struct net_device {
* of the interface.
*/
char name[IFNAMSIZ];
+ unsigned char name_assign_type; /* name assignment type */
/* device name hash chain, please keep it close to name[] */
struct hlist_node name_hlist;
@@ -36,6 +36,10 @@
/* Initial net device group. All devices belong to group 0 by default. */
#define INIT_NETDEV_GROUP 0
+/* interface name assignment types (sysfs name_assign_type attribute) */
+#define NET_NAME_ENUM 0 /* enumerated by kernel (default) */
+#define NET_NAME_USER 1 /* provided by user-space */
+#define NET_NAME_RENAMED 2 /* renamed by user-space */
/* Media selection options. */
@@ -1083,6 +1083,7 @@ static int dev_get_valid_name(struct net *net,
int dev_change_name(struct net_device *dev, const char *newname)
{
char oldname[IFNAMSIZ];
+ unsigned char old_assign_type;
int err = 0;
int ret;
struct net *net;
@@ -1109,10 +1110,14 @@ int dev_change_name(struct net_device *dev, const char *newname)
return err;
}
+ old_assign_type = dev->name_assign_type;
+ dev->name_assign_type = NET_NAME_RENAMED;
+
rollback:
ret = device_rename(&dev->dev, dev->name);
if (ret) {
memcpy(dev->name, oldname, IFNAMSIZ);
+ dev->name_assign_type = old_assign_type;
write_seqcount_end(&devnet_rename_seq);
return ret;
}
@@ -1141,6 +1146,8 @@ rollback:
write_seqcount_begin(&devnet_rename_seq);
memcpy(dev->name, oldname, IFNAMSIZ);
memcpy(oldname, newname, IFNAMSIZ);
+ dev->name_assign_type = old_assign_type;
+ old_assign_type = NET_NAME_RENAMED;
goto rollback;
} else {
pr_err("%s: name change rollback failed: %d\n",
@@ -105,6 +105,7 @@ static ssize_t netdev_store(struct device *dev, struct device_attribute *attr,
NETDEVICE_SHOW_RO(dev_id, fmt_hex);
NETDEVICE_SHOW_RO(dev_port, fmt_dec);
+NETDEVICE_SHOW_RO(name_assign_type, fmt_dec);
NETDEVICE_SHOW_RO(addr_assign_type, fmt_dec);
NETDEVICE_SHOW_RO(addr_len, fmt_dec);
NETDEVICE_SHOW_RO(iflink, fmt_dec);
@@ -377,6 +378,7 @@ static struct attribute *net_class_attrs[] = {
&dev_attr_dev_port.attr,
&dev_attr_iflink.attr,
&dev_attr_ifindex.attr,
+ &dev_attr_name_assign_type.attr,
&dev_attr_addr_assign_type.attr,
&dev_attr_addr_len.attr,
&dev_attr_link_mode.attr,
@@ -1967,6 +1967,8 @@ replay:
}
dev->ifindex = ifm->ifi_index;
+ if (tb[IFLA_IFNAME])
+ dev->name_assign_type = NET_NAME_USER;
if (ops->newlink) {
err = ops->newlink(net, dev, tb, data);