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