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 int __hw_addr_insert(struct netdev_hw_addr_list *list,
20 struct netdev_hw_addr *new, int addr_len)
22 struct rb_node **ins_point = &list->tree.rb_node, *parent = NULL;
23 struct netdev_hw_addr *ha;
28 ha = rb_entry(*ins_point, struct netdev_hw_addr, node);
29 diff = memcmp(new->addr, ha->addr, addr_len);
31 diff = memcmp(&new->type, &ha->type, sizeof(new->type));
35 ins_point = &parent->rb_left;
37 ins_point = &parent->rb_right;
42 rb_link_node_rcu(&new->node, parent, ins_point);
43 rb_insert_color(&new->node, &list->tree);
48 static struct netdev_hw_addr*
49 __hw_addr_create(const unsigned char *addr, int addr_len,
50 unsigned char addr_type, bool global, bool sync)
52 struct netdev_hw_addr *ha;
55 alloc_size = sizeof(*ha);
56 if (alloc_size < L1_CACHE_BYTES)
57 alloc_size = L1_CACHE_BYTES;
58 ha = kmalloc(alloc_size, GFP_ATOMIC);
61 memcpy(ha->addr, addr, addr_len);
64 ha->global_use = global;
65 ha->synced = sync ? 1 : 0;
71 static int __hw_addr_add_ex(struct netdev_hw_addr_list *list,
72 const unsigned char *addr, int addr_len,
73 unsigned char addr_type, bool global, bool sync,
74 int sync_count, bool exclusive)
76 struct rb_node **ins_point = &list->tree.rb_node, *parent = NULL;
77 struct netdev_hw_addr *ha;
79 if (addr_len > MAX_ADDR_LEN)
85 ha = rb_entry(*ins_point, struct netdev_hw_addr, node);
86 diff = memcmp(addr, ha->addr, addr_len);
88 diff = memcmp(&addr_type, &ha->type, sizeof(addr_type));
92 ins_point = &parent->rb_left;
93 } else if (diff > 0) {
94 ins_point = &parent->rb_right;
99 /* check if addr is already used as global */
103 ha->global_use = true;
106 if (ha->synced && sync_count)
116 ha = __hw_addr_create(addr, addr_len, addr_type, global, sync);
120 rb_link_node(&ha->node, parent, ins_point);
121 rb_insert_color(&ha->node, &list->tree);
123 list_add_tail_rcu(&ha->list, &list->list);
129 static int __hw_addr_add(struct netdev_hw_addr_list *list,
130 const unsigned char *addr, int addr_len,
131 unsigned char addr_type)
133 return __hw_addr_add_ex(list, addr, addr_len, addr_type, false, false,
137 static int __hw_addr_del_entry(struct netdev_hw_addr_list *list,
138 struct netdev_hw_addr *ha, bool global,
141 if (global && !ha->global_use)
144 if (sync && !ha->synced)
148 ha->global_use = false;
156 rb_erase(&ha->node, &list->tree);
158 list_del_rcu(&ha->list);
159 kfree_rcu(ha, rcu_head);
164 static struct netdev_hw_addr *__hw_addr_lookup(struct netdev_hw_addr_list *list,
165 const unsigned char *addr, int addr_len,
166 unsigned char addr_type)
168 struct rb_node *node;
170 node = list->tree.rb_node;
173 struct netdev_hw_addr *ha = rb_entry(node, struct netdev_hw_addr, node);
174 int diff = memcmp(addr, ha->addr, addr_len);
176 if (diff == 0 && addr_type)
177 diff = memcmp(&addr_type, &ha->type, sizeof(addr_type));
180 node = node->rb_left;
182 node = node->rb_right;
190 static int __hw_addr_del_ex(struct netdev_hw_addr_list *list,
191 const unsigned char *addr, int addr_len,
192 unsigned char addr_type, bool global, bool sync)
194 struct netdev_hw_addr *ha = __hw_addr_lookup(list, addr, addr_len, addr_type);
198 return __hw_addr_del_entry(list, ha, global, sync);
201 static int __hw_addr_del(struct netdev_hw_addr_list *list,
202 const unsigned char *addr, int addr_len,
203 unsigned char addr_type)
205 return __hw_addr_del_ex(list, addr, addr_len, addr_type, false, false);
208 static int __hw_addr_sync_one(struct netdev_hw_addr_list *to_list,
209 struct netdev_hw_addr *ha,
214 err = __hw_addr_add_ex(to_list, ha->addr, addr_len, ha->type,
215 false, true, ha->sync_cnt, false);
216 if (err && err != -EEXIST)
227 static void __hw_addr_unsync_one(struct netdev_hw_addr_list *to_list,
228 struct netdev_hw_addr_list *from_list,
229 struct netdev_hw_addr *ha,
234 err = __hw_addr_del_ex(to_list, ha->addr, addr_len, ha->type,
239 /* address on from list is not marked synced */
240 __hw_addr_del_entry(from_list, ha, false, false);
243 static int __hw_addr_sync_multiple(struct netdev_hw_addr_list *to_list,
244 struct netdev_hw_addr_list *from_list,
248 struct netdev_hw_addr *ha, *tmp;
250 list_for_each_entry_safe(ha, tmp, &from_list->list, list) {
251 if (ha->sync_cnt == ha->refcount) {
252 __hw_addr_unsync_one(to_list, from_list, ha, addr_len);
254 err = __hw_addr_sync_one(to_list, ha, addr_len);
262 /* This function only works where there is a strict 1-1 relationship
263 * between source and destionation of they synch. If you ever need to
264 * sync addresses to more then 1 destination, you need to use
265 * __hw_addr_sync_multiple().
267 int __hw_addr_sync(struct netdev_hw_addr_list *to_list,
268 struct netdev_hw_addr_list *from_list,
272 struct netdev_hw_addr *ha, *tmp;
274 list_for_each_entry_safe(ha, tmp, &from_list->list, list) {
276 err = __hw_addr_sync_one(to_list, ha, addr_len);
279 } else if (ha->refcount == 1)
280 __hw_addr_unsync_one(to_list, from_list, ha, addr_len);
284 EXPORT_SYMBOL(__hw_addr_sync);
286 void __hw_addr_unsync(struct netdev_hw_addr_list *to_list,
287 struct netdev_hw_addr_list *from_list,
290 struct netdev_hw_addr *ha, *tmp;
292 list_for_each_entry_safe(ha, tmp, &from_list->list, list) {
294 __hw_addr_unsync_one(to_list, from_list, ha, addr_len);
297 EXPORT_SYMBOL(__hw_addr_unsync);
300 * __hw_addr_sync_dev - Synchonize device's multicast list
301 * @list: address list to syncronize
302 * @dev: device to sync
303 * @sync: function to call if address should be added
304 * @unsync: function to call if address should be removed
306 * This function is intended to be called from the ndo_set_rx_mode
307 * function of devices that require explicit address add/remove
308 * notifications. The unsync function may be NULL in which case
309 * the addresses requiring removal will simply be removed without
310 * any notification to the device.
312 int __hw_addr_sync_dev(struct netdev_hw_addr_list *list,
313 struct net_device *dev,
314 int (*sync)(struct net_device *, const unsigned char *),
315 int (*unsync)(struct net_device *,
316 const unsigned char *))
318 struct netdev_hw_addr *ha, *tmp;
321 /* first go through and flush out any stale entries */
322 list_for_each_entry_safe(ha, tmp, &list->list, list) {
323 if (!ha->sync_cnt || ha->refcount != 1)
326 /* if unsync is defined and fails defer unsyncing address */
327 if (unsync && unsync(dev, ha->addr))
331 __hw_addr_del_entry(list, ha, false, false);
334 /* go through and sync new entries to the list */
335 list_for_each_entry_safe(ha, tmp, &list->list, list) {
339 err = sync(dev, ha->addr);
349 EXPORT_SYMBOL(__hw_addr_sync_dev);
352 * __hw_addr_ref_sync_dev - Synchronize device's multicast address list taking
353 * into account references
354 * @list: address list to synchronize
355 * @dev: device to sync
356 * @sync: function to call if address or reference on it should be added
357 * @unsync: function to call if address or some reference on it should removed
359 * This function is intended to be called from the ndo_set_rx_mode
360 * function of devices that require explicit address or references on it
361 * add/remove notifications. The unsync function may be NULL in which case
362 * the addresses or references on it requiring removal will simply be
363 * removed without any notification to the device. That is responsibility of
364 * the driver to identify and distribute address or references on it between
365 * internal address tables.
367 int __hw_addr_ref_sync_dev(struct netdev_hw_addr_list *list,
368 struct net_device *dev,
369 int (*sync)(struct net_device *,
370 const unsigned char *, int),
371 int (*unsync)(struct net_device *,
372 const unsigned char *, int))
374 struct netdev_hw_addr *ha, *tmp;
377 /* first go through and flush out any unsynced/stale entries */
378 list_for_each_entry_safe(ha, tmp, &list->list, list) {
379 /* sync if address is not used */
380 if ((ha->sync_cnt << 1) <= ha->refcount)
383 /* if fails defer unsyncing address */
384 ref_cnt = ha->refcount - ha->sync_cnt;
385 if (unsync && unsync(dev, ha->addr, ref_cnt))
388 ha->refcount = (ref_cnt << 1) + 1;
389 ha->sync_cnt = ref_cnt;
390 __hw_addr_del_entry(list, ha, false, false);
393 /* go through and sync updated/new entries to the list */
394 list_for_each_entry_safe(ha, tmp, &list->list, list) {
395 /* sync if address added or reused */
396 if ((ha->sync_cnt << 1) >= ha->refcount)
399 ref_cnt = ha->refcount - ha->sync_cnt;
400 err = sync(dev, ha->addr, ref_cnt);
404 ha->refcount = ref_cnt << 1;
405 ha->sync_cnt = ref_cnt;
410 EXPORT_SYMBOL(__hw_addr_ref_sync_dev);
413 * __hw_addr_ref_unsync_dev - Remove synchronized addresses and references on
415 * @list: address list to remove synchronized addresses (references on it) from
416 * @dev: device to sync
417 * @unsync: function to call if address and references on it should be removed
419 * Remove all addresses that were added to the device by
420 * __hw_addr_ref_sync_dev(). This function is intended to be called from the
421 * ndo_stop or ndo_open functions on devices that require explicit address (or
422 * references on it) add/remove notifications. If the unsync function pointer
423 * is NULL then this function can be used to just reset the sync_cnt for the
424 * addresses in the list.
426 void __hw_addr_ref_unsync_dev(struct netdev_hw_addr_list *list,
427 struct net_device *dev,
428 int (*unsync)(struct net_device *,
429 const unsigned char *, int))
431 struct netdev_hw_addr *ha, *tmp;
433 list_for_each_entry_safe(ha, tmp, &list->list, list) {
437 /* if fails defer unsyncing address */
438 if (unsync && unsync(dev, ha->addr, ha->sync_cnt))
441 ha->refcount -= ha->sync_cnt - 1;
443 __hw_addr_del_entry(list, ha, false, false);
446 EXPORT_SYMBOL(__hw_addr_ref_unsync_dev);
449 * __hw_addr_unsync_dev - Remove synchronized addresses from device
450 * @list: address list to remove synchronized addresses from
451 * @dev: device to sync
452 * @unsync: function to call if address should be removed
454 * Remove all addresses that were added to the device by __hw_addr_sync_dev().
455 * This function is intended to be called from the ndo_stop or ndo_open
456 * functions on devices that require explicit address add/remove
457 * notifications. If the unsync function pointer is NULL then this function
458 * can be used to just reset the sync_cnt for the addresses in the list.
460 void __hw_addr_unsync_dev(struct netdev_hw_addr_list *list,
461 struct net_device *dev,
462 int (*unsync)(struct net_device *,
463 const unsigned char *))
465 struct netdev_hw_addr *ha, *tmp;
467 list_for_each_entry_safe(ha, tmp, &list->list, list) {
471 /* if unsync is defined and fails defer unsyncing address */
472 if (unsync && unsync(dev, ha->addr))
476 __hw_addr_del_entry(list, ha, false, false);
479 EXPORT_SYMBOL(__hw_addr_unsync_dev);
481 static void __hw_addr_flush(struct netdev_hw_addr_list *list)
483 struct netdev_hw_addr *ha, *tmp;
485 list->tree = RB_ROOT;
486 list_for_each_entry_safe(ha, tmp, &list->list, list) {
487 list_del_rcu(&ha->list);
488 kfree_rcu(ha, rcu_head);
493 void __hw_addr_init(struct netdev_hw_addr_list *list)
495 INIT_LIST_HEAD(&list->list);
497 list->tree = RB_ROOT;
499 EXPORT_SYMBOL(__hw_addr_init);
502 * Device addresses handling functions
505 /* Check that netdev->dev_addr is not written to directly as this would
506 * break the rbtree layout. All changes should go thru dev_addr_set() and co.
507 * Remove this check in mid-2024.
509 void dev_addr_check(struct net_device *dev)
511 if (!memcmp(dev->dev_addr, dev->dev_addr_shadow, MAX_ADDR_LEN))
514 netdev_warn(dev, "Current addr: %*ph\n", MAX_ADDR_LEN, dev->dev_addr);
515 netdev_warn(dev, "Expected addr: %*ph\n",
516 MAX_ADDR_LEN, dev->dev_addr_shadow);
517 netdev_WARN(dev, "Incorrect netdev->dev_addr\n");
521 * dev_addr_flush - Flush device address list
524 * Flush device address list and reset ->dev_addr.
526 * The caller must hold the rtnl_mutex.
528 void dev_addr_flush(struct net_device *dev)
530 /* rtnl_mutex must be held here */
533 __hw_addr_flush(&dev->dev_addrs);
534 dev->dev_addr = NULL;
538 * dev_addr_init - Init device address list
541 * Init device address list and create the first element,
542 * used by ->dev_addr.
544 * The caller must hold the rtnl_mutex.
546 int dev_addr_init(struct net_device *dev)
548 unsigned char addr[MAX_ADDR_LEN];
549 struct netdev_hw_addr *ha;
552 /* rtnl_mutex must be held here */
554 __hw_addr_init(&dev->dev_addrs);
555 memset(addr, 0, sizeof(addr));
556 err = __hw_addr_add(&dev->dev_addrs, addr, sizeof(addr),
557 NETDEV_HW_ADDR_T_LAN);
560 * Get the first (previously created) address from the list
561 * and set dev_addr pointer to this location.
563 ha = list_first_entry(&dev->dev_addrs.list,
564 struct netdev_hw_addr, list);
565 dev->dev_addr = ha->addr;
570 void dev_addr_mod(struct net_device *dev, unsigned int offset,
571 const void *addr, size_t len)
573 struct netdev_hw_addr *ha;
577 ha = container_of(dev->dev_addr, struct netdev_hw_addr, addr[0]);
578 rb_erase(&ha->node, &dev->dev_addrs.tree);
579 memcpy(&ha->addr[offset], addr, len);
580 memcpy(&dev->dev_addr_shadow[offset], addr, len);
581 WARN_ON(__hw_addr_insert(&dev->dev_addrs, ha, dev->addr_len));
583 EXPORT_SYMBOL(dev_addr_mod);
586 * dev_addr_add - Add a device address
588 * @addr: address to add
589 * @addr_type: address type
591 * Add a device address to the device or increase the reference count if
594 * The caller must hold the rtnl_mutex.
596 int dev_addr_add(struct net_device *dev, const unsigned char *addr,
597 unsigned char addr_type)
603 err = dev_pre_changeaddr_notify(dev, addr, NULL);
606 err = __hw_addr_add(&dev->dev_addrs, addr, dev->addr_len, addr_type);
608 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
611 EXPORT_SYMBOL(dev_addr_add);
614 * dev_addr_del - Release a device address.
616 * @addr: address to delete
617 * @addr_type: address type
619 * Release reference to a device address and remove it from the device
620 * if the reference count drops to zero.
622 * The caller must hold the rtnl_mutex.
624 int dev_addr_del(struct net_device *dev, const unsigned char *addr,
625 unsigned char addr_type)
628 struct netdev_hw_addr *ha;
633 * We can not remove the first address from the list because
634 * dev->dev_addr points to that.
636 ha = list_first_entry(&dev->dev_addrs.list,
637 struct netdev_hw_addr, list);
638 if (!memcmp(ha->addr, addr, dev->addr_len) &&
639 ha->type == addr_type && ha->refcount == 1)
642 err = __hw_addr_del(&dev->dev_addrs, addr, dev->addr_len,
645 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
648 EXPORT_SYMBOL(dev_addr_del);
651 * Unicast list handling functions
655 * dev_uc_add_excl - Add a global secondary unicast address
657 * @addr: address to add
659 int dev_uc_add_excl(struct net_device *dev, const unsigned char *addr)
663 netif_addr_lock_bh(dev);
664 err = __hw_addr_add_ex(&dev->uc, addr, dev->addr_len,
665 NETDEV_HW_ADDR_T_UNICAST, true, false,
668 __dev_set_rx_mode(dev);
669 netif_addr_unlock_bh(dev);
672 EXPORT_SYMBOL(dev_uc_add_excl);
675 * dev_uc_add - Add a secondary unicast address
677 * @addr: address to add
679 * Add a secondary unicast address to the device or increase
680 * the reference count if it already exists.
682 int dev_uc_add(struct net_device *dev, const unsigned char *addr)
686 netif_addr_lock_bh(dev);
687 err = __hw_addr_add(&dev->uc, addr, dev->addr_len,
688 NETDEV_HW_ADDR_T_UNICAST);
690 __dev_set_rx_mode(dev);
691 netif_addr_unlock_bh(dev);
694 EXPORT_SYMBOL(dev_uc_add);
697 * dev_uc_del - Release secondary unicast address.
699 * @addr: address to delete
701 * Release reference to a secondary unicast address and remove it
702 * from the device if the reference count drops to zero.
704 int dev_uc_del(struct net_device *dev, const unsigned char *addr)
708 netif_addr_lock_bh(dev);
709 err = __hw_addr_del(&dev->uc, addr, dev->addr_len,
710 NETDEV_HW_ADDR_T_UNICAST);
712 __dev_set_rx_mode(dev);
713 netif_addr_unlock_bh(dev);
716 EXPORT_SYMBOL(dev_uc_del);
719 * dev_uc_sync - Synchronize device's unicast list to another device
720 * @to: destination device
721 * @from: source device
723 * Add newly added addresses to the destination device and release
724 * addresses that have no users left. The source device must be
725 * locked by netif_addr_lock_bh.
727 * This function is intended to be called from the dev->set_rx_mode
728 * function of layered software devices. This function assumes that
729 * addresses will only ever be synced to the @to devices and no other.
731 int dev_uc_sync(struct net_device *to, struct net_device *from)
735 if (to->addr_len != from->addr_len)
739 err = __hw_addr_sync(&to->uc, &from->uc, to->addr_len);
741 __dev_set_rx_mode(to);
742 netif_addr_unlock(to);
745 EXPORT_SYMBOL(dev_uc_sync);
748 * dev_uc_sync_multiple - Synchronize device's unicast list to another
749 * device, but allow for multiple calls to sync to multiple devices.
750 * @to: destination device
751 * @from: source device
753 * Add newly added addresses to the destination device and release
754 * addresses that have been deleted from the source. The source device
755 * must be locked by netif_addr_lock_bh.
757 * This function is intended to be called from the dev->set_rx_mode
758 * function of layered software devices. It allows for a single source
759 * device to be synced to multiple destination devices.
761 int dev_uc_sync_multiple(struct net_device *to, struct net_device *from)
765 if (to->addr_len != from->addr_len)
769 err = __hw_addr_sync_multiple(&to->uc, &from->uc, to->addr_len);
771 __dev_set_rx_mode(to);
772 netif_addr_unlock(to);
775 EXPORT_SYMBOL(dev_uc_sync_multiple);
778 * dev_uc_unsync - Remove synchronized addresses from the destination device
779 * @to: destination device
780 * @from: source device
782 * Remove all addresses that were added to the destination device by
783 * dev_uc_sync(). This function is intended to be called from the
784 * dev->stop function of layered software devices.
786 void dev_uc_unsync(struct net_device *to, struct net_device *from)
788 if (to->addr_len != from->addr_len)
791 /* netif_addr_lock_bh() uses lockdep subclass 0, this is okay for two
793 * 1) This is always called without any addr_list_lock, so as the
794 * outermost one here, it must be 0.
795 * 2) This is called by some callers after unlinking the upper device,
796 * so the dev->lower_level becomes 1 again.
797 * Therefore, the subclass for 'from' is 0, for 'to' is either 1 or
800 netif_addr_lock_bh(from);
802 __hw_addr_unsync(&to->uc, &from->uc, to->addr_len);
803 __dev_set_rx_mode(to);
804 netif_addr_unlock(to);
805 netif_addr_unlock_bh(from);
807 EXPORT_SYMBOL(dev_uc_unsync);
810 * dev_uc_flush - Flush unicast addresses
813 * Flush unicast addresses.
815 void dev_uc_flush(struct net_device *dev)
817 netif_addr_lock_bh(dev);
818 __hw_addr_flush(&dev->uc);
819 netif_addr_unlock_bh(dev);
821 EXPORT_SYMBOL(dev_uc_flush);
824 * dev_uc_init - Init unicast address list
827 * Init unicast address list.
829 void dev_uc_init(struct net_device *dev)
831 __hw_addr_init(&dev->uc);
833 EXPORT_SYMBOL(dev_uc_init);
836 * Multicast list handling functions
840 * dev_mc_add_excl - Add a global secondary multicast address
842 * @addr: address to add
844 int dev_mc_add_excl(struct net_device *dev, const unsigned char *addr)
848 netif_addr_lock_bh(dev);
849 err = __hw_addr_add_ex(&dev->mc, addr, dev->addr_len,
850 NETDEV_HW_ADDR_T_MULTICAST, true, false,
853 __dev_set_rx_mode(dev);
854 netif_addr_unlock_bh(dev);
857 EXPORT_SYMBOL(dev_mc_add_excl);
859 static int __dev_mc_add(struct net_device *dev, const unsigned char *addr,
864 netif_addr_lock_bh(dev);
865 err = __hw_addr_add_ex(&dev->mc, addr, dev->addr_len,
866 NETDEV_HW_ADDR_T_MULTICAST, global, false,
869 __dev_set_rx_mode(dev);
870 netif_addr_unlock_bh(dev);
874 * dev_mc_add - Add a multicast address
876 * @addr: address to add
878 * Add a multicast address to the device or increase
879 * the reference count if it already exists.
881 int dev_mc_add(struct net_device *dev, const unsigned char *addr)
883 return __dev_mc_add(dev, addr, false);
885 EXPORT_SYMBOL(dev_mc_add);
888 * dev_mc_add_global - Add a global multicast address
890 * @addr: address to add
892 * Add a global multicast address to the device.
894 int dev_mc_add_global(struct net_device *dev, const unsigned char *addr)
896 return __dev_mc_add(dev, addr, true);
898 EXPORT_SYMBOL(dev_mc_add_global);
900 static int __dev_mc_del(struct net_device *dev, const unsigned char *addr,
905 netif_addr_lock_bh(dev);
906 err = __hw_addr_del_ex(&dev->mc, addr, dev->addr_len,
907 NETDEV_HW_ADDR_T_MULTICAST, global, false);
909 __dev_set_rx_mode(dev);
910 netif_addr_unlock_bh(dev);
915 * dev_mc_del - Delete a multicast address.
917 * @addr: address to delete
919 * Release reference to a multicast address and remove it
920 * from the device if the reference count drops to zero.
922 int dev_mc_del(struct net_device *dev, const unsigned char *addr)
924 return __dev_mc_del(dev, addr, false);
926 EXPORT_SYMBOL(dev_mc_del);
929 * dev_mc_del_global - Delete a global multicast address.
931 * @addr: address to delete
933 * Release reference to a multicast address and remove it
934 * from the device if the reference count drops to zero.
936 int dev_mc_del_global(struct net_device *dev, const unsigned char *addr)
938 return __dev_mc_del(dev, addr, true);
940 EXPORT_SYMBOL(dev_mc_del_global);
943 * dev_mc_sync - Synchronize device's multicast list to another device
944 * @to: destination device
945 * @from: source device
947 * Add newly added addresses to the destination device and release
948 * addresses that have no users left. The source device must be
949 * locked by netif_addr_lock_bh.
951 * This function is intended to be called from the ndo_set_rx_mode
952 * function of layered software devices.
954 int dev_mc_sync(struct net_device *to, struct net_device *from)
958 if (to->addr_len != from->addr_len)
962 err = __hw_addr_sync(&to->mc, &from->mc, to->addr_len);
964 __dev_set_rx_mode(to);
965 netif_addr_unlock(to);
968 EXPORT_SYMBOL(dev_mc_sync);
971 * dev_mc_sync_multiple - Synchronize device's multicast list to another
972 * device, but allow for multiple calls to sync to multiple devices.
973 * @to: destination device
974 * @from: source device
976 * Add newly added addresses to the destination device and release
977 * addresses that have no users left. The source device must be
978 * locked by netif_addr_lock_bh.
980 * This function is intended to be called from the ndo_set_rx_mode
981 * function of layered software devices. It allows for a single
982 * source device to be synced to multiple destination devices.
984 int dev_mc_sync_multiple(struct net_device *to, struct net_device *from)
988 if (to->addr_len != from->addr_len)
992 err = __hw_addr_sync_multiple(&to->mc, &from->mc, to->addr_len);
994 __dev_set_rx_mode(to);
995 netif_addr_unlock(to);
998 EXPORT_SYMBOL(dev_mc_sync_multiple);
1001 * dev_mc_unsync - Remove synchronized addresses from the destination device
1002 * @to: destination device
1003 * @from: source device
1005 * Remove all addresses that were added to the destination device by
1006 * dev_mc_sync(). This function is intended to be called from the
1007 * dev->stop function of layered software devices.
1009 void dev_mc_unsync(struct net_device *to, struct net_device *from)
1011 if (to->addr_len != from->addr_len)
1014 /* See the above comments inside dev_uc_unsync(). */
1015 netif_addr_lock_bh(from);
1016 netif_addr_lock(to);
1017 __hw_addr_unsync(&to->mc, &from->mc, to->addr_len);
1018 __dev_set_rx_mode(to);
1019 netif_addr_unlock(to);
1020 netif_addr_unlock_bh(from);
1022 EXPORT_SYMBOL(dev_mc_unsync);
1025 * dev_mc_flush - Flush multicast addresses
1028 * Flush multicast addresses.
1030 void dev_mc_flush(struct net_device *dev)
1032 netif_addr_lock_bh(dev);
1033 __hw_addr_flush(&dev->mc);
1034 netif_addr_unlock_bh(dev);
1036 EXPORT_SYMBOL(dev_mc_flush);
1039 * dev_mc_init - Init multicast address list
1042 * Init multicast address list.
1044 void dev_mc_init(struct net_device *dev)
1046 __hw_addr_init(&dev->mc);
1048 EXPORT_SYMBOL(dev_mc_init);