if_fddisubr.c revision 54263
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 54263 1999-12-07 17:39:16Z shin $ 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/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#if defined(INET) || defined(INET6) 57#include <netinet/in.h> 58#include <netinet/in_var.h> 59#include <netinet/if_ether.h> 60#endif 61#ifdef INET6 62#include <netinet6/nd6.h> 63#endif 64#if defined(__FreeBSD__) 65#include <netinet/if_fddi.h> 66#else 67#include <net/if_fddi.h> 68#endif 69 70#ifdef IPX 71#include <netipx/ipx.h> 72#include <netipx/ipx_if.h> 73#endif 74 75#ifdef NS 76#include <netns/ns.h> 77#include <netns/ns_if.h> 78#endif 79 80#ifdef DECNET 81#include <netdnet/dn.h> 82#endif 83 84#ifdef ISO 85#include <netiso/argo_debug.h> 86#include <netiso/iso.h> 87#include <netiso/iso_var.h> 88#include <netiso/iso_snpac.h> 89#endif 90 91#ifdef LLC 92#include <netccitt/dll.h> 93#include <netccitt/llc_var.h> 94#endif 95 96#ifdef NETATALK 97#include <netatalk/at.h> 98#include <netatalk/at_var.h> 99#include <netatalk/at_extern.h> 100 101#define llc_snap_org_code llc_un.type_snap.org_code 102#define llc_snap_ether_type llc_un.type_snap.ether_type 103 104extern u_char at_org_code[ 3 ]; 105extern u_char aarp_org_code[ 3 ]; 106#endif /* NETATALK */ 107 108#if defined(LLC) && defined(CCITT) 109extern struct ifqueue pkintrq; 110#endif 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, loop_copy = 0, error = 0, hdrcmplt = 0; 144 u_char esrc[6], edst[6]; 145 register struct mbuf *m = m0; 146 register struct rtentry *rt; 147 register struct fddi_header *fh; 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) != NULL) { 155 if ((rt->rt_flags & RTF_UP) == 0) { 156 if ((rt0 = rt = RTALLOC1(dst, 1)) != NULL) 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 type = htons(ETHERTYPE_IP); 190 break; 191 } 192#endif 193#ifdef INET6 194 case AF_INET6: 195 if (!nd6_storelladdr(&ac->ac_if, rt, m, dst, (u_char *)edst)) { 196 /* this must be impossible, so we bark */ 197 printf("nd6_storelladdr failed\n"); 198 return(0); 199 } 200 type = htons(ETHERTYPE_IPV6); 201 break; 202#endif 203#ifdef IPX 204 case AF_IPX: 205 type = htons(ETHERTYPE_IPX); 206 bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host), 207 (caddr_t)edst, sizeof (edst)); 208 break; 209#endif 210#ifdef NETATALK 211 case AF_APPLETALK: { 212 struct at_ifaddr *aa; 213 if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) 214 return (0); 215 /* 216 * ifaddr is the first thing in at_ifaddr 217 */ 218 if ((aa = at_ifawithnet( (struct sockaddr_at *)dst)) == 0) 219 goto bad; 220 221 /* 222 * In the phase 2 case, we need to prepend an mbuf for the llc header. 223 * Since we must preserve the value of m, which is passed to us by 224 * value, we m_copy() the first mbuf, and use it for our llc header. 225 */ 226 if (aa->aa_flags & AFA_PHASE2) { 227 struct llc llc; 228 229 M_PREPEND(m, sizeof(struct llc), M_WAIT); 230 if (m == 0) 231 senderr(ENOBUFS); 232 llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP; 233 llc.llc_control = LLC_UI; 234 bcopy(at_org_code, llc.llc_snap_org_code, sizeof(at_org_code)); 235 llc.llc_snap_ether_type = htons(ETHERTYPE_AT); 236 bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc)); 237 type = 0; 238 } else { 239 type = htons(ETHERTYPE_AT); 240 } 241 break; 242 } 243#endif /* NETATALK */ 244#ifdef NS 245 case AF_NS: 246 type = htons(ETHERTYPE_NS); 247 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), 248 (caddr_t)edst, sizeof (edst)); 249 break; 250#endif 251#ifdef ISO 252 case AF_ISO: { 253 int snpalen; 254 struct llc *l; 255 register struct sockaddr_dl *sdl; 256 257 if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) && 258 sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) { 259 bcopy(LLADDR(sdl), (caddr_t)edst, sizeof(edst)); 260 } else if (error = 261 iso_snparesolve(ifp, (struct sockaddr_iso *)dst, 262 (char *)edst, &snpalen)) 263 goto bad; /* Not Resolved */ 264 /* If broadcasting on a simplex interface, loopback a copy */ 265 if (*edst & 1) 266 m->m_flags |= (M_BCAST|M_MCAST); 267 M_PREPEND(m, 3, M_DONTWAIT); 268 if (m == NULL) 269 return (0); 270 type = 0; 271 l = mtod(m, struct llc *); 272 l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP; 273 l->llc_control = LLC_UI; 274 IFDEBUG(D_ETHER) 275 int i; 276 printf("unoutput: sending pkt to: "); 277 for (i=0; i<6; i++) 278 printf("%x ", edst[i] & 0xff); 279 printf("\n"); 280 ENDDEBUG 281 } break; 282#endif /* ISO */ 283#ifdef LLC 284/* case AF_NSAP: */ 285 case AF_CCITT: { 286 register struct sockaddr_dl *sdl = 287 (struct sockaddr_dl *) rt -> rt_gateway; 288 289 if (sdl && sdl->sdl_family != AF_LINK && sdl->sdl_alen <= 0) 290 goto bad; /* Not a link interface ? Funny ... */ 291 bcopy(LLADDR(sdl), (char *)edst, sizeof(edst)); 292 if (*edst & 1) 293 loop_copy = 1; 294 type = 0; 295#ifdef LLC_DEBUG 296 { 297 int i; 298 register struct llc *l = mtod(m, struct llc *); 299 300 printf("fddi_output: sending LLC2 pkt to: "); 301 for (i=0; i<6; i++) 302 printf("%x ", edst[i] & 0xff); 303 printf(" len 0x%x dsap 0x%x ssap 0x%x control 0x%x\n", 304 type & 0xff, l->llc_dsap & 0xff, l->llc_ssap &0xff, 305 l->llc_control & 0xff); 306 307 } 308#endif /* LLC_DEBUG */ 309 } break; 310#endif /* LLC */ 311 312 case pseudo_AF_HDRCMPLT: 313 { 314 struct ether_header *eh; 315 hdrcmplt = 1; 316 eh = (struct ether_header *)dst->sa_data; 317 (void)memcpy((caddr_t)esrc, (caddr_t)eh->ether_shost, sizeof (esrc)); 318 /* FALLTHROUGH */ 319 } 320 321 case AF_UNSPEC: 322 { 323 struct ether_header *eh; 324 loop_copy = -1; 325 eh = (struct ether_header *)dst->sa_data; 326 (void)memcpy((caddr_t)edst, (caddr_t)eh->ether_dhost, sizeof (edst)); 327 if (*edst & 1) 328 m->m_flags |= (M_BCAST|M_MCAST); 329 type = eh->ether_type; 330 break; 331 } 332 333 case AF_IMPLINK: 334 { 335 fh = mtod(m, struct fddi_header *); 336 error = EPROTONOSUPPORT; 337 switch (fh->fddi_fc & (FDDIFC_C|FDDIFC_L|FDDIFC_F)) { 338 case FDDIFC_LLC_ASYNC: { 339 /* legal priorities are 0 through 7 */ 340 if ((fh->fddi_fc & FDDIFC_Z) > 7) 341 goto bad; 342 break; 343 } 344 case FDDIFC_LLC_SYNC: { 345 /* FDDIFC_Z bits reserved, must be zero */ 346 if (fh->fddi_fc & FDDIFC_Z) 347 goto bad; 348 break; 349 } 350 case FDDIFC_SMT: { 351 /* FDDIFC_Z bits must be non zero */ 352 if ((fh->fddi_fc & FDDIFC_Z) == 0) 353 goto bad; 354 break; 355 } 356 default: { 357 /* anything else is too dangerous */ 358 goto bad; 359 } 360 } 361 error = 0; 362 if (fh->fddi_dhost[0] & 1) 363 m->m_flags |= (M_BCAST|M_MCAST); 364 goto queue_it; 365 } 366 default: 367 printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit, 368 dst->sa_family); 369 senderr(EAFNOSUPPORT); 370 } 371 372 if (type != 0) { 373 register struct llc *l; 374 M_PREPEND(m, sizeof (struct llc), M_DONTWAIT); 375 if (m == 0) 376 senderr(ENOBUFS); 377 l = mtod(m, struct llc *); 378 l->llc_control = LLC_UI; 379 l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP; 380 l->llc_snap.org_code[0] = l->llc_snap.org_code[1] = l->llc_snap.org_code[2] = 0; 381 (void)memcpy((caddr_t) &l->llc_snap.ether_type, (caddr_t) &type, 382 sizeof(u_int16_t)); 383 } 384 385 /* 386 * Add local net header. If no space in first mbuf, 387 * allocate another. 388 */ 389 M_PREPEND(m, sizeof (struct fddi_header), M_DONTWAIT); 390 if (m == 0) 391 senderr(ENOBUFS); 392 fh = mtod(m, struct fddi_header *); 393 fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4; 394 (void)memcpy((caddr_t)fh->fddi_dhost, (caddr_t)edst, sizeof (edst)); 395 queue_it: 396 if (hdrcmplt) 397 (void)memcpy((caddr_t)fh->fddi_shost, (caddr_t)esrc, 398 sizeof(fh->fddi_shost)); 399 else 400 (void)memcpy((caddr_t)fh->fddi_shost, (caddr_t)ac->ac_enaddr, 401 sizeof(fh->fddi_shost)); 402 /* 403 * If a simplex interface, and the packet is being sent to our 404 * Ethernet address or a broadcast address, loopback a copy. 405 * XXX To make a simplex device behave exactly like a duplex 406 * device, we should copy in the case of sending to our own 407 * ethernet address (thus letting the original actually appear 408 * on the wire). However, we don't do that here for security 409 * reasons and compatibility with the original behavior. 410 */ 411 if ((ifp->if_flags & IFF_SIMPLEX) && 412 (loop_copy != -1)) { 413 if ((m->m_flags & M_BCAST) || loop_copy) { 414 struct mbuf *n = m_copy(m, 0, (int)M_COPYALL); 415 416 (void) if_simloop(ifp, 417 n, dst, sizeof(struct fddi_header)); 418 } else if (bcmp(fh->fddi_dhost, 419 fh->fddi_shost, sizeof(fh->fddi_shost)) == 0) { 420 (void) if_simloop(ifp, 421 m, dst, sizeof(struct fddi_header)); 422 return(0); /* XXX */ 423 } 424 } 425 426 s = splimp(); 427 /* 428 * Queue message on interface, and start output if interface 429 * not yet active. 430 */ 431 if (IF_QFULL(&ifp->if_snd)) { 432 IF_DROP(&ifp->if_snd); 433 splx(s); 434 senderr(ENOBUFS); 435 } 436 ifp->if_obytes += m->m_pkthdr.len; 437 IF_ENQUEUE(&ifp->if_snd, m); 438 if ((ifp->if_flags & IFF_OACTIVE) == 0) 439 (*ifp->if_start)(ifp); 440 splx(s); 441 if (m->m_flags & M_MCAST) 442 ifp->if_omcasts++; 443 return (error); 444 445bad: 446 if (m) 447 m_freem(m); 448 return (error); 449} 450 451/* 452 * Process a received FDDI packet; 453 * the packet is in the mbuf chain m without 454 * the fddi header, which is provided separately. 455 */ 456void 457fddi_input(ifp, fh, m) 458 struct ifnet *ifp; 459 register struct fddi_header *fh; 460 struct mbuf *m; 461{ 462 register struct ifqueue *inq; 463 register struct llc *l; 464 int s; 465 466 if ((ifp->if_flags & IFF_UP) == 0) { 467 m_freem(m); 468 return; 469 } 470 getmicrotime(&ifp->if_lastchange); 471 ifp->if_ibytes += m->m_pkthdr.len + sizeof (*fh); 472 if (fh->fddi_dhost[0] & 1) { 473 if (bcmp((caddr_t)fddibroadcastaddr, (caddr_t)fh->fddi_dhost, 474 sizeof(fddibroadcastaddr)) == 0) 475 m->m_flags |= M_BCAST; 476 else 477 m->m_flags |= M_MCAST; 478 ifp->if_imcasts++; 479 } else if ((ifp->if_flags & IFF_PROMISC) 480 && bcmp(((struct arpcom *)ifp)->ac_enaddr, (caddr_t)fh->fddi_dhost, 481 sizeof(fh->fddi_dhost)) != 0) { 482 m_freem(m); 483 return; 484 } 485 486#ifdef M_LINK0 487 /* 488 * If this has a LLC priority of 0, then mark it so upper 489 * layers have a hint that it really came via a FDDI/Ethernet 490 * bridge. 491 */ 492 if ((fh->fddi_fc & FDDIFC_LLC_PRIO7) == FDDIFC_LLC_PRIO0) 493 m->m_flags |= M_LINK0; 494#endif 495 496 l = mtod(m, struct llc *); 497 switch (l->llc_dsap) { 498#if defined(INET) || defined(INET6) || defined(NS) || defined(DECNET) || defined(IPX) || defined(NETATALK) 499 case LLC_SNAP_LSAP: 500 { 501 u_int16_t type; 502 if (l->llc_control != LLC_UI || l->llc_ssap != LLC_SNAP_LSAP) 503 goto dropanyway; 504#ifdef NETATALK 505 if (Bcmp(&(l->llc_snap_org_code)[0], at_org_code, 506 sizeof(at_org_code)) == 0 && 507 ntohs(l->llc_snap_ether_type) == ETHERTYPE_AT) { 508 inq = &atintrq2; 509 m_adj( m, sizeof( struct llc )); 510 schednetisr(NETISR_ATALK); 511 break; 512 } 513 514 if (Bcmp(&(l->llc_snap_org_code)[0], aarp_org_code, 515 sizeof(aarp_org_code)) == 0 && 516 ntohs(l->llc_snap_ether_type) == ETHERTYPE_AARP) { 517 m_adj( m, sizeof( struct llc )); 518 aarpinput((struct arpcom *)ifp, m); /* XXX */ 519 return; 520 } 521#endif /* NETATALK */ 522 if (l->llc_snap.org_code[0] != 0 || l->llc_snap.org_code[1] != 0|| l->llc_snap.org_code[2] != 0) 523 goto dropanyway; 524 type = ntohs(l->llc_snap.ether_type); 525 m_adj(m, 8); 526 switch (type) { 527#ifdef INET 528 case ETHERTYPE_IP: 529 if (ipflow_fastforward(m)) 530 return; 531 schednetisr(NETISR_IP); 532 inq = &ipintrq; 533 break; 534 535 case ETHERTYPE_ARP: 536#if !defined(__bsdi__) || _BSDI_VERSION >= 199401 537 schednetisr(NETISR_ARP); 538 inq = &arpintrq; 539 break; 540#else 541 arpinput((struct arpcom *)ifp, m); 542 return; 543#endif 544#endif 545#ifdef INET6 546 case ETHERTYPE_IPV6: 547 schednetisr(NETISR_IPV6); 548 inq = &ip6intrq; 549 break; 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