if_fddisubr.c revision 105598
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 105598 2002-10-21 02:51:56Z brooks $ 37 */ 38 39#include "opt_atalk.h" 40#include "opt_inet.h" 41#include "opt_inet6.h" 42#include "opt_ipx.h" 43#include "opt_mac.h" 44 45#include <sys/param.h> 46#include <sys/systm.h> 47#include <sys/kernel.h> 48#include <sys/mac.h> 49#include <sys/malloc.h> 50#include <sys/mbuf.h> 51#include <sys/module.h> 52#include <sys/socket.h> 53#include <sys/sockio.h> 54 55#include <net/if.h> 56#include <net/if_llc.h> 57#include <net/if_dl.h> 58#include <net/if_types.h> 59#include <net/netisr.h> 60#include <net/route.h> 61#include <net/bpf.h> 62#include <net/fddi.h> 63 64#if defined(INET) || defined(INET6) 65#include <netinet/in.h> 66#include <netinet/in_var.h> 67#include <netinet/if_ether.h> 68#endif 69#ifdef INET6 70#include <netinet6/nd6.h> 71#endif 72 73#ifdef IPX 74#include <netipx/ipx.h> 75#include <netipx/ipx_if.h> 76#endif 77 78#ifdef NS 79#include <netns/ns.h> 80#include <netns/ns_if.h> 81#endif 82 83#ifdef DECNET 84#include <netdnet/dn.h> 85#endif 86 87#ifdef NETATALK 88#include <netatalk/at.h> 89#include <netatalk/at_var.h> 90#include <netatalk/at_extern.h> 91 92extern u_char at_org_code[ 3 ]; 93extern u_char aarp_org_code[ 3 ]; 94#endif /* NETATALK */ 95 96static u_char fddibroadcastaddr[FDDI_ADDR_LEN] = 97 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 98 99static int fddi_resolvemulti(struct ifnet *, struct sockaddr **, 100 struct sockaddr *); 101static int fddi_output(struct ifnet *, struct mbuf *, struct sockaddr *, 102 struct rtentry *); 103 104 105#define IFP2AC(IFP) ((struct arpcom *)IFP) 106#define senderr(e) { error = (e); goto bad; } 107 108/* 109 * FDDI output routine. 110 * Encapsulate a packet of type family for the local net. 111 * Use trailer local net encapsulation if enough data in first 112 * packet leaves a multiple of 512 bytes of data in remainder. 113 * Assumes that ifp is actually pointer to arpcom structure. 114 */ 115static int 116fddi_output(ifp, m, dst, rt0) 117 struct ifnet *ifp; 118 struct mbuf *m; 119 struct sockaddr *dst; 120 struct rtentry *rt0; 121{ 122 u_int16_t type; 123 int loop_copy = 0, error = 0, hdrcmplt = 0; 124 u_char esrc[FDDI_ADDR_LEN], edst[FDDI_ADDR_LEN]; 125 struct rtentry *rt; 126 struct fddi_header *fh; 127 struct arpcom *ac = IFP2AC(ifp); 128 129#ifdef MAC 130 error = mac_check_ifnet_transmit(ifp, m); 131 if (error) 132 senderr(error); 133#endif 134 135 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) 136 senderr(ENETDOWN); 137 getmicrotime(&ifp->if_lastchange); 138 if ((rt = rt0) != NULL) { 139 if ((rt->rt_flags & RTF_UP) == 0) { 140 if ((rt0 = rt = rtalloc1(dst, 1, 0UL)) != NULL) 141 rt->rt_refcnt--; 142 else 143 senderr(EHOSTUNREACH); 144 } 145 if (rt->rt_flags & RTF_GATEWAY) { 146 if (rt->rt_gwroute == 0) 147 goto lookup; 148 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { 149 rtfree(rt); rt = rt0; 150 lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, 0UL); 151 if ((rt = rt->rt_gwroute) == 0) 152 senderr(EHOSTUNREACH); 153 } 154 } 155 if (rt->rt_flags & RTF_REJECT) 156 if (rt->rt_rmx.rmx_expire == 0 || 157 time_second < rt->rt_rmx.rmx_expire) 158 senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH); 159 } 160 switch (dst->sa_family) { 161 162#ifdef INET 163 case AF_INET: { 164 if (!arpresolve(ifp, rt, m, dst, edst, rt0)) 165 return (0); /* if not yet resolved */ 166 type = htons(ETHERTYPE_IP); 167 break; 168 } 169#endif 170#ifdef INET6 171 case AF_INET6: 172 if (!nd6_storelladdr(ifp, rt, m, dst, (u_char *)edst)) { 173 /* Something bad happened */ 174 return (0); 175 } 176 type = htons(ETHERTYPE_IPV6); 177 break; 178#endif 179#ifdef IPX 180 case AF_IPX: 181 type = htons(ETHERTYPE_IPX); 182 bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host), 183 (caddr_t)edst, FDDI_ADDR_LEN); 184 break; 185#endif 186#ifdef NETATALK 187 case AF_APPLETALK: { 188 struct at_ifaddr *aa; 189 if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) 190 return (0); 191 /* 192 * ifaddr is the first thing in at_ifaddr 193 */ 194 if ((aa = at_ifawithnet( (struct sockaddr_at *)dst)) == 0) 195 goto bad; 196 197 /* 198 * In the phase 2 case, we need to prepend an mbuf for the llc header. 199 * Since we must preserve the value of m, which is passed to us by 200 * value, we m_copy() the first mbuf, and use it for our llc header. 201 */ 202 if (aa->aa_flags & AFA_PHASE2) { 203 struct llc llc; 204 205 M_PREPEND(m, LLC_SNAPFRAMELEN, M_TRYWAIT); 206 if (m == 0) 207 senderr(ENOBUFS); 208 llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP; 209 llc.llc_control = LLC_UI; 210 bcopy(at_org_code, llc.llc_snap.org_code, sizeof(at_org_code)); 211 llc.llc_snap.ether_type = htons(ETHERTYPE_AT); 212 bcopy(&llc, mtod(m, caddr_t), LLC_SNAPFRAMELEN); 213 type = 0; 214 } else { 215 type = htons(ETHERTYPE_AT); 216 } 217 break; 218 } 219#endif /* NETATALK */ 220#ifdef NS 221 case AF_NS: 222 type = htons(ETHERTYPE_NS); 223 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), 224 (caddr_t)edst, FDDI_ADDR_LEN); 225 break; 226#endif 227 228 case pseudo_AF_HDRCMPLT: 229 { 230 struct ether_header *eh; 231 hdrcmplt = 1; 232 eh = (struct ether_header *)dst->sa_data; 233 bcopy((caddr_t)eh->ether_shost, (caddr_t)esrc, FDDI_ADDR_LEN); 234 /* FALLTHROUGH */ 235 } 236 237 case AF_UNSPEC: 238 { 239 struct ether_header *eh; 240 loop_copy = -1; 241 eh = (struct ether_header *)dst->sa_data; 242 bcopy((caddr_t)eh->ether_dhost, (caddr_t)edst, FDDI_ADDR_LEN); 243 if (*edst & 1) 244 m->m_flags |= (M_BCAST|M_MCAST); 245 type = eh->ether_type; 246 break; 247 } 248 249 case AF_IMPLINK: 250 { 251 fh = mtod(m, struct fddi_header *); 252 error = EPROTONOSUPPORT; 253 switch (fh->fddi_fc & (FDDIFC_C|FDDIFC_L|FDDIFC_F)) { 254 case FDDIFC_LLC_ASYNC: { 255 /* legal priorities are 0 through 7 */ 256 if ((fh->fddi_fc & FDDIFC_Z) > 7) 257 goto bad; 258 break; 259 } 260 case FDDIFC_LLC_SYNC: { 261 /* FDDIFC_Z bits reserved, must be zero */ 262 if (fh->fddi_fc & FDDIFC_Z) 263 goto bad; 264 break; 265 } 266 case FDDIFC_SMT: { 267 /* FDDIFC_Z bits must be non zero */ 268 if ((fh->fddi_fc & FDDIFC_Z) == 0) 269 goto bad; 270 break; 271 } 272 default: { 273 /* anything else is too dangerous */ 274 goto bad; 275 } 276 } 277 error = 0; 278 if (fh->fddi_dhost[0] & 1) 279 m->m_flags |= (M_BCAST|M_MCAST); 280 goto queue_it; 281 } 282 default: 283 if_printf(ifp, "can't handle af%d\n", dst->sa_family); 284 senderr(EAFNOSUPPORT); 285 } 286 287 /* 288 * Add LLC header. 289 */ 290 if (type != 0) { 291 struct llc *l; 292 M_PREPEND(m, LLC_SNAPFRAMELEN, M_DONTWAIT); 293 if (m == 0) 294 senderr(ENOBUFS); 295 l = mtod(m, struct llc *); 296 l->llc_control = LLC_UI; 297 l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP; 298 l->llc_snap.org_code[0] = l->llc_snap.org_code[1] = l->llc_snap.org_code[2] = 0; 299 bcopy((caddr_t)&type, (caddr_t)&l->llc_snap.ether_type, 300 sizeof(u_int16_t)); 301 } 302 303 /* 304 * Add local net header. If no space in first mbuf, 305 * allocate another. 306 */ 307 M_PREPEND(m, FDDI_HDR_LEN, M_DONTWAIT); 308 if (m == 0) 309 senderr(ENOBUFS); 310 fh = mtod(m, struct fddi_header *); 311 fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4; 312 bcopy((caddr_t)edst, (caddr_t)fh->fddi_dhost, FDDI_ADDR_LEN); 313 queue_it: 314 if (hdrcmplt) 315 bcopy((caddr_t)esrc, (caddr_t)fh->fddi_shost, FDDI_ADDR_LEN); 316 else 317 bcopy((caddr_t)ac->ac_enaddr, (caddr_t)fh->fddi_shost, 318 FDDI_ADDR_LEN); 319 320 /* 321 * If a simplex interface, and the packet is being sent to our 322 * Ethernet address or a broadcast address, loopback a copy. 323 * XXX To make a simplex device behave exactly like a duplex 324 * device, we should copy in the case of sending to our own 325 * ethernet address (thus letting the original actually appear 326 * on the wire). However, we don't do that here for security 327 * reasons and compatibility with the original behavior. 328 */ 329 if ((ifp->if_flags & IFF_SIMPLEX) && (loop_copy != -1)) { 330 if ((m->m_flags & M_BCAST) || loop_copy) { 331 struct mbuf *n = m_copy(m, 0, (int)M_COPYALL); 332 333 (void) if_simloop(ifp, 334 n, dst->sa_family, FDDI_HDR_LEN); 335 } else if (bcmp(fh->fddi_dhost, 336 fh->fddi_shost, FDDI_ADDR_LEN) == 0) { 337 (void) if_simloop(ifp, 338 m, dst->sa_family, FDDI_HDR_LEN); 339 return (0); /* XXX */ 340 } 341 } 342 343 if (! IF_HANDOFF(&ifp->if_snd, m, ifp)) 344 senderr(ENOBUFS); 345 return (error); 346 347bad: 348 ifp->if_oerrors++; 349 if (m) 350 m_freem(m); 351 return (error); 352} 353 354/* 355 * Process a received FDDI packet; 356 * the packet is in the mbuf chain m without 357 * the fddi header, which is provided separately. 358 */ 359void 360fddi_input(ifp, fh, m) 361 struct ifnet *ifp; 362 struct fddi_header *fh; 363 struct mbuf *m; 364{ 365 struct ifqueue *inq; 366 struct llc *l; 367 368 /* 369 * Discard packet if interface is not up. 370 */ 371 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) 372 goto dropanyway; 373 374#ifdef MAC 375 mac_create_mbuf_from_ifnet(ifp, m); 376#endif 377 378 /* 379 * Discard non local unicast packets when interface 380 * is in promiscuous mode. 381 */ 382 if ((ifp->if_flags & IFF_PROMISC) && ((fh->fddi_dhost[0] & 1) == 0) && 383 (bcmp(IFP2AC(ifp)->ac_enaddr, (caddr_t)fh->fddi_dhost, 384 FDDI_ADDR_LEN) != 0)) 385 goto dropanyway; 386 387 /* 388 * Set mbuf flags for bcast/mcast. 389 */ 390 if (fh->fddi_dhost[0] & 1) { 391 if (bcmp((caddr_t)ifp->if_broadcastaddr, 392 (caddr_t)fh->fddi_dhost, FDDI_ADDR_LEN) == 0) 393 m->m_flags |= M_BCAST; 394 else 395 m->m_flags |= M_MCAST; 396 ifp->if_imcasts++; 397 } 398 399 /* 400 * Update interface statistics. 401 */ 402 getmicrotime(&ifp->if_lastchange); 403 ifp->if_ibytes += (m->m_pkthdr.len + FDDI_HDR_LEN); 404 405#ifdef M_LINK0 406 /* 407 * If this has a LLC priority of 0, then mark it so upper 408 * layers have a hint that it really came via a FDDI/Ethernet 409 * bridge. 410 */ 411 if ((fh->fddi_fc & FDDIFC_LLC_PRIO7) == FDDIFC_LLC_PRIO0) 412 m->m_flags |= M_LINK0; 413#endif 414 415 m = m_pullup(m, sizeof(struct llc)); 416 if (m == 0) { 417 ifp->if_ierrors++; 418 goto dropanyway; 419 } 420 l = mtod(m, struct llc *); 421 422 switch (l->llc_dsap) { 423 case LLC_SNAP_LSAP: 424 { 425 u_int16_t type; 426 if (l->llc_control != LLC_UI || l->llc_ssap != LLC_SNAP_LSAP) { 427 ifp->if_noproto++; 428 goto dropanyway; 429 } 430#ifdef NETATALK 431 if (Bcmp(&(l->llc_snap.org_code)[0], at_org_code, 432 sizeof(at_org_code)) == 0 && 433 ntohs(l->llc_snap.ether_type) == ETHERTYPE_AT) { 434 inq = &atintrq2; 435 m_adj(m, LLC_SNAPFRAMELEN); 436 schednetisr(NETISR_ATALK); 437 break; 438 } 439 440 if (Bcmp(&(l->llc_snap.org_code)[0], aarp_org_code, 441 sizeof(aarp_org_code)) == 0 && 442 ntohs(l->llc_snap.ether_type) == ETHERTYPE_AARP) { 443 m_adj(m, LLC_SNAPFRAMELEN); 444 aarpinput(IFP2AC(ifp), m); /* XXX */ 445 return; 446 } 447#endif /* NETATALK */ 448 if (l->llc_snap.org_code[0] != 0 || 449 l->llc_snap.org_code[1] != 0 || 450 l->llc_snap.org_code[2] != 0) { 451 ifp->if_noproto++; 452 goto dropanyway; 453 } 454 455 type = ntohs(l->llc_snap.ether_type); 456 m_adj(m, LLC_SNAPFRAMELEN); 457 458 switch (type) { 459#ifdef INET 460 case ETHERTYPE_IP: 461 if (ipflow_fastforward(m)) 462 return; 463 schednetisr(NETISR_IP); 464 inq = &ipintrq; 465 break; 466 467 case ETHERTYPE_ARP: 468 if (ifp->if_flags & IFF_NOARP) 469 goto dropanyway; 470 schednetisr(NETISR_ARP); 471 inq = &arpintrq; 472 break; 473#endif 474#ifdef INET6 475 case ETHERTYPE_IPV6: 476 schednetisr(NETISR_IPV6); 477 inq = &ip6intrq; 478 break; 479#endif 480#ifdef IPX 481 case ETHERTYPE_IPX: 482 schednetisr(NETISR_IPX); 483 inq = &ipxintrq; 484 break; 485#endif 486#ifdef NS 487 case ETHERTYPE_NS: 488 schednetisr(NETISR_NS); 489 inq = &nsintrq; 490 break; 491#endif 492#ifdef DECNET 493 case ETHERTYPE_DECNET: 494 schednetisr(NETISR_DECNET); 495 inq = &decnetintrq; 496 break; 497#endif 498#ifdef NETATALK 499 case ETHERTYPE_AT: 500 schednetisr(NETISR_ATALK); 501 inq = &atintrq1; 502 break; 503 case ETHERTYPE_AARP: 504 /* probably this should be done with a NETISR as well */ 505 aarpinput(IFP2AC(ifp), m); /* XXX */ 506 return; 507#endif /* NETATALK */ 508 default: 509 /* printf("fddi_input: unknown protocol 0x%x\n", type); */ 510 ifp->if_noproto++; 511 goto dropanyway; 512 } 513 break; 514 } 515 516 default: 517 /* printf("fddi_input: unknown dsap 0x%x\n", l->llc_dsap); */ 518 ifp->if_noproto++; 519 goto dropanyway; 520 } 521 522 (void) IF_HANDOFF(inq, m, NULL); 523 return; 524 525dropanyway: 526 ifp->if_iqdrops++; 527 if (m) 528 m_freem(m); 529 return; 530} 531 532/* 533 * Perform common duties while attaching to interface list 534 */ 535void 536fddi_ifattach(ifp, bpf) 537 struct ifnet *ifp; 538 int bpf; 539{ 540 struct ifaddr *ifa; 541 struct sockaddr_dl *sdl; 542 543 ifp->if_type = IFT_FDDI; 544 ifp->if_addrlen = FDDI_ADDR_LEN; 545 ifp->if_hdrlen = 21; 546 547 if_attach(ifp); /* Must be called before additional assignments */ 548 549 ifp->if_mtu = FDDIMTU; 550 ifp->if_output = fddi_output; 551 ifp->if_resolvemulti = fddi_resolvemulti; 552 ifp->if_broadcastaddr = fddibroadcastaddr; 553 ifp->if_baudrate = 100000000; 554#ifdef IFF_NOTRAILERS 555 ifp->if_flags |= IFF_NOTRAILERS; 556#endif 557 ifa = ifaddr_byindex(ifp->if_index); 558 if (ifa == NULL) { 559 printf("%s(): no lladdr for %s%d!\n", __FUNCTION__, 560 ifp->if_name, ifp->if_unit); 561 return; 562 } 563 564 sdl = (struct sockaddr_dl *)ifa->ifa_addr; 565 sdl->sdl_type = IFT_FDDI; 566 sdl->sdl_alen = ifp->if_addrlen; 567 bcopy(IFP2AC(ifp)->ac_enaddr, LLADDR(sdl), ifp->if_addrlen); 568 569 if (bpf) 570 bpfattach(ifp, DLT_FDDI, FDDI_HDR_LEN); 571 572 return; 573} 574 575void 576fddi_ifdetach(ifp, bpf) 577 struct ifnet *ifp; 578 int bpf; 579{ 580 581 if (bpf) 582 bpfdetach(ifp); 583 584 if_detach(ifp); 585 586 return; 587} 588 589int 590fddi_ioctl (ifp, command, data) 591 struct ifnet *ifp; 592 int command; 593 caddr_t data; 594{ 595 struct ifaddr *ifa; 596 struct ifreq *ifr; 597 int error; 598 599 ifa = (struct ifaddr *) data; 600 ifr = (struct ifreq *) data; 601 error = 0; 602 603 switch (command) { 604 case SIOCSIFADDR: 605 ifp->if_flags |= IFF_UP; 606 607 switch (ifa->ifa_addr->sa_family) { 608#ifdef INET 609 case AF_INET: /* before arpwhohas */ 610 ifp->if_init(ifp->if_softc); 611 arp_ifinit(ifp, ifa); 612 break; 613#endif 614#ifdef IPX 615 /* 616 * XXX - This code is probably wrong 617 */ 618 case AF_IPX: { 619 struct ipx_addr *ina; 620 struct arpcom *ac; 621 622 ina = &(IA_SIPX(ifa)->sipx_addr); 623 ac = IFP2AC(ifp); 624 625 if (ipx_nullhost(*ina)) { 626 ina->x_host = *(union ipx_host *) 627 ac->ac_enaddr; 628 } else { 629 bcopy((caddr_t) ina->x_host.c_host, 630 (caddr_t) ac->ac_enaddr, 631 sizeof(ac->ac_enaddr)); 632 } 633 634 /* 635 * Set new address 636 */ 637 ifp->if_init(ifp->if_softc); 638 } 639 break; 640#endif 641 default: 642 ifp->if_init(ifp->if_softc); 643 break; 644 } 645 case SIOCGIFADDR: { 646 struct sockaddr *sa; 647 648 sa = (struct sockaddr *) & ifr->ifr_data; 649 bcopy(IFP2AC(ifp)->ac_enaddr, 650 (caddr_t) sa->sa_data, FDDI_ADDR_LEN); 651 652 } 653 break; 654 case SIOCSIFMTU: 655 /* 656 * Set the interface MTU. 657 */ 658 if (ifr->ifr_mtu > FDDIMTU) { 659 error = EINVAL; 660 } else { 661 ifp->if_mtu = ifr->ifr_mtu; 662 } 663 break; 664 default: 665 break; 666 } 667 668 return (error); 669} 670 671static int 672fddi_resolvemulti(ifp, llsa, sa) 673 struct ifnet *ifp; 674 struct sockaddr **llsa; 675 struct sockaddr *sa; 676{ 677 struct sockaddr_dl *sdl; 678 struct sockaddr_in *sin; 679#ifdef INET6 680 struct sockaddr_in6 *sin6; 681#endif 682 u_char *e_addr; 683 684 switch(sa->sa_family) { 685 case AF_LINK: 686 /* 687 * No mapping needed. Just check that it's a valid MC address. 688 */ 689 sdl = (struct sockaddr_dl *)sa; 690 e_addr = LLADDR(sdl); 691 if ((e_addr[0] & 1) != 1) 692 return (EADDRNOTAVAIL); 693 *llsa = 0; 694 return (0); 695 696#ifdef INET 697 case AF_INET: 698 sin = (struct sockaddr_in *)sa; 699 if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) 700 return (EADDRNOTAVAIL); 701 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR, 702 M_WAITOK); 703 sdl->sdl_len = sizeof *sdl; 704 sdl->sdl_family = AF_LINK; 705 sdl->sdl_index = ifp->if_index; 706 sdl->sdl_type = IFT_FDDI; 707 sdl->sdl_nlen = 0; 708 sdl->sdl_alen = FDDI_ADDR_LEN; 709 sdl->sdl_slen = 0; 710 e_addr = LLADDR(sdl); 711 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr); 712 *llsa = (struct sockaddr *)sdl; 713 return (0); 714#endif 715#ifdef INET6 716 case AF_INET6: 717 sin6 = (struct sockaddr_in6 *)sa; 718 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { 719 /* 720 * An IP6 address of 0 means listen to all 721 * of the Ethernet multicast address used for IP6. 722 * (This is used for multicast routers.) 723 */ 724 ifp->if_flags |= IFF_ALLMULTI; 725 *llsa = 0; 726 return (0); 727 } 728 if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) 729 return (EADDRNOTAVAIL); 730 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR, 731 M_WAITOK); 732 sdl->sdl_len = sizeof *sdl; 733 sdl->sdl_family = AF_LINK; 734 sdl->sdl_index = ifp->if_index; 735 sdl->sdl_type = IFT_FDDI; 736 sdl->sdl_nlen = 0; 737 sdl->sdl_alen = FDDI_ADDR_LEN; 738 sdl->sdl_slen = 0; 739 e_addr = LLADDR(sdl); 740 ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr); 741 *llsa = (struct sockaddr *)sdl; 742 return (0); 743#endif 744 745 default: 746 /* 747 * Well, the text isn't quite right, but it's the name 748 * that counts... 749 */ 750 return (EAFNOSUPPORT); 751 } 752 753 return (0); 754} 755 756static moduledata_t fddi_mod = { 757 "fddi", /* module name */ 758 NULL, /* event handler */ 759 0 /* extra data */ 760}; 761 762DECLARE_MODULE(fddi, fddi_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); 763MODULE_VERSION(fddi, 1); 764