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