1 /* 2 * Copyright (c) 1982, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)if_ethersubr.c 8.1 (Berkeley) 6/10/93 34 * $Id: if_ethersubr.c,v 1.13 1995/12/20 21:53:40 wollman Exp $ 35 */ 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/kernel.h> 40 #include <sys/malloc.h> 41 #include <sys/mbuf.h> 42 #include <sys/protosw.h> 43 #include <sys/socket.h> 44 #include <sys/ioctl.h> 45 #include <sys/errno.h> 46 #include <sys/syslog.h> 47 #include <sys/sysctl.h> 48 49 #include <machine/cpu.h> 50 51 #include <net/if.h> 52 #include <net/netisr.h> 53 #include <net/route.h> 54 #include <net/if_llc.h> 55 #include <net/if_dl.h> 56 #include <net/if_types.h> 57 58 #ifdef INET 59 #include <netinet/in.h> 60 #include <netinet/in_var.h> 61 #endif 62 #include <netinet/if_ether.h> 63 64 #ifdef IPX 65 #include <netipx/ipx.h> 66 #include <netipx/ipx_if.h> 67 #endif 68 69 #ifdef NS 70 #include <netns/ns.h> 71 #include <netns/ns_if.h> 72 #endif 73 74 #ifdef ISO 75 #include <netiso/argo_debug.h> 76 #include <netiso/iso.h> 77 #include <netiso/iso_var.h> 78 #include <netiso/iso_snpac.h> 79 #endif 80 81 #ifdef LLC 82 #include <netccitt/dll.h> 83 #include <netccitt/llc_var.h> 84 #endif 85 86 #if defined(LLC) && defined(CCITT) 87 extern struct ifqueue pkintrq; 88 #endif 89 90 u_char etherbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 91 #define senderr(e) { error = (e); goto bad;} 92 93 /* 94 * Ethernet output routine. 95 * Encapsulate a packet of type family for the local net. 96 * Use trailer local net encapsulation if enough data in first 97 * packet leaves a multiple of 512 bytes of data in remainder. 98 * Assumes that ifp is actually pointer to arpcom structure. 99 */ 100 int 101 ether_output(ifp, m0, dst, rt0) 102 register struct ifnet *ifp; 103 struct mbuf *m0; 104 struct sockaddr *dst; 105 struct rtentry *rt0; 106 { 107 short type; 108 int s, error = 0; 109 u_char edst[6]; 110 register struct mbuf *m = m0; 111 register struct rtentry *rt; 112 struct mbuf *mcopy = (struct mbuf *)0; 113 register struct ether_header *eh; 114 int off, len = m->m_pkthdr.len; 115 struct arpcom *ac = (struct arpcom *)ifp; 116 117 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) 118 senderr(ENETDOWN); 119 ifp->if_lastchange = time; 120 rt = rt0; 121 if (rt) { 122 if ((rt->rt_flags & RTF_UP) == 0) { 123 rt0 = rt = rtalloc1(dst, 1, 0UL); 124 if (rt0) 125 rt->rt_refcnt--; 126 else 127 senderr(EHOSTUNREACH); 128 } 129 if (rt->rt_flags & RTF_GATEWAY) { 130 if (rt->rt_gwroute == 0) 131 goto lookup; 132 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { 133 rtfree(rt); rt = rt0; 134 lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, 135 0UL); 136 if ((rt = rt->rt_gwroute) == 0) 137 senderr(EHOSTUNREACH); 138 } 139 } 140 if (rt->rt_flags & RTF_REJECT) 141 if (rt->rt_rmx.rmx_expire == 0 || 142 time.tv_sec < rt->rt_rmx.rmx_expire) 143 senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH); 144 } 145 switch (dst->sa_family) { 146 147 #ifdef INET 148 case AF_INET: 149 if (!arpresolve(ac, rt, m, dst, edst, rt0)) 150 return (0); /* if not yet resolved */ 151 /* If broadcasting on a simplex interface, loopback a copy */ 152 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX)) 153 mcopy = m_copy(m, 0, (int)M_COPYALL); 154 off = m->m_pkthdr.len - m->m_len; 155 type = ETHERTYPE_IP; 156 break; 157 #endif 158 #ifdef IPX 159 case AF_IPX: 160 type = ETHERTYPE_IPX; 161 bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host), 162 (caddr_t)edst, sizeof (edst)); 163 if (!bcmp((caddr_t)edst, (caddr_t)&ipx_thishost, sizeof(edst))) 164 return (looutput(ifp, m, dst, rt)); 165 /* If broadcasting on a simplex interface, loopback a copy */ 166 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX)) 167 mcopy = m_copy(m, 0, (int)M_COPYALL); 168 break; 169 #endif 170 #ifdef NS 171 case AF_NS: 172 type = ETHERTYPE_NS; 173 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), 174 (caddr_t)edst, sizeof (edst)); 175 if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost, sizeof(edst))) 176 return (looutput(ifp, m, dst, rt)); 177 /* If broadcasting on a simplex interface, loopback a copy */ 178 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX)) 179 mcopy = m_copy(m, 0, (int)M_COPYALL); 180 break; 181 #endif 182 #ifdef ISO 183 case AF_ISO: { 184 int snpalen; 185 struct llc *l; 186 register struct sockaddr_dl *sdl; 187 188 if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) && 189 sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) { 190 bcopy(LLADDR(sdl), (caddr_t)edst, sizeof(edst)); 191 } else if (error = 192 iso_snparesolve(ifp, (struct sockaddr_iso *)dst, 193 (char *)edst, &snpalen)) 194 goto bad; /* Not Resolved */ 195 /* If broadcasting on a simplex interface, loopback a copy */ 196 if (*edst & 1) 197 m->m_flags |= (M_BCAST|M_MCAST); 198 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX) && 199 (mcopy = m_copy(m, 0, (int)M_COPYALL))) { 200 M_PREPEND(mcopy, sizeof (*eh), M_DONTWAIT); 201 if (mcopy) { 202 eh = mtod(mcopy, struct ether_header *); 203 bcopy((caddr_t)edst, 204 (caddr_t)eh->ether_dhost, sizeof (edst)); 205 bcopy((caddr_t)ac->ac_enaddr, 206 (caddr_t)eh->ether_shost, sizeof (edst)); 207 } 208 } 209 M_PREPEND(m, 3, M_DONTWAIT); 210 if (m == NULL) 211 return (0); 212 type = m->m_pkthdr.len; 213 l = mtod(m, struct llc *); 214 l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP; 215 l->llc_control = LLC_UI; 216 len += 3; 217 IFDEBUG(D_ETHER) 218 int i; 219 printf("unoutput: sending pkt to: "); 220 for (i=0; i<6; i++) 221 printf("%x ", edst[i] & 0xff); 222 printf("\n"); 223 ENDDEBUG 224 } break; 225 #endif /* ISO */ 226 #ifdef LLC 227 /* case AF_NSAP: */ 228 case AF_CCITT: { 229 register struct sockaddr_dl *sdl = 230 (struct sockaddr_dl *) rt -> rt_gateway; 231 232 if (sdl && sdl->sdl_family == AF_LINK 233 && sdl->sdl_alen > 0) { 234 bcopy(LLADDR(sdl), (char *)edst, 235 sizeof(edst)); 236 } else goto bad; /* Not a link interface ? Funny ... */ 237 if ((ifp->if_flags & IFF_SIMPLEX) && (*edst & 1) && 238 (mcopy = m_copy(m, 0, (int)M_COPYALL))) { 239 M_PREPEND(mcopy, sizeof (*eh), M_DONTWAIT); 240 if (mcopy) { 241 eh = mtod(mcopy, struct ether_header *); 242 bcopy((caddr_t)edst, 243 (caddr_t)eh->ether_dhost, sizeof (edst)); 244 bcopy((caddr_t)ac->ac_enaddr, 245 (caddr_t)eh->ether_shost, sizeof (edst)); 246 } 247 } 248 type = m->m_pkthdr.len; 249 #ifdef LLC_DEBUG 250 { 251 int i; 252 register struct llc *l = mtod(m, struct llc *); 253 254 printf("ether_output: sending LLC2 pkt to: "); 255 for (i=0; i<6; i++) 256 printf("%x ", edst[i] & 0xff); 257 printf(" len 0x%x dsap 0x%x ssap 0x%x control 0x%x\n", 258 type & 0xff, l->llc_dsap & 0xff, l->llc_ssap &0xff, 259 l->llc_control & 0xff); 260 261 } 262 #endif /* LLC_DEBUG */ 263 } break; 264 #endif /* LLC */ 265 266 case AF_UNSPEC: 267 eh = (struct ether_header *)dst->sa_data; 268 (void)memcpy(edst, eh->ether_dhost, sizeof (edst)); 269 type = eh->ether_type; 270 break; 271 272 default: 273 printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit, 274 dst->sa_family); 275 senderr(EAFNOSUPPORT); 276 } 277 278 279 if (mcopy) 280 (void) looutput(ifp, mcopy, dst, rt); 281 /* 282 * Add local net header. If no space in first mbuf, 283 * allocate another. 284 */ 285 M_PREPEND(m, sizeof (struct ether_header), M_DONTWAIT); 286 if (m == 0) 287 senderr(ENOBUFS); 288 eh = mtod(m, struct ether_header *); 289 type = htons((u_short)type); 290 (void)memcpy(&eh->ether_type, &type, 291 sizeof(eh->ether_type)); 292 (void)memcpy(eh->ether_dhost, edst, sizeof (edst)); 293 (void)memcpy(eh->ether_shost, ac->ac_enaddr, 294 sizeof(eh->ether_shost)); 295 s = splimp(); 296 /* 297 * Queue message on interface, and start output if interface 298 * not yet active. 299 */ 300 if (IF_QFULL(&ifp->if_snd)) { 301 IF_DROP(&ifp->if_snd); 302 splx(s); 303 senderr(ENOBUFS); 304 } 305 IF_ENQUEUE(&ifp->if_snd, m); 306 if ((ifp->if_flags & IFF_OACTIVE) == 0) 307 (*ifp->if_start)(ifp); 308 splx(s); 309 ifp->if_obytes += len + sizeof (struct ether_header); 310 if (m->m_flags & M_MCAST) 311 ifp->if_omcasts++; 312 return (error); 313 314 bad: 315 if (m) 316 m_freem(m); 317 return (error); 318 } 319 320 /* 321 * Process a received Ethernet packet; 322 * the packet is in the mbuf chain m without 323 * the ether header, which is provided separately. 324 */ 325 void 326 ether_input(ifp, eh, m) 327 struct ifnet *ifp; 328 register struct ether_header *eh; 329 struct mbuf *m; 330 { 331 register struct ifqueue *inq; 332 register struct llc *l; 333 u_short ether_type; 334 int s; 335 336 if ((ifp->if_flags & IFF_UP) == 0) { 337 m_freem(m); 338 return; 339 } 340 ifp->if_lastchange = time; 341 ifp->if_ibytes += m->m_pkthdr.len + sizeof (*eh); 342 if (bcmp((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost, 343 sizeof(etherbroadcastaddr)) == 0) 344 m->m_flags |= M_BCAST; 345 else if (eh->ether_dhost[0] & 1) 346 m->m_flags |= M_MCAST; 347 if (m->m_flags & (M_BCAST|M_MCAST)) 348 ifp->if_imcasts++; 349 350 ether_type = ntohs(eh->ether_type); 351 352 switch (ether_type) { 353 #ifdef INET 354 case ETHERTYPE_IP: 355 schednetisr(NETISR_IP); 356 inq = &ipintrq; 357 break; 358 359 case ETHERTYPE_ARP: 360 schednetisr(NETISR_ARP); 361 inq = &arpintrq; 362 break; 363 #endif 364 #ifdef IPX 365 case ETHERTYPE_IPX: 366 schednetisr(NETISR_IPX); 367 inq = &ipxintrq; 368 break; 369 #endif 370 #ifdef NS 371 case ETHERTYPE_NS: 372 schednetisr(NETISR_NS); 373 inq = &nsintrq; 374 break; 375 #endif 376 default: 377 #if defined (ISO) || defined (LLC) 378 if (ether_type > ETHERMTU) 379 goto dropanyway; 380 l = mtod(m, struct llc *); 381 switch (l->llc_dsap) { 382 #ifdef ISO 383 case LLC_ISO_LSAP: 384 switch (l->llc_control) { 385 case LLC_UI: 386 /* LLC_UI_P forbidden in class 1 service */ 387 if ((l->llc_dsap == LLC_ISO_LSAP) && 388 (l->llc_ssap == LLC_ISO_LSAP)) { 389 /* LSAP for ISO */ 390 if (m->m_pkthdr.len > ether_type) 391 m_adj(m, ether_type - m->m_pkthdr.len); 392 m->m_data += 3; /* XXX */ 393 m->m_len -= 3; /* XXX */ 394 m->m_pkthdr.len -= 3; /* XXX */ 395 M_PREPEND(m, sizeof *eh, M_DONTWAIT); 396 if (m == 0) 397 return; 398 *mtod(m, struct ether_header *) = *eh; 399 IFDEBUG(D_ETHER) 400 printf("clnp packet"); 401 ENDDEBUG 402 schednetisr(NETISR_ISO); 403 inq = &clnlintrq; 404 break; 405 } 406 goto dropanyway; 407 408 case LLC_XID: 409 case LLC_XID_P: 410 if(m->m_len < 6) 411 goto dropanyway; 412 l->llc_window = 0; 413 l->llc_fid = 9; 414 l->llc_class = 1; 415 l->llc_dsap = l->llc_ssap = 0; 416 /* Fall through to */ 417 case LLC_TEST: 418 case LLC_TEST_P: 419 { 420 struct sockaddr sa; 421 register struct ether_header *eh2; 422 int i; 423 u_char c = l->llc_dsap; 424 425 l->llc_dsap = l->llc_ssap; 426 l->llc_ssap = c; 427 if (m->m_flags & (M_BCAST | M_MCAST)) 428 bcopy((caddr_t)ac->ac_enaddr, 429 (caddr_t)eh->ether_dhost, 6); 430 sa.sa_family = AF_UNSPEC; 431 sa.sa_len = sizeof(sa); 432 eh2 = (struct ether_header *)sa.sa_data; 433 for (i = 0; i < 6; i++) { 434 eh2->ether_shost[i] = c = eh->ether_dhost[i]; 435 eh2->ether_dhost[i] = 436 eh->ether_dhost[i] = eh->ether_shost[i]; 437 eh->ether_shost[i] = c; 438 } 439 ifp->if_output(ifp, m, &sa, NULL); 440 return; 441 } 442 default: 443 m_freem(m); 444 return; 445 } 446 break; 447 #endif /* ISO */ 448 #ifdef LLC 449 case LLC_X25_LSAP: 450 { 451 if (m->m_pkthdr.len > ether_type) 452 m_adj(m, ether_type - m->m_pkthdr.len); 453 M_PREPEND(m, sizeof(struct sdl_hdr) , M_DONTWAIT); 454 if (m == 0) 455 return; 456 if ( !sdl_sethdrif(ifp, eh->ether_shost, LLC_X25_LSAP, 457 eh->ether_dhost, LLC_X25_LSAP, 6, 458 mtod(m, struct sdl_hdr *))) 459 panic("ETHER cons addr failure"); 460 mtod(m, struct sdl_hdr *)->sdlhdr_len = ether_type; 461 #ifdef LLC_DEBUG 462 printf("llc packet\n"); 463 #endif /* LLC_DEBUG */ 464 schednetisr(NETISR_CCITT); 465 inq = &llcintrq; 466 break; 467 } 468 #endif /* LLC */ 469 dropanyway: 470 default: 471 m_freem(m); 472 return; 473 } 474 #else /* ISO || LLC */ 475 m_freem(m); 476 return; 477 #endif /* ISO || LLC */ 478 } 479 480 s = splimp(); 481 if (IF_QFULL(inq)) { 482 IF_DROP(inq); 483 m_freem(m); 484 } else 485 IF_ENQUEUE(inq, m); 486 splx(s); 487 } 488 489 /* 490 * Perform common duties while attaching to interface list 491 */ 492 void 493 ether_ifattach(ifp) 494 register struct ifnet *ifp; 495 { 496 register struct ifaddr *ifa; 497 register struct sockaddr_dl *sdl; 498 499 ifp->if_type = IFT_ETHER; 500 ifp->if_addrlen = 6; 501 ifp->if_hdrlen = 14; 502 ifp->if_mtu = ETHERMTU; 503 for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) 504 if ((sdl = (struct sockaddr_dl *)ifa->ifa_addr) && 505 sdl->sdl_family == AF_LINK) { 506 sdl->sdl_type = IFT_ETHER; 507 sdl->sdl_alen = ifp->if_addrlen; 508 bcopy((caddr_t)((struct arpcom *)ifp)->ac_enaddr, 509 LLADDR(sdl), ifp->if_addrlen); 510 break; 511 } 512 } 513 514 static u_char ether_ipmulticast_min[6] = 515 { 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 }; 516 static u_char ether_ipmulticast_max[6] = 517 { 0x01, 0x00, 0x5e, 0x7f, 0xff, 0xff }; 518 /* 519 * Add an Ethernet multicast address or range of addresses to the list for a 520 * given interface. 521 */ 522 int 523 ether_addmulti(ifr, ac) 524 struct ifreq *ifr; 525 register struct arpcom *ac; 526 { 527 register struct ether_multi *enm; 528 struct sockaddr_in *sin; 529 u_char addrlo[6]; 530 u_char addrhi[6]; 531 int set_allmulti = 0; 532 int s = splimp(); 533 534 switch (ifr->ifr_addr.sa_family) { 535 536 case AF_UNSPEC: 537 bcopy(ifr->ifr_addr.sa_data, addrlo, 6); 538 bcopy(addrlo, addrhi, 6); 539 break; 540 541 #ifdef INET 542 case AF_INET: 543 sin = (struct sockaddr_in *)&(ifr->ifr_addr); 544 if (sin->sin_addr.s_addr == INADDR_ANY) { 545 /* 546 * An IP address of INADDR_ANY means listen to all 547 * of the Ethernet multicast addresses used for IP. 548 * (This is for the sake of IP multicast routers.) 549 */ 550 bcopy(ether_ipmulticast_min, addrlo, 6); 551 bcopy(ether_ipmulticast_max, addrhi, 6); 552 set_allmulti = 1; 553 } 554 else { 555 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, addrlo); 556 bcopy(addrlo, addrhi, 6); 557 } 558 break; 559 #endif 560 561 default: 562 splx(s); 563 return (EAFNOSUPPORT); 564 } 565 566 /* 567 * Verify that we have valid Ethernet multicast addresses. 568 */ 569 if ((addrlo[0] & 0x01) != 1 || (addrhi[0] & 0x01) != 1) { 570 splx(s); 571 return (EINVAL); 572 } 573 /* 574 * See if the address range is already in the list. 575 */ 576 ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm); 577 if (enm != NULL) { 578 /* 579 * Found it; just increment the reference count. 580 */ 581 ++enm->enm_refcount; 582 splx(s); 583 return (0); 584 } 585 /* 586 * New address or range; malloc a new multicast record 587 * and link it into the interface's multicast list. 588 */ 589 enm = (struct ether_multi *)malloc(sizeof(*enm), M_IFMADDR, M_NOWAIT); 590 if (enm == NULL) { 591 splx(s); 592 return (ENOBUFS); 593 } 594 bcopy(addrlo, enm->enm_addrlo, 6); 595 bcopy(addrhi, enm->enm_addrhi, 6); 596 enm->enm_ac = ac; 597 enm->enm_refcount = 1; 598 enm->enm_next = ac->ac_multiaddrs; 599 ac->ac_multiaddrs = enm; 600 ac->ac_multicnt++; 601 splx(s); 602 if (set_allmulti) 603 ac->ac_if.if_flags |= IFF_ALLMULTI; 604 605 /* 606 * Return ENETRESET to inform the driver that the list has changed 607 * and its reception filter should be adjusted accordingly. 608 */ 609 return (ENETRESET); 610 } 611 612 /* 613 * Delete a multicast address record. 614 */ 615 int 616 ether_delmulti(ifr, ac) 617 struct ifreq *ifr; 618 register struct arpcom *ac; 619 { 620 register struct ether_multi *enm; 621 register struct ether_multi **p; 622 struct sockaddr_in *sin; 623 u_char addrlo[6]; 624 u_char addrhi[6]; 625 int unset_allmulti = 0; 626 int s = splimp(); 627 628 switch (ifr->ifr_addr.sa_family) { 629 630 case AF_UNSPEC: 631 bcopy(ifr->ifr_addr.sa_data, addrlo, 6); 632 bcopy(addrlo, addrhi, 6); 633 break; 634 635 #ifdef INET 636 case AF_INET: 637 sin = (struct sockaddr_in *)&(ifr->ifr_addr); 638 if (sin->sin_addr.s_addr == INADDR_ANY) { 639 /* 640 * An IP address of INADDR_ANY means stop listening 641 * to the range of Ethernet multicast addresses used 642 * for IP. 643 */ 644 bcopy(ether_ipmulticast_min, addrlo, 6); 645 bcopy(ether_ipmulticast_max, addrhi, 6); 646 unset_allmulti = 1; 647 } 648 else { 649 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, addrlo); 650 bcopy(addrlo, addrhi, 6); 651 } 652 break; 653 #endif 654 655 default: 656 splx(s); 657 return (EAFNOSUPPORT); 658 } 659 660 /* 661 * Look up the address in our list. 662 */ 663 ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm); 664 if (enm == NULL) { 665 splx(s); 666 return (ENXIO); 667 } 668 if (--enm->enm_refcount != 0) { 669 /* 670 * Still some claims to this record. 671 */ 672 splx(s); 673 return (0); 674 } 675 /* 676 * No remaining claims to this record; unlink and free it. 677 */ 678 for (p = &enm->enm_ac->ac_multiaddrs; 679 *p != enm; 680 p = &(*p)->enm_next) 681 continue; 682 *p = (*p)->enm_next; 683 free(enm, M_IFMADDR); 684 ac->ac_multicnt--; 685 splx(s); 686 if (unset_allmulti) 687 ac->ac_if.if_flags &= ~IFF_ALLMULTI; 688 689 /* 690 * Return ENETRESET to inform the driver that the list has changed 691 * and its reception filter should be adjusted accordingly. 692 */ 693 return (ENETRESET); 694 } 695 696 SYSCTL_NODE(_net_link, IFT_ETHER, ether, CTLFLAG_RW, 0, "Ethernet"); 697