if_fddisubr.c revision 111888
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 111888 2003-03-04 23:19:55Z jlemon $
37 */
38
39#include "opt_atalk.h"
40#include "opt_inet.h"
41#include "opt_inet6.h"
42#include "opt_ipx.h"
43#include "opt_mac.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/kernel.h>
48#include <sys/mac.h>
49#include <sys/malloc.h>
50#include <sys/mbuf.h>
51#include <sys/module.h>
52#include <sys/socket.h>
53#include <sys/sockio.h>
54
55#include <net/if.h>
56#include <net/if_llc.h>
57#include <net/if_dl.h>
58#include <net/if_types.h>
59#include <net/netisr.h>
60#include <net/route.h>
61#include <net/bpf.h>
62#include <net/fddi.h>
63
64#if defined(INET) || defined(INET6)
65#include <netinet/in.h>
66#include <netinet/in_var.h>
67#include <netinet/if_ether.h>
68#endif
69#ifdef INET6
70#include <netinet6/nd6.h>
71#endif
72
73#ifdef IPX
74#include <netipx/ipx.h>
75#include <netipx/ipx_if.h>
76#endif
77
78#ifdef NS
79#include <netns/ns.h>
80#include <netns/ns_if.h>
81#endif
82
83#ifdef DECNET
84#include <netdnet/dn.h>
85#endif
86
87#ifdef NETATALK
88#include <netatalk/at.h>
89#include <netatalk/at_var.h>
90#include <netatalk/at_extern.h>
91
92extern u_char	at_org_code[ 3 ];
93extern u_char	aarp_org_code[ 3 ];
94#endif /* NETATALK */
95
96static u_char fddibroadcastaddr[FDDI_ADDR_LEN] =
97			{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
98
99static int fddi_resolvemulti(struct ifnet *, struct sockaddr **,
100			      struct sockaddr *);
101static int fddi_output(struct ifnet *, struct mbuf *, struct sockaddr *,
102		       struct rtentry *);
103static void fddi_input(struct ifnet *ifp, struct mbuf *m);
104
105
106#define	IFP2AC(IFP)	((struct arpcom *)IFP)
107#define	senderr(e)	{ error = (e); goto bad; }
108
109/*
110 * FDDI output routine.
111 * Encapsulate a packet of type family for the local net.
112 * Use trailer local net encapsulation if enough data in first
113 * packet leaves a multiple of 512 bytes of data in remainder.
114 * Assumes that ifp is actually pointer to arpcom structure.
115 */
116static int
117fddi_output(ifp, m, dst, rt0)
118	struct ifnet *ifp;
119	struct mbuf *m;
120	struct sockaddr *dst;
121	struct rtentry *rt0;
122{
123	u_int16_t type;
124	int loop_copy = 0, error = 0, hdrcmplt = 0;
125 	u_char esrc[FDDI_ADDR_LEN], edst[FDDI_ADDR_LEN];
126	struct rtentry *rt;
127	struct fddi_header *fh;
128	struct arpcom *ac = IFP2AC(ifp);
129
130#ifdef MAC
131	error = mac_check_ifnet_transmit(ifp, m);
132	if (error)
133		senderr(error);
134#endif
135
136	if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
137		senderr(ENETDOWN);
138	getmicrotime(&ifp->if_lastchange);
139
140	error = rt_check(&rt, &rt0, dst);
141	if (error)
142		goto bad;
143
144	switch (dst->sa_family) {
145
146#ifdef INET
147	case AF_INET: {
148		if (!arpresolve(ifp, rt, m, dst, edst, rt0))
149			return (0);	/* if not yet resolved */
150		type = htons(ETHERTYPE_IP);
151		break;
152	}
153#endif
154#ifdef INET6
155	case AF_INET6:
156		if (!nd6_storelladdr(ifp, rt, m, dst, (u_char *)edst)) {
157			/* Something bad happened */
158			return (0);
159		}
160		type = htons(ETHERTYPE_IPV6);
161		break;
162#endif
163#ifdef IPX
164	case AF_IPX:
165		type = htons(ETHERTYPE_IPX);
166 		bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host),
167		    (caddr_t)edst, FDDI_ADDR_LEN);
168		break;
169#endif
170#ifdef NETATALK
171	case AF_APPLETALK: {
172	    struct at_ifaddr *aa;
173            if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst))
174                return (0);
175	    /*
176	     * ifaddr is the first thing in at_ifaddr
177	     */
178	    if ((aa = at_ifawithnet( (struct sockaddr_at *)dst)) == 0)
179		goto bad;
180
181	    /*
182	     * In the phase 2 case, we need to prepend an mbuf for the llc header.
183	     * Since we must preserve the value of m, which is passed to us by
184	     * value, we m_copy() the first mbuf, and use it for our llc header.
185	     */
186	    if (aa->aa_flags & AFA_PHASE2) {
187		struct llc llc;
188
189		M_PREPEND(m, LLC_SNAPFRAMELEN, M_TRYWAIT);
190		if (m == 0)
191			senderr(ENOBUFS);
192		llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP;
193		llc.llc_control = LLC_UI;
194		bcopy(at_org_code, llc.llc_snap.org_code, sizeof(at_org_code));
195		llc.llc_snap.ether_type = htons(ETHERTYPE_AT);
196		bcopy(&llc, mtod(m, caddr_t), LLC_SNAPFRAMELEN);
197		type = 0;
198	    } else {
199		type = htons(ETHERTYPE_AT);
200	    }
201	    break;
202	}
203#endif /* NETATALK */
204#ifdef NS
205	case AF_NS:
206		type = htons(ETHERTYPE_NS);
207 		bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host),
208		    (caddr_t)edst, FDDI_ADDR_LEN);
209		break;
210#endif
211
212	case pseudo_AF_HDRCMPLT:
213	{
214		struct ether_header *eh;
215		hdrcmplt = 1;
216		eh = (struct ether_header *)dst->sa_data;
217		bcopy((caddr_t)eh->ether_shost, (caddr_t)esrc, FDDI_ADDR_LEN);
218		/* FALLTHROUGH */
219	}
220
221	case AF_UNSPEC:
222	{
223		struct ether_header *eh;
224		loop_copy = -1;
225		eh = (struct ether_header *)dst->sa_data;
226		bcopy((caddr_t)eh->ether_dhost, (caddr_t)edst, FDDI_ADDR_LEN);
227		if (*edst & 1)
228			m->m_flags |= (M_BCAST|M_MCAST);
229		type = eh->ether_type;
230		break;
231	}
232
233	case AF_IMPLINK:
234	{
235		fh = mtod(m, struct fddi_header *);
236		error = EPROTONOSUPPORT;
237		switch (fh->fddi_fc & (FDDIFC_C|FDDIFC_L|FDDIFC_F)) {
238			case FDDIFC_LLC_ASYNC: {
239				/* legal priorities are 0 through 7 */
240				if ((fh->fddi_fc & FDDIFC_Z) > 7)
241			        	goto bad;
242				break;
243			}
244			case FDDIFC_LLC_SYNC: {
245				/* FDDIFC_Z bits reserved, must be zero */
246				if (fh->fddi_fc & FDDIFC_Z)
247					goto bad;
248				break;
249			}
250			case FDDIFC_SMT: {
251				/* FDDIFC_Z bits must be non zero */
252				if ((fh->fddi_fc & FDDIFC_Z) == 0)
253					goto bad;
254				break;
255			}
256			default: {
257				/* anything else is too dangerous */
258               	 		goto bad;
259			}
260		}
261		error = 0;
262		if (fh->fddi_dhost[0] & 1)
263			m->m_flags |= (M_BCAST|M_MCAST);
264		goto queue_it;
265	}
266	default:
267		if_printf(ifp, "can't handle af%d\n", dst->sa_family);
268		senderr(EAFNOSUPPORT);
269	}
270
271	/*
272	 * Add LLC header.
273	 */
274	if (type != 0) {
275		struct llc *l;
276		M_PREPEND(m, LLC_SNAPFRAMELEN, M_DONTWAIT);
277		if (m == 0)
278			senderr(ENOBUFS);
279		l = mtod(m, struct llc *);
280		l->llc_control = LLC_UI;
281		l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP;
282		l->llc_snap.org_code[0] = l->llc_snap.org_code[1] = l->llc_snap.org_code[2] = 0;
283		bcopy((caddr_t)&type, (caddr_t)&l->llc_snap.ether_type,
284			sizeof(u_int16_t));
285	}
286
287	/*
288	 * Add local net header.  If no space in first mbuf,
289	 * allocate another.
290	 */
291	M_PREPEND(m, FDDI_HDR_LEN, M_DONTWAIT);
292	if (m == 0)
293		senderr(ENOBUFS);
294	fh = mtod(m, struct fddi_header *);
295	fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4;
296	bcopy((caddr_t)edst, (caddr_t)fh->fddi_dhost, FDDI_ADDR_LEN);
297  queue_it:
298	if (hdrcmplt)
299		bcopy((caddr_t)esrc, (caddr_t)fh->fddi_shost, FDDI_ADDR_LEN);
300	else
301		bcopy((caddr_t)ac->ac_enaddr, (caddr_t)fh->fddi_shost,
302			FDDI_ADDR_LEN);
303
304	/*
305	 * If a simplex interface, and the packet is being sent to our
306	 * Ethernet address or a broadcast address, loopback a copy.
307	 * XXX To make a simplex device behave exactly like a duplex
308	 * device, we should copy in the case of sending to our own
309	 * ethernet address (thus letting the original actually appear
310	 * on the wire). However, we don't do that here for security
311	 * reasons and compatibility with the original behavior.
312	 */
313	if ((ifp->if_flags & IFF_SIMPLEX) && (loop_copy != -1)) {
314		if ((m->m_flags & M_BCAST) || loop_copy) {
315			struct mbuf *n = m_copy(m, 0, (int)M_COPYALL);
316
317			(void) if_simloop(ifp,
318				n, dst->sa_family, FDDI_HDR_LEN);
319	     	} else if (bcmp(fh->fddi_dhost,
320		    fh->fddi_shost, FDDI_ADDR_LEN) == 0) {
321			(void) if_simloop(ifp,
322				m, dst->sa_family, FDDI_HDR_LEN);
323			return (0);	/* XXX */
324		}
325	}
326
327	if (! IF_HANDOFF(&ifp->if_snd, m, ifp))
328		senderr(ENOBUFS);
329	return (error);
330
331bad:
332	ifp->if_oerrors++;
333	if (m)
334		m_freem(m);
335	return (error);
336}
337
338/*
339 * Process a received FDDI packet;
340 * the packet is in the mbuf chain m without
341 * the fddi header, which is provided separately.
342 */
343static void
344fddi_input(ifp, m)
345	struct ifnet *ifp;
346	struct mbuf *m;
347{
348	int isr;
349	struct llc *l;
350	struct fddi_header *fh;
351
352	fh = mtod(m, struct fddi_header *);
353
354	/*
355	 * Update interface statistics.
356	 */
357	ifp->if_ibytes += m->m_pkthdr.len;
358	getmicrotime(&ifp->if_lastchange);
359
360	/*
361	 * Discard packet if interface is not up.
362	 */
363	if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
364		goto dropanyway;
365
366#ifdef MAC
367	mac_create_mbuf_from_ifnet(ifp, m);
368#endif
369
370	/*
371	 * Discard non local unicast packets when interface
372	 * is in promiscuous mode.
373	 */
374	if ((ifp->if_flags & IFF_PROMISC) && ((fh->fddi_dhost[0] & 1) == 0) &&
375	    (bcmp(IFP2AC(ifp)->ac_enaddr, (caddr_t)fh->fddi_dhost,
376	     FDDI_ADDR_LEN) != 0))
377		goto dropanyway;
378
379	/*
380	 * Set mbuf flags for bcast/mcast.
381	 */
382	if (fh->fddi_dhost[0] & 1) {
383		if (bcmp((caddr_t)ifp->if_broadcastaddr,
384			 (caddr_t)fh->fddi_dhost, FDDI_ADDR_LEN) == 0)
385			m->m_flags |= M_BCAST;
386		else
387			m->m_flags |= M_MCAST;
388		ifp->if_imcasts++;
389	}
390
391#ifdef M_LINK0
392	/*
393	 * If this has a LLC priority of 0, then mark it so upper
394	 * layers have a hint that it really came via a FDDI/Ethernet
395	 * bridge.
396	 */
397	if ((fh->fddi_fc & FDDIFC_LLC_PRIO7) == FDDIFC_LLC_PRIO0)
398		m->m_flags |= M_LINK0;
399#endif
400
401	/* Strip off FDDI header. */
402	m_adj(m, FDDI_HDR_LEN);
403
404	m = m_pullup(m, LLC_SNAPFRAMELEN);
405	if (m == 0) {
406		ifp->if_ierrors++;
407		goto dropanyway;
408	}
409	l = mtod(m, struct llc *);
410
411	switch (l->llc_dsap) {
412	case LLC_SNAP_LSAP:
413	{
414		u_int16_t type;
415		if (l->llc_control != LLC_UI || l->llc_ssap != LLC_SNAP_LSAP) {
416			ifp->if_noproto++;
417			goto dropanyway;
418		}
419#ifdef NETATALK
420		if (Bcmp(&(l->llc_snap.org_code)[0], at_org_code,
421		    sizeof(at_org_code)) == 0 &&
422		    ntohs(l->llc_snap.ether_type) == ETHERTYPE_AT) {
423			isr = NETISR_ATALK2;
424			m_adj(m, LLC_SNAPFRAMELEN);
425			break;
426		}
427
428		if (Bcmp(&(l->llc_snap.org_code)[0], aarp_org_code,
429		    sizeof(aarp_org_code)) == 0 &&
430		    ntohs(l->llc_snap.ether_type) == ETHERTYPE_AARP) {
431			m_adj(m, LLC_SNAPFRAMELEN);
432			isr = NETISR_AARP;
433			break;
434		}
435#endif /* NETATALK */
436		if (l->llc_snap.org_code[0] != 0 ||
437		    l->llc_snap.org_code[1] != 0 ||
438		    l->llc_snap.org_code[2] != 0) {
439			ifp->if_noproto++;
440			goto dropanyway;
441		}
442
443		type = ntohs(l->llc_snap.ether_type);
444		m_adj(m, LLC_SNAPFRAMELEN);
445
446		switch (type) {
447#ifdef INET
448		case ETHERTYPE_IP:
449			if (ipflow_fastforward(m))
450				return;
451			isr = NETISR_IP;
452			break;
453
454		case ETHERTYPE_ARP:
455			if (ifp->if_flags & IFF_NOARP)
456				goto dropanyway;
457			isr = NETISR_ARP;
458			break;
459#endif
460#ifdef INET6
461		case ETHERTYPE_IPV6:
462			isr = NETISR_IPV6;
463			break;
464#endif
465#ifdef IPX
466		case ETHERTYPE_IPX:
467			isr = NETISR_IPX;
468			break;
469#endif
470#ifdef NS
471		case ETHERTYPE_NS:
472			isr = NETISR_NS;
473			break;
474#endif
475#ifdef DECNET
476		case ETHERTYPE_DECNET:
477			isr = NETISR_DECNET;
478			break;
479#endif
480#ifdef NETATALK
481		case ETHERTYPE_AT:
482	                isr = NETISR_ATALK1;
483			break;
484	        case ETHERTYPE_AARP:
485			isr = NETISR_AARP;
486			break;
487#endif /* NETATALK */
488		default:
489			/* printf("fddi_input: unknown protocol 0x%x\n", type); */
490			ifp->if_noproto++;
491			goto dropanyway;
492		}
493		break;
494	}
495
496	default:
497		/* printf("fddi_input: unknown dsap 0x%x\n", l->llc_dsap); */
498		ifp->if_noproto++;
499		goto dropanyway;
500	}
501	netisr_dispatch(isr, m);
502	return;
503
504dropanyway:
505	ifp->if_iqdrops++;
506	if (m)
507		m_freem(m);
508	return;
509}
510
511/*
512 * Perform common duties while attaching to interface list
513 */
514void
515fddi_ifattach(ifp, bpf)
516	struct ifnet *ifp;
517	int bpf;
518{
519	struct ifaddr *ifa;
520	struct sockaddr_dl *sdl;
521
522	ifp->if_type = IFT_FDDI;
523	ifp->if_addrlen = FDDI_ADDR_LEN;
524	ifp->if_hdrlen = 21;
525
526	if_attach(ifp);         /* Must be called before additional assignments */
527
528	ifp->if_mtu = FDDIMTU;
529	ifp->if_output = fddi_output;
530	ifp->if_input = fddi_input;
531	ifp->if_resolvemulti = fddi_resolvemulti;
532	ifp->if_broadcastaddr = fddibroadcastaddr;
533	ifp->if_baudrate = 100000000;
534#ifdef IFF_NOTRAILERS
535	ifp->if_flags |= IFF_NOTRAILERS;
536#endif
537	ifa = ifaddr_byindex(ifp->if_index);
538	if (ifa == NULL) {
539		printf("%s(): no lladdr for %s%d!\n", __FUNCTION__,
540		       ifp->if_name, ifp->if_unit);
541		return;
542	}
543
544	sdl = (struct sockaddr_dl *)ifa->ifa_addr;
545	sdl->sdl_type = IFT_FDDI;
546	sdl->sdl_alen = ifp->if_addrlen;
547	bcopy(IFP2AC(ifp)->ac_enaddr, LLADDR(sdl), ifp->if_addrlen);
548
549	if (bpf)
550		bpfattach(ifp, DLT_FDDI, FDDI_HDR_LEN);
551
552	return;
553}
554
555void
556fddi_ifdetach(ifp, bpf)
557	struct ifnet *ifp;
558	int bpf;
559{
560
561	if (bpf)
562		bpfdetach(ifp);
563
564	if_detach(ifp);
565
566	return;
567}
568
569int
570fddi_ioctl (ifp, command, data)
571	struct ifnet *ifp;
572	int command;
573	caddr_t data;
574{
575	struct ifaddr *ifa;
576	struct ifreq *ifr;
577	int error;
578
579	ifa = (struct ifaddr *) data;
580	ifr = (struct ifreq *) data;
581	error = 0;
582
583	switch (command) {
584	case SIOCSIFADDR:
585		ifp->if_flags |= IFF_UP;
586
587		switch (ifa->ifa_addr->sa_family) {
588#ifdef INET
589		case AF_INET:	/* before arpwhohas */
590			ifp->if_init(ifp->if_softc);
591			arp_ifinit(ifp, ifa);
592			break;
593#endif
594#ifdef IPX
595		/*
596		 * XXX - This code is probably wrong
597		 */
598		case AF_IPX: {
599				struct ipx_addr *ina;
600				struct arpcom *ac;
601
602				ina = &(IA_SIPX(ifa)->sipx_addr);
603				ac = IFP2AC(ifp);
604
605				if (ipx_nullhost(*ina)) {
606					ina->x_host = *(union ipx_host *)
607							ac->ac_enaddr;
608				} else {
609					bcopy((caddr_t) ina->x_host.c_host,
610					      (caddr_t) ac->ac_enaddr,
611					      sizeof(ac->ac_enaddr));
612				}
613
614				/*
615				 * Set new address
616				 */
617				ifp->if_init(ifp->if_softc);
618			}
619			break;
620#endif
621		default:
622			ifp->if_init(ifp->if_softc);
623			break;
624		}
625	case SIOCGIFADDR: {
626			struct sockaddr *sa;
627
628			sa = (struct sockaddr *) & ifr->ifr_data;
629			bcopy(IFP2AC(ifp)->ac_enaddr,
630			      (caddr_t) sa->sa_data, FDDI_ADDR_LEN);
631
632		}
633		break;
634	case SIOCSIFMTU:
635		/*
636		 * Set the interface MTU.
637		 */
638		if (ifr->ifr_mtu > FDDIMTU) {
639			error = EINVAL;
640		} else {
641			ifp->if_mtu = ifr->ifr_mtu;
642		}
643		break;
644	default:
645		break;
646	}
647
648	return (error);
649}
650
651static int
652fddi_resolvemulti(ifp, llsa, sa)
653	struct ifnet *ifp;
654	struct sockaddr **llsa;
655	struct sockaddr *sa;
656{
657	struct sockaddr_dl *sdl;
658	struct sockaddr_in *sin;
659#ifdef INET6
660	struct sockaddr_in6 *sin6;
661#endif
662	u_char *e_addr;
663
664	switch(sa->sa_family) {
665	case AF_LINK:
666		/*
667		 * No mapping needed. Just check that it's a valid MC address.
668		 */
669		sdl = (struct sockaddr_dl *)sa;
670		e_addr = LLADDR(sdl);
671		if ((e_addr[0] & 1) != 1)
672			return (EADDRNOTAVAIL);
673		*llsa = 0;
674		return (0);
675
676#ifdef INET
677	case AF_INET:
678		sin = (struct sockaddr_in *)sa;
679		if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
680			return (EADDRNOTAVAIL);
681		MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
682		       M_WAITOK);
683		sdl->sdl_len = sizeof *sdl;
684		sdl->sdl_family = AF_LINK;
685		sdl->sdl_index = ifp->if_index;
686		sdl->sdl_type = IFT_FDDI;
687		sdl->sdl_nlen = 0;
688		sdl->sdl_alen = FDDI_ADDR_LEN;
689		sdl->sdl_slen = 0;
690		e_addr = LLADDR(sdl);
691		ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr);
692		*llsa = (struct sockaddr *)sdl;
693		return (0);
694#endif
695#ifdef INET6
696	case AF_INET6:
697		sin6 = (struct sockaddr_in6 *)sa;
698		if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
699			/*
700			 * An IP6 address of 0 means listen to all
701			 * of the Ethernet multicast address used for IP6.
702			 * (This is used for multicast routers.)
703			 */
704			ifp->if_flags |= IFF_ALLMULTI;
705			*llsa = 0;
706			return (0);
707		}
708		if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
709			return (EADDRNOTAVAIL);
710		MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
711		       M_WAITOK);
712		sdl->sdl_len = sizeof *sdl;
713		sdl->sdl_family = AF_LINK;
714		sdl->sdl_index = ifp->if_index;
715		sdl->sdl_type = IFT_FDDI;
716		sdl->sdl_nlen = 0;
717		sdl->sdl_alen = FDDI_ADDR_LEN;
718		sdl->sdl_slen = 0;
719		e_addr = LLADDR(sdl);
720		ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr);
721		*llsa = (struct sockaddr *)sdl;
722		return (0);
723#endif
724
725	default:
726		/*
727		 * Well, the text isn't quite right, but it's the name
728		 * that counts...
729		 */
730		return (EAFNOSUPPORT);
731	}
732
733	return (0);
734}
735
736static moduledata_t fddi_mod = {
737	"fddi",	/* module name */
738	NULL,	/* event handler */
739	0	/* extra data */
740};
741
742DECLARE_MODULE(fddi, fddi_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
743MODULE_VERSION(fddi, 1);
744