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