static int dn_def_dev_strategy(ctl_table *table, int *name, int nlen, void *oldval, size_t *oldlenp, void *newval, size_t newlen, void **context) { size_t len; struct net_device *dev; char devname[17]; size_t namel; int rv = 0; devname[0] = 0; if (oldval && oldlenp) { if (get_user(len, oldlenp)) return -EFAULT; if (len) { dev = dn_dev_get_default(); if (dev) { strcpy(devname, dev->name); dev_put(dev); } namel = strlen(devname) + 1; if (len > namel) len = namel; if (copy_to_user(oldval, devname, len)) return -EFAULT; if (put_user(len, oldlenp)) return -EFAULT; } } if (newval && newlen) { if (newlen > 16) return -E2BIG; if (copy_from_user(devname, newval, newlen)) return -EFAULT; devname[newlen] = 0; dev = dev_get_by_name(devname); if (dev == NULL) return -ENODEV; rv = -ENODEV; if (dev->dn_ptr != NULL) { rv = dn_dev_set_default(dev, 1); if (rv) dev_put(dev); } } return rv; }
static int dn_def_dev_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { size_t len; struct net_device *dev; char devname[17]; if (!*lenp || (*ppos && !write)) { *lenp = 0; return 0; } if (write) { if (*lenp > 16) return -E2BIG; if (copy_from_user(devname, buffer, *lenp)) return -EFAULT; devname[*lenp] = 0; strip_it(devname); dev = dev_get_by_name(&init_net, devname); if (dev == NULL) return -ENODEV; if (dev->dn_ptr == NULL) { dev_put(dev); return -ENODEV; } if (dn_dev_set_default(dev, 1)) { dev_put(dev); return -ENODEV; } *ppos += *lenp; return 0; } dev = dn_dev_get_default(); if (dev == NULL) { *lenp = 0; return 0; } strcpy(devname, dev->name); dev_put(dev); len = strlen(devname); devname[len++] = '\n'; if (len > *lenp) len = *lenp; if (copy_to_user(buffer, devname, len)) return -EFAULT; *lenp = len; *ppos += len; return 0; }