1
0
Fork 0
mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-01-24 09:13:20 -05:00

net: bridge: add support for raw sysfs port options

This patch adds a new alternative store callback for port sysfs options
which takes a raw value (buf) and can use it directly. It is needed for the
backup port sysfs support since we have to pass the device by its name.

Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Nikolay Aleksandrov 2018-07-23 11:16:58 +03:00 committed by David S. Miller
parent 0a78c3803d
commit a5f3ea54f3

View file

@ -25,6 +25,15 @@ struct brport_attribute {
struct attribute attr; struct attribute attr;
ssize_t (*show)(struct net_bridge_port *, char *); ssize_t (*show)(struct net_bridge_port *, char *);
int (*store)(struct net_bridge_port *, unsigned long); int (*store)(struct net_bridge_port *, unsigned long);
int (*store_raw)(struct net_bridge_port *, char *);
};
#define BRPORT_ATTR_RAW(_name, _mode, _show, _store) \
const struct brport_attribute brport_attr_##_name = { \
.attr = {.name = __stringify(_name), \
.mode = _mode }, \
.show = _show, \
.store_raw = _store, \
}; };
#define BRPORT_ATTR(_name, _mode, _show, _store) \ #define BRPORT_ATTR(_name, _mode, _show, _store) \
@ -269,27 +278,46 @@ static ssize_t brport_store(struct kobject *kobj,
struct brport_attribute *brport_attr = to_brport_attr(attr); struct brport_attribute *brport_attr = to_brport_attr(attr);
struct net_bridge_port *p = kobj_to_brport(kobj); struct net_bridge_port *p = kobj_to_brport(kobj);
ssize_t ret = -EINVAL; ssize_t ret = -EINVAL;
char *endp;
unsigned long val; unsigned long val;
char *endp;
if (!ns_capable(dev_net(p->dev)->user_ns, CAP_NET_ADMIN)) if (!ns_capable(dev_net(p->dev)->user_ns, CAP_NET_ADMIN))
return -EPERM; return -EPERM;
val = simple_strtoul(buf, &endp, 0); if (!rtnl_trylock())
if (endp != buf) { return restart_syscall();
if (!rtnl_trylock())
return restart_syscall(); if (!p->dev || !p->br)
if (p->dev && p->br && brport_attr->store) { goto out_unlock;
spin_lock_bh(&p->br->lock);
ret = brport_attr->store(p, val); if (brport_attr->store_raw) {
spin_unlock_bh(&p->br->lock); char *buf_copy;
if (!ret) {
br_ifinfo_notify(RTM_NEWLINK, NULL, p); buf_copy = kstrndup(buf, count, GFP_KERNEL);
ret = count; if (!buf_copy) {
} ret = -ENOMEM;
goto out_unlock;
} }
rtnl_unlock(); spin_lock_bh(&p->br->lock);
ret = brport_attr->store_raw(p, buf_copy);
spin_unlock_bh(&p->br->lock);
kfree(buf_copy);
} else if (brport_attr->store) {
val = simple_strtoul(buf, &endp, 0);
if (endp == buf)
goto out_unlock;
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, NULL, p);
ret = count;
}
out_unlock:
rtnl_unlock();
return ret; return ret;
} }