if_ethersubr.c revision 1.21.4.2 1 /* $NetBSD: if_ethersubr.c,v 1.21.4.2 1997/02/11 20:21:12 is 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 #include <net/if_ether.h>
59
60 #include <netinet/in.h>
61 #ifdef INET
62 #include <netinet/in_var.h>
63 #endif
64 #include <netinet/if_ether.h>
65
66 #ifdef NS
67 #include <netns/ns.h>
68 #include <netns/ns_if.h>
69 #endif
70
71 #ifdef ISO
72 #include <netiso/argo_debug.h>
73 #include <netiso/iso.h>
74 #include <netiso/iso_var.h>
75 #include <netiso/iso_snpac.h>
76 #endif
77
78 #ifdef LLC
79 #include <netccitt/dll.h>
80 #include <netccitt/llc_var.h>
81 #endif
82
83 #if defined(LLC) && defined(CCITT)
84 extern struct ifqueue pkintrq;
85 #endif
86
87 u_char etherbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
88 #define senderr(e) { error = (e); goto bad;}
89
90 #define SIN(x) ((struct sockaddr_in *)x)
91
92 /*
93 * Ethernet output routine.
94 * Encapsulate a packet of type family for the local net.
95 * Assumes that ifp is actually pointer to ethercom structure.
96 */
97 int
98 ether_output(ifp, m0, dst, rt0)
99 register struct ifnet *ifp;
100 struct mbuf *m0;
101 struct sockaddr *dst;
102 struct rtentry *rt0;
103 {
104 u_int16_t etype;
105 int s, error = 0;
106 u_char edst[6];
107 register struct mbuf *m = m0;
108 register struct rtentry *rt;
109 struct mbuf *mcopy = (struct mbuf *)0;
110 register struct ether_header *eh;
111 struct arphdr *ah;
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) != NULL) {
117 if ((rt->rt_flags & RTF_UP) == 0) {
118 if ((rt0 = rt = rtalloc1(dst, 1)) != NULL)
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 (m->m_flags & M_BCAST)
143 bcopy((caddr_t)etherbroadcastaddr, (caddr_t)edst,
144 sizeof(edst));
145
146 else if (m->m_flags & M_MCAST) {
147 ETHER_MAP_IP_MULTICAST(&SIN(dst)->sin_addr,
148 (caddr_t)edst)
149
150 } else if (!arpresolve(ifp, 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 etype = htons(ETHERTYPE_IP);
156 break;
157
158 case AF_ARP:
159 ah = mtod(m, struct arphdr *);
160 if (m->m_flags & M_BCAST)
161 bcopy((caddr_t)etherbroadcastaddr, (caddr_t)edst,
162 sizeof(edst));
163 else
164 bcopy((caddr_t)ar_tha(ah),
165 (caddr_t)edst, sizeof(edst));
166
167 switch(ah->ar_op) {
168 case ARPOP_REVREQUEST:
169 case ARPOP_REVREPLY:
170 etype = htons(ETHERTYPE_REVARP);
171 break;
172
173 case ARPOP_REQUEST:
174 case ARPOP_REPLY:
175 default:
176 etype = htons(ETHERTYPE_ARP);
177 }
178
179 break;
180 #endif
181 #ifdef NS
182 case AF_NS:
183 etype = htons(ETHERTYPE_NS);
184 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host),
185 (caddr_t)edst, sizeof (edst));
186 if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost, sizeof(edst)))
187 return (looutput(ifp, m, dst, rt));
188 /* If broadcasting on a simplex interface, loopback a copy */
189 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
190 mcopy = m_copy(m, 0, (int)M_COPYALL);
191 break;
192 #endif
193 #ifdef ISO
194 case AF_ISO: {
195 int snpalen;
196 struct llc *l;
197 register struct sockaddr_dl *sdl;
198
199 if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) &&
200 sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) {
201 bcopy(LLADDR(sdl), (caddr_t)edst, sizeof(edst));
202 } else {
203 error = iso_snparesolve(ifp, (struct sockaddr_iso *)dst,
204 (char *)edst, &snpalen);
205 if (error)
206 goto bad; /* Not Resolved */
207 }
208 /* If broadcasting on a simplex interface, loopback a copy */
209 if (*edst & 1)
210 m->m_flags |= (M_BCAST|M_MCAST);
211 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX) &&
212 (mcopy = m_copy(m, 0, (int)M_COPYALL))) {
213 M_PREPEND(mcopy, sizeof (*eh), M_DONTWAIT);
214 if (mcopy) {
215 eh = mtod(mcopy, struct ether_header *);
216 bcopy((caddr_t)edst,
217 (caddr_t)eh->ether_dhost, sizeof (edst));
218 bcopy(LLADDR(ifp->if_sadl),
219 (caddr_t)eh->ether_shost, sizeof (edst));
220 }
221 }
222 M_PREPEND(m, 3, M_DONTWAIT);
223 if (m == NULL)
224 return (0);
225 etype = htons(m->m_pkthdr.len);
226 l = mtod(m, struct llc *);
227 l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP;
228 l->llc_control = LLC_UI;
229 #ifdef ARGO_DEBUG
230 if (argo_debug[D_ETHER]) {
231 int i;
232 printf("unoutput: sending pkt to: ");
233 for (i=0; i<6; i++)
234 printf("%x ", edst[i] & 0xff);
235 printf("\n");
236 }
237 #endif
238 } break;
239 #endif /* ISO */
240 #ifdef LLC
241 /* case AF_NSAP: */
242 case AF_CCITT: {
243 register struct sockaddr_dl *sdl =
244 (struct sockaddr_dl *) rt -> rt_gateway;
245
246 if (sdl && sdl->sdl_family == AF_LINK
247 && sdl->sdl_alen > 0) {
248 bcopy(LLADDR(sdl), (char *)edst,
249 sizeof(edst));
250 } else goto bad; /* Not a link interface ? Funny ... */
251 if ((ifp->if_flags & IFF_SIMPLEX) && (*edst & 1) &&
252 (mcopy = m_copy(m, 0, (int)M_COPYALL))) {
253 M_PREPEND(mcopy, sizeof (*eh), M_DONTWAIT);
254 if (mcopy) {
255 eh = mtod(mcopy, struct ether_header *);
256 bcopy((caddr_t)edst,
257 (caddr_t)eh->ether_dhost, sizeof (edst));
258 bcopy(LLADDR(ifp->if_sadl),
259 (caddr_t)eh->ether_shost, sizeof (edst));
260 }
261 }
262 etype = htons(m->m_pkthdr.len);
263 #ifdef LLC_DEBUG
264 {
265 int i;
266 register struct llc *l = mtod(m, struct llc *);
267
268 printf("ether_output: sending LLC2 pkt to: ");
269 for (i=0; i<6; i++)
270 printf("%x ", edst[i] & 0xff);
271 printf(" len 0x%x dsap 0x%x ssap 0x%x control 0x%x\n",
272 m->m_pkthdr.len, l->llc_dsap & 0xff, l->llc_ssap &0xff,
273 l->llc_control & 0xff);
274
275 }
276 #endif /* LLC_DEBUG */
277 } break;
278 #endif /* LLC */
279
280 case AF_UNSPEC:
281 eh = (struct ether_header *)dst->sa_data;
282 bcopy((caddr_t)eh->ether_dhost, (caddr_t)edst, sizeof (edst));
283 /* AF_UNSPEC doesn't swap the byte order of the ether_type. */
284 etype = eh->ether_type;
285 break;
286
287 default:
288 printf("%s: can't handle af%d\n", ifp->if_xname,
289 dst->sa_family);
290 senderr(EAFNOSUPPORT);
291 }
292
293 if (mcopy)
294 (void) looutput(ifp, mcopy, dst, rt);
295
296 /*
297 * Add local net header. If no space in first mbuf,
298 * allocate another.
299 */
300 M_PREPEND(m, sizeof (struct ether_header), M_DONTWAIT);
301 if (m == 0)
302 senderr(ENOBUFS);
303 eh = mtod(m, struct ether_header *);
304 bcopy((caddr_t)&etype,(caddr_t)&eh->ether_type,
305 sizeof(eh->ether_type));
306 bcopy((caddr_t)edst, (caddr_t)eh->ether_dhost, sizeof (edst));
307 bcopy(LLADDR(ifp->if_sadl), (caddr_t)eh->ether_shost,
308 sizeof(eh->ether_shost));
309 s = splimp();
310 /*
311 * Queue message on interface, and start output if interface
312 * not yet active.
313 */
314 if (IF_QFULL(&ifp->if_snd)) {
315 IF_DROP(&ifp->if_snd);
316 splx(s);
317 senderr(ENOBUFS);
318 }
319 ifp->if_obytes += m->m_pkthdr.len;
320 IF_ENQUEUE(&ifp->if_snd, m);
321 if ((ifp->if_flags & IFF_OACTIVE) == 0)
322 (*ifp->if_start)(ifp);
323 splx(s);
324 if (m->m_flags & M_MCAST)
325 ifp->if_omcasts++;
326 return (error);
327
328 bad:
329 if (m)
330 m_freem(m);
331 return (error);
332 }
333
334 /*
335 * Process a received Ethernet packet;
336 * the packet is in the mbuf chain m without
337 * the ether header, which is provided separately.
338 */
339 void
340 ether_input(ifp, eh, m)
341 struct ifnet *ifp;
342 register struct ether_header *eh;
343 struct mbuf *m;
344 {
345 register struct ifqueue *inq;
346 u_int16_t etype;
347 int s;
348 #if defined (ISO) || defined (LLC)
349 register struct llc *l;
350 struct ethercom *ac = (struct ethercom *)ifp;
351 #endif
352
353 if ((ifp->if_flags & IFF_UP) == 0) {
354 m_freem(m);
355 return;
356 }
357 ifp->if_lastchange = time;
358 ifp->if_ibytes += m->m_pkthdr.len + sizeof (*eh);
359 if (eh->ether_dhost[0] & 1) {
360 if (bcmp((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost,
361 sizeof(etherbroadcastaddr)) == 0)
362 m->m_flags |= M_BCAST;
363 else
364 m->m_flags |= M_MCAST;
365 }
366 if (m->m_flags & (M_BCAST|M_MCAST))
367 ifp->if_imcasts++;
368
369 etype = ntohs(eh->ether_type);
370 switch (etype) {
371 #ifdef INET
372 case ETHERTYPE_IP:
373 schednetisr(NETISR_IP);
374 inq = &ipintrq;
375 break;
376
377 case ETHERTYPE_ARP:
378 schednetisr(NETISR_ARP);
379 inq = &arpintrq;
380 break;
381
382 case ETHERTYPE_REVARP:
383 revarpinput(m); /* XXX queue? */
384 return;
385 #endif
386 #ifdef NS
387 case ETHERTYPE_NS:
388 schednetisr(NETISR_NS);
389 inq = &nsintrq;
390 break;
391
392 #endif
393 default:
394 #if defined (ISO) || defined (LLC)
395 if (etype > ETHERMTU)
396 goto dropanyway;
397 l = mtod(m, struct llc *);
398 switch (l->llc_dsap) {
399 #ifdef ISO
400 case LLC_ISO_LSAP:
401 switch (l->llc_control) {
402 case LLC_UI:
403 /* LLC_UI_P forbidden in class 1 service */
404 if ((l->llc_dsap == LLC_ISO_LSAP) &&
405 (l->llc_ssap == LLC_ISO_LSAP)) {
406 /* LSAP for ISO */
407 if (m->m_pkthdr.len > etype)
408 m_adj(m, etype - m->m_pkthdr.len);
409 m->m_data += 3; /* XXX */
410 m->m_len -= 3; /* XXX */
411 m->m_pkthdr.len -= 3; /* XXX */
412 M_PREPEND(m, sizeof *eh, M_DONTWAIT);
413 if (m == 0)
414 return;
415 *mtod(m, struct ether_header *) = *eh;
416 #ifdef ARGO_DEBUG
417 if (argo_debug[D_ETHER])
418 printf("clnp packet");
419 #endif
420 schednetisr(NETISR_ISO);
421 inq = &clnlintrq;
422 break;
423 }
424 goto dropanyway;
425
426 case LLC_XID:
427 case LLC_XID_P:
428 if(m->m_len < 6)
429 goto dropanyway;
430 l->llc_window = 0;
431 l->llc_fid = 9;
432 l->llc_class = 1;
433 l->llc_dsap = l->llc_ssap = 0;
434 /* Fall through to */
435 case LLC_TEST:
436 case LLC_TEST_P:
437 {
438 struct sockaddr sa;
439 register struct ether_header *eh2;
440 int i;
441 u_char c = l->llc_dsap;
442
443 l->llc_dsap = l->llc_ssap;
444 l->llc_ssap = c;
445 if (m->m_flags & (M_BCAST | M_MCAST))
446 bcopy(LLADDR(ifp->if_sadl),
447 (caddr_t)eh->ether_dhost, 6);
448 sa.sa_family = AF_UNSPEC;
449 sa.sa_len = sizeof(sa);
450 eh2 = (struct ether_header *)sa.sa_data;
451 for (i = 0; i < 6; i++) {
452 eh2->ether_shost[i] = c = eh->ether_dhost[i];
453 eh2->ether_dhost[i] =
454 eh->ether_dhost[i] = eh->ether_shost[i];
455 eh->ether_shost[i] = c;
456 }
457 ifp->if_output(ifp, m, &sa, NULL);
458 return;
459 }
460 default:
461 m_freem(m);
462 return;
463 }
464 break;
465 #endif /* ISO */
466 #ifdef LLC
467 case LLC_X25_LSAP:
468 {
469 if (m->m_pkthdr.len > etype)
470 m_adj(m, etype - m->m_pkthdr.len);
471 M_PREPEND(m, sizeof(struct sdl_hdr) , M_DONTWAIT);
472 if (m == 0)
473 return;
474 if ( !sdl_sethdrif(ifp, eh->ether_shost, LLC_X25_LSAP,
475 eh->ether_dhost, LLC_X25_LSAP, 6,
476 mtod(m, struct sdl_hdr *)))
477 panic("ETHER cons addr failure");
478 mtod(m, struct sdl_hdr *)->sdlhdr_len = etype;
479 #ifdef LLC_DEBUG
480 printf("llc packet\n");
481 #endif /* LLC_DEBUG */
482 schednetisr(NETISR_CCITT);
483 inq = &llcintrq;
484 break;
485 }
486 #endif /* LLC */
487 dropanyway:
488 default:
489 m_freem(m);
490 return;
491 }
492 #else /* ISO || LLC */
493 m_freem(m);
494 return;
495 #endif /* ISO || LLC */
496 }
497
498 s = splimp();
499 if (IF_QFULL(inq)) {
500 IF_DROP(inq);
501 m_freem(m);
502 } else
503 IF_ENQUEUE(inq, m);
504 splx(s);
505 }
506
507 /*
508 * Convert Ethernet address to printable (loggable) representation.
509 */
510 static char digits[] = "0123456789abcdef";
511 char *
512 ether_sprintf(ap)
513 register u_char *ap;
514 {
515 register i;
516 static char etherbuf[18];
517 register char *cp = etherbuf;
518
519 for (i = 0; i < 6; i++) {
520 *cp++ = digits[*ap >> 4];
521 *cp++ = digits[*ap++ & 0xf];
522 *cp++ = ':';
523 }
524 *--cp = 0;
525 return (etherbuf);
526 }
527
528 /*
529 * Perform common duties while attaching to interface list
530 */
531 void
532 ether_ifattach(ifp, lla)
533 register struct ifnet *ifp;
534 u_int8_t * lla;
535 {
536 register struct sockaddr_dl *sdl;
537
538 ifp->if_type = IFT_ETHER;
539 ifp->if_addrlen = 6;
540 ifp->if_hdrlen = 14;
541 ifp->if_mtu = ETHERMTU;
542 ifp->if_output = ether_output;
543 if ((sdl = ifp->if_sadl) &&
544 sdl->sdl_family == AF_LINK) {
545 sdl->sdl_type = IFT_ETHER;
546 sdl->sdl_alen = ifp->if_addrlen;
547 bcopy((caddr_t)lla, LLADDR(sdl), ifp->if_addrlen);
548 }
549 LIST_INIT(&((struct ethercom *)ifp)->ec_multiaddrs);
550 }
551
552 u_char ether_ipmulticast_min[6] = { 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 };
553 u_char ether_ipmulticast_max[6] = { 0x01, 0x00, 0x5e, 0x7f, 0xff, 0xff };
554 /*
555 * Add an Ethernet multicast address or range of addresses to the list for a
556 * given interface.
557 */
558 int
559 ether_addmulti(ifr, ec)
560 struct ifreq *ifr;
561 register struct ethercom *ec;
562 {
563 register struct ether_multi *enm;
564 struct sockaddr_in *sin;
565 u_char addrlo[6];
566 u_char addrhi[6];
567 int s = splimp();
568
569 switch (ifr->ifr_addr.sa_family) {
570
571 case AF_UNSPEC:
572 bcopy(ifr->ifr_addr.sa_data, addrlo, 6);
573 bcopy(addrlo, addrhi, 6);
574 break;
575
576 #ifdef INET
577 case AF_INET:
578 sin = (struct sockaddr_in *)&(ifr->ifr_addr);
579 if (sin->sin_addr.s_addr == INADDR_ANY) {
580 /*
581 * An IP address of INADDR_ANY means listen to all
582 * of the Ethernet multicast addresses used for IP.
583 * (This is for the sake of IP multicast routers.)
584 */
585 bcopy(ether_ipmulticast_min, addrlo, 6);
586 bcopy(ether_ipmulticast_max, addrhi, 6);
587 }
588 else {
589 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, addrlo);
590 bcopy(addrlo, addrhi, 6);
591 }
592 break;
593 #endif
594
595 default:
596 splx(s);
597 return (EAFNOSUPPORT);
598 }
599
600 /*
601 * Verify that we have valid Ethernet multicast addresses.
602 */
603 if ((addrlo[0] & 0x01) != 1 || (addrhi[0] & 0x01) != 1) {
604 splx(s);
605 return (EINVAL);
606 }
607 /*
608 * See if the address range is already in the list.
609 */
610 ETHER_LOOKUP_MULTI(addrlo, addrhi, ec, enm);
611 if (enm != NULL) {
612 /*
613 * Found it; just increment the reference count.
614 */
615 ++enm->enm_refcount;
616 splx(s);
617 return (0);
618 }
619 /*
620 * New address or range; malloc a new multicast record
621 * and link it into the interface's multicast list.
622 */
623 enm = (struct ether_multi *)malloc(sizeof(*enm), M_IFMADDR, M_NOWAIT);
624 if (enm == NULL) {
625 splx(s);
626 return (ENOBUFS);
627 }
628 bcopy(addrlo, enm->enm_addrlo, 6);
629 bcopy(addrhi, enm->enm_addrhi, 6);
630 enm->enm_ec = ec;
631 enm->enm_refcount = 1;
632 LIST_INSERT_HEAD(&ec->ec_multiaddrs, enm, enm_list);
633 ec->ec_multicnt++;
634 splx(s);
635 /*
636 * Return ENETRESET to inform the driver that the list has changed
637 * and its reception filter should be adjusted accordingly.
638 */
639 return (ENETRESET);
640 }
641
642 /*
643 * Delete a multicast address record.
644 */
645 int
646 ether_delmulti(ifr, ec)
647 struct ifreq *ifr;
648 register struct ethercom *ec;
649 {
650 register struct ether_multi *enm;
651 struct sockaddr_in *sin;
652 u_char addrlo[6];
653 u_char addrhi[6];
654 int s = splimp();
655
656 switch (ifr->ifr_addr.sa_family) {
657
658 case AF_UNSPEC:
659 bcopy(ifr->ifr_addr.sa_data, addrlo, 6);
660 bcopy(addrlo, addrhi, 6);
661 break;
662
663 #ifdef INET
664 case AF_INET:
665 sin = (struct sockaddr_in *)&(ifr->ifr_addr);
666 if (sin->sin_addr.s_addr == INADDR_ANY) {
667 /*
668 * An IP address of INADDR_ANY means stop listening
669 * to the range of Ethernet multicast addresses used
670 * for IP.
671 */
672 bcopy(ether_ipmulticast_min, addrlo, 6);
673 bcopy(ether_ipmulticast_max, addrhi, 6);
674 }
675 else {
676 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, addrlo);
677 bcopy(addrlo, addrhi, 6);
678 }
679 break;
680 #endif
681
682 default:
683 splx(s);
684 return (EAFNOSUPPORT);
685 }
686
687 /*
688 * Look up the address in our list.
689 */
690 ETHER_LOOKUP_MULTI(addrlo, addrhi, ec, enm);
691 if (enm == NULL) {
692 splx(s);
693 return (ENXIO);
694 }
695 if (--enm->enm_refcount != 0) {
696 /*
697 * Still some claims to this record.
698 */
699 splx(s);
700 return (0);
701 }
702 /*
703 * No remaining claims to this record; unlink and free it.
704 */
705 LIST_REMOVE(enm, enm_list);
706 free(enm, M_IFMADDR);
707 ec->ec_multicnt--;
708 splx(s);
709 /*
710 * Return ENETRESET to inform the driver that the list has changed
711 * and its reception filter should be adjusted accordingly.
712 */
713 return (ENETRESET);
714 }
715