11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Sysfs attributes of bridge ports 31da177e4SLinus Torvalds * Linux ethernet bridge 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Authors: 61da177e4SLinus Torvalds * Stephen Hemminger <shemminger@osdl.org> 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or 91da177e4SLinus Torvalds * modify it under the terms of the GNU General Public License 101da177e4SLinus Torvalds * as published by the Free Software Foundation; either version 111da177e4SLinus Torvalds * 2 of the License, or (at your option) any later version. 121da177e4SLinus Torvalds */ 131da177e4SLinus Torvalds 144fc268d2SRandy Dunlap #include <linux/capability.h> 151da177e4SLinus Torvalds #include <linux/kernel.h> 161da177e4SLinus Torvalds #include <linux/netdevice.h> 171da177e4SLinus Torvalds #include <linux/if_bridge.h> 181da177e4SLinus Torvalds #include <linux/rtnetlink.h> 191da177e4SLinus Torvalds #include <linux/spinlock.h> 201da177e4SLinus Torvalds #include <linux/times.h> 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds #include "br_private.h" 231da177e4SLinus Torvalds 2443cb76d9SGreg Kroah-Hartman #define to_dev(obj) container_of(obj, struct device, kobj) 251da177e4SLinus Torvalds #define to_bridge(cd) ((struct net_bridge *)(to_net_dev(cd)->priv)) 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, 321da177e4SLinus Torvalds void (*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; 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds if (!capable(CAP_NET_ADMIN)) 391da177e4SLinus Torvalds return -EPERM; 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds val = simple_strtoul(buf, &endp, 0); 421da177e4SLinus Torvalds if (endp == buf) 431da177e4SLinus Torvalds return -EINVAL; 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds spin_lock_bh(&br->lock); 461da177e4SLinus Torvalds (*set)(br, val); 471da177e4SLinus Torvalds spin_unlock_bh(&br->lock); 481da177e4SLinus Torvalds return len; 491da177e4SLinus Torvalds } 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds 5243cb76d9SGreg Kroah-Hartman static ssize_t show_forward_delay(struct device *d, 5343cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 541da177e4SLinus Torvalds { 5543cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 561da177e4SLinus Torvalds return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay)); 571da177e4SLinus Torvalds } 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds static void set_forward_delay(struct net_bridge *br, unsigned long val) 601da177e4SLinus Torvalds { 611da177e4SLinus Torvalds unsigned long delay = clock_t_to_jiffies(val); 621da177e4SLinus Torvalds br->forward_delay = delay; 631da177e4SLinus Torvalds if (br_is_root_bridge(br)) 641da177e4SLinus Torvalds br->bridge_forward_delay = delay; 651da177e4SLinus Torvalds } 661da177e4SLinus Torvalds 6743cb76d9SGreg Kroah-Hartman static ssize_t store_forward_delay(struct device *d, 6843cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 6943cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 701da177e4SLinus Torvalds { 7143cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_forward_delay); 721da177e4SLinus Torvalds } 7343cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(forward_delay, S_IRUGO | S_IWUSR, 741da177e4SLinus Torvalds show_forward_delay, store_forward_delay); 751da177e4SLinus Torvalds 7643cb76d9SGreg Kroah-Hartman static ssize_t show_hello_time(struct device *d, struct device_attribute *attr, 7743cb76d9SGreg Kroah-Hartman char *buf) 781da177e4SLinus Torvalds { 791da177e4SLinus Torvalds return sprintf(buf, "%lu\n", 8043cb76d9SGreg Kroah-Hartman jiffies_to_clock_t(to_bridge(d)->hello_time)); 811da177e4SLinus Torvalds } 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds static void set_hello_time(struct net_bridge *br, unsigned long val) 841da177e4SLinus Torvalds { 851da177e4SLinus Torvalds unsigned long t = clock_t_to_jiffies(val); 861da177e4SLinus Torvalds br->hello_time = t; 871da177e4SLinus Torvalds if (br_is_root_bridge(br)) 881da177e4SLinus Torvalds br->bridge_hello_time = t; 891da177e4SLinus Torvalds } 901da177e4SLinus Torvalds 9143cb76d9SGreg Kroah-Hartman static ssize_t store_hello_time(struct device *d, 9243cb76d9SGreg Kroah-Hartman struct device_attribute *attr, const char *buf, 931da177e4SLinus Torvalds size_t len) 941da177e4SLinus Torvalds { 9543cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_hello_time); 961da177e4SLinus Torvalds } 9743cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(hello_time, S_IRUGO | S_IWUSR, show_hello_time, 981da177e4SLinus Torvalds store_hello_time); 991da177e4SLinus Torvalds 10043cb76d9SGreg Kroah-Hartman static ssize_t show_max_age(struct device *d, struct device_attribute *attr, 10143cb76d9SGreg Kroah-Hartman char *buf) 1021da177e4SLinus Torvalds { 1031da177e4SLinus Torvalds return sprintf(buf, "%lu\n", 10443cb76d9SGreg Kroah-Hartman jiffies_to_clock_t(to_bridge(d)->max_age)); 1051da177e4SLinus Torvalds } 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds static void set_max_age(struct net_bridge *br, unsigned long val) 1081da177e4SLinus Torvalds { 1091da177e4SLinus Torvalds unsigned long t = clock_t_to_jiffies(val); 1101da177e4SLinus Torvalds br->max_age = t; 1111da177e4SLinus Torvalds if (br_is_root_bridge(br)) 1121da177e4SLinus Torvalds br->bridge_max_age = t; 1131da177e4SLinus Torvalds } 1141da177e4SLinus Torvalds 11543cb76d9SGreg Kroah-Hartman static ssize_t store_max_age(struct device *d, struct device_attribute *attr, 11643cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 1171da177e4SLinus Torvalds { 11843cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_max_age); 1191da177e4SLinus Torvalds } 12043cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(max_age, S_IRUGO | S_IWUSR, show_max_age, store_max_age); 1211da177e4SLinus Torvalds 12243cb76d9SGreg Kroah-Hartman static ssize_t show_ageing_time(struct device *d, 12343cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 1241da177e4SLinus Torvalds { 12543cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1261da177e4SLinus Torvalds return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time)); 1271da177e4SLinus Torvalds } 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds static void set_ageing_time(struct net_bridge *br, unsigned long val) 1301da177e4SLinus Torvalds { 1311da177e4SLinus Torvalds br->ageing_time = clock_t_to_jiffies(val); 1321da177e4SLinus Torvalds } 1331da177e4SLinus Torvalds 13443cb76d9SGreg Kroah-Hartman static ssize_t store_ageing_time(struct device *d, 13543cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 13643cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 1371da177e4SLinus Torvalds { 13843cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_ageing_time); 1391da177e4SLinus Torvalds } 14043cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(ageing_time, S_IRUGO | S_IWUSR, show_ageing_time, 1411da177e4SLinus Torvalds store_ageing_time); 14243cb76d9SGreg Kroah-Hartman 14343cb76d9SGreg Kroah-Hartman static ssize_t show_stp_state(struct device *d, 14443cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 1451da177e4SLinus Torvalds { 14643cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1471da177e4SLinus Torvalds return sprintf(buf, "%d\n", br->stp_enabled); 1481da177e4SLinus Torvalds } 1491da177e4SLinus Torvalds 1501da177e4SLinus Torvalds 15143cb76d9SGreg Kroah-Hartman static ssize_t store_stp_state(struct device *d, 15243cb76d9SGreg Kroah-Hartman struct device_attribute *attr, const char *buf, 15343cb76d9SGreg Kroah-Hartman size_t len) 1541da177e4SLinus Torvalds { 15517120889SStephen Hemminger struct net_bridge *br = to_bridge(d); 15617120889SStephen Hemminger char *endp; 15717120889SStephen Hemminger unsigned long val; 15817120889SStephen Hemminger 15917120889SStephen Hemminger if (!capable(CAP_NET_ADMIN)) 16017120889SStephen Hemminger return -EPERM; 16117120889SStephen Hemminger 16217120889SStephen Hemminger val = simple_strtoul(buf, &endp, 0); 16317120889SStephen Hemminger if (endp == buf) 16417120889SStephen Hemminger return -EINVAL; 16517120889SStephen Hemminger 16617120889SStephen Hemminger rtnl_lock(); 16717120889SStephen Hemminger br_stp_set_enabled(br, val); 16817120889SStephen Hemminger rtnl_unlock(); 16917120889SStephen Hemminger 17035b426c3SAl Viro return len; 1711da177e4SLinus Torvalds } 17243cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(stp_state, S_IRUGO | S_IWUSR, show_stp_state, 1731da177e4SLinus Torvalds store_stp_state); 1741da177e4SLinus Torvalds 17543cb76d9SGreg Kroah-Hartman static ssize_t show_priority(struct device *d, struct device_attribute *attr, 17643cb76d9SGreg Kroah-Hartman char *buf) 1771da177e4SLinus Torvalds { 17843cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1791da177e4SLinus Torvalds return sprintf(buf, "%d\n", 1801da177e4SLinus Torvalds (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]); 1811da177e4SLinus Torvalds } 1821da177e4SLinus Torvalds 1831da177e4SLinus Torvalds static void set_priority(struct net_bridge *br, unsigned long val) 1841da177e4SLinus Torvalds { 1851da177e4SLinus Torvalds br_stp_set_bridge_priority(br, (u16) val); 1861da177e4SLinus Torvalds } 1871da177e4SLinus Torvalds 18843cb76d9SGreg Kroah-Hartman static ssize_t store_priority(struct device *d, struct device_attribute *attr, 1891da177e4SLinus Torvalds const char *buf, size_t len) 1901da177e4SLinus Torvalds { 19143cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_priority); 1921da177e4SLinus Torvalds } 19343cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(priority, S_IRUGO | S_IWUSR, show_priority, store_priority); 1941da177e4SLinus Torvalds 19543cb76d9SGreg Kroah-Hartman static ssize_t show_root_id(struct device *d, struct device_attribute *attr, 19643cb76d9SGreg Kroah-Hartman char *buf) 1971da177e4SLinus Torvalds { 19843cb76d9SGreg Kroah-Hartman return br_show_bridge_id(buf, &to_bridge(d)->designated_root); 1991da177e4SLinus Torvalds } 20043cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_id, S_IRUGO, show_root_id, NULL); 2011da177e4SLinus Torvalds 20243cb76d9SGreg Kroah-Hartman static ssize_t show_bridge_id(struct device *d, struct device_attribute *attr, 20343cb76d9SGreg Kroah-Hartman char *buf) 2041da177e4SLinus Torvalds { 20543cb76d9SGreg Kroah-Hartman return br_show_bridge_id(buf, &to_bridge(d)->bridge_id); 2061da177e4SLinus Torvalds } 20743cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(bridge_id, S_IRUGO, show_bridge_id, NULL); 2081da177e4SLinus Torvalds 20943cb76d9SGreg Kroah-Hartman static ssize_t show_root_port(struct device *d, struct device_attribute *attr, 21043cb76d9SGreg Kroah-Hartman char *buf) 2111da177e4SLinus Torvalds { 21243cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->root_port); 2131da177e4SLinus Torvalds } 21443cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_port, S_IRUGO, show_root_port, NULL); 2151da177e4SLinus Torvalds 21643cb76d9SGreg Kroah-Hartman static ssize_t show_root_path_cost(struct device *d, 21743cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2181da177e4SLinus Torvalds { 21943cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost); 2201da177e4SLinus Torvalds } 22143cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_path_cost, S_IRUGO, show_root_path_cost, NULL); 2221da177e4SLinus Torvalds 22343cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change(struct device *d, 22443cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2251da177e4SLinus Torvalds { 22643cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->topology_change); 2271da177e4SLinus Torvalds } 22843cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change, S_IRUGO, show_topology_change, NULL); 2291da177e4SLinus Torvalds 23043cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change_detected(struct device *d, 23143cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 23243cb76d9SGreg Kroah-Hartman char *buf) 2331da177e4SLinus Torvalds { 23443cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2351da177e4SLinus Torvalds return sprintf(buf, "%d\n", br->topology_change_detected); 2361da177e4SLinus Torvalds } 23743cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change_detected, S_IRUGO, 23843cb76d9SGreg Kroah-Hartman show_topology_change_detected, NULL); 2391da177e4SLinus Torvalds 24043cb76d9SGreg Kroah-Hartman static ssize_t show_hello_timer(struct device *d, 24143cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2421da177e4SLinus Torvalds { 24343cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2441da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer)); 2451da177e4SLinus Torvalds } 24643cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(hello_timer, S_IRUGO, show_hello_timer, NULL); 2471da177e4SLinus Torvalds 24843cb76d9SGreg Kroah-Hartman static ssize_t show_tcn_timer(struct device *d, struct device_attribute *attr, 24943cb76d9SGreg Kroah-Hartman char *buf) 2501da177e4SLinus Torvalds { 25143cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2521da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer)); 2531da177e4SLinus Torvalds } 25443cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(tcn_timer, S_IRUGO, show_tcn_timer, NULL); 2551da177e4SLinus Torvalds 25643cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change_timer(struct device *d, 25743cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 25843cb76d9SGreg Kroah-Hartman char *buf) 2591da177e4SLinus Torvalds { 26043cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2611da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer)); 2621da177e4SLinus Torvalds } 26343cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change_timer, S_IRUGO, show_topology_change_timer, 26443cb76d9SGreg Kroah-Hartman NULL); 2651da177e4SLinus Torvalds 26643cb76d9SGreg Kroah-Hartman static ssize_t show_gc_timer(struct device *d, struct device_attribute *attr, 26743cb76d9SGreg Kroah-Hartman char *buf) 2681da177e4SLinus Torvalds { 26943cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2701da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer)); 2711da177e4SLinus Torvalds } 27243cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(gc_timer, S_IRUGO, show_gc_timer, NULL); 2731da177e4SLinus Torvalds 27443cb76d9SGreg Kroah-Hartman static ssize_t show_group_addr(struct device *d, 27543cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 276fda93d92SStephen Hemminger { 27743cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 278fda93d92SStephen Hemminger return sprintf(buf, "%x:%x:%x:%x:%x:%x\n", 279fda93d92SStephen Hemminger br->group_addr[0], br->group_addr[1], 280fda93d92SStephen Hemminger br->group_addr[2], br->group_addr[3], 281fda93d92SStephen Hemminger br->group_addr[4], br->group_addr[5]); 282fda93d92SStephen Hemminger } 283fda93d92SStephen Hemminger 28443cb76d9SGreg Kroah-Hartman static ssize_t store_group_addr(struct device *d, 28543cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 28643cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 287fda93d92SStephen Hemminger { 28843cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 289fda93d92SStephen Hemminger unsigned new_addr[6]; 290fda93d92SStephen Hemminger int i; 291fda93d92SStephen Hemminger 292fda93d92SStephen Hemminger if (!capable(CAP_NET_ADMIN)) 293fda93d92SStephen Hemminger return -EPERM; 294fda93d92SStephen Hemminger 295fda93d92SStephen Hemminger if (sscanf(buf, "%x:%x:%x:%x:%x:%x", 296fda93d92SStephen Hemminger &new_addr[0], &new_addr[1], &new_addr[2], 297fda93d92SStephen Hemminger &new_addr[3], &new_addr[4], &new_addr[5]) != 6) 298fda93d92SStephen Hemminger return -EINVAL; 299fda93d92SStephen Hemminger 300fda93d92SStephen Hemminger /* Must be 01:80:c2:00:00:0X */ 301fda93d92SStephen Hemminger for (i = 0; i < 5; i++) 302fda93d92SStephen Hemminger if (new_addr[i] != br_group_address[i]) 303fda93d92SStephen Hemminger return -EINVAL; 304fda93d92SStephen Hemminger 305fda93d92SStephen Hemminger if (new_addr[5] & ~0xf) 306fda93d92SStephen Hemminger return -EINVAL; 307fda93d92SStephen Hemminger 308fda93d92SStephen Hemminger if (new_addr[5] == 1 /* 802.3x Pause address */ 309fda93d92SStephen Hemminger || new_addr[5] == 2 /* 802.3ad Slow protocols */ 310fda93d92SStephen Hemminger || new_addr[5] == 3) /* 802.1X PAE address */ 311fda93d92SStephen Hemminger return -EINVAL; 312fda93d92SStephen Hemminger 313fda93d92SStephen Hemminger spin_lock_bh(&br->lock); 314fda93d92SStephen Hemminger for (i = 0; i < 6; i++) 315fda93d92SStephen Hemminger br->group_addr[i] = new_addr[i]; 316fda93d92SStephen Hemminger spin_unlock_bh(&br->lock); 317fda93d92SStephen Hemminger return len; 318fda93d92SStephen Hemminger } 319fda93d92SStephen Hemminger 32043cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(group_addr, S_IRUGO | S_IWUSR, 321fda93d92SStephen Hemminger show_group_addr, store_group_addr); 322fda93d92SStephen Hemminger 3239cf63747SStephen Hemminger static ssize_t store_flush(struct device *d, 3249cf63747SStephen Hemminger struct device_attribute *attr, 3259cf63747SStephen Hemminger const char *buf, size_t len) 3269cf63747SStephen Hemminger { 3279cf63747SStephen Hemminger struct net_bridge *br = to_bridge(d); 3289cf63747SStephen Hemminger 3299cf63747SStephen Hemminger if (!capable(CAP_NET_ADMIN)) 3309cf63747SStephen Hemminger return -EPERM; 3319cf63747SStephen Hemminger 3329cf63747SStephen Hemminger br_fdb_flush(br); 3339cf63747SStephen Hemminger return len; 3349cf63747SStephen Hemminger } 3359cf63747SStephen Hemminger static DEVICE_ATTR(flush, S_IWUSR, NULL, store_flush); 336fda93d92SStephen Hemminger 3371da177e4SLinus Torvalds static struct attribute *bridge_attrs[] = { 33843cb76d9SGreg Kroah-Hartman &dev_attr_forward_delay.attr, 33943cb76d9SGreg Kroah-Hartman &dev_attr_hello_time.attr, 34043cb76d9SGreg Kroah-Hartman &dev_attr_max_age.attr, 34143cb76d9SGreg Kroah-Hartman &dev_attr_ageing_time.attr, 34243cb76d9SGreg Kroah-Hartman &dev_attr_stp_state.attr, 34343cb76d9SGreg Kroah-Hartman &dev_attr_priority.attr, 34443cb76d9SGreg Kroah-Hartman &dev_attr_bridge_id.attr, 34543cb76d9SGreg Kroah-Hartman &dev_attr_root_id.attr, 34643cb76d9SGreg Kroah-Hartman &dev_attr_root_path_cost.attr, 34743cb76d9SGreg Kroah-Hartman &dev_attr_root_port.attr, 34843cb76d9SGreg Kroah-Hartman &dev_attr_topology_change.attr, 34943cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_detected.attr, 35043cb76d9SGreg Kroah-Hartman &dev_attr_hello_timer.attr, 35143cb76d9SGreg Kroah-Hartman &dev_attr_tcn_timer.attr, 35243cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_timer.attr, 35343cb76d9SGreg Kroah-Hartman &dev_attr_gc_timer.attr, 35443cb76d9SGreg Kroah-Hartman &dev_attr_group_addr.attr, 3559cf63747SStephen Hemminger &dev_attr_flush.attr, 3561da177e4SLinus Torvalds NULL 3571da177e4SLinus Torvalds }; 3581da177e4SLinus Torvalds 3591da177e4SLinus Torvalds static struct attribute_group bridge_group = { 3601da177e4SLinus Torvalds .name = SYSFS_BRIDGE_ATTR, 3611da177e4SLinus Torvalds .attrs = bridge_attrs, 3621da177e4SLinus Torvalds }; 3631da177e4SLinus Torvalds 3641da177e4SLinus Torvalds /* 3651da177e4SLinus Torvalds * Export the forwarding information table as a binary file 3661da177e4SLinus Torvalds * The records are struct __fdb_entry. 3671da177e4SLinus Torvalds * 3681da177e4SLinus Torvalds * Returns the number of bytes read. 3691da177e4SLinus Torvalds */ 37091a69029SZhang Rui static ssize_t brforward_read(struct kobject *kobj, 37191a69029SZhang Rui struct bin_attribute *bin_attr, 37291a69029SZhang Rui char *buf, loff_t off, size_t count) 3731da177e4SLinus Torvalds { 37443cb76d9SGreg Kroah-Hartman struct device *dev = to_dev(kobj); 37543cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(dev); 3761da177e4SLinus Torvalds int n; 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds /* must read whole records */ 3791da177e4SLinus Torvalds if (off % sizeof(struct __fdb_entry) != 0) 3801da177e4SLinus Torvalds return -EINVAL; 3811da177e4SLinus Torvalds 3821da177e4SLinus Torvalds n = br_fdb_fillbuf(br, buf, 3831da177e4SLinus Torvalds count / sizeof(struct __fdb_entry), 3841da177e4SLinus Torvalds off / sizeof(struct __fdb_entry)); 3851da177e4SLinus Torvalds 3861da177e4SLinus Torvalds if (n > 0) 3871da177e4SLinus Torvalds n *= sizeof(struct __fdb_entry); 3881da177e4SLinus Torvalds 3891da177e4SLinus Torvalds return n; 3901da177e4SLinus Torvalds } 3911da177e4SLinus Torvalds 3921da177e4SLinus Torvalds static struct bin_attribute bridge_forward = { 3931da177e4SLinus Torvalds .attr = { .name = SYSFS_BRIDGE_FDB, 3947b595756STejun Heo .mode = S_IRUGO, }, 3951da177e4SLinus Torvalds .read = brforward_read, 3961da177e4SLinus Torvalds }; 3971da177e4SLinus Torvalds 3981da177e4SLinus Torvalds /* 3991da177e4SLinus Torvalds * Add entries in sysfs onto the existing network class device 4001da177e4SLinus Torvalds * for the bridge. 4011da177e4SLinus Torvalds * Adds a attribute group "bridge" containing tuning parameters. 4021da177e4SLinus Torvalds * Binary attribute containing the forward table 4031da177e4SLinus Torvalds * Sub directory to hold links to interfaces. 4041da177e4SLinus Torvalds * 4051da177e4SLinus Torvalds * Note: the ifobj exists only to be a subdirectory 4061da177e4SLinus Torvalds * to hold links. The ifobj exists in same data structure 4071da177e4SLinus Torvalds * as it's parent the bridge so reference counting works. 4081da177e4SLinus Torvalds */ 4091da177e4SLinus Torvalds int br_sysfs_addbr(struct net_device *dev) 4101da177e4SLinus Torvalds { 41143cb76d9SGreg Kroah-Hartman struct kobject *brobj = &dev->dev.kobj; 4121da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 4131da177e4SLinus Torvalds int err; 4141da177e4SLinus Torvalds 4151da177e4SLinus Torvalds err = sysfs_create_group(brobj, &bridge_group); 4161da177e4SLinus Torvalds if (err) { 4171da177e4SLinus Torvalds pr_info("%s: can't create group %s/%s\n", 4181da177e4SLinus Torvalds __FUNCTION__, dev->name, bridge_group.name); 4191da177e4SLinus Torvalds goto out1; 4201da177e4SLinus Torvalds } 4211da177e4SLinus Torvalds 4221da177e4SLinus Torvalds err = sysfs_create_bin_file(brobj, &bridge_forward); 4231da177e4SLinus Torvalds if (err) { 4241842c4beSRandy Dunlap pr_info("%s: can't create attribute file %s/%s\n", 4251da177e4SLinus Torvalds __FUNCTION__, dev->name, bridge_forward.attr.name); 4261da177e4SLinus Torvalds goto out2; 4271da177e4SLinus Torvalds } 4281da177e4SLinus Torvalds 429*43b98c4aSGreg Kroah-Hartman br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj); 430*43b98c4aSGreg Kroah-Hartman if (!br->ifobj) { 4311da177e4SLinus Torvalds pr_info("%s: can't add kobject (directory) %s/%s\n", 432*43b98c4aSGreg Kroah-Hartman __FUNCTION__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR); 4331da177e4SLinus Torvalds goto out3; 4341da177e4SLinus Torvalds } 4351da177e4SLinus Torvalds return 0; 4361da177e4SLinus Torvalds out3: 43743cb76d9SGreg Kroah-Hartman sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward); 4381da177e4SLinus Torvalds out2: 43943cb76d9SGreg Kroah-Hartman sysfs_remove_group(&dev->dev.kobj, &bridge_group); 4401da177e4SLinus Torvalds out1: 4411da177e4SLinus Torvalds return err; 4421da177e4SLinus Torvalds 4431da177e4SLinus Torvalds } 4441da177e4SLinus Torvalds 4451da177e4SLinus Torvalds void br_sysfs_delbr(struct net_device *dev) 4461da177e4SLinus Torvalds { 44743cb76d9SGreg Kroah-Hartman struct kobject *kobj = &dev->dev.kobj; 4481da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 4491da177e4SLinus Torvalds 450*43b98c4aSGreg Kroah-Hartman kobject_unregister(br->ifobj); 4511da177e4SLinus Torvalds sysfs_remove_bin_file(kobj, &bridge_forward); 4521da177e4SLinus Torvalds sysfs_remove_group(kobj, &bridge_group); 4531da177e4SLinus Torvalds } 454