1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * net/core/dev_addr_lists.c - Functions for handling net device lists
4 * Copyright (c) 2010 Jiri Pirko <jpirko@redhat.com>
6 * This file contains functions for working with unicast, multicast and device
10 #include <linux/netdevice.h>
11 #include <linux/rtnetlink.h>
12 #include <linux/export.h>
13 #include <linux/list.h>
16 * General list handling functions
19 static struct netdev_hw_addr*
20 __hw_addr_create(const unsigned char *addr, int addr_len,
21 unsigned char addr_type, bool global, bool sync)
23 struct netdev_hw_addr *ha;
26 alloc_size = sizeof(*ha);
27 if (alloc_size < L1_CACHE_BYTES)
28 alloc_size = L1_CACHE_BYTES;
29 ha = kmalloc(alloc_size, GFP_ATOMIC);
32 memcpy(ha->addr, addr, addr_len);
35 ha->global_use = global;
36 ha->synced = sync ? 1 : 0;
42 static int __hw_addr_add_ex(struct netdev_hw_addr_list *list,
43 const unsigned char *addr, int addr_len,
44 unsigned char addr_type, bool global, bool sync,
45 int sync_count, bool exclusive)
47 struct rb_node **ins_point = &list->tree.rb_node, *parent = NULL;
48 struct netdev_hw_addr *ha;
50 if (addr_len > MAX_ADDR_LEN)
53 ha = list_first_entry(&list->list, struct netdev_hw_addr, list);
54 if (ha && !memcmp(addr, ha->addr, addr_len) &&
55 (!addr_type || addr_type == ha->type))
61 ha = rb_entry(*ins_point, struct netdev_hw_addr, node);
62 diff = memcmp(addr, ha->addr, addr_len);
64 diff = memcmp(&addr_type, &ha->type, sizeof(addr_type));
68 ins_point = &parent->rb_left;
69 } else if (diff > 0) {
70 ins_point = &parent->rb_right;
76 /* check if addr is already used as global */
80 ha->global_use = true;
83 if (ha->synced && sync_count)
93 ha = __hw_addr_create(addr, addr_len, addr_type, global, sync);
97 /* The first address in dev->dev_addrs is pointed to by dev->dev_addr
98 * and mutated freely by device drivers and netdev ops, so if we insert
99 * it into the tree we'll end up with an invalid rbtree.
101 if (list->count > 0) {
102 rb_link_node(&ha->node, parent, ins_point);
103 rb_insert_color(&ha->node, &list->tree);
105 RB_CLEAR_NODE(&ha->node);
108 list_add_tail_rcu(&ha->list, &list->list);
114 static int __hw_addr_add(struct netdev_hw_addr_list *list,
115 const unsigned char *addr, int addr_len,
116 unsigned char addr_type)
118 return __hw_addr_add_ex(list, addr, addr_len, addr_type, false, false,
122 static int __hw_addr_del_entry(struct netdev_hw_addr_list *list,
123 struct netdev_hw_addr *ha, bool global,
126 if (global && !ha->global_use)
129 if (sync && !ha->synced)
133 ha->global_use = false;
141 if (!RB_EMPTY_NODE(&ha->node))
142 rb_erase(&ha->node, &list->tree);
144 list_del_rcu(&ha->list);
145 kfree_rcu(ha, rcu_head);
150 static struct netdev_hw_addr *__hw_addr_lookup(struct netdev_hw_addr_list *list,
151 const unsigned char *addr, int addr_len,
152 unsigned char addr_type)
154 struct netdev_hw_addr *ha;
155 struct rb_node *node;
157 /* The first address isn't inserted into the tree because in the dev->dev_addrs
158 * list it's the address pointed to by dev->dev_addr which is freely mutated
159 * in place, so we need to check it separately.
161 ha = list_first_entry(&list->list, struct netdev_hw_addr, list);
162 if (ha && !memcmp(addr, ha->addr, addr_len) &&
163 (!addr_type || addr_type == ha->type))
166 node = list->tree.rb_node;
169 struct netdev_hw_addr *ha = rb_entry(node, struct netdev_hw_addr, node);
170 int diff = memcmp(addr, ha->addr, addr_len);
172 if (diff == 0 && addr_type)
173 diff = memcmp(&addr_type, &ha->type, sizeof(addr_type));
176 node = node->rb_left;
178 node = node->rb_right;
186 static int __hw_addr_del_ex(struct netdev_hw_addr_list *list,
187 const unsigned char *addr, int addr_len,
188 unsigned char addr_type, bool global, bool sync)
190 struct netdev_hw_addr *ha = __hw_addr_lookup(list, addr, addr_len, addr_type);
194 return __hw_addr_del_entry(list, ha, global, sync);
197 static int __hw_addr_del(struct netdev_hw_addr_list *list,
198 const unsigned char *addr, int addr_len,
199 unsigned char addr_type)
201 return __hw_addr_del_ex(list, addr, addr_len, addr_type, false, false);
204 static int __hw_addr_sync_one(struct netdev_hw_addr_list *to_list,
205 struct netdev_hw_addr *ha,
210 err = __hw_addr_add_ex(to_list, ha->addr, addr_len, ha->type,
211 false, true, ha->sync_cnt, false);
212 if (err && err != -EEXIST)
223 static void __hw_addr_unsync_one(struct netdev_hw_addr_list *to_list,
224 struct netdev_hw_addr_list *from_list,
225 struct netdev_hw_addr *ha,
230 err = __hw_addr_del_ex(to_list, ha->addr, addr_len, ha->type,
235 /* address on from list is not marked synced */
236 __hw_addr_del_entry(from_list, ha, false, false);
239 static int __hw_addr_sync_multiple(struct netdev_hw_addr_list *to_list,
240 struct netdev_hw_addr_list *from_list,
244 struct netdev_hw_addr *ha, *tmp;
246 list_for_each_entry_safe(ha, tmp, &from_list->list, list) {
247 if (ha->sync_cnt == ha->refcount) {
248 __hw_addr_unsync_one(to_list, from_list, ha, addr_len);
250 err = __hw_addr_sync_one(to_list, ha, addr_len);
258 /* This function only works where there is a strict 1-1 relationship
259 * between source and destionation of they synch. If you ever need to
260 * sync addresses to more then 1 destination, you need to use
261 * __hw_addr_sync_multiple().
263 int __hw_addr_sync(struct netdev_hw_addr_list *to_list,
264 struct netdev_hw_addr_list *from_list,
268 struct netdev_hw_addr *ha, *tmp;
270 list_for_each_entry_safe(ha, tmp, &from_list->list, list) {
272 err = __hw_addr_sync_one(to_list, ha, addr_len);
275 } else if (ha->refcount == 1)
276 __hw_addr_unsync_one(to_list, from_list, ha, addr_len);
280 EXPORT_SYMBOL(__hw_addr_sync);
282 void __hw_addr_unsync(struct netdev_hw_addr_list *to_list,
283 struct netdev_hw_addr_list *from_list,
286 struct netdev_hw_addr *ha, *tmp;
288 list_for_each_entry_safe(ha, tmp, &from_list->list, list) {
290 __hw_addr_unsync_one(to_list, from_list, ha, addr_len);
293 EXPORT_SYMBOL(__hw_addr_unsync);
296 * __hw_addr_sync_dev - Synchonize device's multicast list
297 * @list: address list to syncronize
298 * @dev: device to sync
299 * @sync: function to call if address should be added
300 * @unsync: function to call if address should be removed
302 * This function is intended to be called from the ndo_set_rx_mode
303 * function of devices that require explicit address add/remove
304 * notifications. The unsync function may be NULL in which case
305 * the addresses requiring removal will simply be removed without
306 * any notification to the device.
308 int __hw_addr_sync_dev(struct netdev_hw_addr_list *list,
309 struct net_device *dev,
310 int (*sync)(struct net_device *, const unsigned char *),
311 int (*unsync)(struct net_device *,
312 const unsigned char *))
314 struct netdev_hw_addr *ha, *tmp;
317 /* first go through and flush out any stale entries */
318 list_for_each_entry_safe(ha, tmp, &list->list, list) {
319 if (!ha->sync_cnt || ha->refcount != 1)
322 /* if unsync is defined and fails defer unsyncing address */
323 if (unsync && unsync(dev, ha->addr))
327 __hw_addr_del_entry(list, ha, false, false);
330 /* go through and sync new entries to the list */
331 list_for_each_entry_safe(ha, tmp, &list->list, list) {
335 err = sync(dev, ha->addr);
345 EXPORT_SYMBOL(__hw_addr_sync_dev);
348 * __hw_addr_ref_sync_dev - Synchronize device's multicast address list taking
349 * into account references
350 * @list: address list to synchronize
351 * @dev: device to sync
352 * @sync: function to call if address or reference on it should be added
353 * @unsync: function to call if address or some reference on it should removed
355 * This function is intended to be called from the ndo_set_rx_mode
356 * function of devices that require explicit address or references on it
357 * add/remove notifications. The unsync function may be NULL in which case
358 * the addresses or references on it requiring removal will simply be
359 * removed without any notification to the device. That is responsibility of
360 * the driver to identify and distribute address or references on it between
361 * internal address tables.
363 int __hw_addr_ref_sync_dev(struct netdev_hw_addr_list *list,
364 struct net_device *dev,
365 int (*sync)(struct net_device *,
366 const unsigned char *, int),
367 int (*unsync)(struct net_device *,
368 const unsigned char *, int))
370 struct netdev_hw_addr *ha, *tmp;
373 /* first go through and flush out any unsynced/stale entries */
374 list_for_each_entry_safe(ha, tmp, &list->list, list) {
375 /* sync if address is not used */
376 if ((ha->sync_cnt << 1) <= ha->refcount)
379 /* if fails defer unsyncing address */
380 ref_cnt = ha->refcount - ha->sync_cnt;
381 if (unsync && unsync(dev, ha->addr, ref_cnt))
384 ha->refcount = (ref_cnt << 1) + 1;
385 ha->sync_cnt = ref_cnt;
386 __hw_addr_del_entry(list, ha, false, false);
389 /* go through and sync updated/new entries to the list */
390 list_for_each_entry_safe(ha, tmp, &list->list, list) {
391 /* sync if address added or reused */
392 if ((ha->sync_cnt << 1) >= ha->refcount)
395 ref_cnt = ha->refcount - ha->sync_cnt;
396 err = sync(dev, ha->addr, ref_cnt);
400 ha->refcount = ref_cnt << 1;
401 ha->sync_cnt = ref_cnt;
406 EXPORT_SYMBOL(__hw_addr_ref_sync_dev);
409 * __hw_addr_ref_unsync_dev - Remove synchronized addresses and references on
411 * @list: address list to remove synchronized addresses (references on it) from
412 * @dev: device to sync
413 * @unsync: function to call if address and references on it should be removed
415 * Remove all addresses that were added to the device by
416 * __hw_addr_ref_sync_dev(). This function is intended to be called from the
417 * ndo_stop or ndo_open functions on devices that require explicit address (or
418 * references on it) add/remove notifications. If the unsync function pointer
419 * is NULL then this function can be used to just reset the sync_cnt for the
420 * addresses in the list.
422 void __hw_addr_ref_unsync_dev(struct netdev_hw_addr_list *list,
423 struct net_device *dev,
424 int (*unsync)(struct net_device *,
425 const unsigned char *, int))
427 struct netdev_hw_addr *ha, *tmp;
429 list_for_each_entry_safe(ha, tmp, &list->list, list) {
433 /* if fails defer unsyncing address */
434 if (unsync && unsync(dev, ha->addr, ha->sync_cnt))
437 ha->refcount -= ha->sync_cnt - 1;
439 __hw_addr_del_entry(list, ha, false, false);
442 EXPORT_SYMBOL(__hw_addr_ref_unsync_dev);
445 * __hw_addr_unsync_dev - Remove synchronized addresses from device
446 * @list: address list to remove synchronized addresses from
447 * @dev: device to sync
448 * @unsync: function to call if address should be removed
450 * Remove all addresses that were added to the device by __hw_addr_sync_dev().
451 * This function is intended to be called from the ndo_stop or ndo_open
452 * functions on devices that require explicit address add/remove
453 * notifications. If the unsync function pointer is NULL then this function
454 * can be used to just reset the sync_cnt for the addresses in the list.
456 void __hw_addr_unsync_dev(struct netdev_hw_addr_list *list,
457 struct net_device *dev,
458 int (*unsync)(struct net_device *,
459 const unsigned char *))
461 struct netdev_hw_addr *ha, *tmp;
463 list_for_each_entry_safe(ha, tmp, &list->list, list) {
467 /* if unsync is defined and fails defer unsyncing address */
468 if (unsync && unsync(dev, ha->addr))
472 __hw_addr_del_entry(list, ha, false, false);
475 EXPORT_SYMBOL(__hw_addr_unsync_dev);
477 static void __hw_addr_flush(struct netdev_hw_addr_list *list)
479 struct netdev_hw_addr *ha, *tmp;
481 list->tree = RB_ROOT;
482 list_for_each_entry_safe(ha, tmp, &list->list, list) {
483 list_del_rcu(&ha->list);
484 kfree_rcu(ha, rcu_head);
489 void __hw_addr_init(struct netdev_hw_addr_list *list)
491 INIT_LIST_HEAD(&list->list);
493 list->tree = RB_ROOT;
495 EXPORT_SYMBOL(__hw_addr_init);
498 * Device addresses handling functions
502 * dev_addr_flush - Flush device address list
505 * Flush device address list and reset ->dev_addr.
507 * The caller must hold the rtnl_mutex.
509 void dev_addr_flush(struct net_device *dev)
511 /* rtnl_mutex must be held here */
513 __hw_addr_flush(&dev->dev_addrs);
514 dev->dev_addr = NULL;
516 EXPORT_SYMBOL(dev_addr_flush);
519 * dev_addr_init - Init device address list
522 * Init device address list and create the first element,
523 * used by ->dev_addr.
525 * The caller must hold the rtnl_mutex.
527 int dev_addr_init(struct net_device *dev)
529 unsigned char addr[MAX_ADDR_LEN];
530 struct netdev_hw_addr *ha;
533 /* rtnl_mutex must be held here */
535 __hw_addr_init(&dev->dev_addrs);
536 memset(addr, 0, sizeof(addr));
537 err = __hw_addr_add(&dev->dev_addrs, addr, sizeof(addr),
538 NETDEV_HW_ADDR_T_LAN);
541 * Get the first (previously created) address from the list
542 * and set dev_addr pointer to this location.
544 ha = list_first_entry(&dev->dev_addrs.list,
545 struct netdev_hw_addr, list);
546 dev->dev_addr = ha->addr;
550 EXPORT_SYMBOL(dev_addr_init);
553 * dev_addr_add - Add a device address
555 * @addr: address to add
556 * @addr_type: address type
558 * Add a device address to the device or increase the reference count if
561 * The caller must hold the rtnl_mutex.
563 int dev_addr_add(struct net_device *dev, const unsigned char *addr,
564 unsigned char addr_type)
570 err = dev_pre_changeaddr_notify(dev, addr, NULL);
573 err = __hw_addr_add(&dev->dev_addrs, addr, dev->addr_len, addr_type);
575 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
578 EXPORT_SYMBOL(dev_addr_add);
581 * dev_addr_del - Release a device address.
583 * @addr: address to delete
584 * @addr_type: address type
586 * Release reference to a device address and remove it from the device
587 * if the reference count drops to zero.
589 * The caller must hold the rtnl_mutex.
591 int dev_addr_del(struct net_device *dev, const unsigned char *addr,
592 unsigned char addr_type)
595 struct netdev_hw_addr *ha;
600 * We can not remove the first address from the list because
601 * dev->dev_addr points to that.
603 ha = list_first_entry(&dev->dev_addrs.list,
604 struct netdev_hw_addr, list);
605 if (!memcmp(ha->addr, addr, dev->addr_len) &&
606 ha->type == addr_type && ha->refcount == 1)
609 err = __hw_addr_del(&dev->dev_addrs, addr, dev->addr_len,
612 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
615 EXPORT_SYMBOL(dev_addr_del);
618 * Unicast list handling functions
622 * dev_uc_add_excl - Add a global secondary unicast address
624 * @addr: address to add
626 int dev_uc_add_excl(struct net_device *dev, const unsigned char *addr)
630 netif_addr_lock_bh(dev);
631 err = __hw_addr_add_ex(&dev->uc, addr, dev->addr_len,
632 NETDEV_HW_ADDR_T_UNICAST, true, false,
635 __dev_set_rx_mode(dev);
636 netif_addr_unlock_bh(dev);
639 EXPORT_SYMBOL(dev_uc_add_excl);
642 * dev_uc_add - Add a secondary unicast address
644 * @addr: address to add
646 * Add a secondary unicast address to the device or increase
647 * the reference count if it already exists.
649 int dev_uc_add(struct net_device *dev, const unsigned char *addr)
653 netif_addr_lock_bh(dev);
654 err = __hw_addr_add(&dev->uc, addr, dev->addr_len,
655 NETDEV_HW_ADDR_T_UNICAST);
657 __dev_set_rx_mode(dev);
658 netif_addr_unlock_bh(dev);
661 EXPORT_SYMBOL(dev_uc_add);
664 * dev_uc_del - Release secondary unicast address.
666 * @addr: address to delete
668 * Release reference to a secondary unicast address and remove it
669 * from the device if the reference count drops to zero.
671 int dev_uc_del(struct net_device *dev, const unsigned char *addr)
675 netif_addr_lock_bh(dev);
676 err = __hw_addr_del(&dev->uc, addr, dev->addr_len,
677 NETDEV_HW_ADDR_T_UNICAST);
679 __dev_set_rx_mode(dev);
680 netif_addr_unlock_bh(dev);
683 EXPORT_SYMBOL(dev_uc_del);
686 * dev_uc_sync - Synchronize device's unicast list to another device
687 * @to: destination device
688 * @from: source device
690 * Add newly added addresses to the destination device and release
691 * addresses that have no users left. The source device must be
692 * locked by netif_addr_lock_bh.
694 * This function is intended to be called from the dev->set_rx_mode
695 * function of layered software devices. This function assumes that
696 * addresses will only ever be synced to the @to devices and no other.
698 int dev_uc_sync(struct net_device *to, struct net_device *from)
702 if (to->addr_len != from->addr_len)
706 err = __hw_addr_sync(&to->uc, &from->uc, to->addr_len);
708 __dev_set_rx_mode(to);
709 netif_addr_unlock(to);
712 EXPORT_SYMBOL(dev_uc_sync);
715 * dev_uc_sync_multiple - Synchronize device's unicast list to another
716 * device, but allow for multiple calls to sync to multiple devices.
717 * @to: destination device
718 * @from: source device
720 * Add newly added addresses to the destination device and release
721 * addresses that have been deleted from the source. The source device
722 * must be locked by netif_addr_lock_bh.
724 * This function is intended to be called from the dev->set_rx_mode
725 * function of layered software devices. It allows for a single source
726 * device to be synced to multiple destination devices.
728 int dev_uc_sync_multiple(struct net_device *to, struct net_device *from)
732 if (to->addr_len != from->addr_len)
736 err = __hw_addr_sync_multiple(&to->uc, &from->uc, to->addr_len);
738 __dev_set_rx_mode(to);
739 netif_addr_unlock(to);
742 EXPORT_SYMBOL(dev_uc_sync_multiple);
745 * dev_uc_unsync - Remove synchronized addresses from the destination device
746 * @to: destination device
747 * @from: source device
749 * Remove all addresses that were added to the destination device by
750 * dev_uc_sync(). This function is intended to be called from the
751 * dev->stop function of layered software devices.
753 void dev_uc_unsync(struct net_device *to, struct net_device *from)
755 if (to->addr_len != from->addr_len)
758 /* netif_addr_lock_bh() uses lockdep subclass 0, this is okay for two
760 * 1) This is always called without any addr_list_lock, so as the
761 * outermost one here, it must be 0.
762 * 2) This is called by some callers after unlinking the upper device,
763 * so the dev->lower_level becomes 1 again.
764 * Therefore, the subclass for 'from' is 0, for 'to' is either 1 or
767 netif_addr_lock_bh(from);
769 __hw_addr_unsync(&to->uc, &from->uc, to->addr_len);
770 __dev_set_rx_mode(to);
771 netif_addr_unlock(to);
772 netif_addr_unlock_bh(from);
774 EXPORT_SYMBOL(dev_uc_unsync);
777 * dev_uc_flush - Flush unicast addresses
780 * Flush unicast addresses.
782 void dev_uc_flush(struct net_device *dev)
784 netif_addr_lock_bh(dev);
785 __hw_addr_flush(&dev->uc);
786 netif_addr_unlock_bh(dev);
788 EXPORT_SYMBOL(dev_uc_flush);
791 * dev_uc_init - Init unicast address list
794 * Init unicast address list.
796 void dev_uc_init(struct net_device *dev)
798 __hw_addr_init(&dev->uc);
800 EXPORT_SYMBOL(dev_uc_init);
803 * Multicast list handling functions
807 * dev_mc_add_excl - Add a global secondary multicast address
809 * @addr: address to add
811 int dev_mc_add_excl(struct net_device *dev, const unsigned char *addr)
815 netif_addr_lock_bh(dev);
816 err = __hw_addr_add_ex(&dev->mc, addr, dev->addr_len,
817 NETDEV_HW_ADDR_T_MULTICAST, true, false,
820 __dev_set_rx_mode(dev);
821 netif_addr_unlock_bh(dev);
824 EXPORT_SYMBOL(dev_mc_add_excl);
826 static int __dev_mc_add(struct net_device *dev, const unsigned char *addr,
831 netif_addr_lock_bh(dev);
832 err = __hw_addr_add_ex(&dev->mc, addr, dev->addr_len,
833 NETDEV_HW_ADDR_T_MULTICAST, global, false,
836 __dev_set_rx_mode(dev);
837 netif_addr_unlock_bh(dev);
841 * dev_mc_add - Add a multicast address
843 * @addr: address to add
845 * Add a multicast address to the device or increase
846 * the reference count if it already exists.
848 int dev_mc_add(struct net_device *dev, const unsigned char *addr)
850 return __dev_mc_add(dev, addr, false);
852 EXPORT_SYMBOL(dev_mc_add);
855 * dev_mc_add_global - Add a global multicast address
857 * @addr: address to add
859 * Add a global multicast address to the device.
861 int dev_mc_add_global(struct net_device *dev, const unsigned char *addr)
863 return __dev_mc_add(dev, addr, true);
865 EXPORT_SYMBOL(dev_mc_add_global);
867 static int __dev_mc_del(struct net_device *dev, const unsigned char *addr,
872 netif_addr_lock_bh(dev);
873 err = __hw_addr_del_ex(&dev->mc, addr, dev->addr_len,
874 NETDEV_HW_ADDR_T_MULTICAST, global, false);
876 __dev_set_rx_mode(dev);
877 netif_addr_unlock_bh(dev);
882 * dev_mc_del - Delete a multicast address.
884 * @addr: address to delete
886 * Release reference to a multicast address and remove it
887 * from the device if the reference count drops to zero.
889 int dev_mc_del(struct net_device *dev, const unsigned char *addr)
891 return __dev_mc_del(dev, addr, false);
893 EXPORT_SYMBOL(dev_mc_del);
896 * dev_mc_del_global - Delete a global multicast address.
898 * @addr: address to delete
900 * Release reference to a multicast address and remove it
901 * from the device if the reference count drops to zero.
903 int dev_mc_del_global(struct net_device *dev, const unsigned char *addr)
905 return __dev_mc_del(dev, addr, true);
907 EXPORT_SYMBOL(dev_mc_del_global);
910 * dev_mc_sync - Synchronize device's multicast list to another device
911 * @to: destination device
912 * @from: source device
914 * Add newly added addresses to the destination device and release
915 * addresses that have no users left. The source device must be
916 * locked by netif_addr_lock_bh.
918 * This function is intended to be called from the ndo_set_rx_mode
919 * function of layered software devices.
921 int dev_mc_sync(struct net_device *to, struct net_device *from)
925 if (to->addr_len != from->addr_len)
929 err = __hw_addr_sync(&to->mc, &from->mc, to->addr_len);
931 __dev_set_rx_mode(to);
932 netif_addr_unlock(to);
935 EXPORT_SYMBOL(dev_mc_sync);
938 * dev_mc_sync_multiple - Synchronize device's multicast list to another
939 * device, but allow for multiple calls to sync to multiple devices.
940 * @to: destination device
941 * @from: source device
943 * Add newly added addresses to the destination device and release
944 * addresses that have no users left. The source device must be
945 * locked by netif_addr_lock_bh.
947 * This function is intended to be called from the ndo_set_rx_mode
948 * function of layered software devices. It allows for a single
949 * source device to be synced to multiple destination devices.
951 int dev_mc_sync_multiple(struct net_device *to, struct net_device *from)
955 if (to->addr_len != from->addr_len)
959 err = __hw_addr_sync_multiple(&to->mc, &from->mc, to->addr_len);
961 __dev_set_rx_mode(to);
962 netif_addr_unlock(to);
965 EXPORT_SYMBOL(dev_mc_sync_multiple);
968 * dev_mc_unsync - Remove synchronized addresses from the destination device
969 * @to: destination device
970 * @from: source device
972 * Remove all addresses that were added to the destination device by
973 * dev_mc_sync(). This function is intended to be called from the
974 * dev->stop function of layered software devices.
976 void dev_mc_unsync(struct net_device *to, struct net_device *from)
978 if (to->addr_len != from->addr_len)
981 /* See the above comments inside dev_uc_unsync(). */
982 netif_addr_lock_bh(from);
984 __hw_addr_unsync(&to->mc, &from->mc, to->addr_len);
985 __dev_set_rx_mode(to);
986 netif_addr_unlock(to);
987 netif_addr_unlock_bh(from);
989 EXPORT_SYMBOL(dev_mc_unsync);
992 * dev_mc_flush - Flush multicast addresses
995 * Flush multicast addresses.
997 void dev_mc_flush(struct net_device *dev)
999 netif_addr_lock_bh(dev);
1000 __hw_addr_flush(&dev->mc);
1001 netif_addr_unlock_bh(dev);
1003 EXPORT_SYMBOL(dev_mc_flush);
1006 * dev_mc_init - Init multicast address list
1009 * Init multicast address list.
1011 void dev_mc_init(struct net_device *dev)
1013 __hw_addr_init(&dev->mc);
1015 EXPORT_SYMBOL(dev_mc_init);