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 401da177e4SLinus Torvalds if (!capable(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 13617120889SStephen Hemminger if (!capable(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 169515853ccSstephen hemminger if (!capable(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 304fda93d92SStephen Hemminger if (!capable(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 312*46acc460SBen 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 3369cf63747SStephen Hemminger if (!capable(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 378c5c23260SHerbert Xu static ssize_t show_multicast_querier(struct device *d, 379c5c23260SHerbert Xu struct device_attribute *attr, 380c5c23260SHerbert Xu char *buf) 381c5c23260SHerbert Xu { 382c5c23260SHerbert Xu struct net_bridge *br = to_bridge(d); 383c5c23260SHerbert Xu return sprintf(buf, "%d\n", br->multicast_querier); 384c5c23260SHerbert Xu } 385c5c23260SHerbert Xu 386c5c23260SHerbert Xu static ssize_t store_multicast_querier(struct device *d, 387c5c23260SHerbert Xu struct device_attribute *attr, 388c5c23260SHerbert Xu const char *buf, size_t len) 389c5c23260SHerbert Xu { 390c5c23260SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_querier); 391c5c23260SHerbert Xu } 392c5c23260SHerbert Xu static DEVICE_ATTR(multicast_querier, S_IRUGO | S_IWUSR, 393c5c23260SHerbert Xu show_multicast_querier, store_multicast_querier); 394c5c23260SHerbert Xu 395b195167fSHerbert Xu static ssize_t show_hash_elasticity(struct device *d, 396b195167fSHerbert Xu struct device_attribute *attr, char *buf) 397b195167fSHerbert Xu { 398b195167fSHerbert Xu struct net_bridge *br = to_bridge(d); 399b195167fSHerbert Xu return sprintf(buf, "%u\n", br->hash_elasticity); 400b195167fSHerbert Xu } 401b195167fSHerbert Xu 402b195167fSHerbert Xu static int set_elasticity(struct net_bridge *br, unsigned long val) 403b195167fSHerbert Xu { 404b195167fSHerbert Xu br->hash_elasticity = val; 405b195167fSHerbert Xu return 0; 406b195167fSHerbert Xu } 407b195167fSHerbert Xu 408b195167fSHerbert Xu static ssize_t store_hash_elasticity(struct device *d, 409b195167fSHerbert Xu struct device_attribute *attr, 410b195167fSHerbert Xu const char *buf, size_t len) 411b195167fSHerbert Xu { 412b195167fSHerbert Xu return store_bridge_parm(d, buf, len, set_elasticity); 413b195167fSHerbert Xu } 414b195167fSHerbert Xu static DEVICE_ATTR(hash_elasticity, S_IRUGO | S_IWUSR, show_hash_elasticity, 415b195167fSHerbert Xu store_hash_elasticity); 416b195167fSHerbert Xu 417b195167fSHerbert Xu static ssize_t show_hash_max(struct device *d, struct device_attribute *attr, 418b195167fSHerbert Xu char *buf) 419b195167fSHerbert Xu { 420b195167fSHerbert Xu struct net_bridge *br = to_bridge(d); 421b195167fSHerbert Xu return sprintf(buf, "%u\n", br->hash_max); 422b195167fSHerbert Xu } 423b195167fSHerbert Xu 424b195167fSHerbert Xu static ssize_t store_hash_max(struct device *d, struct device_attribute *attr, 425b195167fSHerbert Xu const char *buf, size_t len) 426b195167fSHerbert Xu { 427b195167fSHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_hash_max); 428b195167fSHerbert Xu } 429b195167fSHerbert Xu static DEVICE_ATTR(hash_max, S_IRUGO | S_IWUSR, show_hash_max, 430b195167fSHerbert Xu store_hash_max); 431d902eee4SHerbert Xu 432d902eee4SHerbert Xu static ssize_t show_multicast_last_member_count(struct device *d, 433d902eee4SHerbert Xu struct device_attribute *attr, 434d902eee4SHerbert Xu char *buf) 435d902eee4SHerbert Xu { 436d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 437d902eee4SHerbert Xu return sprintf(buf, "%u\n", br->multicast_last_member_count); 438d902eee4SHerbert Xu } 439d902eee4SHerbert Xu 440d902eee4SHerbert Xu static int set_last_member_count(struct net_bridge *br, unsigned long val) 441d902eee4SHerbert Xu { 442d902eee4SHerbert Xu br->multicast_last_member_count = val; 443d902eee4SHerbert Xu return 0; 444d902eee4SHerbert Xu } 445d902eee4SHerbert Xu 446d902eee4SHerbert Xu static ssize_t store_multicast_last_member_count(struct device *d, 447d902eee4SHerbert Xu struct device_attribute *attr, 448d902eee4SHerbert Xu const char *buf, size_t len) 449d902eee4SHerbert Xu { 450d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_last_member_count); 451d902eee4SHerbert Xu } 452d902eee4SHerbert Xu static DEVICE_ATTR(multicast_last_member_count, S_IRUGO | S_IWUSR, 453d902eee4SHerbert Xu show_multicast_last_member_count, 454d902eee4SHerbert Xu store_multicast_last_member_count); 455d902eee4SHerbert Xu 456d902eee4SHerbert Xu static ssize_t show_multicast_startup_query_count( 457d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 458d902eee4SHerbert Xu { 459d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 460d902eee4SHerbert Xu return sprintf(buf, "%u\n", br->multicast_startup_query_count); 461d902eee4SHerbert Xu } 462d902eee4SHerbert Xu 463d902eee4SHerbert Xu static int set_startup_query_count(struct net_bridge *br, unsigned long val) 464d902eee4SHerbert Xu { 465d902eee4SHerbert Xu br->multicast_startup_query_count = val; 466d902eee4SHerbert Xu return 0; 467d902eee4SHerbert Xu } 468d902eee4SHerbert Xu 469d902eee4SHerbert Xu static ssize_t store_multicast_startup_query_count( 470d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 471d902eee4SHerbert Xu size_t len) 472d902eee4SHerbert Xu { 473d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_startup_query_count); 474d902eee4SHerbert Xu } 475d902eee4SHerbert Xu static DEVICE_ATTR(multicast_startup_query_count, S_IRUGO | S_IWUSR, 476d902eee4SHerbert Xu show_multicast_startup_query_count, 477d902eee4SHerbert Xu store_multicast_startup_query_count); 478d902eee4SHerbert Xu 479d902eee4SHerbert Xu static ssize_t show_multicast_last_member_interval( 480d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 481d902eee4SHerbert Xu { 482d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 483d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 484d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_last_member_interval)); 485d902eee4SHerbert Xu } 486d902eee4SHerbert Xu 487d902eee4SHerbert Xu static int set_last_member_interval(struct net_bridge *br, unsigned long val) 488d902eee4SHerbert Xu { 489d902eee4SHerbert Xu br->multicast_last_member_interval = clock_t_to_jiffies(val); 490d902eee4SHerbert Xu return 0; 491d902eee4SHerbert Xu } 492d902eee4SHerbert Xu 493d902eee4SHerbert Xu static ssize_t store_multicast_last_member_interval( 494d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 495d902eee4SHerbert Xu size_t len) 496d902eee4SHerbert Xu { 497d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_last_member_interval); 498d902eee4SHerbert Xu } 499d902eee4SHerbert Xu static DEVICE_ATTR(multicast_last_member_interval, S_IRUGO | S_IWUSR, 500d902eee4SHerbert Xu show_multicast_last_member_interval, 501d902eee4SHerbert Xu store_multicast_last_member_interval); 502d902eee4SHerbert Xu 503d902eee4SHerbert Xu static ssize_t show_multicast_membership_interval( 504d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 505d902eee4SHerbert Xu { 506d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 507d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 508d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_membership_interval)); 509d902eee4SHerbert Xu } 510d902eee4SHerbert Xu 511d902eee4SHerbert Xu static int set_membership_interval(struct net_bridge *br, unsigned long val) 512d902eee4SHerbert Xu { 513d902eee4SHerbert Xu br->multicast_membership_interval = clock_t_to_jiffies(val); 514d902eee4SHerbert Xu return 0; 515d902eee4SHerbert Xu } 516d902eee4SHerbert Xu 517d902eee4SHerbert Xu static ssize_t store_multicast_membership_interval( 518d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 519d902eee4SHerbert Xu size_t len) 520d902eee4SHerbert Xu { 521d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_membership_interval); 522d902eee4SHerbert Xu } 523d902eee4SHerbert Xu static DEVICE_ATTR(multicast_membership_interval, S_IRUGO | S_IWUSR, 524d902eee4SHerbert Xu show_multicast_membership_interval, 525d902eee4SHerbert Xu store_multicast_membership_interval); 526d902eee4SHerbert Xu 527d902eee4SHerbert Xu static ssize_t show_multicast_querier_interval(struct device *d, 528d902eee4SHerbert Xu struct device_attribute *attr, 529d902eee4SHerbert Xu 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_querier_interval)); 534d902eee4SHerbert Xu } 535d902eee4SHerbert Xu 536d902eee4SHerbert Xu static int set_querier_interval(struct net_bridge *br, unsigned long val) 537d902eee4SHerbert Xu { 538d902eee4SHerbert Xu br->multicast_querier_interval = clock_t_to_jiffies(val); 539d902eee4SHerbert Xu return 0; 540d902eee4SHerbert Xu } 541d902eee4SHerbert Xu 542d902eee4SHerbert Xu static ssize_t store_multicast_querier_interval(struct device *d, 543d902eee4SHerbert Xu struct device_attribute *attr, 544d902eee4SHerbert Xu const char *buf, size_t len) 545d902eee4SHerbert Xu { 546d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_querier_interval); 547d902eee4SHerbert Xu } 548d902eee4SHerbert Xu static DEVICE_ATTR(multicast_querier_interval, S_IRUGO | S_IWUSR, 549d902eee4SHerbert Xu show_multicast_querier_interval, 550d902eee4SHerbert Xu store_multicast_querier_interval); 551d902eee4SHerbert Xu 552d902eee4SHerbert Xu static ssize_t show_multicast_query_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_query_interval)); 559d902eee4SHerbert Xu } 560d902eee4SHerbert Xu 561d902eee4SHerbert Xu static int set_query_interval(struct net_bridge *br, unsigned long val) 562d902eee4SHerbert Xu { 563d902eee4SHerbert Xu br->multicast_query_interval = clock_t_to_jiffies(val); 564d902eee4SHerbert Xu return 0; 565d902eee4SHerbert Xu } 566d902eee4SHerbert Xu 567d902eee4SHerbert Xu static ssize_t store_multicast_query_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_query_interval); 572d902eee4SHerbert Xu } 573d902eee4SHerbert Xu static DEVICE_ATTR(multicast_query_interval, S_IRUGO | S_IWUSR, 574d902eee4SHerbert Xu show_multicast_query_interval, 575d902eee4SHerbert Xu store_multicast_query_interval); 576d902eee4SHerbert Xu 577d902eee4SHerbert Xu static ssize_t show_multicast_query_response_interval( 578d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 579d902eee4SHerbert Xu { 580d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 581d902eee4SHerbert Xu return sprintf( 582d902eee4SHerbert Xu buf, "%lu\n", 583d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_query_response_interval)); 584d902eee4SHerbert Xu } 585d902eee4SHerbert Xu 586d902eee4SHerbert Xu static int set_query_response_interval(struct net_bridge *br, unsigned long val) 587d902eee4SHerbert Xu { 588d902eee4SHerbert Xu br->multicast_query_response_interval = clock_t_to_jiffies(val); 589d902eee4SHerbert Xu return 0; 590d902eee4SHerbert Xu } 591d902eee4SHerbert Xu 592d902eee4SHerbert Xu static ssize_t store_multicast_query_response_interval( 593d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 594d902eee4SHerbert Xu size_t len) 595d902eee4SHerbert Xu { 596d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_query_response_interval); 597d902eee4SHerbert Xu } 598d902eee4SHerbert Xu static DEVICE_ATTR(multicast_query_response_interval, S_IRUGO | S_IWUSR, 599d902eee4SHerbert Xu show_multicast_query_response_interval, 600d902eee4SHerbert Xu store_multicast_query_response_interval); 601d902eee4SHerbert Xu 602d902eee4SHerbert Xu static ssize_t show_multicast_startup_query_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_startup_query_interval)); 609d902eee4SHerbert Xu } 610d902eee4SHerbert Xu 611d902eee4SHerbert Xu static int set_startup_query_interval(struct net_bridge *br, unsigned long val) 612d902eee4SHerbert Xu { 613d902eee4SHerbert Xu br->multicast_startup_query_interval = clock_t_to_jiffies(val); 614d902eee4SHerbert Xu return 0; 615d902eee4SHerbert Xu } 616d902eee4SHerbert Xu 617d902eee4SHerbert Xu static ssize_t store_multicast_startup_query_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_startup_query_interval); 622d902eee4SHerbert Xu } 623d902eee4SHerbert Xu static DEVICE_ATTR(multicast_startup_query_interval, S_IRUGO | S_IWUSR, 624d902eee4SHerbert Xu show_multicast_startup_query_interval, 625d902eee4SHerbert Xu store_multicast_startup_query_interval); 6260909e117SHerbert Xu #endif 6274df53d8bSPatrick McHardy #ifdef CONFIG_BRIDGE_NETFILTER 6284df53d8bSPatrick McHardy static ssize_t show_nf_call_iptables( 6294df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 6304df53d8bSPatrick McHardy { 6314df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 6324df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_iptables); 6334df53d8bSPatrick McHardy } 6344df53d8bSPatrick McHardy 6354df53d8bSPatrick McHardy static int set_nf_call_iptables(struct net_bridge *br, unsigned long val) 6364df53d8bSPatrick McHardy { 6374df53d8bSPatrick McHardy br->nf_call_iptables = val ? true : false; 6384df53d8bSPatrick McHardy return 0; 6394df53d8bSPatrick McHardy } 6404df53d8bSPatrick McHardy 6414df53d8bSPatrick McHardy static ssize_t store_nf_call_iptables( 6424df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 6434df53d8bSPatrick McHardy size_t len) 6444df53d8bSPatrick McHardy { 6454df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_iptables); 6464df53d8bSPatrick McHardy } 6474df53d8bSPatrick McHardy static DEVICE_ATTR(nf_call_iptables, S_IRUGO | S_IWUSR, 6484df53d8bSPatrick McHardy show_nf_call_iptables, store_nf_call_iptables); 6494df53d8bSPatrick McHardy 6504df53d8bSPatrick McHardy static ssize_t show_nf_call_ip6tables( 6514df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 6524df53d8bSPatrick McHardy { 6534df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 6544df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_ip6tables); 6554df53d8bSPatrick McHardy } 6564df53d8bSPatrick McHardy 6574df53d8bSPatrick McHardy static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val) 6584df53d8bSPatrick McHardy { 6594df53d8bSPatrick McHardy br->nf_call_ip6tables = val ? true : false; 6604df53d8bSPatrick McHardy return 0; 6614df53d8bSPatrick McHardy } 6624df53d8bSPatrick McHardy 6634df53d8bSPatrick McHardy static ssize_t store_nf_call_ip6tables( 6644df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 6654df53d8bSPatrick McHardy size_t len) 6664df53d8bSPatrick McHardy { 6674df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_ip6tables); 6684df53d8bSPatrick McHardy } 6694df53d8bSPatrick McHardy static DEVICE_ATTR(nf_call_ip6tables, S_IRUGO | S_IWUSR, 6704df53d8bSPatrick McHardy show_nf_call_ip6tables, store_nf_call_ip6tables); 6714df53d8bSPatrick McHardy 6724df53d8bSPatrick McHardy static ssize_t show_nf_call_arptables( 6734df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 6744df53d8bSPatrick McHardy { 6754df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 6764df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_arptables); 6774df53d8bSPatrick McHardy } 6784df53d8bSPatrick McHardy 6794df53d8bSPatrick McHardy static int set_nf_call_arptables(struct net_bridge *br, unsigned long val) 6804df53d8bSPatrick McHardy { 6814df53d8bSPatrick McHardy br->nf_call_arptables = val ? true : false; 6824df53d8bSPatrick McHardy return 0; 6834df53d8bSPatrick McHardy } 6844df53d8bSPatrick McHardy 6854df53d8bSPatrick McHardy static ssize_t store_nf_call_arptables( 6864df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 6874df53d8bSPatrick McHardy size_t len) 6884df53d8bSPatrick McHardy { 6894df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_arptables); 6904df53d8bSPatrick McHardy } 6914df53d8bSPatrick McHardy static DEVICE_ATTR(nf_call_arptables, S_IRUGO | S_IWUSR, 6924df53d8bSPatrick McHardy show_nf_call_arptables, store_nf_call_arptables); 6934df53d8bSPatrick McHardy #endif 6940909e117SHerbert Xu 6951da177e4SLinus Torvalds static struct attribute *bridge_attrs[] = { 69643cb76d9SGreg Kroah-Hartman &dev_attr_forward_delay.attr, 69743cb76d9SGreg Kroah-Hartman &dev_attr_hello_time.attr, 69843cb76d9SGreg Kroah-Hartman &dev_attr_max_age.attr, 69943cb76d9SGreg Kroah-Hartman &dev_attr_ageing_time.attr, 70043cb76d9SGreg Kroah-Hartman &dev_attr_stp_state.attr, 701515853ccSstephen hemminger &dev_attr_group_fwd_mask.attr, 70243cb76d9SGreg Kroah-Hartman &dev_attr_priority.attr, 70343cb76d9SGreg Kroah-Hartman &dev_attr_bridge_id.attr, 70443cb76d9SGreg Kroah-Hartman &dev_attr_root_id.attr, 70543cb76d9SGreg Kroah-Hartman &dev_attr_root_path_cost.attr, 70643cb76d9SGreg Kroah-Hartman &dev_attr_root_port.attr, 70743cb76d9SGreg Kroah-Hartman &dev_attr_topology_change.attr, 70843cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_detected.attr, 70943cb76d9SGreg Kroah-Hartman &dev_attr_hello_timer.attr, 71043cb76d9SGreg Kroah-Hartman &dev_attr_tcn_timer.attr, 71143cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_timer.attr, 71243cb76d9SGreg Kroah-Hartman &dev_attr_gc_timer.attr, 71343cb76d9SGreg Kroah-Hartman &dev_attr_group_addr.attr, 7149cf63747SStephen Hemminger &dev_attr_flush.attr, 7150909e117SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 7160909e117SHerbert Xu &dev_attr_multicast_router.attr, 717561f1103SHerbert Xu &dev_attr_multicast_snooping.attr, 718c5c23260SHerbert Xu &dev_attr_multicast_querier.attr, 719b195167fSHerbert Xu &dev_attr_hash_elasticity.attr, 720b195167fSHerbert Xu &dev_attr_hash_max.attr, 721d902eee4SHerbert Xu &dev_attr_multicast_last_member_count.attr, 722d902eee4SHerbert Xu &dev_attr_multicast_startup_query_count.attr, 723d902eee4SHerbert Xu &dev_attr_multicast_last_member_interval.attr, 724d902eee4SHerbert Xu &dev_attr_multicast_membership_interval.attr, 725d902eee4SHerbert Xu &dev_attr_multicast_querier_interval.attr, 726d902eee4SHerbert Xu &dev_attr_multicast_query_interval.attr, 727d902eee4SHerbert Xu &dev_attr_multicast_query_response_interval.attr, 728d902eee4SHerbert Xu &dev_attr_multicast_startup_query_interval.attr, 7290909e117SHerbert Xu #endif 7304df53d8bSPatrick McHardy #ifdef CONFIG_BRIDGE_NETFILTER 7314df53d8bSPatrick McHardy &dev_attr_nf_call_iptables.attr, 7324df53d8bSPatrick McHardy &dev_attr_nf_call_ip6tables.attr, 7334df53d8bSPatrick McHardy &dev_attr_nf_call_arptables.attr, 7344df53d8bSPatrick McHardy #endif 7351da177e4SLinus Torvalds NULL 7361da177e4SLinus Torvalds }; 7371da177e4SLinus Torvalds 7381da177e4SLinus Torvalds static struct attribute_group bridge_group = { 7391da177e4SLinus Torvalds .name = SYSFS_BRIDGE_ATTR, 7401da177e4SLinus Torvalds .attrs = bridge_attrs, 7411da177e4SLinus Torvalds }; 7421da177e4SLinus Torvalds 7431da177e4SLinus Torvalds /* 7441da177e4SLinus Torvalds * Export the forwarding information table as a binary file 7451da177e4SLinus Torvalds * The records are struct __fdb_entry. 7461da177e4SLinus Torvalds * 7471da177e4SLinus Torvalds * Returns the number of bytes read. 7481da177e4SLinus Torvalds */ 7492c3c8beaSChris Wright static ssize_t brforward_read(struct file *filp, struct kobject *kobj, 75091a69029SZhang Rui struct bin_attribute *bin_attr, 75191a69029SZhang Rui char *buf, loff_t off, size_t count) 7521da177e4SLinus Torvalds { 75343cb76d9SGreg Kroah-Hartman struct device *dev = to_dev(kobj); 75443cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(dev); 7551da177e4SLinus Torvalds int n; 7561da177e4SLinus Torvalds 7571da177e4SLinus Torvalds /* must read whole records */ 7581da177e4SLinus Torvalds if (off % sizeof(struct __fdb_entry) != 0) 7591da177e4SLinus Torvalds return -EINVAL; 7601da177e4SLinus Torvalds 7611da177e4SLinus Torvalds n = br_fdb_fillbuf(br, buf, 7621da177e4SLinus Torvalds count / sizeof(struct __fdb_entry), 7631da177e4SLinus Torvalds off / sizeof(struct __fdb_entry)); 7641da177e4SLinus Torvalds 7651da177e4SLinus Torvalds if (n > 0) 7661da177e4SLinus Torvalds n *= sizeof(struct __fdb_entry); 7671da177e4SLinus Torvalds 7681da177e4SLinus Torvalds return n; 7691da177e4SLinus Torvalds } 7701da177e4SLinus Torvalds 7711da177e4SLinus Torvalds static struct bin_attribute bridge_forward = { 7721da177e4SLinus Torvalds .attr = { .name = SYSFS_BRIDGE_FDB, 7737b595756STejun Heo .mode = S_IRUGO, }, 7741da177e4SLinus Torvalds .read = brforward_read, 7751da177e4SLinus Torvalds }; 7761da177e4SLinus Torvalds 7771da177e4SLinus Torvalds /* 7781da177e4SLinus Torvalds * Add entries in sysfs onto the existing network class device 7791da177e4SLinus Torvalds * for the bridge. 7801da177e4SLinus Torvalds * Adds a attribute group "bridge" containing tuning parameters. 7811da177e4SLinus Torvalds * Binary attribute containing the forward table 7821da177e4SLinus Torvalds * Sub directory to hold links to interfaces. 7831da177e4SLinus Torvalds * 7841da177e4SLinus Torvalds * Note: the ifobj exists only to be a subdirectory 7851da177e4SLinus Torvalds * to hold links. The ifobj exists in same data structure 7861da177e4SLinus Torvalds * as it's parent the bridge so reference counting works. 7871da177e4SLinus Torvalds */ 7881da177e4SLinus Torvalds int br_sysfs_addbr(struct net_device *dev) 7891da177e4SLinus Torvalds { 79043cb76d9SGreg Kroah-Hartman struct kobject *brobj = &dev->dev.kobj; 7911da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 7921da177e4SLinus Torvalds int err; 7931da177e4SLinus Torvalds 7941da177e4SLinus Torvalds err = sysfs_create_group(brobj, &bridge_group); 7951da177e4SLinus Torvalds if (err) { 7961da177e4SLinus Torvalds pr_info("%s: can't create group %s/%s\n", 7970dc47877SHarvey Harrison __func__, dev->name, bridge_group.name); 7981da177e4SLinus Torvalds goto out1; 7991da177e4SLinus Torvalds } 8001da177e4SLinus Torvalds 8011da177e4SLinus Torvalds err = sysfs_create_bin_file(brobj, &bridge_forward); 8021da177e4SLinus Torvalds if (err) { 8031842c4beSRandy Dunlap pr_info("%s: can't create attribute file %s/%s\n", 8040dc47877SHarvey Harrison __func__, dev->name, bridge_forward.attr.name); 8051da177e4SLinus Torvalds goto out2; 8061da177e4SLinus Torvalds } 8071da177e4SLinus Torvalds 80843b98c4aSGreg Kroah-Hartman br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj); 80943b98c4aSGreg Kroah-Hartman if (!br->ifobj) { 8101da177e4SLinus Torvalds pr_info("%s: can't add kobject (directory) %s/%s\n", 8110dc47877SHarvey Harrison __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR); 8121da177e4SLinus Torvalds goto out3; 8131da177e4SLinus Torvalds } 8141da177e4SLinus Torvalds return 0; 8151da177e4SLinus Torvalds out3: 81643cb76d9SGreg Kroah-Hartman sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward); 8171da177e4SLinus Torvalds out2: 81843cb76d9SGreg Kroah-Hartman sysfs_remove_group(&dev->dev.kobj, &bridge_group); 8191da177e4SLinus Torvalds out1: 8201da177e4SLinus Torvalds return err; 8211da177e4SLinus Torvalds 8221da177e4SLinus Torvalds } 8231da177e4SLinus Torvalds 8241da177e4SLinus Torvalds void br_sysfs_delbr(struct net_device *dev) 8251da177e4SLinus Torvalds { 82643cb76d9SGreg Kroah-Hartman struct kobject *kobj = &dev->dev.kobj; 8271da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 8281da177e4SLinus Torvalds 82978a2d906SGreg Kroah-Hartman kobject_put(br->ifobj); 8301da177e4SLinus Torvalds sysfs_remove_bin_file(kobj, &bridge_forward); 8311da177e4SLinus Torvalds sysfs_remove_group(kobj, &bridge_group); 8321da177e4SLinus Torvalds } 833