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