Message ID | 1394990490-1076-2-git-send-email-dh.herrmann@gmail.com |
---|---|
State | Changes Requested, archived |
Delegated to: | David Miller |
Headers | show |
On Sun, 2014-03-16 at 18:21 +0100, David Herrmann wrote: [...] > --- a/include/linux/netdevice.h > +++ b/include/linux/netdevice.h > @@ -74,6 +74,11 @@ void netdev_set_default_ethtool_ops(struct net_device *dev, > #define NET_RX_SUCCESS 0 /* keep 'em coming, baby */ > #define NET_RX_DROP 1 /* packet dropped */ > > +/* interface name assignment types */ > +#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 */ [...] I think these definitions should be put in a UAPI header. Even if the names don't end up being used by userland, that would make it clear that the numbers are a stable ABI. Ben.
Hi On Sun, Mar 16, 2014 at 8:17 PM, Ben Hutchings <ben@decadent.org.uk> wrote: > On Sun, 2014-03-16 at 18:21 +0100, David Herrmann wrote: > [...] >> --- a/include/linux/netdevice.h >> +++ b/include/linux/netdevice.h >> @@ -74,6 +74,11 @@ void netdev_set_default_ethtool_ops(struct net_device *dev, >> #define NET_RX_SUCCESS 0 /* keep 'em coming, baby */ >> #define NET_RX_DROP 1 /* packet dropped */ >> >> +/* interface name assignment types */ >> +#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 */ > [...] > > I think these definitions should be put in a UAPI header. Even if the > names don't end up being used by userland, that would make it clear that > the numbers are a stable ABI. I tried to follow addr_assign_type as closely as possible. The NET_ADDR_* constants are only defined internally either. I am fine with exporting the constants, just want to make sure there's no reason to hide them that I'm not aware of. Thanks David -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index b8d8c80..d3040c5 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -74,6 +74,11 @@ void netdev_set_default_ethtool_ops(struct net_device *dev, #define NET_RX_SUCCESS 0 /* keep 'em coming, baby */ #define NET_RX_DROP 1 /* packet dropped */ +/* interface name assignment types */ +#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 */ + /* * Transmit return codes: transmit return codes originate from three different * namespaces: @@ -1248,6 +1253,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; diff --git a/net/core/dev.c b/net/core/dev.c index 587f9fb..4a2b360 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -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", diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index daed9a6..886403e 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -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, diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index fc122fd..f1bd0fe 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -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);