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