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