if_fddisubr.c revision 36265
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 * $Id: if_fddisubr.c,v 1.29 1998/05/20 14:08:43 dufault Exp $
37 */
38
39#include "opt_atalk.h"
40#include "opt_inet.h"
41#include "opt_ipx.h"
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/kernel.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#ifdef INET
57#include <netinet/in.h>
58#include <netinet/in_var.h>
59#include <netinet/if_ether.h>
60#endif
61#if defined(__FreeBSD__)
62#include <netinet/if_fddi.h>
63#else
64#include <net/if_fddi.h>
65#endif
66
67#ifdef IPX
68#include <netipx/ipx.h>
69#include <netipx/ipx_if.h>
70#endif
71
72#ifdef NS
73#include <netns/ns.h>
74#include <netns/ns_if.h>
75#endif
76
77#ifdef DECNET
78#include <netdnet/dn.h>
79#endif
80
81#ifdef ISO
82#include <netiso/argo_debug.h>
83#include <netiso/iso.h>
84#include <netiso/iso_var.h>
85#include <netiso/iso_snpac.h>
86#endif
87
88#ifdef LLC
89#include <netccitt/dll.h>
90#include <netccitt/llc_var.h>
91#endif
92
93#ifdef NETATALK
94#include <netatalk/at.h>
95#include <netatalk/at_var.h>
96#include <netatalk/at_extern.h>
97
98#define llc_snap_org_code llc_un.type_snap.org_code
99#define llc_snap_ether_type llc_un.type_snap.ether_type
100
101extern u_char	at_org_code[ 3 ];
102extern u_char	aarp_org_code[ 3 ];
103#endif /* NETATALK */
104
105#if defined(LLC) && defined(CCITT)
106extern struct ifqueue pkintrq;
107#endif
108
109#include "bpfilter.h"
110
111#define senderr(e) { error = (e); goto bad;}
112
113/*
114 * This really should be defined in if_llc.h but in case it isn't.
115 */
116#ifndef llc_snap
117#define	llc_snap	llc_un.type_snap
118#endif
119
120#if defined(__bsdi__) || defined(__NetBSD__)
121#define	RTALLOC1(a, b)			rtalloc1(a, b)
122#define	ARPRESOLVE(a, b, c, d, e, f)	arpresolve(a, b, c, d, e)
123#elif defined(__FreeBSD__)
124#define	RTALLOC1(a, b)			rtalloc1(a, b, 0UL)
125#define	ARPRESOLVE(a, b, c, d, e, f)	arpresolve(a, b, c, d, e, f)
126#endif
127/*
128 * FDDI output routine.
129 * Encapsulate a packet of type family for the local net.
130 * Use trailer local net encapsulation if enough data in first
131 * packet leaves a multiple of 512 bytes of data in remainder.
132 * Assumes that ifp is actually pointer to arpcom structure.
133 */
134int
135fddi_output(ifp, m0, dst, rt0)
136	register struct ifnet *ifp;
137	struct mbuf *m0;
138	struct sockaddr *dst;
139	struct rtentry *rt0;
140{
141	u_int16_t type;
142	int s, error = 0;
143 	u_char edst[6];
144	register struct mbuf *m = m0;
145	register struct rtentry *rt;
146	register struct fddi_header *fh;
147	struct mbuf *mcopy = (struct mbuf *)0;
148	struct arpcom *ac = (struct arpcom *)ifp;
149
150	if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
151		senderr(ENETDOWN);
152	getmicrotime(&ifp->if_lastchange);
153#if !defined(__bsdi__) || _BSDI_VERSION >= 199401
154	if (rt = rt0) {
155		if ((rt->rt_flags & RTF_UP) == 0) {
156			if (rt0 = rt = RTALLOC1(dst, 1))
157				rt->rt_refcnt--;
158			else
159				senderr(EHOSTUNREACH);
160		}
161		if (rt->rt_flags & RTF_GATEWAY) {
162			if (rt->rt_gwroute == 0)
163				goto lookup;
164			if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) {
165				rtfree(rt); rt = rt0;
166			lookup: rt->rt_gwroute = RTALLOC1(rt->rt_gateway, 1);
167				if ((rt = rt->rt_gwroute) == 0)
168					senderr(EHOSTUNREACH);
169			}
170		}
171		if (rt->rt_flags & RTF_REJECT)
172			if (rt->rt_rmx.rmx_expire == 0 ||
173			    time_second < rt->rt_rmx.rmx_expire)
174				senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH);
175	}
176#endif
177	switch (dst->sa_family) {
178
179#ifdef INET
180	case AF_INET: {
181#if !defined(__bsdi__) || _BSDI_VERSION >= 199401
182		if (!ARPRESOLVE(ac, rt, m, dst, edst, rt0))
183			return (0);	/* if not yet resolved */
184#else
185		int usetrailers;
186		if (!arpresolve(ac, m, &((struct sockaddr_in *)dst)->sin_addr, edst, &usetrailers))
187			return (0);	/* if not yet resolved */
188#endif
189		/* If broadcasting on a simplex interface, loopback a copy */
190		if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
191			mcopy = m_copy(m, 0, (int)M_COPYALL);
192		type = htons(ETHERTYPE_IP);
193		break;
194	}
195#endif
196#ifdef IPX
197	case AF_IPX:
198		{
199		struct ifaddr *ia;
200
201		type = htons(ETHERTYPE_IPX);
202 		bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host),
203		    (caddr_t)edst, sizeof (edst));
204
205		for(ia = ifp->if_addrhead.tqh_first; ia != 0;
206		    ia = ia->ifa_link.tqe_next) {
207			if(ia->ifa_addr->sa_family == AF_IPX &&
208			   !bcmp((caddr_t)edst,
209				 (caddr_t)&((struct ipx_ifaddr *)ia)->ia_addr.sipx_addr.x_host,
210				 sizeof(edst)) )
211				return (looutput(ifp, m, dst, rt));
212		}
213
214		/* If broadcasting on a simplex interface, loopback a copy */
215		if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
216			mcopy = m_copy(m, 0, (int)M_COPYALL);
217		break;
218		}
219#endif
220#ifdef NETATALK
221	case AF_APPLETALK: {
222	    struct at_ifaddr *aa;
223            if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) {
224#ifdef NETATALKDEBUG
225                extern char *prsockaddr(struct sockaddr *);
226                printf("aarpresolv: failed for %s\n", prsockaddr(dst));
227#endif
228                return (0);
229            }
230	    /*
231	     * ifaddr is the first thing in at_ifaddr
232	     */
233	    if ((aa = at_ifawithnet( (struct sockaddr_at *)dst)) == 0)
234		goto bad;
235
236	    /*
237	     * In the phase 2 case, we need to prepend an mbuf for the llc header.
238	     * Since we must preserve the value of m, which is passed to us by
239	     * value, we m_copy() the first mbuf, and use it for our llc header.
240	     */
241	    if (aa->aa_flags & AFA_PHASE2) {
242		struct llc llc;
243
244		M_PREPEND(m, sizeof(struct llc), M_WAIT);
245		if (m == 0)
246			senderr(ENOBUFS);
247		llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP;
248		llc.llc_control = LLC_UI;
249		bcopy(at_org_code, llc.llc_snap_org_code, sizeof(at_org_code));
250		llc.llc_snap_ether_type = htons(ETHERTYPE_AT);
251		bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc));
252		type = 0;
253	    } else {
254		type = htons(ETHERTYPE_AT);
255	    }
256	    break;
257	}
258#endif /* NETATALK */
259#ifdef NS
260	case AF_NS:
261		type = htons(ETHERTYPE_NS);
262 		bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host),
263		    (caddr_t)edst, sizeof (edst));
264		if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost, sizeof(edst)))
265			return (looutput(ifp, m, dst, rt));
266		/* If broadcasting on a simplex interface, loopback a copy */
267		if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
268			mcopy = m_copy(m, 0, (int)M_COPYALL);
269		break;
270#endif
271#ifdef	ISO
272	case AF_ISO: {
273		int	snpalen;
274		struct	llc *l;
275		register struct sockaddr_dl *sdl;
276
277		if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) &&
278		    sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) {
279			bcopy(LLADDR(sdl), (caddr_t)edst, sizeof(edst));
280		} else if (error =
281			    iso_snparesolve(ifp, (struct sockaddr_iso *)dst,
282					    (char *)edst, &snpalen))
283			goto bad; /* Not Resolved */
284		/* If broadcasting on a simplex interface, loopback a copy */
285		if (*edst & 1)
286			m->m_flags |= (M_BCAST|M_MCAST);
287		if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX) &&
288		    (mcopy = m_copy(m, 0, (int)M_COPYALL))) {
289			M_PREPEND(mcopy, sizeof (*fh), M_DONTWAIT);
290			if (mcopy) {
291				fh = mtod(mcopy, struct fddi_header *);
292				bcopy((caddr_t)edst,
293				      (caddr_t)fh->fddi_dhost, sizeof (edst));
294				bcopy((caddr_t)ac->ac_enaddr,
295				      (caddr_t)fh->fddi_shost, sizeof (edst));
296			}
297		}
298		M_PREPEND(m, 3, M_DONTWAIT);
299		if (m == NULL)
300			return (0);
301		type = 0;
302		l = mtod(m, struct llc *);
303		l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP;
304		l->llc_control = LLC_UI;
305		IFDEBUG(D_ETHER)
306			int i;
307			printf("unoutput: sending pkt to: ");
308			for (i=0; i<6; i++)
309				printf("%x ", edst[i] & 0xff);
310			printf("\n");
311		ENDDEBUG
312		} break;
313#endif /* ISO */
314#ifdef	LLC
315/*	case AF_NSAP: */
316	case AF_CCITT: {
317		register struct sockaddr_dl *sdl =
318			(struct sockaddr_dl *) rt -> rt_gateway;
319
320		if (sdl && sdl->sdl_family != AF_LINK && sdl->sdl_alen <= 0)
321			goto bad; /* Not a link interface ? Funny ... */
322		bcopy(LLADDR(sdl), (char *)edst, sizeof(edst));
323		if ((ifp->if_flags & IFF_SIMPLEX) && (*edst & 1) &&
324		    (mcopy = m_copy(m, 0, (int)M_COPYALL))) {
325			M_PREPEND(mcopy, sizeof (*fh), M_DONTWAIT);
326			if (mcopy) {
327				fh = mtod(mcopy, struct fddi_header *);
328				bcopy((caddr_t)edst,
329				      (caddr_t)fh->fddi_dhost, sizeof (edst));
330				bcopy((caddr_t)ac->ac_enaddr,
331				      (caddr_t)fh->fddi_shost, sizeof (edst));
332				fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4;
333			}
334		}
335		type = 0;
336#ifdef LLC_DEBUG
337		{
338			int i;
339			register struct llc *l = mtod(m, struct llc *);
340
341			printf("fddi_output: sending LLC2 pkt to: ");
342			for (i=0; i<6; i++)
343				printf("%x ", edst[i] & 0xff);
344			printf(" len 0x%x dsap 0x%x ssap 0x%x control 0x%x\n",
345			       type & 0xff, l->llc_dsap & 0xff, l->llc_ssap &0xff,
346			       l->llc_control & 0xff);
347
348		}
349#endif /* LLC_DEBUG */
350		} break;
351#endif /* LLC */
352
353	case AF_UNSPEC:
354	{
355		struct ether_header *eh;
356		eh = (struct ether_header *)dst->sa_data;
357 		(void)memcpy((caddr_t)edst, (caddr_t)eh->ether_dhost, sizeof (edst));
358		if (*edst & 1)
359			m->m_flags |= (M_BCAST|M_MCAST);
360		type = eh->ether_type;
361		break;
362	}
363
364#if NBPFILTER > 0
365	case AF_IMPLINK:
366	{
367		fh = mtod(m, struct fddi_header *);
368		error = EPROTONOSUPPORT;
369		switch (fh->fddi_fc & (FDDIFC_C|FDDIFC_L|FDDIFC_F)) {
370			case FDDIFC_LLC_ASYNC: {
371				/* legal priorities are 0 through 7 */
372				if ((fh->fddi_fc & FDDIFC_Z) > 7)
373			        	goto bad;
374				break;
375			}
376			case FDDIFC_LLC_SYNC: {
377				/* FDDIFC_Z bits reserved, must be zero */
378				if (fh->fddi_fc & FDDIFC_Z)
379					goto bad;
380				break;
381			}
382			case FDDIFC_SMT: {
383				/* FDDIFC_Z bits must be non zero */
384				if ((fh->fddi_fc & FDDIFC_Z) == 0)
385					goto bad;
386				break;
387			}
388			default: {
389				/* anything else is too dangerous */
390               	 		goto bad;
391			}
392		}
393		error = 0;
394		if (fh->fddi_dhost[0] & 1)
395			m->m_flags |= (M_BCAST|M_MCAST);
396		goto queue_it;
397	}
398#endif
399	default:
400		printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit,
401			dst->sa_family);
402		senderr(EAFNOSUPPORT);
403	}
404
405
406	if (mcopy)
407		(void) looutput(ifp, mcopy, dst, rt);
408	if (type != 0) {
409		register struct llc *l;
410		M_PREPEND(m, sizeof (struct llc), M_DONTWAIT);
411		if (m == 0)
412			senderr(ENOBUFS);
413		l = mtod(m, struct llc *);
414		l->llc_control = LLC_UI;
415		l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP;
416		l->llc_snap.org_code[0] = l->llc_snap.org_code[1] = l->llc_snap.org_code[2] = 0;
417		(void)memcpy((caddr_t) &l->llc_snap.ether_type, (caddr_t) &type,
418			sizeof(u_int16_t));
419	}
420	/*
421	 * Add local net header.  If no space in first mbuf,
422	 * allocate another.
423	 */
424	M_PREPEND(m, sizeof (struct fddi_header), M_DONTWAIT);
425	if (m == 0)
426		senderr(ENOBUFS);
427	fh = mtod(m, struct fddi_header *);
428	fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4;
429 	(void)memcpy((caddr_t)fh->fddi_dhost, (caddr_t)edst, sizeof (edst));
430  queue_it:
431 	(void)memcpy((caddr_t)fh->fddi_shost, (caddr_t)ac->ac_enaddr,
432	    sizeof(fh->fddi_shost));
433	s = splimp();
434	/*
435	 * Queue message on interface, and start output if interface
436	 * not yet active.
437	 */
438	if (IF_QFULL(&ifp->if_snd)) {
439		IF_DROP(&ifp->if_snd);
440		splx(s);
441		senderr(ENOBUFS);
442	}
443	ifp->if_obytes += m->m_pkthdr.len;
444	IF_ENQUEUE(&ifp->if_snd, m);
445	if ((ifp->if_flags & IFF_OACTIVE) == 0)
446		(*ifp->if_start)(ifp);
447	splx(s);
448	if (m->m_flags & M_MCAST)
449		ifp->if_omcasts++;
450	return (error);
451
452bad:
453	if (m)
454		m_freem(m);
455	return (error);
456}
457
458/*
459 * Process a received FDDI packet;
460 * the packet is in the mbuf chain m without
461 * the fddi header, which is provided separately.
462 */
463void
464fddi_input(ifp, fh, m)
465	struct ifnet *ifp;
466	register struct fddi_header *fh;
467	struct mbuf *m;
468{
469	register struct ifqueue *inq;
470	register struct llc *l;
471	int s;
472
473	if ((ifp->if_flags & IFF_UP) == 0) {
474		m_freem(m);
475		return;
476	}
477	getmicrotime(&ifp->if_lastchange);
478	ifp->if_ibytes += m->m_pkthdr.len + sizeof (*fh);
479	if (fh->fddi_dhost[0] & 1) {
480		if (bcmp((caddr_t)fddibroadcastaddr, (caddr_t)fh->fddi_dhost,
481		    sizeof(fddibroadcastaddr)) == 0)
482			m->m_flags |= M_BCAST;
483		else
484			m->m_flags |= M_MCAST;
485		ifp->if_imcasts++;
486	} else if ((ifp->if_flags & IFF_PROMISC)
487	    && bcmp(((struct arpcom *)ifp)->ac_enaddr, (caddr_t)fh->fddi_dhost,
488		    sizeof(fh->fddi_dhost)) != 0) {
489		m_freem(m);
490		return;
491	}
492
493#ifdef M_LINK0
494	/*
495	 * If this has a LLC priority of 0, then mark it so upper
496	 * layers have a hint that it really came via a FDDI/Ethernet
497	 * bridge.
498	 */
499	if ((fh->fddi_fc & FDDIFC_LLC_PRIO7) == FDDIFC_LLC_PRIO0)
500		m->m_flags |= M_LINK0;
501#endif
502
503	l = mtod(m, struct llc *);
504	switch (l->llc_dsap) {
505#if defined(INET) || defined(NS) || defined(DECNET) || defined(IPX) || defined(NETATALK)
506	case LLC_SNAP_LSAP:
507	{
508		u_int16_t type;
509		if (l->llc_control != LLC_UI || l->llc_ssap != LLC_SNAP_LSAP)
510			goto dropanyway;
511#ifdef NETATALK
512		if (Bcmp(&(l->llc_snap_org_code)[0], at_org_code,
513			 sizeof(at_org_code)) == 0 &&
514		 	ntohs(l->llc_snap_ether_type) == ETHERTYPE_AT) {
515		    inq = &atintrq2;
516		    m_adj( m, sizeof( struct llc ));
517		    schednetisr(NETISR_ATALK);
518		    break;
519		}
520
521		if (Bcmp(&(l->llc_snap_org_code)[0], aarp_org_code,
522			 sizeof(aarp_org_code)) == 0 &&
523			ntohs(l->llc_snap_ether_type) == ETHERTYPE_AARP) {
524		    m_adj( m, sizeof( struct llc ));
525		    aarpinput((struct arpcom *)ifp, m); /* XXX */
526		    return;
527		}
528#endif /* NETATALK */
529		if (l->llc_snap.org_code[0] != 0 || l->llc_snap.org_code[1] != 0|| l->llc_snap.org_code[2] != 0)
530			goto dropanyway;
531		type = ntohs(l->llc_snap.ether_type);
532		m_adj(m, 8);
533		switch (type) {
534#ifdef INET
535		case ETHERTYPE_IP:
536			if (ipflow_fastforward(m))
537				return;
538			schednetisr(NETISR_IP);
539			inq = &ipintrq;
540			break;
541
542		case ETHERTYPE_ARP:
543#if !defined(__bsdi__) || _BSDI_VERSION >= 199401
544			schednetisr(NETISR_ARP);
545			inq = &arpintrq;
546			break;
547#else
548			arpinput((struct arpcom *)ifp, m);
549			return;
550#endif
551#endif
552#ifdef IPX
553		case ETHERTYPE_IPX:
554			schednetisr(NETISR_IPX);
555			inq = &ipxintrq;
556			break;
557#endif
558#ifdef NS
559		case ETHERTYPE_NS:
560			schednetisr(NETISR_NS);
561			inq = &nsintrq;
562			break;
563#endif
564#ifdef DECNET
565		case ETHERTYPE_DECNET:
566			schednetisr(NETISR_DECNET);
567			inq = &decnetintrq;
568			break;
569#endif
570#ifdef NETATALK
571		case ETHERTYPE_AT:
572	                schednetisr(NETISR_ATALK);
573			inq = &atintrq1;
574			break;
575	        case ETHERTYPE_AARP:
576			/* probably this should be done with a NETISR as well */
577			aarpinput((struct arpcom *)ifp, m); /* XXX */
578			return;
579#endif /* NETATALK */
580		default:
581			/* printf("fddi_input: unknown protocol 0x%x\n", type); */
582			ifp->if_noproto++;
583			goto dropanyway;
584		}
585		break;
586	}
587#endif /* INET || NS */
588#ifdef	ISO
589	case LLC_ISO_LSAP:
590		switch (l->llc_control) {
591		case LLC_UI:
592			/* LLC_UI_P forbidden in class 1 service */
593			if ((l->llc_dsap == LLC_ISO_LSAP) &&
594			    (l->llc_ssap == LLC_ISO_LSAP)) {
595				/* LSAP for ISO */
596				m->m_data += 3;		/* XXX */
597				m->m_len -= 3;		/* XXX */
598				m->m_pkthdr.len -= 3;	/* XXX */
599				M_PREPEND(m, sizeof *fh, M_DONTWAIT);
600				if (m == 0)
601					return;
602				*mtod(m, struct fddi_header *) = *fh;
603				IFDEBUG(D_ETHER)
604					printf("clnp packet");
605				ENDDEBUG
606				schednetisr(NETISR_ISO);
607				inq = &clnlintrq;
608				break;
609			}
610			goto dropanyway;
611
612		case LLC_XID:
613		case LLC_XID_P:
614			if(m->m_len < 6)
615				goto dropanyway;
616			l->llc_window = 0;
617			l->llc_fid = 9;
618			l->llc_class = 1;
619			l->llc_dsap = l->llc_ssap = 0;
620			/* Fall through to */
621		case LLC_TEST:
622		case LLC_TEST_P:
623		{
624			struct sockaddr sa;
625			register struct ether_header *eh;
626			struct arpcom *ac = (struct arpcom *) ifp;
627			int i;
628			u_char c = l->llc_dsap;
629
630			l->llc_dsap = l->llc_ssap;
631			l->llc_ssap = c;
632			if (m->m_flags & (M_BCAST | M_MCAST))
633				bcopy((caddr_t)ac->ac_enaddr,
634				      (caddr_t)eh->ether_dhost, 6);
635			sa.sa_family = AF_UNSPEC;
636			sa.sa_len = sizeof(sa);
637			eh = (struct ether_header *)sa.sa_data;
638			for (i = 0; i < 6; i++) {
639				eh->ether_shost[i] = fh->fddi_dhost[i];
640				eh->ether_dhost[i] = fh->fddi_shost[i];
641			}
642			eh->ether_type = 0;
643			ifp->if_output(ifp, m, &sa, NULL);
644			return;
645		}
646		default:
647			m_freem(m);
648			return;
649		}
650		break;
651#endif /* ISO */
652#ifdef LLC
653	case LLC_X25_LSAP:
654	{
655		M_PREPEND(m, sizeof(struct sdl_hdr) , M_DONTWAIT);
656		if (m == 0)
657			return;
658		if ( !sdl_sethdrif(ifp, fh->fddi_shost, LLC_X25_LSAP,
659				    fh->fddi_dhost, LLC_X25_LSAP, 6,
660				    mtod(m, struct sdl_hdr *)))
661			panic("ETHER cons addr failure");
662		mtod(m, struct sdl_hdr *)->sdlhdr_len = m->m_pkthdr.len - sizeof(struct sdl_hdr);
663#ifdef LLC_DEBUG
664		printf("llc packet\n");
665#endif /* LLC_DEBUG */
666		schednetisr(NETISR_CCITT);
667		inq = &llcintrq;
668		break;
669	}
670#endif /* LLC */
671
672	default:
673		/* printf("fddi_input: unknown dsap 0x%x\n", l->llc_dsap); */
674		ifp->if_noproto++;
675	dropanyway:
676		m_freem(m);
677		return;
678	}
679
680	s = splimp();
681	if (IF_QFULL(inq)) {
682		IF_DROP(inq);
683		m_freem(m);
684	} else
685		IF_ENQUEUE(inq, m);
686	splx(s);
687}
688/*
689 * Perform common duties while attaching to interface list
690 */
691#ifdef __NetBSD__
692#define	ifa_next	ifa_list.tqe_next
693#endif
694
695void
696fddi_ifattach(ifp)
697	register struct ifnet *ifp;
698{
699	register struct ifaddr *ifa;
700	register struct sockaddr_dl *sdl;
701
702	ifp->if_type = IFT_FDDI;
703	ifp->if_addrlen = 6;
704	ifp->if_hdrlen = 21;
705	ifp->if_mtu = FDDIMTU;
706	ifp->if_baudrate = 100000000;
707#ifdef IFF_NOTRAILERS
708	ifp->if_flags |= IFF_NOTRAILERS;
709#endif
710#if defined(__FreeBSD__)
711	ifa = ifnet_addrs[ifp->if_index - 1];
712	sdl = (struct sockaddr_dl *)ifa->ifa_addr;
713	sdl->sdl_type = IFT_FDDI;
714	sdl->sdl_alen = ifp->if_addrlen;
715	bcopy(((struct arpcom *)ifp)->ac_enaddr, LLADDR(sdl), ifp->if_addrlen);
716#elif defined(__NetBSD__)
717	LIST_INIT(&((struct arpcom *)ifp)->ac_multiaddrs);
718	for (ifa = ifp->if_addrlist.tqh_first; ifa != NULL; ifa = ifa->ifa_list.tqe_next)
719#else
720	for (ifa = ifp->if_addrlist; ifa != NULL; ifa = ifa->ifa_next)
721#endif
722#if !defined(__FreeBSD__)
723		if ((sdl = (struct sockaddr_dl *)ifa->ifa_addr) &&
724		    sdl->sdl_family == AF_LINK) {
725			sdl->sdl_type = IFT_FDDI;
726			sdl->sdl_alen = ifp->if_addrlen;
727			bcopy((caddr_t)((struct arpcom *)ifp)->ac_enaddr,
728			      LLADDR(sdl), ifp->if_addrlen);
729			break;
730		}
731#endif
732}
733