11da177e4SLinus Torvalds /* 215401946SWang Sheng-Hui * Sysfs attributes of bridge 31da177e4SLinus Torvalds * Linux ethernet bridge 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Authors: 61da177e4SLinus Torvalds * Stephen Hemminger <shemminger@osdl.org> 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or 91da177e4SLinus Torvalds * modify it under the terms of the GNU General Public License 101da177e4SLinus Torvalds * as published by the Free Software Foundation; either version 111da177e4SLinus Torvalds * 2 of the License, or (at your option) any later version. 121da177e4SLinus Torvalds */ 131da177e4SLinus Torvalds 144fc268d2SRandy Dunlap #include <linux/capability.h> 151da177e4SLinus Torvalds #include <linux/kernel.h> 161da177e4SLinus Torvalds #include <linux/netdevice.h> 17b3343a2aSJohn Fastabend #include <linux/etherdevice.h> 181da177e4SLinus Torvalds #include <linux/if_bridge.h> 191da177e4SLinus Torvalds #include <linux/rtnetlink.h> 201da177e4SLinus Torvalds #include <linux/spinlock.h> 211da177e4SLinus Torvalds #include <linux/times.h> 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds #include "br_private.h" 241da177e4SLinus Torvalds 25524ad0a7SWang Chen #define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd))) 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds /* 281da177e4SLinus Torvalds * Common code for storing bridge parameters. 291da177e4SLinus Torvalds */ 3043cb76d9SGreg Kroah-Hartman static ssize_t store_bridge_parm(struct device *d, 311da177e4SLinus Torvalds const char *buf, size_t len, 328d4698f7SStephen Hemminger int (*set)(struct net_bridge *, unsigned long)) 331da177e4SLinus Torvalds { 3443cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 351da177e4SLinus Torvalds char *endp; 361da177e4SLinus Torvalds unsigned long val; 378d4698f7SStephen Hemminger int err; 381da177e4SLinus Torvalds 39cb990503SEric W. Biederman if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) 401da177e4SLinus Torvalds return -EPERM; 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds val = simple_strtoul(buf, &endp, 0); 431da177e4SLinus Torvalds if (endp == buf) 441da177e4SLinus Torvalds return -EINVAL; 451da177e4SLinus Torvalds 468d4698f7SStephen Hemminger err = (*set)(br, val); 478d4698f7SStephen Hemminger return err ? err : len; 481da177e4SLinus Torvalds } 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds 51fbf2671bSsfeldma@cumulusnetworks.com static ssize_t forward_delay_show(struct device *d, 5243cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 531da177e4SLinus Torvalds { 5443cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 551da177e4SLinus Torvalds return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay)); 561da177e4SLinus Torvalds } 571da177e4SLinus Torvalds 58fbf2671bSsfeldma@cumulusnetworks.com static ssize_t forward_delay_store(struct device *d, 5943cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 6043cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 611da177e4SLinus Torvalds { 6214f98f25Sstephen hemminger return store_bridge_parm(d, buf, len, br_set_forward_delay); 631da177e4SLinus Torvalds } 64fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(forward_delay); 651da177e4SLinus Torvalds 66fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hello_time_show(struct device *d, struct device_attribute *attr, 6743cb76d9SGreg Kroah-Hartman char *buf) 681da177e4SLinus Torvalds { 691da177e4SLinus Torvalds return sprintf(buf, "%lu\n", 7043cb76d9SGreg Kroah-Hartman jiffies_to_clock_t(to_bridge(d)->hello_time)); 711da177e4SLinus Torvalds } 721da177e4SLinus Torvalds 73fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hello_time_store(struct device *d, 7443cb76d9SGreg Kroah-Hartman struct device_attribute *attr, const char *buf, 751da177e4SLinus Torvalds size_t len) 761da177e4SLinus Torvalds { 7714f98f25Sstephen hemminger return store_bridge_parm(d, buf, len, br_set_hello_time); 781da177e4SLinus Torvalds } 79fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(hello_time); 801da177e4SLinus Torvalds 81fbf2671bSsfeldma@cumulusnetworks.com static ssize_t max_age_show(struct device *d, struct device_attribute *attr, 8243cb76d9SGreg Kroah-Hartman char *buf) 831da177e4SLinus Torvalds { 841da177e4SLinus Torvalds return sprintf(buf, "%lu\n", 8543cb76d9SGreg Kroah-Hartman jiffies_to_clock_t(to_bridge(d)->max_age)); 861da177e4SLinus Torvalds } 871da177e4SLinus Torvalds 88fbf2671bSsfeldma@cumulusnetworks.com static ssize_t max_age_store(struct device *d, struct device_attribute *attr, 8943cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 901da177e4SLinus Torvalds { 9114f98f25Sstephen hemminger return store_bridge_parm(d, buf, len, br_set_max_age); 921da177e4SLinus Torvalds } 93fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(max_age); 941da177e4SLinus Torvalds 95fbf2671bSsfeldma@cumulusnetworks.com static ssize_t ageing_time_show(struct device *d, 9643cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 971da177e4SLinus Torvalds { 9843cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 991da177e4SLinus Torvalds return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time)); 1001da177e4SLinus Torvalds } 1011da177e4SLinus Torvalds 1028d4698f7SStephen Hemminger static int set_ageing_time(struct net_bridge *br, unsigned long val) 1031da177e4SLinus Torvalds { 104af379392SNikolay Aleksandrov int ret; 105af379392SNikolay Aleksandrov 106af379392SNikolay Aleksandrov if (!rtnl_trylock()) 107af379392SNikolay Aleksandrov return restart_syscall(); 108af379392SNikolay Aleksandrov 109af379392SNikolay Aleksandrov ret = br_set_ageing_time(br, val); 110af379392SNikolay Aleksandrov rtnl_unlock(); 111af379392SNikolay Aleksandrov 112af379392SNikolay Aleksandrov return ret; 1131da177e4SLinus Torvalds } 1141da177e4SLinus Torvalds 115fbf2671bSsfeldma@cumulusnetworks.com static ssize_t ageing_time_store(struct device *d, 11643cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 11743cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 1181da177e4SLinus Torvalds { 11943cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_ageing_time); 1201da177e4SLinus Torvalds } 121fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(ageing_time); 12243cb76d9SGreg Kroah-Hartman 123fbf2671bSsfeldma@cumulusnetworks.com static ssize_t stp_state_show(struct device *d, 12443cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 1251da177e4SLinus Torvalds { 12643cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1271da177e4SLinus Torvalds return sprintf(buf, "%d\n", br->stp_enabled); 1281da177e4SLinus Torvalds } 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds 131fbf2671bSsfeldma@cumulusnetworks.com static ssize_t stp_state_store(struct device *d, 13243cb76d9SGreg Kroah-Hartman struct device_attribute *attr, const char *buf, 13343cb76d9SGreg Kroah-Hartman size_t len) 1341da177e4SLinus Torvalds { 13517120889SStephen Hemminger struct net_bridge *br = to_bridge(d); 13617120889SStephen Hemminger char *endp; 13717120889SStephen Hemminger unsigned long val; 13817120889SStephen Hemminger 139cb990503SEric W. Biederman if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) 14017120889SStephen Hemminger return -EPERM; 14117120889SStephen Hemminger 14217120889SStephen Hemminger val = simple_strtoul(buf, &endp, 0); 14317120889SStephen Hemminger if (endp == buf) 14417120889SStephen Hemminger return -EINVAL; 14517120889SStephen Hemminger 146af38f298SEric W. Biederman if (!rtnl_trylock()) 147af38f298SEric W. Biederman return restart_syscall(); 14817120889SStephen Hemminger br_stp_set_enabled(br, val); 14917120889SStephen Hemminger rtnl_unlock(); 15017120889SStephen Hemminger 15135b426c3SAl Viro return len; 1521da177e4SLinus Torvalds } 153fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(stp_state); 1541da177e4SLinus Torvalds 155fbf2671bSsfeldma@cumulusnetworks.com static ssize_t group_fwd_mask_show(struct device *d, 156fbf2671bSsfeldma@cumulusnetworks.com struct device_attribute *attr, 157fbf2671bSsfeldma@cumulusnetworks.com char *buf) 158515853ccSstephen hemminger { 159515853ccSstephen hemminger struct net_bridge *br = to_bridge(d); 160515853ccSstephen hemminger return sprintf(buf, "%#x\n", br->group_fwd_mask); 161515853ccSstephen hemminger } 162515853ccSstephen hemminger 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 { 169515853ccSstephen hemminger struct net_bridge *br = to_bridge(d); 170515853ccSstephen hemminger char *endp; 171515853ccSstephen hemminger unsigned long val; 172515853ccSstephen hemminger 173cb990503SEric W. Biederman if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) 174515853ccSstephen hemminger return -EPERM; 175515853ccSstephen hemminger 176515853ccSstephen hemminger val = simple_strtoul(buf, &endp, 0); 177515853ccSstephen hemminger if (endp == buf) 178515853ccSstephen hemminger return -EINVAL; 179515853ccSstephen hemminger 180515853ccSstephen hemminger if (val & BR_GROUPFWD_RESTRICTED) 181515853ccSstephen hemminger return -EINVAL; 182515853ccSstephen hemminger 183515853ccSstephen hemminger br->group_fwd_mask = val; 184515853ccSstephen hemminger 185515853ccSstephen hemminger return len; 186515853ccSstephen hemminger } 187fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(group_fwd_mask); 188515853ccSstephen hemminger 189fbf2671bSsfeldma@cumulusnetworks.com static ssize_t priority_show(struct device *d, struct device_attribute *attr, 19043cb76d9SGreg Kroah-Hartman char *buf) 1911da177e4SLinus Torvalds { 19243cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1931da177e4SLinus Torvalds return sprintf(buf, "%d\n", 1941da177e4SLinus Torvalds (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]); 1951da177e4SLinus Torvalds } 1961da177e4SLinus Torvalds 1978d4698f7SStephen Hemminger static int set_priority(struct net_bridge *br, unsigned long val) 1981da177e4SLinus Torvalds { 1991da177e4SLinus Torvalds br_stp_set_bridge_priority(br, (u16) val); 2008d4698f7SStephen Hemminger return 0; 2011da177e4SLinus Torvalds } 2021da177e4SLinus Torvalds 203fbf2671bSsfeldma@cumulusnetworks.com static ssize_t priority_store(struct device *d, struct device_attribute *attr, 2041da177e4SLinus Torvalds const char *buf, size_t len) 2051da177e4SLinus Torvalds { 20643cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_priority); 2071da177e4SLinus Torvalds } 208fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(priority); 2091da177e4SLinus Torvalds 210fbf2671bSsfeldma@cumulusnetworks.com static ssize_t root_id_show(struct device *d, struct device_attribute *attr, 21143cb76d9SGreg Kroah-Hartman char *buf) 2121da177e4SLinus Torvalds { 21343cb76d9SGreg Kroah-Hartman return br_show_bridge_id(buf, &to_bridge(d)->designated_root); 2141da177e4SLinus Torvalds } 215fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(root_id); 2161da177e4SLinus Torvalds 217fbf2671bSsfeldma@cumulusnetworks.com static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr, 21843cb76d9SGreg Kroah-Hartman char *buf) 2191da177e4SLinus Torvalds { 22043cb76d9SGreg Kroah-Hartman return br_show_bridge_id(buf, &to_bridge(d)->bridge_id); 2211da177e4SLinus Torvalds } 222fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(bridge_id); 2231da177e4SLinus Torvalds 224fbf2671bSsfeldma@cumulusnetworks.com static ssize_t root_port_show(struct device *d, struct device_attribute *attr, 22543cb76d9SGreg Kroah-Hartman char *buf) 2261da177e4SLinus Torvalds { 22743cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->root_port); 2281da177e4SLinus Torvalds } 229fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(root_port); 2301da177e4SLinus Torvalds 231fbf2671bSsfeldma@cumulusnetworks.com static ssize_t root_path_cost_show(struct device *d, 23243cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2331da177e4SLinus Torvalds { 23443cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost); 2351da177e4SLinus Torvalds } 236fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(root_path_cost); 2371da177e4SLinus Torvalds 238fbf2671bSsfeldma@cumulusnetworks.com static ssize_t topology_change_show(struct device *d, 23943cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2401da177e4SLinus Torvalds { 24143cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->topology_change); 2421da177e4SLinus Torvalds } 243fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(topology_change); 2441da177e4SLinus Torvalds 245fbf2671bSsfeldma@cumulusnetworks.com static ssize_t topology_change_detected_show(struct device *d, 24643cb76d9SGreg Kroah-Hartman 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, "%d\n", br->topology_change_detected); 2511da177e4SLinus Torvalds } 252fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(topology_change_detected); 2531da177e4SLinus Torvalds 254fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hello_timer_show(struct device *d, 25543cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2561da177e4SLinus Torvalds { 25743cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2581da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer)); 2591da177e4SLinus Torvalds } 260fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(hello_timer); 2611da177e4SLinus Torvalds 262fbf2671bSsfeldma@cumulusnetworks.com static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr, 26343cb76d9SGreg Kroah-Hartman char *buf) 2641da177e4SLinus Torvalds { 26543cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2661da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer)); 2671da177e4SLinus Torvalds } 268fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(tcn_timer); 2691da177e4SLinus Torvalds 270fbf2671bSsfeldma@cumulusnetworks.com static ssize_t topology_change_timer_show(struct device *d, 27143cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 27243cb76d9SGreg Kroah-Hartman char *buf) 2731da177e4SLinus Torvalds { 27443cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2751da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer)); 2761da177e4SLinus Torvalds } 277fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(topology_change_timer); 2781da177e4SLinus Torvalds 279fbf2671bSsfeldma@cumulusnetworks.com static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr, 28043cb76d9SGreg Kroah-Hartman char *buf) 2811da177e4SLinus Torvalds { 28243cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2831da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer)); 2841da177e4SLinus Torvalds } 285fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RO(gc_timer); 2861da177e4SLinus Torvalds 287fbf2671bSsfeldma@cumulusnetworks.com static ssize_t group_addr_show(struct device *d, 28843cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 289fda93d92SStephen Hemminger { 29043cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 291fda93d92SStephen Hemminger return sprintf(buf, "%x:%x:%x:%x:%x:%x\n", 292fda93d92SStephen Hemminger br->group_addr[0], br->group_addr[1], 293fda93d92SStephen Hemminger br->group_addr[2], br->group_addr[3], 294fda93d92SStephen Hemminger br->group_addr[4], br->group_addr[5]); 295fda93d92SStephen Hemminger } 296fda93d92SStephen Hemminger 297fbf2671bSsfeldma@cumulusnetworks.com static ssize_t group_addr_store(struct device *d, 29843cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 29943cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 300fda93d92SStephen Hemminger { 30143cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 3024197f24bSBen Hutchings u8 new_addr[6]; 303fda93d92SStephen Hemminger int i; 304fda93d92SStephen Hemminger 305cb990503SEric W. Biederman if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) 306fda93d92SStephen Hemminger return -EPERM; 307fda93d92SStephen Hemminger 3084197f24bSBen Hutchings if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", 309fda93d92SStephen Hemminger &new_addr[0], &new_addr[1], &new_addr[2], 310fda93d92SStephen Hemminger &new_addr[3], &new_addr[4], &new_addr[5]) != 6) 311fda93d92SStephen Hemminger return -EINVAL; 312fda93d92SStephen Hemminger 31346acc460SBen Hutchings if (!is_link_local_ether_addr(new_addr)) 314fda93d92SStephen Hemminger return -EINVAL; 315fda93d92SStephen Hemminger 316f64f9e71SJoe Perches if (new_addr[5] == 1 || /* 802.3x Pause address */ 317f64f9e71SJoe Perches new_addr[5] == 2 || /* 802.3ad Slow protocols */ 318f64f9e71SJoe Perches new_addr[5] == 3) /* 802.1X PAE address */ 319fda93d92SStephen Hemminger return -EINVAL; 320fda93d92SStephen Hemminger 321204177f3SToshiaki Makita if (!rtnl_trylock()) 322204177f3SToshiaki Makita return restart_syscall(); 323204177f3SToshiaki Makita 324fda93d92SStephen Hemminger spin_lock_bh(&br->lock); 325fda93d92SStephen Hemminger for (i = 0; i < 6; i++) 326fda93d92SStephen Hemminger br->group_addr[i] = new_addr[i]; 327fda93d92SStephen Hemminger spin_unlock_bh(&br->lock); 328204177f3SToshiaki Makita 329204177f3SToshiaki Makita br->group_addr_set = true; 330204177f3SToshiaki Makita br_recalculate_fwd_mask(br); 331204177f3SToshiaki Makita 332204177f3SToshiaki Makita rtnl_unlock(); 333204177f3SToshiaki Makita 334fda93d92SStephen Hemminger return len; 335fda93d92SStephen Hemminger } 336fda93d92SStephen Hemminger 337fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(group_addr); 338fda93d92SStephen Hemminger 339*14f31bb3SXin Long static int set_flush(struct net_bridge *br, unsigned long val) 340*14f31bb3SXin Long { 341*14f31bb3SXin Long br_fdb_flush(br); 342*14f31bb3SXin Long return 0; 343*14f31bb3SXin Long } 344*14f31bb3SXin Long 345fbf2671bSsfeldma@cumulusnetworks.com static ssize_t flush_store(struct device *d, 3469cf63747SStephen Hemminger struct device_attribute *attr, 3479cf63747SStephen Hemminger const char *buf, size_t len) 3489cf63747SStephen Hemminger { 349*14f31bb3SXin Long return store_bridge_parm(d, buf, len, set_flush); 3509cf63747SStephen Hemminger } 351fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_WO(flush); 352fda93d92SStephen Hemminger 3530909e117SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 354fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_router_show(struct device *d, 3550909e117SHerbert Xu struct device_attribute *attr, char *buf) 3560909e117SHerbert Xu { 3570909e117SHerbert Xu struct net_bridge *br = to_bridge(d); 3580909e117SHerbert Xu return sprintf(buf, "%d\n", br->multicast_router); 3590909e117SHerbert Xu } 3600909e117SHerbert Xu 361fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_router_store(struct device *d, 3620909e117SHerbert Xu struct device_attribute *attr, 3630909e117SHerbert Xu const char *buf, size_t len) 3640909e117SHerbert Xu { 3650909e117SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_router); 3660909e117SHerbert Xu } 367fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_router); 368561f1103SHerbert Xu 369fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_snooping_show(struct device *d, 370561f1103SHerbert Xu struct device_attribute *attr, 371561f1103SHerbert Xu char *buf) 372561f1103SHerbert Xu { 373561f1103SHerbert Xu struct net_bridge *br = to_bridge(d); 374561f1103SHerbert Xu return sprintf(buf, "%d\n", !br->multicast_disabled); 375561f1103SHerbert Xu } 376561f1103SHerbert Xu 377fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_snooping_store(struct device *d, 378561f1103SHerbert Xu struct device_attribute *attr, 379561f1103SHerbert Xu const char *buf, size_t len) 380561f1103SHerbert Xu { 381561f1103SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_toggle); 382561f1103SHerbert Xu } 383fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_snooping); 384b195167fSHerbert Xu 385fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_use_ifaddr_show(struct device *d, 3861c8ad5bfSCong Wang struct device_attribute *attr, 3871c8ad5bfSCong Wang char *buf) 3881c8ad5bfSCong Wang { 3891c8ad5bfSCong Wang struct net_bridge *br = to_bridge(d); 3901c8ad5bfSCong Wang return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr); 3911c8ad5bfSCong Wang } 3921c8ad5bfSCong Wang 3931c8ad5bfSCong Wang static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val) 3941c8ad5bfSCong Wang { 3951c8ad5bfSCong Wang br->multicast_query_use_ifaddr = !!val; 3961c8ad5bfSCong Wang return 0; 3971c8ad5bfSCong Wang } 3981c8ad5bfSCong Wang 3991c8ad5bfSCong Wang static ssize_t 400fbf2671bSsfeldma@cumulusnetworks.com multicast_query_use_ifaddr_store(struct device *d, 4011c8ad5bfSCong Wang struct device_attribute *attr, 4021c8ad5bfSCong Wang const char *buf, size_t len) 4031c8ad5bfSCong Wang { 4041c8ad5bfSCong Wang return store_bridge_parm(d, buf, len, set_query_use_ifaddr); 4051c8ad5bfSCong Wang } 406fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_query_use_ifaddr); 4071c8ad5bfSCong Wang 408fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_show(struct device *d, 409c5c23260SHerbert Xu struct device_attribute *attr, 410c5c23260SHerbert Xu char *buf) 411c5c23260SHerbert Xu { 412c5c23260SHerbert Xu struct net_bridge *br = to_bridge(d); 413c5c23260SHerbert Xu return sprintf(buf, "%d\n", br->multicast_querier); 414c5c23260SHerbert Xu } 415c5c23260SHerbert Xu 416fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_store(struct device *d, 417c5c23260SHerbert Xu struct device_attribute *attr, 418c5c23260SHerbert Xu const char *buf, size_t len) 419c5c23260SHerbert Xu { 420c5c23260SHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_querier); 421c5c23260SHerbert Xu } 422fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_querier); 423c5c23260SHerbert Xu 424fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_elasticity_show(struct device *d, 425b195167fSHerbert Xu struct device_attribute *attr, char *buf) 426b195167fSHerbert Xu { 427b195167fSHerbert Xu struct net_bridge *br = to_bridge(d); 428b195167fSHerbert Xu return sprintf(buf, "%u\n", br->hash_elasticity); 429b195167fSHerbert Xu } 430b195167fSHerbert Xu 431b195167fSHerbert Xu static int set_elasticity(struct net_bridge *br, unsigned long val) 432b195167fSHerbert Xu { 433b195167fSHerbert Xu br->hash_elasticity = val; 434b195167fSHerbert Xu return 0; 435b195167fSHerbert Xu } 436b195167fSHerbert Xu 437fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_elasticity_store(struct device *d, 438b195167fSHerbert Xu struct device_attribute *attr, 439b195167fSHerbert Xu const char *buf, size_t len) 440b195167fSHerbert Xu { 441b195167fSHerbert Xu return store_bridge_parm(d, buf, len, set_elasticity); 442b195167fSHerbert Xu } 443fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(hash_elasticity); 444b195167fSHerbert Xu 445fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_max_show(struct device *d, struct device_attribute *attr, 446b195167fSHerbert Xu char *buf) 447b195167fSHerbert Xu { 448b195167fSHerbert Xu struct net_bridge *br = to_bridge(d); 449b195167fSHerbert Xu return sprintf(buf, "%u\n", br->hash_max); 450b195167fSHerbert Xu } 451b195167fSHerbert Xu 452fbf2671bSsfeldma@cumulusnetworks.com static ssize_t hash_max_store(struct device *d, struct device_attribute *attr, 453b195167fSHerbert Xu const char *buf, size_t len) 454b195167fSHerbert Xu { 455b195167fSHerbert Xu return store_bridge_parm(d, buf, len, br_multicast_set_hash_max); 456b195167fSHerbert Xu } 457fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(hash_max); 458d902eee4SHerbert Xu 459fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_count_show(struct device *d, 460d902eee4SHerbert Xu struct device_attribute *attr, 461d902eee4SHerbert Xu char *buf) 462d902eee4SHerbert Xu { 463d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 464d902eee4SHerbert Xu return sprintf(buf, "%u\n", br->multicast_last_member_count); 465d902eee4SHerbert Xu } 466d902eee4SHerbert Xu 467d902eee4SHerbert Xu static int set_last_member_count(struct net_bridge *br, unsigned long val) 468d902eee4SHerbert Xu { 469d902eee4SHerbert Xu br->multicast_last_member_count = val; 470d902eee4SHerbert Xu return 0; 471d902eee4SHerbert Xu } 472d902eee4SHerbert Xu 473fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_count_store(struct device *d, 474d902eee4SHerbert Xu struct device_attribute *attr, 475d902eee4SHerbert Xu const char *buf, size_t len) 476d902eee4SHerbert Xu { 477d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_last_member_count); 478d902eee4SHerbert Xu } 479fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_last_member_count); 480d902eee4SHerbert Xu 481fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_count_show( 482d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 483d902eee4SHerbert Xu { 484d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 485d902eee4SHerbert Xu return sprintf(buf, "%u\n", br->multicast_startup_query_count); 486d902eee4SHerbert Xu } 487d902eee4SHerbert Xu 488d902eee4SHerbert Xu static int set_startup_query_count(struct net_bridge *br, unsigned long val) 489d902eee4SHerbert Xu { 490d902eee4SHerbert Xu br->multicast_startup_query_count = val; 491d902eee4SHerbert Xu return 0; 492d902eee4SHerbert Xu } 493d902eee4SHerbert Xu 494fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_count_store( 495d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 496d902eee4SHerbert Xu size_t len) 497d902eee4SHerbert Xu { 498d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_startup_query_count); 499d902eee4SHerbert Xu } 500fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_startup_query_count); 501d902eee4SHerbert Xu 502fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_interval_show( 503d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 504d902eee4SHerbert Xu { 505d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 506d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 507d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_last_member_interval)); 508d902eee4SHerbert Xu } 509d902eee4SHerbert Xu 510d902eee4SHerbert Xu static int set_last_member_interval(struct net_bridge *br, unsigned long val) 511d902eee4SHerbert Xu { 512d902eee4SHerbert Xu br->multicast_last_member_interval = clock_t_to_jiffies(val); 513d902eee4SHerbert Xu return 0; 514d902eee4SHerbert Xu } 515d902eee4SHerbert Xu 516fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_last_member_interval_store( 517d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 518d902eee4SHerbert Xu size_t len) 519d902eee4SHerbert Xu { 520d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_last_member_interval); 521d902eee4SHerbert Xu } 522fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_last_member_interval); 523d902eee4SHerbert Xu 524fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_membership_interval_show( 525d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 526d902eee4SHerbert Xu { 527d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 528d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 529d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_membership_interval)); 530d902eee4SHerbert Xu } 531d902eee4SHerbert Xu 532d902eee4SHerbert Xu static int set_membership_interval(struct net_bridge *br, unsigned long val) 533d902eee4SHerbert Xu { 534d902eee4SHerbert Xu br->multicast_membership_interval = clock_t_to_jiffies(val); 535d902eee4SHerbert Xu return 0; 536d902eee4SHerbert Xu } 537d902eee4SHerbert Xu 538fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_membership_interval_store( 539d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 540d902eee4SHerbert Xu size_t len) 541d902eee4SHerbert Xu { 542d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_membership_interval); 543d902eee4SHerbert Xu } 544fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_membership_interval); 545d902eee4SHerbert Xu 546fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_interval_show(struct device *d, 547d902eee4SHerbert Xu struct device_attribute *attr, 548d902eee4SHerbert Xu char *buf) 549d902eee4SHerbert Xu { 550d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 551d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 552d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_querier_interval)); 553d902eee4SHerbert Xu } 554d902eee4SHerbert Xu 555d902eee4SHerbert Xu static int set_querier_interval(struct net_bridge *br, unsigned long val) 556d902eee4SHerbert Xu { 557d902eee4SHerbert Xu br->multicast_querier_interval = clock_t_to_jiffies(val); 558d902eee4SHerbert Xu return 0; 559d902eee4SHerbert Xu } 560d902eee4SHerbert Xu 561fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_querier_interval_store(struct device *d, 562d902eee4SHerbert Xu struct device_attribute *attr, 563d902eee4SHerbert Xu const char *buf, size_t len) 564d902eee4SHerbert Xu { 565d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_querier_interval); 566d902eee4SHerbert Xu } 567fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_querier_interval); 568d902eee4SHerbert Xu 569fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_interval_show(struct device *d, 570d902eee4SHerbert Xu struct device_attribute *attr, 571d902eee4SHerbert Xu char *buf) 572d902eee4SHerbert Xu { 573d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 574d902eee4SHerbert Xu return sprintf(buf, "%lu\n", 575d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_query_interval)); 576d902eee4SHerbert Xu } 577d902eee4SHerbert Xu 578d902eee4SHerbert Xu static int set_query_interval(struct net_bridge *br, unsigned long val) 579d902eee4SHerbert Xu { 580d902eee4SHerbert Xu br->multicast_query_interval = clock_t_to_jiffies(val); 581d902eee4SHerbert Xu return 0; 582d902eee4SHerbert Xu } 583d902eee4SHerbert Xu 584fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_interval_store(struct device *d, 585d902eee4SHerbert Xu struct device_attribute *attr, 586d902eee4SHerbert Xu const char *buf, size_t len) 587d902eee4SHerbert Xu { 588d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_query_interval); 589d902eee4SHerbert Xu } 590fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_query_interval); 591d902eee4SHerbert Xu 592fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_response_interval_show( 593d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 594d902eee4SHerbert Xu { 595d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 596d902eee4SHerbert Xu return sprintf( 597d902eee4SHerbert Xu buf, "%lu\n", 598d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_query_response_interval)); 599d902eee4SHerbert Xu } 600d902eee4SHerbert Xu 601d902eee4SHerbert Xu static int set_query_response_interval(struct net_bridge *br, unsigned long val) 602d902eee4SHerbert Xu { 603d902eee4SHerbert Xu br->multicast_query_response_interval = clock_t_to_jiffies(val); 604d902eee4SHerbert Xu return 0; 605d902eee4SHerbert Xu } 606d902eee4SHerbert Xu 607fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_query_response_interval_store( 608d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 609d902eee4SHerbert Xu size_t len) 610d902eee4SHerbert Xu { 611d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_query_response_interval); 612d902eee4SHerbert Xu } 613fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_query_response_interval); 614d902eee4SHerbert Xu 615fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_interval_show( 616d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, char *buf) 617d902eee4SHerbert Xu { 618d902eee4SHerbert Xu struct net_bridge *br = to_bridge(d); 619d902eee4SHerbert Xu return sprintf( 620d902eee4SHerbert Xu buf, "%lu\n", 621d902eee4SHerbert Xu jiffies_to_clock_t(br->multicast_startup_query_interval)); 622d902eee4SHerbert Xu } 623d902eee4SHerbert Xu 624d902eee4SHerbert Xu static int set_startup_query_interval(struct net_bridge *br, unsigned long val) 625d902eee4SHerbert Xu { 626d902eee4SHerbert Xu br->multicast_startup_query_interval = clock_t_to_jiffies(val); 627d902eee4SHerbert Xu return 0; 628d902eee4SHerbert Xu } 629d902eee4SHerbert Xu 630fbf2671bSsfeldma@cumulusnetworks.com static ssize_t multicast_startup_query_interval_store( 631d902eee4SHerbert Xu struct device *d, struct device_attribute *attr, const char *buf, 632d902eee4SHerbert Xu size_t len) 633d902eee4SHerbert Xu { 634d902eee4SHerbert Xu return store_bridge_parm(d, buf, len, set_startup_query_interval); 635d902eee4SHerbert Xu } 636fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(multicast_startup_query_interval); 6370909e117SHerbert Xu #endif 63834666d46SPablo Neira Ayuso #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 639fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_iptables_show( 6404df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 6414df53d8bSPatrick McHardy { 6424df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 6434df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_iptables); 6444df53d8bSPatrick McHardy } 6454df53d8bSPatrick McHardy 6464df53d8bSPatrick McHardy static int set_nf_call_iptables(struct net_bridge *br, unsigned long val) 6474df53d8bSPatrick McHardy { 6484df53d8bSPatrick McHardy br->nf_call_iptables = val ? true : false; 6494df53d8bSPatrick McHardy return 0; 6504df53d8bSPatrick McHardy } 6514df53d8bSPatrick McHardy 652fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_iptables_store( 6534df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 6544df53d8bSPatrick McHardy size_t len) 6554df53d8bSPatrick McHardy { 6564df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_iptables); 6574df53d8bSPatrick McHardy } 658fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(nf_call_iptables); 6594df53d8bSPatrick McHardy 660fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_ip6tables_show( 6614df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 6624df53d8bSPatrick McHardy { 6634df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 6644df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_ip6tables); 6654df53d8bSPatrick McHardy } 6664df53d8bSPatrick McHardy 6674df53d8bSPatrick McHardy static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val) 6684df53d8bSPatrick McHardy { 6694df53d8bSPatrick McHardy br->nf_call_ip6tables = val ? true : false; 6704df53d8bSPatrick McHardy return 0; 6714df53d8bSPatrick McHardy } 6724df53d8bSPatrick McHardy 673fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_ip6tables_store( 6744df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 6754df53d8bSPatrick McHardy size_t len) 6764df53d8bSPatrick McHardy { 6774df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_ip6tables); 6784df53d8bSPatrick McHardy } 679fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(nf_call_ip6tables); 6804df53d8bSPatrick McHardy 681fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_arptables_show( 6824df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, char *buf) 6834df53d8bSPatrick McHardy { 6844df53d8bSPatrick McHardy struct net_bridge *br = to_bridge(d); 6854df53d8bSPatrick McHardy return sprintf(buf, "%u\n", br->nf_call_arptables); 6864df53d8bSPatrick McHardy } 6874df53d8bSPatrick McHardy 6884df53d8bSPatrick McHardy static int set_nf_call_arptables(struct net_bridge *br, unsigned long val) 6894df53d8bSPatrick McHardy { 6904df53d8bSPatrick McHardy br->nf_call_arptables = val ? true : false; 6914df53d8bSPatrick McHardy return 0; 6924df53d8bSPatrick McHardy } 6934df53d8bSPatrick McHardy 694fbf2671bSsfeldma@cumulusnetworks.com static ssize_t nf_call_arptables_store( 6954df53d8bSPatrick McHardy struct device *d, struct device_attribute *attr, const char *buf, 6964df53d8bSPatrick McHardy size_t len) 6974df53d8bSPatrick McHardy { 6984df53d8bSPatrick McHardy return store_bridge_parm(d, buf, len, set_nf_call_arptables); 6994df53d8bSPatrick McHardy } 700fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(nf_call_arptables); 7014df53d8bSPatrick McHardy #endif 702243a2e63SVlad Yasevich #ifdef CONFIG_BRIDGE_VLAN_FILTERING 703fbf2671bSsfeldma@cumulusnetworks.com static ssize_t vlan_filtering_show(struct device *d, 704243a2e63SVlad Yasevich struct device_attribute *attr, 705243a2e63SVlad Yasevich char *buf) 706243a2e63SVlad Yasevich { 707243a2e63SVlad Yasevich struct net_bridge *br = to_bridge(d); 708243a2e63SVlad Yasevich return sprintf(buf, "%d\n", br->vlan_enabled); 709243a2e63SVlad Yasevich } 710243a2e63SVlad Yasevich 711fbf2671bSsfeldma@cumulusnetworks.com static ssize_t vlan_filtering_store(struct device *d, 712243a2e63SVlad Yasevich struct device_attribute *attr, 713243a2e63SVlad Yasevich const char *buf, size_t len) 714243a2e63SVlad Yasevich { 715243a2e63SVlad Yasevich return store_bridge_parm(d, buf, len, br_vlan_filter_toggle); 716243a2e63SVlad Yasevich } 717fbf2671bSsfeldma@cumulusnetworks.com static DEVICE_ATTR_RW(vlan_filtering); 718204177f3SToshiaki Makita 719204177f3SToshiaki Makita static ssize_t vlan_protocol_show(struct device *d, 720204177f3SToshiaki Makita struct device_attribute *attr, 721204177f3SToshiaki Makita char *buf) 722204177f3SToshiaki Makita { 723204177f3SToshiaki Makita struct net_bridge *br = to_bridge(d); 724204177f3SToshiaki Makita return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto)); 725204177f3SToshiaki Makita } 726204177f3SToshiaki Makita 727204177f3SToshiaki Makita static ssize_t vlan_protocol_store(struct device *d, 728204177f3SToshiaki Makita struct device_attribute *attr, 729204177f3SToshiaki Makita const char *buf, size_t len) 730204177f3SToshiaki Makita { 731204177f3SToshiaki Makita return store_bridge_parm(d, buf, len, br_vlan_set_proto); 732204177f3SToshiaki Makita } 733204177f3SToshiaki Makita static DEVICE_ATTR_RW(vlan_protocol); 73496a20d9dSVlad Yasevich 73596a20d9dSVlad Yasevich static ssize_t default_pvid_show(struct device *d, 73696a20d9dSVlad Yasevich struct device_attribute *attr, 73796a20d9dSVlad Yasevich char *buf) 73896a20d9dSVlad Yasevich { 73996a20d9dSVlad Yasevich struct net_bridge *br = to_bridge(d); 74096a20d9dSVlad Yasevich return sprintf(buf, "%d\n", br->default_pvid); 74196a20d9dSVlad Yasevich } 74296a20d9dSVlad Yasevich 74396a20d9dSVlad Yasevich static ssize_t default_pvid_store(struct device *d, 74496a20d9dSVlad Yasevich struct device_attribute *attr, 74596a20d9dSVlad Yasevich const char *buf, size_t len) 74696a20d9dSVlad Yasevich { 74796a20d9dSVlad Yasevich return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid); 74896a20d9dSVlad Yasevich } 74996a20d9dSVlad Yasevich static DEVICE_ATTR_RW(default_pvid); 750243a2e63SVlad Yasevich #endif 7510909e117SHerbert Xu 7521da177e4SLinus Torvalds static struct attribute *bridge_attrs[] = { 75343cb76d9SGreg Kroah-Hartman &dev_attr_forward_delay.attr, 75443cb76d9SGreg Kroah-Hartman &dev_attr_hello_time.attr, 75543cb76d9SGreg Kroah-Hartman &dev_attr_max_age.attr, 75643cb76d9SGreg Kroah-Hartman &dev_attr_ageing_time.attr, 75743cb76d9SGreg Kroah-Hartman &dev_attr_stp_state.attr, 758515853ccSstephen hemminger &dev_attr_group_fwd_mask.attr, 75943cb76d9SGreg Kroah-Hartman &dev_attr_priority.attr, 76043cb76d9SGreg Kroah-Hartman &dev_attr_bridge_id.attr, 76143cb76d9SGreg Kroah-Hartman &dev_attr_root_id.attr, 76243cb76d9SGreg Kroah-Hartman &dev_attr_root_path_cost.attr, 76343cb76d9SGreg Kroah-Hartman &dev_attr_root_port.attr, 76443cb76d9SGreg Kroah-Hartman &dev_attr_topology_change.attr, 76543cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_detected.attr, 76643cb76d9SGreg Kroah-Hartman &dev_attr_hello_timer.attr, 76743cb76d9SGreg Kroah-Hartman &dev_attr_tcn_timer.attr, 76843cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_timer.attr, 76943cb76d9SGreg Kroah-Hartman &dev_attr_gc_timer.attr, 77043cb76d9SGreg Kroah-Hartman &dev_attr_group_addr.attr, 7719cf63747SStephen Hemminger &dev_attr_flush.attr, 7720909e117SHerbert Xu #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 7730909e117SHerbert Xu &dev_attr_multicast_router.attr, 774561f1103SHerbert Xu &dev_attr_multicast_snooping.attr, 775c5c23260SHerbert Xu &dev_attr_multicast_querier.attr, 7761c8ad5bfSCong Wang &dev_attr_multicast_query_use_ifaddr.attr, 777b195167fSHerbert Xu &dev_attr_hash_elasticity.attr, 778b195167fSHerbert Xu &dev_attr_hash_max.attr, 779d902eee4SHerbert Xu &dev_attr_multicast_last_member_count.attr, 780d902eee4SHerbert Xu &dev_attr_multicast_startup_query_count.attr, 781d902eee4SHerbert Xu &dev_attr_multicast_last_member_interval.attr, 782d902eee4SHerbert Xu &dev_attr_multicast_membership_interval.attr, 783d902eee4SHerbert Xu &dev_attr_multicast_querier_interval.attr, 784d902eee4SHerbert Xu &dev_attr_multicast_query_interval.attr, 785d902eee4SHerbert Xu &dev_attr_multicast_query_response_interval.attr, 786d902eee4SHerbert Xu &dev_attr_multicast_startup_query_interval.attr, 7870909e117SHerbert Xu #endif 78834666d46SPablo Neira Ayuso #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 7894df53d8bSPatrick McHardy &dev_attr_nf_call_iptables.attr, 7904df53d8bSPatrick McHardy &dev_attr_nf_call_ip6tables.attr, 7914df53d8bSPatrick McHardy &dev_attr_nf_call_arptables.attr, 7924df53d8bSPatrick McHardy #endif 793243a2e63SVlad Yasevich #ifdef CONFIG_BRIDGE_VLAN_FILTERING 794243a2e63SVlad Yasevich &dev_attr_vlan_filtering.attr, 795204177f3SToshiaki Makita &dev_attr_vlan_protocol.attr, 79696a20d9dSVlad Yasevich &dev_attr_default_pvid.attr, 797243a2e63SVlad Yasevich #endif 7981da177e4SLinus Torvalds NULL 7991da177e4SLinus Torvalds }; 8001da177e4SLinus Torvalds 8011da177e4SLinus Torvalds static struct attribute_group bridge_group = { 8021da177e4SLinus Torvalds .name = SYSFS_BRIDGE_ATTR, 8031da177e4SLinus Torvalds .attrs = bridge_attrs, 8041da177e4SLinus Torvalds }; 8051da177e4SLinus Torvalds 8061da177e4SLinus Torvalds /* 8071da177e4SLinus Torvalds * Export the forwarding information table as a binary file 8081da177e4SLinus Torvalds * The records are struct __fdb_entry. 8091da177e4SLinus Torvalds * 8101da177e4SLinus Torvalds * Returns the number of bytes read. 8111da177e4SLinus Torvalds */ 8122c3c8beaSChris Wright static ssize_t brforward_read(struct file *filp, struct kobject *kobj, 81391a69029SZhang Rui struct bin_attribute *bin_attr, 81491a69029SZhang Rui char *buf, loff_t off, size_t count) 8151da177e4SLinus Torvalds { 816aeb7ed14SGeliang Tang struct device *dev = kobj_to_dev(kobj); 81743cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(dev); 8181da177e4SLinus Torvalds int n; 8191da177e4SLinus Torvalds 8201da177e4SLinus Torvalds /* must read whole records */ 8211da177e4SLinus Torvalds if (off % sizeof(struct __fdb_entry) != 0) 8221da177e4SLinus Torvalds return -EINVAL; 8231da177e4SLinus Torvalds 8241da177e4SLinus Torvalds n = br_fdb_fillbuf(br, buf, 8251da177e4SLinus Torvalds count / sizeof(struct __fdb_entry), 8261da177e4SLinus Torvalds off / sizeof(struct __fdb_entry)); 8271da177e4SLinus Torvalds 8281da177e4SLinus Torvalds if (n > 0) 8291da177e4SLinus Torvalds n *= sizeof(struct __fdb_entry); 8301da177e4SLinus Torvalds 8311da177e4SLinus Torvalds return n; 8321da177e4SLinus Torvalds } 8331da177e4SLinus Torvalds 8341da177e4SLinus Torvalds static struct bin_attribute bridge_forward = { 8351da177e4SLinus Torvalds .attr = { .name = SYSFS_BRIDGE_FDB, 8367b595756STejun Heo .mode = S_IRUGO, }, 8371da177e4SLinus Torvalds .read = brforward_read, 8381da177e4SLinus Torvalds }; 8391da177e4SLinus Torvalds 8401da177e4SLinus Torvalds /* 8411da177e4SLinus Torvalds * Add entries in sysfs onto the existing network class device 8421da177e4SLinus Torvalds * for the bridge. 8431da177e4SLinus Torvalds * Adds a attribute group "bridge" containing tuning parameters. 8441da177e4SLinus Torvalds * Binary attribute containing the forward table 8451da177e4SLinus Torvalds * Sub directory to hold links to interfaces. 8461da177e4SLinus Torvalds * 8471da177e4SLinus Torvalds * Note: the ifobj exists only to be a subdirectory 8481da177e4SLinus Torvalds * to hold links. The ifobj exists in same data structure 8491da177e4SLinus Torvalds * as it's parent the bridge so reference counting works. 8501da177e4SLinus Torvalds */ 8511da177e4SLinus Torvalds int br_sysfs_addbr(struct net_device *dev) 8521da177e4SLinus Torvalds { 85343cb76d9SGreg Kroah-Hartman struct kobject *brobj = &dev->dev.kobj; 8541da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 8551da177e4SLinus Torvalds int err; 8561da177e4SLinus Torvalds 8571da177e4SLinus Torvalds err = sysfs_create_group(brobj, &bridge_group); 8581da177e4SLinus Torvalds if (err) { 8591da177e4SLinus Torvalds pr_info("%s: can't create group %s/%s\n", 8600dc47877SHarvey Harrison __func__, dev->name, bridge_group.name); 8611da177e4SLinus Torvalds goto out1; 8621da177e4SLinus Torvalds } 8631da177e4SLinus Torvalds 8641da177e4SLinus Torvalds err = sysfs_create_bin_file(brobj, &bridge_forward); 8651da177e4SLinus Torvalds if (err) { 8661842c4beSRandy Dunlap pr_info("%s: can't create attribute file %s/%s\n", 8670dc47877SHarvey Harrison __func__, dev->name, bridge_forward.attr.name); 8681da177e4SLinus Torvalds goto out2; 8691da177e4SLinus Torvalds } 8701da177e4SLinus Torvalds 87143b98c4aSGreg Kroah-Hartman br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj); 87243b98c4aSGreg Kroah-Hartman if (!br->ifobj) { 8731da177e4SLinus Torvalds pr_info("%s: can't add kobject (directory) %s/%s\n", 8740dc47877SHarvey Harrison __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR); 8751da177e4SLinus Torvalds goto out3; 8761da177e4SLinus Torvalds } 8771da177e4SLinus Torvalds return 0; 8781da177e4SLinus Torvalds out3: 87943cb76d9SGreg Kroah-Hartman sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward); 8801da177e4SLinus Torvalds out2: 88143cb76d9SGreg Kroah-Hartman sysfs_remove_group(&dev->dev.kobj, &bridge_group); 8821da177e4SLinus Torvalds out1: 8831da177e4SLinus Torvalds return err; 8841da177e4SLinus Torvalds 8851da177e4SLinus Torvalds } 8861da177e4SLinus Torvalds 8871da177e4SLinus Torvalds void br_sysfs_delbr(struct net_device *dev) 8881da177e4SLinus Torvalds { 88943cb76d9SGreg Kroah-Hartman struct kobject *kobj = &dev->dev.kobj; 8901da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 8911da177e4SLinus Torvalds 89278a2d906SGreg Kroah-Hartman kobject_put(br->ifobj); 8931da177e4SLinus Torvalds sysfs_remove_bin_file(kobj, &bridge_forward); 8941da177e4SLinus Torvalds sysfs_remove_group(kobj, &bridge_group); 8951da177e4SLinus Torvalds } 896