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); 275fda93d92SStephen Hemminger return sprintf(buf, "%x:%x:%x:%x:%x:%x\n", 276fda93d92SStephen Hemminger br->group_addr[0], br->group_addr[1], 277fda93d92SStephen Hemminger br->group_addr[2], br->group_addr[3], 278fda93d92SStephen Hemminger br->group_addr[4], br->group_addr[5]); 279fda93d92SStephen Hemminger } 280fda93d92SStephen Hemminger 281fbf2671bSsfeldma@cumulusnetworks.com static ssize_t group_addr_store(struct device *d, 28243cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 28343cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 284fda93d92SStephen Hemminger { 28543cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2864197f24bSBen Hutchings u8 new_addr[6]; 287fda93d92SStephen Hemminger int i; 288fda93d92SStephen Hemminger 289cb990503SEric W. Biederman if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) 290fda93d92SStephen Hemminger return -EPERM; 291fda93d92SStephen Hemminger 2924197f24bSBen Hutchings if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", 293fda93d92SStephen Hemminger &new_addr[0], &new_addr[1], &new_addr[2], 294fda93d92SStephen Hemminger &new_addr[3], &new_addr[4], &new_addr[5]) != 6) 295fda93d92SStephen Hemminger return -EINVAL; 296fda93d92SStephen Hemminger 29746acc460SBen Hutchings if (!is_link_local_ether_addr(new_addr)) 298fda93d92SStephen Hemminger return -EINVAL; 299fda93d92SStephen Hemminger 300f64f9e71SJoe Perches if (new_addr[5] == 1 || /* 802.3x Pause address */ 301f64f9e71SJoe Perches new_addr[5] == 2 || /* 802.3ad Slow protocols */ 302f64f9e71SJoe Perches new_addr[5] == 3) /* 802.1X PAE address */ 303fda93d92SStephen Hemminger return -EINVAL; 304fda93d92SStephen Hemminger 305204177f3SToshiaki Makita if (!rtnl_trylock()) 306204177f3SToshiaki Makita return restart_syscall(); 307204177f3SToshiaki Makita 308fda93d92SStephen Hemminger spin_lock_bh(&br->lock); 309fda93d92SStephen Hemminger for (i = 0; i < 6; i++) 310fda93d92SStephen Hemminger br->group_addr[i] = new_addr[i]; 311fda93d92SStephen Hemminger spin_unlock_bh(&br->lock); 312204177f3SToshiaki Makita 313204177f3SToshiaki Makita br->group_addr_set = true; 314204177f3SToshiaki Makita br_recalculate_fwd_mask(br); 315047831a9SXin Long netdev_state_change(br->dev); 316204177f3SToshiaki Makita 317204177f3SToshiaki Makita rtnl_unlock(); 318204177f3SToshiaki Makita 319fda93d92SStephen Hemminger return len; 320fda93d92SStephen Hemminger } 321fda93d92SStephen Hemminger 322fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(group_addr); 323fda93d92SStephen Hemminger 32414f31bb3SXin Long static int set_flush(struct net_bridge *br, unsigned long val) 32514f31bb3SXin Long { 32614f31bb3SXin Long br_fdb_flush(br); 32714f31bb3SXin Long return 0; 32814f31bb3SXin Long } 32914f31bb3SXin Long 330fbf2671bSsfeldma@cumulusnetworks.com static ssize_t flush_store(struct device *d, 3319cf63747SStephen Hemminger struct device_attribute *attr, 3329cf63747SStephen Hemminger const char *buf, size_t len) 3339cf63747SStephen Hemminger { 33414f31bb3SXin Long return store_bridge_parm(d, buf, len, set_flush); 3359cf63747SStephen Hemminger } 336fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_WO(flush); 337fda93d92SStephen Hemminger 3380909e117SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 339fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_router_show(struct device *d, 3400909e117SHerbert Xu struct device_attribute *attr, char *buf) 3410909e117SHerbert Xu { 3420909e117SHerbert Xu struct net_bridge *br = to_bridge(d); 3430909e117SHerbert Xu return sprintf(buf, "%d\n", br->multicast_router); 3440909e117SHerbert Xu } 3450909e117SHerbert Xu 346fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_router_store(struct device *d, 3470909e117SHerbert Xu struct device_attribute *attr, 3480909e117SHerbert Xu const char *buf, size_t len) 3490909e117SHerbert Xu { 3500909e117SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_router); 3510909e117SHerbert Xu } 352fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_router); 353561f1103SHerbert Xu 354fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_snooping_show(struct device *d, 355561f1103SHerbert Xu struct device_attribute *attr, 356561f1103SHerbert Xu char *buf) 357561f1103SHerbert Xu { 358561f1103SHerbert Xu struct net_bridge *br = to_bridge(d); 359561f1103SHerbert Xu return sprintf(buf, "%d\n", !br->multicast_disabled); 360561f1103SHerbert Xu } 361561f1103SHerbert Xu 362fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_snooping_store(struct device *d, 363561f1103SHerbert Xu struct device_attribute *attr, 364561f1103SHerbert Xu const char *buf, size_t len) 365561f1103SHerbert Xu { 366561f1103SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_toggle); 367561f1103SHerbert Xu } 368fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_snooping); 369b195167fSHerbert Xu 370fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_use_ifaddr_show(struct device *d, 3711c8ad5bfSCong Wang struct device_attribute *attr, 3721c8ad5bfSCong Wang char *buf) 3731c8ad5bfSCong Wang { 3741c8ad5bfSCong Wang struct net_bridge *br = to_bridge(d); 3751c8ad5bfSCong Wang return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr); 3761c8ad5bfSCong Wang } 3771c8ad5bfSCong Wang 3781c8ad5bfSCong Wang static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val) 3791c8ad5bfSCong Wang { 3801c8ad5bfSCong Wang br->multicast_query_use_ifaddr = !!val; 3811c8ad5bfSCong Wang return 0; 3821c8ad5bfSCong Wang } 3831c8ad5bfSCong Wang 3841c8ad5bfSCong Wang static ssize_t 385fbf2671bSsfeldma@cumulusnetworks.com multicast_query_use_ifaddr_store(struct device *d, 3861c8ad5bfSCong Wang struct device_attribute *attr, 3871c8ad5bfSCong Wang const char *buf, size_t len) 3881c8ad5bfSCong Wang { 3891c8ad5bfSCong Wang return store_bridge_parm(d, buf, len, set_query_use_ifaddr); 3901c8ad5bfSCong Wang } 391fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_query_use_ifaddr); 3921c8ad5bfSCong Wang 393fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_show(struct device *d, 394c5c23260SHerbert Xu struct device_attribute *attr, 395c5c23260SHerbert Xu char *buf) 396c5c23260SHerbert Xu { 397c5c23260SHerbert Xu struct net_bridge *br = to_bridge(d); 398c5c23260SHerbert Xu return sprintf(buf, "%d\n", br->multicast_querier); 399c5c23260SHerbert Xu } 400c5c23260SHerbert Xu 401fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_store(struct device *d, 402c5c23260SHerbert Xu struct device_attribute *attr, 403c5c23260SHerbert Xu const char *buf, size_t len) 404c5c23260SHerbert Xu { 405c5c23260SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_querier); 406c5c23260SHerbert Xu } 407fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_querier); 408c5c23260SHerbert Xu 409fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_elasticity_show(struct device *d, 410b195167fSHerbert Xu struct device_attribute *attr, char *buf) 411b195167fSHerbert Xu { 412b195167fSHerbert Xu struct net_bridge *br = to_bridge(d); 413b195167fSHerbert Xu return sprintf(buf, "%u\n", br->hash_elasticity); 414b195167fSHerbert Xu } 415b195167fSHerbert Xu 416b195167fSHerbert Xu static int set_elasticity(struct net_bridge *br, unsigned long val) 417b195167fSHerbert Xu { 418b195167fSHerbert Xu br->hash_elasticity = val; 419b195167fSHerbert Xu return 0; 420b195167fSHerbert Xu } 421b195167fSHerbert Xu 422fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_elasticity_store(struct device *d, 423b195167fSHerbert Xu struct device_attribute *attr, 424b195167fSHerbert Xu const char *buf, size_t len) 425b195167fSHerbert Xu { 426b195167fSHerbert Xu return store_bridge_parm(d, buf, len, set_elasticity); 427b195167fSHerbert Xu } 428fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(hash_elasticity); 429b195167fSHerbert Xu 430fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_max_show(struct device *d, struct device_attribute *attr, 431b195167fSHerbert Xu char *buf) 432b195167fSHerbert Xu { 433b195167fSHerbert Xu struct net_bridge *br = to_bridge(d); 434b195167fSHerbert Xu return sprintf(buf, "%u\n", br->hash_max); 435b195167fSHerbert Xu } 436b195167fSHerbert Xu 437fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_max_store(struct device *d, struct device_attribute *attr, 438b195167fSHerbert Xu const char *buf, size_t len) 439b195167fSHerbert Xu { 440b195167fSHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_hash_max); 441b195167fSHerbert Xu } 442fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(hash_max); 443d902eee4SHerbert Xu 4445e923585SNikolay Aleksandrov static ssize_t multicast_igmp_version_show(struct device *d, 4455e923585SNikolay Aleksandrov struct device_attribute *attr, 4465e923585SNikolay Aleksandrov char *buf) 4475e923585SNikolay Aleksandrov { 4485e923585SNikolay Aleksandrov struct net_bridge *br = to_bridge(d); 4495e923585SNikolay Aleksandrov 4505e923585SNikolay Aleksandrov return sprintf(buf, "%u\n", br->multicast_igmp_version); 4515e923585SNikolay Aleksandrov } 4525e923585SNikolay Aleksandrov 4535e923585SNikolay Aleksandrov static ssize_t multicast_igmp_version_store(struct device *d, 4545e923585SNikolay Aleksandrov struct device_attribute *attr, 4555e923585SNikolay Aleksandrov const char *buf, size_t len) 4565e923585SNikolay Aleksandrov { 4575e923585SNikolay Aleksandrov return store_bridge_parm(d, buf, len, br_multicast_set_igmp_version); 4585e923585SNikolay Aleksandrov } 4595e923585SNikolay Aleksandrov static DEVICE_ATTR_RW(multicast_igmp_version); 4605e923585SNikolay Aleksandrov 461fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_count_show(struct device *d, 462d902eee4SHerbert Xu struct device_attribute *attr, 463d902eee4SHerbert Xu char *buf) 464d902eee4SHerbert Xu { 465d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 466d902eee4SHerbert Xu return sprintf(buf, "%u\n", br->multicast_last_member_count); 467d902eee4SHerbert Xu } 468d902eee4SHerbert Xu 469d902eee4SHerbert Xu static int set_last_member_count(struct net_bridge *br, unsigned long val) 470d902eee4SHerbert Xu { 471d902eee4SHerbert Xu br->multicast_last_member_count = val; 472d902eee4SHerbert Xu return 0; 473d902eee4SHerbert Xu } 474d902eee4SHerbert Xu 475fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_count_store(struct device *d, 476d902eee4SHerbert Xu struct device_attribute *attr, 477d902eee4SHerbert Xu const char *buf, size_t len) 478d902eee4SHerbert Xu { 479d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_last_member_count); 480d902eee4SHerbert Xu } 481fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_last_member_count); 482d902eee4SHerbert Xu 483fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_count_show( 484d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 485d902eee4SHerbert Xu { 486d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 487d902eee4SHerbert Xu return sprintf(buf, "%u\n", br->multicast_startup_query_count); 488d902eee4SHerbert Xu } 489d902eee4SHerbert Xu 490d902eee4SHerbert Xu static int set_startup_query_count(struct net_bridge *br, unsigned long val) 491d902eee4SHerbert Xu { 492d902eee4SHerbert Xu br->multicast_startup_query_count = val; 493d902eee4SHerbert Xu return 0; 494d902eee4SHerbert Xu } 495d902eee4SHerbert Xu 496fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_count_store( 497d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 498d902eee4SHerbert Xu size_t len) 499d902eee4SHerbert Xu { 500d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_startup_query_count); 501d902eee4SHerbert Xu } 502fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_startup_query_count); 503d902eee4SHerbert Xu 504fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_interval_show( 505d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 506d902eee4SHerbert Xu { 507d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 508d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 509d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_last_member_interval)); 510d902eee4SHerbert Xu } 511d902eee4SHerbert Xu 512d902eee4SHerbert Xu static int set_last_member_interval(struct net_bridge *br, unsigned long val) 513d902eee4SHerbert Xu { 514d902eee4SHerbert Xu br->multicast_last_member_interval = clock_t_to_jiffies(val); 515d902eee4SHerbert Xu return 0; 516d902eee4SHerbert Xu } 517d902eee4SHerbert Xu 518fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_interval_store( 519d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 520d902eee4SHerbert Xu size_t len) 521d902eee4SHerbert Xu { 522d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_last_member_interval); 523d902eee4SHerbert Xu } 524fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_last_member_interval); 525d902eee4SHerbert Xu 526fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_membership_interval_show( 527d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 528d902eee4SHerbert Xu { 529d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 530d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 531d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_membership_interval)); 532d902eee4SHerbert Xu } 533d902eee4SHerbert Xu 534d902eee4SHerbert Xu static int set_membership_interval(struct net_bridge *br, unsigned long val) 535d902eee4SHerbert Xu { 536d902eee4SHerbert Xu br->multicast_membership_interval = clock_t_to_jiffies(val); 537d902eee4SHerbert Xu return 0; 538d902eee4SHerbert Xu } 539d902eee4SHerbert Xu 540fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_membership_interval_store( 541d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 542d902eee4SHerbert Xu size_t len) 543d902eee4SHerbert Xu { 544d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_membership_interval); 545d902eee4SHerbert Xu } 546fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_membership_interval); 547d902eee4SHerbert Xu 548fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_interval_show(struct device *d, 549d902eee4SHerbert Xu struct device_attribute *attr, 550d902eee4SHerbert Xu char *buf) 551d902eee4SHerbert Xu { 552d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 553d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 554d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_querier_interval)); 555d902eee4SHerbert Xu } 556d902eee4SHerbert Xu 557d902eee4SHerbert Xu static int set_querier_interval(struct net_bridge *br, unsigned long val) 558d902eee4SHerbert Xu { 559d902eee4SHerbert Xu br->multicast_querier_interval = clock_t_to_jiffies(val); 560d902eee4SHerbert Xu return 0; 561d902eee4SHerbert Xu } 562d902eee4SHerbert Xu 563fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_interval_store(struct device *d, 564d902eee4SHerbert Xu struct device_attribute *attr, 565d902eee4SHerbert Xu const char *buf, size_t len) 566d902eee4SHerbert Xu { 567d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_querier_interval); 568d902eee4SHerbert Xu } 569fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_querier_interval); 570d902eee4SHerbert Xu 571fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_interval_show(struct device *d, 572d902eee4SHerbert Xu struct device_attribute *attr, 573d902eee4SHerbert Xu char *buf) 574d902eee4SHerbert Xu { 575d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 576d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 577d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_query_interval)); 578d902eee4SHerbert Xu } 579d902eee4SHerbert Xu 580d902eee4SHerbert Xu static int set_query_interval(struct net_bridge *br, unsigned long val) 581d902eee4SHerbert Xu { 582d902eee4SHerbert Xu br->multicast_query_interval = clock_t_to_jiffies(val); 583d902eee4SHerbert Xu return 0; 584d902eee4SHerbert Xu } 585d902eee4SHerbert Xu 586fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_interval_store(struct device *d, 587d902eee4SHerbert Xu struct device_attribute *attr, 588d902eee4SHerbert Xu const char *buf, size_t len) 589d902eee4SHerbert Xu { 590d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_query_interval); 591d902eee4SHerbert Xu } 592fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_query_interval); 593d902eee4SHerbert Xu 594fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_response_interval_show( 595d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 596d902eee4SHerbert Xu { 597d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 598d902eee4SHerbert Xu return sprintf( 599d902eee4SHerbert Xu buf, "%lu\n", 600d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_query_response_interval)); 601d902eee4SHerbert Xu } 602d902eee4SHerbert Xu 603d902eee4SHerbert Xu static int set_query_response_interval(struct net_bridge *br, unsigned long val) 604d902eee4SHerbert Xu { 605d902eee4SHerbert Xu br->multicast_query_response_interval = clock_t_to_jiffies(val); 606d902eee4SHerbert Xu return 0; 607d902eee4SHerbert Xu } 608d902eee4SHerbert Xu 609fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_response_interval_store( 610d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 611d902eee4SHerbert Xu size_t len) 612d902eee4SHerbert Xu { 613d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_query_response_interval); 614d902eee4SHerbert Xu } 615fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_query_response_interval); 616d902eee4SHerbert Xu 617fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_interval_show( 618d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 619d902eee4SHerbert Xu { 620d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 621d902eee4SHerbert Xu return sprintf( 622d902eee4SHerbert Xu buf, "%lu\n", 623d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_startup_query_interval)); 624d902eee4SHerbert Xu } 625d902eee4SHerbert Xu 626d902eee4SHerbert Xu static int set_startup_query_interval(struct net_bridge *br, unsigned long val) 627d902eee4SHerbert Xu { 628d902eee4SHerbert Xu br->multicast_startup_query_interval = clock_t_to_jiffies(val); 629d902eee4SHerbert Xu return 0; 630d902eee4SHerbert Xu } 631d902eee4SHerbert Xu 632fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_interval_store( 633d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 634d902eee4SHerbert Xu size_t len) 635d902eee4SHerbert Xu { 636d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_startup_query_interval); 637d902eee4SHerbert Xu } 638fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_startup_query_interval); 6391080ab95SNikolay Aleksandrov 6401080ab95SNikolay Aleksandrov static ssize_t multicast_stats_enabled_show(struct device *d, 6411080ab95SNikolay Aleksandrov struct device_attribute *attr, 6421080ab95SNikolay Aleksandrov char *buf) 6431080ab95SNikolay Aleksandrov { 6441080ab95SNikolay Aleksandrov struct net_bridge *br = to_bridge(d); 6451080ab95SNikolay Aleksandrov 6461080ab95SNikolay Aleksandrov return sprintf(buf, "%u\n", br->multicast_stats_enabled); 6471080ab95SNikolay Aleksandrov } 6481080ab95SNikolay Aleksandrov 6491080ab95SNikolay Aleksandrov static int set_stats_enabled(struct net_bridge *br, unsigned long val) 6501080ab95SNikolay Aleksandrov { 6511080ab95SNikolay Aleksandrov br->multicast_stats_enabled = !!val; 6521080ab95SNikolay Aleksandrov return 0; 6531080ab95SNikolay Aleksandrov } 6541080ab95SNikolay Aleksandrov 6551080ab95SNikolay Aleksandrov static ssize_t multicast_stats_enabled_store(struct device *d, 6561080ab95SNikolay Aleksandrov struct device_attribute *attr, 6571080ab95SNikolay Aleksandrov const char *buf, 6581080ab95SNikolay Aleksandrov size_t len) 6591080ab95SNikolay Aleksandrov { 6601080ab95SNikolay Aleksandrov return store_bridge_parm(d, buf, len, set_stats_enabled); 6611080ab95SNikolay Aleksandrov } 6621080ab95SNikolay Aleksandrov static DEVICE_ATTR_RW(multicast_stats_enabled); 663aa2ae3e7SNikolay Aleksandrov 664aa2ae3e7SNikolay Aleksandrov #if IS_ENABLED(CONFIG_IPV6) 665aa2ae3e7SNikolay Aleksandrov static ssize_t multicast_mld_version_show(struct device *d, 666aa2ae3e7SNikolay Aleksandrov struct device_attribute *attr, 667aa2ae3e7SNikolay Aleksandrov char *buf) 668aa2ae3e7SNikolay Aleksandrov { 669aa2ae3e7SNikolay Aleksandrov struct net_bridge *br = to_bridge(d); 670aa2ae3e7SNikolay Aleksandrov 671aa2ae3e7SNikolay Aleksandrov return sprintf(buf, "%u\n", br->multicast_mld_version); 672aa2ae3e7SNikolay Aleksandrov } 673aa2ae3e7SNikolay Aleksandrov 674aa2ae3e7SNikolay Aleksandrov static ssize_t multicast_mld_version_store(struct device *d, 675aa2ae3e7SNikolay Aleksandrov struct device_attribute *attr, 676aa2ae3e7SNikolay Aleksandrov const char *buf, size_t len) 677aa2ae3e7SNikolay Aleksandrov { 678aa2ae3e7SNikolay Aleksandrov return store_bridge_parm(d, buf, len, br_multicast_set_mld_version); 679aa2ae3e7SNikolay Aleksandrov } 680aa2ae3e7SNikolay Aleksandrov static DEVICE_ATTR_RW(multicast_mld_version); 681aa2ae3e7SNikolay Aleksandrov #endif 6820909e117SHerbert Xu #endif 68334666d46SPablo Neira Ayuso #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 684fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_iptables_show( 6854df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 6864df53d8bSPatrick McHardy { 6874df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 6884df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_iptables); 6894df53d8bSPatrick McHardy } 6904df53d8bSPatrick McHardy 6914df53d8bSPatrick McHardy static int set_nf_call_iptables(struct net_bridge *br, unsigned long val) 6924df53d8bSPatrick McHardy { 6934df53d8bSPatrick McHardy br->nf_call_iptables = val ? true : false; 6944df53d8bSPatrick McHardy return 0; 6954df53d8bSPatrick McHardy } 6964df53d8bSPatrick McHardy 697fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_iptables_store( 6984df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 6994df53d8bSPatrick McHardy size_t len) 7004df53d8bSPatrick McHardy { 7014df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_iptables); 7024df53d8bSPatrick McHardy } 703fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(nf_call_iptables); 7044df53d8bSPatrick McHardy 705fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_ip6tables_show( 7064df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 7074df53d8bSPatrick McHardy { 7084df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 7094df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_ip6tables); 7104df53d8bSPatrick McHardy } 7114df53d8bSPatrick McHardy 7124df53d8bSPatrick McHardy static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val) 7134df53d8bSPatrick McHardy { 7144df53d8bSPatrick McHardy br->nf_call_ip6tables = val ? true : false; 7154df53d8bSPatrick McHardy return 0; 7164df53d8bSPatrick McHardy } 7174df53d8bSPatrick McHardy 718fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_ip6tables_store( 7194df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 7204df53d8bSPatrick McHardy size_t len) 7214df53d8bSPatrick McHardy { 7224df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_ip6tables); 7234df53d8bSPatrick McHardy } 724fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(nf_call_ip6tables); 7254df53d8bSPatrick McHardy 726fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_arptables_show( 7274df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 7284df53d8bSPatrick McHardy { 7294df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 7304df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_arptables); 7314df53d8bSPatrick McHardy } 7324df53d8bSPatrick McHardy 7334df53d8bSPatrick McHardy static int set_nf_call_arptables(struct net_bridge *br, unsigned long val) 7344df53d8bSPatrick McHardy { 7354df53d8bSPatrick McHardy br->nf_call_arptables = val ? true : false; 7364df53d8bSPatrick McHardy return 0; 7374df53d8bSPatrick McHardy } 7384df53d8bSPatrick McHardy 739fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_arptables_store( 7404df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 7414df53d8bSPatrick McHardy size_t len) 7424df53d8bSPatrick McHardy { 7434df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_arptables); 7444df53d8bSPatrick McHardy } 745fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(nf_call_arptables); 7464df53d8bSPatrick McHardy #endif 747243a2e63SVlad Yasevich #ifdef CONFIG_BRIDGE_VLAN_FILTERING 748fbf2671bSsfeldma@cumulusnetworks.com static ssize_t vlan_filtering_show(struct device *d, 749243a2e63SVlad Yasevich struct device_attribute *attr, 750243a2e63SVlad Yasevich char *buf) 751243a2e63SVlad Yasevich { 752243a2e63SVlad Yasevich struct net_bridge *br = to_bridge(d); 753243a2e63SVlad Yasevich return sprintf(buf, "%d\n", br->vlan_enabled); 754243a2e63SVlad Yasevich } 755243a2e63SVlad Yasevich 756fbf2671bSsfeldma@cumulusnetworks.com static ssize_t vlan_filtering_store(struct device *d, 757243a2e63SVlad Yasevich struct device_attribute *attr, 758243a2e63SVlad Yasevich const char *buf, size_t len) 759243a2e63SVlad Yasevich { 760243a2e63SVlad Yasevich return store_bridge_parm(d, buf, len, br_vlan_filter_toggle); 761243a2e63SVlad Yasevich } 762fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(vlan_filtering); 763204177f3SToshiaki Makita 764204177f3SToshiaki Makita static ssize_t vlan_protocol_show(struct device *d, 765204177f3SToshiaki Makita struct device_attribute *attr, 766204177f3SToshiaki Makita char *buf) 767204177f3SToshiaki Makita { 768204177f3SToshiaki Makita struct net_bridge *br = to_bridge(d); 769204177f3SToshiaki Makita return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto)); 770204177f3SToshiaki Makita } 771204177f3SToshiaki Makita 772204177f3SToshiaki Makita static ssize_t vlan_protocol_store(struct device *d, 773204177f3SToshiaki Makita struct device_attribute *attr, 774204177f3SToshiaki Makita const char *buf, size_t len) 775204177f3SToshiaki Makita { 776204177f3SToshiaki Makita return store_bridge_parm(d, buf, len, br_vlan_set_proto); 777204177f3SToshiaki Makita } 778204177f3SToshiaki Makita static DEVICE_ATTR_RW(vlan_protocol); 77996a20d9dSVlad Yasevich 78096a20d9dSVlad Yasevich static ssize_t default_pvid_show(struct device *d, 78196a20d9dSVlad Yasevich struct device_attribute *attr, 78296a20d9dSVlad Yasevich char *buf) 78396a20d9dSVlad Yasevich { 78496a20d9dSVlad Yasevich struct net_bridge *br = to_bridge(d); 78596a20d9dSVlad Yasevich return sprintf(buf, "%d\n", br->default_pvid); 78696a20d9dSVlad Yasevich } 78796a20d9dSVlad Yasevich 78896a20d9dSVlad Yasevich static ssize_t default_pvid_store(struct device *d, 78996a20d9dSVlad Yasevich struct device_attribute *attr, 79096a20d9dSVlad Yasevich const char *buf, size_t len) 79196a20d9dSVlad Yasevich { 79296a20d9dSVlad Yasevich return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid); 79396a20d9dSVlad Yasevich } 79496a20d9dSVlad Yasevich static DEVICE_ATTR_RW(default_pvid); 7956dada9b1SNikolay Aleksandrov 7966dada9b1SNikolay Aleksandrov static ssize_t vlan_stats_enabled_show(struct device *d, 7976dada9b1SNikolay Aleksandrov struct device_attribute *attr, 7986dada9b1SNikolay Aleksandrov char *buf) 7996dada9b1SNikolay Aleksandrov { 8006dada9b1SNikolay Aleksandrov struct net_bridge *br = to_bridge(d); 8016dada9b1SNikolay Aleksandrov return sprintf(buf, "%u\n", br->vlan_stats_enabled); 8026dada9b1SNikolay Aleksandrov } 8036dada9b1SNikolay Aleksandrov 8046dada9b1SNikolay Aleksandrov static ssize_t vlan_stats_enabled_store(struct device *d, 8056dada9b1SNikolay Aleksandrov struct device_attribute *attr, 8066dada9b1SNikolay Aleksandrov const char *buf, size_t len) 8076dada9b1SNikolay Aleksandrov { 8086dada9b1SNikolay Aleksandrov return store_bridge_parm(d, buf, len, br_vlan_set_stats); 8096dada9b1SNikolay Aleksandrov } 8106dada9b1SNikolay Aleksandrov static DEVICE_ATTR_RW(vlan_stats_enabled); 811243a2e63SVlad Yasevich #endif 8120909e117SHerbert Xu 8131da177e4SLinus Torvalds static struct attribute *bridge_attrs[] = { 81443cb76d9SGreg Kroah-Hartman &dev_attr_forward_delay.attr, 81543cb76d9SGreg Kroah-Hartman &dev_attr_hello_time.attr, 81643cb76d9SGreg Kroah-Hartman &dev_attr_max_age.attr, 81743cb76d9SGreg Kroah-Hartman &dev_attr_ageing_time.attr, 81843cb76d9SGreg Kroah-Hartman &dev_attr_stp_state.attr, 819515853ccSstephen hemminger &dev_attr_group_fwd_mask.attr, 82043cb76d9SGreg Kroah-Hartman &dev_attr_priority.attr, 82143cb76d9SGreg Kroah-Hartman &dev_attr_bridge_id.attr, 82243cb76d9SGreg Kroah-Hartman &dev_attr_root_id.attr, 82343cb76d9SGreg Kroah-Hartman &dev_attr_root_path_cost.attr, 82443cb76d9SGreg Kroah-Hartman &dev_attr_root_port.attr, 82543cb76d9SGreg Kroah-Hartman &dev_attr_topology_change.attr, 82643cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_detected.attr, 82743cb76d9SGreg Kroah-Hartman &dev_attr_hello_timer.attr, 82843cb76d9SGreg Kroah-Hartman &dev_attr_tcn_timer.attr, 82943cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_timer.attr, 83043cb76d9SGreg Kroah-Hartman &dev_attr_gc_timer.attr, 83143cb76d9SGreg Kroah-Hartman &dev_attr_group_addr.attr, 8329cf63747SStephen Hemminger &dev_attr_flush.attr, 8330909e117SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 8340909e117SHerbert Xu &dev_attr_multicast_router.attr, 835561f1103SHerbert Xu &dev_attr_multicast_snooping.attr, 836c5c23260SHerbert Xu &dev_attr_multicast_querier.attr, 8371c8ad5bfSCong Wang &dev_attr_multicast_query_use_ifaddr.attr, 838b195167fSHerbert Xu &dev_attr_hash_elasticity.attr, 839b195167fSHerbert Xu &dev_attr_hash_max.attr, 840d902eee4SHerbert Xu &dev_attr_multicast_last_member_count.attr, 841d902eee4SHerbert Xu &dev_attr_multicast_startup_query_count.attr, 842d902eee4SHerbert Xu &dev_attr_multicast_last_member_interval.attr, 843d902eee4SHerbert Xu &dev_attr_multicast_membership_interval.attr, 844d902eee4SHerbert Xu &dev_attr_multicast_querier_interval.attr, 845d902eee4SHerbert Xu &dev_attr_multicast_query_interval.attr, 846d902eee4SHerbert Xu &dev_attr_multicast_query_response_interval.attr, 847d902eee4SHerbert Xu &dev_attr_multicast_startup_query_interval.attr, 8481080ab95SNikolay Aleksandrov &dev_attr_multicast_stats_enabled.attr, 8495e923585SNikolay Aleksandrov &dev_attr_multicast_igmp_version.attr, 850aa2ae3e7SNikolay Aleksandrov #if IS_ENABLED(CONFIG_IPV6) 851aa2ae3e7SNikolay Aleksandrov &dev_attr_multicast_mld_version.attr, 852aa2ae3e7SNikolay Aleksandrov #endif 8530909e117SHerbert Xu #endif 85434666d46SPablo Neira Ayuso #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 8554df53d8bSPatrick McHardy &dev_attr_nf_call_iptables.attr, 8564df53d8bSPatrick McHardy &dev_attr_nf_call_ip6tables.attr, 8574df53d8bSPatrick McHardy &dev_attr_nf_call_arptables.attr, 8584df53d8bSPatrick McHardy #endif 859243a2e63SVlad Yasevich #ifdef CONFIG_BRIDGE_VLAN_FILTERING 860243a2e63SVlad Yasevich &dev_attr_vlan_filtering.attr, 861204177f3SToshiaki Makita &dev_attr_vlan_protocol.attr, 86296a20d9dSVlad Yasevich &dev_attr_default_pvid.attr, 8636dada9b1SNikolay Aleksandrov &dev_attr_vlan_stats_enabled.attr, 864243a2e63SVlad Yasevich #endif 8651da177e4SLinus Torvalds NULL 8661da177e4SLinus Torvalds }; 8671da177e4SLinus Torvalds 868*cddbb79fSArvind Yadav static const struct attribute_group bridge_group = { 8691da177e4SLinus Torvalds .name = SYSFS_BRIDGE_ATTR, 8701da177e4SLinus Torvalds .attrs = bridge_attrs, 8711da177e4SLinus Torvalds }; 8721da177e4SLinus Torvalds 8731da177e4SLinus Torvalds /* 8741da177e4SLinus Torvalds * Export the forwarding information table as a binary file 8751da177e4SLinus Torvalds * The records are struct __fdb_entry. 8761da177e4SLinus Torvalds * 8771da177e4SLinus Torvalds * Returns the number of bytes read. 8781da177e4SLinus Torvalds */ 8792c3c8beaSChris Wright static ssize_t brforward_read(struct file *filp, struct kobject *kobj, 88091a69029SZhang Rui struct bin_attribute *bin_attr, 88191a69029SZhang Rui char *buf, loff_t off, size_t count) 8821da177e4SLinus Torvalds { 883aeb7ed14SGeliang Tang struct device *dev = kobj_to_dev(kobj); 88443cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(dev); 8851da177e4SLinus Torvalds int n; 8861da177e4SLinus Torvalds 8871da177e4SLinus Torvalds /* must read whole records */ 8881da177e4SLinus Torvalds if (off % sizeof(struct __fdb_entry) != 0) 8891da177e4SLinus Torvalds return -EINVAL; 8901da177e4SLinus Torvalds 8911da177e4SLinus Torvalds n = br_fdb_fillbuf(br, buf, 8921da177e4SLinus Torvalds count / sizeof(struct __fdb_entry), 8931da177e4SLinus Torvalds off / sizeof(struct __fdb_entry)); 8941da177e4SLinus Torvalds 8951da177e4SLinus Torvalds if (n > 0) 8961da177e4SLinus Torvalds n *= sizeof(struct __fdb_entry); 8971da177e4SLinus Torvalds 8981da177e4SLinus Torvalds return n; 8991da177e4SLinus Torvalds } 9001da177e4SLinus Torvalds 9011da177e4SLinus Torvalds static struct bin_attribute bridge_forward = { 9021da177e4SLinus Torvalds .attr = { .name = SYSFS_BRIDGE_FDB, 9037b595756STejun Heo .mode = S_IRUGO, }, 9041da177e4SLinus Torvalds .read = brforward_read, 9051da177e4SLinus Torvalds }; 9061da177e4SLinus Torvalds 9071da177e4SLinus Torvalds /* 9081da177e4SLinus Torvalds * Add entries in sysfs onto the existing network class device 9091da177e4SLinus Torvalds * for the bridge. 9101da177e4SLinus Torvalds * Adds a attribute group "bridge" containing tuning parameters. 9111da177e4SLinus Torvalds * Binary attribute containing the forward table 9121da177e4SLinus Torvalds * Sub directory to hold links to interfaces. 9131da177e4SLinus Torvalds * 9141da177e4SLinus Torvalds * Note: the ifobj exists only to be a subdirectory 9151da177e4SLinus Torvalds * to hold links. The ifobj exists in same data structure 9161da177e4SLinus Torvalds * as it's parent the bridge so reference counting works. 9171da177e4SLinus Torvalds */ 9181da177e4SLinus Torvalds int br_sysfs_addbr(struct net_device *dev) 9191da177e4SLinus Torvalds { 92043cb76d9SGreg Kroah-Hartman struct kobject *brobj = &dev->dev.kobj; 9211da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 9221da177e4SLinus Torvalds int err; 9231da177e4SLinus Torvalds 9241da177e4SLinus Torvalds err = sysfs_create_group(brobj, &bridge_group); 9251da177e4SLinus Torvalds if (err) { 9261da177e4SLinus Torvalds pr_info("%s: can't create group %s/%s\n", 9270dc47877SHarvey Harrison __func__, dev->name, bridge_group.name); 9281da177e4SLinus Torvalds goto out1; 9291da177e4SLinus Torvalds } 9301da177e4SLinus Torvalds 9311da177e4SLinus Torvalds err = sysfs_create_bin_file(brobj, &bridge_forward); 9321da177e4SLinus Torvalds if (err) { 9331842c4beSRandy Dunlap pr_info("%s: can't create attribute file %s/%s\n", 9340dc47877SHarvey Harrison __func__, dev->name, bridge_forward.attr.name); 9351da177e4SLinus Torvalds goto out2; 9361da177e4SLinus Torvalds } 9371da177e4SLinus Torvalds 93843b98c4aSGreg Kroah-Hartman br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj); 93943b98c4aSGreg Kroah-Hartman if (!br->ifobj) { 9401da177e4SLinus Torvalds pr_info("%s: can't add kobject (directory) %s/%s\n", 9410dc47877SHarvey Harrison __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR); 942b5958963SPan Bian err = -ENOMEM; 9431da177e4SLinus Torvalds goto out3; 9441da177e4SLinus Torvalds } 9451da177e4SLinus Torvalds return 0; 9461da177e4SLinus Torvalds out3: 94743cb76d9SGreg Kroah-Hartman sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward); 9481da177e4SLinus Torvalds out2: 94943cb76d9SGreg Kroah-Hartman sysfs_remove_group(&dev->dev.kobj, &bridge_group); 9501da177e4SLinus Torvalds out1: 9511da177e4SLinus Torvalds return err; 9521da177e4SLinus Torvalds 9531da177e4SLinus Torvalds } 9541da177e4SLinus Torvalds 9551da177e4SLinus Torvalds void br_sysfs_delbr(struct net_device *dev) 9561da177e4SLinus Torvalds { 95743cb76d9SGreg Kroah-Hartman struct kobject *kobj = &dev->dev.kobj; 9581da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 9591da177e4SLinus Torvalds 96078a2d906SGreg Kroah-Hartman kobject_put(br->ifobj); 9611da177e4SLinus Torvalds sysfs_remove_bin_file(kobj, &bridge_forward); 9621da177e4SLinus Torvalds sysfs_remove_group(kobj, &bridge_group); 9631da177e4SLinus Torvalds } 964