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