1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/*
* Linux NET3: Multicast List maintenance.
*
* Authors:
* Tim Kordas <tjk@nostromo.eeap.cwru.edu>
* Richard Underwood <richard@wuzz.demon.co.uk>
*
* Stir fried together from the IP multicast and CAP patches above
* Alan Cox <Alan.Cox@linux.org>
*
* Fixes:
* Alan Cox : Update the device on a real delete
* rather than any time but...
* Alan Cox : IFF_ALLMULTI support.
* Alan Cox : New format set_multicast_list() calls.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include <asm/uaccess.h>
#include <asm/system.h>
#include <asm/bitops.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/socket.h>
#include <linux/sockios.h>
#include <linux/in.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/if_ether.h>
#include <linux/inet.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <net/ip.h>
#include <net/route.h>
#include <linux/skbuff.h>
#include <net/sock.h>
#include <net/arp.h>
#include <linux/net_alias.h>
/*
* Device multicast list maintenance.
*
* This is used both by IP and by the user level maintenance functions.
* Unlike BSD we maintain a usage count on a given multicast address so
* that a casual user application can add/delete multicasts used by
* protocols without doing damage to the protocols when it deletes the
* entries. It also helps IP as it tracks overlapping maps.
*/
/*
* Update the multicast list into the physical NIC controller.
*/
void dev_mc_upload(struct device *dev)
{
/* Don't do anything till we up the interface
[dev_open will call this function so the list will
stay sane] */
if(!(dev->flags&IFF_UP))
return;
/*
* An aliased device should end up with the combined
* multicast list of all its aliases.
* Really, multicasting with logical interfaces is very
* subtle question. Now we DO forward multicast packets
* to logical interfcases, that doubles multicast
* traffic but allows mrouted to work.
* Alas, mrouted does not understand aliases even
* in 4.4BSD --ANK
*/
dev = net_alias_main_dev(dev);
/*
* Devices with no set multicast don't get set
*/
if(dev->set_multicast_list==NULL)
return;
dev->set_multicast_list(dev);
}
/*
* Delete a device level multicast
*/
void dev_mc_delete(struct device *dev, void *addr, int alen, int all)
{
struct dev_mc_list **dmi;
dev = net_alias_main_dev(dev);
for(dmi=&dev->mc_list;*dmi!=NULL;dmi=&(*dmi)->next)
{
/*
* Find the entry we want to delete. The device could
* have variable length entries so check these too.
*/
if(memcmp((*dmi)->dmi_addr,addr,(*dmi)->dmi_addrlen)==0 && alen==(*dmi)->dmi_addrlen)
{
struct dev_mc_list *tmp= *dmi;
if(--(*dmi)->dmi_users && !all)
return;
/*
* Last user. So delete the entry.
*/
*dmi=(*dmi)->next;
dev->mc_count--;
kfree_s(tmp,sizeof(*tmp));
/*
* We have altered the list, so the card
* loaded filter is now wrong. Fix it
*/
dev_mc_upload(dev);
return;
}
}
}
/*
* Add a device level multicast
*/
void dev_mc_add(struct device *dev, void *addr, int alen, int newonly)
{
struct dev_mc_list *dmi;
dev = net_alias_main_dev(dev);
for(dmi=dev->mc_list;dmi!=NULL;dmi=dmi->next)
{
if(memcmp(dmi->dmi_addr,addr,dmi->dmi_addrlen)==0 && dmi->dmi_addrlen==alen)
{
if(!newonly)
dmi->dmi_users++;
return;
}
}
dmi=(struct dev_mc_list *)kmalloc(sizeof(*dmi),GFP_KERNEL);
if(dmi==NULL)
return; /* GFP_KERNEL so can't happen anyway */
memcpy(dmi->dmi_addr, addr, alen);
dmi->dmi_addrlen=alen;
dmi->next=dev->mc_list;
dmi->dmi_users=1;
dev->mc_list=dmi;
dev->mc_count++;
dev_mc_upload(dev);
}
/*
* Discard multicast list when a device is downed
*/
void dev_mc_discard(struct device *dev)
{
if (net_alias_is(dev))
return;
while(dev->mc_list!=NULL)
{
struct dev_mc_list *tmp=dev->mc_list;
dev->mc_list=dev->mc_list->next;
kfree_s(tmp,sizeof(*tmp));
}
dev->mc_count=0;
}
|