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