static ssize_t store_mesh_iface(struct kobject *kobj, struct attribute *attr, char *buff, size_t count) { struct net_device *net_dev = kobj_to_netdev(kobj); struct hard_iface *hard_iface = hardif_get_by_netdev(net_dev); int status_tmp = -1; int ret = count; if (!hard_iface) return count; if (buff[count - 1] == '\n') buff[count - 1] = '\0'; if (strlen(buff) >= IFNAMSIZ) { pr_err("Invalid parameter for 'mesh_iface' setting received: " "interface name too long '%s'\n", buff); hardif_free_ref(hard_iface); return -EINVAL; } if (strncmp(buff, "none", 4) == 0) status_tmp = IF_NOT_IN_USE; else status_tmp = IF_I_WANT_YOU; if (hard_iface->if_status == status_tmp) goto out; if ((hard_iface->soft_iface) && (strncmp(hard_iface->soft_iface->name, buff, IFNAMSIZ) == 0)) goto out; if (!rtnl_trylock()) { ret = -ERESTARTSYS; goto out; } if (status_tmp == IF_NOT_IN_USE) { hardif_disable_interface(hard_iface); goto unlock; } /* if the interface already is in use */ if (hard_iface->if_status != IF_NOT_IN_USE) hardif_disable_interface(hard_iface); ret = hardif_enable_interface(hard_iface, buff); unlock: rtnl_unlock(); out: hardif_free_ref(hard_iface); return ret; }
static ssize_t store_mesh_iface(struct kobject *kobj, struct attribute *attr, char *buff, size_t count) { struct device *dev = to_dev(kobj->parent); struct net_device *net_dev = to_net_dev(dev); struct batman_if *batman_if = get_batman_if_by_netdev(net_dev); int status_tmp = -1; if (!batman_if) return count; if (strncmp(buff, "none", 4) == 0) status_tmp = IF_NOT_IN_USE; if (strncmp(buff, "bat0", 4) == 0) status_tmp = IF_I_WANT_YOU; if (status_tmp < 0) { if (buff[count - 1] == '\n') buff[count - 1] = '\0'; pr_err("Invalid parameter for 'mesh_iface' setting received: " "%s\n", buff); return -EINVAL; } if ((batman_if->if_status == status_tmp) || ((status_tmp == IF_I_WANT_YOU) && (batman_if->if_status != IF_NOT_IN_USE))) return count; if (status_tmp == IF_I_WANT_YOU) status_tmp = hardif_enable_interface(batman_if); else hardif_disable_interface(batman_if); return (status_tmp < 0 ? status_tmp : count); }