if_ethersubr.c revision 1.9 1 /* $NetBSD: if_ethersubr.c,v 1.9 1994/06/29 06:36:11 cgd 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 extern struct ifnet loif;
87 #define senderr(e) { error = (e); goto bad;}
88
89 /*
90 * Ethernet output routine.
91 * Encapsulate a packet of type family for the local net.
92 * Use trailer local net encapsulation if enough data in first
93 * packet leaves a multiple of 512 bytes of data in remainder.
94 * Assumes that ifp is actually pointer to arpcom structure.
95 */
96 int
97 ether_output(ifp, m0, dst, rt0)
98 register struct ifnet *ifp;
99 struct mbuf *m0;
100 struct sockaddr *dst;
101 struct rtentry *rt0;
102 {
103 u_short etype;
104 int s, error = 0;
105 u_char edst[6];
106 register struct mbuf *m = m0;
107 register struct rtentry *rt;
108 struct mbuf *mcopy = (struct mbuf *)0;
109 register struct ether_header *eh;
110 int off, len = m->m_pkthdr.len;
111 struct arpcom *ac = (struct arpcom *)ifp;
112
113 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
114 senderr(ENETDOWN);
115 ifp->if_lastchange = time;
116 if (rt = rt0) {
117 if ((rt->rt_flags & RTF_UP) == 0) {
118 if (rt0 = rt = rtalloc1(dst, 1))
119 rt->rt_refcnt--;
120 else
121 senderr(EHOSTUNREACH);
122 }
123 if (rt->rt_flags & RTF_GATEWAY) {
124 if (rt->rt_gwroute == 0)
125 goto lookup;
126 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) {
127 rtfree(rt); rt = rt0;
128 lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1);
129 if ((rt = rt->rt_gwroute) == 0)
130 senderr(EHOSTUNREACH);
131 }
132 }
133 if (rt->rt_flags & RTF_REJECT)
134 if (rt->rt_rmx.rmx_expire == 0 ||
135 time.tv_sec < rt->rt_rmx.rmx_expire)
136 senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH);
137 }
138 switch (dst->sa_family) {
139
140 #ifdef INET
141 case AF_INET:
142 if (!arpresolve(ac, rt, m, dst, edst))
143 return (0); /* if not yet resolved */
144 /* If broadcasting on a simplex interface, loopback a copy */
145 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
146 mcopy = m_copy(m, 0, (int)M_COPYALL);
147 off = m->m_pkthdr.len - m->m_len;
148 etype = ETHERTYPE_IP;
149 break;
150 #endif
151 #ifdef NS
152 case AF_NS:
153 etype = ETHERTYPE_NS;
154 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host),
155 (caddr_t)edst, sizeof (edst));
156 if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost, sizeof(edst)))
157 return (looutput(ifp, m, dst, rt));
158 /* If broadcasting on a simplex interface, loopback a copy */
159 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
160 mcopy = m_copy(m, 0, (int)M_COPYALL);
161 break;
162 #endif
163 #ifdef ISO
164 case AF_ISO: {
165 int snpalen;
166 struct llc *l;
167 register struct sockaddr_dl *sdl;
168
169 if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) &&
170 sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) {
171 bcopy(LLADDR(sdl), (caddr_t)edst, sizeof(edst));
172 } else if (error =
173 iso_snparesolve(ifp, (struct sockaddr_iso *)dst,
174 (char *)edst, &snpalen))
175 goto bad; /* Not Resolved */
176 /* If broadcasting on a simplex interface, loopback a copy */
177 if (*edst & 1)
178 m->m_flags |= (M_BCAST|M_MCAST);
179 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX) &&
180 (mcopy = m_copy(m, 0, (int)M_COPYALL))) {
181 M_PREPEND(mcopy, sizeof (*eh), M_DONTWAIT);
182 if (mcopy) {
183 eh = mtod(mcopy, struct ether_header *);
184 bcopy((caddr_t)edst,
185 (caddr_t)eh->ether_dhost, sizeof (edst));
186 bcopy((caddr_t)ac->ac_enaddr,
187 (caddr_t)eh->ether_shost, sizeof (edst));
188 }
189 }
190 M_PREPEND(m, 3, M_DONTWAIT);
191 if (m == NULL)
192 return (0);
193 etype = m->m_pkthdr.len;
194 l = mtod(m, struct llc *);
195 l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP;
196 l->llc_control = LLC_UI;
197 len += 3;
198 IFDEBUG(D_ETHER)
199 int i;
200 printf("unoutput: sending pkt to: ");
201 for (i=0; i<6; i++)
202 printf("%x ", edst[i] & 0xff);
203 printf("\n");
204 ENDDEBUG
205 } break;
206 #endif /* ISO */
207 #ifdef LLC
208 /* case AF_NSAP: */
209 case AF_CCITT: {
210 register struct sockaddr_dl *sdl =
211 (struct sockaddr_dl *) rt -> rt_gateway;
212
213 if (sdl && sdl->sdl_family == AF_LINK
214 && sdl->sdl_alen > 0) {
215 bcopy(LLADDR(sdl), (char *)edst,
216 sizeof(edst));
217 } else goto bad; /* Not a link interface ? Funny ... */
218 if ((ifp->if_flags & IFF_SIMPLEX) && (*edst & 1) &&
219 (mcopy = m_copy(m, 0, (int)M_COPYALL))) {
220 M_PREPEND(mcopy, sizeof (*eh), M_DONTWAIT);
221 if (mcopy) {
222 eh = mtod(mcopy, struct ether_header *);
223 bcopy((caddr_t)edst,
224 (caddr_t)eh->ether_dhost, sizeof (edst));
225 bcopy((caddr_t)ac->ac_enaddr,
226 (caddr_t)eh->ether_shost, sizeof (edst));
227 }
228 }
229 etype = m->m_pkthdr.len;
230 #ifdef LLC_DEBUG
231 {
232 int i;
233 register struct llc *l = mtod(m, struct llc *);
234
235 printf("ether_output: sending LLC2 pkt to: ");
236 for (i=0; i<6; i++)
237 printf("%x ", edst[i] & 0xff);
238 printf(" len 0x%x dsap 0x%x ssap 0x%x control 0x%x\n",
239 etype & 0xff, l->llc_dsap & 0xff, l->llc_ssap &0xff,
240 l->llc_control & 0xff);
241
242 }
243 #endif /* LLC_DEBUG */
244 } break;
245 #endif /* LLC */
246
247 case AF_UNSPEC:
248 eh = (struct ether_header *)dst->sa_data;
249 bcopy((caddr_t)eh->ether_dhost, (caddr_t)edst, sizeof (edst));
250 /* AF_UNSPEC doesn't swap the byte order of the ether_type. */
251 etype = ntohs(eh->ether_type);
252 break;
253
254 default:
255 printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit,
256 dst->sa_family);
257 senderr(EAFNOSUPPORT);
258 }
259
260
261 if (mcopy)
262 (void) looutput(ifp, mcopy, dst, rt);
263 /*
264 * Add local net header. If no space in first mbuf,
265 * allocate another.
266 */
267 M_PREPEND(m, sizeof (struct ether_header), M_DONTWAIT);
268 if (m == 0)
269 senderr(ENOBUFS);
270 eh = mtod(m, struct ether_header *);
271 etype = htons(etype);
272 bcopy((caddr_t)&etype,(caddr_t)&eh->ether_type,
273 sizeof(eh->ether_type));
274 bcopy((caddr_t)edst, (caddr_t)eh->ether_dhost, sizeof (edst));
275 bcopy((caddr_t)ac->ac_enaddr, (caddr_t)eh->ether_shost,
276 sizeof(eh->ether_shost));
277 s = splimp();
278 /*
279 * Queue message on interface, and start output if interface
280 * not yet active.
281 */
282 if (IF_QFULL(&ifp->if_snd)) {
283 IF_DROP(&ifp->if_snd);
284 splx(s);
285 senderr(ENOBUFS);
286 }
287 IF_ENQUEUE(&ifp->if_snd, m);
288 if ((ifp->if_flags & IFF_OACTIVE) == 0)
289 (*ifp->if_start)(ifp);
290 splx(s);
291 ifp->if_obytes += len + sizeof (struct ether_header);
292 if (m->m_flags & M_MCAST)
293 ifp->if_omcasts++;
294 return (error);
295
296 bad:
297 if (m)
298 m_freem(m);
299 return (error);
300 }
301
302 /*
303 * Process a received Ethernet packet;
304 * the packet is in the mbuf chain m without
305 * the ether header, which is provided separately.
306 */
307 void
308 ether_input(ifp, eh, m)
309 struct ifnet *ifp;
310 register struct ether_header *eh;
311 struct mbuf *m;
312 {
313 register struct ifqueue *inq;
314 register struct llc *l;
315 u_short etype;
316 struct arpcom *ac = (struct arpcom *)ifp;
317 int s;
318
319 if ((ifp->if_flags & IFF_UP) == 0) {
320 m_freem(m);
321 return;
322 }
323 ifp->if_lastchange = time;
324 ifp->if_ibytes += m->m_pkthdr.len + sizeof (*eh);
325 if (eh->ether_dhost[0] & 1) {
326 if (bcmp((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost,
327 sizeof(etherbroadcastaddr)) == 0)
328 m->m_flags |= M_BCAST;
329 else
330 m->m_flags |= M_MCAST;
331 }
332 if (m->m_flags & (M_BCAST|M_MCAST))
333 ifp->if_imcasts++;
334
335 etype = ntohs(eh->ether_type);
336 switch (etype) {
337 #ifdef INET
338 case ETHERTYPE_IP:
339 schednetisr(NETISR_IP);
340 inq = &ipintrq;
341 break;
342
343 case ETHERTYPE_ARP:
344 schednetisr(NETISR_ARP);
345 inq = &arpintrq;
346 break;
347
348 case ETHERTYPE_REVARP:
349 revarpinput(m); /* XXX queue? */
350 return;
351 #endif
352 #ifdef NS
353 case ETHERTYPE_NS:
354 schednetisr(NETISR_NS);
355 inq = &nsintrq;
356 break;
357
358 #endif
359 default:
360 #if defined (ISO) || defined (LLC)
361 if (eh->ether_type > ETHERMTU)
362 goto dropanyway;
363 l = mtod(m, struct llc *);
364 switch (l->llc_dsap) {
365 #ifdef ISO
366 case LLC_ISO_LSAP:
367 switch (l->llc_control) {
368 case LLC_UI:
369 /* LLC_UI_P forbidden in class 1 service */
370 if ((l->llc_dsap == LLC_ISO_LSAP) &&
371 (l->llc_ssap == LLC_ISO_LSAP)) {
372 /* LSAP for ISO */
373 if (m->m_pkthdr.len > eh->ether_type)
374 m_adj(m, eh->ether_type - m->m_pkthdr.len);
375 m->m_data += 3; /* XXX */
376 m->m_len -= 3; /* XXX */
377 m->m_pkthdr.len -= 3; /* XXX */
378 M_PREPEND(m, sizeof *eh, M_DONTWAIT);
379 if (m == 0)
380 return;
381 *mtod(m, struct ether_header *) = *eh;
382 IFDEBUG(D_ETHER)
383 printf("clnp packet");
384 ENDDEBUG
385 schednetisr(NETISR_ISO);
386 inq = &clnlintrq;
387 break;
388 }
389 goto dropanyway;
390
391 case LLC_XID:
392 case LLC_XID_P:
393 if(m->m_len < 6)
394 goto dropanyway;
395 l->llc_window = 0;
396 l->llc_fid = 9;
397 l->llc_class = 1;
398 l->llc_dsap = l->llc_ssap = 0;
399 /* Fall through to */
400 case LLC_TEST:
401 case LLC_TEST_P:
402 {
403 struct sockaddr sa;
404 register struct ether_header *eh2;
405 int i;
406 u_char c = l->llc_dsap;
407
408 l->llc_dsap = l->llc_ssap;
409 l->llc_ssap = c;
410 if (m->m_flags & (M_BCAST | M_MCAST))
411 bcopy((caddr_t)ac->ac_enaddr,
412 (caddr_t)eh->ether_dhost, 6);
413 sa.sa_family = AF_UNSPEC;
414 sa.sa_len = sizeof(sa);
415 eh2 = (struct ether_header *)sa.sa_data;
416 for (i = 0; i < 6; i++) {
417 eh2->ether_shost[i] = c = eh->ether_dhost[i];
418 eh2->ether_dhost[i] =
419 eh->ether_dhost[i] = eh->ether_shost[i];
420 eh->ether_shost[i] = c;
421 }
422 ifp->if_output(ifp, m, &sa, NULL);
423 return;
424 }
425 default:
426 m_freem(m);
427 return;
428 }
429 break;
430 #endif /* ISO */
431 #ifdef LLC
432 case LLC_X25_LSAP:
433 {
434 if (m->m_pkthdr.len > eh->ether_type)
435 m_adj(m, eh->ether_type - m->m_pkthdr.len);
436 M_PREPEND(m, sizeof(struct sdl_hdr) , M_DONTWAIT);
437 if (m == 0)
438 return;
439 if ( !sdl_sethdrif(ifp, eh->ether_shost, LLC_X25_LSAP,
440 eh->ether_dhost, LLC_X25_LSAP, 6,
441 mtod(m, struct sdl_hdr *)))
442 panic("ETHER cons addr failure");
443 mtod(m, struct sdl_hdr *)->sdlhdr_len = eh->ether_type;
444 #ifdef LLC_DEBUG
445 printf("llc packet\n");
446 #endif /* LLC_DEBUG */
447 schednetisr(NETISR_CCITT);
448 inq = &llcintrq;
449 break;
450 }
451 #endif /* LLC */
452 dropanyway:
453 default:
454 m_freem(m);
455 return;
456 }
457 #else /* ISO || LLC */
458 m_freem(m);
459 return;
460 #endif /* ISO || LLC */
461 }
462
463 s = splimp();
464 if (IF_QFULL(inq)) {
465 IF_DROP(inq);
466 m_freem(m);
467 } else
468 IF_ENQUEUE(inq, m);
469 splx(s);
470 }
471
472 /*
473 * Convert Ethernet address to printable (loggable) representation.
474 */
475 static char digits[] = "0123456789abcdef";
476 char *
477 ether_sprintf(ap)
478 register u_char *ap;
479 {
480 register i;
481 static char etherbuf[18];
482 register char *cp = etherbuf;
483
484 for (i = 0; i < 6; i++) {
485 *cp++ = digits[*ap >> 4];
486 *cp++ = digits[*ap++ & 0xf];
487 *cp++ = ':';
488 }
489 *--cp = 0;
490 return (etherbuf);
491 }
492
493 /*
494 * Perform common duties while attaching to interface list
495 */
496 void
497 ether_ifattach(ifp)
498 register struct ifnet *ifp;
499 {
500 register struct ifaddr *ifa;
501 register struct sockaddr_dl *sdl;
502
503 ifp->if_type = IFT_ETHER;
504 ifp->if_addrlen = 6;
505 ifp->if_hdrlen = 14;
506 ifp->if_mtu = ETHERMTU;
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