| 1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
/* |
| 3 |
* Sysfs attributes of bridge |
| 4 |
* Linux ethernet bridge |
| 5 |
* |
| 6 |
* Authors: |
| 7 |
* Stephen Hemminger <[email protected]> |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <linux/capability.h> |
| 11 |
#include <linux/kernel.h> |
| 12 |
#include <linux/netdevice.h> |
| 13 |
#include <linux/etherdevice.h> |
| 14 |
#include <linux/hex.h> |
| 15 |
#include <linux/if_bridge.h> |
| 16 |
#include <linux/rtnetlink.h> |
| 17 |
#include <linux/spinlock.h> |
| 18 |
#include <linux/times.h> |
| 19 |
#include <linux/sched/signal.h> |
| 20 |
|
| 21 |
#include "br_private.h" |
| 22 |
|
| 23 |
/* IMPORTANT: new bridge options must be added with netlink support only |
| 24 |
* please do not add new sysfs entries |
| 25 |
*/ |
| 26 |
|
| 27 |
#define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd))) |
| 28 |
|
| 29 |
/* |
| 30 |
* Common code for storing bridge parameters. |
| 31 |
*/ |
| 32 |
static ssize_t store_bridge_parm(struct device *d, |
| 33 |
const char *buf, size_t len, |
| 34 |
int (*set)(struct net_bridge *br, unsigned long val, |
| 35 |
struct netlink_ext_ack *extack)) |
| 36 |
{ |
| 37 |
struct net_bridge *br = to_bridge(d); |
| 38 |
struct netlink_ext_ack extack = {0}; |
| 39 |
unsigned long val; |
| 40 |
int err; |
| 41 |
|
| 42 |
if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) |
| 43 |
return -EPERM; |
| 44 |
|
| 45 |
err = kstrtoul(buf, 0, &val); |
| 46 |
if (err != 0) |
| 47 |
return err; |
| 48 |
|
| 49 |
if (!rtnl_trylock()) |
| 50 |
return restart_syscall(); |
| 51 |
|
| 52 |
err = (*set)(br, val, &extack); |
| 53 |
if (!err) |
| 54 |
netdev_state_change(br->dev); |
| 55 |
if (extack._msg) { |
| 56 |
if (err) |
| 57 |
br_err(br, "%s\n", extack._msg); |
| 58 |
else |
| 59 |
br_warn(br, "%s\n", extack._msg); |
| 60 |
} |
| 61 |
rtnl_unlock(); |
| 62 |
|
| 63 |
return err ? err : len; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
static ssize_t forward_delay_show(struct device *d, |
| 68 |
struct device_attribute *attr, char *buf) |
| 69 |
{ |
| 70 |
struct net_bridge *br = to_bridge(d); |
| 71 |
return sysfs_emit(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay)); |
| 72 |
} |
| 73 |
|
| 74 |
static int set_forward_delay(struct net_bridge *br, unsigned long val, |
| 75 |
struct netlink_ext_ack *extack) |
| 76 |
{ |
| 77 |
return br_set_forward_delay(br, val); |
| 78 |
} |
| 79 |
|
| 80 |
static ssize_t forward_delay_store(struct device *d, |
| 81 |
struct device_attribute *attr, |
| 82 |
const char *buf, size_t len) |
| 83 |
{ |
| 84 |
return store_bridge_parm(d, buf, len, set_forward_delay); |
| 85 |
} |
| 86 |
static DEVICE_ATTR_RW(forward_delay); |
| 87 |
|
| 88 |
static ssize_t hello_time_show(struct device *d, struct device_attribute *attr, |
| 89 |
char *buf) |
| 90 |
{ |
| 91 |
return sysfs_emit(buf, "%lu\n", |
| 92 |
jiffies_to_clock_t(to_bridge(d)->hello_time)); |
| 93 |
} |
| 94 |
|
| 95 |
static int set_hello_time(struct net_bridge *br, unsigned long val, |
| 96 |
struct netlink_ext_ack *extack) |
| 97 |
{ |
| 98 |
return br_set_hello_time(br, val); |
| 99 |
} |
| 100 |
|
| 101 |
static ssize_t hello_time_store(struct device *d, |
| 102 |
struct device_attribute *attr, const char *buf, |
| 103 |
size_t len) |
| 104 |
{ |
| 105 |
return store_bridge_parm(d, buf, len, set_hello_time); |
| 106 |
} |
| 107 |
static DEVICE_ATTR_RW(hello_time); |
| 108 |
|
| 109 |
static ssize_t max_age_show(struct device *d, struct device_attribute *attr, |
| 110 |
char *buf) |
| 111 |
{ |
| 112 |
return sysfs_emit(buf, "%lu\n", |
| 113 |
jiffies_to_clock_t(to_bridge(d)->max_age)); |
| 114 |
} |
| 115 |
|
| 116 |
static int set_max_age(struct net_bridge *br, unsigned long val, |
| 117 |
struct netlink_ext_ack *extack) |
| 118 |
{ |
| 119 |
return br_set_max_age(br, val); |
| 120 |
} |
| 121 |
|
| 122 |
static ssize_t max_age_store(struct device *d, struct device_attribute *attr, |
| 123 |
const char *buf, size_t len) |
| 124 |
{ |
| 125 |
return store_bridge_parm(d, buf, len, set_max_age); |
| 126 |
} |
| 127 |
static DEVICE_ATTR_RW(max_age); |
| 128 |
|
| 129 |
static ssize_t ageing_time_show(struct device *d, |
| 130 |
struct device_attribute *attr, char *buf) |
| 131 |
{ |
| 132 |
struct net_bridge *br = to_bridge(d); |
| 133 |
return sysfs_emit(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time)); |
| 134 |
} |
| 135 |
|
| 136 |
static int set_ageing_time(struct net_bridge *br, unsigned long val, |
| 137 |
struct netlink_ext_ack *extack) |
| 138 |
{ |
| 139 |
return br_set_ageing_time(br, val); |
| 140 |
} |
| 141 |
|
| 142 |
static ssize_t ageing_time_store(struct device *d, |
| 143 |
struct device_attribute *attr, |
| 144 |
const char *buf, size_t len) |
| 145 |
{ |
| 146 |
return store_bridge_parm(d, buf, len, set_ageing_time); |
| 147 |
} |
| 148 |
static DEVICE_ATTR_RW(ageing_time); |
| 149 |
|
| 150 |
static ssize_t stp_state_show(struct device *d, |
| 151 |
struct device_attribute *attr, char *buf) |
| 152 |
{ |
| 153 |
struct net_bridge *br = to_bridge(d); |
| 154 |
return sysfs_emit(buf, "%d\n", br->stp_enabled); |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
static int set_stp_state(struct net_bridge *br, unsigned long val, |
| 159 |
struct netlink_ext_ack *extack) |
| 160 |
{ |
| 161 |
return br_stp_set_enabled(br, val, extack); |
| 162 |
} |
| 163 |
|
| 164 |
static ssize_t stp_state_store(struct device *d, |
| 165 |
struct device_attribute *attr, const char *buf, |
| 166 |
size_t len) |
| 167 |
{ |
| 168 |
return store_bridge_parm(d, buf, len, set_stp_state); |
| 169 |
} |
| 170 |
static DEVICE_ATTR_RW(stp_state); |
| 171 |
|
| 172 |
static ssize_t group_fwd_mask_show(struct device *d, |
| 173 |
struct device_attribute *attr, |
| 174 |
char *buf) |
| 175 |
{ |
| 176 |
struct net_bridge *br = to_bridge(d); |
| 177 |
return sysfs_emit(buf, "%#x\n", br->group_fwd_mask); |
| 178 |
} |
| 179 |
|
| 180 |
static int set_group_fwd_mask(struct net_bridge *br, unsigned long val, |
| 181 |
struct netlink_ext_ack *extack) |
| 182 |
{ |
| 183 |
if (val & BR_GROUPFWD_RESTRICTED) |
| 184 |
return -EINVAL; |
| 185 |
|
| 186 |
br->group_fwd_mask = val; |
| 187 |
|
| 188 |
return 0; |
| 189 |
} |
| 190 |
|
| 191 |
static ssize_t group_fwd_mask_store(struct device *d, |
| 192 |
struct device_attribute *attr, |
| 193 |
const char *buf, |
| 194 |
size_t len) |
| 195 |
{ |
| 196 |
return store_bridge_parm(d, buf, len, set_group_fwd_mask); |
| 197 |
} |
| 198 |
static DEVICE_ATTR_RW(group_fwd_mask); |
| 199 |
|
| 200 |
static ssize_t priority_show(struct device *d, struct device_attribute *attr, |
| 201 |
char *buf) |
| 202 |
{ |
| 203 |
struct net_bridge *br = to_bridge(d); |
| 204 |
return sysfs_emit(buf, "%d\n", |
| 205 |
(br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]); |
| 206 |
} |
| 207 |
|
| 208 |
static int set_priority(struct net_bridge *br, unsigned long val, |
| 209 |
struct netlink_ext_ack *extack) |
| 210 |
{ |
| 211 |
br_stp_set_bridge_priority(br, (u16) val); |
| 212 |
return 0; |
| 213 |
} |
| 214 |
|
| 215 |
static ssize_t priority_store(struct device *d, struct device_attribute *attr, |
| 216 |
const char *buf, size_t len) |
| 217 |
{ |
| 218 |
return store_bridge_parm(d, buf, len, set_priority); |
| 219 |
} |
| 220 |
static DEVICE_ATTR_RW(priority); |
| 221 |
|
| 222 |
static ssize_t root_id_show(struct device *d, struct device_attribute *attr, |
| 223 |
char *buf) |
| 224 |
{ |
| 225 |
return br_show_bridge_id(buf, &to_bridge(d)->designated_root); |
| 226 |
} |
| 227 |
static DEVICE_ATTR_RO(root_id); |
| 228 |
|
| 229 |
static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr, |
| 230 |
char *buf) |
| 231 |
{ |
| 232 |
return br_show_bridge_id(buf, &to_bridge(d)->bridge_id); |
| 233 |
} |
| 234 |
static DEVICE_ATTR_RO(bridge_id); |
| 235 |
|
| 236 |
static ssize_t root_port_show(struct device *d, struct device_attribute *attr, |
| 237 |
char *buf) |
| 238 |
{ |
| 239 |
return sysfs_emit(buf, "%d\n", to_bridge(d)->root_port); |
| 240 |
} |
| 241 |
static DEVICE_ATTR_RO(root_port); |
| 242 |
|
| 243 |
static ssize_t root_path_cost_show(struct device *d, |
| 244 |
struct device_attribute *attr, char *buf) |
| 245 |
{ |
| 246 |
return sysfs_emit(buf, "%d\n", to_bridge(d)->root_path_cost); |
| 247 |
} |
| 248 |
static DEVICE_ATTR_RO(root_path_cost); |
| 249 |
|
| 250 |
static ssize_t topology_change_show(struct device *d, |
| 251 |
struct device_attribute *attr, char *buf) |
| 252 |
{ |
| 253 |
return sysfs_emit(buf, "%d\n", to_bridge(d)->topology_change); |
| 254 |
} |
| 255 |
static DEVICE_ATTR_RO(topology_change); |
| 256 |
|
| 257 |
static ssize_t topology_change_detected_show(struct device *d, |
| 258 |
struct device_attribute *attr, |
| 259 |
char *buf) |
| 260 |
{ |
| 261 |
struct net_bridge *br = to_bridge(d); |
| 262 |
return sysfs_emit(buf, "%d\n", br->topology_change_detected); |
| 263 |
} |
| 264 |
static DEVICE_ATTR_RO(topology_change_detected); |
| 265 |
|
| 266 |
static ssize_t hello_timer_show(struct device *d, |
| 267 |
struct device_attribute *attr, char *buf) |
| 268 |
{ |
| 269 |
struct net_bridge *br = to_bridge(d); |
| 270 |
return sysfs_emit(buf, "%ld\n", br_timer_value(&br->hello_timer)); |
| 271 |
} |
| 272 |
static DEVICE_ATTR_RO(hello_timer); |
| 273 |
|
| 274 |
static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr, |
| 275 |
char *buf) |
| 276 |
{ |
| 277 |
struct net_bridge *br = to_bridge(d); |
| 278 |
return sysfs_emit(buf, "%ld\n", br_timer_value(&br->tcn_timer)); |
| 279 |
} |
| 280 |
static DEVICE_ATTR_RO(tcn_timer); |
| 281 |
|
| 282 |
static ssize_t topology_change_timer_show(struct device *d, |
| 283 |
struct device_attribute *attr, |
| 284 |
char *buf) |
| 285 |
{ |
| 286 |
struct net_bridge *br = to_bridge(d); |
| 287 |
return sysfs_emit(buf, "%ld\n", br_timer_value(&br->topology_change_timer)); |
| 288 |
} |
| 289 |
static DEVICE_ATTR_RO(topology_change_timer); |
| 290 |
|
| 291 |
static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr, |
| 292 |
char *buf) |
| 293 |
{ |
| 294 |
struct net_bridge *br = to_bridge(d); |
| 295 |
return sysfs_emit(buf, "%ld\n", br_timer_value(&br->gc_work.timer)); |
| 296 |
} |
| 297 |
static DEVICE_ATTR_RO(gc_timer); |
| 298 |
|
| 299 |
static ssize_t group_addr_show(struct device *d, |
| 300 |
struct device_attribute *attr, char *buf) |
| 301 |
{ |
| 302 |
struct net_bridge *br = to_bridge(d); |
| 303 |
return sysfs_emit(buf, "%pM\n", br->group_addr); |
| 304 |
} |
| 305 |
|
| 306 |
static ssize_t group_addr_store(struct device *d, |
| 307 |
struct device_attribute *attr, |
| 308 |
const char *buf, size_t len) |
| 309 |
{ |
| 310 |
struct net_bridge *br = to_bridge(d); |
| 311 |
u8 new_addr[6]; |
| 312 |
|
| 313 |
if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) |
| 314 |
return -EPERM; |
| 315 |
|
| 316 |
if (!mac_pton(buf, new_addr)) |
| 317 |
return -EINVAL; |
| 318 |
|
| 319 |
if (!is_link_local_ether_addr(new_addr)) |
| 320 |
return -EINVAL; |
| 321 |
|
| 322 |
if (new_addr[5] == 1 || /* 802.3x Pause address */ |
| 323 |
new_addr[5] == 2 || /* 802.3ad Slow protocols */ |
| 324 |
new_addr[5] == 3) /* 802.1X PAE address */ |
| 325 |
return -EINVAL; |
| 326 |
|
| 327 |
if (!rtnl_trylock()) |
| 328 |
return restart_syscall(); |
| 329 |
|
| 330 |
spin_lock_bh(&br->lock); |
| 331 |
ether_addr_copy(br->group_addr, new_addr); |
| 332 |
spin_unlock_bh(&br->lock); |
| 333 |
|
| 334 |
br_opt_toggle(br, BROPT_GROUP_ADDR_SET, true); |
| 335 |
br_recalculate_fwd_mask(br); |
| 336 |
netdev_state_change(br->dev); |
| 337 |
|
| 338 |
rtnl_unlock(); |
| 339 |
|
| 340 |
return len; |
| 341 |
} |
| 342 |
|
| 343 |
static DEVICE_ATTR_RW(group_addr); |
| 344 |
|
| 345 |
static int set_flush(struct net_bridge *br, unsigned long val, |
| 346 |
struct netlink_ext_ack *extack) |
| 347 |
{ |
| 348 |
struct net_bridge_fdb_flush_desc desc = { |
| 349 |
.flags_mask = BIT(BR_FDB_STATIC) |
| 350 |
}; |
| 351 |
|
| 352 |
br_fdb_flush(br, &desc); |
| 353 |
return 0; |
| 354 |
} |
| 355 |
|
| 356 |
static ssize_t flush_store(struct device *d, |
| 357 |
struct device_attribute *attr, |
| 358 |
const char *buf, size_t len) |
| 359 |
{ |
| 360 |
return store_bridge_parm(d, buf, len, set_flush); |
| 361 |
} |
| 362 |
static DEVICE_ATTR_WO(flush); |
| 363 |
|
| 364 |
static ssize_t no_linklocal_learn_show(struct device *d, |
| 365 |
struct device_attribute *attr, |
| 366 |
char *buf) |
| 367 |
{ |
| 368 |
struct net_bridge *br = to_bridge(d); |
| 369 |
return sysfs_emit(buf, "%d\n", br_boolopt_get(br, BR_BOOLOPT_NO_LL_LEARN)); |
| 370 |
} |
| 371 |
|
| 372 |
static int set_no_linklocal_learn(struct net_bridge *br, unsigned long val, |
| 373 |
struct netlink_ext_ack *extack) |
| 374 |
{ |
| 375 |
return br_boolopt_toggle(br, BR_BOOLOPT_NO_LL_LEARN, !!val, extack); |
| 376 |
} |
| 377 |
|
| 378 |
static ssize_t no_linklocal_learn_store(struct device *d, |
| 379 |
struct device_attribute *attr, |
| 380 |
const char *buf, size_t len) |
| 381 |
{ |
| 382 |
return store_bridge_parm(d, buf, len, set_no_linklocal_learn); |
| 383 |
} |
| 384 |
static DEVICE_ATTR_RW(no_linklocal_learn); |
| 385 |
|
| 386 |
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 387 |
static ssize_t multicast_router_show(struct device *d, |
| 388 |
struct device_attribute *attr, char *buf) |
| 389 |
{ |
| 390 |
struct net_bridge *br = to_bridge(d); |
| 391 |
return sysfs_emit(buf, "%d\n", br->multicast_ctx.multicast_router); |
| 392 |
} |
| 393 |
|
| 394 |
static int set_multicast_router(struct net_bridge *br, unsigned long val, |
| 395 |
struct netlink_ext_ack *extack) |
| 396 |
{ |
| 397 |
return br_multicast_set_router(&br->multicast_ctx, val); |
| 398 |
} |
| 399 |
|
| 400 |
static ssize_t multicast_router_store(struct device *d, |
| 401 |
struct device_attribute *attr, |
| 402 |
const char *buf, size_t len) |
| 403 |
{ |
| 404 |
return store_bridge_parm(d, buf, len, set_multicast_router); |
| 405 |
} |
| 406 |
static DEVICE_ATTR_RW(multicast_router); |
| 407 |
|
| 408 |
static ssize_t multicast_snooping_show(struct device *d, |
| 409 |
struct device_attribute *attr, |
| 410 |
char *buf) |
| 411 |
{ |
| 412 |
struct net_bridge *br = to_bridge(d); |
| 413 |
return sysfs_emit(buf, "%d\n", br_opt_get(br, BROPT_MULTICAST_ENABLED)); |
| 414 |
} |
| 415 |
|
| 416 |
static ssize_t multicast_snooping_store(struct device *d, |
| 417 |
struct device_attribute *attr, |
| 418 |
const char *buf, size_t len) |
| 419 |
{ |
| 420 |
return store_bridge_parm(d, buf, len, br_multicast_toggle); |
| 421 |
} |
| 422 |
static DEVICE_ATTR_RW(multicast_snooping); |
| 423 |
|
| 424 |
static ssize_t multicast_query_use_ifaddr_show(struct device *d, |
| 425 |
struct device_attribute *attr, |
| 426 |
char *buf) |
| 427 |
{ |
| 428 |
struct net_bridge *br = to_bridge(d); |
| 429 |
return sysfs_emit(buf, "%d\n", |
| 430 |
br_opt_get(br, BROPT_MULTICAST_QUERY_USE_IFADDR)); |
| 431 |
} |
| 432 |
|
| 433 |
static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val, |
| 434 |
struct netlink_ext_ack *extack) |
| 435 |
{ |
| 436 |
br_opt_toggle(br, BROPT_MULTICAST_QUERY_USE_IFADDR, !!val); |
| 437 |
return 0; |
| 438 |
} |
| 439 |
|
| 440 |
static ssize_t |
| 441 |
multicast_query_use_ifaddr_store(struct device *d, |
| 442 |
struct device_attribute *attr, |
| 443 |
const char *buf, size_t len) |
| 444 |
{ |
| 445 |
return store_bridge_parm(d, buf, len, set_query_use_ifaddr); |
| 446 |
} |
| 447 |
static DEVICE_ATTR_RW(multicast_query_use_ifaddr); |
| 448 |
|
| 449 |
static ssize_t multicast_querier_show(struct device *d, |
| 450 |
struct device_attribute *attr, |
| 451 |
char *buf) |
| 452 |
{ |
| 453 |
struct net_bridge *br = to_bridge(d); |
| 454 |
return sysfs_emit(buf, "%d\n", br->multicast_ctx.multicast_querier); |
| 455 |
} |
| 456 |
|
| 457 |
static int set_multicast_querier(struct net_bridge *br, unsigned long val, |
| 458 |
struct netlink_ext_ack *extack) |
| 459 |
{ |
| 460 |
return br_multicast_set_querier(&br->multicast_ctx, val); |
| 461 |
} |
| 462 |
|
| 463 |
static ssize_t multicast_querier_store(struct device *d, |
| 464 |
struct device_attribute *attr, |
| 465 |
const char *buf, size_t len) |
| 466 |
{ |
| 467 |
return store_bridge_parm(d, buf, len, set_multicast_querier); |
| 468 |
} |
| 469 |
static DEVICE_ATTR_RW(multicast_querier); |
| 470 |
|
| 471 |
static ssize_t hash_elasticity_show(struct device *d, |
| 472 |
struct device_attribute *attr, char *buf) |
| 473 |
{ |
| 474 |
return sysfs_emit(buf, "%u\n", RHT_ELASTICITY); |
| 475 |
} |
| 476 |
|
| 477 |
static int set_elasticity(struct net_bridge *br, unsigned long val, |
| 478 |
struct netlink_ext_ack *extack) |
| 479 |
{ |
| 480 |
/* 16 is RHT_ELASTICITY */ |
| 481 |
NL_SET_ERR_MSG_MOD(extack, |
| 482 |
"the hash_elasticity option has been deprecated and is always 16"); |
| 483 |
return 0; |
| 484 |
} |
| 485 |
|
| 486 |
static ssize_t hash_elasticity_store(struct device *d, |
| 487 |
struct device_attribute *attr, |
| 488 |
const char *buf, size_t len) |
| 489 |
{ |
| 490 |
return store_bridge_parm(d, buf, len, set_elasticity); |
| 491 |
} |
| 492 |
static DEVICE_ATTR_RW(hash_elasticity); |
| 493 |
|
| 494 |
static ssize_t hash_max_show(struct device *d, struct device_attribute *attr, |
| 495 |
char *buf) |
| 496 |
{ |
| 497 |
struct net_bridge *br = to_bridge(d); |
| 498 |
return sysfs_emit(buf, "%u\n", br->hash_max); |
| 499 |
} |
| 500 |
|
| 501 |
static int set_hash_max(struct net_bridge *br, unsigned long val, |
| 502 |
struct netlink_ext_ack *extack) |
| 503 |
{ |
| 504 |
br->hash_max = val; |
| 505 |
return 0; |
| 506 |
} |
| 507 |
|
| 508 |
static ssize_t hash_max_store(struct device *d, struct device_attribute *attr, |
| 509 |
const char *buf, size_t len) |
| 510 |
{ |
| 511 |
return store_bridge_parm(d, buf, len, set_hash_max); |
| 512 |
} |
| 513 |
static DEVICE_ATTR_RW(hash_max); |
| 514 |
|
| 515 |
static ssize_t multicast_igmp_version_show(struct device *d, |
| 516 |
struct device_attribute *attr, |
| 517 |
char *buf) |
| 518 |
{ |
| 519 |
struct net_bridge *br = to_bridge(d); |
| 520 |
|
| 521 |
return sysfs_emit(buf, "%u\n", br->multicast_ctx.multicast_igmp_version); |
| 522 |
} |
| 523 |
|
| 524 |
static int set_multicast_igmp_version(struct net_bridge *br, unsigned long val, |
| 525 |
struct netlink_ext_ack *extack) |
| 526 |
{ |
| 527 |
return br_multicast_set_igmp_version(&br->multicast_ctx, val); |
| 528 |
} |
| 529 |
|
| 530 |
static ssize_t multicast_igmp_version_store(struct device *d, |
| 531 |
struct device_attribute *attr, |
| 532 |
const char *buf, size_t len) |
| 533 |
{ |
| 534 |
return store_bridge_parm(d, buf, len, set_multicast_igmp_version); |
| 535 |
} |
| 536 |
static DEVICE_ATTR_RW(multicast_igmp_version); |
| 537 |
|
| 538 |
static ssize_t multicast_last_member_count_show(struct device *d, |
| 539 |
struct device_attribute *attr, |
| 540 |
char *buf) |
| 541 |
{ |
| 542 |
struct net_bridge *br = to_bridge(d); |
| 543 |
return sysfs_emit(buf, "%u\n", br->multicast_ctx.multicast_last_member_count); |
| 544 |
} |
| 545 |
|
| 546 |
static int set_last_member_count(struct net_bridge *br, unsigned long val, |
| 547 |
struct netlink_ext_ack *extack) |
| 548 |
{ |
| 549 |
br->multicast_ctx.multicast_last_member_count = val; |
| 550 |
return 0; |
| 551 |
} |
| 552 |
|
| 553 |
static ssize_t multicast_last_member_count_store(struct device *d, |
| 554 |
struct device_attribute *attr, |
| 555 |
const char *buf, size_t len) |
| 556 |
{ |
| 557 |
return store_bridge_parm(d, buf, len, set_last_member_count); |
| 558 |
} |
| 559 |
static DEVICE_ATTR_RW(multicast_last_member_count); |
| 560 |
|
| 561 |
static ssize_t multicast_startup_query_count_show( |
| 562 |
struct device *d, struct device_attribute *attr, char *buf) |
| 563 |
{ |
| 564 |
struct net_bridge *br = to_bridge(d); |
| 565 |
return sysfs_emit(buf, "%u\n", br->multicast_ctx.multicast_startup_query_count); |
| 566 |
} |
| 567 |
|
| 568 |
static int set_startup_query_count(struct net_bridge *br, unsigned long val, |
| 569 |
struct netlink_ext_ack *extack) |
| 570 |
{ |
| 571 |
br->multicast_ctx.multicast_startup_query_count = val; |
| 572 |
return 0; |
| 573 |
} |
| 574 |
|
| 575 |
static ssize_t multicast_startup_query_count_store( |
| 576 |
struct device *d, struct device_attribute *attr, const char *buf, |
| 577 |
size_t len) |
| 578 |
{ |
| 579 |
return store_bridge_parm(d, buf, len, set_startup_query_count); |
| 580 |
} |
| 581 |
static DEVICE_ATTR_RW(multicast_startup_query_count); |
| 582 |
|
| 583 |
static ssize_t multicast_last_member_interval_show( |
| 584 |
struct device *d, struct device_attribute *attr, char *buf) |
| 585 |
{ |
| 586 |
struct net_bridge *br = to_bridge(d); |
| 587 |
return sysfs_emit(buf, "%lu\n", |
| 588 |
jiffies_to_clock_t(br->multicast_ctx.multicast_last_member_interval)); |
| 589 |
} |
| 590 |
|
| 591 |
static int set_last_member_interval(struct net_bridge *br, unsigned long val, |
| 592 |
struct netlink_ext_ack *extack) |
| 593 |
{ |
| 594 |
br->multicast_ctx.multicast_last_member_interval = clock_t_to_jiffies(val); |
| 595 |
return 0; |
| 596 |
} |
| 597 |
|
| 598 |
static ssize_t multicast_last_member_interval_store( |
| 599 |
struct device *d, struct device_attribute *attr, const char *buf, |
| 600 |
size_t len) |
| 601 |
{ |
| 602 |
return store_bridge_parm(d, buf, len, set_last_member_interval); |
| 603 |
} |
| 604 |
static DEVICE_ATTR_RW(multicast_last_member_interval); |
| 605 |
|
| 606 |
static ssize_t multicast_membership_interval_show( |
| 607 |
struct device *d, struct device_attribute *attr, char *buf) |
| 608 |
{ |
| 609 |
struct net_bridge *br = to_bridge(d); |
| 610 |
return sysfs_emit(buf, "%lu\n", |
| 611 |
jiffies_to_clock_t(br->multicast_ctx.multicast_membership_interval)); |
| 612 |
} |
| 613 |
|
| 614 |
static int set_membership_interval(struct net_bridge *br, unsigned long val, |
| 615 |
struct netlink_ext_ack *extack) |
| 616 |
{ |
| 617 |
br->multicast_ctx.multicast_membership_interval = clock_t_to_jiffies(val); |
| 618 |
return 0; |
| 619 |
} |
| 620 |
|
| 621 |
static ssize_t multicast_membership_interval_store( |
| 622 |
struct device *d, struct device_attribute *attr, const char *buf, |
| 623 |
size_t len) |
| 624 |
{ |
| 625 |
return store_bridge_parm(d, buf, len, set_membership_interval); |
| 626 |
} |
| 627 |
static DEVICE_ATTR_RW(multicast_membership_interval); |
| 628 |
|
| 629 |
static ssize_t multicast_querier_interval_show(struct device *d, |
| 630 |
struct device_attribute *attr, |
| 631 |
char *buf) |
| 632 |
{ |
| 633 |
struct net_bridge *br = to_bridge(d); |
| 634 |
return sysfs_emit(buf, "%lu\n", |
| 635 |
jiffies_to_clock_t(br->multicast_ctx.multicast_querier_interval)); |
| 636 |
} |
| 637 |
|
| 638 |
static int set_querier_interval(struct net_bridge *br, unsigned long val, |
| 639 |
struct netlink_ext_ack *extack) |
| 640 |
{ |
| 641 |
br->multicast_ctx.multicast_querier_interval = clock_t_to_jiffies(val); |
| 642 |
return 0; |
| 643 |
} |
| 644 |
|
| 645 |
static ssize_t multicast_querier_interval_store(struct device *d, |
| 646 |
struct device_attribute *attr, |
| 647 |
const char *buf, size_t len) |
| 648 |
{ |
| 649 |
return store_bridge_parm(d, buf, len, set_querier_interval); |
| 650 |
} |
| 651 |
static DEVICE_ATTR_RW(multicast_querier_interval); |
| 652 |
|
| 653 |
static ssize_t multicast_query_interval_show(struct device *d, |
| 654 |
struct device_attribute *attr, |
| 655 |
char *buf) |
| 656 |
{ |
| 657 |
struct net_bridge *br = to_bridge(d); |
| 658 |
return sysfs_emit(buf, "%lu\n", |
| 659 |
jiffies_to_clock_t(br->multicast_ctx.multicast_query_interval)); |
| 660 |
} |
| 661 |
|
| 662 |
static int set_query_interval(struct net_bridge *br, unsigned long val, |
| 663 |
struct netlink_ext_ack *extack) |
| 664 |
{ |
| 665 |
br_multicast_set_query_intvl(&br->multicast_ctx, val); |
| 666 |
return 0; |
| 667 |
} |
| 668 |
|
| 669 |
static ssize_t multicast_query_interval_store(struct device *d, |
| 670 |
struct device_attribute *attr, |
| 671 |
const char *buf, size_t len) |
| 672 |
{ |
| 673 |
return store_bridge_parm(d, buf, len, set_query_interval); |
| 674 |
} |
| 675 |
static DEVICE_ATTR_RW(multicast_query_interval); |
| 676 |
|
| 677 |
static ssize_t multicast_query_response_interval_show( |
| 678 |
struct device *d, struct device_attribute *attr, char *buf) |
| 679 |
{ |
| 680 |
struct net_bridge *br = to_bridge(d); |
| 681 |
return sysfs_emit(buf, "%lu\n", |
| 682 |
jiffies_to_clock_t(br->multicast_ctx.multicast_query_response_interval)); |
| 683 |
} |
| 684 |
|
| 685 |
static int set_query_response_interval(struct net_bridge *br, unsigned long val, |
| 686 |
struct netlink_ext_ack *extack) |
| 687 |
{ |
| 688 |
br->multicast_ctx.multicast_query_response_interval = clock_t_to_jiffies(val); |
| 689 |
return 0; |
| 690 |
} |
| 691 |
|
| 692 |
static ssize_t multicast_query_response_interval_store( |
| 693 |
struct device *d, struct device_attribute *attr, const char *buf, |
| 694 |
size_t len) |
| 695 |
{ |
| 696 |
return store_bridge_parm(d, buf, len, set_query_response_interval); |
| 697 |
} |
| 698 |
static DEVICE_ATTR_RW(multicast_query_response_interval); |
| 699 |
|
| 700 |
static ssize_t multicast_startup_query_interval_show( |
| 701 |
struct device *d, struct device_attribute *attr, char *buf) |
| 702 |
{ |
| 703 |
struct net_bridge *br = to_bridge(d); |
| 704 |
return sysfs_emit(buf, "%lu\n", |
| 705 |
jiffies_to_clock_t(br->multicast_ctx.multicast_startup_query_interval)); |
| 706 |
} |
| 707 |
|
| 708 |
static int set_startup_query_interval(struct net_bridge *br, unsigned long val, |
| 709 |
struct netlink_ext_ack *extack) |
| 710 |
{ |
| 711 |
br_multicast_set_startup_query_intvl(&br->multicast_ctx, val); |
| 712 |
return 0; |
| 713 |
} |
| 714 |
|
| 715 |
static ssize_t multicast_startup_query_interval_store( |
| 716 |
struct device *d, struct device_attribute *attr, const char *buf, |
| 717 |
size_t len) |
| 718 |
{ |
| 719 |
return store_bridge_parm(d, buf, len, set_startup_query_interval); |
| 720 |
} |
| 721 |
static DEVICE_ATTR_RW(multicast_startup_query_interval); |
| 722 |
|
| 723 |
static ssize_t multicast_stats_enabled_show(struct device *d, |
| 724 |
struct device_attribute *attr, |
| 725 |
char *buf) |
| 726 |
{ |
| 727 |
struct net_bridge *br = to_bridge(d); |
| 728 |
|
| 729 |
return sysfs_emit(buf, "%d\n", |
| 730 |
br_opt_get(br, BROPT_MULTICAST_STATS_ENABLED)); |
| 731 |
} |
| 732 |
|
| 733 |
static int set_stats_enabled(struct net_bridge *br, unsigned long val, |
| 734 |
struct netlink_ext_ack *extack) |
| 735 |
{ |
| 736 |
br_opt_toggle(br, BROPT_MULTICAST_STATS_ENABLED, !!val); |
| 737 |
return 0; |
| 738 |
} |
| 739 |
|
| 740 |
static ssize_t multicast_stats_enabled_store(struct device *d, |
| 741 |
struct device_attribute *attr, |
| 742 |
const char *buf, |
| 743 |
size_t len) |
| 744 |
{ |
| 745 |
return store_bridge_parm(d, buf, len, set_stats_enabled); |
| 746 |
} |
| 747 |
static DEVICE_ATTR_RW(multicast_stats_enabled); |
| 748 |
|
| 749 |
#if IS_ENABLED(CONFIG_IPV6) |
| 750 |
static ssize_t multicast_mld_version_show(struct device *d, |
| 751 |
struct device_attribute *attr, |
| 752 |
char *buf) |
| 753 |
{ |
| 754 |
struct net_bridge *br = to_bridge(d); |
| 755 |
|
| 756 |
return sysfs_emit(buf, "%u\n", br->multicast_ctx.multicast_mld_version); |
| 757 |
} |
| 758 |
|
| 759 |
static int set_multicast_mld_version(struct net_bridge *br, unsigned long val, |
| 760 |
struct netlink_ext_ack *extack) |
| 761 |
{ |
| 762 |
return br_multicast_set_mld_version(&br->multicast_ctx, val); |
| 763 |
} |
| 764 |
|
| 765 |
static ssize_t multicast_mld_version_store(struct device *d, |
| 766 |
struct device_attribute *attr, |
| 767 |
const char *buf, size_t len) |
| 768 |
{ |
| 769 |
return store_bridge_parm(d, buf, len, set_multicast_mld_version); |
| 770 |
} |
| 771 |
static DEVICE_ATTR_RW(multicast_mld_version); |
| 772 |
#endif |
| 773 |
#endif |
| 774 |
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
| 775 |
static ssize_t nf_call_iptables_show( |
| 776 |
struct device *d, struct device_attribute *attr, char *buf) |
| 777 |
{ |
| 778 |
struct net_bridge *br = to_bridge(d); |
| 779 |
return sysfs_emit(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_IPTABLES)); |
| 780 |
} |
| 781 |
|
| 782 |
static int set_nf_call_iptables(struct net_bridge *br, unsigned long val, |
| 783 |
struct netlink_ext_ack *extack) |
| 784 |
{ |
| 785 |
br_opt_toggle(br, BROPT_NF_CALL_IPTABLES, !!val); |
| 786 |
return 0; |
| 787 |
} |
| 788 |
|
| 789 |
static ssize_t nf_call_iptables_store( |
| 790 |
struct device *d, struct device_attribute *attr, const char *buf, |
| 791 |
size_t len) |
| 792 |
{ |
| 793 |
return store_bridge_parm(d, buf, len, set_nf_call_iptables); |
| 794 |
} |
| 795 |
static DEVICE_ATTR_RW(nf_call_iptables); |
| 796 |
|
| 797 |
static ssize_t nf_call_ip6tables_show( |
| 798 |
struct device *d, struct device_attribute *attr, char *buf) |
| 799 |
{ |
| 800 |
struct net_bridge *br = to_bridge(d); |
| 801 |
return sysfs_emit(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_IP6TABLES)); |
| 802 |
} |
| 803 |
|
| 804 |
static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val, |
| 805 |
struct netlink_ext_ack *extack) |
| 806 |
{ |
| 807 |
br_opt_toggle(br, BROPT_NF_CALL_IP6TABLES, !!val); |
| 808 |
return 0; |
| 809 |
} |
| 810 |
|
| 811 |
static ssize_t nf_call_ip6tables_store( |
| 812 |
struct device *d, struct device_attribute *attr, const char *buf, |
| 813 |
size_t len) |
| 814 |
{ |
| 815 |
return store_bridge_parm(d, buf, len, set_nf_call_ip6tables); |
| 816 |
} |
| 817 |
static DEVICE_ATTR_RW(nf_call_ip6tables); |
| 818 |
|
| 819 |
static ssize_t nf_call_arptables_show( |
| 820 |
struct device *d, struct device_attribute *attr, char *buf) |
| 821 |
{ |
| 822 |
struct net_bridge *br = to_bridge(d); |
| 823 |
return sysfs_emit(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_ARPTABLES)); |
| 824 |
} |
| 825 |
|
| 826 |
static int set_nf_call_arptables(struct net_bridge *br, unsigned long val, |
| 827 |
struct netlink_ext_ack *extack) |
| 828 |
{ |
| 829 |
br_opt_toggle(br, BROPT_NF_CALL_ARPTABLES, !!val); |
| 830 |
return 0; |
| 831 |
} |
| 832 |
|
| 833 |
static ssize_t nf_call_arptables_store( |
| 834 |
struct device *d, struct device_attribute *attr, const char *buf, |
| 835 |
size_t len) |
| 836 |
{ |
| 837 |
return store_bridge_parm(d, buf, len, set_nf_call_arptables); |
| 838 |
} |
| 839 |
static DEVICE_ATTR_RW(nf_call_arptables); |
| 840 |
#endif |
| 841 |
#ifdef CONFIG_BRIDGE_VLAN_FILTERING |
| 842 |
static ssize_t vlan_filtering_show(struct device *d, |
| 843 |
struct device_attribute *attr, |
| 844 |
char *buf) |
| 845 |
{ |
| 846 |
struct net_bridge *br = to_bridge(d); |
| 847 |
return sysfs_emit(buf, "%d\n", br_opt_get(br, BROPT_VLAN_ENABLED)); |
| 848 |
} |
| 849 |
|
| 850 |
static ssize_t vlan_filtering_store(struct device *d, |
| 851 |
struct device_attribute *attr, |
| 852 |
const char *buf, size_t len) |
| 853 |
{ |
| 854 |
return store_bridge_parm(d, buf, len, br_vlan_filter_toggle); |
| 855 |
} |
| 856 |
static DEVICE_ATTR_RW(vlan_filtering); |
| 857 |
|
| 858 |
static ssize_t vlan_protocol_show(struct device *d, |
| 859 |
struct device_attribute *attr, |
| 860 |
char *buf) |
| 861 |
{ |
| 862 |
struct net_bridge *br = to_bridge(d); |
| 863 |
return sysfs_emit(buf, "%#06x\n", ntohs(br->vlan_proto)); |
| 864 |
} |
| 865 |
|
| 866 |
static ssize_t vlan_protocol_store(struct device *d, |
| 867 |
struct device_attribute *attr, |
| 868 |
const char *buf, size_t len) |
| 869 |
{ |
| 870 |
return store_bridge_parm(d, buf, len, br_vlan_set_proto); |
| 871 |
} |
| 872 |
static DEVICE_ATTR_RW(vlan_protocol); |
| 873 |
|
| 874 |
static ssize_t default_pvid_show(struct device *d, |
| 875 |
struct device_attribute *attr, |
| 876 |
char *buf) |
| 877 |
{ |
| 878 |
struct net_bridge *br = to_bridge(d); |
| 879 |
return sysfs_emit(buf, "%d\n", br->default_pvid); |
| 880 |
} |
| 881 |
|
| 882 |
static ssize_t default_pvid_store(struct device *d, |
| 883 |
struct device_attribute *attr, |
| 884 |
const char *buf, size_t len) |
| 885 |
{ |
| 886 |
return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid); |
| 887 |
} |
| 888 |
static DEVICE_ATTR_RW(default_pvid); |
| 889 |
|
| 890 |
static ssize_t vlan_stats_enabled_show(struct device *d, |
| 891 |
struct device_attribute *attr, |
| 892 |
char *buf) |
| 893 |
{ |
| 894 |
struct net_bridge *br = to_bridge(d); |
| 895 |
return sysfs_emit(buf, "%u\n", br_opt_get(br, BROPT_VLAN_STATS_ENABLED)); |
| 896 |
} |
| 897 |
|
| 898 |
static int set_vlan_stats_enabled(struct net_bridge *br, unsigned long val, |
| 899 |
struct netlink_ext_ack *extack) |
| 900 |
{ |
| 901 |
return br_vlan_set_stats(br, val); |
| 902 |
} |
| 903 |
|
| 904 |
static ssize_t vlan_stats_enabled_store(struct device *d, |
| 905 |
struct device_attribute *attr, |
| 906 |
const char *buf, size_t len) |
| 907 |
{ |
| 908 |
return store_bridge_parm(d, buf, len, set_vlan_stats_enabled); |
| 909 |
} |
| 910 |
static DEVICE_ATTR_RW(vlan_stats_enabled); |
| 911 |
|
| 912 |
static ssize_t vlan_stats_per_port_show(struct device *d, |
| 913 |
struct device_attribute *attr, |
| 914 |
char *buf) |
| 915 |
{ |
| 916 |
struct net_bridge *br = to_bridge(d); |
| 917 |
return sysfs_emit(buf, "%u\n", br_opt_get(br, BROPT_VLAN_STATS_PER_PORT)); |
| 918 |
} |
| 919 |
|
| 920 |
static int set_vlan_stats_per_port(struct net_bridge *br, unsigned long val, |
| 921 |
struct netlink_ext_ack *extack) |
| 922 |
{ |
| 923 |
return br_vlan_set_stats_per_port(br, val); |
| 924 |
} |
| 925 |
|
| 926 |
static ssize_t vlan_stats_per_port_store(struct device *d, |
| 927 |
struct device_attribute *attr, |
| 928 |
const char *buf, size_t len) |
| 929 |
{ |
| 930 |
return store_bridge_parm(d, buf, len, set_vlan_stats_per_port); |
| 931 |
} |
| 932 |
static DEVICE_ATTR_RW(vlan_stats_per_port); |
| 933 |
#endif |
| 934 |
|
| 935 |
static struct attribute *bridge_attrs[] = { |
| 936 |
&dev_attr_forward_delay.attr, |
| 937 |
&dev_attr_hello_time.attr, |
| 938 |
&dev_attr_max_age.attr, |
| 939 |
&dev_attr_ageing_time.attr, |
| 940 |
&dev_attr_stp_state.attr, |
| 941 |
&dev_attr_group_fwd_mask.attr, |
| 942 |
&dev_attr_priority.attr, |
| 943 |
&dev_attr_bridge_id.attr, |
| 944 |
&dev_attr_root_id.attr, |
| 945 |
&dev_attr_root_path_cost.attr, |
| 946 |
&dev_attr_root_port.attr, |
| 947 |
&dev_attr_topology_change.attr, |
| 948 |
&dev_attr_topology_change_detected.attr, |
| 949 |
&dev_attr_hello_timer.attr, |
| 950 |
&dev_attr_tcn_timer.attr, |
| 951 |
&dev_attr_topology_change_timer.attr, |
| 952 |
&dev_attr_gc_timer.attr, |
| 953 |
&dev_attr_group_addr.attr, |
| 954 |
&dev_attr_flush.attr, |
| 955 |
&dev_attr_no_linklocal_learn.attr, |
| 956 |
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING |
| 957 |
&dev_attr_multicast_router.attr, |
| 958 |
&dev_attr_multicast_snooping.attr, |
| 959 |
&dev_attr_multicast_querier.attr, |
| 960 |
&dev_attr_multicast_query_use_ifaddr.attr, |
| 961 |
&dev_attr_hash_elasticity.attr, |
| 962 |
&dev_attr_hash_max.attr, |
| 963 |
&dev_attr_multicast_last_member_count.attr, |
| 964 |
&dev_attr_multicast_startup_query_count.attr, |
| 965 |
&dev_attr_multicast_last_member_interval.attr, |
| 966 |
&dev_attr_multicast_membership_interval.attr, |
| 967 |
&dev_attr_multicast_querier_interval.attr, |
| 968 |
&dev_attr_multicast_query_interval.attr, |
| 969 |
&dev_attr_multicast_query_response_interval.attr, |
| 970 |
&dev_attr_multicast_startup_query_interval.attr, |
| 971 |
&dev_attr_multicast_stats_enabled.attr, |
| 972 |
&dev_attr_multicast_igmp_version.attr, |
| 973 |
#if IS_ENABLED(CONFIG_IPV6) |
| 974 |
&dev_attr_multicast_mld_version.attr, |
| 975 |
#endif |
| 976 |
#endif |
| 977 |
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
| 978 |
&dev_attr_nf_call_iptables.attr, |
| 979 |
&dev_attr_nf_call_ip6tables.attr, |
| 980 |
&dev_attr_nf_call_arptables.attr, |
| 981 |
#endif |
| 982 |
#ifdef CONFIG_BRIDGE_VLAN_FILTERING |
| 983 |
&dev_attr_vlan_filtering.attr, |
| 984 |
&dev_attr_vlan_protocol.attr, |
| 985 |
&dev_attr_default_pvid.attr, |
| 986 |
&dev_attr_vlan_stats_enabled.attr, |
| 987 |
&dev_attr_vlan_stats_per_port.attr, |
| 988 |
#endif |
| 989 |
NULL |
| 990 |
}; |
| 991 |
|
| 992 |
static const struct attribute_group bridge_group = { |
| 993 |
.name = SYSFS_BRIDGE_ATTR, |
| 994 |
.attrs = bridge_attrs, |
| 995 |
}; |
| 996 |
|
| 997 |
/* |
| 998 |
* Export the forwarding information table as a binary file |
| 999 |
* The records are struct __fdb_entry. |
| 1000 |
* |
| 1001 |
* Returns the number of bytes read. |
| 1002 |
*/ |
| 1003 |
static ssize_t brforward_read(struct file *filp, struct kobject *kobj, |
| 1004 |
const struct bin_attribute *bin_attr, |
| 1005 |
char *buf, loff_t off, size_t count) |
| 1006 |
{ |
| 1007 |
struct device *dev = kobj_to_dev(kobj); |
| 1008 |
struct net_bridge *br = to_bridge(dev); |
| 1009 |
int n; |
| 1010 |
|
| 1011 |
/* must read whole records */ |
| 1012 |
if (off % sizeof(struct __fdb_entry) != 0) |
| 1013 |
return -EINVAL; |
| 1014 |
|
| 1015 |
n = br_fdb_fillbuf(br, buf, |
| 1016 |
count / sizeof(struct __fdb_entry), |
| 1017 |
off / sizeof(struct __fdb_entry)); |
| 1018 |
|
| 1019 |
if (n > 0) |
| 1020 |
n *= sizeof(struct __fdb_entry); |
| 1021 |
|
| 1022 |
return n; |
| 1023 |
} |
| 1024 |
|
| 1025 |
static const struct bin_attribute bridge_forward = { |
| 1026 |
.attr = { .name = SYSFS_BRIDGE_FDB, |
| 1027 |
.mode = 0444, }, |
| 1028 |
.read = brforward_read, |
| 1029 |
}; |
| 1030 |
|
| 1031 |
/* |
| 1032 |
* Add entries in sysfs onto the existing network class device |
| 1033 |
* for the bridge. |
| 1034 |
* Adds a attribute group "bridge" containing tuning parameters. |
| 1035 |
* Binary attribute containing the forward table |
| 1036 |
* Sub directory to hold links to interfaces. |
| 1037 |
* |
| 1038 |
* Note: the ifobj exists only to be a subdirectory |
| 1039 |
* to hold links. The ifobj exists in same data structure |
| 1040 |
* as it's parent the bridge so reference counting works. |
| 1041 |
*/ |
| 1042 |
int br_sysfs_addbr(struct net_device *dev) |
| 1043 |
{ |
| 1044 |
struct kobject *brobj = &dev->dev.kobj; |
| 1045 |
struct net_bridge *br = netdev_priv(dev); |
| 1046 |
int err; |
| 1047 |
|
| 1048 |
err = sysfs_create_group(brobj, &bridge_group); |
| 1049 |
if (err) { |
| 1050 |
pr_info("%s: can't create group %s/%s\n", |
| 1051 |
__func__, dev->name, bridge_group.name); |
| 1052 |
goto out1; |
| 1053 |
} |
| 1054 |
|
| 1055 |
err = sysfs_create_bin_file(brobj, &bridge_forward); |
| 1056 |
if (err) { |
| 1057 |
pr_info("%s: can't create attribute file %s/%s\n", |
| 1058 |
__func__, dev->name, bridge_forward.attr.name); |
| 1059 |
goto out2; |
| 1060 |
} |
| 1061 |
|
| 1062 |
br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj); |
| 1063 |
if (!br->ifobj) { |
| 1064 |
pr_info("%s: can't add kobject (directory) %s/%s\n", |
| 1065 |
__func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR); |
| 1066 |
err = -ENOMEM; |
| 1067 |
goto out3; |
| 1068 |
} |
| 1069 |
return 0; |
| 1070 |
out3: |
| 1071 |
sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward); |
| 1072 |
out2: |
| 1073 |
sysfs_remove_group(&dev->dev.kobj, &bridge_group); |
| 1074 |
out1: |
| 1075 |
return err; |
| 1076 |
|
| 1077 |
} |
| 1078 |
|
| 1079 |
void br_sysfs_delbr(struct net_device *dev) |
| 1080 |
{ |
| 1081 |
struct kobject *kobj = &dev->dev.kobj; |
| 1082 |
struct net_bridge *br = netdev_priv(dev); |
| 1083 |
|
| 1084 |
kobject_put(br->ifobj); |
| 1085 |
sysfs_remove_bin_file(kobj, &bridge_forward); |
| 1086 |
sysfs_remove_group(kobj, &bridge_group); |
| 1087 |
} |