예제 #1
0
static ssize_t brport_store(struct kobject *kobj,
			    struct attribute *attr,
			    const char *buf, size_t count)
{
	struct brport_attribute *brport_attr = to_brport_attr(attr);
	struct net_bridge_port *p = to_brport(kobj);
	ssize_t ret = -EINVAL;
	char *endp;
	unsigned long val;

	if (!ns_capable(dev_net(p->dev)->user_ns, CAP_NET_ADMIN))
		return -EPERM;

	val = simple_strtoul(buf, &endp, 0);
	if (endp != buf) {
		if (!rtnl_trylock())
			return restart_syscall();
		if (p->dev && p->br && brport_attr->store) {
			spin_lock_bh(&p->br->lock);
			ret = brport_attr->store(p, val);
			spin_unlock_bh(&p->br->lock);
			if (!ret) {
				br_ifinfo_notify(RTM_NEWLINK, p);
				ret = count;
			}
		}
		rtnl_unlock();
	}
	return ret;
}
예제 #2
0
static ssize_t brport_show(struct kobject *kobj,
                           struct attribute *attr, char *buf) {
  struct brport_attribute *brport_attr = to_brport_attr(attr);
  struct net_bridge_port *p = to_brport(kobj);

  return brport_attr->show(p, buf);
}