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