This source file includes following definitions.
- dev_mc_upload
- dev_mc_delete
- dev_mc_add
- dev_mc_discard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include <asm/segment.h>
22 #include <asm/system.h>
23 #include <asm/bitops.h>
24 #include <linux/types.h>
25 #include <linux/kernel.h>
26 #include <linux/sched.h>
27 #include <linux/string.h>
28 #include <linux/mm.h>
29 #include <linux/socket.h>
30 #include <linux/sockios.h>
31 #include <linux/in.h>
32 #include <linux/errno.h>
33 #include <linux/interrupt.h>
34 #include <linux/if_ether.h>
35 #include <linux/inet.h>
36 #include <linux/netdevice.h>
37 #include <linux/etherdevice.h>
38 #include <net/ip.h>
39 #include <net/route.h>
40 #include <linux/skbuff.h>
41 #include <net/sock.h>
42 #include <net/arp.h>
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 void dev_mc_upload(struct device *dev)
61 {
62 struct dev_mc_list *dmi;
63 char *data, *tmp;
64
65
66
67
68
69 if(!(dev->flags&IFF_UP))
70 return;
71
72
73
74 if(dev->set_multicast_list==NULL)
75 return;
76
77 if(dev->flags&IFF_PROMISC)
78 {
79 dev->set_multicast_list(dev, -1, NULL);
80 return;
81 }
82
83 if(dev->mc_count==0)
84 {
85 dev->set_multicast_list(dev,0,NULL);
86 return;
87 }
88
89 data=kmalloc(dev->mc_count*dev->addr_len, GFP_KERNEL);
90 if(data==NULL)
91 {
92 printk("Unable to get memory to set multicast list on %s\n",dev->name);
93 return;
94 }
95 for(tmp = data, dmi=dev->mc_list;dmi!=NULL;dmi=dmi->next)
96 {
97 memcpy(tmp,dmi->dmi_addr, dmi->dmi_addrlen);
98 tmp+=dev->addr_len;
99 }
100 dev->set_multicast_list(dev,dev->mc_count,data);
101 kfree(data);
102 }
103
104
105
106
107
108 void dev_mc_delete(struct device *dev, void *addr, int alen, int all)
109 {
110 struct dev_mc_list **dmi;
111 for(dmi=&dev->mc_list;*dmi!=NULL;dmi=&(*dmi)->next)
112 {
113 if(memcmp((*dmi)->dmi_addr,addr,(*dmi)->dmi_addrlen)==0 && alen==(*dmi)->dmi_addrlen)
114 {
115 struct dev_mc_list *tmp= *dmi;
116 if(--(*dmi)->dmi_users && !all)
117 return;
118 *dmi=(*dmi)->next;
119 dev->mc_count--;
120 kfree_s(tmp,sizeof(*tmp));
121 dev_mc_upload(dev);
122 return;
123 }
124 }
125 }
126
127
128
129
130
131 void dev_mc_add(struct device *dev, void *addr, int alen, int newonly)
132 {
133 struct dev_mc_list *dmi;
134 for(dmi=dev->mc_list;dmi!=NULL;dmi=dmi->next)
135 {
136 if(memcmp(dmi->dmi_addr,addr,dmi->dmi_addrlen)==0 && dmi->dmi_addrlen==alen)
137 {
138 if(!newonly)
139 dmi->dmi_users++;
140 return;
141 }
142 }
143 dmi=(struct dev_mc_list *)kmalloc(sizeof(*dmi),GFP_KERNEL);
144 if(dmi==NULL)
145 return;
146 memcpy(dmi->dmi_addr, addr, alen);
147 dmi->dmi_addrlen=alen;
148 dmi->next=dev->mc_list;
149 dmi->dmi_users=1;
150 dev->mc_list=dmi;
151 dev->mc_count++;
152 dev_mc_upload(dev);
153 }
154
155
156
157
158
159 void dev_mc_discard(struct device *dev)
160 {
161 while(dev->mc_list!=NULL)
162 {
163 struct dev_mc_list *tmp=dev->mc_list;
164 dev->mc_list=dev->mc_list->next;
165 kfree_s(tmp,sizeof(*tmp));
166 }
167 dev->mc_count=0;
168 }
169