Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Remove ifnet_addrs



details:   https://anonhg.NetBSD.org/src/rev/dc00714f0314
branches:  trunk
changeset: 809282:dc00714f0314
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Mon Jun 29 09:40:36 2015 +0000

description:
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@

diffstat:

 sys/net/if.c |  39 ++++++++++-----------------------------
 1 files changed, 10 insertions(+), 29 deletions(-)

diffs (109 lines):

diff -r c789ab415d68 -r dc00714f0314 sys/net/if.c
--- a/sys/net/if.c      Mon Jun 29 08:40:52 2015 +0000
+++ b/sys/net/if.c      Mon Jun 29 09:40:36 2015 +0000
@@ -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 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 @@
 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 @@
 
        ifp->if_sadl = NULL;
 
-       ifnet_addrs[ifp->if_index] = NULL;
-       ifafree(ifa);
        ifp->if_dl = NULL;
        ifafree(ifa);
 }
@@ -484,15 +479,13 @@
        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 @@
        }
 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 @@
                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 @@
                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) {



Home | Main Index | Thread Index | Old Index