at v3.10-rc2 21 kB view raw
1/* 2 * net/core/dev_addr_lists.c - Functions for handling net device lists 3 * Copyright (c) 2010 Jiri Pirko <jpirko@redhat.com> 4 * 5 * This file contains functions for working with unicast, multicast and device 6 * addresses lists. 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 */ 13 14#include <linux/netdevice.h> 15#include <linux/rtnetlink.h> 16#include <linux/export.h> 17#include <linux/list.h> 18 19/* 20 * General list handling functions 21 */ 22 23static int __hw_addr_create_ex(struct netdev_hw_addr_list *list, 24 const unsigned char *addr, int addr_len, 25 unsigned char addr_type, bool global, 26 bool sync) 27{ 28 struct netdev_hw_addr *ha; 29 int alloc_size; 30 31 alloc_size = sizeof(*ha); 32 if (alloc_size < L1_CACHE_BYTES) 33 alloc_size = L1_CACHE_BYTES; 34 ha = kmalloc(alloc_size, GFP_ATOMIC); 35 if (!ha) 36 return -ENOMEM; 37 memcpy(ha->addr, addr, addr_len); 38 ha->type = addr_type; 39 ha->refcount = 1; 40 ha->global_use = global; 41 ha->synced = sync; 42 list_add_tail_rcu(&ha->list, &list->list); 43 list->count++; 44 45 return 0; 46} 47 48static int __hw_addr_add_ex(struct netdev_hw_addr_list *list, 49 const unsigned char *addr, int addr_len, 50 unsigned char addr_type, bool global, bool sync) 51{ 52 struct netdev_hw_addr *ha; 53 54 if (addr_len > MAX_ADDR_LEN) 55 return -EINVAL; 56 57 list_for_each_entry(ha, &list->list, list) { 58 if (!memcmp(ha->addr, addr, addr_len) && 59 ha->type == addr_type) { 60 if (global) { 61 /* check if addr is already used as global */ 62 if (ha->global_use) 63 return 0; 64 else 65 ha->global_use = true; 66 } 67 if (sync) { 68 if (ha->synced) 69 return 0; 70 else 71 ha->synced = true; 72 } 73 ha->refcount++; 74 return 0; 75 } 76 } 77 78 return __hw_addr_create_ex(list, addr, addr_len, addr_type, global, 79 sync); 80} 81 82static int __hw_addr_add(struct netdev_hw_addr_list *list, 83 const unsigned char *addr, int addr_len, 84 unsigned char addr_type) 85{ 86 return __hw_addr_add_ex(list, addr, addr_len, addr_type, false, false); 87} 88 89static int __hw_addr_del_entry(struct netdev_hw_addr_list *list, 90 struct netdev_hw_addr *ha, bool global, 91 bool sync) 92{ 93 if (global && !ha->global_use) 94 return -ENOENT; 95 96 if (sync && !ha->synced) 97 return -ENOENT; 98 99 if (global) 100 ha->global_use = false; 101 102 if (sync) 103 ha->synced = false; 104 105 if (--ha->refcount) 106 return 0; 107 list_del_rcu(&ha->list); 108 kfree_rcu(ha, rcu_head); 109 list->count--; 110 return 0; 111} 112 113static int __hw_addr_del_ex(struct netdev_hw_addr_list *list, 114 const unsigned char *addr, int addr_len, 115 unsigned char addr_type, bool global, bool sync) 116{ 117 struct netdev_hw_addr *ha; 118 119 list_for_each_entry(ha, &list->list, list) { 120 if (!memcmp(ha->addr, addr, addr_len) && 121 (ha->type == addr_type || !addr_type)) 122 return __hw_addr_del_entry(list, ha, global, sync); 123 } 124 return -ENOENT; 125} 126 127static int __hw_addr_del(struct netdev_hw_addr_list *list, 128 const unsigned char *addr, int addr_len, 129 unsigned char addr_type) 130{ 131 return __hw_addr_del_ex(list, addr, addr_len, addr_type, false, false); 132} 133 134static int __hw_addr_sync_one(struct netdev_hw_addr_list *to_list, 135 struct netdev_hw_addr *ha, 136 int addr_len) 137{ 138 int err; 139 140 err = __hw_addr_add_ex(to_list, ha->addr, addr_len, ha->type, 141 false, true); 142 if (err) 143 return err; 144 ha->sync_cnt++; 145 ha->refcount++; 146 147 return 0; 148} 149 150static void __hw_addr_unsync_one(struct netdev_hw_addr_list *to_list, 151 struct netdev_hw_addr_list *from_list, 152 struct netdev_hw_addr *ha, 153 int addr_len) 154{ 155 int err; 156 157 err = __hw_addr_del_ex(to_list, ha->addr, addr_len, ha->type, 158 false, true); 159 if (err) 160 return; 161 ha->sync_cnt--; 162 __hw_addr_del_entry(from_list, ha, false, true); 163} 164 165static int __hw_addr_sync_multiple(struct netdev_hw_addr_list *to_list, 166 struct netdev_hw_addr_list *from_list, 167 int addr_len) 168{ 169 int err = 0; 170 struct netdev_hw_addr *ha, *tmp; 171 172 list_for_each_entry_safe(ha, tmp, &from_list->list, list) { 173 if (ha->sync_cnt == ha->refcount) { 174 __hw_addr_unsync_one(to_list, from_list, ha, addr_len); 175 } else { 176 err = __hw_addr_sync_one(to_list, ha, addr_len); 177 if (err) 178 break; 179 } 180 } 181 return err; 182} 183 184int __hw_addr_add_multiple(struct netdev_hw_addr_list *to_list, 185 struct netdev_hw_addr_list *from_list, 186 int addr_len, unsigned char addr_type) 187{ 188 int err; 189 struct netdev_hw_addr *ha, *ha2; 190 unsigned char type; 191 192 list_for_each_entry(ha, &from_list->list, list) { 193 type = addr_type ? addr_type : ha->type; 194 err = __hw_addr_add(to_list, ha->addr, addr_len, type); 195 if (err) 196 goto unroll; 197 } 198 return 0; 199 200unroll: 201 list_for_each_entry(ha2, &from_list->list, list) { 202 if (ha2 == ha) 203 break; 204 type = addr_type ? addr_type : ha2->type; 205 __hw_addr_del(to_list, ha2->addr, addr_len, type); 206 } 207 return err; 208} 209EXPORT_SYMBOL(__hw_addr_add_multiple); 210 211void __hw_addr_del_multiple(struct netdev_hw_addr_list *to_list, 212 struct netdev_hw_addr_list *from_list, 213 int addr_len, unsigned char addr_type) 214{ 215 struct netdev_hw_addr *ha; 216 unsigned char type; 217 218 list_for_each_entry(ha, &from_list->list, list) { 219 type = addr_type ? addr_type : ha->type; 220 __hw_addr_del(to_list, ha->addr, addr_len, type); 221 } 222} 223EXPORT_SYMBOL(__hw_addr_del_multiple); 224 225/* This function only works where there is a strict 1-1 relationship 226 * between source and destionation of they synch. If you ever need to 227 * sync addresses to more then 1 destination, you need to use 228 * __hw_addr_sync_multiple(). 229 */ 230int __hw_addr_sync(struct netdev_hw_addr_list *to_list, 231 struct netdev_hw_addr_list *from_list, 232 int addr_len) 233{ 234 int err = 0; 235 struct netdev_hw_addr *ha, *tmp; 236 237 list_for_each_entry_safe(ha, tmp, &from_list->list, list) { 238 if (!ha->sync_cnt) { 239 err = __hw_addr_sync_one(to_list, ha, addr_len); 240 if (err) 241 break; 242 } else if (ha->refcount == 1) 243 __hw_addr_unsync_one(to_list, from_list, ha, addr_len); 244 } 245 return err; 246} 247EXPORT_SYMBOL(__hw_addr_sync); 248 249void __hw_addr_unsync(struct netdev_hw_addr_list *to_list, 250 struct netdev_hw_addr_list *from_list, 251 int addr_len) 252{ 253 struct netdev_hw_addr *ha, *tmp; 254 255 list_for_each_entry_safe(ha, tmp, &from_list->list, list) { 256 if (ha->sync_cnt) 257 __hw_addr_unsync_one(to_list, from_list, ha, addr_len); 258 } 259} 260EXPORT_SYMBOL(__hw_addr_unsync); 261 262void __hw_addr_flush(struct netdev_hw_addr_list *list) 263{ 264 struct netdev_hw_addr *ha, *tmp; 265 266 list_for_each_entry_safe(ha, tmp, &list->list, list) { 267 list_del_rcu(&ha->list); 268 kfree_rcu(ha, rcu_head); 269 } 270 list->count = 0; 271} 272EXPORT_SYMBOL(__hw_addr_flush); 273 274void __hw_addr_init(struct netdev_hw_addr_list *list) 275{ 276 INIT_LIST_HEAD(&list->list); 277 list->count = 0; 278} 279EXPORT_SYMBOL(__hw_addr_init); 280 281/* 282 * Device addresses handling functions 283 */ 284 285/** 286 * dev_addr_flush - Flush device address list 287 * @dev: device 288 * 289 * Flush device address list and reset ->dev_addr. 290 * 291 * The caller must hold the rtnl_mutex. 292 */ 293void dev_addr_flush(struct net_device *dev) 294{ 295 /* rtnl_mutex must be held here */ 296 297 __hw_addr_flush(&dev->dev_addrs); 298 dev->dev_addr = NULL; 299} 300EXPORT_SYMBOL(dev_addr_flush); 301 302/** 303 * dev_addr_init - Init device address list 304 * @dev: device 305 * 306 * Init device address list and create the first element, 307 * used by ->dev_addr. 308 * 309 * The caller must hold the rtnl_mutex. 310 */ 311int dev_addr_init(struct net_device *dev) 312{ 313 unsigned char addr[MAX_ADDR_LEN]; 314 struct netdev_hw_addr *ha; 315 int err; 316 317 /* rtnl_mutex must be held here */ 318 319 __hw_addr_init(&dev->dev_addrs); 320 memset(addr, 0, sizeof(addr)); 321 err = __hw_addr_add(&dev->dev_addrs, addr, sizeof(addr), 322 NETDEV_HW_ADDR_T_LAN); 323 if (!err) { 324 /* 325 * Get the first (previously created) address from the list 326 * and set dev_addr pointer to this location. 327 */ 328 ha = list_first_entry(&dev->dev_addrs.list, 329 struct netdev_hw_addr, list); 330 dev->dev_addr = ha->addr; 331 } 332 return err; 333} 334EXPORT_SYMBOL(dev_addr_init); 335 336/** 337 * dev_addr_add - Add a device address 338 * @dev: device 339 * @addr: address to add 340 * @addr_type: address type 341 * 342 * Add a device address to the device or increase the reference count if 343 * it already exists. 344 * 345 * The caller must hold the rtnl_mutex. 346 */ 347int dev_addr_add(struct net_device *dev, const unsigned char *addr, 348 unsigned char addr_type) 349{ 350 int err; 351 352 ASSERT_RTNL(); 353 354 err = __hw_addr_add(&dev->dev_addrs, addr, dev->addr_len, addr_type); 355 if (!err) 356 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); 357 return err; 358} 359EXPORT_SYMBOL(dev_addr_add); 360 361/** 362 * dev_addr_del - Release a device address. 363 * @dev: device 364 * @addr: address to delete 365 * @addr_type: address type 366 * 367 * Release reference to a device address and remove it from the device 368 * if the reference count drops to zero. 369 * 370 * The caller must hold the rtnl_mutex. 371 */ 372int dev_addr_del(struct net_device *dev, const unsigned char *addr, 373 unsigned char addr_type) 374{ 375 int err; 376 struct netdev_hw_addr *ha; 377 378 ASSERT_RTNL(); 379 380 /* 381 * We can not remove the first address from the list because 382 * dev->dev_addr points to that. 383 */ 384 ha = list_first_entry(&dev->dev_addrs.list, 385 struct netdev_hw_addr, list); 386 if (!memcmp(ha->addr, addr, dev->addr_len) && 387 ha->type == addr_type && ha->refcount == 1) 388 return -ENOENT; 389 390 err = __hw_addr_del(&dev->dev_addrs, addr, dev->addr_len, 391 addr_type); 392 if (!err) 393 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); 394 return err; 395} 396EXPORT_SYMBOL(dev_addr_del); 397 398/** 399 * dev_addr_add_multiple - Add device addresses from another device 400 * @to_dev: device to which addresses will be added 401 * @from_dev: device from which addresses will be added 402 * @addr_type: address type - 0 means type will be used from from_dev 403 * 404 * Add device addresses of the one device to another. 405 ** 406 * The caller must hold the rtnl_mutex. 407 */ 408int dev_addr_add_multiple(struct net_device *to_dev, 409 struct net_device *from_dev, 410 unsigned char addr_type) 411{ 412 int err; 413 414 ASSERT_RTNL(); 415 416 if (from_dev->addr_len != to_dev->addr_len) 417 return -EINVAL; 418 err = __hw_addr_add_multiple(&to_dev->dev_addrs, &from_dev->dev_addrs, 419 to_dev->addr_len, addr_type); 420 if (!err) 421 call_netdevice_notifiers(NETDEV_CHANGEADDR, to_dev); 422 return err; 423} 424EXPORT_SYMBOL(dev_addr_add_multiple); 425 426/** 427 * dev_addr_del_multiple - Delete device addresses by another device 428 * @to_dev: device where the addresses will be deleted 429 * @from_dev: device supplying the addresses to be deleted 430 * @addr_type: address type - 0 means type will be used from from_dev 431 * 432 * Deletes addresses in to device by the list of addresses in from device. 433 * 434 * The caller must hold the rtnl_mutex. 435 */ 436int dev_addr_del_multiple(struct net_device *to_dev, 437 struct net_device *from_dev, 438 unsigned char addr_type) 439{ 440 ASSERT_RTNL(); 441 442 if (from_dev->addr_len != to_dev->addr_len) 443 return -EINVAL; 444 __hw_addr_del_multiple(&to_dev->dev_addrs, &from_dev->dev_addrs, 445 to_dev->addr_len, addr_type); 446 call_netdevice_notifiers(NETDEV_CHANGEADDR, to_dev); 447 return 0; 448} 449EXPORT_SYMBOL(dev_addr_del_multiple); 450 451/* 452 * Unicast list handling functions 453 */ 454 455/** 456 * dev_uc_add_excl - Add a global secondary unicast address 457 * @dev: device 458 * @addr: address to add 459 */ 460int dev_uc_add_excl(struct net_device *dev, const unsigned char *addr) 461{ 462 struct netdev_hw_addr *ha; 463 int err; 464 465 netif_addr_lock_bh(dev); 466 list_for_each_entry(ha, &dev->uc.list, list) { 467 if (!memcmp(ha->addr, addr, dev->addr_len) && 468 ha->type == NETDEV_HW_ADDR_T_UNICAST) { 469 err = -EEXIST; 470 goto out; 471 } 472 } 473 err = __hw_addr_create_ex(&dev->uc, addr, dev->addr_len, 474 NETDEV_HW_ADDR_T_UNICAST, true, false); 475 if (!err) 476 __dev_set_rx_mode(dev); 477out: 478 netif_addr_unlock_bh(dev); 479 return err; 480} 481EXPORT_SYMBOL(dev_uc_add_excl); 482 483/** 484 * dev_uc_add - Add a secondary unicast address 485 * @dev: device 486 * @addr: address to add 487 * 488 * Add a secondary unicast address to the device or increase 489 * the reference count if it already exists. 490 */ 491int dev_uc_add(struct net_device *dev, const unsigned char *addr) 492{ 493 int err; 494 495 netif_addr_lock_bh(dev); 496 err = __hw_addr_add(&dev->uc, addr, dev->addr_len, 497 NETDEV_HW_ADDR_T_UNICAST); 498 if (!err) 499 __dev_set_rx_mode(dev); 500 netif_addr_unlock_bh(dev); 501 return err; 502} 503EXPORT_SYMBOL(dev_uc_add); 504 505/** 506 * dev_uc_del - Release secondary unicast address. 507 * @dev: device 508 * @addr: address to delete 509 * 510 * Release reference to a secondary unicast address and remove it 511 * from the device if the reference count drops to zero. 512 */ 513int dev_uc_del(struct net_device *dev, const unsigned char *addr) 514{ 515 int err; 516 517 netif_addr_lock_bh(dev); 518 err = __hw_addr_del(&dev->uc, addr, dev->addr_len, 519 NETDEV_HW_ADDR_T_UNICAST); 520 if (!err) 521 __dev_set_rx_mode(dev); 522 netif_addr_unlock_bh(dev); 523 return err; 524} 525EXPORT_SYMBOL(dev_uc_del); 526 527/** 528 * dev_uc_sync - Synchronize device's unicast list to another device 529 * @to: destination device 530 * @from: source device 531 * 532 * Add newly added addresses to the destination device and release 533 * addresses that have no users left. The source device must be 534 * locked by netif_addr_lock_bh. 535 * 536 * This function is intended to be called from the dev->set_rx_mode 537 * function of layered software devices. This function assumes that 538 * addresses will only ever be synced to the @to devices and no other. 539 */ 540int dev_uc_sync(struct net_device *to, struct net_device *from) 541{ 542 int err = 0; 543 544 if (to->addr_len != from->addr_len) 545 return -EINVAL; 546 547 netif_addr_lock_nested(to); 548 err = __hw_addr_sync(&to->uc, &from->uc, to->addr_len); 549 if (!err) 550 __dev_set_rx_mode(to); 551 netif_addr_unlock(to); 552 return err; 553} 554EXPORT_SYMBOL(dev_uc_sync); 555 556/** 557 * dev_uc_sync_multiple - Synchronize device's unicast list to another 558 * device, but allow for multiple calls to sync to multiple devices. 559 * @to: destination device 560 * @from: source device 561 * 562 * Add newly added addresses to the destination device and release 563 * addresses that have been deleted from the source. The source device 564 * must be locked by netif_addr_lock_bh. 565 * 566 * This function is intended to be called from the dev->set_rx_mode 567 * function of layered software devices. It allows for a single source 568 * device to be synced to multiple destination devices. 569 */ 570int dev_uc_sync_multiple(struct net_device *to, struct net_device *from) 571{ 572 int err = 0; 573 574 if (to->addr_len != from->addr_len) 575 return -EINVAL; 576 577 netif_addr_lock_nested(to); 578 err = __hw_addr_sync_multiple(&to->uc, &from->uc, to->addr_len); 579 if (!err) 580 __dev_set_rx_mode(to); 581 netif_addr_unlock(to); 582 return err; 583} 584EXPORT_SYMBOL(dev_uc_sync_multiple); 585 586/** 587 * dev_uc_unsync - Remove synchronized addresses from the destination device 588 * @to: destination device 589 * @from: source device 590 * 591 * Remove all addresses that were added to the destination device by 592 * dev_uc_sync(). This function is intended to be called from the 593 * dev->stop function of layered software devices. 594 */ 595void dev_uc_unsync(struct net_device *to, struct net_device *from) 596{ 597 if (to->addr_len != from->addr_len) 598 return; 599 600 netif_addr_lock_bh(from); 601 netif_addr_lock_nested(to); 602 __hw_addr_unsync(&to->uc, &from->uc, to->addr_len); 603 __dev_set_rx_mode(to); 604 netif_addr_unlock(to); 605 netif_addr_unlock_bh(from); 606} 607EXPORT_SYMBOL(dev_uc_unsync); 608 609/** 610 * dev_uc_flush - Flush unicast addresses 611 * @dev: device 612 * 613 * Flush unicast addresses. 614 */ 615void dev_uc_flush(struct net_device *dev) 616{ 617 netif_addr_lock_bh(dev); 618 __hw_addr_flush(&dev->uc); 619 netif_addr_unlock_bh(dev); 620} 621EXPORT_SYMBOL(dev_uc_flush); 622 623/** 624 * dev_uc_flush - Init unicast address list 625 * @dev: device 626 * 627 * Init unicast address list. 628 */ 629void dev_uc_init(struct net_device *dev) 630{ 631 __hw_addr_init(&dev->uc); 632} 633EXPORT_SYMBOL(dev_uc_init); 634 635/* 636 * Multicast list handling functions 637 */ 638 639/** 640 * dev_mc_add_excl - Add a global secondary multicast address 641 * @dev: device 642 * @addr: address to add 643 */ 644int dev_mc_add_excl(struct net_device *dev, const unsigned char *addr) 645{ 646 struct netdev_hw_addr *ha; 647 int err; 648 649 netif_addr_lock_bh(dev); 650 list_for_each_entry(ha, &dev->mc.list, list) { 651 if (!memcmp(ha->addr, addr, dev->addr_len) && 652 ha->type == NETDEV_HW_ADDR_T_MULTICAST) { 653 err = -EEXIST; 654 goto out; 655 } 656 } 657 err = __hw_addr_create_ex(&dev->mc, addr, dev->addr_len, 658 NETDEV_HW_ADDR_T_MULTICAST, true, false); 659 if (!err) 660 __dev_set_rx_mode(dev); 661out: 662 netif_addr_unlock_bh(dev); 663 return err; 664} 665EXPORT_SYMBOL(dev_mc_add_excl); 666 667static int __dev_mc_add(struct net_device *dev, const unsigned char *addr, 668 bool global) 669{ 670 int err; 671 672 netif_addr_lock_bh(dev); 673 err = __hw_addr_add_ex(&dev->mc, addr, dev->addr_len, 674 NETDEV_HW_ADDR_T_MULTICAST, global, false); 675 if (!err) 676 __dev_set_rx_mode(dev); 677 netif_addr_unlock_bh(dev); 678 return err; 679} 680/** 681 * dev_mc_add - Add a multicast address 682 * @dev: device 683 * @addr: address to add 684 * 685 * Add a multicast address to the device or increase 686 * the reference count if it already exists. 687 */ 688int dev_mc_add(struct net_device *dev, const unsigned char *addr) 689{ 690 return __dev_mc_add(dev, addr, false); 691} 692EXPORT_SYMBOL(dev_mc_add); 693 694/** 695 * dev_mc_add_global - Add a global multicast address 696 * @dev: device 697 * @addr: address to add 698 * 699 * Add a global multicast address to the device. 700 */ 701int dev_mc_add_global(struct net_device *dev, const unsigned char *addr) 702{ 703 return __dev_mc_add(dev, addr, true); 704} 705EXPORT_SYMBOL(dev_mc_add_global); 706 707static int __dev_mc_del(struct net_device *dev, const unsigned char *addr, 708 bool global) 709{ 710 int err; 711 712 netif_addr_lock_bh(dev); 713 err = __hw_addr_del_ex(&dev->mc, addr, dev->addr_len, 714 NETDEV_HW_ADDR_T_MULTICAST, global, false); 715 if (!err) 716 __dev_set_rx_mode(dev); 717 netif_addr_unlock_bh(dev); 718 return err; 719} 720 721/** 722 * dev_mc_del - Delete a multicast address. 723 * @dev: device 724 * @addr: address to delete 725 * 726 * Release reference to a multicast address and remove it 727 * from the device if the reference count drops to zero. 728 */ 729int dev_mc_del(struct net_device *dev, const unsigned char *addr) 730{ 731 return __dev_mc_del(dev, addr, false); 732} 733EXPORT_SYMBOL(dev_mc_del); 734 735/** 736 * dev_mc_del_global - Delete a global multicast address. 737 * @dev: device 738 * @addr: address to delete 739 * 740 * Release reference to a multicast address and remove it 741 * from the device if the reference count drops to zero. 742 */ 743int dev_mc_del_global(struct net_device *dev, const unsigned char *addr) 744{ 745 return __dev_mc_del(dev, addr, true); 746} 747EXPORT_SYMBOL(dev_mc_del_global); 748 749/** 750 * dev_mc_sync - Synchronize device's unicast list to another device 751 * @to: destination device 752 * @from: source device 753 * 754 * Add newly added addresses to the destination device and release 755 * addresses that have no users left. The source device must be 756 * locked by netif_addr_lock_bh. 757 * 758 * This function is intended to be called from the ndo_set_rx_mode 759 * function of layered software devices. 760 */ 761int dev_mc_sync(struct net_device *to, struct net_device *from) 762{ 763 int err = 0; 764 765 if (to->addr_len != from->addr_len) 766 return -EINVAL; 767 768 netif_addr_lock_nested(to); 769 err = __hw_addr_sync(&to->mc, &from->mc, to->addr_len); 770 if (!err) 771 __dev_set_rx_mode(to); 772 netif_addr_unlock(to); 773 return err; 774} 775EXPORT_SYMBOL(dev_mc_sync); 776 777/** 778 * dev_mc_sync_multiple - Synchronize device's unicast list to another 779 * device, but allow for multiple calls to sync to multiple devices. 780 * @to: destination device 781 * @from: source device 782 * 783 * Add newly added addresses to the destination device and release 784 * addresses that have no users left. The source device must be 785 * locked by netif_addr_lock_bh. 786 * 787 * This function is intended to be called from the ndo_set_rx_mode 788 * function of layered software devices. It allows for a single 789 * source device to be synced to multiple destination devices. 790 */ 791int dev_mc_sync_multiple(struct net_device *to, struct net_device *from) 792{ 793 int err = 0; 794 795 if (to->addr_len != from->addr_len) 796 return -EINVAL; 797 798 netif_addr_lock_nested(to); 799 err = __hw_addr_sync(&to->mc, &from->mc, to->addr_len); 800 if (!err) 801 __dev_set_rx_mode(to); 802 netif_addr_unlock(to); 803 return err; 804} 805EXPORT_SYMBOL(dev_mc_sync_multiple); 806 807/** 808 * dev_mc_unsync - Remove synchronized addresses from the destination device 809 * @to: destination device 810 * @from: source device 811 * 812 * Remove all addresses that were added to the destination device by 813 * dev_mc_sync(). This function is intended to be called from the 814 * dev->stop function of layered software devices. 815 */ 816void dev_mc_unsync(struct net_device *to, struct net_device *from) 817{ 818 if (to->addr_len != from->addr_len) 819 return; 820 821 netif_addr_lock_bh(from); 822 netif_addr_lock_nested(to); 823 __hw_addr_unsync(&to->mc, &from->mc, to->addr_len); 824 __dev_set_rx_mode(to); 825 netif_addr_unlock(to); 826 netif_addr_unlock_bh(from); 827} 828EXPORT_SYMBOL(dev_mc_unsync); 829 830/** 831 * dev_mc_flush - Flush multicast addresses 832 * @dev: device 833 * 834 * Flush multicast addresses. 835 */ 836void dev_mc_flush(struct net_device *dev) 837{ 838 netif_addr_lock_bh(dev); 839 __hw_addr_flush(&dev->mc); 840 netif_addr_unlock_bh(dev); 841} 842EXPORT_SYMBOL(dev_mc_flush); 843 844/** 845 * dev_mc_flush - Init multicast address list 846 * @dev: device 847 * 848 * Init multicast address list. 849 */ 850void dev_mc_init(struct net_device *dev) 851{ 852 __hw_addr_init(&dev->mc); 853} 854EXPORT_SYMBOL(dev_mc_init);