1 /* $NetBSD: if_ethersubr.c,v 1.12 1995/04/07 22:19:29 mycroft Exp $ */ 2 3 /* 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 * @(#)if_ethersubr.c 8.1 (Berkeley) 6/10/93 36 */ 37 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/kernel.h> 41 #include <sys/malloc.h> 42 #include <sys/mbuf.h> 43 #include <sys/protosw.h> 44 #include <sys/socket.h> 45 #include <sys/ioctl.h> 46 #include <sys/errno.h> 47 #include <sys/syslog.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 NS 65 #include <netns/ns.h> 66 #include <netns/ns_if.h> 67 #endif 68 69 #ifdef ISO 70 #include <netiso/argo_debug.h> 71 #include <netiso/iso.h> 72 #include <netiso/iso_var.h> 73 #include <netiso/iso_snpac.h> 74 #endif 75 76 #ifdef LLC 77 #include <netccitt/dll.h> 78 #include <netccitt/llc_var.h> 79 #endif 80 81 #if defined(LLC) && defined(CCITT) 82 extern struct ifqueue pkintrq; 83 #endif 84 85 u_char etherbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 86 #define senderr(e) { error = (e); goto bad;} 87 88 /* 89 * Ethernet output routine. 90 * Encapsulate a packet of type family for the local net. 91 * Use trailer local net encapsulation if enough data in first 92 * packet leaves a multiple of 512 bytes of data in remainder. 93 * Assumes that ifp is actually pointer to arpcom structure. 94 */ 95 int 96 ether_output(ifp, m0, dst, rt0) 97 register struct ifnet *ifp; 98 struct mbuf *m0; 99 struct sockaddr *dst; 100 struct rtentry *rt0; 101 { 102 u_int16_t etype; 103 int s, error = 0; 104 u_char edst[6]; 105 register struct mbuf *m = m0; 106 register struct rtentry *rt; 107 struct mbuf *mcopy = (struct mbuf *)0; 108 register struct ether_header *eh; 109 int off, len = m->m_pkthdr.len; 110 struct arpcom *ac = (struct arpcom *)ifp; 111 112 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) 113 senderr(ENETDOWN); 114 ifp->if_lastchange = time; 115 if (rt = rt0) { 116 if ((rt->rt_flags & RTF_UP) == 0) { 117 if (rt0 = rt = rtalloc1(dst, 1)) 118 rt->rt_refcnt--; 119 else 120 senderr(EHOSTUNREACH); 121 } 122 if (rt->rt_flags & RTF_GATEWAY) { 123 if (rt->rt_gwroute == 0) 124 goto lookup; 125 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { 126 rtfree(rt); rt = rt0; 127 lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1); 128 if ((rt = rt->rt_gwroute) == 0) 129 senderr(EHOSTUNREACH); 130 } 131 } 132 if (rt->rt_flags & RTF_REJECT) 133 if (rt->rt_rmx.rmx_expire == 0 || 134 time.tv_sec < rt->rt_rmx.rmx_expire) 135 senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH); 136 } 137 switch (dst->sa_family) { 138 139 #ifdef INET 140 case AF_INET: 141 if (!arpresolve(ac, rt, m, dst, edst)) 142 return (0); /* if not yet resolved */ 143 /* If broadcasting on a simplex interface, loopback a copy */ 144 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX)) 145 mcopy = m_copy(m, 0, (int)M_COPYALL); 146 off = m->m_pkthdr.len - m->m_len; 147 etype = ETHERTYPE_IP; 148 break; 149 #endif 150 #ifdef NS 151 case AF_NS: 152 etype = ETHERTYPE_NS; 153 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), 154 (caddr_t)edst, sizeof (edst)); 155 if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost, sizeof(edst))) 156 return (looutput(ifp, m, dst, rt)); 157 /* If broadcasting on a simplex interface, loopback a copy */ 158 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX)) 159 mcopy = m_copy(m, 0, (int)M_COPYALL); 160 break; 161 #endif 162 #ifdef ISO 163 case AF_ISO: { 164 int snpalen; 165 struct llc *l; 166 register struct sockaddr_dl *sdl; 167 168 if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) && 169 sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) { 170 bcopy(LLADDR(sdl), (caddr_t)edst, sizeof(edst)); 171 } else if (error = 172 iso_snparesolve(ifp, (struct sockaddr_iso *)dst, 173 (char *)edst, &snpalen)) 174 goto bad; /* Not Resolved */ 175 /* If broadcasting on a simplex interface, loopback a copy */ 176 if (*edst & 1) 177 m->m_flags |= (M_BCAST|M_MCAST); 178 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX) && 179 (mcopy = m_copy(m, 0, (int)M_COPYALL))) { 180 M_PREPEND(mcopy, sizeof (*eh), M_DONTWAIT); 181 if (mcopy) { 182 eh = mtod(mcopy, struct ether_header *); 183 bcopy((caddr_t)edst, 184 (caddr_t)eh->ether_dhost, sizeof (edst)); 185 bcopy((caddr_t)ac->ac_enaddr, 186 (caddr_t)eh->ether_shost, sizeof (edst)); 187 } 188 } 189 M_PREPEND(m, 3, M_DONTWAIT); 190 if (m == NULL) 191 return (0); 192 etype = m->m_pkthdr.len; 193 l = mtod(m, struct llc *); 194 l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP; 195 l->llc_control = LLC_UI; 196 len += 3; 197 IFDEBUG(D_ETHER) 198 int i; 199 printf("unoutput: sending pkt to: "); 200 for (i=0; i<6; i++) 201 printf("%x ", edst[i] & 0xff); 202 printf("\n"); 203 ENDDEBUG 204 } break; 205 #endif /* ISO */ 206 #ifdef LLC 207 /* case AF_NSAP: */ 208 case AF_CCITT: { 209 register struct sockaddr_dl *sdl = 210 (struct sockaddr_dl *) rt -> rt_gateway; 211 212 if (sdl && sdl->sdl_family == AF_LINK 213 && sdl->sdl_alen > 0) { 214 bcopy(LLADDR(sdl), (char *)edst, 215 sizeof(edst)); 216 } else goto bad; /* Not a link interface ? Funny ... */ 217 if ((ifp->if_flags & IFF_SIMPLEX) && (*edst & 1) && 218 (mcopy = m_copy(m, 0, (int)M_COPYALL))) { 219 M_PREPEND(mcopy, sizeof (*eh), M_DONTWAIT); 220 if (mcopy) { 221 eh = mtod(mcopy, struct ether_header *); 222 bcopy((caddr_t)edst, 223 (caddr_t)eh->ether_dhost, sizeof (edst)); 224 bcopy((caddr_t)ac->ac_enaddr, 225 (caddr_t)eh->ether_shost, sizeof (edst)); 226 } 227 } 228 etype = m->m_pkthdr.len; 229 #ifdef LLC_DEBUG 230 { 231 int i; 232 register struct llc *l = mtod(m, struct llc *); 233 234 printf("ether_output: sending LLC2 pkt to: "); 235 for (i=0; i<6; i++) 236 printf("%x ", edst[i] & 0xff); 237 printf(" len 0x%x dsap 0x%x ssap 0x%x control 0x%x\n", 238 etype & 0xff, l->llc_dsap & 0xff, l->llc_ssap &0xff, 239 l->llc_control & 0xff); 240 241 } 242 #endif /* LLC_DEBUG */ 243 } break; 244 #endif /* LLC */ 245 246 case AF_UNSPEC: 247 eh = (struct ether_header *)dst->sa_data; 248 bcopy((caddr_t)eh->ether_dhost, (caddr_t)edst, sizeof (edst)); 249 /* AF_UNSPEC doesn't swap the byte order of the ether_type. */ 250 etype = ntohs(eh->ether_type); 251 break; 252 253 default: 254 printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit, 255 dst->sa_family); 256 senderr(EAFNOSUPPORT); 257 } 258 259 260 if (mcopy) 261 (void) looutput(ifp, mcopy, dst, rt); 262 /* 263 * Add local net header. If no space in first mbuf, 264 * allocate another. 265 */ 266 M_PREPEND(m, sizeof (struct ether_header), M_DONTWAIT); 267 if (m == 0) 268 senderr(ENOBUFS); 269 eh = mtod(m, struct ether_header *); 270 etype = htons(etype); 271 bcopy((caddr_t)&etype,(caddr_t)&eh->ether_type, 272 sizeof(eh->ether_type)); 273 bcopy((caddr_t)edst, (caddr_t)eh->ether_dhost, sizeof (edst)); 274 bcopy((caddr_t)ac->ac_enaddr, (caddr_t)eh->ether_shost, 275 sizeof(eh->ether_shost)); 276 s = splimp(); 277 /* 278 * Queue message on interface, and start output if interface 279 * not yet active. 280 */ 281 if (IF_QFULL(&ifp->if_snd)) { 282 IF_DROP(&ifp->if_snd); 283 splx(s); 284 senderr(ENOBUFS); 285 } 286 IF_ENQUEUE(&ifp->if_snd, m); 287 if ((ifp->if_flags & IFF_OACTIVE) == 0) 288 (*ifp->if_start)(ifp); 289 splx(s); 290 ifp->if_obytes += len + sizeof (struct ether_header); 291 if (m->m_flags & M_MCAST) 292 ifp->if_omcasts++; 293 return (error); 294 295 bad: 296 if (m) 297 m_freem(m); 298 return (error); 299 } 300 301 /* 302 * Process a received Ethernet packet; 303 * the packet is in the mbuf chain m without 304 * the ether header, which is provided separately. 305 */ 306 void 307 ether_input(ifp, eh, m) 308 struct ifnet *ifp; 309 register struct ether_header *eh; 310 struct mbuf *m; 311 { 312 register struct ifqueue *inq; 313 register struct llc *l; 314 u_int16_t etype; 315 struct arpcom *ac = (struct arpcom *)ifp; 316 int s; 317 318 if ((ifp->if_flags & IFF_UP) == 0) { 319 m_freem(m); 320 return; 321 } 322 ifp->if_lastchange = time; 323 ifp->if_ibytes += m->m_pkthdr.len + sizeof (*eh); 324 if (eh->ether_dhost[0] & 1) { 325 if (bcmp((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost, 326 sizeof(etherbroadcastaddr)) == 0) 327 m->m_flags |= M_BCAST; 328 else 329 m->m_flags |= M_MCAST; 330 } 331 if (m->m_flags & (M_BCAST|M_MCAST)) 332 ifp->if_imcasts++; 333 334 etype = ntohs(eh->ether_type); 335 switch (etype) { 336 #ifdef INET 337 case ETHERTYPE_IP: 338 schednetisr(NETISR_IP); 339 inq = &ipintrq; 340 break; 341 342 case ETHERTYPE_ARP: 343 schednetisr(NETISR_ARP); 344 inq = &arpintrq; 345 break; 346 347 case ETHERTYPE_REVARP: 348 revarpinput(m); /* XXX queue? */ 349 return; 350 #endif 351 #ifdef NS 352 case ETHERTYPE_NS: 353 schednetisr(NETISR_NS); 354 inq = &nsintrq; 355 break; 356 357 #endif 358 default: 359 #if defined (ISO) || defined (LLC) 360 if (etype > ETHERMTU) 361 goto dropanyway; 362 l = mtod(m, struct llc *); 363 switch (l->llc_dsap) { 364 #ifdef ISO 365 case LLC_ISO_LSAP: 366 switch (l->llc_control) { 367 case LLC_UI: 368 /* LLC_UI_P forbidden in class 1 service */ 369 if ((l->llc_dsap == LLC_ISO_LSAP) && 370 (l->llc_ssap == LLC_ISO_LSAP)) { 371 /* LSAP for ISO */ 372 if (m->m_pkthdr.len > etype) 373 m_adj(m, etype - m->m_pkthdr.len); 374 m->m_data += 3; /* XXX */ 375 m->m_len -= 3; /* XXX */ 376 m->m_pkthdr.len -= 3; /* XXX */ 377 M_PREPEND(m, sizeof *eh, M_DONTWAIT); 378 if (m == 0) 379 return; 380 *mtod(m, struct ether_header *) = *eh; 381 IFDEBUG(D_ETHER) 382 printf("clnp packet"); 383 ENDDEBUG 384 schednetisr(NETISR_ISO); 385 inq = &clnlintrq; 386 break; 387 } 388 goto dropanyway; 389 390 case LLC_XID: 391 case LLC_XID_P: 392 if(m->m_len < 6) 393 goto dropanyway; 394 l->llc_window = 0; 395 l->llc_fid = 9; 396 l->llc_class = 1; 397 l->llc_dsap = l->llc_ssap = 0; 398 /* Fall through to */ 399 case LLC_TEST: 400 case LLC_TEST_P: 401 { 402 struct sockaddr sa; 403 register struct ether_header *eh2; 404 int i; 405 u_char c = l->llc_dsap; 406 407 l->llc_dsap = l->llc_ssap; 408 l->llc_ssap = c; 409 if (m->m_flags & (M_BCAST | M_MCAST)) 410 bcopy((caddr_t)ac->ac_enaddr, 411 (caddr_t)eh->ether_dhost, 6); 412 sa.sa_family = AF_UNSPEC; 413 sa.sa_len = sizeof(sa); 414 eh2 = (struct ether_header *)sa.sa_data; 415 for (i = 0; i < 6; i++) { 416 eh2->ether_shost[i] = c = eh->ether_dhost[i]; 417 eh2->ether_dhost[i] = 418 eh->ether_dhost[i] = eh->ether_shost[i]; 419 eh->ether_shost[i] = c; 420 } 421 ifp->if_output(ifp, m, &sa, NULL); 422 return; 423 } 424 default: 425 m_freem(m); 426 return; 427 } 428 break; 429 #endif /* ISO */ 430 #ifdef LLC 431 case LLC_X25_LSAP: 432 { 433 if (m->m_pkthdr.len > etype) 434 m_adj(m, etype - m->m_pkthdr.len); 435 M_PREPEND(m, sizeof(struct sdl_hdr) , M_DONTWAIT); 436 if (m == 0) 437 return; 438 if ( !sdl_sethdrif(ifp, eh->ether_shost, LLC_X25_LSAP, 439 eh->ether_dhost, LLC_X25_LSAP, 6, 440 mtod(m, struct sdl_hdr *))) 441 panic("ETHER cons addr failure"); 442 mtod(m, struct sdl_hdr *)->sdlhdr_len = etype; 443 #ifdef LLC_DEBUG 444 printf("llc packet\n"); 445 #endif /* LLC_DEBUG */ 446 schednetisr(NETISR_CCITT); 447 inq = &llcintrq; 448 break; 449 } 450 #endif /* LLC */ 451 dropanyway: 452 default: 453 m_freem(m); 454 return; 455 } 456 #else /* ISO || LLC */ 457 m_freem(m); 458 return; 459 #endif /* ISO || LLC */ 460 } 461 462 s = splimp(); 463 if (IF_QFULL(inq)) { 464 IF_DROP(inq); 465 m_freem(m); 466 } else 467 IF_ENQUEUE(inq, m); 468 splx(s); 469 } 470 471 /* 472 * Convert Ethernet address to printable (loggable) representation. 473 */ 474 static char digits[] = "0123456789abcdef"; 475 char * 476 ether_sprintf(ap) 477 register u_char *ap; 478 { 479 register i; 480 static char etherbuf[18]; 481 register char *cp = etherbuf; 482 483 for (i = 0; i < 6; i++) { 484 *cp++ = digits[*ap >> 4]; 485 *cp++ = digits[*ap++ & 0xf]; 486 *cp++ = ':'; 487 } 488 *--cp = 0; 489 return (etherbuf); 490 } 491 492 /* 493 * Perform common duties while attaching to interface list 494 */ 495 void 496 ether_ifattach(ifp) 497 register struct ifnet *ifp; 498 { 499 register struct ifaddr *ifa; 500 register struct sockaddr_dl *sdl; 501 502 ifp->if_type = IFT_ETHER; 503 ifp->if_addrlen = 6; 504 ifp->if_hdrlen = 14; 505 ifp->if_mtu = ETHERMTU; 506 ifp->if_output = ether_output; 507 for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) 508 if ((sdl = (struct sockaddr_dl *)ifa->ifa_addr) && 509 sdl->sdl_family == AF_LINK) { 510 sdl->sdl_type = IFT_ETHER; 511 sdl->sdl_alen = ifp->if_addrlen; 512 bcopy((caddr_t)((struct arpcom *)ifp)->ac_enaddr, 513 LLADDR(sdl), ifp->if_addrlen); 514 break; 515 } 516 } 517 518 u_char ether_ipmulticast_min[6] = { 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 }; 519 u_char ether_ipmulticast_max[6] = { 0x01, 0x00, 0x5e, 0x7f, 0xff, 0xff }; 520 /* 521 * Add an Ethernet multicast address or range of addresses to the list for a 522 * given interface. 523 */ 524 int 525 ether_addmulti(ifr, ac) 526 struct ifreq *ifr; 527 register struct arpcom *ac; 528 { 529 register struct ether_multi *enm; 530 struct sockaddr_in *sin; 531 u_char addrlo[6]; 532 u_char addrhi[6]; 533 int s = splimp(); 534 535 switch (ifr->ifr_addr.sa_family) { 536 537 case AF_UNSPEC: 538 bcopy(ifr->ifr_addr.sa_data, addrlo, 6); 539 bcopy(addrlo, addrhi, 6); 540 break; 541 542 #ifdef INET 543 case AF_INET: 544 sin = (struct sockaddr_in *)&(ifr->ifr_addr); 545 if (sin->sin_addr.s_addr == INADDR_ANY) { 546 /* 547 * An IP address of INADDR_ANY means listen to all 548 * of the Ethernet multicast addresses used for IP. 549 * (This is for the sake of IP multicast routers.) 550 */ 551 bcopy(ether_ipmulticast_min, addrlo, 6); 552 bcopy(ether_ipmulticast_max, addrhi, 6); 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 /* 603 * Return ENETRESET to inform the driver that the list has changed 604 * and its reception filter should be adjusted accordingly. 605 */ 606 return (ENETRESET); 607 } 608 609 /* 610 * Delete a multicast address record. 611 */ 612 int 613 ether_delmulti(ifr, ac) 614 struct ifreq *ifr; 615 register struct arpcom *ac; 616 { 617 register struct ether_multi *enm; 618 register struct ether_multi **p; 619 struct sockaddr_in *sin; 620 u_char addrlo[6]; 621 u_char addrhi[6]; 622 int s = splimp(); 623 624 switch (ifr->ifr_addr.sa_family) { 625 626 case AF_UNSPEC: 627 bcopy(ifr->ifr_addr.sa_data, addrlo, 6); 628 bcopy(addrlo, addrhi, 6); 629 break; 630 631 #ifdef INET 632 case AF_INET: 633 sin = (struct sockaddr_in *)&(ifr->ifr_addr); 634 if (sin->sin_addr.s_addr == INADDR_ANY) { 635 /* 636 * An IP address of INADDR_ANY means stop listening 637 * to the range of Ethernet multicast addresses used 638 * for IP. 639 */ 640 bcopy(ether_ipmulticast_min, addrlo, 6); 641 bcopy(ether_ipmulticast_max, addrhi, 6); 642 } 643 else { 644 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, addrlo); 645 bcopy(addrlo, addrhi, 6); 646 } 647 break; 648 #endif 649 650 default: 651 splx(s); 652 return (EAFNOSUPPORT); 653 } 654 655 /* 656 * Look up the address in our list. 657 */ 658 ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm); 659 if (enm == NULL) { 660 splx(s); 661 return (ENXIO); 662 } 663 if (--enm->enm_refcount != 0) { 664 /* 665 * Still some claims to this record. 666 */ 667 splx(s); 668 return (0); 669 } 670 /* 671 * No remaining claims to this record; unlink and free it. 672 */ 673 for (p = &enm->enm_ac->ac_multiaddrs; 674 *p != enm; 675 p = &(*p)->enm_next) 676 continue; 677 *p = (*p)->enm_next; 678 free(enm, M_IFMADDR); 679 ac->ac_multicnt--; 680 splx(s); 681 /* 682 * Return ENETRESET to inform the driver that the list has changed 683 * and its reception filter should be adjusted accordingly. 684 */ 685 return (ENETRESET); 686 } 687