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) 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 391da177e4SLinus Torvalds if (!capable(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 461da177e4SLinus Torvalds spin_lock_bh(&br->lock); 478d4698f7SStephen Hemminger err = (*set)(br, val); 481da177e4SLinus Torvalds spin_unlock_bh(&br->lock); 498d4698f7SStephen Hemminger return err ? err : len; 501da177e4SLinus Torvalds } 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds 5343cb76d9SGreg Kroah-Hartman static ssize_t show_forward_delay(struct device *d, 5443cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 551da177e4SLinus Torvalds { 5643cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 571da177e4SLinus Torvalds return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay)); 581da177e4SLinus Torvalds } 591da177e4SLinus Torvalds 608d4698f7SStephen Hemminger static int set_forward_delay(struct net_bridge *br, unsigned long val) 611da177e4SLinus Torvalds { 621da177e4SLinus Torvalds unsigned long delay = clock_t_to_jiffies(val); 631da177e4SLinus Torvalds br->forward_delay = delay; 641da177e4SLinus Torvalds if (br_is_root_bridge(br)) 651da177e4SLinus Torvalds br->bridge_forward_delay = delay; 668d4698f7SStephen Hemminger return 0; 671da177e4SLinus Torvalds } 681da177e4SLinus Torvalds 6943cb76d9SGreg Kroah-Hartman static ssize_t store_forward_delay(struct device *d, 7043cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 7143cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 721da177e4SLinus Torvalds { 7343cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_forward_delay); 741da177e4SLinus Torvalds } 7543cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(forward_delay, S_IRUGO | S_IWUSR, 761da177e4SLinus Torvalds show_forward_delay, store_forward_delay); 771da177e4SLinus Torvalds 7843cb76d9SGreg Kroah-Hartman static ssize_t show_hello_time(struct device *d, struct device_attribute *attr, 7943cb76d9SGreg Kroah-Hartman char *buf) 801da177e4SLinus Torvalds { 811da177e4SLinus Torvalds return sprintf(buf, "%lu\n", 8243cb76d9SGreg Kroah-Hartman jiffies_to_clock_t(to_bridge(d)->hello_time)); 831da177e4SLinus Torvalds } 841da177e4SLinus Torvalds 858d4698f7SStephen Hemminger static int set_hello_time(struct net_bridge *br, unsigned long val) 861da177e4SLinus Torvalds { 871da177e4SLinus Torvalds unsigned long t = clock_t_to_jiffies(val); 888d4698f7SStephen Hemminger 898d4698f7SStephen Hemminger if (t < HZ) 908d4698f7SStephen Hemminger return -EINVAL; 918d4698f7SStephen Hemminger 921da177e4SLinus Torvalds br->hello_time = t; 931da177e4SLinus Torvalds if (br_is_root_bridge(br)) 941da177e4SLinus Torvalds br->bridge_hello_time = t; 958d4698f7SStephen Hemminger return 0; 961da177e4SLinus Torvalds } 971da177e4SLinus Torvalds 9843cb76d9SGreg Kroah-Hartman static ssize_t store_hello_time(struct device *d, 9943cb76d9SGreg Kroah-Hartman struct device_attribute *attr, const char *buf, 1001da177e4SLinus Torvalds size_t len) 1011da177e4SLinus Torvalds { 10243cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_hello_time); 1031da177e4SLinus Torvalds } 10443cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(hello_time, S_IRUGO | S_IWUSR, show_hello_time, 1051da177e4SLinus Torvalds store_hello_time); 1061da177e4SLinus Torvalds 10743cb76d9SGreg Kroah-Hartman static ssize_t show_max_age(struct device *d, struct device_attribute *attr, 10843cb76d9SGreg Kroah-Hartman char *buf) 1091da177e4SLinus Torvalds { 1101da177e4SLinus Torvalds return sprintf(buf, "%lu\n", 11143cb76d9SGreg Kroah-Hartman jiffies_to_clock_t(to_bridge(d)->max_age)); 1121da177e4SLinus Torvalds } 1131da177e4SLinus Torvalds 1148d4698f7SStephen Hemminger static int set_max_age(struct net_bridge *br, unsigned long val) 1151da177e4SLinus Torvalds { 1161da177e4SLinus Torvalds unsigned long t = clock_t_to_jiffies(val); 1171da177e4SLinus Torvalds br->max_age = t; 1181da177e4SLinus Torvalds if (br_is_root_bridge(br)) 1191da177e4SLinus Torvalds br->bridge_max_age = t; 1208d4698f7SStephen Hemminger return 0; 1211da177e4SLinus Torvalds } 1221da177e4SLinus Torvalds 12343cb76d9SGreg Kroah-Hartman static ssize_t store_max_age(struct device *d, struct device_attribute *attr, 12443cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 1251da177e4SLinus Torvalds { 12643cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_max_age); 1271da177e4SLinus Torvalds } 12843cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(max_age, S_IRUGO | S_IWUSR, show_max_age, store_max_age); 1291da177e4SLinus Torvalds 13043cb76d9SGreg Kroah-Hartman static ssize_t show_ageing_time(struct device *d, 13143cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 1321da177e4SLinus Torvalds { 13343cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1341da177e4SLinus Torvalds return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time)); 1351da177e4SLinus Torvalds } 1361da177e4SLinus Torvalds 1378d4698f7SStephen Hemminger static int set_ageing_time(struct net_bridge *br, unsigned long val) 1381da177e4SLinus Torvalds { 1391da177e4SLinus Torvalds br->ageing_time = clock_t_to_jiffies(val); 1408d4698f7SStephen Hemminger return 0; 1411da177e4SLinus Torvalds } 1421da177e4SLinus Torvalds 14343cb76d9SGreg Kroah-Hartman static ssize_t store_ageing_time(struct device *d, 14443cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 14543cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 1461da177e4SLinus Torvalds { 14743cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_ageing_time); 1481da177e4SLinus Torvalds } 14943cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(ageing_time, S_IRUGO | S_IWUSR, show_ageing_time, 1501da177e4SLinus Torvalds store_ageing_time); 15143cb76d9SGreg Kroah-Hartman 15243cb76d9SGreg Kroah-Hartman static ssize_t show_stp_state(struct device *d, 15343cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 1541da177e4SLinus Torvalds { 15543cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1561da177e4SLinus Torvalds return sprintf(buf, "%d\n", br->stp_enabled); 1571da177e4SLinus Torvalds } 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvalds 16043cb76d9SGreg Kroah-Hartman static ssize_t store_stp_state(struct device *d, 16143cb76d9SGreg Kroah-Hartman struct device_attribute *attr, const char *buf, 16243cb76d9SGreg Kroah-Hartman size_t len) 1631da177e4SLinus Torvalds { 16417120889SStephen Hemminger struct net_bridge *br = to_bridge(d); 16517120889SStephen Hemminger char *endp; 16617120889SStephen Hemminger unsigned long val; 16717120889SStephen Hemminger 16817120889SStephen Hemminger if (!capable(CAP_NET_ADMIN)) 16917120889SStephen Hemminger return -EPERM; 17017120889SStephen Hemminger 17117120889SStephen Hemminger val = simple_strtoul(buf, &endp, 0); 17217120889SStephen Hemminger if (endp == buf) 17317120889SStephen Hemminger return -EINVAL; 17417120889SStephen Hemminger 175af38f298SEric W. Biederman if (!rtnl_trylock()) 176af38f298SEric W. Biederman return restart_syscall(); 17717120889SStephen Hemminger br_stp_set_enabled(br, val); 17817120889SStephen Hemminger rtnl_unlock(); 17917120889SStephen Hemminger 18035b426c3SAl Viro return len; 1811da177e4SLinus Torvalds } 18243cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(stp_state, S_IRUGO | S_IWUSR, show_stp_state, 1831da177e4SLinus Torvalds store_stp_state); 1841da177e4SLinus Torvalds 18543cb76d9SGreg Kroah-Hartman static ssize_t show_priority(struct device *d, struct device_attribute *attr, 18643cb76d9SGreg Kroah-Hartman char *buf) 1871da177e4SLinus Torvalds { 18843cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1891da177e4SLinus Torvalds return sprintf(buf, "%d\n", 1901da177e4SLinus Torvalds (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]); 1911da177e4SLinus Torvalds } 1921da177e4SLinus Torvalds 1938d4698f7SStephen Hemminger static int set_priority(struct net_bridge *br, unsigned long val) 1941da177e4SLinus Torvalds { 1951da177e4SLinus Torvalds br_stp_set_bridge_priority(br, (u16) val); 1968d4698f7SStephen Hemminger return 0; 1971da177e4SLinus Torvalds } 1981da177e4SLinus Torvalds 19943cb76d9SGreg Kroah-Hartman static ssize_t store_priority(struct device *d, struct device_attribute *attr, 2001da177e4SLinus Torvalds const char *buf, size_t len) 2011da177e4SLinus Torvalds { 20243cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_priority); 2031da177e4SLinus Torvalds } 20443cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(priority, S_IRUGO | S_IWUSR, show_priority, store_priority); 2051da177e4SLinus Torvalds 20643cb76d9SGreg Kroah-Hartman static ssize_t show_root_id(struct device *d, struct device_attribute *attr, 20743cb76d9SGreg Kroah-Hartman char *buf) 2081da177e4SLinus Torvalds { 20943cb76d9SGreg Kroah-Hartman return br_show_bridge_id(buf, &to_bridge(d)->designated_root); 2101da177e4SLinus Torvalds } 21143cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_id, S_IRUGO, show_root_id, NULL); 2121da177e4SLinus Torvalds 21343cb76d9SGreg Kroah-Hartman static ssize_t show_bridge_id(struct device *d, struct device_attribute *attr, 21443cb76d9SGreg Kroah-Hartman char *buf) 2151da177e4SLinus Torvalds { 21643cb76d9SGreg Kroah-Hartman return br_show_bridge_id(buf, &to_bridge(d)->bridge_id); 2171da177e4SLinus Torvalds } 21843cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(bridge_id, S_IRUGO, show_bridge_id, NULL); 2191da177e4SLinus Torvalds 22043cb76d9SGreg Kroah-Hartman static ssize_t show_root_port(struct device *d, struct device_attribute *attr, 22143cb76d9SGreg Kroah-Hartman char *buf) 2221da177e4SLinus Torvalds { 22343cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->root_port); 2241da177e4SLinus Torvalds } 22543cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_port, S_IRUGO, show_root_port, NULL); 2261da177e4SLinus Torvalds 22743cb76d9SGreg Kroah-Hartman static ssize_t show_root_path_cost(struct device *d, 22843cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2291da177e4SLinus Torvalds { 23043cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost); 2311da177e4SLinus Torvalds } 23243cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_path_cost, S_IRUGO, show_root_path_cost, NULL); 2331da177e4SLinus Torvalds 23443cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change(struct device *d, 23543cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2361da177e4SLinus Torvalds { 23743cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->topology_change); 2381da177e4SLinus Torvalds } 23943cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change, S_IRUGO, show_topology_change, NULL); 2401da177e4SLinus Torvalds 24143cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change_detected(struct device *d, 24243cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 24343cb76d9SGreg Kroah-Hartman char *buf) 2441da177e4SLinus Torvalds { 24543cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2461da177e4SLinus Torvalds return sprintf(buf, "%d\n", br->topology_change_detected); 2471da177e4SLinus Torvalds } 24843cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change_detected, S_IRUGO, 24943cb76d9SGreg Kroah-Hartman show_topology_change_detected, NULL); 2501da177e4SLinus Torvalds 25143cb76d9SGreg Kroah-Hartman static ssize_t show_hello_timer(struct device *d, 25243cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2531da177e4SLinus Torvalds { 25443cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2551da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer)); 2561da177e4SLinus Torvalds } 25743cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(hello_timer, S_IRUGO, show_hello_timer, NULL); 2581da177e4SLinus Torvalds 25943cb76d9SGreg Kroah-Hartman static ssize_t show_tcn_timer(struct device *d, struct device_attribute *attr, 26043cb76d9SGreg Kroah-Hartman char *buf) 2611da177e4SLinus Torvalds { 26243cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2631da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer)); 2641da177e4SLinus Torvalds } 26543cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(tcn_timer, S_IRUGO, show_tcn_timer, NULL); 2661da177e4SLinus Torvalds 26743cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change_timer(struct device *d, 26843cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 26943cb76d9SGreg Kroah-Hartman char *buf) 2701da177e4SLinus Torvalds { 27143cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2721da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer)); 2731da177e4SLinus Torvalds } 27443cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change_timer, S_IRUGO, show_topology_change_timer, 27543cb76d9SGreg Kroah-Hartman NULL); 2761da177e4SLinus Torvalds 27743cb76d9SGreg Kroah-Hartman static ssize_t show_gc_timer(struct device *d, struct device_attribute *attr, 27843cb76d9SGreg Kroah-Hartman char *buf) 2791da177e4SLinus Torvalds { 28043cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2811da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer)); 2821da177e4SLinus Torvalds } 28343cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(gc_timer, S_IRUGO, show_gc_timer, NULL); 2841da177e4SLinus Torvalds 28543cb76d9SGreg Kroah-Hartman static ssize_t show_group_addr(struct device *d, 28643cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 287fda93d92SStephen Hemminger { 28843cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 289fda93d92SStephen Hemminger return sprintf(buf, "%x:%x:%x:%x:%x:%x\n", 290fda93d92SStephen Hemminger br->group_addr[0], br->group_addr[1], 291fda93d92SStephen Hemminger br->group_addr[2], br->group_addr[3], 292fda93d92SStephen Hemminger br->group_addr[4], br->group_addr[5]); 293fda93d92SStephen Hemminger } 294fda93d92SStephen Hemminger 29543cb76d9SGreg Kroah-Hartman static ssize_t store_group_addr(struct device *d, 29643cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 29743cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 298fda93d92SStephen Hemminger { 29943cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 300fda93d92SStephen Hemminger unsigned new_addr[6]; 301fda93d92SStephen Hemminger int i; 302fda93d92SStephen Hemminger 303fda93d92SStephen Hemminger if (!capable(CAP_NET_ADMIN)) 304fda93d92SStephen Hemminger return -EPERM; 305fda93d92SStephen Hemminger 306fda93d92SStephen Hemminger if (sscanf(buf, "%x:%x:%x:%x:%x:%x", 307fda93d92SStephen Hemminger &new_addr[0], &new_addr[1], &new_addr[2], 308fda93d92SStephen Hemminger &new_addr[3], &new_addr[4], &new_addr[5]) != 6) 309fda93d92SStephen Hemminger return -EINVAL; 310fda93d92SStephen Hemminger 311fda93d92SStephen Hemminger /* Must be 01:80:c2:00:00:0X */ 312fda93d92SStephen Hemminger for (i = 0; i < 5; i++) 313fda93d92SStephen Hemminger if (new_addr[i] != br_group_address[i]) 314fda93d92SStephen Hemminger return -EINVAL; 315fda93d92SStephen Hemminger 316fda93d92SStephen Hemminger if (new_addr[5] & ~0xf) 317fda93d92SStephen Hemminger return -EINVAL; 318fda93d92SStephen Hemminger 319*f64f9e71SJoe Perches if (new_addr[5] == 1 || /* 802.3x Pause address */ 320*f64f9e71SJoe Perches new_addr[5] == 2 || /* 802.3ad Slow protocols */ 321*f64f9e71SJoe Perches new_addr[5] == 3) /* 802.1X PAE address */ 322fda93d92SStephen Hemminger return -EINVAL; 323fda93d92SStephen Hemminger 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); 328fda93d92SStephen Hemminger return len; 329fda93d92SStephen Hemminger } 330fda93d92SStephen Hemminger 33143cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(group_addr, S_IRUGO | S_IWUSR, 332fda93d92SStephen Hemminger show_group_addr, store_group_addr); 333fda93d92SStephen Hemminger 3349cf63747SStephen Hemminger static ssize_t store_flush(struct device *d, 3359cf63747SStephen Hemminger struct device_attribute *attr, 3369cf63747SStephen Hemminger const char *buf, size_t len) 3379cf63747SStephen Hemminger { 3389cf63747SStephen Hemminger struct net_bridge *br = to_bridge(d); 3399cf63747SStephen Hemminger 3409cf63747SStephen Hemminger if (!capable(CAP_NET_ADMIN)) 3419cf63747SStephen Hemminger return -EPERM; 3429cf63747SStephen Hemminger 3439cf63747SStephen Hemminger br_fdb_flush(br); 3449cf63747SStephen Hemminger return len; 3459cf63747SStephen Hemminger } 3469cf63747SStephen Hemminger static DEVICE_ATTR(flush, S_IWUSR, NULL, store_flush); 347fda93d92SStephen Hemminger 3481da177e4SLinus Torvalds static struct attribute *bridge_attrs[] = { 34943cb76d9SGreg Kroah-Hartman &dev_attr_forward_delay.attr, 35043cb76d9SGreg Kroah-Hartman &dev_attr_hello_time.attr, 35143cb76d9SGreg Kroah-Hartman &dev_attr_max_age.attr, 35243cb76d9SGreg Kroah-Hartman &dev_attr_ageing_time.attr, 35343cb76d9SGreg Kroah-Hartman &dev_attr_stp_state.attr, 35443cb76d9SGreg Kroah-Hartman &dev_attr_priority.attr, 35543cb76d9SGreg Kroah-Hartman &dev_attr_bridge_id.attr, 35643cb76d9SGreg Kroah-Hartman &dev_attr_root_id.attr, 35743cb76d9SGreg Kroah-Hartman &dev_attr_root_path_cost.attr, 35843cb76d9SGreg Kroah-Hartman &dev_attr_root_port.attr, 35943cb76d9SGreg Kroah-Hartman &dev_attr_topology_change.attr, 36043cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_detected.attr, 36143cb76d9SGreg Kroah-Hartman &dev_attr_hello_timer.attr, 36243cb76d9SGreg Kroah-Hartman &dev_attr_tcn_timer.attr, 36343cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_timer.attr, 36443cb76d9SGreg Kroah-Hartman &dev_attr_gc_timer.attr, 36543cb76d9SGreg Kroah-Hartman &dev_attr_group_addr.attr, 3669cf63747SStephen Hemminger &dev_attr_flush.attr, 3671da177e4SLinus Torvalds NULL 3681da177e4SLinus Torvalds }; 3691da177e4SLinus Torvalds 3701da177e4SLinus Torvalds static struct attribute_group bridge_group = { 3711da177e4SLinus Torvalds .name = SYSFS_BRIDGE_ATTR, 3721da177e4SLinus Torvalds .attrs = bridge_attrs, 3731da177e4SLinus Torvalds }; 3741da177e4SLinus Torvalds 3751da177e4SLinus Torvalds /* 3761da177e4SLinus Torvalds * Export the forwarding information table as a binary file 3771da177e4SLinus Torvalds * The records are struct __fdb_entry. 3781da177e4SLinus Torvalds * 3791da177e4SLinus Torvalds * Returns the number of bytes read. 3801da177e4SLinus Torvalds */ 38191a69029SZhang Rui static ssize_t brforward_read(struct kobject *kobj, 38291a69029SZhang Rui struct bin_attribute *bin_attr, 38391a69029SZhang Rui char *buf, loff_t off, size_t count) 3841da177e4SLinus Torvalds { 38543cb76d9SGreg Kroah-Hartman struct device *dev = to_dev(kobj); 38643cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(dev); 3871da177e4SLinus Torvalds int n; 3881da177e4SLinus Torvalds 3891da177e4SLinus Torvalds /* must read whole records */ 3901da177e4SLinus Torvalds if (off % sizeof(struct __fdb_entry) != 0) 3911da177e4SLinus Torvalds return -EINVAL; 3921da177e4SLinus Torvalds 3931da177e4SLinus Torvalds n = br_fdb_fillbuf(br, buf, 3941da177e4SLinus Torvalds count / sizeof(struct __fdb_entry), 3951da177e4SLinus Torvalds off / sizeof(struct __fdb_entry)); 3961da177e4SLinus Torvalds 3971da177e4SLinus Torvalds if (n > 0) 3981da177e4SLinus Torvalds n *= sizeof(struct __fdb_entry); 3991da177e4SLinus Torvalds 4001da177e4SLinus Torvalds return n; 4011da177e4SLinus Torvalds } 4021da177e4SLinus Torvalds 4031da177e4SLinus Torvalds static struct bin_attribute bridge_forward = { 4041da177e4SLinus Torvalds .attr = { .name = SYSFS_BRIDGE_FDB, 4057b595756STejun Heo .mode = S_IRUGO, }, 4061da177e4SLinus Torvalds .read = brforward_read, 4071da177e4SLinus Torvalds }; 4081da177e4SLinus Torvalds 4091da177e4SLinus Torvalds /* 4101da177e4SLinus Torvalds * Add entries in sysfs onto the existing network class device 4111da177e4SLinus Torvalds * for the bridge. 4121da177e4SLinus Torvalds * Adds a attribute group "bridge" containing tuning parameters. 4131da177e4SLinus Torvalds * Binary attribute containing the forward table 4141da177e4SLinus Torvalds * Sub directory to hold links to interfaces. 4151da177e4SLinus Torvalds * 4161da177e4SLinus Torvalds * Note: the ifobj exists only to be a subdirectory 4171da177e4SLinus Torvalds * to hold links. The ifobj exists in same data structure 4181da177e4SLinus Torvalds * as it's parent the bridge so reference counting works. 4191da177e4SLinus Torvalds */ 4201da177e4SLinus Torvalds int br_sysfs_addbr(struct net_device *dev) 4211da177e4SLinus Torvalds { 42243cb76d9SGreg Kroah-Hartman struct kobject *brobj = &dev->dev.kobj; 4231da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 4241da177e4SLinus Torvalds int err; 4251da177e4SLinus Torvalds 4261da177e4SLinus Torvalds err = sysfs_create_group(brobj, &bridge_group); 4271da177e4SLinus Torvalds if (err) { 4281da177e4SLinus Torvalds pr_info("%s: can't create group %s/%s\n", 4290dc47877SHarvey Harrison __func__, dev->name, bridge_group.name); 4301da177e4SLinus Torvalds goto out1; 4311da177e4SLinus Torvalds } 4321da177e4SLinus Torvalds 4331da177e4SLinus Torvalds err = sysfs_create_bin_file(brobj, &bridge_forward); 4341da177e4SLinus Torvalds if (err) { 4351842c4beSRandy Dunlap pr_info("%s: can't create attribute file %s/%s\n", 4360dc47877SHarvey Harrison __func__, dev->name, bridge_forward.attr.name); 4371da177e4SLinus Torvalds goto out2; 4381da177e4SLinus Torvalds } 4391da177e4SLinus Torvalds 44043b98c4aSGreg Kroah-Hartman br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj); 44143b98c4aSGreg Kroah-Hartman if (!br->ifobj) { 4421da177e4SLinus Torvalds pr_info("%s: can't add kobject (directory) %s/%s\n", 4430dc47877SHarvey Harrison __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR); 4441da177e4SLinus Torvalds goto out3; 4451da177e4SLinus Torvalds } 4461da177e4SLinus Torvalds return 0; 4471da177e4SLinus Torvalds out3: 44843cb76d9SGreg Kroah-Hartman sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward); 4491da177e4SLinus Torvalds out2: 45043cb76d9SGreg Kroah-Hartman sysfs_remove_group(&dev->dev.kobj, &bridge_group); 4511da177e4SLinus Torvalds out1: 4521da177e4SLinus Torvalds return err; 4531da177e4SLinus Torvalds 4541da177e4SLinus Torvalds } 4551da177e4SLinus Torvalds 4561da177e4SLinus Torvalds void br_sysfs_delbr(struct net_device *dev) 4571da177e4SLinus Torvalds { 45843cb76d9SGreg Kroah-Hartman struct kobject *kobj = &dev->dev.kobj; 4591da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 4601da177e4SLinus Torvalds 46178a2d906SGreg Kroah-Hartman kobject_put(br->ifobj); 4621da177e4SLinus Torvalds sysfs_remove_bin_file(kobj, &bridge_forward); 4631da177e4SLinus Torvalds sysfs_remove_group(kobj, &bridge_group); 4641da177e4SLinus Torvalds } 465