Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
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;
}