diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2013-10-09 09:33:44 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2013-10-09 09:33:44 +0000 |
commit | 09031ac62e58cfacdc7e5781a0626dcd9a0b906e (patch) | |
tree | fe67c1e7504b1c96c7a57cfc91278d421b2f83ef /sys/netinet | |
parent | be759b8c35882bf5d34e4710d483a191c245250b (diff) |
Introduce in_ifdetach() a function to remove all the IPv4 addresses
of an interface, named after its IPv6 equivalent.
Make use of it instead of removing addresses by hand when detaching
or destroying an interface. As a bonus, multicast records linked
to the just divorced^Wdetached interface are no longer leaked.
No objection from the gang, ok mikeb@
Diffstat (limited to 'sys/netinet')
-rw-r--r-- | sys/netinet/in.c | 15 | ||||
-rw-r--r-- | sys/netinet/in.h | 3 |
2 files changed, 16 insertions, 2 deletions
diff --git a/sys/netinet/in.c b/sys/netinet/in.c index b5723f8f5c1..386ea9732be 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in.c,v 1.85 2013/09/26 08:53:17 mpi Exp $ */ +/* $OpenBSD: in.c,v 1.86 2013/10/09 09:33:43 mpi Exp $ */ /* $NetBSD: in.c,v 1.26 1996/02/13 23:41:39 christos Exp $ */ /* @@ -1017,3 +1017,16 @@ in_delmulti(struct in_multi *inm) } #endif + +void +in_ifdetach(struct ifnet *ifp) +{ + struct ifaddr *ifa, *next; + + /* nuke any of IPv4 addresses we have */ + TAILQ_FOREACH_SAFE(ifa, &ifp->if_addrlist, ifa_list, next) { + if (ifa->ifa_addr->sa_family != AF_INET) + continue; + in_purgeaddr(ifa); + } +} diff --git a/sys/netinet/in.h b/sys/netinet/in.h index 175129f9829..6df6ffab0d1 100644 --- a/sys/netinet/in.h +++ b/sys/netinet/in.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in.h,v 1.96 2013/03/28 15:05:32 bluhm Exp $ */ +/* $OpenBSD: in.h,v 1.97 2013/10/09 09:33:43 mpi Exp $ */ /* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */ /* @@ -840,6 +840,7 @@ int in_localaddr(struct in_addr, u_int); void in_socktrim(struct sockaddr_in *); char *inet_ntoa(struct in_addr); void in_proto_cksum_out(struct mbuf *, struct ifnet *); +void in_ifdetach(struct ifnet *); #define in_hosteq(s,t) ((s).s_addr == (t).s_addr) #define in_nullhost(x) ((x).s_addr == INADDR_ANY) |