11da177e4SLinus Torvalds /* 215401946SWang Sheng-Hui * Sysfs attributes of bridge 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 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 39cb990503SEric W. Biederman if (!ns_capable(dev_net(br->dev)->user_ns, 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 468d4698f7SStephen Hemminger err = (*set)(br, val); 478d4698f7SStephen Hemminger return err ? err : len; 481da177e4SLinus Torvalds } 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds 51fbf2671bSsfeldma@cumulusnetworks.com static ssize_t forward_delay_show(struct device *d, 5243cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 531da177e4SLinus Torvalds { 5443cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 551da177e4SLinus Torvalds return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay)); 561da177e4SLinus Torvalds } 571da177e4SLinus Torvalds 58fbf2671bSsfeldma@cumulusnetworks.com static ssize_t forward_delay_store(struct device *d, 5943cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 6043cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 611da177e4SLinus Torvalds { 6214f98f25Sstephen hemminger return store_bridge_parm(d, buf, len, br_set_forward_delay); 631da177e4SLinus Torvalds } 64fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(forward_delay); 651da177e4SLinus Torvalds 66fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hello_time_show(struct device *d, struct device_attribute *attr, 6743cb76d9SGreg Kroah-Hartman char *buf) 681da177e4SLinus Torvalds { 691da177e4SLinus Torvalds return sprintf(buf, "%lu\n", 7043cb76d9SGreg Kroah-Hartman jiffies_to_clock_t(to_bridge(d)->hello_time)); 711da177e4SLinus Torvalds } 721da177e4SLinus Torvalds 73fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hello_time_store(struct device *d, 7443cb76d9SGreg Kroah-Hartman struct device_attribute *attr, const char *buf, 751da177e4SLinus Torvalds size_t len) 761da177e4SLinus Torvalds { 7714f98f25Sstephen hemminger return store_bridge_parm(d, buf, len, br_set_hello_time); 781da177e4SLinus Torvalds } 79fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(hello_time); 801da177e4SLinus Torvalds 81fbf2671bSsfeldma@cumulusnetworks.com static ssize_t max_age_show(struct device *d, struct device_attribute *attr, 8243cb76d9SGreg Kroah-Hartman char *buf) 831da177e4SLinus Torvalds { 841da177e4SLinus Torvalds return sprintf(buf, "%lu\n", 8543cb76d9SGreg Kroah-Hartman jiffies_to_clock_t(to_bridge(d)->max_age)); 861da177e4SLinus Torvalds } 871da177e4SLinus Torvalds 88fbf2671bSsfeldma@cumulusnetworks.com static ssize_t max_age_store(struct device *d, struct device_attribute *attr, 8943cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 901da177e4SLinus Torvalds { 9114f98f25Sstephen hemminger return store_bridge_parm(d, buf, len, br_set_max_age); 921da177e4SLinus Torvalds } 93fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(max_age); 941da177e4SLinus Torvalds 95fbf2671bSsfeldma@cumulusnetworks.com static ssize_t ageing_time_show(struct device *d, 9643cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 971da177e4SLinus Torvalds { 9843cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 991da177e4SLinus Torvalds return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time)); 1001da177e4SLinus Torvalds } 1011da177e4SLinus Torvalds 1028d4698f7SStephen Hemminger static int set_ageing_time(struct net_bridge *br, unsigned long val) 1031da177e4SLinus Torvalds { 104af379392SNikolay Aleksandrov int ret; 105af379392SNikolay Aleksandrov 106af379392SNikolay Aleksandrov if (!rtnl_trylock()) 107af379392SNikolay Aleksandrov return restart_syscall(); 108af379392SNikolay Aleksandrov 109af379392SNikolay Aleksandrov ret = br_set_ageing_time(br, val); 110af379392SNikolay Aleksandrov rtnl_unlock(); 111af379392SNikolay Aleksandrov 112af379392SNikolay Aleksandrov return ret; 1131da177e4SLinus Torvalds } 1141da177e4SLinus Torvalds 115fbf2671bSsfeldma@cumulusnetworks.com static ssize_t ageing_time_store(struct device *d, 11643cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 11743cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 1181da177e4SLinus Torvalds { 11943cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_ageing_time); 1201da177e4SLinus Torvalds } 121fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(ageing_time); 12243cb76d9SGreg Kroah-Hartman 123fbf2671bSsfeldma@cumulusnetworks.com static ssize_t stp_state_show(struct device *d, 12443cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 1251da177e4SLinus Torvalds { 12643cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1271da177e4SLinus Torvalds return sprintf(buf, "%d\n", br->stp_enabled); 1281da177e4SLinus Torvalds } 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds 131fbf2671bSsfeldma@cumulusnetworks.com static ssize_t stp_state_store(struct device *d, 13243cb76d9SGreg Kroah-Hartman struct device_attribute *attr, const char *buf, 13343cb76d9SGreg Kroah-Hartman size_t len) 1341da177e4SLinus Torvalds { 13517120889SStephen Hemminger struct net_bridge *br = to_bridge(d); 13617120889SStephen Hemminger char *endp; 13717120889SStephen Hemminger unsigned long val; 13817120889SStephen Hemminger 139cb990503SEric W. Biederman if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) 14017120889SStephen Hemminger return -EPERM; 14117120889SStephen Hemminger 14217120889SStephen Hemminger val = simple_strtoul(buf, &endp, 0); 14317120889SStephen Hemminger if (endp == buf) 14417120889SStephen Hemminger return -EINVAL; 14517120889SStephen Hemminger 146af38f298SEric W. Biederman if (!rtnl_trylock()) 147af38f298SEric W. Biederman return restart_syscall(); 14817120889SStephen Hemminger br_stp_set_enabled(br, val); 14917120889SStephen Hemminger rtnl_unlock(); 15017120889SStephen Hemminger 15135b426c3SAl Viro return len; 1521da177e4SLinus Torvalds } 153fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(stp_state); 1541da177e4SLinus Torvalds 155fbf2671bSsfeldma@cumulusnetworks.com static ssize_t group_fwd_mask_show(struct device *d, 156fbf2671bSsfeldma@cumulusnetworks.com struct device_attribute *attr, 157fbf2671bSsfeldma@cumulusnetworks.com char *buf) 158515853ccSstephen hemminger { 159515853ccSstephen hemminger struct net_bridge *br = to_bridge(d); 160515853ccSstephen hemminger return sprintf(buf, "%#x\n", br->group_fwd_mask); 161515853ccSstephen hemminger } 162515853ccSstephen hemminger 163*347db6b4SXin Long static int set_group_fwd_mask(struct net_bridge *br, unsigned long val) 164*347db6b4SXin Long { 165*347db6b4SXin Long if (val & BR_GROUPFWD_RESTRICTED) 166*347db6b4SXin Long return -EINVAL; 167*347db6b4SXin Long 168*347db6b4SXin Long br->group_fwd_mask = val; 169*347db6b4SXin Long 170*347db6b4SXin Long return 0; 171*347db6b4SXin Long } 172515853ccSstephen hemminger 173fbf2671bSsfeldma@cumulusnetworks.com static ssize_t group_fwd_mask_store(struct device *d, 174fbf2671bSsfeldma@cumulusnetworks.com struct device_attribute *attr, 175fbf2671bSsfeldma@cumulusnetworks.com const char *buf, 176515853ccSstephen hemminger size_t len) 177515853ccSstephen hemminger { 178*347db6b4SXin Long return store_bridge_parm(d, buf, len, set_group_fwd_mask); 179515853ccSstephen hemminger } 180fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(group_fwd_mask); 181515853ccSstephen hemminger 182fbf2671bSsfeldma@cumulusnetworks.com static ssize_t priority_show(struct device *d, struct device_attribute *attr, 18343cb76d9SGreg Kroah-Hartman char *buf) 1841da177e4SLinus Torvalds { 18543cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1861da177e4SLinus Torvalds return sprintf(buf, "%d\n", 1871da177e4SLinus Torvalds (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]); 1881da177e4SLinus Torvalds } 1891da177e4SLinus Torvalds 1908d4698f7SStephen Hemminger static int set_priority(struct net_bridge *br, unsigned long val) 1911da177e4SLinus Torvalds { 1921da177e4SLinus Torvalds br_stp_set_bridge_priority(br, (u16) val); 1938d4698f7SStephen Hemminger return 0; 1941da177e4SLinus Torvalds } 1951da177e4SLinus Torvalds 196fbf2671bSsfeldma@cumulusnetworks.com static ssize_t priority_store(struct device *d, struct device_attribute *attr, 1971da177e4SLinus Torvalds const char *buf, size_t len) 1981da177e4SLinus Torvalds { 19943cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_priority); 2001da177e4SLinus Torvalds } 201fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(priority); 2021da177e4SLinus Torvalds 203fbf2671bSsfeldma@cumulusnetworks.com static ssize_t root_id_show(struct device *d, struct device_attribute *attr, 20443cb76d9SGreg Kroah-Hartman char *buf) 2051da177e4SLinus Torvalds { 20643cb76d9SGreg Kroah-Hartman return br_show_bridge_id(buf, &to_bridge(d)->designated_root); 2071da177e4SLinus Torvalds } 208fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(root_id); 2091da177e4SLinus Torvalds 210fbf2671bSsfeldma@cumulusnetworks.com static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr, 21143cb76d9SGreg Kroah-Hartman char *buf) 2121da177e4SLinus Torvalds { 21343cb76d9SGreg Kroah-Hartman return br_show_bridge_id(buf, &to_bridge(d)->bridge_id); 2141da177e4SLinus Torvalds } 215fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(bridge_id); 2161da177e4SLinus Torvalds 217fbf2671bSsfeldma@cumulusnetworks.com static ssize_t root_port_show(struct device *d, struct device_attribute *attr, 21843cb76d9SGreg Kroah-Hartman char *buf) 2191da177e4SLinus Torvalds { 22043cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->root_port); 2211da177e4SLinus Torvalds } 222fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(root_port); 2231da177e4SLinus Torvalds 224fbf2671bSsfeldma@cumulusnetworks.com static ssize_t root_path_cost_show(struct device *d, 22543cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2261da177e4SLinus Torvalds { 22743cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost); 2281da177e4SLinus Torvalds } 229fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(root_path_cost); 2301da177e4SLinus Torvalds 231fbf2671bSsfeldma@cumulusnetworks.com static ssize_t topology_change_show(struct device *d, 23243cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2331da177e4SLinus Torvalds { 23443cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->topology_change); 2351da177e4SLinus Torvalds } 236fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(topology_change); 2371da177e4SLinus Torvalds 238fbf2671bSsfeldma@cumulusnetworks.com static ssize_t topology_change_detected_show(struct device *d, 23943cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 24043cb76d9SGreg Kroah-Hartman char *buf) 2411da177e4SLinus Torvalds { 24243cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2431da177e4SLinus Torvalds return sprintf(buf, "%d\n", br->topology_change_detected); 2441da177e4SLinus Torvalds } 245fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(topology_change_detected); 2461da177e4SLinus Torvalds 247fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hello_timer_show(struct device *d, 24843cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2491da177e4SLinus Torvalds { 25043cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2511da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer)); 2521da177e4SLinus Torvalds } 253fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(hello_timer); 2541da177e4SLinus Torvalds 255fbf2671bSsfeldma@cumulusnetworks.com static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr, 25643cb76d9SGreg Kroah-Hartman char *buf) 2571da177e4SLinus Torvalds { 25843cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2591da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer)); 2601da177e4SLinus Torvalds } 261fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(tcn_timer); 2621da177e4SLinus Torvalds 263fbf2671bSsfeldma@cumulusnetworks.com static ssize_t topology_change_timer_show(struct device *d, 26443cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 26543cb76d9SGreg Kroah-Hartman char *buf) 2661da177e4SLinus Torvalds { 26743cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2681da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer)); 2691da177e4SLinus Torvalds } 270fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(topology_change_timer); 2711da177e4SLinus Torvalds 272fbf2671bSsfeldma@cumulusnetworks.com static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr, 27343cb76d9SGreg Kroah-Hartman char *buf) 2741da177e4SLinus Torvalds { 27543cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2761da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer)); 2771da177e4SLinus Torvalds } 278fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(gc_timer); 2791da177e4SLinus Torvalds 280fbf2671bSsfeldma@cumulusnetworks.com static ssize_t group_addr_show(struct device *d, 28143cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 282fda93d92SStephen Hemminger { 28343cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 284fda93d92SStephen Hemminger return sprintf(buf, "%x:%x:%x:%x:%x:%x\n", 285fda93d92SStephen Hemminger br->group_addr[0], br->group_addr[1], 286fda93d92SStephen Hemminger br->group_addr[2], br->group_addr[3], 287fda93d92SStephen Hemminger br->group_addr[4], br->group_addr[5]); 288fda93d92SStephen Hemminger } 289fda93d92SStephen Hemminger 290fbf2671bSsfeldma@cumulusnetworks.com static ssize_t group_addr_store(struct device *d, 29143cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 29243cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 293fda93d92SStephen Hemminger { 29443cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2954197f24bSBen Hutchings u8 new_addr[6]; 296fda93d92SStephen Hemminger int i; 297fda93d92SStephen Hemminger 298cb990503SEric W. Biederman if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) 299fda93d92SStephen Hemminger return -EPERM; 300fda93d92SStephen Hemminger 3014197f24bSBen Hutchings if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", 302fda93d92SStephen Hemminger &new_addr[0], &new_addr[1], &new_addr[2], 303fda93d92SStephen Hemminger &new_addr[3], &new_addr[4], &new_addr[5]) != 6) 304fda93d92SStephen Hemminger return -EINVAL; 305fda93d92SStephen Hemminger 30646acc460SBen Hutchings if (!is_link_local_ether_addr(new_addr)) 307fda93d92SStephen Hemminger return -EINVAL; 308fda93d92SStephen Hemminger 309f64f9e71SJoe Perches if (new_addr[5] == 1 || /* 802.3x Pause address */ 310f64f9e71SJoe Perches new_addr[5] == 2 || /* 802.3ad Slow protocols */ 311f64f9e71SJoe Perches new_addr[5] == 3) /* 802.1X PAE address */ 312fda93d92SStephen Hemminger return -EINVAL; 313fda93d92SStephen Hemminger 314204177f3SToshiaki Makita if (!rtnl_trylock()) 315204177f3SToshiaki Makita return restart_syscall(); 316204177f3SToshiaki Makita 317fda93d92SStephen Hemminger spin_lock_bh(&br->lock); 318fda93d92SStephen Hemminger for (i = 0; i < 6; i++) 319fda93d92SStephen Hemminger br->group_addr[i] = new_addr[i]; 320fda93d92SStephen Hemminger spin_unlock_bh(&br->lock); 321204177f3SToshiaki Makita 322204177f3SToshiaki Makita br->group_addr_set = true; 323204177f3SToshiaki Makita br_recalculate_fwd_mask(br); 324204177f3SToshiaki Makita 325204177f3SToshiaki Makita rtnl_unlock(); 326204177f3SToshiaki Makita 327fda93d92SStephen Hemminger return len; 328fda93d92SStephen Hemminger } 329fda93d92SStephen Hemminger 330fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(group_addr); 331fda93d92SStephen Hemminger 33214f31bb3SXin Long static int set_flush(struct net_bridge *br, unsigned long val) 33314f31bb3SXin Long { 33414f31bb3SXin Long br_fdb_flush(br); 33514f31bb3SXin Long return 0; 33614f31bb3SXin Long } 33714f31bb3SXin Long 338fbf2671bSsfeldma@cumulusnetworks.com static ssize_t flush_store(struct device *d, 3399cf63747SStephen Hemminger struct device_attribute *attr, 3409cf63747SStephen Hemminger const char *buf, size_t len) 3419cf63747SStephen Hemminger { 34214f31bb3SXin Long return store_bridge_parm(d, buf, len, set_flush); 3439cf63747SStephen Hemminger } 344fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_WO(flush); 345fda93d92SStephen Hemminger 3460909e117SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 347fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_router_show(struct device *d, 3480909e117SHerbert Xu struct device_attribute *attr, char *buf) 3490909e117SHerbert Xu { 3500909e117SHerbert Xu struct net_bridge *br = to_bridge(d); 3510909e117SHerbert Xu return sprintf(buf, "%d\n", br->multicast_router); 3520909e117SHerbert Xu } 3530909e117SHerbert Xu 354fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_router_store(struct device *d, 3550909e117SHerbert Xu struct device_attribute *attr, 3560909e117SHerbert Xu const char *buf, size_t len) 3570909e117SHerbert Xu { 3580909e117SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_router); 3590909e117SHerbert Xu } 360fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_router); 361561f1103SHerbert Xu 362fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_snooping_show(struct device *d, 363561f1103SHerbert Xu struct device_attribute *attr, 364561f1103SHerbert Xu char *buf) 365561f1103SHerbert Xu { 366561f1103SHerbert Xu struct net_bridge *br = to_bridge(d); 367561f1103SHerbert Xu return sprintf(buf, "%d\n", !br->multicast_disabled); 368561f1103SHerbert Xu } 369561f1103SHerbert Xu 370fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_snooping_store(struct device *d, 371561f1103SHerbert Xu struct device_attribute *attr, 372561f1103SHerbert Xu const char *buf, size_t len) 373561f1103SHerbert Xu { 374561f1103SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_toggle); 375561f1103SHerbert Xu } 376fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_snooping); 377b195167fSHerbert Xu 378fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_use_ifaddr_show(struct device *d, 3791c8ad5bfSCong Wang struct device_attribute *attr, 3801c8ad5bfSCong Wang char *buf) 3811c8ad5bfSCong Wang { 3821c8ad5bfSCong Wang struct net_bridge *br = to_bridge(d); 3831c8ad5bfSCong Wang return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr); 3841c8ad5bfSCong Wang } 3851c8ad5bfSCong Wang 3861c8ad5bfSCong Wang static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val) 3871c8ad5bfSCong Wang { 3881c8ad5bfSCong Wang br->multicast_query_use_ifaddr = !!val; 3891c8ad5bfSCong Wang return 0; 3901c8ad5bfSCong Wang } 3911c8ad5bfSCong Wang 3921c8ad5bfSCong Wang static ssize_t 393fbf2671bSsfeldma@cumulusnetworks.com multicast_query_use_ifaddr_store(struct device *d, 3941c8ad5bfSCong Wang struct device_attribute *attr, 3951c8ad5bfSCong Wang const char *buf, size_t len) 3961c8ad5bfSCong Wang { 3971c8ad5bfSCong Wang return store_bridge_parm(d, buf, len, set_query_use_ifaddr); 3981c8ad5bfSCong Wang } 399fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_query_use_ifaddr); 4001c8ad5bfSCong Wang 401fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_show(struct device *d, 402c5c23260SHerbert Xu struct device_attribute *attr, 403c5c23260SHerbert Xu char *buf) 404c5c23260SHerbert Xu { 405c5c23260SHerbert Xu struct net_bridge *br = to_bridge(d); 406c5c23260SHerbert Xu return sprintf(buf, "%d\n", br->multicast_querier); 407c5c23260SHerbert Xu } 408c5c23260SHerbert Xu 409fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_store(struct device *d, 410c5c23260SHerbert Xu struct device_attribute *attr, 411c5c23260SHerbert Xu const char *buf, size_t len) 412c5c23260SHerbert Xu { 413c5c23260SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_querier); 414c5c23260SHerbert Xu } 415fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_querier); 416c5c23260SHerbert Xu 417fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_elasticity_show(struct device *d, 418b195167fSHerbert Xu struct device_attribute *attr, char *buf) 419b195167fSHerbert Xu { 420b195167fSHerbert Xu struct net_bridge *br = to_bridge(d); 421b195167fSHerbert Xu return sprintf(buf, "%u\n", br->hash_elasticity); 422b195167fSHerbert Xu } 423b195167fSHerbert Xu 424b195167fSHerbert Xu static int set_elasticity(struct net_bridge *br, unsigned long val) 425b195167fSHerbert Xu { 426b195167fSHerbert Xu br->hash_elasticity = val; 427b195167fSHerbert Xu return 0; 428b195167fSHerbert Xu } 429b195167fSHerbert Xu 430fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_elasticity_store(struct device *d, 431b195167fSHerbert Xu struct device_attribute *attr, 432b195167fSHerbert Xu const char *buf, size_t len) 433b195167fSHerbert Xu { 434b195167fSHerbert Xu return store_bridge_parm(d, buf, len, set_elasticity); 435b195167fSHerbert Xu } 436fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(hash_elasticity); 437b195167fSHerbert Xu 438fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_max_show(struct device *d, struct device_attribute *attr, 439b195167fSHerbert Xu char *buf) 440b195167fSHerbert Xu { 441b195167fSHerbert Xu struct net_bridge *br = to_bridge(d); 442b195167fSHerbert Xu return sprintf(buf, "%u\n", br->hash_max); 443b195167fSHerbert Xu } 444b195167fSHerbert Xu 445fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_max_store(struct device *d, struct device_attribute *attr, 446b195167fSHerbert Xu const char *buf, size_t len) 447b195167fSHerbert Xu { 448b195167fSHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_hash_max); 449b195167fSHerbert Xu } 450fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(hash_max); 451d902eee4SHerbert Xu 452fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_count_show(struct device *d, 453d902eee4SHerbert Xu struct device_attribute *attr, 454d902eee4SHerbert Xu char *buf) 455d902eee4SHerbert Xu { 456d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 457d902eee4SHerbert Xu return sprintf(buf, "%u\n", br->multicast_last_member_count); 458d902eee4SHerbert Xu } 459d902eee4SHerbert Xu 460d902eee4SHerbert Xu static int set_last_member_count(struct net_bridge *br, unsigned long val) 461d902eee4SHerbert Xu { 462d902eee4SHerbert Xu br->multicast_last_member_count = val; 463d902eee4SHerbert Xu return 0; 464d902eee4SHerbert Xu } 465d902eee4SHerbert Xu 466fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_count_store(struct device *d, 467d902eee4SHerbert Xu struct device_attribute *attr, 468d902eee4SHerbert Xu const char *buf, size_t len) 469d902eee4SHerbert Xu { 470d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_last_member_count); 471d902eee4SHerbert Xu } 472fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_last_member_count); 473d902eee4SHerbert Xu 474fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_count_show( 475d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 476d902eee4SHerbert Xu { 477d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 478d902eee4SHerbert Xu return sprintf(buf, "%u\n", br->multicast_startup_query_count); 479d902eee4SHerbert Xu } 480d902eee4SHerbert Xu 481d902eee4SHerbert Xu static int set_startup_query_count(struct net_bridge *br, unsigned long val) 482d902eee4SHerbert Xu { 483d902eee4SHerbert Xu br->multicast_startup_query_count = val; 484d902eee4SHerbert Xu return 0; 485d902eee4SHerbert Xu } 486d902eee4SHerbert Xu 487fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_count_store( 488d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 489d902eee4SHerbert Xu size_t len) 490d902eee4SHerbert Xu { 491d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_startup_query_count); 492d902eee4SHerbert Xu } 493fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_startup_query_count); 494d902eee4SHerbert Xu 495fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_interval_show( 496d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 497d902eee4SHerbert Xu { 498d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 499d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 500d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_last_member_interval)); 501d902eee4SHerbert Xu } 502d902eee4SHerbert Xu 503d902eee4SHerbert Xu static int set_last_member_interval(struct net_bridge *br, unsigned long val) 504d902eee4SHerbert Xu { 505d902eee4SHerbert Xu br->multicast_last_member_interval = clock_t_to_jiffies(val); 506d902eee4SHerbert Xu return 0; 507d902eee4SHerbert Xu } 508d902eee4SHerbert Xu 509fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_interval_store( 510d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 511d902eee4SHerbert Xu size_t len) 512d902eee4SHerbert Xu { 513d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_last_member_interval); 514d902eee4SHerbert Xu } 515fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_last_member_interval); 516d902eee4SHerbert Xu 517fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_membership_interval_show( 518d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 519d902eee4SHerbert Xu { 520d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 521d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 522d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_membership_interval)); 523d902eee4SHerbert Xu } 524d902eee4SHerbert Xu 525d902eee4SHerbert Xu static int set_membership_interval(struct net_bridge *br, unsigned long val) 526d902eee4SHerbert Xu { 527d902eee4SHerbert Xu br->multicast_membership_interval = clock_t_to_jiffies(val); 528d902eee4SHerbert Xu return 0; 529d902eee4SHerbert Xu } 530d902eee4SHerbert Xu 531fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_membership_interval_store( 532d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 533d902eee4SHerbert Xu size_t len) 534d902eee4SHerbert Xu { 535d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_membership_interval); 536d902eee4SHerbert Xu } 537fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_membership_interval); 538d902eee4SHerbert Xu 539fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_interval_show(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_querier_interval)); 546d902eee4SHerbert Xu } 547d902eee4SHerbert Xu 548d902eee4SHerbert Xu static int set_querier_interval(struct net_bridge *br, unsigned long val) 549d902eee4SHerbert Xu { 550d902eee4SHerbert Xu br->multicast_querier_interval = clock_t_to_jiffies(val); 551d902eee4SHerbert Xu return 0; 552d902eee4SHerbert Xu } 553d902eee4SHerbert Xu 554fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_interval_store(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_querier_interval); 559d902eee4SHerbert Xu } 560fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_querier_interval); 561d902eee4SHerbert Xu 562fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_interval_show(struct device *d, 563d902eee4SHerbert Xu struct device_attribute *attr, 564d902eee4SHerbert Xu char *buf) 565d902eee4SHerbert Xu { 566d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 567d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 568d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_query_interval)); 569d902eee4SHerbert Xu } 570d902eee4SHerbert Xu 571d902eee4SHerbert Xu static int set_query_interval(struct net_bridge *br, unsigned long val) 572d902eee4SHerbert Xu { 573d902eee4SHerbert Xu br->multicast_query_interval = clock_t_to_jiffies(val); 574d902eee4SHerbert Xu return 0; 575d902eee4SHerbert Xu } 576d902eee4SHerbert Xu 577fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_interval_store(struct device *d, 578d902eee4SHerbert Xu struct device_attribute *attr, 579d902eee4SHerbert Xu const char *buf, size_t len) 580d902eee4SHerbert Xu { 581d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_query_interval); 582d902eee4SHerbert Xu } 583fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_query_interval); 584d902eee4SHerbert Xu 585fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_response_interval_show( 586d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 587d902eee4SHerbert Xu { 588d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 589d902eee4SHerbert Xu return sprintf( 590d902eee4SHerbert Xu buf, "%lu\n", 591d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_query_response_interval)); 592d902eee4SHerbert Xu } 593d902eee4SHerbert Xu 594d902eee4SHerbert Xu static int set_query_response_interval(struct net_bridge *br, unsigned long val) 595d902eee4SHerbert Xu { 596d902eee4SHerbert Xu br->multicast_query_response_interval = clock_t_to_jiffies(val); 597d902eee4SHerbert Xu return 0; 598d902eee4SHerbert Xu } 599d902eee4SHerbert Xu 600fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_response_interval_store( 601d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 602d902eee4SHerbert Xu size_t len) 603d902eee4SHerbert Xu { 604d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_query_response_interval); 605d902eee4SHerbert Xu } 606fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_query_response_interval); 607d902eee4SHerbert Xu 608fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_interval_show( 609d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 610d902eee4SHerbert Xu { 611d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 612d902eee4SHerbert Xu return sprintf( 613d902eee4SHerbert Xu buf, "%lu\n", 614d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_startup_query_interval)); 615d902eee4SHerbert Xu } 616d902eee4SHerbert Xu 617d902eee4SHerbert Xu static int set_startup_query_interval(struct net_bridge *br, unsigned long val) 618d902eee4SHerbert Xu { 619d902eee4SHerbert Xu br->multicast_startup_query_interval = clock_t_to_jiffies(val); 620d902eee4SHerbert Xu return 0; 621d902eee4SHerbert Xu } 622d902eee4SHerbert Xu 623fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_interval_store( 624d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 625d902eee4SHerbert Xu size_t len) 626d902eee4SHerbert Xu { 627d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_startup_query_interval); 628d902eee4SHerbert Xu } 629fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_startup_query_interval); 6300909e117SHerbert Xu #endif 63134666d46SPablo Neira Ayuso #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 632fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_iptables_show( 6334df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 6344df53d8bSPatrick McHardy { 6354df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 6364df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_iptables); 6374df53d8bSPatrick McHardy } 6384df53d8bSPatrick McHardy 6394df53d8bSPatrick McHardy static int set_nf_call_iptables(struct net_bridge *br, unsigned long val) 6404df53d8bSPatrick McHardy { 6414df53d8bSPatrick McHardy br->nf_call_iptables = val ? true : false; 6424df53d8bSPatrick McHardy return 0; 6434df53d8bSPatrick McHardy } 6444df53d8bSPatrick McHardy 645fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_iptables_store( 6464df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 6474df53d8bSPatrick McHardy size_t len) 6484df53d8bSPatrick McHardy { 6494df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_iptables); 6504df53d8bSPatrick McHardy } 651fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(nf_call_iptables); 6524df53d8bSPatrick McHardy 653fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_ip6tables_show( 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_ip6tables); 6584df53d8bSPatrick McHardy } 6594df53d8bSPatrick McHardy 6604df53d8bSPatrick McHardy static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val) 6614df53d8bSPatrick McHardy { 6624df53d8bSPatrick McHardy br->nf_call_ip6tables = val ? true : false; 6634df53d8bSPatrick McHardy return 0; 6644df53d8bSPatrick McHardy } 6654df53d8bSPatrick McHardy 666fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_ip6tables_store( 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_ip6tables); 6714df53d8bSPatrick McHardy } 672fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(nf_call_ip6tables); 6734df53d8bSPatrick McHardy 674fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_arptables_show( 6754df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 6764df53d8bSPatrick McHardy { 6774df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 6784df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_arptables); 6794df53d8bSPatrick McHardy } 6804df53d8bSPatrick McHardy 6814df53d8bSPatrick McHardy static int set_nf_call_arptables(struct net_bridge *br, unsigned long val) 6824df53d8bSPatrick McHardy { 6834df53d8bSPatrick McHardy br->nf_call_arptables = val ? true : false; 6844df53d8bSPatrick McHardy return 0; 6854df53d8bSPatrick McHardy } 6864df53d8bSPatrick McHardy 687fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_arptables_store( 6884df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 6894df53d8bSPatrick McHardy size_t len) 6904df53d8bSPatrick McHardy { 6914df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_arptables); 6924df53d8bSPatrick McHardy } 693fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(nf_call_arptables); 6944df53d8bSPatrick McHardy #endif 695243a2e63SVlad Yasevich #ifdef CONFIG_BRIDGE_VLAN_FILTERING 696fbf2671bSsfeldma@cumulusnetworks.com static ssize_t vlan_filtering_show(struct device *d, 697243a2e63SVlad Yasevich struct device_attribute *attr, 698243a2e63SVlad Yasevich char *buf) 699243a2e63SVlad Yasevich { 700243a2e63SVlad Yasevich struct net_bridge *br = to_bridge(d); 701243a2e63SVlad Yasevich return sprintf(buf, "%d\n", br->vlan_enabled); 702243a2e63SVlad Yasevich } 703243a2e63SVlad Yasevich 704fbf2671bSsfeldma@cumulusnetworks.com static ssize_t vlan_filtering_store(struct device *d, 705243a2e63SVlad Yasevich struct device_attribute *attr, 706243a2e63SVlad Yasevich const char *buf, size_t len) 707243a2e63SVlad Yasevich { 708243a2e63SVlad Yasevich return store_bridge_parm(d, buf, len, br_vlan_filter_toggle); 709243a2e63SVlad Yasevich } 710fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(vlan_filtering); 711204177f3SToshiaki Makita 712204177f3SToshiaki Makita static ssize_t vlan_protocol_show(struct device *d, 713204177f3SToshiaki Makita struct device_attribute *attr, 714204177f3SToshiaki Makita char *buf) 715204177f3SToshiaki Makita { 716204177f3SToshiaki Makita struct net_bridge *br = to_bridge(d); 717204177f3SToshiaki Makita return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto)); 718204177f3SToshiaki Makita } 719204177f3SToshiaki Makita 720204177f3SToshiaki Makita static ssize_t vlan_protocol_store(struct device *d, 721204177f3SToshiaki Makita struct device_attribute *attr, 722204177f3SToshiaki Makita const char *buf, size_t len) 723204177f3SToshiaki Makita { 724204177f3SToshiaki Makita return store_bridge_parm(d, buf, len, br_vlan_set_proto); 725204177f3SToshiaki Makita } 726204177f3SToshiaki Makita static DEVICE_ATTR_RW(vlan_protocol); 72796a20d9dSVlad Yasevich 72896a20d9dSVlad Yasevich static ssize_t default_pvid_show(struct device *d, 72996a20d9dSVlad Yasevich struct device_attribute *attr, 73096a20d9dSVlad Yasevich char *buf) 73196a20d9dSVlad Yasevich { 73296a20d9dSVlad Yasevich struct net_bridge *br = to_bridge(d); 73396a20d9dSVlad Yasevich return sprintf(buf, "%d\n", br->default_pvid); 73496a20d9dSVlad Yasevich } 73596a20d9dSVlad Yasevich 73696a20d9dSVlad Yasevich static ssize_t default_pvid_store(struct device *d, 73796a20d9dSVlad Yasevich struct device_attribute *attr, 73896a20d9dSVlad Yasevich const char *buf, size_t len) 73996a20d9dSVlad Yasevich { 74096a20d9dSVlad Yasevich return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid); 74196a20d9dSVlad Yasevich } 74296a20d9dSVlad Yasevich static DEVICE_ATTR_RW(default_pvid); 743243a2e63SVlad Yasevich #endif 7440909e117SHerbert Xu 7451da177e4SLinus Torvalds static struct attribute *bridge_attrs[] = { 74643cb76d9SGreg Kroah-Hartman &dev_attr_forward_delay.attr, 74743cb76d9SGreg Kroah-Hartman &dev_attr_hello_time.attr, 74843cb76d9SGreg Kroah-Hartman &dev_attr_max_age.attr, 74943cb76d9SGreg Kroah-Hartman &dev_attr_ageing_time.attr, 75043cb76d9SGreg Kroah-Hartman &dev_attr_stp_state.attr, 751515853ccSstephen hemminger &dev_attr_group_fwd_mask.attr, 75243cb76d9SGreg Kroah-Hartman &dev_attr_priority.attr, 75343cb76d9SGreg Kroah-Hartman &dev_attr_bridge_id.attr, 75443cb76d9SGreg Kroah-Hartman &dev_attr_root_id.attr, 75543cb76d9SGreg Kroah-Hartman &dev_attr_root_path_cost.attr, 75643cb76d9SGreg Kroah-Hartman &dev_attr_root_port.attr, 75743cb76d9SGreg Kroah-Hartman &dev_attr_topology_change.attr, 75843cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_detected.attr, 75943cb76d9SGreg Kroah-Hartman &dev_attr_hello_timer.attr, 76043cb76d9SGreg Kroah-Hartman &dev_attr_tcn_timer.attr, 76143cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_timer.attr, 76243cb76d9SGreg Kroah-Hartman &dev_attr_gc_timer.attr, 76343cb76d9SGreg Kroah-Hartman &dev_attr_group_addr.attr, 7649cf63747SStephen Hemminger &dev_attr_flush.attr, 7650909e117SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 7660909e117SHerbert Xu &dev_attr_multicast_router.attr, 767561f1103SHerbert Xu &dev_attr_multicast_snooping.attr, 768c5c23260SHerbert Xu &dev_attr_multicast_querier.attr, 7691c8ad5bfSCong Wang &dev_attr_multicast_query_use_ifaddr.attr, 770b195167fSHerbert Xu &dev_attr_hash_elasticity.attr, 771b195167fSHerbert Xu &dev_attr_hash_max.attr, 772d902eee4SHerbert Xu &dev_attr_multicast_last_member_count.attr, 773d902eee4SHerbert Xu &dev_attr_multicast_startup_query_count.attr, 774d902eee4SHerbert Xu &dev_attr_multicast_last_member_interval.attr, 775d902eee4SHerbert Xu &dev_attr_multicast_membership_interval.attr, 776d902eee4SHerbert Xu &dev_attr_multicast_querier_interval.attr, 777d902eee4SHerbert Xu &dev_attr_multicast_query_interval.attr, 778d902eee4SHerbert Xu &dev_attr_multicast_query_response_interval.attr, 779d902eee4SHerbert Xu &dev_attr_multicast_startup_query_interval.attr, 7800909e117SHerbert Xu #endif 78134666d46SPablo Neira Ayuso #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 7824df53d8bSPatrick McHardy &dev_attr_nf_call_iptables.attr, 7834df53d8bSPatrick McHardy &dev_attr_nf_call_ip6tables.attr, 7844df53d8bSPatrick McHardy &dev_attr_nf_call_arptables.attr, 7854df53d8bSPatrick McHardy #endif 786243a2e63SVlad Yasevich #ifdef CONFIG_BRIDGE_VLAN_FILTERING 787243a2e63SVlad Yasevich &dev_attr_vlan_filtering.attr, 788204177f3SToshiaki Makita &dev_attr_vlan_protocol.attr, 78996a20d9dSVlad Yasevich &dev_attr_default_pvid.attr, 790243a2e63SVlad Yasevich #endif 7911da177e4SLinus Torvalds NULL 7921da177e4SLinus Torvalds }; 7931da177e4SLinus Torvalds 7941da177e4SLinus Torvalds static struct attribute_group bridge_group = { 7951da177e4SLinus Torvalds .name = SYSFS_BRIDGE_ATTR, 7961da177e4SLinus Torvalds .attrs = bridge_attrs, 7971da177e4SLinus Torvalds }; 7981da177e4SLinus Torvalds 7991da177e4SLinus Torvalds /* 8001da177e4SLinus Torvalds * Export the forwarding information table as a binary file 8011da177e4SLinus Torvalds * The records are struct __fdb_entry. 8021da177e4SLinus Torvalds * 8031da177e4SLinus Torvalds * Returns the number of bytes read. 8041da177e4SLinus Torvalds */ 8052c3c8beaSChris Wright static ssize_t brforward_read(struct file *filp, struct kobject *kobj, 80691a69029SZhang Rui struct bin_attribute *bin_attr, 80791a69029SZhang Rui char *buf, loff_t off, size_t count) 8081da177e4SLinus Torvalds { 809aeb7ed14SGeliang Tang struct device *dev = kobj_to_dev(kobj); 81043cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(dev); 8111da177e4SLinus Torvalds int n; 8121da177e4SLinus Torvalds 8131da177e4SLinus Torvalds /* must read whole records */ 8141da177e4SLinus Torvalds if (off % sizeof(struct __fdb_entry) != 0) 8151da177e4SLinus Torvalds return -EINVAL; 8161da177e4SLinus Torvalds 8171da177e4SLinus Torvalds n = br_fdb_fillbuf(br, buf, 8181da177e4SLinus Torvalds count / sizeof(struct __fdb_entry), 8191da177e4SLinus Torvalds off / sizeof(struct __fdb_entry)); 8201da177e4SLinus Torvalds 8211da177e4SLinus Torvalds if (n > 0) 8221da177e4SLinus Torvalds n *= sizeof(struct __fdb_entry); 8231da177e4SLinus Torvalds 8241da177e4SLinus Torvalds return n; 8251da177e4SLinus Torvalds } 8261da177e4SLinus Torvalds 8271da177e4SLinus Torvalds static struct bin_attribute bridge_forward = { 8281da177e4SLinus Torvalds .attr = { .name = SYSFS_BRIDGE_FDB, 8297b595756STejun Heo .mode = S_IRUGO, }, 8301da177e4SLinus Torvalds .read = brforward_read, 8311da177e4SLinus Torvalds }; 8321da177e4SLinus Torvalds 8331da177e4SLinus Torvalds /* 8341da177e4SLinus Torvalds * Add entries in sysfs onto the existing network class device 8351da177e4SLinus Torvalds * for the bridge. 8361da177e4SLinus Torvalds * Adds a attribute group "bridge" containing tuning parameters. 8371da177e4SLinus Torvalds * Binary attribute containing the forward table 8381da177e4SLinus Torvalds * Sub directory to hold links to interfaces. 8391da177e4SLinus Torvalds * 8401da177e4SLinus Torvalds * Note: the ifobj exists only to be a subdirectory 8411da177e4SLinus Torvalds * to hold links. The ifobj exists in same data structure 8421da177e4SLinus Torvalds * as it's parent the bridge so reference counting works. 8431da177e4SLinus Torvalds */ 8441da177e4SLinus Torvalds int br_sysfs_addbr(struct net_device *dev) 8451da177e4SLinus Torvalds { 84643cb76d9SGreg Kroah-Hartman struct kobject *brobj = &dev->dev.kobj; 8471da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 8481da177e4SLinus Torvalds int err; 8491da177e4SLinus Torvalds 8501da177e4SLinus Torvalds err = sysfs_create_group(brobj, &bridge_group); 8511da177e4SLinus Torvalds if (err) { 8521da177e4SLinus Torvalds pr_info("%s: can't create group %s/%s\n", 8530dc47877SHarvey Harrison __func__, dev->name, bridge_group.name); 8541da177e4SLinus Torvalds goto out1; 8551da177e4SLinus Torvalds } 8561da177e4SLinus Torvalds 8571da177e4SLinus Torvalds err = sysfs_create_bin_file(brobj, &bridge_forward); 8581da177e4SLinus Torvalds if (err) { 8591842c4beSRandy Dunlap pr_info("%s: can't create attribute file %s/%s\n", 8600dc47877SHarvey Harrison __func__, dev->name, bridge_forward.attr.name); 8611da177e4SLinus Torvalds goto out2; 8621da177e4SLinus Torvalds } 8631da177e4SLinus Torvalds 86443b98c4aSGreg Kroah-Hartman br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj); 86543b98c4aSGreg Kroah-Hartman if (!br->ifobj) { 8661da177e4SLinus Torvalds pr_info("%s: can't add kobject (directory) %s/%s\n", 8670dc47877SHarvey Harrison __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR); 8681da177e4SLinus Torvalds goto out3; 8691da177e4SLinus Torvalds } 8701da177e4SLinus Torvalds return 0; 8711da177e4SLinus Torvalds out3: 87243cb76d9SGreg Kroah-Hartman sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward); 8731da177e4SLinus Torvalds out2: 87443cb76d9SGreg Kroah-Hartman sysfs_remove_group(&dev->dev.kobj, &bridge_group); 8751da177e4SLinus Torvalds out1: 8761da177e4SLinus Torvalds return err; 8771da177e4SLinus Torvalds 8781da177e4SLinus Torvalds } 8791da177e4SLinus Torvalds 8801da177e4SLinus Torvalds void br_sysfs_delbr(struct net_device *dev) 8811da177e4SLinus Torvalds { 88243cb76d9SGreg Kroah-Hartman struct kobject *kobj = &dev->dev.kobj; 8831da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 8841da177e4SLinus Torvalds 88578a2d906SGreg Kroah-Hartman kobject_put(br->ifobj); 8861da177e4SLinus Torvalds sysfs_remove_bin_file(kobj, &bridge_forward); 8871da177e4SLinus Torvalds sysfs_remove_group(kobj, &bridge_group); 8881da177e4SLinus Torvalds } 889