if_ethersubr.c revision 1.1.1.3 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.2 (Berkeley) 4/4/96
34 */
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/malloc.h>
40 #include <sys/mbuf.h>
41 #include <sys/protosw.h>
42 #include <sys/socket.h>
43 #include <sys/ioctl.h>
44 #include <sys/errno.h>
45 #include <sys/syslog.h>
46
47 #include <machine/cpu.h>
48
49 #include <net/if.h>
50 #include <net/netisr.h>
51 #include <net/route.h>
52 #include <net/if_llc.h>
53 #include <net/if_dl.h>
54 #include <net/if_types.h>
55
56 #ifdef INET
57 #include <netinet/in.h>
58 #include <netinet/in_var.h>
59 #endif
60 #include <netinet/if_ether.h>
61
62 #ifdef NS
63 #include <netns/ns.h>
64 #include <netns/ns_if.h>
65 #endif
66
67 #ifdef ISO
68 #include <netiso/argo_debug.h>
69 #include <netiso/iso.h>
70 #include <netiso/iso_var.h>
71 #include <netiso/iso_snpac.h>
72 #endif
73
74 #ifdef LLC
75 #include <netccitt/dll.h>
76 #include <netccitt/llc_var.h>
77 #endif
78
79 #if defined(LLC) && defined(CCITT)
80 extern struct ifqueue pkintrq;
81 #endif
82
83 u_char etherbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
84 extern struct ifnet loif;
85 #define senderr(e) { error = (e); goto bad;}
86
87 /*
88 * Ethernet output routine.
89 * Encapsulate a packet of type family for the local net.
90 * Use trailer local net encapsulation if enough data in first
91 * packet leaves a multiple of 512 bytes of data in remainder.
92 * Assumes that ifp is actually pointer to arpcom structure.
93 */
94 int
95 ether_output(ifp, m0, dst, rt0)
96 register struct ifnet *ifp;
97 struct mbuf *m0;
98 struct sockaddr *dst;
99 struct rtentry *rt0;
100 {
101 short type;
102 int s, error = 0;
103 u_char edst[6];
104 register struct mbuf *m = m0;
105 register struct rtentry *rt;
106 struct mbuf *mcopy = (struct mbuf *)0;
107 register struct ether_header *eh;
108 int off, len = m->m_pkthdr.len;
109 struct arpcom *ac = (struct arpcom *)ifp;
110
111 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
112 senderr(ENETDOWN);
113 ifp->if_lastchange = time;
114 if (rt = rt0) {
115 if ((rt->rt_flags & RTF_UP) == 0) {
116 if (rt0 = rt = rtalloc1(dst, 1)) {
117 rt->rt_refcnt--;
118 if (rt->rt_ifp != ifp)
119 return (*rt->rt_ifp->if_output)
120 (ifp, m0, dst, rt);
121 } else
122 senderr(EHOSTUNREACH);
123 }
124 if ((rt->rt_flags & RTF_GATEWAY) && dst->sa_family != AF_NS) {
125 if (rt->rt_gwroute == 0)
126 goto lookup;
127 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) {
128 rtfree(rt); rt = rt0;
129 lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1);
130 if ((rt = rt->rt_gwroute) == 0)
131 senderr(EHOSTUNREACH);
132 /* the "G" test below also prevents rt == rt0 */
133 if ((rt->rt_flags & RTF_GATEWAY) ||
134 (rt->rt_ifp != ifp)) {
135 rt->rt_refcnt--;
136 rt0->rt_gwroute = 0;
137 senderr(EHOSTUNREACH);
138 }
139 }
140 }
141 if (rt->rt_flags & RTF_REJECT)
142 if (rt->rt_rmx.rmx_expire == 0 ||
143 time.tv_sec < rt->rt_rmx.rmx_expire)
144 senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH);
145 }
146 switch (dst->sa_family) {
147
148 #ifdef INET
149 case AF_INET:
150 if (!arpresolve(ac, rt, m, dst, edst))
151 return (0); /* if not yet resolved */
152 /* If broadcasting on a simplex interface, loopback a copy */
153 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
154 mcopy = m_copy(m, 0, (int)M_COPYALL);
155 off = m->m_pkthdr.len - m->m_len;
156 type = ETHERTYPE_IP;
157 break;
158 #endif
159 #ifdef NS
160 case AF_NS:
161 type = ETHERTYPE_NS;
162 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host),
163 (caddr_t)edst, sizeof (edst));
164 if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost, sizeof(edst)))
165 return (looutput(ifp, m, dst, rt));
166 /* If broadcasting on a simplex interface, loopback a copy */
167 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
168 mcopy = m_copy(m, 0, (int)M_COPYALL);
169 break;
170 #endif
171 #ifdef ISO
172 case AF_ISO: {
173 int snpalen;
174 struct llc *l;
175 register struct sockaddr_dl *sdl;
176
177 if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) &&
178 sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) {
179 bcopy(LLADDR(sdl), (caddr_t)edst, sizeof(edst));
180 } else if (error =
181 iso_snparesolve(ifp, (struct sockaddr_iso *)dst,
182 (char *)edst, &snpalen))
183 goto bad; /* Not Resolved */
184 /* If broadcasting on a simplex interface, loopback a copy */
185 if (*edst & 1)
186 m->m_flags |= (M_BCAST|M_MCAST);
187 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX) &&
188 (mcopy = m_copy(m, 0, (int)M_COPYALL))) {
189 M_PREPEND(mcopy, sizeof (*eh), M_DONTWAIT);
190 if (mcopy) {
191 eh = mtod(mcopy, struct ether_header *);
192 bcopy((caddr_t)edst,
193 (caddr_t)eh->ether_dhost, sizeof (edst));
194 bcopy((caddr_t)ac->ac_enaddr,
195 (caddr_t)eh->ether_shost, sizeof (edst));
196 }
197 }
198 M_PREPEND(m, 3, M_DONTWAIT);
199 if (m == NULL)
200 return (0);
201 type = m->m_pkthdr.len;
202 l = mtod(m, struct llc *);
203 l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP;
204 l->llc_control = LLC_UI;
205 len += 3;
206 IFDEBUG(D_ETHER)
207 int i;
208 printf("unoutput: sending pkt to: ");
209 for (i=0; i<6; i++)
210 printf("%x ", edst[i] & 0xff);
211 printf("\n");
212 ENDDEBUG
213 } break;
214 #endif /* ISO */
215 #ifdef LLC
216 /* case AF_NSAP: */
217 case AF_CCITT: {
218 register struct sockaddr_dl *sdl =
219 (struct sockaddr_dl *) rt -> rt_gateway;
220
221 if (sdl && sdl->sdl_family == AF_LINK
222 && sdl->sdl_alen > 0) {
223 bcopy(LLADDR(sdl), (char *)edst,
224 sizeof(edst));
225 } else goto bad; /* Not a link interface ? Funny ... */
226 if ((ifp->if_flags & IFF_SIMPLEX) && (*edst & 1) &&
227 (mcopy = m_copy(m, 0, (int)M_COPYALL))) {
228 M_PREPEND(mcopy, sizeof (*eh), M_DONTWAIT);
229 if (mcopy) {
230 eh = mtod(mcopy, struct ether_header *);
231 bcopy((caddr_t)edst,
232 (caddr_t)eh->ether_dhost, sizeof (edst));
233 bcopy((caddr_t)ac->ac_enaddr,
234 (caddr_t)eh->ether_shost, sizeof (edst));
235 }
236 }
237 type = m->m_pkthdr.len;
238 #ifdef LLC_DEBUG
239 {
240 int i;
241 register struct llc *l = mtod(m, struct llc *);
242
243 printf("ether_output: sending LLC2 pkt to: ");
244 for (i=0; i<6; i++)
245 printf("%x ", edst[i] & 0xff);
246 printf(" len 0x%x dsap 0x%x ssap 0x%x control 0x%x\n",
247 type & 0xff, l->llc_dsap & 0xff, l->llc_ssap &0xff,
248 l->llc_control & 0xff);
249
250 }
251 #endif /* LLC_DEBUG */
252 } break;
253 #endif /* LLC */
254
255 case AF_UNSPEC:
256 eh = (struct ether_header *)dst->sa_data;
257 bcopy((caddr_t)eh->ether_dhost, (caddr_t)edst, sizeof (edst));
258 type = eh->ether_type;
259 break;
260
261 default:
262 printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit,
263 dst->sa_family);
264 senderr(EAFNOSUPPORT);
265 }
266
267
268 if (mcopy)
269 (void) looutput(ifp, mcopy, dst, rt);
270 /*
271 * Add local net header. If no space in first mbuf,
272 * allocate another.
273 */
274 M_PREPEND(m, sizeof (struct ether_header), M_DONTWAIT);
275 if (m == 0)
276 senderr(ENOBUFS);
277 eh = mtod(m, struct ether_header *);
278 type = htons((u_short)type);
279 bcopy((caddr_t)&type,(caddr_t)&eh->ether_type,
280 sizeof(eh->ether_type));
281 bcopy((caddr_t)edst, (caddr_t)eh->ether_dhost, sizeof (edst));
282 bcopy((caddr_t)ac->ac_enaddr, (caddr_t)eh->ether_shost,
283 sizeof(eh->ether_shost));
284 s = splimp();
285 /*
286 * Queue message on interface, and start output if interface
287 * not yet active.
288 */
289 if (IF_QFULL(&ifp->if_snd)) {
290 IF_DROP(&ifp->if_snd);
291 splx(s);
292 senderr(ENOBUFS);
293 }
294 IF_ENQUEUE(&ifp->if_snd, m);
295 if ((ifp->if_flags & IFF_OACTIVE) == 0)
296 (*ifp->if_start)(ifp);
297 splx(s);
298 ifp->if_obytes += len + sizeof (struct ether_header);
299 if (m->m_flags & M_MCAST)
300 ifp->if_omcasts++;
301 return (error);
302
303 bad:
304 if (m)
305 m_freem(m);
306 return (error);
307 }
308
309 /*
310 * Process a received Ethernet packet;
311 * the packet is in the mbuf chain m without
312 * the ether header, which is provided separately.
313 */
314 void
315 ether_input(ifp, eh, m)
316 struct ifnet *ifp;
317 register struct ether_header *eh;
318 struct mbuf *m;
319 {
320 register struct ifqueue *inq;
321 register struct llc *l;
322 struct arpcom *ac = (struct arpcom *)ifp;
323 int s;
324
325 if ((ifp->if_flags & IFF_UP) == 0) {
326 m_freem(m);
327 return;
328 }
329 ifp->if_lastchange = time;
330 ifp->if_ibytes += m->m_pkthdr.len + sizeof (*eh);
331 if (bcmp((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost,
332 sizeof(etherbroadcastaddr)) == 0)
333 m->m_flags |= M_BCAST;
334 else if (eh->ether_dhost[0] & 1)
335 m->m_flags |= M_MCAST;
336 if (m->m_flags & (M_BCAST|M_MCAST))
337 ifp->if_imcasts++;
338
339 switch (eh->ether_type) {
340 #ifdef INET
341 case ETHERTYPE_IP:
342 schednetisr(NETISR_IP);
343 inq = &ipintrq;
344 break;
345
346 case ETHERTYPE_ARP:
347 schednetisr(NETISR_ARP);
348 inq = &arpintrq;
349 break;
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 (eh->ether_type > 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 > eh->ether_type)
373 m_adj(m, eh->ether_type - 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 > eh->ether_type)
434 m_adj(m, eh->ether_type - 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 = eh->ether_type;
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 for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
507 if ((sdl = (struct sockaddr_dl *)ifa->ifa_addr) &&
508 sdl->sdl_family == AF_LINK) {
509 sdl->sdl_type = IFT_ETHER;
510 sdl->sdl_alen = ifp->if_addrlen;
511 bcopy((caddr_t)((struct arpcom *)ifp)->ac_enaddr,
512 LLADDR(sdl), ifp->if_addrlen);
513 break;
514 }
515 }
516
517 u_char ether_ipmulticast_min[6] = { 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 };
518 u_char ether_ipmulticast_max[6] = { 0x01, 0x00, 0x5e, 0x7f, 0xff, 0xff };
519 /*
520 * Add an Ethernet multicast address or range of addresses to the list for a
521 * given interface.
522 */
523 int
524 ether_addmulti(ifr, ac)
525 struct ifreq *ifr;
526 register struct arpcom *ac;
527 {
528 register struct ether_multi *enm;
529 struct sockaddr_in *sin;
530 u_char addrlo[6];
531 u_char addrhi[6];
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 }
553 else {
554 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, addrlo);
555 bcopy(addrlo, addrhi, 6);
556 }
557 break;
558 #endif
559
560 default:
561 splx(s);
562 return (EAFNOSUPPORT);
563 }
564
565 /*
566 * Verify that we have valid Ethernet multicast addresses.
567 */
568 if ((addrlo[0] & 0x01) != 1 || (addrhi[0] & 0x01) != 1) {
569 splx(s);
570 return (EINVAL);
571 }
572 /*
573 * See if the address range is already in the list.
574 */
575 ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm);
576 if (enm != NULL) {
577 /*
578 * Found it; just increment the reference count.
579 */
580 ++enm->enm_refcount;
581 splx(s);
582 return (0);
583 }
584 /*
585 * New address or range; malloc a new multicast record
586 * and link it into the interface's multicast list.
587 */
588 enm = (struct ether_multi *)malloc(sizeof(*enm), M_IFMADDR, M_NOWAIT);
589 if (enm == NULL) {
590 splx(s);
591 return (ENOBUFS);
592 }
593 bcopy(addrlo, enm->enm_addrlo, 6);
594 bcopy(addrhi, enm->enm_addrhi, 6);
595 enm->enm_ac = ac;
596 enm->enm_refcount = 1;
597 enm->enm_next = ac->ac_multiaddrs;
598 ac->ac_multiaddrs = enm;
599 ac->ac_multicnt++;
600 splx(s);
601 /*
602 * Return ENETRESET to inform the driver that the list has changed
603 * and its reception filter should be adjusted accordingly.
604 */
605 return (ENETRESET);
606 }
607
608 /*
609 * Delete a multicast address record.
610 */
611 int
612 ether_delmulti(ifr, ac)
613 struct ifreq *ifr;
614 register struct arpcom *ac;
615 {
616 register struct ether_multi *enm;
617 register struct ether_multi **p;
618 struct sockaddr_in *sin;
619 u_char addrlo[6];
620 u_char addrhi[6];
621 int s = splimp();
622
623 switch (ifr->ifr_addr.sa_family) {
624
625 case AF_UNSPEC:
626 bcopy(ifr->ifr_addr.sa_data, addrlo, 6);
627 bcopy(addrlo, addrhi, 6);
628 break;
629
630 #ifdef INET
631 case AF_INET:
632 sin = (struct sockaddr_in *)&(ifr->ifr_addr);
633 if (sin->sin_addr.s_addr == INADDR_ANY) {
634 /*
635 * An IP address of INADDR_ANY means stop listening
636 * to the range of Ethernet multicast addresses used
637 * for IP.
638 */
639 bcopy(ether_ipmulticast_min, addrlo, 6);
640 bcopy(ether_ipmulticast_max, addrhi, 6);
641 }
642 else {
643 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, addrlo);
644 bcopy(addrlo, addrhi, 6);
645 }
646 break;
647 #endif
648
649 default:
650 splx(s);
651 return (EAFNOSUPPORT);
652 }
653
654 /*
655 * Look up the address in our list.
656 */
657 ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm);
658 if (enm == NULL) {
659 splx(s);
660 return (ENXIO);
661 }
662 if (--enm->enm_refcount != 0) {
663 /*
664 * Still some claims to this record.
665 */
666 splx(s);
667 return (0);
668 }
669 /*
670 * No remaining claims to this record; unlink and free it.
671 */
672 for (p = &enm->enm_ac->ac_multiaddrs;
673 *p != enm;
674 p = &(*p)->enm_next)
675 continue;
676 *p = (*p)->enm_next;
677 free(enm, M_IFMADDR);
678 ac->ac_multicnt--;
679 splx(s);
680 /*
681 * Return ENETRESET to inform the driver that the list has changed
682 * and its reception filter should be adjusted accordingly.
683 */
684 return (ENETRESET);
685 }
686