Make all network interrupt service routines MPSAFE part 1/3.
[dragonfly.git] / sys / net / if_fddisubr.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1995, 1996
3 * Matt Thomas <matt@3am-software.com>. All rights reserved.
4 * Copyright (c) 1982, 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * from: if_ethersubr.c,v 1.5 1994/12/13 22:31:45 wollman Exp
36 * $FreeBSD: src/sys/net/if_fddisubr.c,v 1.41.2.8 2002/02/20 23:34:09 fjoe Exp $
78195a76 37 * $DragonFly: src/sys/net/Attic/if_fddisubr.c,v 1.19 2005/11/28 17:13:45 dillon Exp $
984263bc
MD
38 */
39
40#include "opt_atalk.h"
41#include "opt_inet.h"
42#include "opt_inet6.h"
43#include "opt_ipx.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/mbuf.h>
48#include <sys/socket.h>
49#include <sys/malloc.h>
78195a76 50#include <sys/serialize.h>
984263bc
MD
51
52#include <net/if.h>
3013ac0e 53#include <net/bpf.h>
984263bc
MD
54#include <net/netisr.h>
55#include <net/route.h>
56#include <net/if_llc.h>
57#include <net/if_dl.h>
58#include <net/if_types.h>
4d723e5a 59#include <net/ifq_var.h>
984263bc
MD
60
61#if defined(INET) || defined(INET6)
62#include <netinet/in.h>
63#include <netinet/in_var.h>
64#include <netinet/if_ether.h>
c401f0fd 65#include <net/ethernet.h>
984263bc
MD
66#endif
67#ifdef INET6
68#include <netinet6/nd6.h>
69#endif
9a7f3897 70#if defined(__DragonFly__) || defined(__FreeBSD__)
984263bc
MD
71#include <netinet/if_fddi.h>
72#else
73#include <net/if_fddi.h>
74#endif
75
76#ifdef IPX
f23061d4 77#include <netproto/ipx/ipx.h>
d2438d69 78#include <netproto/ipx/ipx_if.h>
984263bc
MD
79#endif
80
81#ifdef NS
82#include <netns/ns.h>
83#include <netns/ns_if.h>
84#endif
85
86#ifdef DECNET
87#include <netdnet/dn.h>
88#endif
89
90#ifdef NETATALK
d2438d69
MD
91#include <netproto/atalk/at.h>
92#include <netproto/atalk/at_var.h>
93#include <netproto/atalk/at_extern.h>
984263bc
MD
94
95#define llc_snap_org_code llc_un.type_snap.org_code
96#define llc_snap_ether_type llc_un.type_snap.ether_type
97
98extern u_char at_org_code[ 3 ];
99extern u_char aarp_org_code[ 3 ];
100#endif /* NETATALK */
101
158abb01
RG
102static int fddi_resolvemulti (struct ifnet *, struct sockaddr **,
103 struct sockaddr *);
3013ac0e
JS
104static void fddi_input(struct ifnet *, struct mbuf *);
105static int fddi_output(struct ifnet *, struct mbuf *, struct sockaddr *,
106 struct rtentry *);
984263bc
MD
107
108#define senderr(e) { error = (e); goto bad;}
109
110/*
111 * This really should be defined in if_llc.h but in case it isn't.
112 */
113#ifndef llc_snap
114#define llc_snap llc_un.type_snap
115#endif
116
f23061d4 117#if defined(__DragonFly__)
f3ed2586 118#define RTALLOC1(a, b) _rtlookup(a, b, b ? RTL_DOCLONE : RTL_DONTCLONE)
984263bc 119#define ARPRESOLVE(a, b, c, d, e, f) arpresolve(a, b, c, d, e)
f23061d4 120#elif defined(__FreeBSD__)
984263bc
MD
121#define RTALLOC1(a, b) rtalloc1(a, b, 0UL)
122#define ARPRESOLVE(a, b, c, d, e, f) arpresolve(a, b, c, d, e, f)
123#endif
124/*
125 * FDDI output routine.
126 * Encapsulate a packet of type family for the local net.
127 * Use trailer local net encapsulation if enough data in first
128 * packet leaves a multiple of 512 bytes of data in remainder.
129 * Assumes that ifp is actually pointer to arpcom structure.
130 */
3013ac0e
JS
131static int
132fddi_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
f23061d4 133 struct rtentry *rt)
984263bc 134{
f23061d4 135 struct arpcom *ac = (struct arpcom *)ifp;
984263bc 136 u_int16_t type;
f23061d4 137 u_char esrc[6], edst[6];
82ed7fc2 138 struct fddi_header *fh;
f23061d4 139 boolean_t hdrcmplt = FALSE;
652a8770 140 int loop_copy = 0, error;
4d723e5a 141 struct altq_pktattr pktattr;
984263bc
MD
142
143 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
144 senderr(ENETDOWN);
984263bc 145
4d723e5a
JS
146 /*
147 * If the queueing discipline needs packet classification,
148 * do it before prepending link headers.
149 */
150 ifq_classify(&ifp->if_snd, m, dst->sa_family, &pktattr);
151
f23061d4 152 switch (dst->sa_family) {
984263bc
MD
153#ifdef INET
154 case AF_INET: {
f23061d4 155 if (!arpresolve(ifp, rt, m, dst, edst))
984263bc 156 return (0); /* if not yet resolved */
984263bc
MD
157 type = htons(ETHERTYPE_IP);
158 break;
159 }
160#endif
161#ifdef INET6
162 case AF_INET6:
163 if (!nd6_storelladdr(&ac->ac_if, rt, m, dst, (u_char *)edst)) {
164 /* Something bad happened */
f23061d4 165 return (0);
984263bc
MD
166 }
167 type = htons(ETHERTYPE_IPV6);
168 break;
169#endif
170#ifdef IPX
171 case AF_IPX:
172 type = htons(ETHERTYPE_IPX);
f23061d4
JH
173 bcopy(&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host), edst,
174 sizeof edst);
984263bc
MD
175 break;
176#endif
177#ifdef NETATALK
178 case AF_APPLETALK: {
f23061d4
JH
179 struct at_ifaddr *aa;
180
181 if (!aarpresolve((struct arpcom *) ifp, m,
182 (struct sockaddr_at *)dst, edst))
183 return (0);
184
185 /*
186 * ifaddr is the first thing in at_ifaddr
187 */
188 if ((aa = at_ifawithnet((struct sockaddr_at *)dst)) == NULL) {
189 error = 0; /* XXX */
190 goto bad;
191 }
192
193 /*
194 * In the phase 2 case, we need to prepend an mbuf
195 * for the llc header. Since we must preserve the
196 * value of m, which is passed to us by value, we
197 * m_copy() the first mbuf, and use it for our llc
198 * header.
199 */
200 if (aa->aa_flags & AFA_PHASE2) {
201 struct llc llc;
202
203 M_PREPEND(m, sizeof(struct llc), MB_WAIT);
204 if (m == NULL)
205 senderr(ENOBUFS);
206 llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP;
207 llc.llc_control = LLC_UI;
208 bcopy(at_org_code, llc.llc_snap_org_code,
209 sizeof at_org_code);
210 llc.llc_snap_ether_type = htons(ETHERTYPE_AT);
211 bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc));
212 type = 0;
213 } else {
214 type = htons(ETHERTYPE_AT);
215 }
216 break;
984263bc
MD
217 }
218#endif /* NETATALK */
219#ifdef NS
220 case AF_NS:
221 type = htons(ETHERTYPE_NS);
f23061d4
JH
222 bcopy(&(((struct sockaddr_ns *)dst)->sns_addr.x_host), edst,
223 sizeof edst);
984263bc
MD
224 break;
225#endif
226
227 case pseudo_AF_HDRCMPLT:
228 {
229 struct ether_header *eh;
f23061d4
JH
230
231 hdrcmplt = TRUE;
984263bc 232 eh = (struct ether_header *)dst->sa_data;
f23061d4 233 memcpy(esrc, eh->ether_shost, sizeof esrc);
984263bc
MD
234 /* FALLTHROUGH */
235 }
236
237 case AF_UNSPEC:
238 {
239 struct ether_header *eh;
f23061d4 240
984263bc
MD
241 loop_copy = -1;
242 eh = (struct ether_header *)dst->sa_data;
f23061d4 243 memcpy(edst, eh->ether_dhost, sizeof edst);
984263bc
MD
244 if (*edst & 1)
245 m->m_flags |= (M_BCAST|M_MCAST);
246 type = eh->ether_type;
247 break;
248 }
249
250 case AF_IMPLINK:
251 {
252 fh = mtod(m, struct fddi_header *);
253 error = EPROTONOSUPPORT;
254 switch (fh->fddi_fc & (FDDIFC_C|FDDIFC_L|FDDIFC_F)) {
255 case FDDIFC_LLC_ASYNC: {
256 /* legal priorities are 0 through 7 */
257 if ((fh->fddi_fc & FDDIFC_Z) > 7)
f23061d4 258 goto bad;
984263bc
MD
259 break;
260 }
261 case FDDIFC_LLC_SYNC: {
262 /* FDDIFC_Z bits reserved, must be zero */
263 if (fh->fddi_fc & FDDIFC_Z)
264 goto bad;
265 break;
266 }
267 case FDDIFC_SMT: {
268 /* FDDIFC_Z bits must be non zero */
269 if ((fh->fddi_fc & FDDIFC_Z) == 0)
270 goto bad;
271 break;
272 }
273 default: {
274 /* anything else is too dangerous */
f23061d4 275 goto bad;
984263bc
MD
276 }
277 }
278 error = 0;
279 if (fh->fddi_dhost[0] & 1)
f23061d4 280 m->m_flags |= (M_BCAST | M_MCAST);
984263bc
MD
281 goto queue_it;
282 }
283 default:
3e4a09e7 284 printf("%s: can't handle af%d\n", ifp->if_xname,
984263bc
MD
285 dst->sa_family);
286 senderr(EAFNOSUPPORT);
287 }
288
289 if (type != 0) {
82ed7fc2 290 struct llc *l;
f23061d4
JH
291
292 M_PREPEND(m, sizeof(struct llc), MB_DONTWAIT);
293 if (m == NULL)
294 return (ENOBUFS);
984263bc
MD
295 l = mtod(m, struct llc *);
296 l->llc_control = LLC_UI;
297 l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP;
f23061d4
JH
298 l->llc_snap.org_code[0] = l->llc_snap.org_code[1] =
299 l->llc_snap.org_code[2] = 0;
300 memcpy(&l->llc_snap.ether_type, &type, sizeof(u_int16_t));
984263bc
MD
301 }
302
303 /*
304 * Add local net header. If no space in first mbuf,
305 * allocate another.
306 */
f23061d4
JH
307 M_PREPEND(m, sizeof(struct fddi_header), MB_DONTWAIT);
308 if (m == NULL)
309 return (ENOBUFS);
984263bc
MD
310 fh = mtod(m, struct fddi_header *);
311 fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4;
f23061d4
JH
312 memcpy(fh->fddi_dhost, edst, sizeof edst);
313
314queue_it:
984263bc 315 if (hdrcmplt)
f23061d4 316 memcpy(fh->fddi_shost, esrc, sizeof fh->fddi_shost);
984263bc 317 else
f23061d4 318 memcpy(fh->fddi_shost, ac->ac_enaddr, sizeof fh->fddi_shost);
984263bc 319 /*
f23061d4 320 memcpy(fh->fddi_shost, ac->ac_enaddr, sizeof fh->fddi_shost);
984263bc
MD
321 * Ethernet address or a broadcast address, loopback a copy.
322 * XXX To make a simplex device behave exactly like a duplex
323 * device, we should copy in the case of sending to our own
324 * ethernet address (thus letting the original actually appear
325 * on the wire). However, we don't do that here for security
326 * reasons and compatibility with the original behavior.
327 */
328 if ((ifp->if_flags & IFF_SIMPLEX) &&
329 (loop_copy != -1)) {
330 if ((m->m_flags & M_BCAST) || loop_copy) {
f23061d4
JH
331 struct mbuf *n = m_copypacket(m, MB_DONTWAIT);
332
333 if_simloop(ifp, n, dst->sa_family,
334 sizeof(struct fddi_header));
335 } else if (bcmp(fh->fddi_dhost, fh->fddi_shost,
336 sizeof(fh->fddi_shost)) == 0) {
337 if_simloop(ifp, m, dst->sa_family,
338 sizeof(struct fddi_header));
339 senderr(0); /* XXX */
984263bc
MD
340 }
341 }
342
984263bc 343 /*
652a8770 344 * Dispatch the message to the interface.
984263bc 345 */
652a8770 346 return (ifq_handoff(ifp, m, &pktattr));
984263bc
MD
347
348bad:
0c3c561c 349 m_freem(m);
984263bc
MD
350 return (error);
351}
352
353/*
354 * Process a received FDDI packet;
355 * the packet is in the mbuf chain m without
356 * the fddi header, which is provided separately.
357 */
3013ac0e
JS
358static void
359fddi_input(struct ifnet *ifp, struct mbuf *m)
984263bc 360{
8bde602d 361 int isr;
82ed7fc2 362 struct llc *l;
3013ac0e
JS
363 struct fddi_header *fh = mtod(m, struct fddi_header *);
364
78195a76
MD
365 ASSERT_SERIALIZED(ifp->if_serializer);
366
3013ac0e
JS
367 if (m->m_len < sizeof(struct fddi_header)) {
368 /* XXX error in the caller. */
369 m_freem(m);
370 return;
371 }
372 m_adj(m, sizeof(struct fddi_header));
373 m->m_pkthdr.rcvif = ifp;
984263bc 374
0c3c561c 375 if (!(ifp->if_flags & IFF_UP)) {
984263bc
MD
376 m_freem(m);
377 return;
378 }
379 getmicrotime(&ifp->if_lastchange);
f23061d4 380 ifp->if_ibytes += m->m_pkthdr.len + sizeof *fh;
984263bc 381 if (fh->fddi_dhost[0] & 1) {
c401f0fd
JS
382 if (bcmp(ifp->if_broadcastaddr, fh->fddi_dhost,
383 ifp->if_addrlen) == 0)
984263bc
MD
384 m->m_flags |= M_BCAST;
385 else
386 m->m_flags |= M_MCAST;
387 ifp->if_imcasts++;
8bde602d 388 } else if ((ifp->if_flags & IFF_PROMISC) &&
f23061d4
JH
389 bcmp(((struct arpcom *)ifp)->ac_enaddr, fh->fddi_dhost,
390 sizeof fh->fddi_dhost) != 0) {
984263bc
MD
391 m_freem(m);
392 return;
393 }
394
395#ifdef M_LINK0
396 /*
397 * If this has a LLC priority of 0, then mark it so upper
398 * layers have a hint that it really came via a FDDI/Ethernet
399 * bridge.
400 */
401 if ((fh->fddi_fc & FDDIFC_LLC_PRIO7) == FDDIFC_LLC_PRIO0)
402 m->m_flags |= M_LINK0;
403#endif
404
405 l = mtod(m, struct llc *);
406 switch (l->llc_dsap) {
407#if defined(INET) || defined(INET6) || defined(NS) || defined(DECNET) || defined(IPX) || defined(NETATALK)
408 case LLC_SNAP_LSAP:
409 {
410 u_int16_t type;
411 if (l->llc_control != LLC_UI || l->llc_ssap != LLC_SNAP_LSAP)
412 goto dropanyway;
413#ifdef NETATALK
2e9572df 414 if (bcmp(&(l->llc_snap_org_code)[0], at_org_code,
984263bc 415 sizeof(at_org_code)) == 0 &&
8bde602d
JH
416 sizeof(at_org_code) == 0 &&
417 ntohs(l->llc_snap_ether_type) == ETHERTYPE_AT) {
418 m_adj(m, sizeof(struct llc));
419 isr = NETISR_ATALK2;
420 break;
984263bc
MD
421 }
422
2e9572df 423 if (bcmp(&(l->llc_snap_org_code)[0], aarp_org_code,
984263bc
MD
424 sizeof(aarp_org_code)) == 0 &&
425 ntohs(l->llc_snap_ether_type) == ETHERTYPE_AARP) {
f23061d4 426 m_adj(m, sizeof(struct llc));
8bde602d
JH
427 isr = NETISR_AARP;
428 break;
984263bc 429 }
2e9572df
JH
430#endif
431 if (l->llc_snap.org_code[0] != 0 ||
432 l->llc_snap.org_code[1] != 0 ||
433 l->llc_snap.org_code[2] != 0)
984263bc
MD
434 goto dropanyway;
435 type = ntohs(l->llc_snap.ether_type);
436 m_adj(m, 8);
437 switch (type) {
438#ifdef INET
439 case ETHERTYPE_IP:
440 if (ipflow_fastforward(m))
441 return;
8bde602d 442 isr = NETISR_IP;
984263bc
MD
443 break;
444
445 case ETHERTYPE_ARP:
446 if (ifp->if_flags & IFF_NOARP)
447 goto dropanyway;
8bde602d 448 isr = NETISR_ARP;
984263bc
MD
449 break;
450#endif
451#ifdef INET6
452 case ETHERTYPE_IPV6:
8bde602d 453 isr = NETISR_IPV6;
984263bc
MD
454 break;
455#endif
f23061d4
JH
456#ifdef IPX
457 case ETHERTYPE_IPX:
8bde602d 458 isr = NETISR_IPX;
f23061d4
JH
459 break;
460#endif
984263bc
MD
461#ifdef NS
462 case ETHERTYPE_NS:
8bde602d 463 isr = NETISR_NS;
984263bc
MD
464 break;
465#endif
466#ifdef DECNET
467 case ETHERTYPE_DECNET:
8bde602d 468 isr = NETISR_DECNET;
984263bc
MD
469 break;
470#endif
f23061d4 471#ifdef NETATALK
984263bc 472 case ETHERTYPE_AT:
8bde602d 473 isr = NETISR_ATALK1;
984263bc
MD
474 break;
475 case ETHERTYPE_AARP:
8bde602d
JH
476 isr = NETISR_AARP;
477 break;
984263bc
MD
478#endif /* NETATALK */
479 default:
480 /* printf("fddi_input: unknown protocol 0x%x\n", type); */
481 ifp->if_noproto++;
482 goto dropanyway;
483 }
484 break;
485 }
486#endif /* INET || NS */
f23061d4 487
984263bc
MD
488 default:
489 /* printf("fddi_input: unknown dsap 0x%x\n", l->llc_dsap); */
490 ifp->if_noproto++;
491 dropanyway:
492 m_freem(m);
493 return;
494 }
495
8bde602d 496 netisr_dispatch(isr, m);
984263bc 497}
8bde602d 498
984263bc
MD
499/*
500 * Perform common duties while attaching to interface list
501 */
502#ifdef __NetBSD__
503#define ifa_next ifa_list.tqe_next
504#endif
505
506void
78195a76 507fddi_ifattach(struct ifnet *ifp, lwkt_serialize_t serializer)
984263bc 508{
82ed7fc2 509 struct sockaddr_dl *sdl;
984263bc 510
3013ac0e
JS
511 ifp->if_input = fddi_input;
512 ifp->if_output = fddi_output;
984263bc
MD
513 ifp->if_type = IFT_FDDI;
514 ifp->if_addrlen = 6;
c401f0fd 515 ifp->if_broadcastaddr = fddibroadcastaddr;
984263bc
MD
516 ifp->if_hdrlen = 21;
517 ifp->if_mtu = FDDIMTU;
518 ifp->if_resolvemulti = fddi_resolvemulti;
519 ifp->if_baudrate = 100000000;
520#ifdef IFF_NOTRAILERS
521 ifp->if_flags |= IFF_NOTRAILERS;
522#endif
78195a76 523 if_attach(ifp, serializer);
9a7f3897 524#if defined(__DragonFly__) || defined(__FreeBSD__)
f2682cb9 525 sdl = IF_LLSOCKADDR(ifp);
984263bc
MD
526 sdl->sdl_type = IFT_FDDI;
527 sdl->sdl_alen = ifp->if_addrlen;
528 bcopy(((struct arpcom *)ifp)->ac_enaddr, LLADDR(sdl), ifp->if_addrlen);
529#elif defined(__NetBSD__)
530 LIST_INIT(&((struct arpcom *)ifp)->ac_multiaddrs);
531 for (ifa = ifp->if_addrlist.tqh_first; ifa != NULL; ifa = ifa->ifa_list.tqe_next)
532#else
533 for (ifa = ifp->if_addrlist; ifa != NULL; ifa = ifa->ifa_next)
534#endif
9a7f3897 535#if !defined(__DragonFly__) && !defined(__FreeBSD__)
984263bc
MD
536 if ((sdl = (struct sockaddr_dl *)ifa->ifa_addr) &&
537 sdl->sdl_family == AF_LINK) {
538 sdl->sdl_type = IFT_FDDI;
539 sdl->sdl_alen = ifp->if_addrlen;
f23061d4
JH
540 bcopy(((struct arpcom *)ifp)->ac_enaddr, LLADDR(sdl),
541 ifp->if_addrlen);
984263bc
MD
542 break;
543 }
544#endif
3013ac0e 545 bpfattach(ifp, DLT_FDDI, sizeof(struct fddi_header));
984263bc
MD
546}
547
548static int
549fddi_resolvemulti(ifp, llsa, sa)
550 struct ifnet *ifp;
551 struct sockaddr **llsa;
552 struct sockaddr *sa;
553{
554 struct sockaddr_dl *sdl;
555 struct sockaddr_in *sin;
556#ifdef INET6
557 struct sockaddr_in6 *sin6;
558#endif
559 u_char *e_addr;
560
561 switch(sa->sa_family) {
562 case AF_LINK:
563 /*
564 * No mapping needed. Just check that it's a valid MC address.
565 */
566 sdl = (struct sockaddr_dl *)sa;
567 e_addr = LLADDR(sdl);
568 if ((e_addr[0] & 1) != 1)
569 return EADDRNOTAVAIL;
570 *llsa = 0;
571 return 0;
572
573#ifdef INET
574 case AF_INET:
575 sin = (struct sockaddr_in *)sa;
576 if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
577 return EADDRNOTAVAIL;
578 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
579 M_WAITOK);
580 sdl->sdl_len = sizeof *sdl;
581 sdl->sdl_family = AF_LINK;
582 sdl->sdl_index = ifp->if_index;
583 sdl->sdl_type = IFT_FDDI;
584 sdl->sdl_nlen = 0;
585 sdl->sdl_alen = ETHER_ADDR_LEN; /* XXX */
586 sdl->sdl_slen = 0;
587 e_addr = LLADDR(sdl);
588 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr);
589 *llsa = (struct sockaddr *)sdl;
590 return 0;
591#endif
592#ifdef INET6
593 case AF_INET6:
594 sin6 = (struct sockaddr_in6 *)sa;
595 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
596 /*
597 * An IP6 address of 0 means listen to all
598 * of the Ethernet multicast address used for IP6.
599 * (This is used for multicast routers.)
600 */
601 ifp->if_flags |= IFF_ALLMULTI;
602 *llsa = 0;
603 return 0;
604 }
605 if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
606 return EADDRNOTAVAIL;
607 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
608 M_WAITOK);
609 sdl->sdl_len = sizeof *sdl;
610 sdl->sdl_family = AF_LINK;
611 sdl->sdl_index = ifp->if_index;
612 sdl->sdl_type = IFT_FDDI;
613 sdl->sdl_nlen = 0;
614 sdl->sdl_alen = ETHER_ADDR_LEN; /* XXX */
615 sdl->sdl_slen = 0;
616 e_addr = LLADDR(sdl);
617 ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr);
618 *llsa = (struct sockaddr *)sdl;
619 return 0;
620#endif
621
622 default:
623 /*
624 * Well, the text isn't quite right, but it's the name
625 * that counts...
626 */
627 return EAFNOSUPPORT;
628 }
629}