Skip to content

Commit

Permalink
Driver core: notify userspace of network device renames
Browse files Browse the repository at this point in the history
Provide rename event for when we rename network devices.

Signed-off-by: Jean Tourrilhes <jt@hpl.hp.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Jean Tourrilhes authored and gregkh committed Apr 27, 2007
1 parent 1b0b3b9 commit ca2f37d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/kobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,43 @@ EXPORT_SYMBOL(kobject_set_name);
int kobject_rename(struct kobject * kobj, const char *new_name)
{
int error = 0;
const char *devpath = NULL;
char *devpath_string = NULL;
char *envp[2];

kobj = kobject_get(kobj);
if (!kobj)
return -EINVAL;
if (!kobj->parent)
return -EINVAL;

devpath = kobject_get_path(kobj, GFP_KERNEL);
if (!devpath) {
error = -ENOMEM;
goto out;
}
devpath_string = kmalloc(strlen(devpath) + 15, GFP_KERNEL);
if (!devpath_string) {
error = -ENOMEM;
goto out;
}
sprintf(devpath_string, "DEVPATH_OLD=%s", devpath);
envp[0] = devpath_string;
envp[1] = NULL;
/* Note : if we want to send the new name alone, not the full path,
* we could probably use kobject_name(kobj); */

error = sysfs_rename_dir(kobj, kobj->parent->dentry, new_name);

/* This function is mostly/only used for network interface.
* Some hotplug package track interfaces by their name and
* therefore want to know when the name is changed by the user. */
if (!error)
kobject_uevent_env(kobj, KOBJ_MOVE, envp);

out:
kfree(devpath_string);
kfree(devpath);
kobject_put(kobj);

return error;
Expand Down
11 changes: 11 additions & 0 deletions net/core/net-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,17 @@ static int netdev_uevent(struct device *d, char **envp,
buf += n;
size -= n;

if ((size <= 0) || (i >= num_envp))
return -ENOMEM;

/* pass ifindex to uevent.
* ifindex is useful as it won't change (interface name may change)
* and is what RtNetlink uses natively. */
envp[i++] = buf;
n = snprintf(buf, size, "IFINDEX=%d", dev->ifindex) + 1;
buf += n;
size -= n;

if ((size <= 0) || (i >= num_envp))
return -ENOMEM;

Expand Down

0 comments on commit ca2f37d

Please sign in to comment.