diff options
| author | itojun <itojun@NetBSD.org> | 2003-12-10 11:46:33 +0000 |
|---|---|---|
| committer | itojun <itojun@NetBSD.org> | 2003-12-10 11:46:33 +0000 |
| commit | aa8a6718f04420c2621ccb75de2e2ffa08869d43 (patch) | |
| tree | ab7859a1335713e7d3ccdae75ffd898626724a57 | |
| parent | fbae381aaa42360e3c45875f461e67347695bf0c (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
| -rw-r--r-- | sys/net/if.c | 13 | ||||
| -rw-r--r-- | sys/net/if.h | 4 | ||||
| -rw-r--r-- | sys/netinet/ip_output.c | 8 | ||||
| -rw-r--r-- | sys/netinet6/in6.c | 6 | ||||
| -rw-r--r-- | sys/netinet6/in6_src.c | 13 | ||||
| -rw-r--r-- | sys/netinet6/ip6_mroute.c | 7 | ||||
| -rw-r--r-- | sys/netinet6/ip6_output.c | 20 | ||||
| -rw-r--r-- | sys/netinet6/nd6_rtr.c | 6 |
8 files changed, 44 insertions, 33 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 *)); diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 4a0921fac4e..c76cdfd89ff 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -1,4 +1,4 @@ -/* $NetBSD: ip_output.c,v 1.128 2003/11/19 18:39:34 jonathan Exp $ */ +/* $NetBSD: ip_output.c,v 1.129 2003/12/10 11:46:33 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -98,7 +98,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.128 2003/11/19 18:39:34 jonathan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.129 2003/12/10 11:46:33 itojun Exp $"); #include "opt_pfil_hooks.h" #include "opt_inet.h" @@ -1492,9 +1492,11 @@ ip_multicast_if(a, ifindexp) *ifindexp = 0; if (ntohl(a->s_addr) >> 24 == 0) { ifindex = ntohl(a->s_addr) & 0xffffff; - if (ifindex < 0 || if_index < ifindex) + if (ifindex < 0 || if_indexlim <= ifindex) return NULL; ifp = ifindex2ifnet[ifindex]; + if (!ifp) + return NULL; if (ifindexp) *ifindexp = ifindex; } else { diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index a7bc28bd48e..7c3281d74a5 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1,4 +1,4 @@ -/* $NetBSD: in6.c,v 1.83 2003/12/04 13:57:31 keihan Exp $ */ +/* $NetBSD: in6.c,v 1.84 2003/12/10 11:46:33 itojun Exp $ */ /* $KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $ */ /* @@ -62,7 +62,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.83 2003/12/04 13:57:31 keihan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.84 2003/12/10 11:46:33 itojun Exp $"); #include "opt_inet.h" @@ -293,7 +293,7 @@ in6_ifindex2scopeid(idx) struct ifaddr *ifa; struct sockaddr_in6 *sin6; - if (idx < 0 || if_index < idx) + if (idx < 0 || if_indexlim <= idx) return -1; ifp = ifindex2ifnet[idx]; if (!ifp) diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c index 8a268b2e6e6..b68abf6db38 100644 --- a/sys/netinet6/in6_src.c +++ b/sys/netinet6/in6_src.c @@ -1,4 +1,4 @@ -/* $NetBSD: in6_src.c,v 1.17 2003/09/04 09:17:08 itojun Exp $ */ +/* $NetBSD: in6_src.c,v 1.18 2003/12/10 11:46:33 itojun Exp $ */ /* $KAME: in6_src.c,v 1.36 2001/02/06 04:08:17 itojun Exp $ */ /* @@ -62,7 +62,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.17 2003/09/04 09:17:08 itojun Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.18 2003/12/10 11:46:33 itojun Exp $"); #include "opt_inet.h" @@ -169,7 +169,8 @@ in6_selectsrc(dstsock, opts, mopts, ro, laddr, errorp) * somewhere... */ if (dstsock->sin6_scope_id < 0 || - if_index < dstsock->sin6_scope_id) { + if_indexlim <= dstsock->sin6_scope_id || + !ifindex2ifnet[dstsock->sin6_scope_id]) { *errorp = ENXIO; /* XXX: better error? */ return (0); } @@ -464,7 +465,8 @@ in6_embedscope(in6, sin6, in6p, ifpp) in6->s6_addr16[1] = htons(ifp->if_index); } else if (scopeid) { /* boundary check */ - if (scopeid < 0 || if_index < scopeid) + if (scopeid < 0 || if_indexlim <= scopeid || + !ifindex2ifnet[scopeid]) return ENXIO; /* XXX EINVAL? */ ifp = ifindex2ifnet[scopeid]; /* XXX assignment to 16bit from 32bit variable */ @@ -508,7 +510,8 @@ in6_recoverscope(sin6, in6, ifp) scopeid = ntohs(sin6->sin6_addr.s6_addr16[1]); if (scopeid) { /* sanity check */ - if (scopeid < 0 || if_index < scopeid) + if (scopeid < 0 || if_indexlim <= scopeid || + !ifindex2ifnet[scopeid]) return ENXIO; if (ifp && ifp->if_index != scopeid) return ENXIO; diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c index f33835b82a9..d7ade48c162 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_mroute.c,v 1.59 2003/12/10 09:28:38 itojun Exp $ */ +/* $NetBSD: ip6_mroute.c,v 1.60 2003/12/10 11:46:33 itojun Exp $ */ /* $KAME: ip6_mroute.c,v 1.49 2001/07/25 09:21:18 jinmei Exp $ */ /* @@ -117,7 +117,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.59 2003/12/10 09:28:38 itojun Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.60 2003/12/10 11:46:33 itojun Exp $"); #include "opt_inet.h" #include "opt_mrouting.h" @@ -650,7 +650,8 @@ add_m6if(mifcp) mifp = mif6table + mifcp->mif6c_mifi; if (mifp->m6_ifp) return EADDRINUSE; /* XXX: is it appropriate? */ - if (mifcp->mif6c_pifi == 0 || mifcp->mif6c_pifi > if_index) + if (mifcp->mif6c_pifi == 0 || mifcp->mif6c_pifi >= if_indexlim || + !ifindex2ifnet[mifcp->mif6c_pifi]) return ENXIO; /* * XXX: some OSes can remove ifp and clear ifindex2ifnet[id] diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index 64761c71399..e17439be0ec 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_output.c,v 1.73 2003/11/06 06:10:51 itojun Exp $ */ +/* $NetBSD: ip6_output.c,v 1.74 2003/12/10 11:46:33 itojun Exp $ */ /* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */ /* @@ -62,7 +62,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.73 2003/11/06 06:10:51 itojun Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.74 2003/12/10 11:46:33 itojun Exp $"); #include "opt_inet.h" #include "opt_ipsec.h" @@ -1714,7 +1714,8 @@ ip6_setmoptions(optname, im6op, m) break; } bcopy(mtod(m, u_int *), &ifindex, sizeof(ifindex)); - if (ifindex < 0 || if_index < ifindex) { + if (ifindex < 0 || if_indexlim <= ifindex || + !ifindex2ifnet[ifindex]) { error = ENXIO; /* XXX EINVAL? */ break; } @@ -1793,7 +1794,8 @@ ip6_setmoptions(optname, im6op, m) * If the interface is specified, validate it. */ if (mreq->ipv6mr_interface < 0 || - if_index < mreq->ipv6mr_interface) { + if_indexlim <= mreq->ipv6mr_interface || + !ifindex2ifnet[mreq->ipv6mr_interface]) { error = ENXIO; /* XXX EINVAL? */ break; } @@ -1892,8 +1894,9 @@ ip6_setmoptions(optname, im6op, m) * If an interface address was specified, get a pointer * to its ifnet structure. */ - if (mreq->ipv6mr_interface < 0 - || if_index < mreq->ipv6mr_interface) { + if (mreq->ipv6mr_interface < 0 || + if_indexlim <= mreq->ipv6mr_interface || + !ifindex2ifnet[mreq->ipv6mr_interface]) { error = ENXIO; /* XXX EINVAL? */ break; } @@ -2058,8 +2061,9 @@ ip6_setpktoptions(control, opt, priv) opt->ip6po_pktinfo->ipi6_addr.s6_addr16[1] = htons(opt->ip6po_pktinfo->ipi6_ifindex); - if (opt->ip6po_pktinfo->ipi6_ifindex > if_index || - opt->ip6po_pktinfo->ipi6_ifindex < 0) { + if (opt->ip6po_pktinfo->ipi6_ifindex >= if_indexlim || + opt->ip6po_pktinfo->ipi6_ifindex < 0 || + !ifindex2ifnet[opt->ip6po_pktinfo->ipi6_ifindex]) { return (ENXIO); } diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index f909a6b8915..8e2635bba7b 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -1,4 +1,4 @@ -/* $NetBSD: nd6_rtr.c,v 1.46 2003/10/30 01:43:10 simonb Exp $ */ +/* $NetBSD: nd6_rtr.c,v 1.47 2003/12/10 11:46:33 itojun Exp $ */ /* $KAME: nd6_rtr.c,v 1.95 2001/02/07 08:09:47 itojun Exp $ */ /* @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.46 2003/10/30 01:43:10 simonb Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.47 2003/12/10 11:46:33 itojun Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -1983,7 +1983,7 @@ nd6_setdefaultiface(ifindex) { int error = 0; - if (ifindex < 0 || if_index < ifindex) + if (ifindex < 0 || if_indexlim <= ifindex || !ifindex2ifnet[ifindex]) return (EINVAL); if (nd6_defifindex != ifindex) { |
