1 /* 2 * Sysfs attributes of bridge 3 * Linux ethernet bridge 4 * 5 * Authors: 6 * Stephen Hemminger <shemminger@osdl.org> 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 11 * 2 of the License, or (at your option) any later version. 12 */ 13 14 #include <linux/capability.h> 15 #include <linux/kernel.h> 16 #include <linux/netdevice.h> 17 #include <linux/etherdevice.h> 18 #include <linux/if_bridge.h> 19 #include <linux/rtnetlink.h> 20 #include <linux/spinlock.h> 21 #include <linux/times.h> 22 23 #include "br_private.h" 24 25 #define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd))) 26 27 /* 28 * Common code for storing bridge parameters. 29 */ 30 static ssize_t store_bridge_parm(struct device *d, 31 const char *buf, size_t len, 32 int (*set)(struct net_bridge *, unsigned long)) 33 { 34 struct net_bridge *br = to_bridge(d); 35 char *endp; 36 unsigned long val; 37 int err; 38 39 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) 40 return -EPERM; 41 42 val = simple_strtoul(buf, &endp, 0); 43 if (endp == buf) 44 return -EINVAL; 45 46 if (!rtnl_trylock()) 47 return restart_syscall(); 48 49 err = (*set)(br, val); 50 if (!err) 51 netdev_state_change(br->dev); 52 rtnl_unlock(); 53 54 return err ? err : len; 55 } 56 57 58 static ssize_t forward_delay_show(struct device *d, 59 struct device_attribute *attr, char *buf) 60 { 61 struct net_bridge *br = to_bridge(d); 62 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay)); 63 } 64 65 static ssize_t forward_delay_store(struct device *d, 66 struct device_attribute *attr, 67 const char *buf, size_t len) 68 { 69 return store_bridge_parm(d, buf, len, br_set_forward_delay); 70 } 71 static DEVICE_ATTR_RW(forward_delay); 72 73 static ssize_t hello_time_show(struct device *d, struct device_attribute *attr, 74 char *buf) 75 { 76 return sprintf(buf, "%lu\n", 77 jiffies_to_clock_t(to_bridge(d)->hello_time)); 78 } 79 80 static ssize_t hello_time_store(struct device *d, 81 struct device_attribute *attr, const char *buf, 82 size_t len) 83 { 84 return store_bridge_parm(d, buf, len, br_set_hello_time); 85 } 86 static DEVICE_ATTR_RW(hello_time); 87 88 static ssize_t max_age_show(struct device *d, struct device_attribute *attr, 89 char *buf) 90 { 91 return sprintf(buf, "%lu\n", 92 jiffies_to_clock_t(to_bridge(d)->max_age)); 93 } 94 95 static ssize_t max_age_store(struct device *d, struct device_attribute *attr, 96 const char *buf, size_t len) 97 { 98 return store_bridge_parm(d, buf, len, br_set_max_age); 99 } 100 static DEVICE_ATTR_RW(max_age); 101 102 static ssize_t ageing_time_show(struct device *d, 103 struct device_attribute *attr, char *buf) 104 { 105 struct net_bridge *br = to_bridge(d); 106 return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time)); 107 } 108 109 static int set_ageing_time(struct net_bridge *br, unsigned long val) 110 { 111 return br_set_ageing_time(br, val); 112 } 113 114 static ssize_t ageing_time_store(struct device *d, 115 struct device_attribute *attr, 116 const char *buf, size_t len) 117 { 118 return store_bridge_parm(d, buf, len, set_ageing_time); 119 } 120 static DEVICE_ATTR_RW(ageing_time); 121 122 static ssize_t stp_state_show(struct device *d, 123 struct device_attribute *attr, char *buf) 124 { 125 struct net_bridge *br = to_bridge(d); 126 return sprintf(buf, "%d\n", br->stp_enabled); 127 } 128 129 130 static int set_stp_state(struct net_bridge *br, unsigned long val) 131 { 132 br_stp_set_enabled(br, val); 133 134 return 0; 135 } 136 137 static ssize_t stp_state_store(struct device *d, 138 struct device_attribute *attr, const char *buf, 139 size_t len) 140 { 141 return store_bridge_parm(d, buf, len, set_stp_state); 142 } 143 static DEVICE_ATTR_RW(stp_state); 144 145 static ssize_t group_fwd_mask_show(struct device *d, 146 struct device_attribute *attr, 147 char *buf) 148 { 149 struct net_bridge *br = to_bridge(d); 150 return sprintf(buf, "%#x\n", br->group_fwd_mask); 151 } 152 153 static int set_group_fwd_mask(struct net_bridge *br, unsigned long val) 154 { 155 if (val & BR_GROUPFWD_RESTRICTED) 156 return -EINVAL; 157 158 br->group_fwd_mask = val; 159 160 return 0; 161 } 162 163 static ssize_t group_fwd_mask_store(struct device *d, 164 struct device_attribute *attr, 165 const char *buf, 166 size_t len) 167 { 168 return store_bridge_parm(d, buf, len, set_group_fwd_mask); 169 } 170 static DEVICE_ATTR_RW(group_fwd_mask); 171 172 static ssize_t priority_show(struct device *d, struct device_attribute *attr, 173 char *buf) 174 { 175 struct net_bridge *br = to_bridge(d); 176 return sprintf(buf, "%d\n", 177 (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]); 178 } 179 180 static int set_priority(struct net_bridge *br, unsigned long val) 181 { 182 br_stp_set_bridge_priority(br, (u16) val); 183 return 0; 184 } 185 186 static ssize_t priority_store(struct device *d, struct device_attribute *attr, 187 const char *buf, size_t len) 188 { 189 return store_bridge_parm(d, buf, len, set_priority); 190 } 191 static DEVICE_ATTR_RW(priority); 192 193 static ssize_t root_id_show(struct device *d, struct device_attribute *attr, 194 char *buf) 195 { 196 return br_show_bridge_id(buf, &to_bridge(d)->designated_root); 197 } 198 static DEVICE_ATTR_RO(root_id); 199 200 static ssize_t bridge_id_show(struct device *d, struct device_attribute *attr, 201 char *buf) 202 { 203 return br_show_bridge_id(buf, &to_bridge(d)->bridge_id); 204 } 205 static DEVICE_ATTR_RO(bridge_id); 206 207 static ssize_t root_port_show(struct device *d, struct device_attribute *attr, 208 char *buf) 209 { 210 return sprintf(buf, "%d\n", to_bridge(d)->root_port); 211 } 212 static DEVICE_ATTR_RO(root_port); 213 214 static ssize_t root_path_cost_show(struct device *d, 215 struct device_attribute *attr, char *buf) 216 { 217 return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost); 218 } 219 static DEVICE_ATTR_RO(root_path_cost); 220 221 static ssize_t topology_change_show(struct device *d, 222 struct device_attribute *attr, char *buf) 223 { 224 return sprintf(buf, "%d\n", to_bridge(d)->topology_change); 225 } 226 static DEVICE_ATTR_RO(topology_change); 227 228 static ssize_t topology_change_detected_show(struct device *d, 229 struct device_attribute *attr, 230 char *buf) 231 { 232 struct net_bridge *br = to_bridge(d); 233 return sprintf(buf, "%d\n", br->topology_change_detected); 234 } 235 static DEVICE_ATTR_RO(topology_change_detected); 236 237 static ssize_t hello_timer_show(struct device *d, 238 struct device_attribute *attr, char *buf) 239 { 240 struct net_bridge *br = to_bridge(d); 241 return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer)); 242 } 243 static DEVICE_ATTR_RO(hello_timer); 244 245 static ssize_t tcn_timer_show(struct device *d, struct device_attribute *attr, 246 char *buf) 247 { 248 struct net_bridge *br = to_bridge(d); 249 return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer)); 250 } 251 static DEVICE_ATTR_RO(tcn_timer); 252 253 static ssize_t topology_change_timer_show(struct device *d, 254 struct device_attribute *attr, 255 char *buf) 256 { 257 struct net_bridge *br = to_bridge(d); 258 return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer)); 259 } 260 static DEVICE_ATTR_RO(topology_change_timer); 261 262 static ssize_t gc_timer_show(struct device *d, struct device_attribute *attr, 263 char *buf) 264 { 265 struct net_bridge *br = to_bridge(d); 266 return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer)); 267 } 268 static DEVICE_ATTR_RO(gc_timer); 269 270 static ssize_t group_addr_show(struct device *d, 271 struct device_attribute *attr, char *buf) 272 { 273 struct net_bridge *br = to_bridge(d); 274 return sprintf(buf, "%x:%x:%x:%x:%x:%x\n", 275 br->group_addr[0], br->group_addr[1], 276 br->group_addr[2], br->group_addr[3], 277 br->group_addr[4], br->group_addr[5]); 278 } 279 280 static ssize_t group_addr_store(struct device *d, 281 struct device_attribute *attr, 282 const char *buf, size_t len) 283 { 284 struct net_bridge *br = to_bridge(d); 285 u8 new_addr[6]; 286 int i; 287 288 if (!ns_capable(dev_net(br->dev)->user_ns, CAP_NET_ADMIN)) 289 return -EPERM; 290 291 if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", 292 &new_addr[0], &new_addr[1], &new_addr[2], 293 &new_addr[3], &new_addr[4], &new_addr[5]) != 6) 294 return -EINVAL; 295 296 if (!is_link_local_ether_addr(new_addr)) 297 return -EINVAL; 298 299 if (new_addr[5] == 1 || /* 802.3x Pause address */ 300 new_addr[5] == 2 || /* 802.3ad Slow protocols */ 301 new_addr[5] == 3) /* 802.1X PAE address */ 302 return -EINVAL; 303 304 if (!rtnl_trylock()) 305 return restart_syscall(); 306 307 spin_lock_bh(&br->lock); 308 for (i = 0; i < 6; i++) 309 br->group_addr[i] = new_addr[i]; 310 spin_unlock_bh(&br->lock); 311 312 br->group_addr_set = true; 313 br_recalculate_fwd_mask(br); 314 netdev_state_change(br->dev); 315 316 rtnl_unlock(); 317 318 return len; 319 } 320 321 static DEVICE_ATTR_RW(group_addr); 322 323 static int set_flush(struct net_bridge *br, unsigned long val) 324 { 325 br_fdb_flush(br); 326 return 0; 327 } 328 329 static ssize_t flush_store(struct device *d, 330 struct device_attribute *attr, 331 const char *buf, size_t len) 332 { 333 return store_bridge_parm(d, buf, len, set_flush); 334 } 335 static DEVICE_ATTR_WO(flush); 336 337 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 338 static ssize_t multicast_router_show(struct device *d, 339 struct device_attribute *attr, char *buf) 340 { 341 struct net_bridge *br = to_bridge(d); 342 return sprintf(buf, "%d\n", br->multicast_router); 343 } 344 345 static ssize_t multicast_router_store(struct device *d, 346 struct device_attribute *attr, 347 const char *buf, size_t len) 348 { 349 return store_bridge_parm(d, buf, len, br_multicast_set_router); 350 } 351 static DEVICE_ATTR_RW(multicast_router); 352 353 static ssize_t multicast_snooping_show(struct device *d, 354 struct device_attribute *attr, 355 char *buf) 356 { 357 struct net_bridge *br = to_bridge(d); 358 return sprintf(buf, "%d\n", !br->multicast_disabled); 359 } 360 361 static ssize_t multicast_snooping_store(struct device *d, 362 struct device_attribute *attr, 363 const char *buf, size_t len) 364 { 365 return store_bridge_parm(d, buf, len, br_multicast_toggle); 366 } 367 static DEVICE_ATTR_RW(multicast_snooping); 368 369 static ssize_t multicast_query_use_ifaddr_show(struct device *d, 370 struct device_attribute *attr, 371 char *buf) 372 { 373 struct net_bridge *br = to_bridge(d); 374 return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr); 375 } 376 377 static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val) 378 { 379 br->multicast_query_use_ifaddr = !!val; 380 return 0; 381 } 382 383 static ssize_t 384 multicast_query_use_ifaddr_store(struct device *d, 385 struct device_attribute *attr, 386 const char *buf, size_t len) 387 { 388 return store_bridge_parm(d, buf, len, set_query_use_ifaddr); 389 } 390 static DEVICE_ATTR_RW(multicast_query_use_ifaddr); 391 392 static ssize_t multicast_querier_show(struct device *d, 393 struct device_attribute *attr, 394 char *buf) 395 { 396 struct net_bridge *br = to_bridge(d); 397 return sprintf(buf, "%d\n", br->multicast_querier); 398 } 399 400 static ssize_t multicast_querier_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, br_multicast_set_querier); 405 } 406 static DEVICE_ATTR_RW(multicast_querier); 407 408 static ssize_t hash_elasticity_show(struct device *d, 409 struct device_attribute *attr, char *buf) 410 { 411 struct net_bridge *br = to_bridge(d); 412 return sprintf(buf, "%u\n", br->hash_elasticity); 413 } 414 415 static int set_elasticity(struct net_bridge *br, unsigned long val) 416 { 417 br->hash_elasticity = val; 418 return 0; 419 } 420 421 static ssize_t hash_elasticity_store(struct device *d, 422 struct device_attribute *attr, 423 const char *buf, size_t len) 424 { 425 return store_bridge_parm(d, buf, len, set_elasticity); 426 } 427 static DEVICE_ATTR_RW(hash_elasticity); 428 429 static ssize_t hash_max_show(struct device *d, struct device_attribute *attr, 430 char *buf) 431 { 432 struct net_bridge *br = to_bridge(d); 433 return sprintf(buf, "%u\n", br->hash_max); 434 } 435 436 static ssize_t hash_max_store(struct device *d, struct device_attribute *attr, 437 const char *buf, size_t len) 438 { 439 return store_bridge_parm(d, buf, len, br_multicast_set_hash_max); 440 } 441 static DEVICE_ATTR_RW(hash_max); 442 443 static ssize_t multicast_last_member_count_show(struct device *d, 444 struct device_attribute *attr, 445 char *buf) 446 { 447 struct net_bridge *br = to_bridge(d); 448 return sprintf(buf, "%u\n", br->multicast_last_member_count); 449 } 450 451 static int set_last_member_count(struct net_bridge *br, unsigned long val) 452 { 453 br->multicast_last_member_count = val; 454 return 0; 455 } 456 457 static ssize_t multicast_last_member_count_store(struct device *d, 458 struct device_attribute *attr, 459 const char *buf, size_t len) 460 { 461 return store_bridge_parm(d, buf, len, set_last_member_count); 462 } 463 static DEVICE_ATTR_RW(multicast_last_member_count); 464 465 static ssize_t multicast_startup_query_count_show( 466 struct device *d, struct device_attribute *attr, char *buf) 467 { 468 struct net_bridge *br = to_bridge(d); 469 return sprintf(buf, "%u\n", br->multicast_startup_query_count); 470 } 471 472 static int set_startup_query_count(struct net_bridge *br, unsigned long val) 473 { 474 br->multicast_startup_query_count = val; 475 return 0; 476 } 477 478 static ssize_t multicast_startup_query_count_store( 479 struct device *d, struct device_attribute *attr, const char *buf, 480 size_t len) 481 { 482 return store_bridge_parm(d, buf, len, set_startup_query_count); 483 } 484 static DEVICE_ATTR_RW(multicast_startup_query_count); 485 486 static ssize_t multicast_last_member_interval_show( 487 struct device *d, struct device_attribute *attr, char *buf) 488 { 489 struct net_bridge *br = to_bridge(d); 490 return sprintf(buf, "%lu\n", 491 jiffies_to_clock_t(br->multicast_last_member_interval)); 492 } 493 494 static int set_last_member_interval(struct net_bridge *br, unsigned long val) 495 { 496 br->multicast_last_member_interval = clock_t_to_jiffies(val); 497 return 0; 498 } 499 500 static ssize_t multicast_last_member_interval_store( 501 struct device *d, struct device_attribute *attr, const char *buf, 502 size_t len) 503 { 504 return store_bridge_parm(d, buf, len, set_last_member_interval); 505 } 506 static DEVICE_ATTR_RW(multicast_last_member_interval); 507 508 static ssize_t multicast_membership_interval_show( 509 struct device *d, struct device_attribute *attr, char *buf) 510 { 511 struct net_bridge *br = to_bridge(d); 512 return sprintf(buf, "%lu\n", 513 jiffies_to_clock_t(br->multicast_membership_interval)); 514 } 515 516 static int set_membership_interval(struct net_bridge *br, unsigned long val) 517 { 518 br->multicast_membership_interval = clock_t_to_jiffies(val); 519 return 0; 520 } 521 522 static ssize_t multicast_membership_interval_store( 523 struct device *d, struct device_attribute *attr, const char *buf, 524 size_t len) 525 { 526 return store_bridge_parm(d, buf, len, set_membership_interval); 527 } 528 static DEVICE_ATTR_RW(multicast_membership_interval); 529 530 static ssize_t multicast_querier_interval_show(struct device *d, 531 struct device_attribute *attr, 532 char *buf) 533 { 534 struct net_bridge *br = to_bridge(d); 535 return sprintf(buf, "%lu\n", 536 jiffies_to_clock_t(br->multicast_querier_interval)); 537 } 538 539 static int set_querier_interval(struct net_bridge *br, unsigned long val) 540 { 541 br->multicast_querier_interval = clock_t_to_jiffies(val); 542 return 0; 543 } 544 545 static ssize_t multicast_querier_interval_store(struct device *d, 546 struct device_attribute *attr, 547 const char *buf, size_t len) 548 { 549 return store_bridge_parm(d, buf, len, set_querier_interval); 550 } 551 static DEVICE_ATTR_RW(multicast_querier_interval); 552 553 static ssize_t multicast_query_interval_show(struct device *d, 554 struct device_attribute *attr, 555 char *buf) 556 { 557 struct net_bridge *br = to_bridge(d); 558 return sprintf(buf, "%lu\n", 559 jiffies_to_clock_t(br->multicast_query_interval)); 560 } 561 562 static int set_query_interval(struct net_bridge *br, unsigned long val) 563 { 564 br->multicast_query_interval = clock_t_to_jiffies(val); 565 return 0; 566 } 567 568 static ssize_t multicast_query_interval_store(struct device *d, 569 struct device_attribute *attr, 570 const char *buf, size_t len) 571 { 572 return store_bridge_parm(d, buf, len, set_query_interval); 573 } 574 static DEVICE_ATTR_RW(multicast_query_interval); 575 576 static ssize_t multicast_query_response_interval_show( 577 struct device *d, struct device_attribute *attr, char *buf) 578 { 579 struct net_bridge *br = to_bridge(d); 580 return sprintf( 581 buf, "%lu\n", 582 jiffies_to_clock_t(br->multicast_query_response_interval)); 583 } 584 585 static int set_query_response_interval(struct net_bridge *br, unsigned long val) 586 { 587 br->multicast_query_response_interval = clock_t_to_jiffies(val); 588 return 0; 589 } 590 591 static ssize_t multicast_query_response_interval_store( 592 struct device *d, struct device_attribute *attr, const char *buf, 593 size_t len) 594 { 595 return store_bridge_parm(d, buf, len, set_query_response_interval); 596 } 597 static DEVICE_ATTR_RW(multicast_query_response_interval); 598 599 static ssize_t multicast_startup_query_interval_show( 600 struct device *d, struct device_attribute *attr, char *buf) 601 { 602 struct net_bridge *br = to_bridge(d); 603 return sprintf( 604 buf, "%lu\n", 605 jiffies_to_clock_t(br->multicast_startup_query_interval)); 606 } 607 608 static int set_startup_query_interval(struct net_bridge *br, unsigned long val) 609 { 610 br->multicast_startup_query_interval = clock_t_to_jiffies(val); 611 return 0; 612 } 613 614 static ssize_t multicast_startup_query_interval_store( 615 struct device *d, struct device_attribute *attr, const char *buf, 616 size_t len) 617 { 618 return store_bridge_parm(d, buf, len, set_startup_query_interval); 619 } 620 static DEVICE_ATTR_RW(multicast_startup_query_interval); 621 #endif 622 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 623 static ssize_t nf_call_iptables_show( 624 struct device *d, struct device_attribute *attr, char *buf) 625 { 626 struct net_bridge *br = to_bridge(d); 627 return sprintf(buf, "%u\n", br->nf_call_iptables); 628 } 629 630 static int set_nf_call_iptables(struct net_bridge *br, unsigned long val) 631 { 632 br->nf_call_iptables = val ? true : false; 633 return 0; 634 } 635 636 static ssize_t nf_call_iptables_store( 637 struct device *d, struct device_attribute *attr, const char *buf, 638 size_t len) 639 { 640 return store_bridge_parm(d, buf, len, set_nf_call_iptables); 641 } 642 static DEVICE_ATTR_RW(nf_call_iptables); 643 644 static ssize_t nf_call_ip6tables_show( 645 struct device *d, struct device_attribute *attr, char *buf) 646 { 647 struct net_bridge *br = to_bridge(d); 648 return sprintf(buf, "%u\n", br->nf_call_ip6tables); 649 } 650 651 static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val) 652 { 653 br->nf_call_ip6tables = val ? true : false; 654 return 0; 655 } 656 657 static ssize_t nf_call_ip6tables_store( 658 struct device *d, struct device_attribute *attr, const char *buf, 659 size_t len) 660 { 661 return store_bridge_parm(d, buf, len, set_nf_call_ip6tables); 662 } 663 static DEVICE_ATTR_RW(nf_call_ip6tables); 664 665 static ssize_t nf_call_arptables_show( 666 struct device *d, struct device_attribute *attr, char *buf) 667 { 668 struct net_bridge *br = to_bridge(d); 669 return sprintf(buf, "%u\n", br->nf_call_arptables); 670 } 671 672 static int set_nf_call_arptables(struct net_bridge *br, unsigned long val) 673 { 674 br->nf_call_arptables = val ? true : false; 675 return 0; 676 } 677 678 static ssize_t nf_call_arptables_store( 679 struct device *d, struct device_attribute *attr, const char *buf, 680 size_t len) 681 { 682 return store_bridge_parm(d, buf, len, set_nf_call_arptables); 683 } 684 static DEVICE_ATTR_RW(nf_call_arptables); 685 #endif 686 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 687 static ssize_t vlan_filtering_show(struct device *d, 688 struct device_attribute *attr, 689 char *buf) 690 { 691 struct net_bridge *br = to_bridge(d); 692 return sprintf(buf, "%d\n", br->vlan_enabled); 693 } 694 695 static ssize_t vlan_filtering_store(struct device *d, 696 struct device_attribute *attr, 697 const char *buf, size_t len) 698 { 699 return store_bridge_parm(d, buf, len, br_vlan_filter_toggle); 700 } 701 static DEVICE_ATTR_RW(vlan_filtering); 702 703 static ssize_t vlan_protocol_show(struct device *d, 704 struct device_attribute *attr, 705 char *buf) 706 { 707 struct net_bridge *br = to_bridge(d); 708 return sprintf(buf, "%#06x\n", ntohs(br->vlan_proto)); 709 } 710 711 static ssize_t vlan_protocol_store(struct device *d, 712 struct device_attribute *attr, 713 const char *buf, size_t len) 714 { 715 return store_bridge_parm(d, buf, len, br_vlan_set_proto); 716 } 717 static DEVICE_ATTR_RW(vlan_protocol); 718 719 static ssize_t default_pvid_show(struct device *d, 720 struct device_attribute *attr, 721 char *buf) 722 { 723 struct net_bridge *br = to_bridge(d); 724 return sprintf(buf, "%d\n", br->default_pvid); 725 } 726 727 static ssize_t default_pvid_store(struct device *d, 728 struct device_attribute *attr, 729 const char *buf, size_t len) 730 { 731 return store_bridge_parm(d, buf, len, br_vlan_set_default_pvid); 732 } 733 static DEVICE_ATTR_RW(default_pvid); 734 735 static ssize_t vlan_stats_enabled_show(struct device *d, 736 struct device_attribute *attr, 737 char *buf) 738 { 739 struct net_bridge *br = to_bridge(d); 740 return sprintf(buf, "%u\n", br->vlan_stats_enabled); 741 } 742 743 static ssize_t vlan_stats_enabled_store(struct device *d, 744 struct device_attribute *attr, 745 const char *buf, size_t len) 746 { 747 return store_bridge_parm(d, buf, len, br_vlan_set_stats); 748 } 749 static DEVICE_ATTR_RW(vlan_stats_enabled); 750 #endif 751 752 static struct attribute *bridge_attrs[] = { 753 &dev_attr_forward_delay.attr, 754 &dev_attr_hello_time.attr, 755 &dev_attr_max_age.attr, 756 &dev_attr_ageing_time.attr, 757 &dev_attr_stp_state.attr, 758 &dev_attr_group_fwd_mask.attr, 759 &dev_attr_priority.attr, 760 &dev_attr_bridge_id.attr, 761 &dev_attr_root_id.attr, 762 &dev_attr_root_path_cost.attr, 763 &dev_attr_root_port.attr, 764 &dev_attr_topology_change.attr, 765 &dev_attr_topology_change_detected.attr, 766 &dev_attr_hello_timer.attr, 767 &dev_attr_tcn_timer.attr, 768 &dev_attr_topology_change_timer.attr, 769 &dev_attr_gc_timer.attr, 770 &dev_attr_group_addr.attr, 771 &dev_attr_flush.attr, 772 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 773 &dev_attr_multicast_router.attr, 774 &dev_attr_multicast_snooping.attr, 775 &dev_attr_multicast_querier.attr, 776 &dev_attr_multicast_query_use_ifaddr.attr, 777 &dev_attr_hash_elasticity.attr, 778 &dev_attr_hash_max.attr, 779 &dev_attr_multicast_last_member_count.attr, 780 &dev_attr_multicast_startup_query_count.attr, 781 &dev_attr_multicast_last_member_interval.attr, 782 &dev_attr_multicast_membership_interval.attr, 783 &dev_attr_multicast_querier_interval.attr, 784 &dev_attr_multicast_query_interval.attr, 785 &dev_attr_multicast_query_response_interval.attr, 786 &dev_attr_multicast_startup_query_interval.attr, 787 #endif 788 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 789 &dev_attr_nf_call_iptables.attr, 790 &dev_attr_nf_call_ip6tables.attr, 791 &dev_attr_nf_call_arptables.attr, 792 #endif 793 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 794 &dev_attr_vlan_filtering.attr, 795 &dev_attr_vlan_protocol.attr, 796 &dev_attr_default_pvid.attr, 797 &dev_attr_vlan_stats_enabled.attr, 798 #endif 799 NULL 800 }; 801 802 static struct attribute_group bridge_group = { 803 .name = SYSFS_BRIDGE_ATTR, 804 .attrs = bridge_attrs, 805 }; 806 807 /* 808 * Export the forwarding information table as a binary file 809 * The records are struct __fdb_entry. 810 * 811 * Returns the number of bytes read. 812 */ 813 static ssize_t brforward_read(struct file *filp, struct kobject *kobj, 814 struct bin_attribute *bin_attr, 815 char *buf, loff_t off, size_t count) 816 { 817 struct device *dev = kobj_to_dev(kobj); 818 struct net_bridge *br = to_bridge(dev); 819 int n; 820 821 /* must read whole records */ 822 if (off % sizeof(struct __fdb_entry) != 0) 823 return -EINVAL; 824 825 n = br_fdb_fillbuf(br, buf, 826 count / sizeof(struct __fdb_entry), 827 off / sizeof(struct __fdb_entry)); 828 829 if (n > 0) 830 n *= sizeof(struct __fdb_entry); 831 832 return n; 833 } 834 835 static struct bin_attribute bridge_forward = { 836 .attr = { .name = SYSFS_BRIDGE_FDB, 837 .mode = S_IRUGO, }, 838 .read = brforward_read, 839 }; 840 841 /* 842 * Add entries in sysfs onto the existing network class device 843 * for the bridge. 844 * Adds a attribute group "bridge" containing tuning parameters. 845 * Binary attribute containing the forward table 846 * Sub directory to hold links to interfaces. 847 * 848 * Note: the ifobj exists only to be a subdirectory 849 * to hold links. The ifobj exists in same data structure 850 * as it's parent the bridge so reference counting works. 851 */ 852 int br_sysfs_addbr(struct net_device *dev) 853 { 854 struct kobject *brobj = &dev->dev.kobj; 855 struct net_bridge *br = netdev_priv(dev); 856 int err; 857 858 err = sysfs_create_group(brobj, &bridge_group); 859 if (err) { 860 pr_info("%s: can't create group %s/%s\n", 861 __func__, dev->name, bridge_group.name); 862 goto out1; 863 } 864 865 err = sysfs_create_bin_file(brobj, &bridge_forward); 866 if (err) { 867 pr_info("%s: can't create attribute file %s/%s\n", 868 __func__, dev->name, bridge_forward.attr.name); 869 goto out2; 870 } 871 872 br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj); 873 if (!br->ifobj) { 874 pr_info("%s: can't add kobject (directory) %s/%s\n", 875 __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR); 876 goto out3; 877 } 878 return 0; 879 out3: 880 sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward); 881 out2: 882 sysfs_remove_group(&dev->dev.kobj, &bridge_group); 883 out1: 884 return err; 885 886 } 887 888 void br_sysfs_delbr(struct net_device *dev) 889 { 890 struct kobject *kobj = &dev->dev.kobj; 891 struct net_bridge *br = netdev_priv(dev); 892 893 kobject_put(br->ifobj); 894 sysfs_remove_bin_file(kobj, &bridge_forward); 895 sysfs_remove_group(kobj, &bridge_group); 896 } 897