summaryrefslogtreecommitdiff
path: root/sys/net
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2013-03-20 10:34:13 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2013-03-20 10:34:13 +0000
commit9be5a92778d20a28277219de0503e8681fe31933 (patch)
tree55705a41be9a5135b765807e922c6fc4873ac38d /sys/net
parent3ab723c5b4108351c6e97f06d1d555a7385856d4 (diff)
Introduce if_get() to retrieve an interface descriptor pointer given
an interface index and replace all the redondant checks and accesses to a global array by a call to this function. With imputs from and ok bluhm@, mikeb@
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/if.c26
-rw-r--r--sys/net/if.h5
2 files changed, 21 insertions, 10 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index 7b240389444..6d6f5cc70fb 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.251 2013/03/15 20:45:34 tedu Exp $ */
+/* $OpenBSD: if.c,v 1.252 2013/03/20 10:34:12 mpi Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -190,8 +190,8 @@ ifinit()
if_slowtimo(&if_slowtim);
}
-static int if_index = 0;
-int if_indexlim = 0;
+static unsigned int if_index = 0;
+static unsigned int if_indexlim = 0;
struct ifaddr **ifnet_addrs = NULL;
struct ifnet **ifindex2ifnet = NULL;
struct ifnet_head ifnet = TAILQ_HEAD_INITIALIZER(ifnet);
@@ -932,8 +932,7 @@ ifa_ifwithnet(struct sockaddr *addr, u_int rdomain)
rdomain = rtable_l2(rdomain);
if (af == AF_LINK) {
struct sockaddr_dl *sdl = (struct sockaddr_dl *)addr;
- if (sdl->sdl_index && sdl->sdl_index < if_indexlim &&
- ifindex2ifnet[sdl->sdl_index])
+ if (sdl->sdl_index && if_get(sdl->sdl_index))
return (ifnet_addrs[sdl->sdl_index]);
}
TAILQ_FOREACH(ifp, &ifnet, if_list) {
@@ -1164,8 +1163,7 @@ if_slowtimo(void *arg)
}
/*
- * Map interface name to
- * interface structure pointer.
+ * Map interface name to interface structure pointer.
*/
struct ifnet *
ifunit(const char *name)
@@ -1180,6 +1178,20 @@ ifunit(const char *name)
}
/*
+ * Map interface index to interface structure pointer.
+ */
+struct ifnet *
+if_get(unsigned int index)
+{
+ struct ifnet *ifp = NULL;
+
+ if (index < if_indexlim)
+ ifp = ifindex2ifnet[index];
+
+ return (ifp);
+}
+
+/*
* Interface ioctls.
*/
int
diff --git a/sys/net/if.h b/sys/net/if.h
index 5c3d4d1251a..f496059d9d9 100644
--- a/sys/net/if.h
+++ b/sys/net/if.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.h,v 1.139 2013/03/07 09:40:19 mpi Exp $ */
+/* $OpenBSD: if.h,v 1.140 2013/03/20 10:34:12 mpi Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
@@ -798,9 +798,7 @@ do { \
extern int ifqmaxlen;
extern struct ifnet_head ifnet;
-extern struct ifnet **ifindex2ifnet;
extern struct ifnet *lo0ifp;
-extern int if_indexlim;
#define ether_input_mbuf(ifp, m) ether_input((ifp), NULL, (m))
@@ -833,6 +831,7 @@ int if_addgroup(struct ifnet *, const char *);
int if_delgroup(struct ifnet *, const char *);
void if_group_routechange(struct sockaddr *, struct sockaddr *);
struct ifnet *ifunit(const char *);
+struct ifnet *if_get(unsigned int);
void if_start(struct ifnet *);
void ifnewlladdr(struct ifnet *);