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> 171da177e4SLinus Torvalds #include <linux/if_bridge.h> 181da177e4SLinus Torvalds #include <linux/rtnetlink.h> 191da177e4SLinus Torvalds #include <linux/spinlock.h> 201da177e4SLinus Torvalds #include <linux/times.h> 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds #include "br_private.h" 231da177e4SLinus Torvalds 2443cb76d9SGreg Kroah-Hartman #define to_dev(obj) container_of(obj, struct device, kobj) 25524ad0a7SWang Chen #define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd))) 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds /* 281da177e4SLinus Torvalds * Common code for storing bridge parameters. 291da177e4SLinus Torvalds */ 3043cb76d9SGreg Kroah-Hartman static ssize_t store_bridge_parm(struct device *d, 311da177e4SLinus Torvalds const char *buf, size_t len, 328d4698f7SStephen Hemminger int (*set)(struct net_bridge *, unsigned long)) 331da177e4SLinus Torvalds { 3443cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 351da177e4SLinus Torvalds char *endp; 361da177e4SLinus Torvalds unsigned long val; 378d4698f7SStephen Hemminger int err; 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds if (!capable(CAP_NET_ADMIN)) 401da177e4SLinus Torvalds return -EPERM; 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds val = simple_strtoul(buf, &endp, 0); 431da177e4SLinus Torvalds if (endp == buf) 441da177e4SLinus Torvalds return -EINVAL; 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds spin_lock_bh(&br->lock); 478d4698f7SStephen Hemminger err = (*set)(br, val); 481da177e4SLinus Torvalds spin_unlock_bh(&br->lock); 498d4698f7SStephen Hemminger return err ? err : len; 501da177e4SLinus Torvalds } 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds 5343cb76d9SGreg Kroah-Hartman static ssize_t show_forward_delay(struct device *d, 5443cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 551da177e4SLinus Torvalds { 5643cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 571da177e4SLinus Torvalds return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay)); 581da177e4SLinus Torvalds } 591da177e4SLinus Torvalds 608d4698f7SStephen Hemminger static int set_forward_delay(struct net_bridge *br, unsigned long val) 611da177e4SLinus Torvalds { 621da177e4SLinus Torvalds unsigned long delay = clock_t_to_jiffies(val); 631da177e4SLinus Torvalds br->forward_delay = delay; 641da177e4SLinus Torvalds if (br_is_root_bridge(br)) 651da177e4SLinus Torvalds br->bridge_forward_delay = delay; 668d4698f7SStephen Hemminger return 0; 671da177e4SLinus Torvalds } 681da177e4SLinus Torvalds 6943cb76d9SGreg Kroah-Hartman static ssize_t store_forward_delay(struct device *d, 7043cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 7143cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 721da177e4SLinus Torvalds { 7343cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_forward_delay); 741da177e4SLinus Torvalds } 7543cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(forward_delay, S_IRUGO | S_IWUSR, 761da177e4SLinus Torvalds show_forward_delay, store_forward_delay); 771da177e4SLinus Torvalds 7843cb76d9SGreg Kroah-Hartman static ssize_t show_hello_time(struct device *d, struct device_attribute *attr, 7943cb76d9SGreg Kroah-Hartman char *buf) 801da177e4SLinus Torvalds { 811da177e4SLinus Torvalds return sprintf(buf, "%lu\n", 8243cb76d9SGreg Kroah-Hartman jiffies_to_clock_t(to_bridge(d)->hello_time)); 831da177e4SLinus Torvalds } 841da177e4SLinus Torvalds 858d4698f7SStephen Hemminger static int set_hello_time(struct net_bridge *br, unsigned long val) 861da177e4SLinus Torvalds { 871da177e4SLinus Torvalds unsigned long t = clock_t_to_jiffies(val); 888d4698f7SStephen Hemminger 898d4698f7SStephen Hemminger if (t < HZ) 908d4698f7SStephen Hemminger return -EINVAL; 918d4698f7SStephen Hemminger 921da177e4SLinus Torvalds br->hello_time = t; 931da177e4SLinus Torvalds if (br_is_root_bridge(br)) 941da177e4SLinus Torvalds br->bridge_hello_time = t; 958d4698f7SStephen Hemminger return 0; 961da177e4SLinus Torvalds } 971da177e4SLinus Torvalds 9843cb76d9SGreg Kroah-Hartman static ssize_t store_hello_time(struct device *d, 9943cb76d9SGreg Kroah-Hartman struct device_attribute *attr, const char *buf, 1001da177e4SLinus Torvalds size_t len) 1011da177e4SLinus Torvalds { 10243cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_hello_time); 1031da177e4SLinus Torvalds } 10443cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(hello_time, S_IRUGO | S_IWUSR, show_hello_time, 1051da177e4SLinus Torvalds store_hello_time); 1061da177e4SLinus Torvalds 10743cb76d9SGreg Kroah-Hartman static ssize_t show_max_age(struct device *d, struct device_attribute *attr, 10843cb76d9SGreg Kroah-Hartman char *buf) 1091da177e4SLinus Torvalds { 1101da177e4SLinus Torvalds return sprintf(buf, "%lu\n", 11143cb76d9SGreg Kroah-Hartman jiffies_to_clock_t(to_bridge(d)->max_age)); 1121da177e4SLinus Torvalds } 1131da177e4SLinus Torvalds 1148d4698f7SStephen Hemminger static int set_max_age(struct net_bridge *br, unsigned long val) 1151da177e4SLinus Torvalds { 1161da177e4SLinus Torvalds unsigned long t = clock_t_to_jiffies(val); 1171da177e4SLinus Torvalds br->max_age = t; 1181da177e4SLinus Torvalds if (br_is_root_bridge(br)) 1191da177e4SLinus Torvalds br->bridge_max_age = t; 1208d4698f7SStephen Hemminger return 0; 1211da177e4SLinus Torvalds } 1221da177e4SLinus Torvalds 12343cb76d9SGreg Kroah-Hartman static ssize_t store_max_age(struct device *d, struct device_attribute *attr, 12443cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 1251da177e4SLinus Torvalds { 12643cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_max_age); 1271da177e4SLinus Torvalds } 12843cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(max_age, S_IRUGO | S_IWUSR, show_max_age, store_max_age); 1291da177e4SLinus Torvalds 13043cb76d9SGreg Kroah-Hartman static ssize_t show_ageing_time(struct device *d, 13143cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 1321da177e4SLinus Torvalds { 13343cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1341da177e4SLinus Torvalds return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time)); 1351da177e4SLinus Torvalds } 1361da177e4SLinus Torvalds 1378d4698f7SStephen Hemminger static int set_ageing_time(struct net_bridge *br, unsigned long val) 1381da177e4SLinus Torvalds { 1391da177e4SLinus Torvalds br->ageing_time = clock_t_to_jiffies(val); 1408d4698f7SStephen Hemminger return 0; 1411da177e4SLinus Torvalds } 1421da177e4SLinus Torvalds 14343cb76d9SGreg Kroah-Hartman static ssize_t store_ageing_time(struct device *d, 14443cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 14543cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 1461da177e4SLinus Torvalds { 14743cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_ageing_time); 1481da177e4SLinus Torvalds } 14943cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(ageing_time, S_IRUGO | S_IWUSR, show_ageing_time, 1501da177e4SLinus Torvalds store_ageing_time); 15143cb76d9SGreg Kroah-Hartman 15243cb76d9SGreg Kroah-Hartman static ssize_t show_stp_state(struct device *d, 15343cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 1541da177e4SLinus Torvalds { 15543cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1561da177e4SLinus Torvalds return sprintf(buf, "%d\n", br->stp_enabled); 1571da177e4SLinus Torvalds } 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvalds 16043cb76d9SGreg Kroah-Hartman static ssize_t store_stp_state(struct device *d, 16143cb76d9SGreg Kroah-Hartman struct device_attribute *attr, const char *buf, 16243cb76d9SGreg Kroah-Hartman size_t len) 1631da177e4SLinus Torvalds { 16417120889SStephen Hemminger struct net_bridge *br = to_bridge(d); 16517120889SStephen Hemminger char *endp; 16617120889SStephen Hemminger unsigned long val; 16717120889SStephen Hemminger 16817120889SStephen Hemminger if (!capable(CAP_NET_ADMIN)) 16917120889SStephen Hemminger return -EPERM; 17017120889SStephen Hemminger 17117120889SStephen Hemminger val = simple_strtoul(buf, &endp, 0); 17217120889SStephen Hemminger if (endp == buf) 17317120889SStephen Hemminger return -EINVAL; 17417120889SStephen Hemminger 175af38f298SEric W. Biederman if (!rtnl_trylock()) 176af38f298SEric W. Biederman return restart_syscall(); 17717120889SStephen Hemminger br_stp_set_enabled(br, val); 17817120889SStephen Hemminger rtnl_unlock(); 17917120889SStephen Hemminger 18035b426c3SAl Viro return len; 1811da177e4SLinus Torvalds } 18243cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(stp_state, S_IRUGO | S_IWUSR, show_stp_state, 1831da177e4SLinus Torvalds store_stp_state); 1841da177e4SLinus Torvalds 18543cb76d9SGreg Kroah-Hartman static ssize_t show_priority(struct device *d, struct device_attribute *attr, 18643cb76d9SGreg Kroah-Hartman char *buf) 1871da177e4SLinus Torvalds { 18843cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1891da177e4SLinus Torvalds return sprintf(buf, "%d\n", 1901da177e4SLinus Torvalds (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]); 1911da177e4SLinus Torvalds } 1921da177e4SLinus Torvalds 1938d4698f7SStephen Hemminger static int set_priority(struct net_bridge *br, unsigned long val) 1941da177e4SLinus Torvalds { 1951da177e4SLinus Torvalds br_stp_set_bridge_priority(br, (u16) val); 1968d4698f7SStephen Hemminger return 0; 1971da177e4SLinus Torvalds } 1981da177e4SLinus Torvalds 19943cb76d9SGreg Kroah-Hartman static ssize_t store_priority(struct device *d, struct device_attribute *attr, 2001da177e4SLinus Torvalds const char *buf, size_t len) 2011da177e4SLinus Torvalds { 20243cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_priority); 2031da177e4SLinus Torvalds } 20443cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(priority, S_IRUGO | S_IWUSR, show_priority, store_priority); 2051da177e4SLinus Torvalds 20643cb76d9SGreg Kroah-Hartman static ssize_t show_root_id(struct device *d, struct device_attribute *attr, 20743cb76d9SGreg Kroah-Hartman char *buf) 2081da177e4SLinus Torvalds { 20943cb76d9SGreg Kroah-Hartman return br_show_bridge_id(buf, &to_bridge(d)->designated_root); 2101da177e4SLinus Torvalds } 21143cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_id, S_IRUGO, show_root_id, NULL); 2121da177e4SLinus Torvalds 21343cb76d9SGreg Kroah-Hartman static ssize_t show_bridge_id(struct device *d, struct device_attribute *attr, 21443cb76d9SGreg Kroah-Hartman char *buf) 2151da177e4SLinus Torvalds { 21643cb76d9SGreg Kroah-Hartman return br_show_bridge_id(buf, &to_bridge(d)->bridge_id); 2171da177e4SLinus Torvalds } 21843cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(bridge_id, S_IRUGO, show_bridge_id, NULL); 2191da177e4SLinus Torvalds 22043cb76d9SGreg Kroah-Hartman static ssize_t show_root_port(struct device *d, struct device_attribute *attr, 22143cb76d9SGreg Kroah-Hartman char *buf) 2221da177e4SLinus Torvalds { 22343cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->root_port); 2241da177e4SLinus Torvalds } 22543cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_port, S_IRUGO, show_root_port, NULL); 2261da177e4SLinus Torvalds 22743cb76d9SGreg Kroah-Hartman static ssize_t show_root_path_cost(struct device *d, 22843cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2291da177e4SLinus Torvalds { 23043cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost); 2311da177e4SLinus Torvalds } 23243cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_path_cost, S_IRUGO, show_root_path_cost, NULL); 2331da177e4SLinus Torvalds 23443cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change(struct device *d, 23543cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2361da177e4SLinus Torvalds { 23743cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->topology_change); 2381da177e4SLinus Torvalds } 23943cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change, S_IRUGO, show_topology_change, NULL); 2401da177e4SLinus Torvalds 24143cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change_detected(struct device *d, 24243cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 24343cb76d9SGreg Kroah-Hartman char *buf) 2441da177e4SLinus Torvalds { 24543cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2461da177e4SLinus Torvalds return sprintf(buf, "%d\n", br->topology_change_detected); 2471da177e4SLinus Torvalds } 24843cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change_detected, S_IRUGO, 24943cb76d9SGreg Kroah-Hartman show_topology_change_detected, NULL); 2501da177e4SLinus Torvalds 25143cb76d9SGreg Kroah-Hartman static ssize_t show_hello_timer(struct device *d, 25243cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2531da177e4SLinus Torvalds { 25443cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2551da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer)); 2561da177e4SLinus Torvalds } 25743cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(hello_timer, S_IRUGO, show_hello_timer, NULL); 2581da177e4SLinus Torvalds 25943cb76d9SGreg Kroah-Hartman static ssize_t show_tcn_timer(struct device *d, struct device_attribute *attr, 26043cb76d9SGreg Kroah-Hartman char *buf) 2611da177e4SLinus Torvalds { 26243cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2631da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer)); 2641da177e4SLinus Torvalds } 26543cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(tcn_timer, S_IRUGO, show_tcn_timer, NULL); 2661da177e4SLinus Torvalds 26743cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change_timer(struct device *d, 26843cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 26943cb76d9SGreg Kroah-Hartman char *buf) 2701da177e4SLinus Torvalds { 27143cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2721da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer)); 2731da177e4SLinus Torvalds } 27443cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change_timer, S_IRUGO, show_topology_change_timer, 27543cb76d9SGreg Kroah-Hartman NULL); 2761da177e4SLinus Torvalds 27743cb76d9SGreg Kroah-Hartman static ssize_t show_gc_timer(struct device *d, struct device_attribute *attr, 27843cb76d9SGreg Kroah-Hartman char *buf) 2791da177e4SLinus Torvalds { 28043cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2811da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer)); 2821da177e4SLinus Torvalds } 28343cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(gc_timer, S_IRUGO, show_gc_timer, NULL); 2841da177e4SLinus Torvalds 28543cb76d9SGreg Kroah-Hartman static ssize_t show_group_addr(struct device *d, 28643cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 287fda93d92SStephen Hemminger { 28843cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 289fda93d92SStephen Hemminger return sprintf(buf, "%x:%x:%x:%x:%x:%x\n", 290fda93d92SStephen Hemminger br->group_addr[0], br->group_addr[1], 291fda93d92SStephen Hemminger br->group_addr[2], br->group_addr[3], 292fda93d92SStephen Hemminger br->group_addr[4], br->group_addr[5]); 293fda93d92SStephen Hemminger } 294fda93d92SStephen Hemminger 29543cb76d9SGreg Kroah-Hartman static ssize_t store_group_addr(struct device *d, 29643cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 29743cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 298fda93d92SStephen Hemminger { 29943cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 300fda93d92SStephen Hemminger unsigned new_addr[6]; 301fda93d92SStephen Hemminger int i; 302fda93d92SStephen Hemminger 303fda93d92SStephen Hemminger if (!capable(CAP_NET_ADMIN)) 304fda93d92SStephen Hemminger return -EPERM; 305fda93d92SStephen Hemminger 306fda93d92SStephen Hemminger if (sscanf(buf, "%x:%x:%x:%x:%x:%x", 307fda93d92SStephen Hemminger &new_addr[0], &new_addr[1], &new_addr[2], 308fda93d92SStephen Hemminger &new_addr[3], &new_addr[4], &new_addr[5]) != 6) 309fda93d92SStephen Hemminger return -EINVAL; 310fda93d92SStephen Hemminger 311fda93d92SStephen Hemminger /* Must be 01:80:c2:00:00:0X */ 312fda93d92SStephen Hemminger for (i = 0; i < 5; i++) 313fda93d92SStephen Hemminger if (new_addr[i] != br_group_address[i]) 314fda93d92SStephen Hemminger return -EINVAL; 315fda93d92SStephen Hemminger 316fda93d92SStephen Hemminger if (new_addr[5] & ~0xf) 317fda93d92SStephen Hemminger return -EINVAL; 318fda93d92SStephen Hemminger 319f64f9e71SJoe Perches if (new_addr[5] == 1 || /* 802.3x Pause address */ 320f64f9e71SJoe Perches new_addr[5] == 2 || /* 802.3ad Slow protocols */ 321f64f9e71SJoe Perches new_addr[5] == 3) /* 802.1X PAE address */ 322fda93d92SStephen Hemminger return -EINVAL; 323fda93d92SStephen Hemminger 324fda93d92SStephen Hemminger spin_lock_bh(&br->lock); 325fda93d92SStephen Hemminger for (i = 0; i < 6; i++) 326fda93d92SStephen Hemminger br->group_addr[i] = new_addr[i]; 327fda93d92SStephen Hemminger spin_unlock_bh(&br->lock); 328fda93d92SStephen Hemminger return len; 329fda93d92SStephen Hemminger } 330fda93d92SStephen Hemminger 33143cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(group_addr, S_IRUGO | S_IWUSR, 332fda93d92SStephen Hemminger show_group_addr, store_group_addr); 333fda93d92SStephen Hemminger 3349cf63747SStephen Hemminger static ssize_t store_flush(struct device *d, 3359cf63747SStephen Hemminger struct device_attribute *attr, 3369cf63747SStephen Hemminger const char *buf, size_t len) 3379cf63747SStephen Hemminger { 3389cf63747SStephen Hemminger struct net_bridge *br = to_bridge(d); 3399cf63747SStephen Hemminger 3409cf63747SStephen Hemminger if (!capable(CAP_NET_ADMIN)) 3419cf63747SStephen Hemminger return -EPERM; 3429cf63747SStephen Hemminger 3439cf63747SStephen Hemminger br_fdb_flush(br); 3449cf63747SStephen Hemminger return len; 3459cf63747SStephen Hemminger } 3469cf63747SStephen Hemminger static DEVICE_ATTR(flush, S_IWUSR, NULL, store_flush); 347fda93d92SStephen Hemminger 3480909e117SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 3490909e117SHerbert Xu static ssize_t show_multicast_router(struct device *d, 3500909e117SHerbert Xu struct device_attribute *attr, char *buf) 3510909e117SHerbert Xu { 3520909e117SHerbert Xu struct net_bridge *br = to_bridge(d); 3530909e117SHerbert Xu return sprintf(buf, "%d\n", br->multicast_router); 3540909e117SHerbert Xu } 3550909e117SHerbert Xu 3560909e117SHerbert Xu static ssize_t store_multicast_router(struct device *d, 3570909e117SHerbert Xu struct device_attribute *attr, 3580909e117SHerbert Xu const char *buf, size_t len) 3590909e117SHerbert Xu { 3600909e117SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_router); 3610909e117SHerbert Xu } 3620909e117SHerbert Xu static DEVICE_ATTR(multicast_router, S_IRUGO | S_IWUSR, show_multicast_router, 3630909e117SHerbert Xu store_multicast_router); 364561f1103SHerbert Xu 365561f1103SHerbert Xu static ssize_t show_multicast_snooping(struct device *d, 366561f1103SHerbert Xu struct device_attribute *attr, 367561f1103SHerbert Xu char *buf) 368561f1103SHerbert Xu { 369561f1103SHerbert Xu struct net_bridge *br = to_bridge(d); 370561f1103SHerbert Xu return sprintf(buf, "%d\n", !br->multicast_disabled); 371561f1103SHerbert Xu } 372561f1103SHerbert Xu 373561f1103SHerbert Xu static ssize_t store_multicast_snooping(struct device *d, 374561f1103SHerbert Xu struct device_attribute *attr, 375561f1103SHerbert Xu const char *buf, size_t len) 376561f1103SHerbert Xu { 377561f1103SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_toggle); 378561f1103SHerbert Xu } 379561f1103SHerbert Xu static DEVICE_ATTR(multicast_snooping, S_IRUGO | S_IWUSR, 380561f1103SHerbert Xu show_multicast_snooping, store_multicast_snooping); 381b195167fSHerbert Xu 382b195167fSHerbert Xu static ssize_t show_hash_elasticity(struct device *d, 383b195167fSHerbert Xu struct device_attribute *attr, char *buf) 384b195167fSHerbert Xu { 385b195167fSHerbert Xu struct net_bridge *br = to_bridge(d); 386b195167fSHerbert Xu return sprintf(buf, "%u\n", br->hash_elasticity); 387b195167fSHerbert Xu } 388b195167fSHerbert Xu 389b195167fSHerbert Xu static int set_elasticity(struct net_bridge *br, unsigned long val) 390b195167fSHerbert Xu { 391b195167fSHerbert Xu br->hash_elasticity = val; 392b195167fSHerbert Xu return 0; 393b195167fSHerbert Xu } 394b195167fSHerbert Xu 395b195167fSHerbert Xu static ssize_t store_hash_elasticity(struct device *d, 396b195167fSHerbert Xu struct device_attribute *attr, 397b195167fSHerbert Xu const char *buf, size_t len) 398b195167fSHerbert Xu { 399b195167fSHerbert Xu return store_bridge_parm(d, buf, len, set_elasticity); 400b195167fSHerbert Xu } 401b195167fSHerbert Xu static DEVICE_ATTR(hash_elasticity, S_IRUGO | S_IWUSR, show_hash_elasticity, 402b195167fSHerbert Xu store_hash_elasticity); 403b195167fSHerbert Xu 404b195167fSHerbert Xu static ssize_t show_hash_max(struct device *d, struct device_attribute *attr, 405b195167fSHerbert Xu char *buf) 406b195167fSHerbert Xu { 407b195167fSHerbert Xu struct net_bridge *br = to_bridge(d); 408b195167fSHerbert Xu return sprintf(buf, "%u\n", br->hash_max); 409b195167fSHerbert Xu } 410b195167fSHerbert Xu 411b195167fSHerbert Xu static ssize_t store_hash_max(struct device *d, struct device_attribute *attr, 412b195167fSHerbert Xu const char *buf, size_t len) 413b195167fSHerbert Xu { 414b195167fSHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_hash_max); 415b195167fSHerbert Xu } 416b195167fSHerbert Xu static DEVICE_ATTR(hash_max, S_IRUGO | S_IWUSR, show_hash_max, 417b195167fSHerbert Xu store_hash_max); 418d902eee4SHerbert Xu 419d902eee4SHerbert Xu static ssize_t show_multicast_last_member_count(struct device *d, 420d902eee4SHerbert Xu struct device_attribute *attr, 421d902eee4SHerbert Xu char *buf) 422d902eee4SHerbert Xu { 423d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 424d902eee4SHerbert Xu return sprintf(buf, "%u\n", br->multicast_last_member_count); 425d902eee4SHerbert Xu } 426d902eee4SHerbert Xu 427d902eee4SHerbert Xu static int set_last_member_count(struct net_bridge *br, unsigned long val) 428d902eee4SHerbert Xu { 429d902eee4SHerbert Xu br->multicast_last_member_count = val; 430d902eee4SHerbert Xu return 0; 431d902eee4SHerbert Xu } 432d902eee4SHerbert Xu 433d902eee4SHerbert Xu static ssize_t store_multicast_last_member_count(struct device *d, 434d902eee4SHerbert Xu struct device_attribute *attr, 435d902eee4SHerbert Xu const char *buf, size_t len) 436d902eee4SHerbert Xu { 437d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_last_member_count); 438d902eee4SHerbert Xu } 439d902eee4SHerbert Xu static DEVICE_ATTR(multicast_last_member_count, S_IRUGO | S_IWUSR, 440d902eee4SHerbert Xu show_multicast_last_member_count, 441d902eee4SHerbert Xu store_multicast_last_member_count); 442d902eee4SHerbert Xu 443d902eee4SHerbert Xu static ssize_t show_multicast_startup_query_count( 444d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 445d902eee4SHerbert Xu { 446d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 447d902eee4SHerbert Xu return sprintf(buf, "%u\n", br->multicast_startup_query_count); 448d902eee4SHerbert Xu } 449d902eee4SHerbert Xu 450d902eee4SHerbert Xu static int set_startup_query_count(struct net_bridge *br, unsigned long val) 451d902eee4SHerbert Xu { 452d902eee4SHerbert Xu br->multicast_startup_query_count = val; 453d902eee4SHerbert Xu return 0; 454d902eee4SHerbert Xu } 455d902eee4SHerbert Xu 456d902eee4SHerbert Xu static ssize_t store_multicast_startup_query_count( 457d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 458d902eee4SHerbert Xu size_t len) 459d902eee4SHerbert Xu { 460d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_startup_query_count); 461d902eee4SHerbert Xu } 462d902eee4SHerbert Xu static DEVICE_ATTR(multicast_startup_query_count, S_IRUGO | S_IWUSR, 463d902eee4SHerbert Xu show_multicast_startup_query_count, 464d902eee4SHerbert Xu store_multicast_startup_query_count); 465d902eee4SHerbert Xu 466d902eee4SHerbert Xu static ssize_t show_multicast_last_member_interval( 467d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 468d902eee4SHerbert Xu { 469d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 470d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 471d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_last_member_interval)); 472d902eee4SHerbert Xu } 473d902eee4SHerbert Xu 474d902eee4SHerbert Xu static int set_last_member_interval(struct net_bridge *br, unsigned long val) 475d902eee4SHerbert Xu { 476d902eee4SHerbert Xu br->multicast_last_member_interval = clock_t_to_jiffies(val); 477d902eee4SHerbert Xu return 0; 478d902eee4SHerbert Xu } 479d902eee4SHerbert Xu 480d902eee4SHerbert Xu static ssize_t store_multicast_last_member_interval( 481d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 482d902eee4SHerbert Xu size_t len) 483d902eee4SHerbert Xu { 484d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_last_member_interval); 485d902eee4SHerbert Xu } 486d902eee4SHerbert Xu static DEVICE_ATTR(multicast_last_member_interval, S_IRUGO | S_IWUSR, 487d902eee4SHerbert Xu show_multicast_last_member_interval, 488d902eee4SHerbert Xu store_multicast_last_member_interval); 489d902eee4SHerbert Xu 490d902eee4SHerbert Xu static ssize_t show_multicast_membership_interval( 491d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 492d902eee4SHerbert Xu { 493d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 494d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 495d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_membership_interval)); 496d902eee4SHerbert Xu } 497d902eee4SHerbert Xu 498d902eee4SHerbert Xu static int set_membership_interval(struct net_bridge *br, unsigned long val) 499d902eee4SHerbert Xu { 500d902eee4SHerbert Xu br->multicast_membership_interval = clock_t_to_jiffies(val); 501d902eee4SHerbert Xu return 0; 502d902eee4SHerbert Xu } 503d902eee4SHerbert Xu 504d902eee4SHerbert Xu static ssize_t store_multicast_membership_interval( 505d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 506d902eee4SHerbert Xu size_t len) 507d902eee4SHerbert Xu { 508d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_membership_interval); 509d902eee4SHerbert Xu } 510d902eee4SHerbert Xu static DEVICE_ATTR(multicast_membership_interval, S_IRUGO | S_IWUSR, 511d902eee4SHerbert Xu show_multicast_membership_interval, 512d902eee4SHerbert Xu store_multicast_membership_interval); 513d902eee4SHerbert Xu 514d902eee4SHerbert Xu static ssize_t show_multicast_querier_interval(struct device *d, 515d902eee4SHerbert Xu struct device_attribute *attr, 516d902eee4SHerbert Xu char *buf) 517d902eee4SHerbert Xu { 518d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 519d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 520d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_querier_interval)); 521d902eee4SHerbert Xu } 522d902eee4SHerbert Xu 523d902eee4SHerbert Xu static int set_querier_interval(struct net_bridge *br, unsigned long val) 524d902eee4SHerbert Xu { 525d902eee4SHerbert Xu br->multicast_querier_interval = clock_t_to_jiffies(val); 526d902eee4SHerbert Xu return 0; 527d902eee4SHerbert Xu } 528d902eee4SHerbert Xu 529d902eee4SHerbert Xu static ssize_t store_multicast_querier_interval(struct device *d, 530d902eee4SHerbert Xu struct device_attribute *attr, 531d902eee4SHerbert Xu const char *buf, size_t len) 532d902eee4SHerbert Xu { 533d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_querier_interval); 534d902eee4SHerbert Xu } 535d902eee4SHerbert Xu static DEVICE_ATTR(multicast_querier_interval, S_IRUGO | S_IWUSR, 536d902eee4SHerbert Xu show_multicast_querier_interval, 537d902eee4SHerbert Xu store_multicast_querier_interval); 538d902eee4SHerbert Xu 539d902eee4SHerbert Xu static ssize_t show_multicast_query_interval(struct device *d, 540d902eee4SHerbert Xu struct device_attribute *attr, 541d902eee4SHerbert Xu char *buf) 542d902eee4SHerbert Xu { 543d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 544d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 545d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_query_interval)); 546d902eee4SHerbert Xu } 547d902eee4SHerbert Xu 548d902eee4SHerbert Xu static int set_query_interval(struct net_bridge *br, unsigned long val) 549d902eee4SHerbert Xu { 550d902eee4SHerbert Xu br->multicast_query_interval = clock_t_to_jiffies(val); 551d902eee4SHerbert Xu return 0; 552d902eee4SHerbert Xu } 553d902eee4SHerbert Xu 554d902eee4SHerbert Xu static ssize_t store_multicast_query_interval(struct device *d, 555d902eee4SHerbert Xu struct device_attribute *attr, 556d902eee4SHerbert Xu const char *buf, size_t len) 557d902eee4SHerbert Xu { 558d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_query_interval); 559d902eee4SHerbert Xu } 560d902eee4SHerbert Xu static DEVICE_ATTR(multicast_query_interval, S_IRUGO | S_IWUSR, 561d902eee4SHerbert Xu show_multicast_query_interval, 562d902eee4SHerbert Xu store_multicast_query_interval); 563d902eee4SHerbert Xu 564d902eee4SHerbert Xu static ssize_t show_multicast_query_response_interval( 565d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 566d902eee4SHerbert Xu { 567d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 568d902eee4SHerbert Xu return sprintf( 569d902eee4SHerbert Xu buf, "%lu\n", 570d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_query_response_interval)); 571d902eee4SHerbert Xu } 572d902eee4SHerbert Xu 573d902eee4SHerbert Xu static int set_query_response_interval(struct net_bridge *br, unsigned long val) 574d902eee4SHerbert Xu { 575d902eee4SHerbert Xu br->multicast_query_response_interval = clock_t_to_jiffies(val); 576d902eee4SHerbert Xu return 0; 577d902eee4SHerbert Xu } 578d902eee4SHerbert Xu 579d902eee4SHerbert Xu static ssize_t store_multicast_query_response_interval( 580d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 581d902eee4SHerbert Xu size_t len) 582d902eee4SHerbert Xu { 583d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_query_response_interval); 584d902eee4SHerbert Xu } 585d902eee4SHerbert Xu static DEVICE_ATTR(multicast_query_response_interval, S_IRUGO | S_IWUSR, 586d902eee4SHerbert Xu show_multicast_query_response_interval, 587d902eee4SHerbert Xu store_multicast_query_response_interval); 588d902eee4SHerbert Xu 589d902eee4SHerbert Xu static ssize_t show_multicast_startup_query_interval( 590d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 591d902eee4SHerbert Xu { 592d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 593d902eee4SHerbert Xu return sprintf( 594d902eee4SHerbert Xu buf, "%lu\n", 595d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_startup_query_interval)); 596d902eee4SHerbert Xu } 597d902eee4SHerbert Xu 598d902eee4SHerbert Xu static int set_startup_query_interval(struct net_bridge *br, unsigned long val) 599d902eee4SHerbert Xu { 600d902eee4SHerbert Xu br->multicast_startup_query_interval = clock_t_to_jiffies(val); 601d902eee4SHerbert Xu return 0; 602d902eee4SHerbert Xu } 603d902eee4SHerbert Xu 604d902eee4SHerbert Xu static ssize_t store_multicast_startup_query_interval( 605d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 606d902eee4SHerbert Xu size_t len) 607d902eee4SHerbert Xu { 608d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_startup_query_interval); 609d902eee4SHerbert Xu } 610d902eee4SHerbert Xu static DEVICE_ATTR(multicast_startup_query_interval, S_IRUGO | S_IWUSR, 611d902eee4SHerbert Xu show_multicast_startup_query_interval, 612d902eee4SHerbert Xu store_multicast_startup_query_interval); 6130909e117SHerbert Xu #endif 614*4df53d8bSPatrick McHardy #ifdef CONFIG_BRIDGE_NETFILTER 615*4df53d8bSPatrick McHardy static ssize_t show_nf_call_iptables( 616*4df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 617*4df53d8bSPatrick McHardy { 618*4df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 619*4df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_iptables); 620*4df53d8bSPatrick McHardy } 621*4df53d8bSPatrick McHardy 622*4df53d8bSPatrick McHardy static int set_nf_call_iptables(struct net_bridge *br, unsigned long val) 623*4df53d8bSPatrick McHardy { 624*4df53d8bSPatrick McHardy br->nf_call_iptables = val ? true : false; 625*4df53d8bSPatrick McHardy return 0; 626*4df53d8bSPatrick McHardy } 627*4df53d8bSPatrick McHardy 628*4df53d8bSPatrick McHardy static ssize_t store_nf_call_iptables( 629*4df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 630*4df53d8bSPatrick McHardy size_t len) 631*4df53d8bSPatrick McHardy { 632*4df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_iptables); 633*4df53d8bSPatrick McHardy } 634*4df53d8bSPatrick McHardy static DEVICE_ATTR(nf_call_iptables, S_IRUGO | S_IWUSR, 635*4df53d8bSPatrick McHardy show_nf_call_iptables, store_nf_call_iptables); 636*4df53d8bSPatrick McHardy 637*4df53d8bSPatrick McHardy static ssize_t show_nf_call_ip6tables( 638*4df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 639*4df53d8bSPatrick McHardy { 640*4df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 641*4df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_ip6tables); 642*4df53d8bSPatrick McHardy } 643*4df53d8bSPatrick McHardy 644*4df53d8bSPatrick McHardy static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val) 645*4df53d8bSPatrick McHardy { 646*4df53d8bSPatrick McHardy br->nf_call_ip6tables = val ? true : false; 647*4df53d8bSPatrick McHardy return 0; 648*4df53d8bSPatrick McHardy } 649*4df53d8bSPatrick McHardy 650*4df53d8bSPatrick McHardy static ssize_t store_nf_call_ip6tables( 651*4df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 652*4df53d8bSPatrick McHardy size_t len) 653*4df53d8bSPatrick McHardy { 654*4df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_ip6tables); 655*4df53d8bSPatrick McHardy } 656*4df53d8bSPatrick McHardy static DEVICE_ATTR(nf_call_ip6tables, S_IRUGO | S_IWUSR, 657*4df53d8bSPatrick McHardy show_nf_call_ip6tables, store_nf_call_ip6tables); 658*4df53d8bSPatrick McHardy 659*4df53d8bSPatrick McHardy static ssize_t show_nf_call_arptables( 660*4df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 661*4df53d8bSPatrick McHardy { 662*4df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 663*4df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_arptables); 664*4df53d8bSPatrick McHardy } 665*4df53d8bSPatrick McHardy 666*4df53d8bSPatrick McHardy static int set_nf_call_arptables(struct net_bridge *br, unsigned long val) 667*4df53d8bSPatrick McHardy { 668*4df53d8bSPatrick McHardy br->nf_call_arptables = val ? true : false; 669*4df53d8bSPatrick McHardy return 0; 670*4df53d8bSPatrick McHardy } 671*4df53d8bSPatrick McHardy 672*4df53d8bSPatrick McHardy static ssize_t store_nf_call_arptables( 673*4df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 674*4df53d8bSPatrick McHardy size_t len) 675*4df53d8bSPatrick McHardy { 676*4df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_arptables); 677*4df53d8bSPatrick McHardy } 678*4df53d8bSPatrick McHardy static DEVICE_ATTR(nf_call_arptables, S_IRUGO | S_IWUSR, 679*4df53d8bSPatrick McHardy show_nf_call_arptables, store_nf_call_arptables); 680*4df53d8bSPatrick McHardy #endif 6810909e117SHerbert Xu 6821da177e4SLinus Torvalds static struct attribute *bridge_attrs[] = { 68343cb76d9SGreg Kroah-Hartman &dev_attr_forward_delay.attr, 68443cb76d9SGreg Kroah-Hartman &dev_attr_hello_time.attr, 68543cb76d9SGreg Kroah-Hartman &dev_attr_max_age.attr, 68643cb76d9SGreg Kroah-Hartman &dev_attr_ageing_time.attr, 68743cb76d9SGreg Kroah-Hartman &dev_attr_stp_state.attr, 68843cb76d9SGreg Kroah-Hartman &dev_attr_priority.attr, 68943cb76d9SGreg Kroah-Hartman &dev_attr_bridge_id.attr, 69043cb76d9SGreg Kroah-Hartman &dev_attr_root_id.attr, 69143cb76d9SGreg Kroah-Hartman &dev_attr_root_path_cost.attr, 69243cb76d9SGreg Kroah-Hartman &dev_attr_root_port.attr, 69343cb76d9SGreg Kroah-Hartman &dev_attr_topology_change.attr, 69443cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_detected.attr, 69543cb76d9SGreg Kroah-Hartman &dev_attr_hello_timer.attr, 69643cb76d9SGreg Kroah-Hartman &dev_attr_tcn_timer.attr, 69743cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_timer.attr, 69843cb76d9SGreg Kroah-Hartman &dev_attr_gc_timer.attr, 69943cb76d9SGreg Kroah-Hartman &dev_attr_group_addr.attr, 7009cf63747SStephen Hemminger &dev_attr_flush.attr, 7010909e117SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 7020909e117SHerbert Xu &dev_attr_multicast_router.attr, 703561f1103SHerbert Xu &dev_attr_multicast_snooping.attr, 704b195167fSHerbert Xu &dev_attr_hash_elasticity.attr, 705b195167fSHerbert Xu &dev_attr_hash_max.attr, 706d902eee4SHerbert Xu &dev_attr_multicast_last_member_count.attr, 707d902eee4SHerbert Xu &dev_attr_multicast_startup_query_count.attr, 708d902eee4SHerbert Xu &dev_attr_multicast_last_member_interval.attr, 709d902eee4SHerbert Xu &dev_attr_multicast_membership_interval.attr, 710d902eee4SHerbert Xu &dev_attr_multicast_querier_interval.attr, 711d902eee4SHerbert Xu &dev_attr_multicast_query_interval.attr, 712d902eee4SHerbert Xu &dev_attr_multicast_query_response_interval.attr, 713d902eee4SHerbert Xu &dev_attr_multicast_startup_query_interval.attr, 7140909e117SHerbert Xu #endif 715*4df53d8bSPatrick McHardy #ifdef CONFIG_BRIDGE_NETFILTER 716*4df53d8bSPatrick McHardy &dev_attr_nf_call_iptables.attr, 717*4df53d8bSPatrick McHardy &dev_attr_nf_call_ip6tables.attr, 718*4df53d8bSPatrick McHardy &dev_attr_nf_call_arptables.attr, 719*4df53d8bSPatrick McHardy #endif 7201da177e4SLinus Torvalds NULL 7211da177e4SLinus Torvalds }; 7221da177e4SLinus Torvalds 7231da177e4SLinus Torvalds static struct attribute_group bridge_group = { 7241da177e4SLinus Torvalds .name = SYSFS_BRIDGE_ATTR, 7251da177e4SLinus Torvalds .attrs = bridge_attrs, 7261da177e4SLinus Torvalds }; 7271da177e4SLinus Torvalds 7281da177e4SLinus Torvalds /* 7291da177e4SLinus Torvalds * Export the forwarding information table as a binary file 7301da177e4SLinus Torvalds * The records are struct __fdb_entry. 7311da177e4SLinus Torvalds * 7321da177e4SLinus Torvalds * Returns the number of bytes read. 7331da177e4SLinus Torvalds */ 7342c3c8beaSChris Wright static ssize_t brforward_read(struct file *filp, struct kobject *kobj, 73591a69029SZhang Rui struct bin_attribute *bin_attr, 73691a69029SZhang Rui char *buf, loff_t off, size_t count) 7371da177e4SLinus Torvalds { 73843cb76d9SGreg Kroah-Hartman struct device *dev = to_dev(kobj); 73943cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(dev); 7401da177e4SLinus Torvalds int n; 7411da177e4SLinus Torvalds 7421da177e4SLinus Torvalds /* must read whole records */ 7431da177e4SLinus Torvalds if (off % sizeof(struct __fdb_entry) != 0) 7441da177e4SLinus Torvalds return -EINVAL; 7451da177e4SLinus Torvalds 7461da177e4SLinus Torvalds n = br_fdb_fillbuf(br, buf, 7471da177e4SLinus Torvalds count / sizeof(struct __fdb_entry), 7481da177e4SLinus Torvalds off / sizeof(struct __fdb_entry)); 7491da177e4SLinus Torvalds 7501da177e4SLinus Torvalds if (n > 0) 7511da177e4SLinus Torvalds n *= sizeof(struct __fdb_entry); 7521da177e4SLinus Torvalds 7531da177e4SLinus Torvalds return n; 7541da177e4SLinus Torvalds } 7551da177e4SLinus Torvalds 7561da177e4SLinus Torvalds static struct bin_attribute bridge_forward = { 7571da177e4SLinus Torvalds .attr = { .name = SYSFS_BRIDGE_FDB, 7587b595756STejun Heo .mode = S_IRUGO, }, 7591da177e4SLinus Torvalds .read = brforward_read, 7601da177e4SLinus Torvalds }; 7611da177e4SLinus Torvalds 7621da177e4SLinus Torvalds /* 7631da177e4SLinus Torvalds * Add entries in sysfs onto the existing network class device 7641da177e4SLinus Torvalds * for the bridge. 7651da177e4SLinus Torvalds * Adds a attribute group "bridge" containing tuning parameters. 7661da177e4SLinus Torvalds * Binary attribute containing the forward table 7671da177e4SLinus Torvalds * Sub directory to hold links to interfaces. 7681da177e4SLinus Torvalds * 7691da177e4SLinus Torvalds * Note: the ifobj exists only to be a subdirectory 7701da177e4SLinus Torvalds * to hold links. The ifobj exists in same data structure 7711da177e4SLinus Torvalds * as it's parent the bridge so reference counting works. 7721da177e4SLinus Torvalds */ 7731da177e4SLinus Torvalds int br_sysfs_addbr(struct net_device *dev) 7741da177e4SLinus Torvalds { 77543cb76d9SGreg Kroah-Hartman struct kobject *brobj = &dev->dev.kobj; 7761da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 7771da177e4SLinus Torvalds int err; 7781da177e4SLinus Torvalds 7791da177e4SLinus Torvalds err = sysfs_create_group(brobj, &bridge_group); 7801da177e4SLinus Torvalds if (err) { 7811da177e4SLinus Torvalds pr_info("%s: can't create group %s/%s\n", 7820dc47877SHarvey Harrison __func__, dev->name, bridge_group.name); 7831da177e4SLinus Torvalds goto out1; 7841da177e4SLinus Torvalds } 7851da177e4SLinus Torvalds 7861da177e4SLinus Torvalds err = sysfs_create_bin_file(brobj, &bridge_forward); 7871da177e4SLinus Torvalds if (err) { 7881842c4beSRandy Dunlap pr_info("%s: can't create attribute file %s/%s\n", 7890dc47877SHarvey Harrison __func__, dev->name, bridge_forward.attr.name); 7901da177e4SLinus Torvalds goto out2; 7911da177e4SLinus Torvalds } 7921da177e4SLinus Torvalds 79343b98c4aSGreg Kroah-Hartman br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj); 79443b98c4aSGreg Kroah-Hartman if (!br->ifobj) { 7951da177e4SLinus Torvalds pr_info("%s: can't add kobject (directory) %s/%s\n", 7960dc47877SHarvey Harrison __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR); 7971da177e4SLinus Torvalds goto out3; 7981da177e4SLinus Torvalds } 7991da177e4SLinus Torvalds return 0; 8001da177e4SLinus Torvalds out3: 80143cb76d9SGreg Kroah-Hartman sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward); 8021da177e4SLinus Torvalds out2: 80343cb76d9SGreg Kroah-Hartman sysfs_remove_group(&dev->dev.kobj, &bridge_group); 8041da177e4SLinus Torvalds out1: 8051da177e4SLinus Torvalds return err; 8061da177e4SLinus Torvalds 8071da177e4SLinus Torvalds } 8081da177e4SLinus Torvalds 8091da177e4SLinus Torvalds void br_sysfs_delbr(struct net_device *dev) 8101da177e4SLinus Torvalds { 81143cb76d9SGreg Kroah-Hartman struct kobject *kobj = &dev->dev.kobj; 8121da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 8131da177e4SLinus Torvalds 81478a2d906SGreg Kroah-Hartman kobject_put(br->ifobj); 8151da177e4SLinus Torvalds sysfs_remove_bin_file(kobj, &bridge_forward); 8161da177e4SLinus Torvalds sysfs_remove_group(kobj, &bridge_group); 8171da177e4SLinus Torvalds } 818