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#include <net/multicast_list.h>
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/malloc.h>
41#include <net/if_dl.h>
42
43__private_extern__ void
44multicast_list_init(struct multicast_list * mc_list)
45{
46 SLIST_INIT(mc_list);
47 return;
48}
49
50
51
52
53
54
55
56__private_extern__ int
57multicast_list_remove(struct multicast_list * mc_list)
58{
59 int error;
60 struct multicast_entry * mc;
61 int result = 0;
62
63 while ((mc = SLIST_FIRST(mc_list)) != NULL) {
64 error = ifnet_remove_multicast(mc->mc_ifma);
65 if (error != 0) {
66 result = error;
67 }
68 SLIST_REMOVE_HEAD(mc_list, mc_entries);
69 ifmaddr_release(mc->mc_ifma);
70 FREE(mc, M_DEVBUF);
71 }
72 return (result);
73}
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88__private_extern__ int
89multicast_list_program(struct multicast_list * mc_list,
90 struct ifnet * source_ifp,
91 struct ifnet * target_ifp)
92{
93 int alen;
94 int error = 0;
95 int i;
96 struct multicast_entry * mc = NULL;
97 struct multicast_list new_mc_list;
98 struct sockaddr_dl source_sdl;
99 ifmultiaddr_t * source_multicast_list;
100 struct sockaddr_dl target_sdl;
101
102 alen = target_ifp->if_addrlen;
103 bzero((char *)&target_sdl, sizeof(target_sdl));
104 target_sdl.sdl_len = sizeof(target_sdl);
105 target_sdl.sdl_family = AF_LINK;
106 target_sdl.sdl_type = target_ifp->if_type;
107 target_sdl.sdl_alen = alen;
108 target_sdl.sdl_index = target_ifp->if_index;
109
110
111 multicast_list_init(&new_mc_list);
112 error = ifnet_get_multicast_list(source_ifp, &source_multicast_list);
113 if (error != 0) {
114 printf("multicast_list_program: "
115 "ifnet_get_multicast_list(%s%d) failed, %d\n",
116 source_ifp->if_name, source_ifp->if_unit, error);
117 return (error);
118 }
119 for (i = 0; source_multicast_list[i] != NULL; i++) {
120 if (ifmaddr_address(source_multicast_list[i],
121 (struct sockaddr *)&source_sdl,
122 sizeof(source_sdl)) != 0
123 || source_sdl.sdl_family != AF_LINK) {
124 continue;
125 }
126 mc = _MALLOC(sizeof(struct multicast_entry), M_DEVBUF, M_WAITOK);
127 bcopy(LLADDR(&source_sdl), LLADDR(&target_sdl), alen);
128 error = ifnet_add_multicast(target_ifp, (struct sockaddr *)&target_sdl,
129 &mc->mc_ifma);
130 if (error != 0) {
131 FREE(mc, M_DEVBUF);
132 break;
133 }
134 SLIST_INSERT_HEAD(&new_mc_list, mc, mc_entries);
135 }
136 if (error != 0) {
137
138 (void)multicast_list_remove(&new_mc_list);
139 } else {
140
141 (void)multicast_list_remove(mc_list);
142 *mc_list = new_mc_list;
143 }
144 return (error);
145}
146