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> 22174cd4b1SIngo Molnar #include <linux/sched/signal.h> 231da177e4SLinus Torvalds 241da177e4SLinus Torvalds #include "br_private.h" 251da177e4SLinus Torvalds 26524ad0a7SWang Chen #define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd))) 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds /* 291da177e4SLinus Torvalds * Common code for storing bridge parameters. 301da177e4SLinus Torvalds */ 3143cb76d9SGreg Kroah-Hartman static ssize_t store_bridge_parm(struct device *d, 321da177e4SLinus Torvalds const char *buf, size_t len, 338d4698f7SStephen Hemminger int (*set)(struct net_bridge *, unsigned long)) 341da177e4SLinus Torvalds { 3543cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 361da177e4SLinus Torvalds char *endp; 371da177e4SLinus Torvalds unsigned long val; 388d4698f7SStephen Hemminger int err; 391da177e4SLinus Torvalds 40cb990503SEric W. Biederman if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) 411da177e4SLinus Torvalds return -EPERM; 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds val = simple_strtoul(buf, &endp, 0); 441da177e4SLinus Torvalds if (endp == buf) 451da177e4SLinus Torvalds return -EINVAL; 461da177e4SLinus Torvalds 47047831a9SXin Long if (!rtnl_trylock()) 48047831a9SXin Long return restart_syscall(); 49047831a9SXin Long 508d4698f7SStephen Hemminger err = (*set)(br, val); 51047831a9SXin Long if (!err) 52047831a9SXin Long netdev_state_change(br->dev); 53047831a9SXin Long rtnl_unlock(); 54047831a9SXin Long 558d4698f7SStephen Hemminger return err ? err : len; 561da177e4SLinus Torvalds } 571da177e4SLinus Torvalds 581da177e4SLinus Torvalds 59fbf2671bSsfeldma@cumulusnetworks.com static ssize_t forward_delay_show(struct device *d, 6043cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 611da177e4SLinus Torvalds { 6243cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 631da177e4SLinus Torvalds return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay)); 641da177e4SLinus Torvalds } 651da177e4SLinus Torvalds 66fbf2671bSsfeldma@cumulusnetworks.com static ssize_t forward_delay_store(struct device *d, 6743cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 6843cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 691da177e4SLinus Torvalds { 7014f98f25Sstephen hemminger return store_bridge_parm(d, buf, len, br_set_forward_delay); 711da177e4SLinus Torvalds } 72fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(forward_delay); 731da177e4SLinus Torvalds 74fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hello_time_show(struct device *d, struct device_attribute *attr, 7543cb76d9SGreg Kroah-Hartman char *buf) 761da177e4SLinus Torvalds { 771da177e4SLinus Torvalds return sprintf(buf, "%lu\n", 7843cb76d9SGreg Kroah-Hartman jiffies_to_clock_t(to_bridge(d)->hello_time)); 791da177e4SLinus Torvalds } 801da177e4SLinus Torvalds 81fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hello_time_store(struct device *d, 8243cb76d9SGreg Kroah-Hartman struct device_attribute *attr, const char *buf, 831da177e4SLinus Torvalds size_t len) 841da177e4SLinus Torvalds { 8514f98f25Sstephen hemminger return store_bridge_parm(d, buf, len, br_set_hello_time); 861da177e4SLinus Torvalds } 87fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(hello_time); 881da177e4SLinus Torvalds 89fbf2671bSsfeldma@cumulusnetworks.com static ssize_t max_age_show(struct device *d, struct device_attribute *attr, 9043cb76d9SGreg Kroah-Hartman char *buf) 911da177e4SLinus Torvalds { 921da177e4SLinus Torvalds return sprintf(buf, "%lu\n", 9343cb76d9SGreg Kroah-Hartman jiffies_to_clock_t(to_bridge(d)->max_age)); 941da177e4SLinus Torvalds } 951da177e4SLinus Torvalds 96fbf2671bSsfeldma@cumulusnetworks.com static ssize_t max_age_store(struct device *d, struct device_attribute *attr, 9743cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 981da177e4SLinus Torvalds { 9914f98f25Sstephen hemminger return store_bridge_parm(d, buf, len, br_set_max_age); 1001da177e4SLinus Torvalds } 101fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(max_age); 1021da177e4SLinus Torvalds 103fbf2671bSsfeldma@cumulusnetworks.com static ssize_t ageing_time_show(struct device *d, 10443cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 1051da177e4SLinus Torvalds { 10643cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1071da177e4SLinus Torvalds return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time)); 1081da177e4SLinus Torvalds } 1091da177e4SLinus Torvalds 1108d4698f7SStephen Hemminger static int set_ageing_time(struct net_bridge *br, unsigned long val) 1111da177e4SLinus Torvalds { 112047831a9SXin Long return br_set_ageing_time(br, val); 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 1314436156bSXin Long static int set_stp_state(struct net_bridge *br, unsigned long val) 1321da177e4SLinus Torvalds { 13317120889SStephen Hemminger br_stp_set_enabled(br, val); 13417120889SStephen Hemminger 1354436156bSXin Long return 0; 1364436156bSXin Long } 1374436156bSXin Long 1384436156bSXin Long static ssize_t stp_state_store(struct device *d, 1394436156bSXin Long struct device_attribute *attr, const char *buf, 1404436156bSXin Long size_t len) 1414436156bSXin Long { 1424436156bSXin Long return store_bridge_parm(d, buf, len, set_stp_state); 1431da177e4SLinus Torvalds } 144fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(stp_state); 1451da177e4SLinus Torvalds 146fbf2671bSsfeldma@cumulusnetworks.com static ssize_t group_fwd_mask_show(struct device *d, 147fbf2671bSsfeldma@cumulusnetworks.com struct device_attribute *attr, 148fbf2671bSsfeldma@cumulusnetworks.com char *buf) 149515853ccSstephen hemminger { 150515853ccSstephen hemminger struct net_bridge *br = to_bridge(d); 151515853ccSstephen hemminger return sprintf(buf, "%#x\n", br->group_fwd_mask); 152515853ccSstephen hemminger } 153515853ccSstephen hemminger 154347db6b4SXin Long static int set_group_fwd_mask(struct net_bridge *br, unsigned long val) 155347db6b4SXin Long { 156347db6b4SXin Long if (val & BR_GROUPFWD_RESTRICTED) 157347db6b4SXin Long return -EINVAL; 158347db6b4SXin Long 159347db6b4SXin Long br->group_fwd_mask = val; 160347db6b4SXin Long 161347db6b4SXin Long return 0; 162347db6b4SXin Long } 163515853ccSstephen hemminger 164fbf2671bSsfeldma@cumulusnetworks.com static ssize_t group_fwd_mask_store(struct device *d, 165fbf2671bSsfeldma@cumulusnetworks.com struct device_attribute *attr, 166fbf2671bSsfeldma@cumulusnetworks.com const char *buf, 167515853ccSstephen hemminger size_t len) 168515853ccSstephen hemminger { 169347db6b4SXin Long return store_bridge_parm(d, buf, len, set_group_fwd_mask); 170515853ccSstephen hemminger } 171fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(group_fwd_mask); 172515853ccSstephen hemminger 173fbf2671bSsfeldma@cumulusnetworks.com static ssize_t priority_show(struct device *d, struct device_attribute *attr, 17443cb76d9SGreg Kroah-Hartman char *buf) 1751da177e4SLinus Torvalds { 17643cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1771da177e4SLinus Torvalds return sprintf(buf, "%d\n", 1781da177e4SLinus Torvalds (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]); 1791da177e4SLinus Torvalds } 1801da177e4SLinus Torvalds 1818d4698f7SStephen Hemminger static int set_priority(struct net_bridge *br, unsigned long val) 1821da177e4SLinus Torvalds { 1831da177e4SLinus Torvalds br_stp_set_bridge_priority(br, (u16) val); 1848d4698f7SStephen Hemminger return 0; 1851da177e4SLinus Torvalds } 1861da177e4SLinus Torvalds 187fbf2671bSsfeldma@cumulusnetworks.com static ssize_t priority_store(struct device *d, struct device_attribute *attr, 1881da177e4SLinus Torvalds const char *buf, size_t len) 1891da177e4SLinus Torvalds { 19043cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_priority); 1911da177e4SLinus Torvalds } 192fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(priority); 1931da177e4SLinus Torvalds 194fbf2671bSsfeldma@cumulusnetworks.com static ssize_t root_id_show(struct device *d, struct device_attribute *attr, 19543cb76d9SGreg Kroah-Hartman char *buf) 1961da177e4SLinus Torvalds { 19743cb76d9SGreg Kroah-Hartman return br_show_bridge_id(buf, &to_bridge(d)->designated_root); 1981da177e4SLinus Torvalds } 199fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(root_id); 2001da177e4SLinus Torvalds 201fbf2671bSsfeldma@cumulusnetworks.com static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr, 20243cb76d9SGreg Kroah-Hartman char *buf) 2031da177e4SLinus Torvalds { 20443cb76d9SGreg Kroah-Hartman return br_show_bridge_id(buf, &to_bridge(d)->bridge_id); 2051da177e4SLinus Torvalds } 206fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(bridge_id); 2071da177e4SLinus Torvalds 208fbf2671bSsfeldma@cumulusnetworks.com static ssize_t root_port_show(struct device *d, struct device_attribute *attr, 20943cb76d9SGreg Kroah-Hartman char *buf) 2101da177e4SLinus Torvalds { 21143cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->root_port); 2121da177e4SLinus Torvalds } 213fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(root_port); 2141da177e4SLinus Torvalds 215fbf2671bSsfeldma@cumulusnetworks.com static ssize_t root_path_cost_show(struct device *d, 21643cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2171da177e4SLinus Torvalds { 21843cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost); 2191da177e4SLinus Torvalds } 220fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(root_path_cost); 2211da177e4SLinus Torvalds 222fbf2671bSsfeldma@cumulusnetworks.com static ssize_t topology_change_show(struct device *d, 22343cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2241da177e4SLinus Torvalds { 22543cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->topology_change); 2261da177e4SLinus Torvalds } 227fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(topology_change); 2281da177e4SLinus Torvalds 229fbf2671bSsfeldma@cumulusnetworks.com static ssize_t topology_change_detected_show(struct device *d, 23043cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 23143cb76d9SGreg Kroah-Hartman char *buf) 2321da177e4SLinus Torvalds { 23343cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2341da177e4SLinus Torvalds return sprintf(buf, "%d\n", br->topology_change_detected); 2351da177e4SLinus Torvalds } 236fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(topology_change_detected); 2371da177e4SLinus Torvalds 238fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hello_timer_show(struct device *d, 23943cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2401da177e4SLinus Torvalds { 24143cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2421da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer)); 2431da177e4SLinus Torvalds } 244fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(hello_timer); 2451da177e4SLinus Torvalds 246fbf2671bSsfeldma@cumulusnetworks.com static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr, 24743cb76d9SGreg Kroah-Hartman char *buf) 2481da177e4SLinus Torvalds { 24943cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2501da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer)); 2511da177e4SLinus Torvalds } 252fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(tcn_timer); 2531da177e4SLinus Torvalds 254fbf2671bSsfeldma@cumulusnetworks.com static ssize_t topology_change_timer_show(struct device *d, 25543cb76d9SGreg Kroah-Hartman 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->topology_change_timer)); 2601da177e4SLinus Torvalds } 261fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(topology_change_timer); 2621da177e4SLinus Torvalds 263fbf2671bSsfeldma@cumulusnetworks.com static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr, 26443cb76d9SGreg Kroah-Hartman char *buf) 2651da177e4SLinus Torvalds { 26643cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 267f7cdee8aSNikolay Aleksandrov return sprintf(buf, "%ld\n", br_timer_value(&br->gc_work.timer)); 2681da177e4SLinus Torvalds } 269fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(gc_timer); 2701da177e4SLinus Torvalds 271fbf2671bSsfeldma@cumulusnetworks.com static ssize_t group_addr_show(struct device *d, 27243cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 273fda93d92SStephen Hemminger { 27443cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 275*223b229bSAndy Shevchenko return sprintf(buf, "%pM\n", br->group_addr); 276fda93d92SStephen Hemminger } 277fda93d92SStephen Hemminger 278fbf2671bSsfeldma@cumulusnetworks.com static ssize_t group_addr_store(struct device *d, 27943cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 28043cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 281fda93d92SStephen Hemminger { 28243cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2834197f24bSBen Hutchings u8 new_addr[6]; 284fda93d92SStephen Hemminger 285cb990503SEric W. Biederman if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) 286fda93d92SStephen Hemminger return -EPERM; 287fda93d92SStephen Hemminger 288*223b229bSAndy Shevchenko if (!mac_pton(buf, new_addr)) 289fda93d92SStephen Hemminger return -EINVAL; 290fda93d92SStephen Hemminger 29146acc460SBen Hutchings if (!is_link_local_ether_addr(new_addr)) 292fda93d92SStephen Hemminger return -EINVAL; 293fda93d92SStephen Hemminger 294f64f9e71SJoe Perches if (new_addr[5] == 1 || /* 802.3x Pause address */ 295f64f9e71SJoe Perches new_addr[5] == 2 || /* 802.3ad Slow protocols */ 296f64f9e71SJoe Perches new_addr[5] == 3) /* 802.1X PAE address */ 297fda93d92SStephen Hemminger return -EINVAL; 298fda93d92SStephen Hemminger 299204177f3SToshiaki Makita if (!rtnl_trylock()) 300204177f3SToshiaki Makita return restart_syscall(); 301204177f3SToshiaki Makita 302fda93d92SStephen Hemminger spin_lock_bh(&br->lock); 303*223b229bSAndy Shevchenko ether_addr_copy(br->group_addr, new_addr); 304fda93d92SStephen Hemminger spin_unlock_bh(&br->lock); 305204177f3SToshiaki Makita 306204177f3SToshiaki Makita br->group_addr_set = true; 307204177f3SToshiaki Makita br_recalculate_fwd_mask(br); 308047831a9SXin Long netdev_state_change(br->dev); 309204177f3SToshiaki Makita 310204177f3SToshiaki Makita rtnl_unlock(); 311204177f3SToshiaki Makita 312fda93d92SStephen Hemminger return len; 313fda93d92SStephen Hemminger } 314fda93d92SStephen Hemminger 315fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(group_addr); 316fda93d92SStephen Hemminger 31714f31bb3SXin Long static int set_flush(struct net_bridge *br, unsigned long val) 31814f31bb3SXin Long { 31914f31bb3SXin Long br_fdb_flush(br); 32014f31bb3SXin Long return 0; 32114f31bb3SXin Long } 32214f31bb3SXin Long 323fbf2671bSsfeldma@cumulusnetworks.com static ssize_t flush_store(struct device *d, 3249cf63747SStephen Hemminger struct device_attribute *attr, 3259cf63747SStephen Hemminger const char *buf, size_t len) 3269cf63747SStephen Hemminger { 32714f31bb3SXin Long return store_bridge_parm(d, buf, len, set_flush); 3289cf63747SStephen Hemminger } 329fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_WO(flush); 330fda93d92SStephen Hemminger 3310909e117SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 332fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_router_show(struct device *d, 3330909e117SHerbert Xu struct device_attribute *attr, char *buf) 3340909e117SHerbert Xu { 3350909e117SHerbert Xu struct net_bridge *br = to_bridge(d); 3360909e117SHerbert Xu return sprintf(buf, "%d\n", br->multicast_router); 3370909e117SHerbert Xu } 3380909e117SHerbert Xu 339fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_router_store(struct device *d, 3400909e117SHerbert Xu struct device_attribute *attr, 3410909e117SHerbert Xu const char *buf, size_t len) 3420909e117SHerbert Xu { 3430909e117SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_router); 3440909e117SHerbert Xu } 345fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_router); 346561f1103SHerbert Xu 347fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_snooping_show(struct device *d, 348561f1103SHerbert Xu struct device_attribute *attr, 349561f1103SHerbert Xu char *buf) 350561f1103SHerbert Xu { 351561f1103SHerbert Xu struct net_bridge *br = to_bridge(d); 352561f1103SHerbert Xu return sprintf(buf, "%d\n", !br->multicast_disabled); 353561f1103SHerbert Xu } 354561f1103SHerbert Xu 355fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_snooping_store(struct device *d, 356561f1103SHerbert Xu struct device_attribute *attr, 357561f1103SHerbert Xu const char *buf, size_t len) 358561f1103SHerbert Xu { 359561f1103SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_toggle); 360561f1103SHerbert Xu } 361fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_snooping); 362b195167fSHerbert Xu 363fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_use_ifaddr_show(struct device *d, 3641c8ad5bfSCong Wang struct device_attribute *attr, 3651c8ad5bfSCong Wang char *buf) 3661c8ad5bfSCong Wang { 3671c8ad5bfSCong Wang struct net_bridge *br = to_bridge(d); 3681c8ad5bfSCong Wang return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr); 3691c8ad5bfSCong Wang } 3701c8ad5bfSCong Wang 3711c8ad5bfSCong Wang static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val) 3721c8ad5bfSCong Wang { 3731c8ad5bfSCong Wang br->multicast_query_use_ifaddr = !!val; 3741c8ad5bfSCong Wang return 0; 3751c8ad5bfSCong Wang } 3761c8ad5bfSCong Wang 3771c8ad5bfSCong Wang static ssize_t 378fbf2671bSsfeldma@cumulusnetworks.com multicast_query_use_ifaddr_store(struct device *d, 3791c8ad5bfSCong Wang struct device_attribute *attr, 3801c8ad5bfSCong Wang const char *buf, size_t len) 3811c8ad5bfSCong Wang { 3821c8ad5bfSCong Wang return store_bridge_parm(d, buf, len, set_query_use_ifaddr); 3831c8ad5bfSCong Wang } 384fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_query_use_ifaddr); 3851c8ad5bfSCong Wang 386fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_show(struct device *d, 387c5c23260SHerbert Xu struct device_attribute *attr, 388c5c23260SHerbert Xu char *buf) 389c5c23260SHerbert Xu { 390c5c23260SHerbert Xu struct net_bridge *br = to_bridge(d); 391c5c23260SHerbert Xu return sprintf(buf, "%d\n", br->multicast_querier); 392c5c23260SHerbert Xu } 393c5c23260SHerbert Xu 394fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_store(struct device *d, 395c5c23260SHerbert Xu struct device_attribute *attr, 396c5c23260SHerbert Xu const char *buf, size_t len) 397c5c23260SHerbert Xu { 398c5c23260SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_querier); 399c5c23260SHerbert Xu } 400fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_querier); 401c5c23260SHerbert Xu 402fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_elasticity_show(struct device *d, 403b195167fSHerbert Xu struct device_attribute *attr, char *buf) 404b195167fSHerbert Xu { 405b195167fSHerbert Xu struct net_bridge *br = to_bridge(d); 406b195167fSHerbert Xu return sprintf(buf, "%u\n", br->hash_elasticity); 407b195167fSHerbert Xu } 408b195167fSHerbert Xu 409b195167fSHerbert Xu static int set_elasticity(struct net_bridge *br, unsigned long val) 410b195167fSHerbert Xu { 411b195167fSHerbert Xu br->hash_elasticity = val; 412b195167fSHerbert Xu return 0; 413b195167fSHerbert Xu } 414b195167fSHerbert Xu 415fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_elasticity_store(struct device *d, 416b195167fSHerbert Xu struct device_attribute *attr, 417b195167fSHerbert Xu const char *buf, size_t len) 418b195167fSHerbert Xu { 419b195167fSHerbert Xu return store_bridge_parm(d, buf, len, set_elasticity); 420b195167fSHerbert Xu } 421fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(hash_elasticity); 422b195167fSHerbert Xu 423fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_max_show(struct device *d, struct device_attribute *attr, 424b195167fSHerbert Xu char *buf) 425b195167fSHerbert Xu { 426b195167fSHerbert Xu struct net_bridge *br = to_bridge(d); 427b195167fSHerbert Xu return sprintf(buf, "%u\n", br->hash_max); 428b195167fSHerbert Xu } 429b195167fSHerbert Xu 430fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_max_store(struct device *d, struct device_attribute *attr, 431b195167fSHerbert Xu const char *buf, size_t len) 432b195167fSHerbert Xu { 433b195167fSHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_hash_max); 434b195167fSHerbert Xu } 435fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(hash_max); 436d902eee4SHerbert Xu 4375e923585SNikolay Aleksandrov static ssize_t multicast_igmp_version_show(struct device *d, 4385e923585SNikolay Aleksandrov struct device_attribute *attr, 4395e923585SNikolay Aleksandrov char *buf) 4405e923585SNikolay Aleksandrov { 4415e923585SNikolay Aleksandrov struct net_bridge *br = to_bridge(d); 4425e923585SNikolay Aleksandrov 4435e923585SNikolay Aleksandrov return sprintf(buf, "%u\n", br->multicast_igmp_version); 4445e923585SNikolay Aleksandrov } 4455e923585SNikolay Aleksandrov 4465e923585SNikolay Aleksandrov static ssize_t multicast_igmp_version_store(struct device *d, 4475e923585SNikolay Aleksandrov struct device_attribute *attr, 4485e923585SNikolay Aleksandrov const char *buf, size_t len) 4495e923585SNikolay Aleksandrov { 4505e923585SNikolay Aleksandrov return store_bridge_parm(d, buf, len, br_multicast_set_igmp_version); 4515e923585SNikolay Aleksandrov } 4525e923585SNikolay Aleksandrov static DEVICE_ATTR_RW(multicast_igmp_version); 4535e923585SNikolay Aleksandrov 454fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_count_show(struct device *d, 455d902eee4SHerbert Xu struct device_attribute *attr, 456d902eee4SHerbert Xu char *buf) 457d902eee4SHerbert Xu { 458d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 459d902eee4SHerbert Xu return sprintf(buf, "%u\n", br->multicast_last_member_count); 460d902eee4SHerbert Xu } 461d902eee4SHerbert Xu 462d902eee4SHerbert Xu static int set_last_member_count(struct net_bridge *br, unsigned long val) 463d902eee4SHerbert Xu { 464d902eee4SHerbert Xu br->multicast_last_member_count = val; 465d902eee4SHerbert Xu return 0; 466d902eee4SHerbert Xu } 467d902eee4SHerbert Xu 468fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_count_store(struct device *d, 469d902eee4SHerbert Xu struct device_attribute *attr, 470d902eee4SHerbert Xu const char *buf, size_t len) 471d902eee4SHerbert Xu { 472d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_last_member_count); 473d902eee4SHerbert Xu } 474fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_last_member_count); 475d902eee4SHerbert Xu 476fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_count_show( 477d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 478d902eee4SHerbert Xu { 479d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 480d902eee4SHerbert Xu return sprintf(buf, "%u\n", br->multicast_startup_query_count); 481d902eee4SHerbert Xu } 482d902eee4SHerbert Xu 483d902eee4SHerbert Xu static int set_startup_query_count(struct net_bridge *br, unsigned long val) 484d902eee4SHerbert Xu { 485d902eee4SHerbert Xu br->multicast_startup_query_count = val; 486d902eee4SHerbert Xu return 0; 487d902eee4SHerbert Xu } 488d902eee4SHerbert Xu 489fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_count_store( 490d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 491d902eee4SHerbert Xu size_t len) 492d902eee4SHerbert Xu { 493d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_startup_query_count); 494d902eee4SHerbert Xu } 495fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_startup_query_count); 496d902eee4SHerbert Xu 497fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_interval_show( 498d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 499d902eee4SHerbert Xu { 500d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 501d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 502d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_last_member_interval)); 503d902eee4SHerbert Xu } 504d902eee4SHerbert Xu 505d902eee4SHerbert Xu static int set_last_member_interval(struct net_bridge *br, unsigned long val) 506d902eee4SHerbert Xu { 507d902eee4SHerbert Xu br->multicast_last_member_interval = clock_t_to_jiffies(val); 508d902eee4SHerbert Xu return 0; 509d902eee4SHerbert Xu } 510d902eee4SHerbert Xu 511fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_interval_store( 512d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 513d902eee4SHerbert Xu size_t len) 514d902eee4SHerbert Xu { 515d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_last_member_interval); 516d902eee4SHerbert Xu } 517fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_last_member_interval); 518d902eee4SHerbert Xu 519fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_membership_interval_show( 520d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 521d902eee4SHerbert Xu { 522d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 523d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 524d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_membership_interval)); 525d902eee4SHerbert Xu } 526d902eee4SHerbert Xu 527d902eee4SHerbert Xu static int set_membership_interval(struct net_bridge *br, unsigned long val) 528d902eee4SHerbert Xu { 529d902eee4SHerbert Xu br->multicast_membership_interval = clock_t_to_jiffies(val); 530d902eee4SHerbert Xu return 0; 531d902eee4SHerbert Xu } 532d902eee4SHerbert Xu 533fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_membership_interval_store( 534d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 535d902eee4SHerbert Xu size_t len) 536d902eee4SHerbert Xu { 537d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_membership_interval); 538d902eee4SHerbert Xu } 539fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_membership_interval); 540d902eee4SHerbert Xu 541fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_interval_show(struct device *d, 542d902eee4SHerbert Xu struct device_attribute *attr, 543d902eee4SHerbert Xu char *buf) 544d902eee4SHerbert Xu { 545d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 546d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 547d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_querier_interval)); 548d902eee4SHerbert Xu } 549d902eee4SHerbert Xu 550d902eee4SHerbert Xu static int set_querier_interval(struct net_bridge *br, unsigned long val) 551d902eee4SHerbert Xu { 552d902eee4SHerbert Xu br->multicast_querier_interval = clock_t_to_jiffies(val); 553d902eee4SHerbert Xu return 0; 554d902eee4SHerbert Xu } 555d902eee4SHerbert Xu 556fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_interval_store(struct device *d, 557d902eee4SHerbert Xu struct device_attribute *attr, 558d902eee4SHerbert Xu const char *buf, size_t len) 559d902eee4SHerbert Xu { 560d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_querier_interval); 561d902eee4SHerbert Xu } 562fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_querier_interval); 563d902eee4SHerbert Xu 564fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_interval_show(struct device *d, 565d902eee4SHerbert Xu struct device_attribute *attr, 566d902eee4SHerbert Xu char *buf) 567d902eee4SHerbert Xu { 568d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 569d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 570d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_query_interval)); 571d902eee4SHerbert Xu } 572d902eee4SHerbert Xu 573d902eee4SHerbert Xu static int set_query_interval(struct net_bridge *br, unsigned long val) 574d902eee4SHerbert Xu { 575d902eee4SHerbert Xu br->multicast_query_interval = clock_t_to_jiffies(val); 576d902eee4SHerbert Xu return 0; 577d902eee4SHerbert Xu } 578d902eee4SHerbert Xu 579fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_interval_store(struct device *d, 580d902eee4SHerbert Xu struct device_attribute *attr, 581d902eee4SHerbert Xu const char *buf, size_t len) 582d902eee4SHerbert Xu { 583d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_query_interval); 584d902eee4SHerbert Xu } 585fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_query_interval); 586d902eee4SHerbert Xu 587fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_response_interval_show( 588d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 589d902eee4SHerbert Xu { 590d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 591d902eee4SHerbert Xu return sprintf( 592d902eee4SHerbert Xu buf, "%lu\n", 593d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_query_response_interval)); 594d902eee4SHerbert Xu } 595d902eee4SHerbert Xu 596d902eee4SHerbert Xu static int set_query_response_interval(struct net_bridge *br, unsigned long val) 597d902eee4SHerbert Xu { 598d902eee4SHerbert Xu br->multicast_query_response_interval = clock_t_to_jiffies(val); 599d902eee4SHerbert Xu return 0; 600d902eee4SHerbert Xu } 601d902eee4SHerbert Xu 602fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_response_interval_store( 603d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 604d902eee4SHerbert Xu size_t len) 605d902eee4SHerbert Xu { 606d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_query_response_interval); 607d902eee4SHerbert Xu } 608fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_query_response_interval); 609d902eee4SHerbert Xu 610fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_interval_show( 611d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 612d902eee4SHerbert Xu { 613d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 614d902eee4SHerbert Xu return sprintf( 615d902eee4SHerbert Xu buf, "%lu\n", 616d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_startup_query_interval)); 617d902eee4SHerbert Xu } 618d902eee4SHerbert Xu 619d902eee4SHerbert Xu static int set_startup_query_interval(struct net_bridge *br, unsigned long val) 620d902eee4SHerbert Xu { 621d902eee4SHerbert Xu br->multicast_startup_query_interval = clock_t_to_jiffies(val); 622d902eee4SHerbert Xu return 0; 623d902eee4SHerbert Xu } 624d902eee4SHerbert Xu 625fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_interval_store( 626d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 627d902eee4SHerbert Xu size_t len) 628d902eee4SHerbert Xu { 629d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_startup_query_interval); 630d902eee4SHerbert Xu } 631fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_startup_query_interval); 6321080ab95SNikolay Aleksandrov 6331080ab95SNikolay Aleksandrov static ssize_t multicast_stats_enabled_show(struct device *d, 6341080ab95SNikolay Aleksandrov struct device_attribute *attr, 6351080ab95SNikolay Aleksandrov char *buf) 6361080ab95SNikolay Aleksandrov { 6371080ab95SNikolay Aleksandrov struct net_bridge *br = to_bridge(d); 6381080ab95SNikolay Aleksandrov 6391080ab95SNikolay Aleksandrov return sprintf(buf, "%u\n", br->multicast_stats_enabled); 6401080ab95SNikolay Aleksandrov } 6411080ab95SNikolay Aleksandrov 6421080ab95SNikolay Aleksandrov static int set_stats_enabled(struct net_bridge *br, unsigned long val) 6431080ab95SNikolay Aleksandrov { 6441080ab95SNikolay Aleksandrov br->multicast_stats_enabled = !!val; 6451080ab95SNikolay Aleksandrov return 0; 6461080ab95SNikolay Aleksandrov } 6471080ab95SNikolay Aleksandrov 6481080ab95SNikolay Aleksandrov static ssize_t multicast_stats_enabled_store(struct device *d, 6491080ab95SNikolay Aleksandrov struct device_attribute *attr, 6501080ab95SNikolay Aleksandrov const char *buf, 6511080ab95SNikolay Aleksandrov size_t len) 6521080ab95SNikolay Aleksandrov { 6531080ab95SNikolay Aleksandrov return store_bridge_parm(d, buf, len, set_stats_enabled); 6541080ab95SNikolay Aleksandrov } 6551080ab95SNikolay Aleksandrov static DEVICE_ATTR_RW(multicast_stats_enabled); 656aa2ae3e7SNikolay Aleksandrov 657aa2ae3e7SNikolay Aleksandrov #if IS_ENABLED(CONFIG_IPV6) 658aa2ae3e7SNikolay Aleksandrov static ssize_t multicast_mld_version_show(struct device *d, 659aa2ae3e7SNikolay Aleksandrov struct device_attribute *attr, 660aa2ae3e7SNikolay Aleksandrov char *buf) 661aa2ae3e7SNikolay Aleksandrov { 662aa2ae3e7SNikolay Aleksandrov struct net_bridge *br = to_bridge(d); 663aa2ae3e7SNikolay Aleksandrov 664aa2ae3e7SNikolay Aleksandrov return sprintf(buf, "%u\n", br->multicast_mld_version); 665aa2ae3e7SNikolay Aleksandrov } 666aa2ae3e7SNikolay Aleksandrov 667aa2ae3e7SNikolay Aleksandrov static ssize_t multicast_mld_version_store(struct device *d, 668aa2ae3e7SNikolay Aleksandrov struct device_attribute *attr, 669aa2ae3e7SNikolay Aleksandrov const char *buf, size_t len) 670aa2ae3e7SNikolay Aleksandrov { 671aa2ae3e7SNikolay Aleksandrov return store_bridge_parm(d, buf, len, br_multicast_set_mld_version); 672aa2ae3e7SNikolay Aleksandrov } 673aa2ae3e7SNikolay Aleksandrov static DEVICE_ATTR_RW(multicast_mld_version); 674aa2ae3e7SNikolay Aleksandrov #endif 6750909e117SHerbert Xu #endif 67634666d46SPablo Neira Ayuso #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 677fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_iptables_show( 6784df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 6794df53d8bSPatrick McHardy { 6804df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 6814df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_iptables); 6824df53d8bSPatrick McHardy } 6834df53d8bSPatrick McHardy 6844df53d8bSPatrick McHardy static int set_nf_call_iptables(struct net_bridge *br, unsigned long val) 6854df53d8bSPatrick McHardy { 6864df53d8bSPatrick McHardy br->nf_call_iptables = val ? true : false; 6874df53d8bSPatrick McHardy return 0; 6884df53d8bSPatrick McHardy } 6894df53d8bSPatrick McHardy 690fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_iptables_store( 6914df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 6924df53d8bSPatrick McHardy size_t len) 6934df53d8bSPatrick McHardy { 6944df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_iptables); 6954df53d8bSPatrick McHardy } 696fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(nf_call_iptables); 6974df53d8bSPatrick McHardy 698fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_ip6tables_show( 6994df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 7004df53d8bSPatrick McHardy { 7014df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 7024df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_ip6tables); 7034df53d8bSPatrick McHardy } 7044df53d8bSPatrick McHardy 7054df53d8bSPatrick McHardy static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val) 7064df53d8bSPatrick McHardy { 7074df53d8bSPatrick McHardy br->nf_call_ip6tables = val ? true : false; 7084df53d8bSPatrick McHardy return 0; 7094df53d8bSPatrick McHardy } 7104df53d8bSPatrick McHardy 711fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_ip6tables_store( 7124df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 7134df53d8bSPatrick McHardy size_t len) 7144df53d8bSPatrick McHardy { 7154df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_ip6tables); 7164df53d8bSPatrick McHardy } 717fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(nf_call_ip6tables); 7184df53d8bSPatrick McHardy 719fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_arptables_show( 7204df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 7214df53d8bSPatrick McHardy { 7224df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 7234df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_arptables); 7244df53d8bSPatrick McHardy } 7254df53d8bSPatrick McHardy 7264df53d8bSPatrick McHardy static int set_nf_call_arptables(struct net_bridge *br, unsigned long val) 7274df53d8bSPatrick McHardy { 7284df53d8bSPatrick McHardy br->nf_call_arptables = val ? true : false; 7294df53d8bSPatrick McHardy return 0; 7304df53d8bSPatrick McHardy } 7314df53d8bSPatrick McHardy 732fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_arptables_store( 7334df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 7344df53d8bSPatrick McHardy size_t len) 7354df53d8bSPatrick McHardy { 7364df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_arptables); 7374df53d8bSPatrick McHardy } 738fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(nf_call_arptables); 7394df53d8bSPatrick McHardy #endif 740243a2e63SVlad Yasevich #ifdef CONFIG_BRIDGE_VLAN_FILTERING 741fbf2671bSsfeldma@cumulusnetworks.com static ssize_t vlan_filtering_show(struct device *d, 742243a2e63SVlad Yasevich struct device_attribute *attr, 743243a2e63SVlad Yasevich char *buf) 744243a2e63SVlad Yasevich { 745243a2e63SVlad Yasevich struct net_bridge *br = to_bridge(d); 746243a2e63SVlad Yasevich return sprintf(buf, "%d\n", br->vlan_enabled); 747243a2e63SVlad Yasevich } 748243a2e63SVlad Yasevich 749fbf2671bSsfeldma@cumulusnetworks.com static ssize_t vlan_filtering_store(struct device *d, 750243a2e63SVlad Yasevich struct device_attribute *attr, 751243a2e63SVlad Yasevich const char *buf, size_t len) 752243a2e63SVlad Yasevich { 753243a2e63SVlad Yasevich return store_bridge_parm(d, buf, len, br_vlan_filter_toggle); 754243a2e63SVlad Yasevich } 755fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(vlan_filtering); 756204177f3SToshiaki Makita 757204177f3SToshiaki Makita static ssize_t vlan_protocol_show(struct device *d, 758204177f3SToshiaki Makita struct device_attribute *attr, 759204177f3SToshiaki Makita char *buf) 760204177f3SToshiaki Makita { 761204177f3SToshiaki Makita struct net_bridge *br = to_bridge(d); 762204177f3SToshiaki Makita return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto)); 763204177f3SToshiaki Makita } 764204177f3SToshiaki Makita 765204177f3SToshiaki Makita static ssize_t vlan_protocol_store(struct device *d, 766204177f3SToshiaki Makita struct device_attribute *attr, 767204177f3SToshiaki Makita const char *buf, size_t len) 768204177f3SToshiaki Makita { 769204177f3SToshiaki Makita return store_bridge_parm(d, buf, len, br_vlan_set_proto); 770204177f3SToshiaki Makita } 771204177f3SToshiaki Makita static DEVICE_ATTR_RW(vlan_protocol); 77296a20d9dSVlad Yasevich 77396a20d9dSVlad Yasevich static ssize_t default_pvid_show(struct device *d, 77496a20d9dSVlad Yasevich struct device_attribute *attr, 77596a20d9dSVlad Yasevich char *buf) 77696a20d9dSVlad Yasevich { 77796a20d9dSVlad Yasevich struct net_bridge *br = to_bridge(d); 77896a20d9dSVlad Yasevich return sprintf(buf, "%d\n", br->default_pvid); 77996a20d9dSVlad Yasevich } 78096a20d9dSVlad Yasevich 78196a20d9dSVlad Yasevich static ssize_t default_pvid_store(struct device *d, 78296a20d9dSVlad Yasevich struct device_attribute *attr, 78396a20d9dSVlad Yasevich const char *buf, size_t len) 78496a20d9dSVlad Yasevich { 78596a20d9dSVlad Yasevich return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid); 78696a20d9dSVlad Yasevich } 78796a20d9dSVlad Yasevich static DEVICE_ATTR_RW(default_pvid); 7886dada9b1SNikolay Aleksandrov 7896dada9b1SNikolay Aleksandrov static ssize_t vlan_stats_enabled_show(struct device *d, 7906dada9b1SNikolay Aleksandrov struct device_attribute *attr, 7916dada9b1SNikolay Aleksandrov char *buf) 7926dada9b1SNikolay Aleksandrov { 7936dada9b1SNikolay Aleksandrov struct net_bridge *br = to_bridge(d); 7946dada9b1SNikolay Aleksandrov return sprintf(buf, "%u\n", br->vlan_stats_enabled); 7956dada9b1SNikolay Aleksandrov } 7966dada9b1SNikolay Aleksandrov 7976dada9b1SNikolay Aleksandrov static ssize_t vlan_stats_enabled_store(struct device *d, 7986dada9b1SNikolay Aleksandrov struct device_attribute *attr, 7996dada9b1SNikolay Aleksandrov const char *buf, size_t len) 8006dada9b1SNikolay Aleksandrov { 8016dada9b1SNikolay Aleksandrov return store_bridge_parm(d, buf, len, br_vlan_set_stats); 8026dada9b1SNikolay Aleksandrov } 8036dada9b1SNikolay Aleksandrov static DEVICE_ATTR_RW(vlan_stats_enabled); 804243a2e63SVlad Yasevich #endif 8050909e117SHerbert Xu 8061da177e4SLinus Torvalds static struct attribute *bridge_attrs[] = { 80743cb76d9SGreg Kroah-Hartman &dev_attr_forward_delay.attr, 80843cb76d9SGreg Kroah-Hartman &dev_attr_hello_time.attr, 80943cb76d9SGreg Kroah-Hartman &dev_attr_max_age.attr, 81043cb76d9SGreg Kroah-Hartman &dev_attr_ageing_time.attr, 81143cb76d9SGreg Kroah-Hartman &dev_attr_stp_state.attr, 812515853ccSstephen hemminger &dev_attr_group_fwd_mask.attr, 81343cb76d9SGreg Kroah-Hartman &dev_attr_priority.attr, 81443cb76d9SGreg Kroah-Hartman &dev_attr_bridge_id.attr, 81543cb76d9SGreg Kroah-Hartman &dev_attr_root_id.attr, 81643cb76d9SGreg Kroah-Hartman &dev_attr_root_path_cost.attr, 81743cb76d9SGreg Kroah-Hartman &dev_attr_root_port.attr, 81843cb76d9SGreg Kroah-Hartman &dev_attr_topology_change.attr, 81943cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_detected.attr, 82043cb76d9SGreg Kroah-Hartman &dev_attr_hello_timer.attr, 82143cb76d9SGreg Kroah-Hartman &dev_attr_tcn_timer.attr, 82243cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_timer.attr, 82343cb76d9SGreg Kroah-Hartman &dev_attr_gc_timer.attr, 82443cb76d9SGreg Kroah-Hartman &dev_attr_group_addr.attr, 8259cf63747SStephen Hemminger &dev_attr_flush.attr, 8260909e117SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 8270909e117SHerbert Xu &dev_attr_multicast_router.attr, 828561f1103SHerbert Xu &dev_attr_multicast_snooping.attr, 829c5c23260SHerbert Xu &dev_attr_multicast_querier.attr, 8301c8ad5bfSCong Wang &dev_attr_multicast_query_use_ifaddr.attr, 831b195167fSHerbert Xu &dev_attr_hash_elasticity.attr, 832b195167fSHerbert Xu &dev_attr_hash_max.attr, 833d902eee4SHerbert Xu &dev_attr_multicast_last_member_count.attr, 834d902eee4SHerbert Xu &dev_attr_multicast_startup_query_count.attr, 835d902eee4SHerbert Xu &dev_attr_multicast_last_member_interval.attr, 836d902eee4SHerbert Xu &dev_attr_multicast_membership_interval.attr, 837d902eee4SHerbert Xu &dev_attr_multicast_querier_interval.attr, 838d902eee4SHerbert Xu &dev_attr_multicast_query_interval.attr, 839d902eee4SHerbert Xu &dev_attr_multicast_query_response_interval.attr, 840d902eee4SHerbert Xu &dev_attr_multicast_startup_query_interval.attr, 8411080ab95SNikolay Aleksandrov &dev_attr_multicast_stats_enabled.attr, 8425e923585SNikolay Aleksandrov &dev_attr_multicast_igmp_version.attr, 843aa2ae3e7SNikolay Aleksandrov #if IS_ENABLED(CONFIG_IPV6) 844aa2ae3e7SNikolay Aleksandrov &dev_attr_multicast_mld_version.attr, 845aa2ae3e7SNikolay Aleksandrov #endif 8460909e117SHerbert Xu #endif 84734666d46SPablo Neira Ayuso #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 8484df53d8bSPatrick McHardy &dev_attr_nf_call_iptables.attr, 8494df53d8bSPatrick McHardy &dev_attr_nf_call_ip6tables.attr, 8504df53d8bSPatrick McHardy &dev_attr_nf_call_arptables.attr, 8514df53d8bSPatrick McHardy #endif 852243a2e63SVlad Yasevich #ifdef CONFIG_BRIDGE_VLAN_FILTERING 853243a2e63SVlad Yasevich &dev_attr_vlan_filtering.attr, 854204177f3SToshiaki Makita &dev_attr_vlan_protocol.attr, 85596a20d9dSVlad Yasevich &dev_attr_default_pvid.attr, 8566dada9b1SNikolay Aleksandrov &dev_attr_vlan_stats_enabled.attr, 857243a2e63SVlad Yasevich #endif 8581da177e4SLinus Torvalds NULL 8591da177e4SLinus Torvalds }; 8601da177e4SLinus Torvalds 861cddbb79fSArvind Yadav static const struct attribute_group bridge_group = { 8621da177e4SLinus Torvalds .name = SYSFS_BRIDGE_ATTR, 8631da177e4SLinus Torvalds .attrs = bridge_attrs, 8641da177e4SLinus Torvalds }; 8651da177e4SLinus Torvalds 8661da177e4SLinus Torvalds /* 8671da177e4SLinus Torvalds * Export the forwarding information table as a binary file 8681da177e4SLinus Torvalds * The records are struct __fdb_entry. 8691da177e4SLinus Torvalds * 8701da177e4SLinus Torvalds * Returns the number of bytes read. 8711da177e4SLinus Torvalds */ 8722c3c8beaSChris Wright static ssize_t brforward_read(struct file *filp, struct kobject *kobj, 87391a69029SZhang Rui struct bin_attribute *bin_attr, 87491a69029SZhang Rui char *buf, loff_t off, size_t count) 8751da177e4SLinus Torvalds { 876aeb7ed14SGeliang Tang struct device *dev = kobj_to_dev(kobj); 87743cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(dev); 8781da177e4SLinus Torvalds int n; 8791da177e4SLinus Torvalds 8801da177e4SLinus Torvalds /* must read whole records */ 8811da177e4SLinus Torvalds if (off % sizeof(struct __fdb_entry) != 0) 8821da177e4SLinus Torvalds return -EINVAL; 8831da177e4SLinus Torvalds 8841da177e4SLinus Torvalds n = br_fdb_fillbuf(br, buf, 8851da177e4SLinus Torvalds count / sizeof(struct __fdb_entry), 8861da177e4SLinus Torvalds off / sizeof(struct __fdb_entry)); 8871da177e4SLinus Torvalds 8881da177e4SLinus Torvalds if (n > 0) 8891da177e4SLinus Torvalds n *= sizeof(struct __fdb_entry); 8901da177e4SLinus Torvalds 8911da177e4SLinus Torvalds return n; 8921da177e4SLinus Torvalds } 8931da177e4SLinus Torvalds 8941da177e4SLinus Torvalds static struct bin_attribute bridge_forward = { 8951da177e4SLinus Torvalds .attr = { .name = SYSFS_BRIDGE_FDB, 8967b595756STejun Heo .mode = S_IRUGO, }, 8971da177e4SLinus Torvalds .read = brforward_read, 8981da177e4SLinus Torvalds }; 8991da177e4SLinus Torvalds 9001da177e4SLinus Torvalds /* 9011da177e4SLinus Torvalds * Add entries in sysfs onto the existing network class device 9021da177e4SLinus Torvalds * for the bridge. 9031da177e4SLinus Torvalds * Adds a attribute group "bridge" containing tuning parameters. 9041da177e4SLinus Torvalds * Binary attribute containing the forward table 9051da177e4SLinus Torvalds * Sub directory to hold links to interfaces. 9061da177e4SLinus Torvalds * 9071da177e4SLinus Torvalds * Note: the ifobj exists only to be a subdirectory 9081da177e4SLinus Torvalds * to hold links. The ifobj exists in same data structure 9091da177e4SLinus Torvalds * as it's parent the bridge so reference counting works. 9101da177e4SLinus Torvalds */ 9111da177e4SLinus Torvalds int br_sysfs_addbr(struct net_device *dev) 9121da177e4SLinus Torvalds { 91343cb76d9SGreg Kroah-Hartman struct kobject *brobj = &dev->dev.kobj; 9141da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 9151da177e4SLinus Torvalds int err; 9161da177e4SLinus Torvalds 9171da177e4SLinus Torvalds err = sysfs_create_group(brobj, &bridge_group); 9181da177e4SLinus Torvalds if (err) { 9191da177e4SLinus Torvalds pr_info("%s: can't create group %s/%s\n", 9200dc47877SHarvey Harrison __func__, dev->name, bridge_group.name); 9211da177e4SLinus Torvalds goto out1; 9221da177e4SLinus Torvalds } 9231da177e4SLinus Torvalds 9241da177e4SLinus Torvalds err = sysfs_create_bin_file(brobj, &bridge_forward); 9251da177e4SLinus Torvalds if (err) { 9261842c4beSRandy Dunlap pr_info("%s: can't create attribute file %s/%s\n", 9270dc47877SHarvey Harrison __func__, dev->name, bridge_forward.attr.name); 9281da177e4SLinus Torvalds goto out2; 9291da177e4SLinus Torvalds } 9301da177e4SLinus Torvalds 93143b98c4aSGreg Kroah-Hartman br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj); 93243b98c4aSGreg Kroah-Hartman if (!br->ifobj) { 9331da177e4SLinus Torvalds pr_info("%s: can't add kobject (directory) %s/%s\n", 9340dc47877SHarvey Harrison __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR); 935b5958963SPan Bian err = -ENOMEM; 9361da177e4SLinus Torvalds goto out3; 9371da177e4SLinus Torvalds } 9381da177e4SLinus Torvalds return 0; 9391da177e4SLinus Torvalds out3: 94043cb76d9SGreg Kroah-Hartman sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward); 9411da177e4SLinus Torvalds out2: 94243cb76d9SGreg Kroah-Hartman sysfs_remove_group(&dev->dev.kobj, &bridge_group); 9431da177e4SLinus Torvalds out1: 9441da177e4SLinus Torvalds return err; 9451da177e4SLinus Torvalds 9461da177e4SLinus Torvalds } 9471da177e4SLinus Torvalds 9481da177e4SLinus Torvalds void br_sysfs_delbr(struct net_device *dev) 9491da177e4SLinus Torvalds { 95043cb76d9SGreg Kroah-Hartman struct kobject *kobj = &dev->dev.kobj; 9511da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 9521da177e4SLinus Torvalds 95378a2d906SGreg Kroah-Hartman kobject_put(br->ifobj); 9541da177e4SLinus Torvalds sysfs_remove_bin_file(kobj, &bridge_forward); 9551da177e4SLinus Torvalds sysfs_remove_group(kobj, &bridge_group); 9561da177e4SLinus Torvalds } 957