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 static void set_stp_state(struct net_bridge *br, unsigned long val) 1511da177e4SLinus Torvalds { 1521da177e4SLinus Torvalds br->stp_enabled = val; 1531da177e4SLinus Torvalds } 1541da177e4SLinus Torvalds 15543cb76d9SGreg Kroah-Hartman static ssize_t store_stp_state(struct device *d, 15643cb76d9SGreg Kroah-Hartman struct device_attribute *attr, const char *buf, 15743cb76d9SGreg Kroah-Hartman size_t len) 1581da177e4SLinus Torvalds { 15943cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_stp_state); 1601da177e4SLinus Torvalds } 16143cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(stp_state, S_IRUGO | S_IWUSR, show_stp_state, 1621da177e4SLinus Torvalds store_stp_state); 1631da177e4SLinus Torvalds 16443cb76d9SGreg Kroah-Hartman static ssize_t show_priority(struct device *d, struct device_attribute *attr, 16543cb76d9SGreg Kroah-Hartman char *buf) 1661da177e4SLinus Torvalds { 16743cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 1681da177e4SLinus Torvalds return sprintf(buf, "%d\n", 1691da177e4SLinus Torvalds (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]); 1701da177e4SLinus Torvalds } 1711da177e4SLinus Torvalds 1721da177e4SLinus Torvalds static void set_priority(struct net_bridge *br, unsigned long val) 1731da177e4SLinus Torvalds { 1741da177e4SLinus Torvalds br_stp_set_bridge_priority(br, (u16) val); 1751da177e4SLinus Torvalds } 1761da177e4SLinus Torvalds 17743cb76d9SGreg Kroah-Hartman static ssize_t store_priority(struct device *d, struct device_attribute *attr, 1781da177e4SLinus Torvalds const char *buf, size_t len) 1791da177e4SLinus Torvalds { 18043cb76d9SGreg Kroah-Hartman return store_bridge_parm(d, buf, len, set_priority); 1811da177e4SLinus Torvalds } 18243cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(priority, S_IRUGO | S_IWUSR, show_priority, store_priority); 1831da177e4SLinus Torvalds 18443cb76d9SGreg Kroah-Hartman static ssize_t show_root_id(struct device *d, struct device_attribute *attr, 18543cb76d9SGreg Kroah-Hartman char *buf) 1861da177e4SLinus Torvalds { 18743cb76d9SGreg Kroah-Hartman return br_show_bridge_id(buf, &to_bridge(d)->designated_root); 1881da177e4SLinus Torvalds } 18943cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_id, S_IRUGO, show_root_id, NULL); 1901da177e4SLinus Torvalds 19143cb76d9SGreg Kroah-Hartman static ssize_t show_bridge_id(struct device *d, struct device_attribute *attr, 19243cb76d9SGreg Kroah-Hartman char *buf) 1931da177e4SLinus Torvalds { 19443cb76d9SGreg Kroah-Hartman return br_show_bridge_id(buf, &to_bridge(d)->bridge_id); 1951da177e4SLinus Torvalds } 19643cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(bridge_id, S_IRUGO, show_bridge_id, NULL); 1971da177e4SLinus Torvalds 19843cb76d9SGreg Kroah-Hartman static ssize_t show_root_port(struct device *d, struct device_attribute *attr, 19943cb76d9SGreg Kroah-Hartman char *buf) 2001da177e4SLinus Torvalds { 20143cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->root_port); 2021da177e4SLinus Torvalds } 20343cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_port, S_IRUGO, show_root_port, NULL); 2041da177e4SLinus Torvalds 20543cb76d9SGreg Kroah-Hartman static ssize_t show_root_path_cost(struct device *d, 20643cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2071da177e4SLinus Torvalds { 20843cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost); 2091da177e4SLinus Torvalds } 21043cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(root_path_cost, S_IRUGO, show_root_path_cost, NULL); 2111da177e4SLinus Torvalds 21243cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change(struct device *d, 21343cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2141da177e4SLinus Torvalds { 21543cb76d9SGreg Kroah-Hartman return sprintf(buf, "%d\n", to_bridge(d)->topology_change); 2161da177e4SLinus Torvalds } 21743cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change, S_IRUGO, show_topology_change, NULL); 2181da177e4SLinus Torvalds 21943cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change_detected(struct device *d, 22043cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 22143cb76d9SGreg Kroah-Hartman char *buf) 2221da177e4SLinus Torvalds { 22343cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2241da177e4SLinus Torvalds return sprintf(buf, "%d\n", br->topology_change_detected); 2251da177e4SLinus Torvalds } 22643cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change_detected, S_IRUGO, 22743cb76d9SGreg Kroah-Hartman show_topology_change_detected, NULL); 2281da177e4SLinus Torvalds 22943cb76d9SGreg Kroah-Hartman static ssize_t show_hello_timer(struct device *d, 23043cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 2311da177e4SLinus Torvalds { 23243cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2331da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer)); 2341da177e4SLinus Torvalds } 23543cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(hello_timer, S_IRUGO, show_hello_timer, NULL); 2361da177e4SLinus Torvalds 23743cb76d9SGreg Kroah-Hartman static ssize_t show_tcn_timer(struct device *d, struct device_attribute *attr, 23843cb76d9SGreg Kroah-Hartman char *buf) 2391da177e4SLinus Torvalds { 24043cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2411da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer)); 2421da177e4SLinus Torvalds } 24343cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(tcn_timer, S_IRUGO, show_tcn_timer, NULL); 2441da177e4SLinus Torvalds 24543cb76d9SGreg Kroah-Hartman static ssize_t show_topology_change_timer(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, "%ld\n", br_timer_value(&br->topology_change_timer)); 2511da177e4SLinus Torvalds } 25243cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(topology_change_timer, S_IRUGO, show_topology_change_timer, 25343cb76d9SGreg Kroah-Hartman NULL); 2541da177e4SLinus Torvalds 25543cb76d9SGreg Kroah-Hartman static ssize_t show_gc_timer(struct device *d, struct device_attribute *attr, 25643cb76d9SGreg Kroah-Hartman char *buf) 2571da177e4SLinus Torvalds { 25843cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 2591da177e4SLinus Torvalds return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer)); 2601da177e4SLinus Torvalds } 26143cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(gc_timer, S_IRUGO, show_gc_timer, NULL); 2621da177e4SLinus Torvalds 26343cb76d9SGreg Kroah-Hartman static ssize_t show_group_addr(struct device *d, 26443cb76d9SGreg Kroah-Hartman struct device_attribute *attr, char *buf) 265fda93d92SStephen Hemminger { 26643cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 267fda93d92SStephen Hemminger return sprintf(buf, "%x:%x:%x:%x:%x:%x\n", 268fda93d92SStephen Hemminger br->group_addr[0], br->group_addr[1], 269fda93d92SStephen Hemminger br->group_addr[2], br->group_addr[3], 270fda93d92SStephen Hemminger br->group_addr[4], br->group_addr[5]); 271fda93d92SStephen Hemminger } 272fda93d92SStephen Hemminger 27343cb76d9SGreg Kroah-Hartman static ssize_t store_group_addr(struct device *d, 27443cb76d9SGreg Kroah-Hartman struct device_attribute *attr, 27543cb76d9SGreg Kroah-Hartman const char *buf, size_t len) 276fda93d92SStephen Hemminger { 27743cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(d); 278fda93d92SStephen Hemminger unsigned new_addr[6]; 279fda93d92SStephen Hemminger int i; 280fda93d92SStephen Hemminger 281fda93d92SStephen Hemminger if (!capable(CAP_NET_ADMIN)) 282fda93d92SStephen Hemminger return -EPERM; 283fda93d92SStephen Hemminger 284fda93d92SStephen Hemminger if (sscanf(buf, "%x:%x:%x:%x:%x:%x", 285fda93d92SStephen Hemminger &new_addr[0], &new_addr[1], &new_addr[2], 286fda93d92SStephen Hemminger &new_addr[3], &new_addr[4], &new_addr[5]) != 6) 287fda93d92SStephen Hemminger return -EINVAL; 288fda93d92SStephen Hemminger 289fda93d92SStephen Hemminger /* Must be 01:80:c2:00:00:0X */ 290fda93d92SStephen Hemminger for (i = 0; i < 5; i++) 291fda93d92SStephen Hemminger if (new_addr[i] != br_group_address[i]) 292fda93d92SStephen Hemminger return -EINVAL; 293fda93d92SStephen Hemminger 294fda93d92SStephen Hemminger if (new_addr[5] & ~0xf) 295fda93d92SStephen Hemminger return -EINVAL; 296fda93d92SStephen Hemminger 297fda93d92SStephen Hemminger if (new_addr[5] == 1 /* 802.3x Pause address */ 298fda93d92SStephen Hemminger || new_addr[5] == 2 /* 802.3ad Slow protocols */ 299fda93d92SStephen Hemminger || new_addr[5] == 3) /* 802.1X PAE address */ 300fda93d92SStephen Hemminger return -EINVAL; 301fda93d92SStephen Hemminger 302fda93d92SStephen Hemminger spin_lock_bh(&br->lock); 303fda93d92SStephen Hemminger for (i = 0; i < 6; i++) 304fda93d92SStephen Hemminger br->group_addr[i] = new_addr[i]; 305fda93d92SStephen Hemminger spin_unlock_bh(&br->lock); 306fda93d92SStephen Hemminger return len; 307fda93d92SStephen Hemminger } 308fda93d92SStephen Hemminger 30943cb76d9SGreg Kroah-Hartman static DEVICE_ATTR(group_addr, S_IRUGO | S_IWUSR, 310fda93d92SStephen Hemminger show_group_addr, store_group_addr); 311fda93d92SStephen Hemminger 312*9cf63747SStephen Hemminger static ssize_t store_flush(struct device *d, 313*9cf63747SStephen Hemminger struct device_attribute *attr, 314*9cf63747SStephen Hemminger const char *buf, size_t len) 315*9cf63747SStephen Hemminger { 316*9cf63747SStephen Hemminger struct net_bridge *br = to_bridge(d); 317*9cf63747SStephen Hemminger 318*9cf63747SStephen Hemminger if (!capable(CAP_NET_ADMIN)) 319*9cf63747SStephen Hemminger return -EPERM; 320*9cf63747SStephen Hemminger 321*9cf63747SStephen Hemminger br_fdb_flush(br); 322*9cf63747SStephen Hemminger return len; 323*9cf63747SStephen Hemminger } 324*9cf63747SStephen Hemminger static DEVICE_ATTR(flush, S_IWUSR, NULL, store_flush); 325fda93d92SStephen Hemminger 3261da177e4SLinus Torvalds static struct attribute *bridge_attrs[] = { 32743cb76d9SGreg Kroah-Hartman &dev_attr_forward_delay.attr, 32843cb76d9SGreg Kroah-Hartman &dev_attr_hello_time.attr, 32943cb76d9SGreg Kroah-Hartman &dev_attr_max_age.attr, 33043cb76d9SGreg Kroah-Hartman &dev_attr_ageing_time.attr, 33143cb76d9SGreg Kroah-Hartman &dev_attr_stp_state.attr, 33243cb76d9SGreg Kroah-Hartman &dev_attr_priority.attr, 33343cb76d9SGreg Kroah-Hartman &dev_attr_bridge_id.attr, 33443cb76d9SGreg Kroah-Hartman &dev_attr_root_id.attr, 33543cb76d9SGreg Kroah-Hartman &dev_attr_root_path_cost.attr, 33643cb76d9SGreg Kroah-Hartman &dev_attr_root_port.attr, 33743cb76d9SGreg Kroah-Hartman &dev_attr_topology_change.attr, 33843cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_detected.attr, 33943cb76d9SGreg Kroah-Hartman &dev_attr_hello_timer.attr, 34043cb76d9SGreg Kroah-Hartman &dev_attr_tcn_timer.attr, 34143cb76d9SGreg Kroah-Hartman &dev_attr_topology_change_timer.attr, 34243cb76d9SGreg Kroah-Hartman &dev_attr_gc_timer.attr, 34343cb76d9SGreg Kroah-Hartman &dev_attr_group_addr.attr, 344*9cf63747SStephen Hemminger &dev_attr_flush.attr, 3451da177e4SLinus Torvalds NULL 3461da177e4SLinus Torvalds }; 3471da177e4SLinus Torvalds 3481da177e4SLinus Torvalds static struct attribute_group bridge_group = { 3491da177e4SLinus Torvalds .name = SYSFS_BRIDGE_ATTR, 3501da177e4SLinus Torvalds .attrs = bridge_attrs, 3511da177e4SLinus Torvalds }; 3521da177e4SLinus Torvalds 3531da177e4SLinus Torvalds /* 3541da177e4SLinus Torvalds * Export the forwarding information table as a binary file 3551da177e4SLinus Torvalds * The records are struct __fdb_entry. 3561da177e4SLinus Torvalds * 3571da177e4SLinus Torvalds * Returns the number of bytes read. 3581da177e4SLinus Torvalds */ 3591da177e4SLinus Torvalds static ssize_t brforward_read(struct kobject *kobj, char *buf, 3601da177e4SLinus Torvalds loff_t off, size_t count) 3611da177e4SLinus Torvalds { 36243cb76d9SGreg Kroah-Hartman struct device *dev = to_dev(kobj); 36343cb76d9SGreg Kroah-Hartman struct net_bridge *br = to_bridge(dev); 3641da177e4SLinus Torvalds int n; 3651da177e4SLinus Torvalds 3661da177e4SLinus Torvalds /* must read whole records */ 3671da177e4SLinus Torvalds if (off % sizeof(struct __fdb_entry) != 0) 3681da177e4SLinus Torvalds return -EINVAL; 3691da177e4SLinus Torvalds 3701da177e4SLinus Torvalds n = br_fdb_fillbuf(br, buf, 3711da177e4SLinus Torvalds count / sizeof(struct __fdb_entry), 3721da177e4SLinus Torvalds off / sizeof(struct __fdb_entry)); 3731da177e4SLinus Torvalds 3741da177e4SLinus Torvalds if (n > 0) 3751da177e4SLinus Torvalds n *= sizeof(struct __fdb_entry); 3761da177e4SLinus Torvalds 3771da177e4SLinus Torvalds return n; 3781da177e4SLinus Torvalds } 3791da177e4SLinus Torvalds 3801da177e4SLinus Torvalds static struct bin_attribute bridge_forward = { 3811da177e4SLinus Torvalds .attr = { .name = SYSFS_BRIDGE_FDB, 3821da177e4SLinus Torvalds .mode = S_IRUGO, 3831da177e4SLinus Torvalds .owner = THIS_MODULE, }, 3841da177e4SLinus Torvalds .read = brforward_read, 3851da177e4SLinus Torvalds }; 3861da177e4SLinus Torvalds 3871da177e4SLinus Torvalds /* 3881da177e4SLinus Torvalds * Add entries in sysfs onto the existing network class device 3891da177e4SLinus Torvalds * for the bridge. 3901da177e4SLinus Torvalds * Adds a attribute group "bridge" containing tuning parameters. 3911da177e4SLinus Torvalds * Binary attribute containing the forward table 3921da177e4SLinus Torvalds * Sub directory to hold links to interfaces. 3931da177e4SLinus Torvalds * 3941da177e4SLinus Torvalds * Note: the ifobj exists only to be a subdirectory 3951da177e4SLinus Torvalds * to hold links. The ifobj exists in same data structure 3961da177e4SLinus Torvalds * as it's parent the bridge so reference counting works. 3971da177e4SLinus Torvalds */ 3981da177e4SLinus Torvalds int br_sysfs_addbr(struct net_device *dev) 3991da177e4SLinus Torvalds { 40043cb76d9SGreg Kroah-Hartman struct kobject *brobj = &dev->dev.kobj; 4011da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 4021da177e4SLinus Torvalds int err; 4031da177e4SLinus Torvalds 4041da177e4SLinus Torvalds err = sysfs_create_group(brobj, &bridge_group); 4051da177e4SLinus Torvalds if (err) { 4061da177e4SLinus Torvalds pr_info("%s: can't create group %s/%s\n", 4071da177e4SLinus Torvalds __FUNCTION__, dev->name, bridge_group.name); 4081da177e4SLinus Torvalds goto out1; 4091da177e4SLinus Torvalds } 4101da177e4SLinus Torvalds 4111da177e4SLinus Torvalds err = sysfs_create_bin_file(brobj, &bridge_forward); 4121da177e4SLinus Torvalds if (err) { 4131842c4beSRandy Dunlap pr_info("%s: can't create attribute file %s/%s\n", 4141da177e4SLinus Torvalds __FUNCTION__, dev->name, bridge_forward.attr.name); 4151da177e4SLinus Torvalds goto out2; 4161da177e4SLinus Torvalds } 4171da177e4SLinus Torvalds 4181da177e4SLinus Torvalds 4191da177e4SLinus Torvalds kobject_set_name(&br->ifobj, SYSFS_BRIDGE_PORT_SUBDIR); 4201da177e4SLinus Torvalds br->ifobj.ktype = NULL; 4211da177e4SLinus Torvalds br->ifobj.kset = NULL; 4221da177e4SLinus Torvalds br->ifobj.parent = brobj; 4231da177e4SLinus Torvalds 4241da177e4SLinus Torvalds err = kobject_register(&br->ifobj); 4251da177e4SLinus Torvalds if (err) { 4261da177e4SLinus Torvalds pr_info("%s: can't add kobject (directory) %s/%s\n", 4271da177e4SLinus Torvalds __FUNCTION__, dev->name, br->ifobj.name); 4281da177e4SLinus Torvalds goto out3; 4291da177e4SLinus Torvalds } 4301da177e4SLinus Torvalds return 0; 4311da177e4SLinus Torvalds out3: 43243cb76d9SGreg Kroah-Hartman sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward); 4331da177e4SLinus Torvalds out2: 43443cb76d9SGreg Kroah-Hartman sysfs_remove_group(&dev->dev.kobj, &bridge_group); 4351da177e4SLinus Torvalds out1: 4361da177e4SLinus Torvalds return err; 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvalds } 4391da177e4SLinus Torvalds 4401da177e4SLinus Torvalds void br_sysfs_delbr(struct net_device *dev) 4411da177e4SLinus Torvalds { 44243cb76d9SGreg Kroah-Hartman struct kobject *kobj = &dev->dev.kobj; 4431da177e4SLinus Torvalds struct net_bridge *br = netdev_priv(dev); 4441da177e4SLinus Torvalds 4451da177e4SLinus Torvalds kobject_unregister(&br->ifobj); 4461da177e4SLinus Torvalds sysfs_remove_bin_file(kobj, &bridge_forward); 4471da177e4SLinus Torvalds sysfs_remove_group(kobj, &bridge_group); 4481da177e4SLinus Torvalds } 449