Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net (1) Make if_index "wrap" at USHRT_MAX instead of goi...
details: https://anonhg.NetBSD.org/src/rev/589ef4ef27a2
branches: trunk
changeset: 521942:589ef4ef27a2
user: atatat <atatat%NetBSD.org@localhost>
date: Sat Feb 09 05:56:34 2002 +0000
description:
(1) Make if_index "wrap" at USHRT_MAX instead of going above it so
that other parts of the kernel won't lose gratuitously. There are
places where it's assumed that it won't grow that large.
(2) Avoid accidental reuse of occupied slots in the ifindex2ifnet[]
table.
diffstat:
sys/net/if.c | 44 ++++++++++++++++++++++++++++++++++++++------
1 files changed, 38 insertions(+), 6 deletions(-)
diffs (76 lines):
diff -r 567bb049323a -r 589ef4ef27a2 sys/net/if.c
--- a/sys/net/if.c Sat Feb 09 05:01:39 2002 +0000
+++ b/sys/net/if.c Sat Feb 09 05:56:34 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if.c,v 1.101 2001/12/02 19:44:25 abs Exp $ */
+/* $NetBSD: if.c,v 1.102 2002/02/09 05:56:34 atatat Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -101,7 +101,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.101 2001/12/02 19:44:25 abs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.102 2002/02/09 05:56:34 atatat Exp $");
#include "opt_inet.h"
@@ -256,7 +256,7 @@
/* Nothing. */
}
-int if_index = 0;
+int if_index = 1;
struct ifaddr **ifnet_addrs = NULL;
struct ifnet **ifindex2ifnet = NULL;
@@ -354,13 +354,45 @@
if_attach(ifp)
struct ifnet *ifp;
{
- static size_t if_indexlim = 8;
+ static size_t if_indexlim = 0;
+ int indexlim = 0;
- if (if_index == 0)
+ if (if_indexlim == 0) {
TAILQ_INIT(&ifnet);
+ if_indexlim = 8;
+ }
TAILQ_INIT(&ifp->if_addrlist);
TAILQ_INSERT_TAIL(&ifnet, ifp, if_list);
- ifp->if_index = ++if_index;
+ ifp->if_index = if_index;
+ if (ifindex2ifnet == 0)
+ if_index++;
+ else
+ while (ifindex2ifnet[ifp->if_index] != NULL) {
+ ++if_index;
+ if (if_index == 0)
+ if_index = 1;
+ /*
+ * If we hit USHRT_MAX, we skip back to 0 since
+ * there are a number of places where the value
+ * of if_index or if_index itself is compared
+ * to to or stored in an unsigned short. By
+ * jumping back, we won't botch those assignments
+ * or comparisons.
+ */
+ else if (if_index == USHRT_MAX) {
+ /*
+ * However, if we have to jump back to
+ * zero *twice* without finding an empty
+ * slot in ifindex2ifnet[], then there
+ * there are too many (>65535) interfaces.
+ */
+ if (indexlim++)
+ panic("too many interfaces");
+ else
+ if_index = 1;
+ }
+ ifp->if_index = if_index;
+ }
/*
* We have some arrays that should be indexed by if_index.
Home |
Main Index |
Thread Index |
Old Index