Module Name:    src
Committed By:   ozaki-r
Date:           Mon Jun 29 09:40:36 UTC 2015

Modified Files:
        src/sys/net: if.c

Log Message:
Remove ifnet_addrs

We can assume that ifnet_addrs[ifp->if_index] is always the same as
ifp->if_dl, so we can replace ifnet_addrs[ifp->if_index] with ifp->if_dl
and remove ifnet_addrs entirely.

ok martin@


To generate a diff of this commit:
cvs rdiff -u -r1.315 -r1.316 src/sys/net/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.315 src/sys/net/if.c:1.316
--- src/sys/net/if.c:1.315	Mon May 18 06:38:59 2015
+++ src/sys/net/if.c	Mon Jun 29 09:40:36 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.315 2015/05/18 06:38:59 martin Exp $	*/
+/*	$NetBSD: if.c,v 1.316 2015/06/29 09:40:36 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.315 2015/05/18 06:38:59 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.316 2015/06/29 09:40:36 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -169,8 +169,6 @@ static uint64_t			index_gen;
 static kmutex_t			index_gen_mtx;
 static kmutex_t			if_clone_mtx;
 
-static struct ifaddr **		ifnet_addrs = NULL;
-
 struct ifnet *lo0ifp;
 int	ifqmaxlen = IFQ_MAXLEN;
 
@@ -407,8 +405,7 @@ static void
 if_sadl_setrefs(struct ifnet *ifp, struct ifaddr *ifa)
 {
 	const struct sockaddr_dl *sdl;
-	ifnet_addrs[ifp->if_index] = ifa;
-	ifaref(ifa);
+
 	ifp->if_dl = ifa;
 	ifaref(ifa);
 	sdl = satosdl(ifa->ifa_addr);
@@ -452,8 +449,6 @@ if_deactivate_sadl(struct ifnet *ifp)
 
 	ifp->if_sadl = NULL;
 
-	ifnet_addrs[ifp->if_index] = NULL;
-	ifafree(ifa);
 	ifp->if_dl = NULL;
 	ifafree(ifa);
 }
@@ -484,15 +479,13 @@ if_free_sadl(struct ifnet *ifp)
 	struct ifaddr *ifa;
 	int s;
 
-	ifa = ifnet_addrs[ifp->if_index];
+	ifa = ifp->if_dl;
 	if (ifa == NULL) {
 		KASSERT(ifp->if_sadl == NULL);
-		KASSERT(ifp->if_dl == NULL);
 		return;
 	}
 
 	KASSERT(ifp->if_sadl != NULL);
-	KASSERT(ifp->if_dl != NULL);
 
 	s = splnet();
 	rtinit(ifa, RTM_DELETE, 0);
@@ -547,13 +540,10 @@ if_getindex(ifnet_t *ifp)
 	}
 skip:
 	/*
-	 * We have some arrays that should be indexed by if_index.
-	 * since if_index will grow dynamically, they should grow too.
-	 *	struct ifadd **ifnet_addrs
-	 *	struct ifnet **ifindex2ifnet
+	 * ifindex2ifnet is indexed by if_index. Since if_index will
+	 * grow dynamically, it should grow too.
 	 */
-	if (ifnet_addrs == NULL || ifindex2ifnet == NULL ||
-	    ifp->if_index >= if_indexlim) {
+	if (ifindex2ifnet == NULL || ifp->if_index >= if_indexlim) {
 		size_t m, n, oldlim;
 		void *q;
 
@@ -561,16 +551,6 @@ skip:
 		while (ifp->if_index >= if_indexlim)
 			if_indexlim <<= 1;
 
-		/* grow ifnet_addrs */
-		m = oldlim * sizeof(struct ifaddr *);
-		n = if_indexlim * sizeof(struct ifaddr *);
-		q = malloc(n, M_IFADDR, M_WAITOK|M_ZERO);
-		if (ifnet_addrs != NULL) {
-			memcpy(q, ifnet_addrs, m);
-			free(ifnet_addrs, M_IFADDR);
-		}
-		ifnet_addrs = (struct ifaddr **)q;
-
 		/* grow ifindex2ifnet */
 		m = oldlim * sizeof(struct ifnet *);
 		n = if_indexlim * sizeof(struct ifnet *);
@@ -1260,8 +1240,9 @@ ifa_ifwithnet(const struct sockaddr *add
 		sdl = satocsdl(addr);
 		if (sdl->sdl_index && sdl->sdl_index < if_indexlim &&
 		    ifindex2ifnet[sdl->sdl_index] &&
-		    ifindex2ifnet[sdl->sdl_index]->if_output != if_nulloutput)
-			return ifnet_addrs[sdl->sdl_index];
+		    ifindex2ifnet[sdl->sdl_index]->if_output != if_nulloutput) {
+			return ifindex2ifnet[sdl->sdl_index]->if_dl;
+		}
 	}
 #ifdef NETATALK
 	if (af == AF_APPLETALK) {

Reply via email to