summaryrefslogtreecommitdiff
path: root/sys/net
diff options
context:
space:
mode:
authoritojun <itojun@NetBSD.org>2003-12-10 11:46:33 +0000
committeritojun <itojun@NetBSD.org>2003-12-10 11:46:33 +0000
commitaa8a6718f04420c2621ccb75de2e2ffa08869d43 (patch)
treeab7859a1335713e7d3ccdae75ffd898626724a57 /sys/net
parentfbae381aaa42360e3c45875f461e67347695bf0c (diff)
use if_indexlim (instead of if_index) and ifindex2ifnet[x] != NULL
to check if interface exists, as (1) if_index has different meaning (2) ifindex2ifnet could become NULL when interface gets destroyed, since when we have introduced dynamically-created interfaces. from kame
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/if.c13
-rw-r--r--sys/net/if.h4
2 files changed, 9 insertions, 8 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index 55d00835e0c..885138b5e3b 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $NetBSD: if.c,v 1.136 2003/12/04 19:38:24 atatat Exp $ */
+/* $NetBSD: if.c,v 1.137 2003/12/10 11:46:33 itojun Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.136 2003/12/04 19:38:24 atatat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.137 2003/12/10 11:46:33 itojun Exp $");
#include "opt_inet.h"
@@ -255,8 +255,9 @@ if_nulldrain(ifp)
/* Nothing. */
}
-u_int if_index = 1;
+static u_int if_index = 1;
struct ifnet_head ifnet;
+size_t if_indexlim = 0;
struct ifaddr **ifnet_addrs = NULL;
struct ifnet **ifindex2ifnet = NULL;
@@ -354,7 +355,6 @@ void
if_attach(ifp)
struct ifnet *ifp;
{
- static size_t if_indexlim = 0;
int indexlim = 0;
if (if_indexlim == 0) {
@@ -980,7 +980,8 @@ ifa_ifwithnet(addr)
if (af == AF_LINK) {
sdl = (struct sockaddr_dl *)addr;
- if (sdl->sdl_index && sdl->sdl_index <= if_index &&
+ 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]);
}
@@ -1296,7 +1297,7 @@ ifunit(name)
* If the number took all of the name, then it's a valid ifindex.
*/
if (i == IFNAMSIZ || (cp != name && *cp == '\0')) {
- if (unit >= if_index)
+ if (unit >= if_indexlim)
return (NULL);
ifp = ifindex2ifnet[unit];
if (ifp == NULL || ifp->if_output == if_nulloutput)
diff --git a/sys/net/if.h b/sys/net/if.h
index d54a6550501..44c0182202d 100644
--- a/sys/net/if.h
+++ b/sys/net/if.h
@@ -1,4 +1,4 @@
-/* $NetBSD: if.h,v 1.94 2003/11/28 08:56:48 keihan Exp $ */
+/* $NetBSD: if.h,v 1.95 2003/12/10 11:46:33 itojun Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -736,7 +736,7 @@ extern struct ifnet **ifindex2ifnet;
#if 0
struct ifnet loif[];
#endif
-extern u_int if_index;
+extern size_t if_indexlim;
char *ether_sprintf __P((const u_char *));