network device renaming sysfs fix
Subsystems (2)
PATCH 1/1 network device renaming sysfs fix
(repost, now will hopefully reach the mailing list)
I believe this is a better approach for fixing the sysfs renaming discrepancy. Later I'll also look into fixing the same issue with sysctl.
net/core/dev.c +6 -2
@@ -2347,10 +2347,14 @@return -EEXIST ;memcpy (dev->name, ifr->ifr_newname,IFNAMSIZ ); dev->name[IFNAMSIZ -1 ] =0 ; -strlcpy (dev->class_dev.class_id, dev->name,BUS_ID_SIZE ); + + err =class_device_rename (&dev->class_dev, dev->name); +if (err) +printk (KERN_DEBUG "SIOCSIFNAME: error renaming class_device (%d)\n" , err); +notifier_call_chain (&netdev_chain,NETDEV_CHANGENAME , dev); -return 0 ; +return err;/* * Unknown or private ioctl
Signature · 2 lines
Dan Aloni [email protected]
Quoted 6 lines · On Fri, 15 Aug 2003 14:15:14 +0300 Dan Aloni <[email protected]> wrote:
(repost, now will hopefully reach the mailing list)
I believe this is a better approach for fixing the sysfs renaming discrepancy. Later I'll also look into fixing the same issue with sysctl.
Yes, this is a better fix because it won't break when unregister and free are split into seperate steps (coming soon).
But, do we really need the debug message?
Why return an error if you already committed the change? If you get an error, then don't rename the network device.
The class_dev kobject name is 20 chars and IFNAMSIZ is 16, so the solution needs to truncate if new_name is not null terminated (all 16 chars long).
This seems like the best approach:
net/core/dev.c +10 -6
@@ -2343,14 +2343,18 @@case SIOCSIFNAME :if (dev->flags &IFF_UP )return -EBUSY ; + ifr->ifr_newname[IFNAMSIZ -1 ] ='\0' ;if (__dev_get_by_name (ifr->ifr_newname))return -EEXIST ; -memcpy (dev->name, ifr->ifr_newname,IFNAMSIZ ); - dev->name[IFNAMSIZ -1 ] =0 ; -strlcpy (dev->class_dev.class_id, dev->name,BUS_ID_SIZE ); -notifier_call_chain (&netdev_chain, -NETDEV_CHANGENAME , dev); -return 0 ; + err =class_device_rename (&dev->class_dev, + ifr->ifr_newname); +if (!err) { +strlcpy (dev->name, ifr->ifr_newname,IFNAMSIZ ); + +notifier_call_chain (&netdev_chain, +NETDEV_CHANGENAME , dev); + } +return err;/* * Unknown or private ioctl
Quoted 11 lines · Stephen Hemminger
Yes, this is a better fix because it won't break when unregister and free are split into seperate steps (coming soon).
But, do we really need the debug message?
Why return an error if you already committed the change? If you get an error, then don't rename the network device.The
class_devkobject name is 20 chars and IFNAMSIZ is 16, so the solution needs to truncate ifnew_nameis not null terminated (all 16 chars long).This seems like the best approach:
Agreed.
net/core/dev.c
Quoted 3 lines
diff -Nru
a/net/core/dev.cb/net/core/dev.cnet/core/dev.c +0
-0
[patch]
Signature · 2 lines
Dan Aloni [email protected]
Quoted 4 lines · On Fri, 15 Aug 2003 09:37:24 -0700 Stephen Hemminger <[email protected]>…
The
class_devkobject name is 20 chars and IFNAMSIZ is 16, so the solution needs to truncate ifnew_nameis not null terminated (all 16 chars long).This seems like the best approach:
Patch applied, thanks everyone.
Can't the device name also change via netlink messages? If so, do we handle that case properly?
Quoted 6 lines · David S. Miller
Quoted 3 lines · On Fri, 15 Aug 2003 09:37:24 -0700 Stephen Hemminger <[email protected]>…
The
class_devkobject name is 20 chars and IFNAMSIZ is 16, so the solution needs to truncate ifnew_nameis not null terminated (all 16 chars long).
Quoted 6 lines
Quoted 1 line
This seems like the best approach:
Patch applied, thanks everyone.
Can't the device name also change via netlink messages? If so, do we handle that case properly?
No it can't, AFAIK. You might be confusing between netlink and notifier calls (which allow ipv4 to update the names of aliases when the device name changes).
BTW, it is possible to add notifier handling for fixing device naming discrepancies regarding family-level sysctl registration. I think this is how the sysctl issue should be fixed.
Signature · 2 lines
Dan Aloni [email protected]
Agreed. We had not yet found the class_device_rename. Hopefully, this is no longer in HTML format.
By all means, help not to look like a bozo :-) - a tall order, I realize.
Mark Huth
Quoted 29 lines · Dan Aloni
(repost, now will hopefully reach the mailing list)
I believe this is a better approach for fixing the sysfs renaming discrepancy. Later I'll also look into fixing the same issue with sysctl.
net/core/dev.c +6
-2@@ -2347,10 +2347,14 @@return -EEXIST ;memcpy (dev->name, ifr->ifr_newname,IFNAMSIZ ); dev->name[IFNAMSIZ -1 ] =0 ; -strlcpy (dev->class_dev.class_id, dev->name,BUS_ID_SIZE ); + + err =class_device_rename (&dev->class_dev, dev->name); +if (err) +printk (KERN_DEBUG "SIOCSIFNAME: error renaming class_device (%d)\n" , err); +notifier_call_chain (&netdev_chain,NETDEV_CHANGENAME , dev); -return 0 ; +return err;/* * Unknown or private ioctl