Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/netinet undo interface address addition attempt, when in...
details: https://anonhg.NetBSD.org/src/rev/15b906b1cc52
branches: trunk
changeset: 483530:15b906b1cc52
user: itojun <itojun%NetBSD.org@localhost>
date: Sun Mar 12 05:01:16 2000 +0000
description:
undo interface address addition attempt, when in_ifinit fails.
(this basically avoids memory leakage)
diffstat:
sys/netinet/in.c | 25 +++++++++++++++++++++----
1 files changed, 21 insertions(+), 4 deletions(-)
diffs (61 lines):
diff -r 4c144daeec3d -r 15b906b1cc52 sys/netinet/in.c
--- a/sys/netinet/in.c Sun Mar 12 04:59:24 2000 +0000
+++ b/sys/netinet/in.c Sun Mar 12 05:01:16 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: in.c,v 1.55 2000/03/06 19:33:13 itojun Exp $ */
+/* $NetBSD: in.c,v 1.56 2000/03/12 05:01:16 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -316,6 +316,7 @@
struct in_aliasreq *ifra = (struct in_aliasreq *)data;
struct sockaddr_in oldaddr;
int error, hostIsNew, maskIsNew;
+ int newifaddr;
#if NGIF > 0
if (ifp && ifp->if_type == IFT_GIF) {
@@ -408,7 +409,10 @@
LIST_INIT(&ia->ia_multiaddrs);
if ((ifp->if_flags & IFF_LOOPBACK) == 0)
in_interfaces++;
- }
+
+ newifaddr = 1;
+ } else
+ newifaddr = 0;
break;
case SIOCSIFBRDADDR:
@@ -471,7 +475,17 @@
break;
case SIOCSIFADDR:
- return (in_ifinit(ifp, ia, satosin(&ifr->ifr_addr), 1));
+ error = in_ifinit(ifp, ia, satosin(&ifr->ifr_addr), 1);
+ undo:
+ if (error && newifaddr) {
+ TAILQ_REMOVE(&ifp->if_addrlist, &ia->ia_ifa, ifa_list);
+ IFAFREE(&ia->ia_ifa);
+ TAILQ_REMOVE(&in_ifaddr, ia, ia_list);
+ IFAFREE(&ia->ia_ifa);
+ if ((ifp->if_flags & IFF_LOOPBACK) == 0)
+ in_interfaces--;
+ }
+ return error;
case SIOCSIFNETMASK:
ia->ia_subnetmask = ia->ia_sockmask.sin_addr.s_addr =
@@ -502,8 +516,11 @@
maskIsNew = 1; /* We lie; but the effect's the same */
}
if (ifra->ifra_addr.sin_family == AF_INET &&
- (hostIsNew || maskIsNew))
+ (hostIsNew || maskIsNew)) {
error = in_ifinit(ifp, ia, &ifra->ifra_addr, 0);
+ if (error)
+ goto undo;
+ }
if ((ifp->if_flags & IFF_BROADCAST) &&
(ifra->ifra_broadaddr.sin_family == AF_INET))
ia->ia_broadaddr = ifra->ifra_broadaddr;
Home |
Main Index |
Thread Index |
Old Index