2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
25 * - keep track of multicast addresses added to one interface based on the
26 * actual multicast addresses in another
27 * - used by VLAN and BOND
31 * Modification History:
33 * April 29, 2004 Dieter Siegmund (dieter@apple.com)
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>
43 __private_extern__
void
44 multicast_list_init(struct multicast_list
* mc_list
)
51 * Function: multicast_list_remove
53 * Remove the given list of multicast addresses from the interface and from
54 * the multicast list structure.
56 __private_extern__
int
57 multicast_list_remove(struct multicast_list
* mc_list
)
60 struct multicast_entry
* mc
;
63 while ((mc
= SLIST_FIRST(mc_list
)) != NULL
) {
64 error
= ifnet_remove_multicast(mc
->mc_ifma
);
68 SLIST_REMOVE_HEAD(mc_list
, mc_entries
);
69 ifmaddr_release(mc
->mc_ifma
);
76 * Function: multicast_list_program
78 * Program the multicast filter on "target_ifp" using the values from
79 * "source_ifp", and saving the result in "mc_list"
81 * We build a new list of multicast addresses while programming the new list.
82 * If that completes successfully, we remove the old list, and return the
85 * If it fails, we remove what we've added to the new list, and
88 __private_extern__
int
89 multicast_list_program(struct multicast_list
* mc_list
,
90 struct ifnet
* source_ifp
,
91 struct ifnet
* target_ifp
)
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
;
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
;
110 /* build a new list */
111 multicast_list_init(&new_mc_list
);
112 error
= ifnet_get_multicast_list(source_ifp
, &source_multicast_list
);
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
);
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
) {
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
,
134 SLIST_INSERT_HEAD(&new_mc_list
, mc
, mc_entries
);
137 /* restore previous state */
138 (void)multicast_list_remove(&new_mc_list
);
140 /* remove the old entries, and return the new list */
141 (void)multicast_list_remove(mc_list
);
142 *mc_list
= new_mc_list
;