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)
56 ha = rb_entry(*ins_point, struct netdev_hw_addr, node);
57 diff = memcmp(addr, ha->addr, addr_len);
59 diff = memcmp(&addr_type, &ha->type, sizeof(addr_type));
63 ins_point = &parent->rb_left;
64 } else if (diff > 0) {
65 ins_point = &parent->rb_right;
70 /* check if addr is already used as global */
74 ha->global_use = true;
77 if (ha->synced && sync_count)
87 ha = __hw_addr_create(addr, addr_len, addr_type, global, sync);
91 /* The first address in dev->dev_addrs is pointed to by dev->dev_addr
92 * and mutated freely by device drivers and netdev ops, so if we insert
93 * it into the tree we'll end up with an invalid rbtree.
95 if (list->count > 0) {
96 rb_link_node(&ha->node, parent, ins_point);
97 rb_insert_color(&ha->node, &list->tree);
99 RB_CLEAR_NODE(&ha->node);
102 list_add_tail_rcu(&ha->list, &list->list);
108 static int __hw_addr_add(struct netdev_hw_addr_list *list,
109 const unsigned char *addr, int addr_len,
110 unsigned char addr_type)
112 return __hw_addr_add_ex(list, addr, addr_len, addr_type, false, false,
116 static int __hw_addr_del_entry(struct netdev_hw_addr_list *list,
117 struct netdev_hw_addr *ha, bool global,
120 if (global && !ha->global_use)
123 if (sync && !ha->synced)
127 ha->global_use = false;
135 if (!RB_EMPTY_NODE(&ha->node))
136 rb_erase(&ha->node, &list->tree);
138 list_del_rcu(&ha->list);
139 kfree_rcu(ha, rcu_head);
144 static struct netdev_hw_addr *__hw_addr_lookup(struct netdev_hw_addr_list *list,
145 const unsigned char *addr, int addr_len,
146 unsigned char addr_type)
148 struct netdev_hw_addr *ha;
149 struct rb_node *node;
151 /* The first address isn't inserted into the tree because in the dev->dev_addrs
152 * list it's the address pointed to by dev->dev_addr which is freely mutated
153 * in place, so we need to check it separately.
155 ha = list_first_entry(&list->list, struct netdev_hw_addr, list);
156 if (ha && !memcmp(addr, ha->addr, addr_len) &&
157 (!addr_type || addr_type == ha->type))
160 node = list->tree.rb_node;
163 struct netdev_hw_addr *ha = rb_entry(node, struct netdev_hw_addr, node);
164 int diff = memcmp(addr, ha->addr, addr_len);
166 if (diff == 0 && addr_type)
167 diff = memcmp(&addr_type, &ha->type, sizeof(addr_type));
170 node = node->rb_left;
172 node = node->rb_right;
180 static int __hw_addr_del_ex(struct netdev_hw_addr_list *list,
181 const unsigned char *addr, int addr_len,
182 unsigned char addr_type, bool global, bool sync)
184 struct netdev_hw_addr *ha = __hw_addr_lookup(list, addr, addr_len, addr_type);
188 return __hw_addr_del_entry(list, ha, global, sync);
191 static int __hw_addr_del(struct netdev_hw_addr_list *list,
192 const unsigned char *addr, int addr_len,
193 unsigned char addr_type)
195 return __hw_addr_del_ex(list, addr, addr_len, addr_type, false, false);
198 static int __hw_addr_sync_one(struct netdev_hw_addr_list *to_list,
199 struct netdev_hw_addr *ha,
204 err = __hw_addr_add_ex(to_list, ha->addr, addr_len, ha->type,
205 false, true, ha->sync_cnt, false);
206 if (err && err != -EEXIST)
217 static void __hw_addr_unsync_one(struct netdev_hw_addr_list *to_list,
218 struct netdev_hw_addr_list *from_list,
219 struct netdev_hw_addr *ha,
224 err = __hw_addr_del_ex(to_list, ha->addr, addr_len, ha->type,
229 /* address on from list is not marked synced */
230 __hw_addr_del_entry(from_list, ha, false, false);
233 static int __hw_addr_sync_multiple(struct netdev_hw_addr_list *to_list,
234 struct netdev_hw_addr_list *from_list,
238 struct netdev_hw_addr *ha, *tmp;
240 list_for_each_entry_safe(ha, tmp, &from_list->list, list) {
241 if (ha->sync_cnt == ha->refcount) {
242 __hw_addr_unsync_one(to_list, from_list, ha, addr_len);
244 err = __hw_addr_sync_one(to_list, ha, addr_len);
252 /* This function only works where there is a strict 1-1 relationship
253 * between source and destionation of they synch. If you ever need to
254 * sync addresses to more then 1 destination, you need to use
255 * __hw_addr_sync_multiple().
257 int __hw_addr_sync(struct netdev_hw_addr_list *to_list,
258 struct netdev_hw_addr_list *from_list,
262 struct netdev_hw_addr *ha, *tmp;
264 list_for_each_entry_safe(ha, tmp, &from_list->list, list) {
266 err = __hw_addr_sync_one(to_list, ha, addr_len);
269 } else if (ha->refcount == 1)
270 __hw_addr_unsync_one(to_list, from_list, ha, addr_len);
274 EXPORT_SYMBOL(__hw_addr_sync);
276 void __hw_addr_unsync(struct netdev_hw_addr_list *to_list,
277 struct netdev_hw_addr_list *from_list,
280 struct netdev_hw_addr *ha, *tmp;
282 list_for_each_entry_safe(ha, tmp, &from_list->list, list) {
284 __hw_addr_unsync_one(to_list, from_list, ha, addr_len);
287 EXPORT_SYMBOL(__hw_addr_unsync);
290 * __hw_addr_sync_dev - Synchonize device's multicast list
291 * @list: address list to syncronize
292 * @dev: device to sync
293 * @sync: function to call if address should be added
294 * @unsync: function to call if address should be removed
296 * This function is intended to be called from the ndo_set_rx_mode
297 * function of devices that require explicit address add/remove
298 * notifications. The unsync function may be NULL in which case
299 * the addresses requiring removal will simply be removed without
300 * any notification to the device.
302 int __hw_addr_sync_dev(struct netdev_hw_addr_list *list,
303 struct net_device *dev,
304 int (*sync)(struct net_device *, const unsigned char *),
305 int (*unsync)(struct net_device *,
306 const unsigned char *))
308 struct netdev_hw_addr *ha, *tmp;
311 /* first go through and flush out any stale entries */
312 list_for_each_entry_safe(ha, tmp, &list->list, list) {
313 if (!ha->sync_cnt || ha->refcount != 1)
316 /* if unsync is defined and fails defer unsyncing address */
317 if (unsync && unsync(dev, ha->addr))
321 __hw_addr_del_entry(list, ha, false, false);
324 /* go through and sync new entries to the list */
325 list_for_each_entry_safe(ha, tmp, &list->list, list) {
329 err = sync(dev, ha->addr);
339 EXPORT_SYMBOL(__hw_addr_sync_dev);
342 * __hw_addr_ref_sync_dev - Synchronize device's multicast address list taking
343 * into account references
344 * @list: address list to synchronize
345 * @dev: device to sync
346 * @sync: function to call if address or reference on it should be added
347 * @unsync: function to call if address or some reference on it should removed
349 * This function is intended to be called from the ndo_set_rx_mode
350 * function of devices that require explicit address or references on it
351 * add/remove notifications. The unsync function may be NULL in which case
352 * the addresses or references on it requiring removal will simply be
353 * removed without any notification to the device. That is responsibility of
354 * the driver to identify and distribute address or references on it between
355 * internal address tables.
357 int __hw_addr_ref_sync_dev(struct netdev_hw_addr_list *list,
358 struct net_device *dev,
359 int (*sync)(struct net_device *,
360 const unsigned char *, int),
361 int (*unsync)(struct net_device *,
362 const unsigned char *, int))
364 struct netdev_hw_addr *ha, *tmp;
367 /* first go through and flush out any unsynced/stale entries */
368 list_for_each_entry_safe(ha, tmp, &list->list, list) {
369 /* sync if address is not used */
370 if ((ha->sync_cnt << 1) <= ha->refcount)
373 /* if fails defer unsyncing address */
374 ref_cnt = ha->refcount - ha->sync_cnt;
375 if (unsync && unsync(dev, ha->addr, ref_cnt))
378 ha->refcount = (ref_cnt << 1) + 1;
379 ha->sync_cnt = ref_cnt;
380 __hw_addr_del_entry(list, ha, false, false);
383 /* go through and sync updated/new entries to the list */
384 list_for_each_entry_safe(ha, tmp, &list->list, list) {
385 /* sync if address added or reused */
386 if ((ha->sync_cnt << 1) >= ha->refcount)
389 ref_cnt = ha->refcount - ha->sync_cnt;
390 err = sync(dev, ha->addr, ref_cnt);
394 ha->refcount = ref_cnt << 1;
395 ha->sync_cnt = ref_cnt;
400 EXPORT_SYMBOL(__hw_addr_ref_sync_dev);
403 * __hw_addr_ref_unsync_dev - Remove synchronized addresses and references on
405 * @list: address list to remove synchronized addresses (references on it) from
406 * @dev: device to sync
407 * @unsync: function to call if address and references on it should be removed
409 * Remove all addresses that were added to the device by
410 * __hw_addr_ref_sync_dev(). This function is intended to be called from the
411 * ndo_stop or ndo_open functions on devices that require explicit address (or
412 * references on it) add/remove notifications. If the unsync function pointer
413 * is NULL then this function can be used to just reset the sync_cnt for the
414 * addresses in the list.
416 void __hw_addr_ref_unsync_dev(struct netdev_hw_addr_list *list,
417 struct net_device *dev,
418 int (*unsync)(struct net_device *,
419 const unsigned char *, int))
421 struct netdev_hw_addr *ha, *tmp;
423 list_for_each_entry_safe(ha, tmp, &list->list, list) {
427 /* if fails defer unsyncing address */
428 if (unsync && unsync(dev, ha->addr, ha->sync_cnt))
431 ha->refcount -= ha->sync_cnt - 1;
433 __hw_addr_del_entry(list, ha, false, false);
436 EXPORT_SYMBOL(__hw_addr_ref_unsync_dev);
439 * __hw_addr_unsync_dev - Remove synchronized addresses from device
440 * @list: address list to remove synchronized addresses from
441 * @dev: device to sync
442 * @unsync: function to call if address should be removed
444 * Remove all addresses that were added to the device by __hw_addr_sync_dev().
445 * This function is intended to be called from the ndo_stop or ndo_open
446 * functions on devices that require explicit address add/remove
447 * notifications. If the unsync function pointer is NULL then this function
448 * can be used to just reset the sync_cnt for the addresses in the list.
450 void __hw_addr_unsync_dev(struct netdev_hw_addr_list *list,
451 struct net_device *dev,
452 int (*unsync)(struct net_device *,
453 const unsigned char *))
455 struct netdev_hw_addr *ha, *tmp;
457 list_for_each_entry_safe(ha, tmp, &list->list, list) {
461 /* if unsync is defined and fails defer unsyncing address */
462 if (unsync && unsync(dev, ha->addr))
466 __hw_addr_del_entry(list, ha, false, false);
469 EXPORT_SYMBOL(__hw_addr_unsync_dev);
471 static void __hw_addr_flush(struct netdev_hw_addr_list *list)
473 struct netdev_hw_addr *ha, *tmp;
475 list->tree = RB_ROOT;
476 list_for_each_entry_safe(ha, tmp, &list->list, list) {
477 list_del_rcu(&ha->list);
478 kfree_rcu(ha, rcu_head);
483 void __hw_addr_init(struct netdev_hw_addr_list *list)
485 INIT_LIST_HEAD(&list->list);
487 list->tree = RB_ROOT;
489 EXPORT_SYMBOL(__hw_addr_init);
492 * Device addresses handling functions
496 * dev_addr_flush - Flush device address list
499 * Flush device address list and reset ->dev_addr.
501 * The caller must hold the rtnl_mutex.
503 void dev_addr_flush(struct net_device *dev)
505 /* rtnl_mutex must be held here */
507 __hw_addr_flush(&dev->dev_addrs);
508 dev->dev_addr = NULL;
510 EXPORT_SYMBOL(dev_addr_flush);
513 * dev_addr_init - Init device address list
516 * Init device address list and create the first element,
517 * used by ->dev_addr.
519 * The caller must hold the rtnl_mutex.
521 int dev_addr_init(struct net_device *dev)
523 unsigned char addr[MAX_ADDR_LEN];
524 struct netdev_hw_addr *ha;
527 /* rtnl_mutex must be held here */
529 __hw_addr_init(&dev->dev_addrs);
530 memset(addr, 0, sizeof(addr));
531 err = __hw_addr_add(&dev->dev_addrs, addr, sizeof(addr),
532 NETDEV_HW_ADDR_T_LAN);
535 * Get the first (previously created) address from the list
536 * and set dev_addr pointer to this location.
538 ha = list_first_entry(&dev->dev_addrs.list,
539 struct netdev_hw_addr, list);
540 dev->dev_addr = ha->addr;
544 EXPORT_SYMBOL(dev_addr_init);
547 * dev_addr_add - Add a device address
549 * @addr: address to add
550 * @addr_type: address type
552 * Add a device address to the device or increase the reference count if
555 * The caller must hold the rtnl_mutex.
557 int dev_addr_add(struct net_device *dev, const unsigned char *addr,
558 unsigned char addr_type)
564 err = dev_pre_changeaddr_notify(dev, addr, NULL);
567 err = __hw_addr_add(&dev->dev_addrs, addr, dev->addr_len, addr_type);
569 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
572 EXPORT_SYMBOL(dev_addr_add);
575 * dev_addr_del - Release a device address.
577 * @addr: address to delete
578 * @addr_type: address type
580 * Release reference to a device address and remove it from the device
581 * if the reference count drops to zero.
583 * The caller must hold the rtnl_mutex.
585 int dev_addr_del(struct net_device *dev, const unsigned char *addr,
586 unsigned char addr_type)
589 struct netdev_hw_addr *ha;
594 * We can not remove the first address from the list because
595 * dev->dev_addr points to that.
597 ha = list_first_entry(&dev->dev_addrs.list,
598 struct netdev_hw_addr, list);
599 if (!memcmp(ha->addr, addr, dev->addr_len) &&
600 ha->type == addr_type && ha->refcount == 1)
603 err = __hw_addr_del(&dev->dev_addrs, addr, dev->addr_len,
606 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
609 EXPORT_SYMBOL(dev_addr_del);
612 * Unicast list handling functions
616 * dev_uc_add_excl - Add a global secondary unicast address
618 * @addr: address to add
620 int dev_uc_add_excl(struct net_device *dev, const unsigned char *addr)
624 netif_addr_lock_bh(dev);
625 err = __hw_addr_add_ex(&dev->uc, addr, dev->addr_len,
626 NETDEV_HW_ADDR_T_UNICAST, true, false,
629 __dev_set_rx_mode(dev);
630 netif_addr_unlock_bh(dev);
633 EXPORT_SYMBOL(dev_uc_add_excl);
636 * dev_uc_add - Add a secondary unicast address
638 * @addr: address to add
640 * Add a secondary unicast address to the device or increase
641 * the reference count if it already exists.
643 int dev_uc_add(struct net_device *dev, const unsigned char *addr)
647 netif_addr_lock_bh(dev);
648 err = __hw_addr_add(&dev->uc, addr, dev->addr_len,
649 NETDEV_HW_ADDR_T_UNICAST);
651 __dev_set_rx_mode(dev);
652 netif_addr_unlock_bh(dev);
655 EXPORT_SYMBOL(dev_uc_add);
658 * dev_uc_del - Release secondary unicast address.
660 * @addr: address to delete
662 * Release reference to a secondary unicast address and remove it
663 * from the device if the reference count drops to zero.
665 int dev_uc_del(struct net_device *dev, const unsigned char *addr)
669 netif_addr_lock_bh(dev);
670 err = __hw_addr_del(&dev->uc, addr, dev->addr_len,
671 NETDEV_HW_ADDR_T_UNICAST);
673 __dev_set_rx_mode(dev);
674 netif_addr_unlock_bh(dev);
677 EXPORT_SYMBOL(dev_uc_del);
680 * dev_uc_sync - Synchronize device's unicast list to another device
681 * @to: destination device
682 * @from: source device
684 * Add newly added addresses to the destination device and release
685 * addresses that have no users left. The source device must be
686 * locked by netif_addr_lock_bh.
688 * This function is intended to be called from the dev->set_rx_mode
689 * function of layered software devices. This function assumes that
690 * addresses will only ever be synced to the @to devices and no other.
692 int dev_uc_sync(struct net_device *to, struct net_device *from)
696 if (to->addr_len != from->addr_len)
700 err = __hw_addr_sync(&to->uc, &from->uc, to->addr_len);
702 __dev_set_rx_mode(to);
703 netif_addr_unlock(to);
706 EXPORT_SYMBOL(dev_uc_sync);
709 * dev_uc_sync_multiple - Synchronize device's unicast list to another
710 * device, but allow for multiple calls to sync to multiple devices.
711 * @to: destination device
712 * @from: source device
714 * Add newly added addresses to the destination device and release
715 * addresses that have been deleted from the source. The source device
716 * must be locked by netif_addr_lock_bh.
718 * This function is intended to be called from the dev->set_rx_mode
719 * function of layered software devices. It allows for a single source
720 * device to be synced to multiple destination devices.
722 int dev_uc_sync_multiple(struct net_device *to, struct net_device *from)
726 if (to->addr_len != from->addr_len)
730 err = __hw_addr_sync_multiple(&to->uc, &from->uc, to->addr_len);
732 __dev_set_rx_mode(to);
733 netif_addr_unlock(to);
736 EXPORT_SYMBOL(dev_uc_sync_multiple);
739 * dev_uc_unsync - Remove synchronized addresses from the destination device
740 * @to: destination device
741 * @from: source device
743 * Remove all addresses that were added to the destination device by
744 * dev_uc_sync(). This function is intended to be called from the
745 * dev->stop function of layered software devices.
747 void dev_uc_unsync(struct net_device *to, struct net_device *from)
749 if (to->addr_len != from->addr_len)
752 /* netif_addr_lock_bh() uses lockdep subclass 0, this is okay for two
754 * 1) This is always called without any addr_list_lock, so as the
755 * outermost one here, it must be 0.
756 * 2) This is called by some callers after unlinking the upper device,
757 * so the dev->lower_level becomes 1 again.
758 * Therefore, the subclass for 'from' is 0, for 'to' is either 1 or
761 netif_addr_lock_bh(from);
763 __hw_addr_unsync(&to->uc, &from->uc, to->addr_len);
764 __dev_set_rx_mode(to);
765 netif_addr_unlock(to);
766 netif_addr_unlock_bh(from);
768 EXPORT_SYMBOL(dev_uc_unsync);
771 * dev_uc_flush - Flush unicast addresses
774 * Flush unicast addresses.
776 void dev_uc_flush(struct net_device *dev)
778 netif_addr_lock_bh(dev);
779 __hw_addr_flush(&dev->uc);
780 netif_addr_unlock_bh(dev);
782 EXPORT_SYMBOL(dev_uc_flush);
785 * dev_uc_init - Init unicast address list
788 * Init unicast address list.
790 void dev_uc_init(struct net_device *dev)
792 __hw_addr_init(&dev->uc);
794 EXPORT_SYMBOL(dev_uc_init);
797 * Multicast list handling functions
801 * dev_mc_add_excl - Add a global secondary multicast address
803 * @addr: address to add
805 int dev_mc_add_excl(struct net_device *dev, const unsigned char *addr)
809 netif_addr_lock_bh(dev);
810 err = __hw_addr_add_ex(&dev->mc, addr, dev->addr_len,
811 NETDEV_HW_ADDR_T_MULTICAST, true, false,
814 __dev_set_rx_mode(dev);
815 netif_addr_unlock_bh(dev);
818 EXPORT_SYMBOL(dev_mc_add_excl);
820 static int __dev_mc_add(struct net_device *dev, const unsigned char *addr,
825 netif_addr_lock_bh(dev);
826 err = __hw_addr_add_ex(&dev->mc, addr, dev->addr_len,
827 NETDEV_HW_ADDR_T_MULTICAST, global, false,
830 __dev_set_rx_mode(dev);
831 netif_addr_unlock_bh(dev);
835 * dev_mc_add - Add a multicast address
837 * @addr: address to add
839 * Add a multicast address to the device or increase
840 * the reference count if it already exists.
842 int dev_mc_add(struct net_device *dev, const unsigned char *addr)
844 return __dev_mc_add(dev, addr, false);
846 EXPORT_SYMBOL(dev_mc_add);
849 * dev_mc_add_global - Add a global multicast address
851 * @addr: address to add
853 * Add a global multicast address to the device.
855 int dev_mc_add_global(struct net_device *dev, const unsigned char *addr)
857 return __dev_mc_add(dev, addr, true);
859 EXPORT_SYMBOL(dev_mc_add_global);
861 static int __dev_mc_del(struct net_device *dev, const unsigned char *addr,
866 netif_addr_lock_bh(dev);
867 err = __hw_addr_del_ex(&dev->mc, addr, dev->addr_len,
868 NETDEV_HW_ADDR_T_MULTICAST, global, false);
870 __dev_set_rx_mode(dev);
871 netif_addr_unlock_bh(dev);
876 * dev_mc_del - Delete a multicast address.
878 * @addr: address to delete
880 * Release reference to a multicast address and remove it
881 * from the device if the reference count drops to zero.
883 int dev_mc_del(struct net_device *dev, const unsigned char *addr)
885 return __dev_mc_del(dev, addr, false);
887 EXPORT_SYMBOL(dev_mc_del);
890 * dev_mc_del_global - Delete a global multicast address.
892 * @addr: address to delete
894 * Release reference to a multicast address and remove it
895 * from the device if the reference count drops to zero.
897 int dev_mc_del_global(struct net_device *dev, const unsigned char *addr)
899 return __dev_mc_del(dev, addr, true);
901 EXPORT_SYMBOL(dev_mc_del_global);
904 * dev_mc_sync - Synchronize device's multicast list to another device
905 * @to: destination device
906 * @from: source device
908 * Add newly added addresses to the destination device and release
909 * addresses that have no users left. The source device must be
910 * locked by netif_addr_lock_bh.
912 * This function is intended to be called from the ndo_set_rx_mode
913 * function of layered software devices.
915 int dev_mc_sync(struct net_device *to, struct net_device *from)
919 if (to->addr_len != from->addr_len)
923 err = __hw_addr_sync(&to->mc, &from->mc, to->addr_len);
925 __dev_set_rx_mode(to);
926 netif_addr_unlock(to);
929 EXPORT_SYMBOL(dev_mc_sync);
932 * dev_mc_sync_multiple - Synchronize device's multicast list to another
933 * device, but allow for multiple calls to sync to multiple devices.
934 * @to: destination device
935 * @from: source device
937 * Add newly added addresses to the destination device and release
938 * addresses that have no users left. The source device must be
939 * locked by netif_addr_lock_bh.
941 * This function is intended to be called from the ndo_set_rx_mode
942 * function of layered software devices. It allows for a single
943 * source device to be synced to multiple destination devices.
945 int dev_mc_sync_multiple(struct net_device *to, struct net_device *from)
949 if (to->addr_len != from->addr_len)
953 err = __hw_addr_sync_multiple(&to->mc, &from->mc, to->addr_len);
955 __dev_set_rx_mode(to);
956 netif_addr_unlock(to);
959 EXPORT_SYMBOL(dev_mc_sync_multiple);
962 * dev_mc_unsync - Remove synchronized addresses from the destination device
963 * @to: destination device
964 * @from: source device
966 * Remove all addresses that were added to the destination device by
967 * dev_mc_sync(). This function is intended to be called from the
968 * dev->stop function of layered software devices.
970 void dev_mc_unsync(struct net_device *to, struct net_device *from)
972 if (to->addr_len != from->addr_len)
975 /* See the above comments inside dev_uc_unsync(). */
976 netif_addr_lock_bh(from);
978 __hw_addr_unsync(&to->mc, &from->mc, to->addr_len);
979 __dev_set_rx_mode(to);
980 netif_addr_unlock(to);
981 netif_addr_unlock_bh(from);
983 EXPORT_SYMBOL(dev_mc_unsync);
986 * dev_mc_flush - Flush multicast addresses
989 * Flush multicast addresses.
991 void dev_mc_flush(struct net_device *dev)
993 netif_addr_lock_bh(dev);
994 __hw_addr_flush(&dev->mc);
995 netif_addr_unlock_bh(dev);
997 EXPORT_SYMBOL(dev_mc_flush);
1000 * dev_mc_init - Init multicast address list
1003 * Init multicast address list.
1005 void dev_mc_init(struct net_device *dev)
1007 __hw_addr_init(&dev->mc);
1009 EXPORT_SYMBOL(dev_mc_init);