net: set name assign type for renamed devices
authorTom Gundersen <teg@jklm.no>
Mon, 14 Jul 2014 14:37:23 +0000 (16:37 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 15 Jul 2014 23:12:01 +0000 (16:12 -0700)
Based on a patch from David Herrmann.

This is the only place devices can be renamed.

v9: restore revers-christmas-tree order of local variables

Signed-off-by: Tom Gundersen <teg@jklm.no>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/dev.c

index 6e2a2cd8232199b2ff15502cdcb4f761f3c52136..38793fb84a354c7ffdc5a360ed288f5f707731ed 100644 (file)
@@ -1082,6 +1082,7 @@ static int dev_get_valid_name(struct net *net,
  */
 int dev_change_name(struct net_device *dev, const char *newname)
 {
+       unsigned char old_assign_type;
        char oldname[IFNAMSIZ];
        int err = 0;
        int ret;
@@ -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",