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