static ssize_t show_iface_status(struct kobject *kobj, struct attribute *attr, char *buff) { struct net_device *net_dev = kobj_to_netdev(kobj); struct hard_iface *hard_iface = hardif_get_by_netdev(net_dev); ssize_t length; if (!hard_iface) return 0; switch (hard_iface->if_status) { case IF_TO_BE_REMOVED: length = sprintf(buff, "disabling\n"); break; case IF_INACTIVE: length = sprintf(buff, "inactive\n"); break; case IF_ACTIVE: length = sprintf(buff, "active\n"); break; case IF_TO_BE_ACTIVATED: length = sprintf(buff, "enabling\n"); break; case IF_NOT_IN_USE: default: length = sprintf(buff, "not in use\n"); break; } hardif_free_ref(hard_iface); return length; }
static ssize_t store_gw_bwidth(struct kobject *kobj, struct attribute *attr, char *buff, size_t count) { struct net_device *net_dev = kobj_to_netdev(kobj); if (buff[count - 1] == '\n') buff[count - 1] = '\0'; return gw_bandwidth_set(net_dev, buff, count); }
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_gw_mode(struct kobject *kobj, struct attribute *attr, char *buff, size_t count) { struct net_device *net_dev = kobj_to_netdev(kobj); struct bat_priv *bat_priv = netdev_priv(net_dev); char *curr_gw_mode_str; int gw_mode_tmp = -1; if (buff[count - 1] == '\n') buff[count - 1] = '\0'; if (strncmp(buff, GW_MODE_OFF_NAME, strlen(GW_MODE_OFF_NAME)) == 0) gw_mode_tmp = GW_MODE_OFF; if (strncmp(buff, GW_MODE_CLIENT_NAME, strlen(GW_MODE_CLIENT_NAME)) == 0) gw_mode_tmp = GW_MODE_CLIENT; if (strncmp(buff, GW_MODE_SERVER_NAME, strlen(GW_MODE_SERVER_NAME)) == 0) gw_mode_tmp = GW_MODE_SERVER; if (gw_mode_tmp < 0) { bat_info(net_dev, "Invalid parameter for 'gw mode' setting received: " "%s\n", buff); return -EINVAL; } if (atomic_read(&bat_priv->gw_mode) == gw_mode_tmp) return count; switch (atomic_read(&bat_priv->gw_mode)) { case GW_MODE_CLIENT: curr_gw_mode_str = GW_MODE_CLIENT_NAME; break; case GW_MODE_SERVER: curr_gw_mode_str = GW_MODE_SERVER_NAME; break; default: curr_gw_mode_str = GW_MODE_OFF_NAME; break; } bat_info(net_dev, "Changing gw mode from: %s to: %s\n", curr_gw_mode_str, buff); gw_deselect(bat_priv); atomic_set(&bat_priv->gw_mode, (unsigned)gw_mode_tmp); return count; }
static ssize_t show_mesh_iface(struct kobject *kobj, struct attribute *attr, char *buff) { struct net_device *net_dev = kobj_to_netdev(kobj); struct hard_iface *hard_iface = hardif_get_by_netdev(net_dev); ssize_t length; if (!hard_iface) return 0; length = sprintf(buff, "%s\n", hard_iface->if_status == IF_NOT_IN_USE ? "none" : hard_iface->soft_iface->name); hardif_free_ref(hard_iface); return length; }
static ssize_t store_vis_mode(struct kobject *kobj, struct attribute *attr, char *buff, size_t count) { struct net_device *net_dev = kobj_to_netdev(kobj); struct bat_priv *bat_priv = netdev_priv(net_dev); unsigned long val; int ret, vis_mode_tmp = -1; ret = strict_strtoul(buff, 10, &val); if (((count == 2) && (!ret) && (val == VIS_TYPE_CLIENT_UPDATE)) || (strncmp(buff, "client", 6) == 0) || (strncmp(buff, "off", 3) == 0)) vis_mode_tmp = VIS_TYPE_CLIENT_UPDATE; if (((count == 2) && (!ret) && (val == VIS_TYPE_SERVER_SYNC)) || (strncmp(buff, "server", 6) == 0)) vis_mode_tmp = VIS_TYPE_SERVER_SYNC; if (vis_mode_tmp < 0) { if (buff[count - 1] == '\n') buff[count - 1] = '\0'; bat_info(net_dev, "Invalid parameter for 'vis mode' setting received: " "%s\n", buff); return -EINVAL; } if (atomic_read(&bat_priv->vis_mode) == vis_mode_tmp) return count; bat_info(net_dev, "Changing vis mode from: %s to: %s\n", atomic_read(&bat_priv->vis_mode) == VIS_TYPE_CLIENT_UPDATE ? "client" : "server", vis_mode_tmp == VIS_TYPE_CLIENT_UPDATE ? "client" : "server"); atomic_set(&bat_priv->vis_mode, (unsigned)vis_mode_tmp); return count; }
static struct bat_priv *kobj_to_batpriv(struct kobject *obj) { struct net_device *net_dev = kobj_to_netdev(obj); return netdev_priv(net_dev); }