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