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