1 //==========================================================================
3 // src/sys/netinet/in.c
5 //==========================================================================
6 //####BSDCOPYRIGHTBEGIN####
8 // -------------------------------------------
10 // Portions of this software may have been derived from OpenBSD,
11 // FreeBSD or other sources, and are covered by the appropriate
12 // copyright disclaimers included herein.
14 // Portions created by Red Hat are
15 // Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
17 // -------------------------------------------
19 //####BSDCOPYRIGHTEND####
20 //==========================================================================
23 * Copyright (c) 1982, 1986, 1991, 1993
24 * The Regents of the University of California. All rights reserved.
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in the
33 * documentation and/or other materials provided with the distribution.
34 * 3. All advertising materials mentioning features or use of this software
35 * must display the following acknowledgement:
36 * This product includes software developed by the University of
37 * California, Berkeley and its contributors.
38 * 4. Neither the name of the University nor the names of its contributors
39 * may be used to endorse or promote products derived from this software
40 * without specific prior written permission.
42 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * @(#)in.c 8.4 (Berkeley) 1/9/95
55 * $FreeBSD: src/sys/netinet/in.c,v 1.44.2.5 2001/08/13 16:26:17 ume Exp $
58 #include <sys/param.h>
59 #include <sys/sockio.h>
60 #include <sys/malloc.h>
61 #include <sys/socket.h>
62 #include <sys/sysctl.h>
65 #include <net/if_types.h>
66 #include <net/route.h>
68 #include <netinet/in.h>
69 #include <netinet/in_var.h>
70 #include <netinet/in_pcb.h>
72 #include <netinet/igmp_var.h>
74 static int in_mask2len __P((struct in_addr *));
75 static void in_len2mask __P((struct in_addr *, int));
76 static int in_lifaddr_ioctl __P((struct socket *, u_long, caddr_t,
77 struct ifnet *, struct proc *));
79 static void in_socktrim __P((struct sockaddr_in *));
80 static int in_ifinit __P((struct ifnet *,
81 struct in_ifaddr *, struct sockaddr_in *, int));
83 static int subnetsarelocal = 0;
84 SYSCTL_INT(_net_inet_ip, OID_AUTO, subnets_are_local, CTLFLAG_RW,
85 &subnetsarelocal, 0, "");
87 struct in_multihead in_multihead; /* XXX BSS initialization */
89 extern struct inpcbinfo ripcbinfo;
90 extern struct inpcbinfo udbinfo;
93 * Return 1 if an internet address is for a ``local'' host
94 * (one to which we have a connection). If subnetsarelocal
95 * is true, this includes other subnets of the local net.
96 * Otherwise, it includes only the directly-connected (sub)nets.
102 register u_long i = ntohl(in.s_addr);
103 register struct in_ifaddr *ia;
105 if (subnetsarelocal) {
106 for (ia = in_ifaddrhead.tqh_first; ia;
107 ia = ia->ia_link.tqe_next)
108 if ((i & ia->ia_netmask) == ia->ia_net)
111 for (ia = in_ifaddrhead.tqh_first; ia;
112 ia = ia->ia_link.tqe_next)
113 if ((i & ia->ia_subnetmask) == ia->ia_subnet)
120 * Determine whether an IP address is in a reserved set of addresses
121 * that may not be forwarded, or whether datagrams to that destination
128 register u_long i = ntohl(in.s_addr);
131 if (IN_EXPERIMENTAL(i) || IN_MULTICAST(i))
134 net = i & IN_CLASSA_NET;
135 if (net == 0 || net == (IN_LOOPBACKNET << IN_CLASSA_NSHIFT))
142 * Trim a mask in a sockaddr
146 struct sockaddr_in *ap;
148 register char *cplim = (char *) &ap->sin_addr;
149 register char *cp = (char *) (&ap->sin_addr + 1);
152 while (--cp >= cplim)
154 (ap)->sin_len = cp - (char *) (ap) + 1;
161 struct in_addr *mask;
167 for (x = 0; x < sizeof(*mask); x++) {
172 if (x < sizeof(*mask)) {
173 for (y = 0; y < 8; y++) {
174 if ((p[x] & (0x80 >> y)) == 0)
182 in_len2mask(mask, len)
183 struct in_addr *mask;
190 bzero(mask, sizeof(*mask));
191 for (i = 0; i < len / 8; i++)
194 p[i] = (0xff00 >> (len % 8)) & 0xff;
197 static int in_interfaces; /* number of external internet interfaces */
200 * Generic internet control operations (ioctl's).
201 * Ifp is 0 if not an interface-specific ioctl.
205 in_control(so, cmd, data, ifp, p)
209 register struct ifnet *ifp;
212 register struct ifreq *ifr = (struct ifreq *)data;
213 register struct in_ifaddr *ia = 0, *iap;
214 register struct ifaddr *ifa;
215 struct in_ifaddr *oia;
216 struct in_aliasreq *ifra = (struct in_aliasreq *)data;
217 struct sockaddr_in oldaddr;
218 int error, hostIsNew, maskIsNew, s;
228 return in_lifaddr_ioctl(so, cmd, data, ifp, p);
232 * Find address for this interface, if it exists.
234 * If an alias address was specified, find that one instead of
235 * the first one on the interface.
238 for (iap = in_ifaddrhead.tqh_first; iap;
239 iap = iap->ia_link.tqe_next)
240 if (iap->ia_ifp == ifp) {
241 if (((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr.s_addr ==
242 iap->ia_addr.sin_addr.s_addr) {
245 } else if (ia == NULL) {
247 if (ifr->ifr_addr.sa_family != AF_INET)
257 case SIOCSIFADDR: // Moved from after this search, otherwise repeated
258 // identical SIOCSIFADDRs leaked the previously allocated record.
261 return (EADDRNOTAVAIL);
262 if (ifra->ifra_addr.sin_family == AF_INET) {
263 for (oia = ia; ia; ia = ia->ia_link.tqe_next) {
264 if (ia->ia_ifp == ifp &&
265 ia->ia_addr.sin_addr.s_addr ==
266 ifra->ifra_addr.sin_addr.s_addr)
269 if ((ifp->if_flags & IFF_POINTOPOINT)
270 && (cmd == SIOCAIFADDR)
271 && (ifra->ifra_dstaddr.sin_addr.s_addr
276 if (cmd == SIOCDIFADDR && ia == 0)
277 return (EADDRNOTAVAIL);
282 return (EADDRNOTAVAIL);
283 if (ia == (struct in_ifaddr *)0) {
284 ia = (struct in_ifaddr *)
285 malloc(sizeof *ia, M_IFADDR, M_WAITOK); // This alloc was leaked
286 if (ia == (struct in_ifaddr *)NULL)
288 bzero((caddr_t)ia, sizeof *ia);
290 * Protect from ipintr() traversing address list
291 * while we're modifying it.
295 TAILQ_INSERT_TAIL(&in_ifaddrhead, ia, ia_link);
297 TAILQ_INSERT_TAIL(&ifp->if_addrhead, ifa, ifa_link);
299 ifa->ifa_addr = (struct sockaddr *)&ia->ia_addr;
300 ifa->ifa_dstaddr = (struct sockaddr *)&ia->ia_dstaddr;
301 ifa->ifa_netmask = (struct sockaddr *)&ia->ia_sockmask;
302 ia->ia_sockmask.sin_len = 8;
303 if (ifp->if_flags & IFF_BROADCAST) {
304 ia->ia_broadaddr.sin_len = sizeof(ia->ia_addr);
305 ia->ia_broadaddr.sin_family = AF_INET;
308 if (!(ifp->if_flags & IFF_LOOPBACK))
321 if (ia == (struct in_ifaddr *)0)
322 return (EADDRNOTAVAIL);
328 *((struct sockaddr_in *)&ifr->ifr_addr) = ia->ia_addr;
332 if ((ifp->if_flags & IFF_BROADCAST) == 0)
334 *((struct sockaddr_in *)&ifr->ifr_dstaddr) = ia->ia_broadaddr;
338 if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
340 *((struct sockaddr_in *)&ifr->ifr_dstaddr) = ia->ia_dstaddr;
344 *((struct sockaddr_in *)&ifr->ifr_addr) = ia->ia_sockmask;
348 if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
350 oldaddr = ia->ia_dstaddr;
351 ia->ia_dstaddr = *(struct sockaddr_in *)&ifr->ifr_dstaddr;
352 if (ifp->if_ioctl && (error = (*ifp->if_ioctl)
353 (ifp, SIOCSIFDSTADDR, (caddr_t)ia))) {
354 ia->ia_dstaddr = oldaddr;
357 if (ia->ia_flags & IFA_ROUTE) {
358 ia->ia_ifa.ifa_dstaddr = (struct sockaddr *)&oldaddr;
359 rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST);
360 ia->ia_ifa.ifa_dstaddr =
361 (struct sockaddr *)&ia->ia_dstaddr;
362 rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP);
367 if ((ifp->if_flags & IFF_BROADCAST) == 0)
369 ia->ia_broadaddr = *(struct sockaddr_in *)&ifr->ifr_broadaddr;
373 return (in_ifinit(ifp, ia,
374 (struct sockaddr_in *) &ifr->ifr_addr, 1));
377 i = ifra->ifra_addr.sin_addr.s_addr;
378 ia->ia_subnetmask = ntohl(ia->ia_sockmask.sin_addr.s_addr = i);
385 if (ia->ia_addr.sin_family == AF_INET) {
386 if (ifra->ifra_addr.sin_len == 0) {
387 ifra->ifra_addr = ia->ia_addr;
389 } else if (ifra->ifra_addr.sin_addr.s_addr ==
390 ia->ia_addr.sin_addr.s_addr)
393 if (ifra->ifra_mask.sin_len) {
395 ia->ia_sockmask = ifra->ifra_mask;
397 ntohl(ia->ia_sockmask.sin_addr.s_addr);
400 if ((ifp->if_flags & IFF_POINTOPOINT) &&
401 (ifra->ifra_dstaddr.sin_family == AF_INET)) {
403 ia->ia_dstaddr = ifra->ifra_dstaddr;
404 maskIsNew = 1; /* We lie; but the effect's the same */
406 if (ifra->ifra_addr.sin_family == AF_INET &&
407 (hostIsNew || maskIsNew))
408 error = in_ifinit(ifp, ia, &ifra->ifra_addr, 0);
409 if ((ifp->if_flags & IFF_BROADCAST) &&
410 (ifra->ifra_broadaddr.sin_family == AF_INET))
411 ia->ia_broadaddr = ifra->ifra_broadaddr;
416 * in_ifscrub kills the interface route.
420 * in_ifadown gets rid of all the rest of
421 * the routes. This is not quite the right
422 * thing to do, but at least if we are running
423 * a routing process they will come back.
425 in_ifadown(&ia->ia_ifa, 1);
427 * XXX horrible hack to detect that we are being called
430 if (!ifnet_addrs[ifp->if_index - 1]) {
431 in_pcbpurgeif0(LIST_FIRST(ripcbinfo.listhead), ifp);
432 in_pcbpurgeif0(LIST_FIRST(udbinfo.listhead), ifp);
436 * Protect from ipintr() traversing address list
437 * while we're modifying it.
442 TAILQ_REMOVE(&ifp->if_addrhead, ifa, ifa_link);
444 TAILQ_REMOVE(&in_ifaddrhead, oia, ia_link);
445 IFAFREE(&oia->ia_ifa);
450 if (ifp == 0 || ifp->if_ioctl == 0)
452 return ((*ifp->if_ioctl)(ifp, cmd, data));
459 * SIOCGLIFADDR: get first address. (?!?)
460 * SIOCGLIFADDR with IFLR_PREFIX:
461 * get first address that matches the specified prefix.
462 * SIOCALIFADDR: add the specified address.
463 * SIOCALIFADDR with IFLR_PREFIX:
464 * EINVAL since we can't deduce hostid part of the address.
465 * SIOCDLIFADDR: delete the specified address.
466 * SIOCDLIFADDR with IFLR_PREFIX:
467 * delete the first address that matches the specified prefix.
469 * EINVAL on invalid parameters
470 * EADDRNOTAVAIL on prefix match failed/specified address not found
471 * other values may be returned from in_ioctl()
474 in_lifaddr_ioctl(so, cmd, data, ifp, p)
481 struct if_laddrreq *iflr = (struct if_laddrreq *)data;
486 panic("invalid argument to in_lifaddr_ioctl");
492 /* address must be specified on GET with IFLR_PREFIX */
493 if ((iflr->flags & IFLR_PREFIX) == 0)
498 /* address must be specified on ADD and DELETE */
499 if (iflr->addr.ss_family != AF_INET)
501 if (iflr->addr.ss_len != sizeof(struct sockaddr_in))
503 /* XXX need improvement */
504 if (iflr->dstaddr.ss_family
505 && iflr->dstaddr.ss_family != AF_INET)
507 if (iflr->dstaddr.ss_family
508 && iflr->dstaddr.ss_len != sizeof(struct sockaddr_in))
511 default: /*shouldn't happen*/
514 if (sizeof(struct in_addr) * 8 < iflr->prefixlen)
520 struct in_aliasreq ifra;
522 if (iflr->flags & IFLR_PREFIX)
525 /* copy args to in_aliasreq, perform ioctl(SIOCAIFADDR_IN6). */
526 bzero(&ifra, sizeof(ifra));
527 bcopy(iflr->iflr_name, ifra.ifra_name,
528 sizeof(ifra.ifra_name));
530 bcopy(&iflr->addr, &ifra.ifra_addr, iflr->addr.ss_len);
532 if (iflr->dstaddr.ss_family) { /*XXX*/
533 bcopy(&iflr->dstaddr, &ifra.ifra_dstaddr,
534 iflr->dstaddr.ss_len);
537 ifra.ifra_mask.sin_family = AF_INET;
538 ifra.ifra_mask.sin_len = sizeof(struct sockaddr_in);
539 in_len2mask(&ifra.ifra_mask.sin_addr, iflr->prefixlen);
541 return in_control(so, SIOCAIFADDR, (caddr_t)&ifra, ifp, p);
546 struct in_ifaddr *ia;
547 struct in_addr mask, candidate, match;
548 struct sockaddr_in *sin;
551 bzero(&match.s_addr, sizeof(match.s_addr));
552 bzero(&mask, sizeof(mask));
553 if (iflr->flags & IFLR_PREFIX) {
554 /* lookup a prefix rather than address. */
555 in_len2mask(&mask, iflr->prefixlen);
557 sin = (struct sockaddr_in *)&iflr->addr;
558 match.s_addr = sin->sin_addr.s_addr;
559 match.s_addr &= mask.s_addr;
561 /* if you set extra bits, that's wrong */
562 if (match.s_addr != sin->sin_addr.s_addr)
567 if (cmd == SIOCGLIFADDR) {
568 /* on getting an address, take the 1st match */
571 /* on deleting an address, do exact match */
572 in_len2mask(&mask, 32);
573 sin = (struct sockaddr_in *)&iflr->addr;
574 match.s_addr = sin->sin_addr.s_addr;
580 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
581 if (ifa->ifa_addr->sa_family != AF_INET6)
585 candidate.s_addr = ((struct sockaddr_in *)&ifa->ifa_addr)->sin_addr.s_addr;
586 candidate.s_addr &= mask.s_addr;
587 if (candidate.s_addr == match.s_addr)
591 return EADDRNOTAVAIL;
592 ia = (struct in_ifaddr *)ifa;
594 if (cmd == SIOCGLIFADDR) {
595 /* fill in the if_laddrreq structure */
596 bcopy(&ia->ia_addr, &iflr->addr, ia->ia_addr.sin_len);
598 if ((ifp->if_flags & IFF_POINTOPOINT) != 0) {
599 bcopy(&ia->ia_dstaddr, &iflr->dstaddr,
600 ia->ia_dstaddr.sin_len);
602 bzero(&iflr->dstaddr, sizeof(iflr->dstaddr));
605 in_mask2len(&ia->ia_sockmask.sin_addr);
607 iflr->flags = 0; /*XXX*/
611 struct in_aliasreq ifra;
613 /* fill in_aliasreq and do ioctl(SIOCDIFADDR_IN6) */
614 bzero(&ifra, sizeof(ifra));
615 bcopy(iflr->iflr_name, ifra.ifra_name,
616 sizeof(ifra.ifra_name));
618 bcopy(&ia->ia_addr, &ifra.ifra_addr,
619 ia->ia_addr.sin_len);
620 if ((ifp->if_flags & IFF_POINTOPOINT) != 0) {
621 bcopy(&ia->ia_dstaddr, &ifra.ifra_dstaddr,
622 ia->ia_dstaddr.sin_len);
624 bcopy(&ia->ia_sockmask, &ifra.ifra_dstaddr,
625 ia->ia_sockmask.sin_len);
627 return in_control(so, SIOCDIFADDR, (caddr_t)&ifra,
633 return EOPNOTSUPP; /*just for safety*/
637 * Delete any existing route for an interface.
641 register struct ifnet *ifp;
642 register struct in_ifaddr *ia;
645 if ((ia->ia_flags & IFA_ROUTE) == 0)
647 if (ifp->if_flags & (IFF_LOOPBACK|IFF_POINTOPOINT))
648 rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST);
650 rtinit(&(ia->ia_ifa), (int)RTM_DELETE, 0);
651 ia->ia_flags &= ~IFA_ROUTE;
655 * Initialize an interface's internet address
656 * and routing table entry.
659 in_ifinit(ifp, ia, sin, scrub)
660 register struct ifnet *ifp;
661 register struct in_ifaddr *ia;
662 struct sockaddr_in *sin;
665 register u_long i = ntohl(sin->sin_addr.s_addr);
666 struct sockaddr_in oldaddr;
667 int s = splimp(), flags = RTF_UP, error;
669 oldaddr = ia->ia_addr;
672 * Give the interface a chance to initialize
673 * if this is its first address,
674 * and to validate the address if necessary.
677 (error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)ia))) {
679 ia->ia_addr = oldaddr;
684 ia->ia_ifa.ifa_addr = (struct sockaddr *)&oldaddr;
686 ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr;
689 ia->ia_netmask = IN_CLASSA_NET;
690 else if (IN_CLASSB(i))
691 ia->ia_netmask = IN_CLASSB_NET;
693 ia->ia_netmask = IN_CLASSC_NET;
695 * The subnet mask usually includes at least the standard network part,
696 * but may may be smaller in the case of supernetting.
697 * If it is set, we believe it.
699 if (ia->ia_subnetmask == 0) {
700 ia->ia_subnetmask = ia->ia_netmask;
701 ia->ia_sockmask.sin_addr.s_addr = htonl(ia->ia_subnetmask);
703 ia->ia_netmask &= ia->ia_subnetmask;
704 ia->ia_net = i & ia->ia_netmask;
705 ia->ia_subnet = i & ia->ia_subnetmask;
706 in_socktrim(&ia->ia_sockmask);
708 * Add route for the network.
710 ia->ia_ifa.ifa_metric = ifp->if_metric;
711 if (ifp->if_flags & IFF_BROADCAST) {
712 ia->ia_broadaddr.sin_addr.s_addr =
713 htonl(ia->ia_subnet | ~ia->ia_subnetmask);
714 ia->ia_netbroadcast.s_addr =
715 htonl(ia->ia_net | ~ ia->ia_netmask);
716 } else if (ifp->if_flags & IFF_LOOPBACK) {
717 ia->ia_ifa.ifa_dstaddr = ia->ia_ifa.ifa_addr;
719 } else if (ifp->if_flags & IFF_POINTOPOINT) {
720 if (ia->ia_dstaddr.sin_family != AF_INET)
724 if ((error = rtinit(&(ia->ia_ifa), (int)RTM_ADD, flags)) == 0)
725 ia->ia_flags |= IFA_ROUTE;
726 /* XXX check if the subnet route points to the same interface */
731 * If the interface supports multicast, join the "all hosts"
732 * multicast group on that interface.
734 if (ifp->if_flags & IFF_MULTICAST) {
737 addr.s_addr = htonl(INADDR_ALLHOSTS_GROUP);
738 in_addmulti(&addr, ifp);
745 * Return 1 if the address might be a local broadcast address.
748 in_broadcast(in, ifp)
752 register struct ifaddr *ifa;
755 if (in.s_addr == INADDR_BROADCAST ||
756 in.s_addr == INADDR_ANY)
758 if ((ifp->if_flags & IFF_BROADCAST) == 0)
760 t = ntohl(in.s_addr);
762 * Look through the list of addresses for a match
763 * with a broadcast address.
765 #define ia ((struct in_ifaddr *)ifa)
766 for (ifa = ifp->if_addrhead.tqh_first; ifa;
767 ifa = ifa->ifa_link.tqe_next)
768 if (ifa->ifa_addr->sa_family == AF_INET &&
769 (in.s_addr == ia->ia_broadaddr.sin_addr.s_addr ||
770 in.s_addr == ia->ia_netbroadcast.s_addr ||
772 * Check for old-style (host 0) broadcast.
774 t == ia->ia_subnet || t == ia->ia_net) &&
776 * Check for an all one subnetmask. These
777 * only exist when an interface gets a secondary
780 ia->ia_subnetmask != (u_long)0xffffffff)
786 * Add an address to the list of IP multicast addresses for a given interface.
790 register struct in_addr *ap;
791 register struct ifnet *ifp;
793 register struct in_multi *inm;
795 struct sockaddr_in sin;
796 struct ifmultiaddr *ifma;
800 * Call generic routine to add membership or increment
801 * refcount. It wants addresses in the form of a sockaddr,
802 * so we build one here (being careful to zero the unused bytes).
804 bzero(&sin, sizeof sin);
805 sin.sin_family = AF_INET;
806 sin.sin_len = sizeof sin;
808 error = if_addmulti(ifp, (struct sockaddr *)&sin, &ifma);
815 * If ifma->ifma_protospec is null, then if_addmulti() created
816 * a new record. Otherwise, we are done.
818 if (ifma->ifma_protospec != 0) {
820 return ifma->ifma_protospec;
823 /* XXX - if_addmulti uses M_WAITOK. Can this really be called
824 at interrupt time? If so, need to fix if_addmulti. XXX */
825 inm = (struct in_multi *)malloc(sizeof(*inm), M_IPMADDR, M_NOWAIT);
831 bzero(inm, sizeof *inm);
834 inm->inm_ifma = ifma;
835 ifma->ifma_protospec = inm;
836 LIST_INSERT_HEAD(&in_multihead, inm, inm_link);
839 * Let IGMP know that we have joined a new IP multicast group.
847 * Delete a multicast address record.
851 register struct in_multi *inm;
853 struct ifmultiaddr *ifma = inm->inm_ifma;
854 struct in_multi my_inm;
857 my_inm.inm_ifp = NULL ; /* don't send the leave msg */
858 if (ifma->ifma_refcount == 1) {
860 * No remaining claims to this record; let IGMP know that
861 * we are leaving the multicast group.
862 * But do it after the if_delmulti() which might reset
863 * the interface and nuke the packet.
866 ifma->ifma_protospec = 0;
867 LIST_REMOVE(inm, inm_link);
868 free(inm, M_IPMADDR);
870 /* XXX - should be separate API for when we have an ifma? */
871 if_delmulti(ifma->ifma_ifp, ifma->ifma_addr);
872 if (my_inm.inm_ifp != NULL)
873 igmp_leavegroup(&my_inm);