11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Sysfs attributes of bridge ports 31da177e4SLinus Torvalds * Linux ethernet bridge 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Authors: 61da177e4SLinus Torvalds * Stephen Hemminger <shemminger@osdl.org> 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or 91da177e4SLinus Torvalds * modify it under the terms of the GNU General Public License 101da177e4SLinus Torvalds * as published by the Free Software Foundation; either version 111da177e4SLinus Torvalds * 2 of the License, or (at your option) any later version. 121da177e4SLinus Torvalds */ 131da177e4SLinus Torvalds 144fc268d2SRandy Dunlap #include <linux/capability.h> 151da177e4SLinus Torvalds #include <linux/kernel.h> 161da177e4SLinus Torvalds #include <linux/netdevice.h> 17b3343a2aSJohn Fastabend #include <linux/etherdevice.h> 181da177e4SLinus Torvalds #include <linux/if_bridge.h> 191da177e4SLinus Torvalds #include <linux/rtnetlink.h> 201da177e4SLinus Torvalds #include <linux/spinlock.h> 211da177e4SLinus Torvalds #include <linux/times.h> 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds #include "br_private.h" 241da177e4SLinus Torvalds 2543cb76d9SGreg Kroah-Hartman #define to_dev(obj) container_of(obj, struct device, kobj) 26524ad0a7SWang Chen #define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd))) 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds /* 291da177e4SLinus Torvalds * Common code for storing bridge parameters. 301da177e4SLinus Torvalds */ 3143cb76d9SGreg Kroah-Hartman static ssize_t store_bridge_parm(struct device *d, 321da177e4SLinus Torvalds const char *buf, size_t len, 338d4698f7SStephen Hemminger int (*set)(struct net_bridge *, unsigned long)) 341da177e4SLinus Torvalds { 3543cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 361da177e4SLinus Torvalds char *endp; 371da177e4SLinus Torvalds unsigned long val; 388d4698f7SStephen Hemminger int err; 391da177e4SLinus Torvalds 40cb990503SEric W. Biederman if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) 411da177e4SLinus Torvalds return -EPERM; 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds val = simple_strtoul(buf, &endp, 0); 441da177e4SLinus Torvalds if (endp == buf) 451da177e4SLinus Torvalds return -EINVAL; 461da177e4SLinus Torvalds 478d4698f7SStephen Hemminger err = (*set)(br, val); 488d4698f7SStephen Hemminger return err ? err : len; 491da177e4SLinus Torvalds } 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds 5243cb76d9SGreg Kroah-Hartman static ssize_t show_forward_delay(struct device *d, 5343cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 541da177e4SLinus Torvalds { 5543cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 561da177e4SLinus Torvalds return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay)); 571da177e4SLinus Torvalds } 581da177e4SLinus Torvalds 5943cb76d9SGreg Kroah-Hartman static ssize_t store_forward_delay(struct device *d, 6043cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 6143cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 621da177e4SLinus Torvalds { 6314f98f25Sstephen hemminger return store_bridge_parm(d, buf, len, br_set_forward_delay); 641da177e4SLinus Torvalds } 6543cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(forward_delay, S_IRUGO | S_IWUSR, 661da177e4SLinus Torvalds show_forward_delay, store_forward_delay); 671da177e4SLinus Torvalds 6843cb76d9SGreg Kroah-Hartman static ssize_t show_hello_time(struct device *d, struct device_attribute *attr, 6943cb76d9SGreg Kroah-Hartman char *buf) 701da177e4SLinus Torvalds { 711da177e4SLinus Torvalds return sprintf(buf, "%lu\n", 7243cb76d9SGreg Kroah-Hartman jiffies_to_clock_t(to_bridge(d)->hello_time)); 731da177e4SLinus Torvalds } 741da177e4SLinus Torvalds 7543cb76d9SGreg Kroah-Hartman static ssize_t store_hello_time(struct device *d, 7643cb76d9SGreg Kroah-Hartman struct device_attribute *attr, const char *buf, 771da177e4SLinus Torvalds size_t len) 781da177e4SLinus Torvalds { 7914f98f25Sstephen hemminger return store_bridge_parm(d, buf, len, br_set_hello_time); 801da177e4SLinus Torvalds } 8143cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(hello_time, S_IRUGO | S_IWUSR, show_hello_time, 821da177e4SLinus Torvalds store_hello_time); 831da177e4SLinus Torvalds 8443cb76d9SGreg Kroah-Hartman static ssize_t show_max_age(struct device *d, struct device_attribute *attr, 8543cb76d9SGreg Kroah-Hartman char *buf) 861da177e4SLinus Torvalds { 871da177e4SLinus Torvalds return sprintf(buf, "%lu\n", 8843cb76d9SGreg Kroah-Hartman jiffies_to_clock_t(to_bridge(d)->max_age)); 891da177e4SLinus Torvalds } 901da177e4SLinus Torvalds 9143cb76d9SGreg Kroah-Hartman static ssize_t store_max_age(struct device *d, struct device_attribute *attr, 9243cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 931da177e4SLinus Torvalds { 9414f98f25Sstephen hemminger return store_bridge_parm(d, buf, len, br_set_max_age); 951da177e4SLinus Torvalds } 9643cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(max_age, S_IRUGO | S_IWUSR, show_max_age, store_max_age); 971da177e4SLinus Torvalds 9843cb76d9SGreg Kroah-Hartman static ssize_t show_ageing_time(struct device *d, 9943cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 1001da177e4SLinus Torvalds { 10143cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1021da177e4SLinus Torvalds return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time)); 1031da177e4SLinus Torvalds } 1041da177e4SLinus Torvalds 1058d4698f7SStephen Hemminger static int set_ageing_time(struct net_bridge *br, unsigned long val) 1061da177e4SLinus Torvalds { 1071da177e4SLinus Torvalds br->ageing_time = clock_t_to_jiffies(val); 1088d4698f7SStephen Hemminger return 0; 1091da177e4SLinus Torvalds } 1101da177e4SLinus Torvalds 11143cb76d9SGreg Kroah-Hartman static ssize_t store_ageing_time(struct device *d, 11243cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 11343cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 1141da177e4SLinus Torvalds { 11543cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_ageing_time); 1161da177e4SLinus Torvalds } 11743cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(ageing_time, S_IRUGO | S_IWUSR, show_ageing_time, 1181da177e4SLinus Torvalds store_ageing_time); 11943cb76d9SGreg Kroah-Hartman 12043cb76d9SGreg Kroah-Hartman static ssize_t show_stp_state(struct device *d, 12143cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 1221da177e4SLinus Torvalds { 12343cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1241da177e4SLinus Torvalds return sprintf(buf, "%d\n", br->stp_enabled); 1251da177e4SLinus Torvalds } 1261da177e4SLinus Torvalds 1271da177e4SLinus Torvalds 12843cb76d9SGreg Kroah-Hartman static ssize_t store_stp_state(struct device *d, 12943cb76d9SGreg Kroah-Hartman struct device_attribute *attr, const char *buf, 13043cb76d9SGreg Kroah-Hartman size_t len) 1311da177e4SLinus Torvalds { 13217120889SStephen Hemminger struct net_bridge *br = to_bridge(d); 13317120889SStephen Hemminger char *endp; 13417120889SStephen Hemminger unsigned long val; 13517120889SStephen Hemminger 136cb990503SEric W. Biederman if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) 13717120889SStephen Hemminger return -EPERM; 13817120889SStephen Hemminger 13917120889SStephen Hemminger val = simple_strtoul(buf, &endp, 0); 14017120889SStephen Hemminger if (endp == buf) 14117120889SStephen Hemminger return -EINVAL; 14217120889SStephen Hemminger 143af38f298SEric W. Biederman if (!rtnl_trylock()) 144af38f298SEric W. Biederman return restart_syscall(); 14517120889SStephen Hemminger br_stp_set_enabled(br, val); 14617120889SStephen Hemminger rtnl_unlock(); 14717120889SStephen Hemminger 14835b426c3SAl Viro return len; 1491da177e4SLinus Torvalds } 15043cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(stp_state, S_IRUGO | S_IWUSR, show_stp_state, 1511da177e4SLinus Torvalds store_stp_state); 1521da177e4SLinus Torvalds 153515853ccSstephen hemminger static ssize_t show_group_fwd_mask(struct device *d, 154515853ccSstephen hemminger struct device_attribute *attr, char *buf) 155515853ccSstephen hemminger { 156515853ccSstephen hemminger struct net_bridge *br = to_bridge(d); 157515853ccSstephen hemminger return sprintf(buf, "%#x\n", br->group_fwd_mask); 158515853ccSstephen hemminger } 159515853ccSstephen hemminger 160515853ccSstephen hemminger 161515853ccSstephen hemminger static ssize_t store_group_fwd_mask(struct device *d, 162515853ccSstephen hemminger struct device_attribute *attr, const char *buf, 163515853ccSstephen hemminger size_t len) 164515853ccSstephen hemminger { 165515853ccSstephen hemminger struct net_bridge *br = to_bridge(d); 166515853ccSstephen hemminger char *endp; 167515853ccSstephen hemminger unsigned long val; 168515853ccSstephen hemminger 169cb990503SEric W. Biederman if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) 170515853ccSstephen hemminger return -EPERM; 171515853ccSstephen hemminger 172515853ccSstephen hemminger val = simple_strtoul(buf, &endp, 0); 173515853ccSstephen hemminger if (endp == buf) 174515853ccSstephen hemminger return -EINVAL; 175515853ccSstephen hemminger 176515853ccSstephen hemminger if (val & BR_GROUPFWD_RESTRICTED) 177515853ccSstephen hemminger return -EINVAL; 178515853ccSstephen hemminger 179515853ccSstephen hemminger br->group_fwd_mask = val; 180515853ccSstephen hemminger 181515853ccSstephen hemminger return len; 182515853ccSstephen hemminger } 183515853ccSstephen hemminger static DEVICE_ATTR(group_fwd_mask, S_IRUGO | S_IWUSR, show_group_fwd_mask, 184515853ccSstephen hemminger store_group_fwd_mask); 185515853ccSstephen hemminger 18643cb76d9SGreg Kroah-Hartman static ssize_t show_priority(struct device *d, struct device_attribute *attr, 18743cb76d9SGreg Kroah-Hartman char *buf) 1881da177e4SLinus Torvalds { 18943cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1901da177e4SLinus Torvalds return sprintf(buf, "%d\n", 1911da177e4SLinus Torvalds (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]); 1921da177e4SLinus Torvalds } 1931da177e4SLinus Torvalds 1948d4698f7SStephen Hemminger static int set_priority(struct net_bridge *br, unsigned long val) 1951da177e4SLinus Torvalds { 1961da177e4SLinus Torvalds br_stp_set_bridge_priority(br, (u16) val); 1978d4698f7SStephen Hemminger return 0; 1981da177e4SLinus Torvalds } 1991da177e4SLinus Torvalds 20043cb76d9SGreg Kroah-Hartman static ssize_t store_priority(struct device *d, struct device_attribute *attr, 2011da177e4SLinus Torvalds const char *buf, size_t len) 2021da177e4SLinus Torvalds { 20343cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_priority); 2041da177e4SLinus Torvalds } 20543cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(priority, S_IRUGO | S_IWUSR, show_priority, store_priority); 2061da177e4SLinus Torvalds 20743cb76d9SGreg Kroah-Hartman static ssize_t show_root_id(struct device *d, struct device_attribute *attr, 20843cb76d9SGreg Kroah-Hartman char *buf) 2091da177e4SLinus Torvalds { 21043cb76d9SGreg Kroah-Hartman return br_show_bridge_id(buf, &to_bridge(d)->designated_root); 2111da177e4SLinus Torvalds } 21243cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_id, S_IRUGO, show_root_id, NULL); 2131da177e4SLinus Torvalds 21443cb76d9SGreg Kroah-Hartman static ssize_t show_bridge_id(struct device *d, struct device_attribute *attr, 21543cb76d9SGreg Kroah-Hartman char *buf) 2161da177e4SLinus Torvalds { 21743cb76d9SGreg Kroah-Hartman return br_show_bridge_id(buf, &to_bridge(d)->bridge_id); 2181da177e4SLinus Torvalds } 21943cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(bridge_id, S_IRUGO, show_bridge_id, NULL); 2201da177e4SLinus Torvalds 22143cb76d9SGreg Kroah-Hartman static ssize_t show_root_port(struct device *d, struct device_attribute *attr, 22243cb76d9SGreg Kroah-Hartman char *buf) 2231da177e4SLinus Torvalds { 22443cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->root_port); 2251da177e4SLinus Torvalds } 22643cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_port, S_IRUGO, show_root_port, NULL); 2271da177e4SLinus Torvalds 22843cb76d9SGreg Kroah-Hartman static ssize_t show_root_path_cost(struct device *d, 22943cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2301da177e4SLinus Torvalds { 23143cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost); 2321da177e4SLinus Torvalds } 23343cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_path_cost, S_IRUGO, show_root_path_cost, NULL); 2341da177e4SLinus Torvalds 23543cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change(struct device *d, 23643cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2371da177e4SLinus Torvalds { 23843cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->topology_change); 2391da177e4SLinus Torvalds } 24043cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change, S_IRUGO, show_topology_change, NULL); 2411da177e4SLinus Torvalds 24243cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change_detected(struct device *d, 24343cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 24443cb76d9SGreg Kroah-Hartman char *buf) 2451da177e4SLinus Torvalds { 24643cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2471da177e4SLinus Torvalds return sprintf(buf, "%d\n", br->topology_change_detected); 2481da177e4SLinus Torvalds } 24943cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change_detected, S_IRUGO, 25043cb76d9SGreg Kroah-Hartman show_topology_change_detected, NULL); 2511da177e4SLinus Torvalds 25243cb76d9SGreg Kroah-Hartman static ssize_t show_hello_timer(struct device *d, 25343cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2541da177e4SLinus Torvalds { 25543cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2561da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer)); 2571da177e4SLinus Torvalds } 25843cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(hello_timer, S_IRUGO, show_hello_timer, NULL); 2591da177e4SLinus Torvalds 26043cb76d9SGreg Kroah-Hartman static ssize_t show_tcn_timer(struct device *d, struct device_attribute *attr, 26143cb76d9SGreg Kroah-Hartman char *buf) 2621da177e4SLinus Torvalds { 26343cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2641da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer)); 2651da177e4SLinus Torvalds } 26643cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(tcn_timer, S_IRUGO, show_tcn_timer, NULL); 2671da177e4SLinus Torvalds 26843cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change_timer(struct device *d, 26943cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 27043cb76d9SGreg Kroah-Hartman char *buf) 2711da177e4SLinus Torvalds { 27243cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2731da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer)); 2741da177e4SLinus Torvalds } 27543cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change_timer, S_IRUGO, show_topology_change_timer, 27643cb76d9SGreg Kroah-Hartman NULL); 2771da177e4SLinus Torvalds 27843cb76d9SGreg Kroah-Hartman static ssize_t show_gc_timer(struct device *d, struct device_attribute *attr, 27943cb76d9SGreg Kroah-Hartman char *buf) 2801da177e4SLinus Torvalds { 28143cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2821da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer)); 2831da177e4SLinus Torvalds } 28443cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(gc_timer, S_IRUGO, show_gc_timer, NULL); 2851da177e4SLinus Torvalds 28643cb76d9SGreg Kroah-Hartman static ssize_t show_group_addr(struct device *d, 28743cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 288fda93d92SStephen Hemminger { 28943cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 290fda93d92SStephen Hemminger return sprintf(buf, "%x:%x:%x:%x:%x:%x\n", 291fda93d92SStephen Hemminger br->group_addr[0], br->group_addr[1], 292fda93d92SStephen Hemminger br->group_addr[2], br->group_addr[3], 293fda93d92SStephen Hemminger br->group_addr[4], br->group_addr[5]); 294fda93d92SStephen Hemminger } 295fda93d92SStephen Hemminger 29643cb76d9SGreg Kroah-Hartman static ssize_t store_group_addr(struct device *d, 29743cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 29843cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 299fda93d92SStephen Hemminger { 30043cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 3014197f24bSBen Hutchings u8 new_addr[6]; 302fda93d92SStephen Hemminger int i; 303fda93d92SStephen Hemminger 304cb990503SEric W. Biederman if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) 305fda93d92SStephen Hemminger return -EPERM; 306fda93d92SStephen Hemminger 3074197f24bSBen Hutchings if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", 308fda93d92SStephen Hemminger &new_addr[0], &new_addr[1], &new_addr[2], 309fda93d92SStephen Hemminger &new_addr[3], &new_addr[4], &new_addr[5]) != 6) 310fda93d92SStephen Hemminger return -EINVAL; 311fda93d92SStephen Hemminger 31246acc460SBen Hutchings if (!is_link_local_ether_addr(new_addr)) 313fda93d92SStephen Hemminger return -EINVAL; 314fda93d92SStephen Hemminger 315f64f9e71SJoe Perches if (new_addr[5] == 1 || /* 802.3x Pause address */ 316f64f9e71SJoe Perches new_addr[5] == 2 || /* 802.3ad Slow protocols */ 317f64f9e71SJoe Perches new_addr[5] == 3) /* 802.1X PAE address */ 318fda93d92SStephen Hemminger return -EINVAL; 319fda93d92SStephen Hemminger 320fda93d92SStephen Hemminger spin_lock_bh(&br->lock); 321fda93d92SStephen Hemminger for (i = 0; i < 6; i++) 322fda93d92SStephen Hemminger br->group_addr[i] = new_addr[i]; 323fda93d92SStephen Hemminger spin_unlock_bh(&br->lock); 324fda93d92SStephen Hemminger return len; 325fda93d92SStephen Hemminger } 326fda93d92SStephen Hemminger 32743cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(group_addr, S_IRUGO | S_IWUSR, 328fda93d92SStephen Hemminger show_group_addr, store_group_addr); 329fda93d92SStephen Hemminger 3309cf63747SStephen Hemminger static ssize_t store_flush(struct device *d, 3319cf63747SStephen Hemminger struct device_attribute *attr, 3329cf63747SStephen Hemminger const char *buf, size_t len) 3339cf63747SStephen Hemminger { 3349cf63747SStephen Hemminger struct net_bridge *br = to_bridge(d); 3359cf63747SStephen Hemminger 336cb990503SEric W. Biederman if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) 3379cf63747SStephen Hemminger return -EPERM; 3389cf63747SStephen Hemminger 3399cf63747SStephen Hemminger br_fdb_flush(br); 3409cf63747SStephen Hemminger return len; 3419cf63747SStephen Hemminger } 3429cf63747SStephen Hemminger static DEVICE_ATTR(flush, S_IWUSR, NULL, store_flush); 343fda93d92SStephen Hemminger 3440909e117SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 3450909e117SHerbert Xu static ssize_t show_multicast_router(struct device *d, 3460909e117SHerbert Xu struct device_attribute *attr, char *buf) 3470909e117SHerbert Xu { 3480909e117SHerbert Xu struct net_bridge *br = to_bridge(d); 3490909e117SHerbert Xu return sprintf(buf, "%d\n", br->multicast_router); 3500909e117SHerbert Xu } 3510909e117SHerbert Xu 3520909e117SHerbert Xu static ssize_t store_multicast_router(struct device *d, 3530909e117SHerbert Xu struct device_attribute *attr, 3540909e117SHerbert Xu const char *buf, size_t len) 3550909e117SHerbert Xu { 3560909e117SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_router); 3570909e117SHerbert Xu } 3580909e117SHerbert Xu static DEVICE_ATTR(multicast_router, S_IRUGO | S_IWUSR, show_multicast_router, 3590909e117SHerbert Xu store_multicast_router); 360561f1103SHerbert Xu 361561f1103SHerbert Xu static ssize_t show_multicast_snooping(struct device *d, 362561f1103SHerbert Xu struct device_attribute *attr, 363561f1103SHerbert Xu char *buf) 364561f1103SHerbert Xu { 365561f1103SHerbert Xu struct net_bridge *br = to_bridge(d); 366561f1103SHerbert Xu return sprintf(buf, "%d\n", !br->multicast_disabled); 367561f1103SHerbert Xu } 368561f1103SHerbert Xu 369561f1103SHerbert Xu static ssize_t store_multicast_snooping(struct device *d, 370561f1103SHerbert Xu struct device_attribute *attr, 371561f1103SHerbert Xu const char *buf, size_t len) 372561f1103SHerbert Xu { 373561f1103SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_toggle); 374561f1103SHerbert Xu } 375561f1103SHerbert Xu static DEVICE_ATTR(multicast_snooping, S_IRUGO | S_IWUSR, 376561f1103SHerbert Xu show_multicast_snooping, store_multicast_snooping); 377b195167fSHerbert Xu 378*1c8ad5bfSCong Wang static ssize_t show_multicast_query_use_ifaddr(struct device *d, 379*1c8ad5bfSCong Wang struct device_attribute *attr, 380*1c8ad5bfSCong Wang char *buf) 381*1c8ad5bfSCong Wang { 382*1c8ad5bfSCong Wang struct net_bridge *br = to_bridge(d); 383*1c8ad5bfSCong Wang return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr); 384*1c8ad5bfSCong Wang } 385*1c8ad5bfSCong Wang 386*1c8ad5bfSCong Wang static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val) 387*1c8ad5bfSCong Wang { 388*1c8ad5bfSCong Wang br->multicast_query_use_ifaddr = !!val; 389*1c8ad5bfSCong Wang return 0; 390*1c8ad5bfSCong Wang } 391*1c8ad5bfSCong Wang 392*1c8ad5bfSCong Wang static ssize_t 393*1c8ad5bfSCong Wang store_multicast_query_use_ifaddr(struct device *d, 394*1c8ad5bfSCong Wang struct device_attribute *attr, 395*1c8ad5bfSCong Wang const char *buf, size_t len) 396*1c8ad5bfSCong Wang { 397*1c8ad5bfSCong Wang return store_bridge_parm(d, buf, len, set_query_use_ifaddr); 398*1c8ad5bfSCong Wang } 399*1c8ad5bfSCong Wang static DEVICE_ATTR(multicast_query_use_ifaddr, S_IRUGO | S_IWUSR, 400*1c8ad5bfSCong Wang show_multicast_query_use_ifaddr, 401*1c8ad5bfSCong Wang store_multicast_query_use_ifaddr); 402*1c8ad5bfSCong Wang 403c5c23260SHerbert Xu static ssize_t show_multicast_querier(struct device *d, 404c5c23260SHerbert Xu struct device_attribute *attr, 405c5c23260SHerbert Xu char *buf) 406c5c23260SHerbert Xu { 407c5c23260SHerbert Xu struct net_bridge *br = to_bridge(d); 408c5c23260SHerbert Xu return sprintf(buf, "%d\n", br->multicast_querier); 409c5c23260SHerbert Xu } 410c5c23260SHerbert Xu 411c5c23260SHerbert Xu static ssize_t store_multicast_querier(struct device *d, 412c5c23260SHerbert Xu struct device_attribute *attr, 413c5c23260SHerbert Xu const char *buf, size_t len) 414c5c23260SHerbert Xu { 415c5c23260SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_querier); 416c5c23260SHerbert Xu } 417c5c23260SHerbert Xu static DEVICE_ATTR(multicast_querier, S_IRUGO | S_IWUSR, 418c5c23260SHerbert Xu show_multicast_querier, store_multicast_querier); 419c5c23260SHerbert Xu 420b195167fSHerbert Xu static ssize_t show_hash_elasticity(struct device *d, 421b195167fSHerbert Xu struct device_attribute *attr, char *buf) 422b195167fSHerbert Xu { 423b195167fSHerbert Xu struct net_bridge *br = to_bridge(d); 424b195167fSHerbert Xu return sprintf(buf, "%u\n", br->hash_elasticity); 425b195167fSHerbert Xu } 426b195167fSHerbert Xu 427b195167fSHerbert Xu static int set_elasticity(struct net_bridge *br, unsigned long val) 428b195167fSHerbert Xu { 429b195167fSHerbert Xu br->hash_elasticity = val; 430b195167fSHerbert Xu return 0; 431b195167fSHerbert Xu } 432b195167fSHerbert Xu 433b195167fSHerbert Xu static ssize_t store_hash_elasticity(struct device *d, 434b195167fSHerbert Xu struct device_attribute *attr, 435b195167fSHerbert Xu const char *buf, size_t len) 436b195167fSHerbert Xu { 437b195167fSHerbert Xu return store_bridge_parm(d, buf, len, set_elasticity); 438b195167fSHerbert Xu } 439b195167fSHerbert Xu static DEVICE_ATTR(hash_elasticity, S_IRUGO | S_IWUSR, show_hash_elasticity, 440b195167fSHerbert Xu store_hash_elasticity); 441b195167fSHerbert Xu 442b195167fSHerbert Xu static ssize_t show_hash_max(struct device *d, struct device_attribute *attr, 443b195167fSHerbert Xu char *buf) 444b195167fSHerbert Xu { 445b195167fSHerbert Xu struct net_bridge *br = to_bridge(d); 446b195167fSHerbert Xu return sprintf(buf, "%u\n", br->hash_max); 447b195167fSHerbert Xu } 448b195167fSHerbert Xu 449b195167fSHerbert Xu static ssize_t store_hash_max(struct device *d, struct device_attribute *attr, 450b195167fSHerbert Xu const char *buf, size_t len) 451b195167fSHerbert Xu { 452b195167fSHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_hash_max); 453b195167fSHerbert Xu } 454b195167fSHerbert Xu static DEVICE_ATTR(hash_max, S_IRUGO | S_IWUSR, show_hash_max, 455b195167fSHerbert Xu store_hash_max); 456d902eee4SHerbert Xu 457d902eee4SHerbert Xu static ssize_t show_multicast_last_member_count(struct device *d, 458d902eee4SHerbert Xu struct device_attribute *attr, 459d902eee4SHerbert Xu char *buf) 460d902eee4SHerbert Xu { 461d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 462d902eee4SHerbert Xu return sprintf(buf, "%u\n", br->multicast_last_member_count); 463d902eee4SHerbert Xu } 464d902eee4SHerbert Xu 465d902eee4SHerbert Xu static int set_last_member_count(struct net_bridge *br, unsigned long val) 466d902eee4SHerbert Xu { 467d902eee4SHerbert Xu br->multicast_last_member_count = val; 468d902eee4SHerbert Xu return 0; 469d902eee4SHerbert Xu } 470d902eee4SHerbert Xu 471d902eee4SHerbert Xu static ssize_t store_multicast_last_member_count(struct device *d, 472d902eee4SHerbert Xu struct device_attribute *attr, 473d902eee4SHerbert Xu const char *buf, size_t len) 474d902eee4SHerbert Xu { 475d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_last_member_count); 476d902eee4SHerbert Xu } 477d902eee4SHerbert Xu static DEVICE_ATTR(multicast_last_member_count, S_IRUGO | S_IWUSR, 478d902eee4SHerbert Xu show_multicast_last_member_count, 479d902eee4SHerbert Xu store_multicast_last_member_count); 480d902eee4SHerbert Xu 481d902eee4SHerbert Xu static ssize_t show_multicast_startup_query_count( 482d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 483d902eee4SHerbert Xu { 484d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 485d902eee4SHerbert Xu return sprintf(buf, "%u\n", br->multicast_startup_query_count); 486d902eee4SHerbert Xu } 487d902eee4SHerbert Xu 488d902eee4SHerbert Xu static int set_startup_query_count(struct net_bridge *br, unsigned long val) 489d902eee4SHerbert Xu { 490d902eee4SHerbert Xu br->multicast_startup_query_count = val; 491d902eee4SHerbert Xu return 0; 492d902eee4SHerbert Xu } 493d902eee4SHerbert Xu 494d902eee4SHerbert Xu static ssize_t store_multicast_startup_query_count( 495d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 496d902eee4SHerbert Xu size_t len) 497d902eee4SHerbert Xu { 498d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_startup_query_count); 499d902eee4SHerbert Xu } 500d902eee4SHerbert Xu static DEVICE_ATTR(multicast_startup_query_count, S_IRUGO | S_IWUSR, 501d902eee4SHerbert Xu show_multicast_startup_query_count, 502d902eee4SHerbert Xu store_multicast_startup_query_count); 503d902eee4SHerbert Xu 504d902eee4SHerbert Xu static ssize_t show_multicast_last_member_interval( 505d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 506d902eee4SHerbert Xu { 507d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 508d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 509d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_last_member_interval)); 510d902eee4SHerbert Xu } 511d902eee4SHerbert Xu 512d902eee4SHerbert Xu static int set_last_member_interval(struct net_bridge *br, unsigned long val) 513d902eee4SHerbert Xu { 514d902eee4SHerbert Xu br->multicast_last_member_interval = clock_t_to_jiffies(val); 515d902eee4SHerbert Xu return 0; 516d902eee4SHerbert Xu } 517d902eee4SHerbert Xu 518d902eee4SHerbert Xu static ssize_t store_multicast_last_member_interval( 519d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 520d902eee4SHerbert Xu size_t len) 521d902eee4SHerbert Xu { 522d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_last_member_interval); 523d902eee4SHerbert Xu } 524d902eee4SHerbert Xu static DEVICE_ATTR(multicast_last_member_interval, S_IRUGO | S_IWUSR, 525d902eee4SHerbert Xu show_multicast_last_member_interval, 526d902eee4SHerbert Xu store_multicast_last_member_interval); 527d902eee4SHerbert Xu 528d902eee4SHerbert Xu static ssize_t show_multicast_membership_interval( 529d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 530d902eee4SHerbert Xu { 531d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 532d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 533d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_membership_interval)); 534d902eee4SHerbert Xu } 535d902eee4SHerbert Xu 536d902eee4SHerbert Xu static int set_membership_interval(struct net_bridge *br, unsigned long val) 537d902eee4SHerbert Xu { 538d902eee4SHerbert Xu br->multicast_membership_interval = clock_t_to_jiffies(val); 539d902eee4SHerbert Xu return 0; 540d902eee4SHerbert Xu } 541d902eee4SHerbert Xu 542d902eee4SHerbert Xu static ssize_t store_multicast_membership_interval( 543d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 544d902eee4SHerbert Xu size_t len) 545d902eee4SHerbert Xu { 546d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_membership_interval); 547d902eee4SHerbert Xu } 548d902eee4SHerbert Xu static DEVICE_ATTR(multicast_membership_interval, S_IRUGO | S_IWUSR, 549d902eee4SHerbert Xu show_multicast_membership_interval, 550d902eee4SHerbert Xu store_multicast_membership_interval); 551d902eee4SHerbert Xu 552d902eee4SHerbert Xu static ssize_t show_multicast_querier_interval(struct device *d, 553d902eee4SHerbert Xu struct device_attribute *attr, 554d902eee4SHerbert Xu char *buf) 555d902eee4SHerbert Xu { 556d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 557d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 558d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_querier_interval)); 559d902eee4SHerbert Xu } 560d902eee4SHerbert Xu 561d902eee4SHerbert Xu static int set_querier_interval(struct net_bridge *br, unsigned long val) 562d902eee4SHerbert Xu { 563d902eee4SHerbert Xu br->multicast_querier_interval = clock_t_to_jiffies(val); 564d902eee4SHerbert Xu return 0; 565d902eee4SHerbert Xu } 566d902eee4SHerbert Xu 567d902eee4SHerbert Xu static ssize_t store_multicast_querier_interval(struct device *d, 568d902eee4SHerbert Xu struct device_attribute *attr, 569d902eee4SHerbert Xu const char *buf, size_t len) 570d902eee4SHerbert Xu { 571d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_querier_interval); 572d902eee4SHerbert Xu } 573d902eee4SHerbert Xu static DEVICE_ATTR(multicast_querier_interval, S_IRUGO | S_IWUSR, 574d902eee4SHerbert Xu show_multicast_querier_interval, 575d902eee4SHerbert Xu store_multicast_querier_interval); 576d902eee4SHerbert Xu 577d902eee4SHerbert Xu static ssize_t show_multicast_query_interval(struct device *d, 578d902eee4SHerbert Xu struct device_attribute *attr, 579d902eee4SHerbert Xu char *buf) 580d902eee4SHerbert Xu { 581d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 582d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 583d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_query_interval)); 584d902eee4SHerbert Xu } 585d902eee4SHerbert Xu 586d902eee4SHerbert Xu static int set_query_interval(struct net_bridge *br, unsigned long val) 587d902eee4SHerbert Xu { 588d902eee4SHerbert Xu br->multicast_query_interval = clock_t_to_jiffies(val); 589d902eee4SHerbert Xu return 0; 590d902eee4SHerbert Xu } 591d902eee4SHerbert Xu 592d902eee4SHerbert Xu static ssize_t store_multicast_query_interval(struct device *d, 593d902eee4SHerbert Xu struct device_attribute *attr, 594d902eee4SHerbert Xu const char *buf, size_t len) 595d902eee4SHerbert Xu { 596d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_query_interval); 597d902eee4SHerbert Xu } 598d902eee4SHerbert Xu static DEVICE_ATTR(multicast_query_interval, S_IRUGO | S_IWUSR, 599d902eee4SHerbert Xu show_multicast_query_interval, 600d902eee4SHerbert Xu store_multicast_query_interval); 601d902eee4SHerbert Xu 602d902eee4SHerbert Xu static ssize_t show_multicast_query_response_interval( 603d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 604d902eee4SHerbert Xu { 605d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 606d902eee4SHerbert Xu return sprintf( 607d902eee4SHerbert Xu buf, "%lu\n", 608d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_query_response_interval)); 609d902eee4SHerbert Xu } 610d902eee4SHerbert Xu 611d902eee4SHerbert Xu static int set_query_response_interval(struct net_bridge *br, unsigned long val) 612d902eee4SHerbert Xu { 613d902eee4SHerbert Xu br->multicast_query_response_interval = clock_t_to_jiffies(val); 614d902eee4SHerbert Xu return 0; 615d902eee4SHerbert Xu } 616d902eee4SHerbert Xu 617d902eee4SHerbert Xu static ssize_t store_multicast_query_response_interval( 618d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 619d902eee4SHerbert Xu size_t len) 620d902eee4SHerbert Xu { 621d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_query_response_interval); 622d902eee4SHerbert Xu } 623d902eee4SHerbert Xu static DEVICE_ATTR(multicast_query_response_interval, S_IRUGO | S_IWUSR, 624d902eee4SHerbert Xu show_multicast_query_response_interval, 625d902eee4SHerbert Xu store_multicast_query_response_interval); 626d902eee4SHerbert Xu 627d902eee4SHerbert Xu static ssize_t show_multicast_startup_query_interval( 628d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 629d902eee4SHerbert Xu { 630d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 631d902eee4SHerbert Xu return sprintf( 632d902eee4SHerbert Xu buf, "%lu\n", 633d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_startup_query_interval)); 634d902eee4SHerbert Xu } 635d902eee4SHerbert Xu 636d902eee4SHerbert Xu static int set_startup_query_interval(struct net_bridge *br, unsigned long val) 637d902eee4SHerbert Xu { 638d902eee4SHerbert Xu br->multicast_startup_query_interval = clock_t_to_jiffies(val); 639d902eee4SHerbert Xu return 0; 640d902eee4SHerbert Xu } 641d902eee4SHerbert Xu 642d902eee4SHerbert Xu static ssize_t store_multicast_startup_query_interval( 643d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 644d902eee4SHerbert Xu size_t len) 645d902eee4SHerbert Xu { 646d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_startup_query_interval); 647d902eee4SHerbert Xu } 648d902eee4SHerbert Xu static DEVICE_ATTR(multicast_startup_query_interval, S_IRUGO | S_IWUSR, 649d902eee4SHerbert Xu show_multicast_startup_query_interval, 650d902eee4SHerbert Xu store_multicast_startup_query_interval); 6510909e117SHerbert Xu #endif 6524df53d8bSPatrick McHardy #ifdef CONFIG_BRIDGE_NETFILTER 6534df53d8bSPatrick McHardy static ssize_t show_nf_call_iptables( 6544df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 6554df53d8bSPatrick McHardy { 6564df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 6574df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_iptables); 6584df53d8bSPatrick McHardy } 6594df53d8bSPatrick McHardy 6604df53d8bSPatrick McHardy static int set_nf_call_iptables(struct net_bridge *br, unsigned long val) 6614df53d8bSPatrick McHardy { 6624df53d8bSPatrick McHardy br->nf_call_iptables = val ? true : false; 6634df53d8bSPatrick McHardy return 0; 6644df53d8bSPatrick McHardy } 6654df53d8bSPatrick McHardy 6664df53d8bSPatrick McHardy static ssize_t store_nf_call_iptables( 6674df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 6684df53d8bSPatrick McHardy size_t len) 6694df53d8bSPatrick McHardy { 6704df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_iptables); 6714df53d8bSPatrick McHardy } 6724df53d8bSPatrick McHardy static DEVICE_ATTR(nf_call_iptables, S_IRUGO | S_IWUSR, 6734df53d8bSPatrick McHardy show_nf_call_iptables, store_nf_call_iptables); 6744df53d8bSPatrick McHardy 6754df53d8bSPatrick McHardy static ssize_t show_nf_call_ip6tables( 6764df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 6774df53d8bSPatrick McHardy { 6784df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 6794df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_ip6tables); 6804df53d8bSPatrick McHardy } 6814df53d8bSPatrick McHardy 6824df53d8bSPatrick McHardy static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val) 6834df53d8bSPatrick McHardy { 6844df53d8bSPatrick McHardy br->nf_call_ip6tables = val ? true : false; 6854df53d8bSPatrick McHardy return 0; 6864df53d8bSPatrick McHardy } 6874df53d8bSPatrick McHardy 6884df53d8bSPatrick McHardy static ssize_t store_nf_call_ip6tables( 6894df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 6904df53d8bSPatrick McHardy size_t len) 6914df53d8bSPatrick McHardy { 6924df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_ip6tables); 6934df53d8bSPatrick McHardy } 6944df53d8bSPatrick McHardy static DEVICE_ATTR(nf_call_ip6tables, S_IRUGO | S_IWUSR, 6954df53d8bSPatrick McHardy show_nf_call_ip6tables, store_nf_call_ip6tables); 6964df53d8bSPatrick McHardy 6974df53d8bSPatrick McHardy static ssize_t show_nf_call_arptables( 6984df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 6994df53d8bSPatrick McHardy { 7004df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 7014df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_arptables); 7024df53d8bSPatrick McHardy } 7034df53d8bSPatrick McHardy 7044df53d8bSPatrick McHardy static int set_nf_call_arptables(struct net_bridge *br, unsigned long val) 7054df53d8bSPatrick McHardy { 7064df53d8bSPatrick McHardy br->nf_call_arptables = val ? true : false; 7074df53d8bSPatrick McHardy return 0; 7084df53d8bSPatrick McHardy } 7094df53d8bSPatrick McHardy 7104df53d8bSPatrick McHardy static ssize_t store_nf_call_arptables( 7114df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 7124df53d8bSPatrick McHardy size_t len) 7134df53d8bSPatrick McHardy { 7144df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_arptables); 7154df53d8bSPatrick McHardy } 7164df53d8bSPatrick McHardy static DEVICE_ATTR(nf_call_arptables, S_IRUGO | S_IWUSR, 7174df53d8bSPatrick McHardy show_nf_call_arptables, store_nf_call_arptables); 7184df53d8bSPatrick McHardy #endif 719243a2e63SVlad Yasevich #ifdef CONFIG_BRIDGE_VLAN_FILTERING 720243a2e63SVlad Yasevich static ssize_t show_vlan_filtering(struct device *d, 721243a2e63SVlad Yasevich struct device_attribute *attr, 722243a2e63SVlad Yasevich char *buf) 723243a2e63SVlad Yasevich { 724243a2e63SVlad Yasevich struct net_bridge *br = to_bridge(d); 725243a2e63SVlad Yasevich return sprintf(buf, "%d\n", br->vlan_enabled); 726243a2e63SVlad Yasevich } 727243a2e63SVlad Yasevich 728243a2e63SVlad Yasevich static ssize_t store_vlan_filtering(struct device *d, 729243a2e63SVlad Yasevich struct device_attribute *attr, 730243a2e63SVlad Yasevich const char *buf, size_t len) 731243a2e63SVlad Yasevich { 732243a2e63SVlad Yasevich return store_bridge_parm(d, buf, len, br_vlan_filter_toggle); 733243a2e63SVlad Yasevich } 734243a2e63SVlad Yasevich static DEVICE_ATTR(vlan_filtering, S_IRUGO | S_IWUSR, 735243a2e63SVlad Yasevich show_vlan_filtering, store_vlan_filtering); 736243a2e63SVlad Yasevich #endif 7370909e117SHerbert Xu 7381da177e4SLinus Torvalds static struct attribute *bridge_attrs[] = { 73943cb76d9SGreg Kroah-Hartman &dev_attr_forward_delay.attr, 74043cb76d9SGreg Kroah-Hartman &dev_attr_hello_time.attr, 74143cb76d9SGreg Kroah-Hartman &dev_attr_max_age.attr, 74243cb76d9SGreg Kroah-Hartman &dev_attr_ageing_time.attr, 74343cb76d9SGreg Kroah-Hartman &dev_attr_stp_state.attr, 744515853ccSstephen hemminger &dev_attr_group_fwd_mask.attr, 74543cb76d9SGreg Kroah-Hartman &dev_attr_priority.attr, 74643cb76d9SGreg Kroah-Hartman &dev_attr_bridge_id.attr, 74743cb76d9SGreg Kroah-Hartman &dev_attr_root_id.attr, 74843cb76d9SGreg Kroah-Hartman &dev_attr_root_path_cost.attr, 74943cb76d9SGreg Kroah-Hartman &dev_attr_root_port.attr, 75043cb76d9SGreg Kroah-Hartman &dev_attr_topology_change.attr, 75143cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_detected.attr, 75243cb76d9SGreg Kroah-Hartman &dev_attr_hello_timer.attr, 75343cb76d9SGreg Kroah-Hartman &dev_attr_tcn_timer.attr, 75443cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_timer.attr, 75543cb76d9SGreg Kroah-Hartman &dev_attr_gc_timer.attr, 75643cb76d9SGreg Kroah-Hartman &dev_attr_group_addr.attr, 7579cf63747SStephen Hemminger &dev_attr_flush.attr, 7580909e117SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 7590909e117SHerbert Xu &dev_attr_multicast_router.attr, 760561f1103SHerbert Xu &dev_attr_multicast_snooping.attr, 761c5c23260SHerbert Xu &dev_attr_multicast_querier.attr, 762*1c8ad5bfSCong Wang &dev_attr_multicast_query_use_ifaddr.attr, 763b195167fSHerbert Xu &dev_attr_hash_elasticity.attr, 764b195167fSHerbert Xu &dev_attr_hash_max.attr, 765d902eee4SHerbert Xu &dev_attr_multicast_last_member_count.attr, 766d902eee4SHerbert Xu &dev_attr_multicast_startup_query_count.attr, 767d902eee4SHerbert Xu &dev_attr_multicast_last_member_interval.attr, 768d902eee4SHerbert Xu &dev_attr_multicast_membership_interval.attr, 769d902eee4SHerbert Xu &dev_attr_multicast_querier_interval.attr, 770d902eee4SHerbert Xu &dev_attr_multicast_query_interval.attr, 771d902eee4SHerbert Xu &dev_attr_multicast_query_response_interval.attr, 772d902eee4SHerbert Xu &dev_attr_multicast_startup_query_interval.attr, 7730909e117SHerbert Xu #endif 7744df53d8bSPatrick McHardy #ifdef CONFIG_BRIDGE_NETFILTER 7754df53d8bSPatrick McHardy &dev_attr_nf_call_iptables.attr, 7764df53d8bSPatrick McHardy &dev_attr_nf_call_ip6tables.attr, 7774df53d8bSPatrick McHardy &dev_attr_nf_call_arptables.attr, 7784df53d8bSPatrick McHardy #endif 779243a2e63SVlad Yasevich #ifdef CONFIG_BRIDGE_VLAN_FILTERING 780243a2e63SVlad Yasevich &dev_attr_vlan_filtering.attr, 781243a2e63SVlad Yasevich #endif 7821da177e4SLinus Torvalds NULL 7831da177e4SLinus Torvalds }; 7841da177e4SLinus Torvalds 7851da177e4SLinus Torvalds static struct attribute_group bridge_group = { 7861da177e4SLinus Torvalds .name = SYSFS_BRIDGE_ATTR, 7871da177e4SLinus Torvalds .attrs = bridge_attrs, 7881da177e4SLinus Torvalds }; 7891da177e4SLinus Torvalds 7901da177e4SLinus Torvalds /* 7911da177e4SLinus Torvalds * Export the forwarding information table as a binary file 7921da177e4SLinus Torvalds * The records are struct __fdb_entry. 7931da177e4SLinus Torvalds * 7941da177e4SLinus Torvalds * Returns the number of bytes read. 7951da177e4SLinus Torvalds */ 7962c3c8beaSChris Wright static ssize_t brforward_read(struct file *filp, struct kobject *kobj, 79791a69029SZhang Rui struct bin_attribute *bin_attr, 79891a69029SZhang Rui char *buf, loff_t off, size_t count) 7991da177e4SLinus Torvalds { 80043cb76d9SGreg Kroah-Hartman struct device *dev = to_dev(kobj); 80143cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(dev); 8021da177e4SLinus Torvalds int n; 8031da177e4SLinus Torvalds 8041da177e4SLinus Torvalds /* must read whole records */ 8051da177e4SLinus Torvalds if (off % sizeof(struct __fdb_entry) != 0) 8061da177e4SLinus Torvalds return -EINVAL; 8071da177e4SLinus Torvalds 8081da177e4SLinus Torvalds n = br_fdb_fillbuf(br, buf, 8091da177e4SLinus Torvalds count / sizeof(struct __fdb_entry), 8101da177e4SLinus Torvalds off / sizeof(struct __fdb_entry)); 8111da177e4SLinus Torvalds 8121da177e4SLinus Torvalds if (n > 0) 8131da177e4SLinus Torvalds n *= sizeof(struct __fdb_entry); 8141da177e4SLinus Torvalds 8151da177e4SLinus Torvalds return n; 8161da177e4SLinus Torvalds } 8171da177e4SLinus Torvalds 8181da177e4SLinus Torvalds static struct bin_attribute bridge_forward = { 8191da177e4SLinus Torvalds .attr = { .name = SYSFS_BRIDGE_FDB, 8207b595756STejun Heo .mode = S_IRUGO, }, 8211da177e4SLinus Torvalds .read = brforward_read, 8221da177e4SLinus Torvalds }; 8231da177e4SLinus Torvalds 8241da177e4SLinus Torvalds /* 8251da177e4SLinus Torvalds * Add entries in sysfs onto the existing network class device 8261da177e4SLinus Torvalds * for the bridge. 8271da177e4SLinus Torvalds * Adds a attribute group "bridge" containing tuning parameters. 8281da177e4SLinus Torvalds * Binary attribute containing the forward table 8291da177e4SLinus Torvalds * Sub directory to hold links to interfaces. 8301da177e4SLinus Torvalds * 8311da177e4SLinus Torvalds * Note: the ifobj exists only to be a subdirectory 8321da177e4SLinus Torvalds * to hold links. The ifobj exists in same data structure 8331da177e4SLinus Torvalds * as it's parent the bridge so reference counting works. 8341da177e4SLinus Torvalds */ 8351da177e4SLinus Torvalds int br_sysfs_addbr(struct net_device *dev) 8361da177e4SLinus Torvalds { 83743cb76d9SGreg Kroah-Hartman struct kobject *brobj = &dev->dev.kobj; 8381da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 8391da177e4SLinus Torvalds int err; 8401da177e4SLinus Torvalds 8411da177e4SLinus Torvalds err = sysfs_create_group(brobj, &bridge_group); 8421da177e4SLinus Torvalds if (err) { 8431da177e4SLinus Torvalds pr_info("%s: can't create group %s/%s\n", 8440dc47877SHarvey Harrison __func__, dev->name, bridge_group.name); 8451da177e4SLinus Torvalds goto out1; 8461da177e4SLinus Torvalds } 8471da177e4SLinus Torvalds 8481da177e4SLinus Torvalds err = sysfs_create_bin_file(brobj, &bridge_forward); 8491da177e4SLinus Torvalds if (err) { 8501842c4beSRandy Dunlap pr_info("%s: can't create attribute file %s/%s\n", 8510dc47877SHarvey Harrison __func__, dev->name, bridge_forward.attr.name); 8521da177e4SLinus Torvalds goto out2; 8531da177e4SLinus Torvalds } 8541da177e4SLinus Torvalds 85543b98c4aSGreg Kroah-Hartman br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj); 85643b98c4aSGreg Kroah-Hartman if (!br->ifobj) { 8571da177e4SLinus Torvalds pr_info("%s: can't add kobject (directory) %s/%s\n", 8580dc47877SHarvey Harrison __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR); 8591da177e4SLinus Torvalds goto out3; 8601da177e4SLinus Torvalds } 8611da177e4SLinus Torvalds return 0; 8621da177e4SLinus Torvalds out3: 86343cb76d9SGreg Kroah-Hartman sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward); 8641da177e4SLinus Torvalds out2: 86543cb76d9SGreg Kroah-Hartman sysfs_remove_group(&dev->dev.kobj, &bridge_group); 8661da177e4SLinus Torvalds out1: 8671da177e4SLinus Torvalds return err; 8681da177e4SLinus Torvalds 8691da177e4SLinus Torvalds } 8701da177e4SLinus Torvalds 8711da177e4SLinus Torvalds void br_sysfs_delbr(struct net_device *dev) 8721da177e4SLinus Torvalds { 87343cb76d9SGreg Kroah-Hartman struct kobject *kobj = &dev->dev.kobj; 8741da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 8751da177e4SLinus Torvalds 87678a2d906SGreg Kroah-Hartman kobject_put(br->ifobj); 8771da177e4SLinus Torvalds sysfs_remove_bin_file(kobj, &bridge_forward); 8781da177e4SLinus Torvalds sysfs_remove_group(kobj, &bridge_group); 8791da177e4SLinus Torvalds } 880