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