2 * Linux NET3: Multicast List maintenance.
5 * Tim Kordas <tjk@nostromo.eeap.cwru.edu>
6 * Richard Underwood <richard@wuzz.demon.co.uk>
8 * Stir fried together from the IP multicast and CAP patches above
9 * Alan Cox <Alan.Cox@linux.org>
12 * Alan Cox : Update the device on a real delete
13 * rather than any time but...
14 * Alan Cox : IFF_ALLMULTI support.
15 * Alan Cox : New format set_multicast_list() calls.
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version
20 * 2 of the License, or (at your option) any later version.
23 #include <linux/config.h>
24 #include <asm/uaccess.h>
25 #include <asm/system.h>
26 #include <asm/bitops.h>
27 #include <linux/types.h>
28 #include <linux/kernel.h>
29 #include <linux/sched.h>
30 #include <linux/string.h>
32 #include <linux/socket.h>
33 #include <linux/sockios.h>
35 #include <linux/errno.h>
36 #include <linux/interrupt.h>
37 #include <linux/if_ether.h>
38 #include <linux/inet.h>
39 #include <linux/netdevice.h>
40 #include <linux/etherdevice.h>
41 #include <linux/proc_fs.h>
42 #include <linux/init.h>
44 #include <net/route.h>
45 #include <linux/skbuff.h>
51 * Device multicast list maintenance.
53 * This is used both by IP and by the user level maintenance functions.
54 * Unlike BSD we maintain a usage count on a given multicast address so
55 * that a casual user application can add/delete multicasts used by
56 * protocols without doing damage to the protocols when it deletes the
57 * entries. It also helps IP as it tracks overlapping maps.
59 * Device mc lists are changed by bh at least if IPv6 is enabled,
60 * so that it must be bh protected.
64 * Update the multicast list into the physical NIC controller.
67 void dev_mc_upload(struct device
*dev
)
69 /* Don't do anything till we up the interface
70 [dev_open will call this function so the list will
73 if(!(dev
->flags
&IFF_UP
))
77 * Devices with no set multicast don't get set
80 if(dev
->set_multicast_list
==NULL
)
84 dev
->set_multicast_list(dev
);
89 * Delete a device level multicast
92 int dev_mc_delete(struct device
*dev
, void *addr
, int alen
, int glbl
)
95 struct dev_mc_list
*dmi
, **dmip
;
98 for (dmip
=&dev
->mc_list
; (dmi
=*dmip
)!=NULL
; dmip
=&dmi
->next
) {
100 * Find the entry we want to delete. The device could
101 * have variable length entries so check these too.
103 if (memcmp(dmi
->dmi_addr
,addr
,dmi
->dmi_addrlen
)==0 && alen
==dmi
->dmi_addrlen
) {
105 int old_glbl
= dmi
->dmi_gusers
;
114 * Last user. So delete the entry.
118 kfree_s(dmi
,sizeof(*dmi
));
120 * We have altered the list, so the card
121 * loaded filter is now wrong. Fix it
135 * Add a device level multicast
138 int dev_mc_add(struct device
*dev
, void *addr
, int alen
, int glbl
)
141 struct dev_mc_list
*dmi
, *dmi1
;
143 dmi1
= (struct dev_mc_list
*)kmalloc(sizeof(*dmi
), gfp_any());
146 for(dmi
=dev
->mc_list
; dmi
!=NULL
; dmi
=dmi
->next
) {
147 if (memcmp(dmi
->dmi_addr
,addr
,dmi
->dmi_addrlen
)==0 && dmi
->dmi_addrlen
==alen
) {
149 int old_glbl
= dmi
->dmi_gusers
;
159 if ((dmi
=dmi1
)==NULL
)
161 memcpy(dmi
->dmi_addr
, addr
, alen
);
162 dmi
->dmi_addrlen
=alen
;
163 dmi
->next
=dev
->mc_list
;
165 dmi
->dmi_gusers
=glbl
? 1 : 0;
180 * Discard multicast list when a device is downed
183 void dev_mc_discard(struct device
*dev
)
186 while (dev
->mc_list
!=NULL
) {
187 struct dev_mc_list
*tmp
=dev
->mc_list
;
188 dev
->mc_list
=tmp
->next
;
189 if (tmp
->dmi_users
> tmp
->dmi_gusers
)
190 printk("dev_mc_discard: multicast leakage! dmi_users=%d\n", tmp
->dmi_users
);
191 kfree_s(tmp
,sizeof(*tmp
));
197 #ifdef CONFIG_PROC_FS
198 static int dev_mc_read_proc(char *buffer
, char **start
, off_t offset
,
199 int length
, int *eof
, void *data
)
201 off_t pos
=0, begin
=0;
202 struct dev_mc_list
*m
;
208 for (dev
= dev_base
; dev
; dev
= dev
->next
) {
209 for (m
= dev
->mc_list
; m
; m
= m
->next
) {
212 len
+= sprintf(buffer
+len
,"%-4d %-15s %-5d %-5d ", dev
->ifindex
, dev
->name
,
213 m
->dmi_users
, m
->dmi_gusers
);
215 for (i
=0; i
<m
->dmi_addrlen
; i
++)
216 len
+= sprintf(buffer
+len
, "%02x", m
->dmi_addr
[i
]);
218 len
+=sprintf(buffer
+len
, "\n");
225 if (pos
> offset
+length
)
233 *start
=buffer
+(offset
-begin
);
243 __initfunc(void dev_mcast_init(void))
245 #ifdef CONFIG_PROC_FS
246 struct proc_dir_entry
*ent
;
248 ent
= create_proc_entry("net/dev_mcast", 0, 0);
249 ent
->read_proc
= dev_mc_read_proc
;