Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Replace open-coded access (and boundary checking) of ifi...
details: https://anonhg.NetBSD.org/src/rev/f24c15a569d1
branches: trunk
changeset: 329277:f24c15a569d1
user: rmind <rmind%NetBSD.org@localhost>
date: Sat May 17 21:26:20 2014 +0000
description:
Replace open-coded access (and boundary checking) of ifindex2ifnet with
if_byindex() function.
diffstat:
sys/compat/linux/common/linux_socket.c | 9 +++------
sys/compat/linux32/common/linux32_socket.c | 9 +++------
sys/netinet/ip_output.c | 8 +++-----
sys/netinet6/in6_src.c | 6 +++---
sys/netinet6/ip6_mroute.c | 12 +++---------
sys/netinet6/ip6_output.c | 22 +++++++---------------
sys/netinet6/nd6_rtr.c | 18 +++++++-----------
sys/netinet6/scope6.c | 25 ++++++-------------------
8 files changed, 35 insertions(+), 74 deletions(-)
diffs (truncated from 326 to 300 lines):
diff -r d30769b8cf36 -r f24c15a569d1 sys/compat/linux/common/linux_socket.c
--- a/sys/compat/linux/common/linux_socket.c Sat May 17 21:22:56 2014 +0000
+++ b/sys/compat/linux/common/linux_socket.c Sat May 17 21:26:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_socket.c,v 1.117 2014/01/27 19:19:15 njoly Exp $ */
+/* $NetBSD: linux_socket.c,v 1.118 2014/05/17 21:26:20 rmind Exp $ */
/*-
* Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.117 2014/01/27 19:19:15 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.118 2014/05/17 21:26:20 rmind Exp $");
#if defined(_KERNEL_OPT)
#include "opt_inet.h"
@@ -1105,10 +1105,7 @@
if (error)
return error;
- if (ifr.ifr_ifru.ifru_ifindex >= if_indexlim)
- return ENODEV;
-
- ifp = ifindex2ifnet[ifr.ifr_ifru.ifru_ifindex];
+ ifp = if_byindex(ifr.ifr_ifru.ifru_ifindex);
if (ifp == NULL)
return ENODEV;
diff -r d30769b8cf36 -r f24c15a569d1 sys/compat/linux32/common/linux32_socket.c
--- a/sys/compat/linux32/common/linux32_socket.c Sat May 17 21:22:56 2014 +0000
+++ b/sys/compat/linux32/common/linux32_socket.c Sat May 17 21:26:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux32_socket.c,v 1.17 2013/01/11 19:01:36 christos Exp $ */
+/* $NetBSD: linux32_socket.c,v 1.18 2014/05/17 21:26:20 rmind Exp $ */
/*-
* Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.17 2013/01/11 19:01:36 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.18 2014/05/17 21:26:20 rmind Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -398,10 +398,7 @@
if (error)
return error;
- if (ifr.ifr_ifru.ifru_ifindex >= if_indexlim)
- return ENODEV;
-
- ifp = ifindex2ifnet[ifr.ifr_ifru.ifru_ifindex];
+ ifp = if_byindex(ifr.ifr_ifru.ifru_ifindex);
if (ifp == NULL)
return ENODEV;
diff -r d30769b8cf36 -r f24c15a569d1 sys/netinet/ip_output.c
--- a/sys/netinet/ip_output.c Sat May 17 21:22:56 2014 +0000
+++ b/sys/netinet/ip_output.c Sat May 17 21:26:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_output.c,v 1.224 2013/06/29 21:06:58 rmind Exp $ */
+/* $NetBSD: ip_output.c,v 1.225 2014/05/17 21:26:20 rmind Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.224 2013/06/29 21:06:58 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.225 2014/05/17 21:26:20 rmind Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@@ -1315,9 +1315,7 @@
*ifindexp = 0;
if (ntohl(a->s_addr) >> 24 == 0) {
ifindex = ntohl(a->s_addr) & 0xffffff;
- if (ifindex < 0 || if_indexlim <= ifindex)
- return NULL;
- ifp = ifindex2ifnet[ifindex];
+ ifp = if_byindex(ifindex);
if (!ifp)
return NULL;
if (ifindexp)
diff -r d30769b8cf36 -r f24c15a569d1 sys/netinet6/in6_src.c
--- a/sys/netinet6/in6_src.c Sat May 17 21:22:56 2014 +0000
+++ b/sys/netinet6/in6_src.c Sat May 17 21:26:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: in6_src.c,v 1.53 2012/06/25 15:28:39 christos Exp $ */
+/* $NetBSD: in6_src.c,v 1.54 2014/05/17 21:26:20 rmind Exp $ */
/* $KAME: in6_src.c,v 1.159 2005/10/19 01:40:32 t-momose Exp $ */
/*
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.53 2012/06/25 15:28:39 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.54 2014/05/17 21:26:20 rmind Exp $");
#include "opt_inet.h"
@@ -591,7 +591,7 @@
/* If the caller specify the outgoing interface explicitly, use it. */
if (opts && (pi = opts->ip6po_pktinfo) != NULL && pi->ipi6_ifindex) {
/* XXX boundary check is assumed to be already done. */
- ifp = ifindex2ifnet[pi->ipi6_ifindex];
+ ifp = if_byindex(pi->ipi6_ifindex);
if (ifp != NULL &&
(norouteok || retrt == NULL ||
IN6_IS_ADDR_MULTICAST(dst))) {
diff -r d30769b8cf36 -r f24c15a569d1 sys/netinet6/ip6_mroute.c
--- a/sys/netinet6/ip6_mroute.c Sat May 17 21:22:56 2014 +0000
+++ b/sys/netinet6/ip6_mroute.c Sat May 17 21:26:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ip6_mroute.c,v 1.106 2014/02/25 18:30:12 pooka Exp $ */
+/* $NetBSD: ip6_mroute.c,v 1.107 2014/05/17 21:26:20 rmind 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.106 2014/02/25 18:30:12 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.107 2014/05/17 21:26:20 rmind Exp $");
#include "opt_inet.h"
#include "opt_mrouting.h"
@@ -658,13 +658,7 @@
mifp = mif6table + mifcp->mif6c_mifi;
if (mifp->m6_ifp)
return EADDRINUSE; /* XXX: is it appropriate? */
- if (mifcp->mif6c_pifi == 0 || mifcp->mif6c_pifi >= if_indexlim)
- return ENXIO;
- /*
- * XXX: some OSes can remove ifp and clear ifindex2ifnet[id]
- * even for id between 0 and if_index.
- */
- if ((ifp = ifindex2ifnet[mifcp->mif6c_pifi]) == NULL)
+ if (!mifcp->mif6c_pifi || (ifp = if_byindex(mifcp->mif6c_pifi)) == NULL)
return ENXIO;
if (mifcp->mif6c_flags & MIFF_REGISTER) {
diff -r d30769b8cf36 -r f24c15a569d1 sys/netinet6/ip6_output.c
--- a/sys/netinet6/ip6_output.c Sat May 17 21:22:56 2014 +0000
+++ b/sys/netinet6/ip6_output.c Sat May 17 21:26:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ip6_output.c,v 1.155 2013/10/03 20:27:55 christos Exp $ */
+/* $NetBSD: ip6_output.c,v 1.156 2014/05/17 21:26:20 rmind 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.155 2013/10/03 20:27:55 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.156 2014/05/17 21:26:20 rmind Exp $");
#include "opt_inet.h"
#include "opt_inet6.h"
@@ -2277,11 +2277,10 @@
break;
if (ifindex != 0) {
- if (if_indexlim <= ifindex || !ifindex2ifnet[ifindex]) {
+ if ((ifp = if_byindex(ifindex)) == NULL) {
error = ENXIO; /* XXX EINVAL? */
break;
}
- ifp = ifindex2ifnet[ifindex];
if ((ifp->if_flags & IFF_MULTICAST) == 0) {
error = EADDRNOTAVAIL;
break;
@@ -2379,12 +2378,10 @@
/*
* If the interface is specified, validate it.
*/
- if (if_indexlim <= mreq.ipv6mr_interface ||
- !ifindex2ifnet[mreq.ipv6mr_interface]) {
+ if ((ifp = if_byindex(mreq.ipv6mr_interface)) == NULL) {
error = ENXIO; /* XXX EINVAL? */
break;
}
- ifp = ifindex2ifnet[mreq.ipv6mr_interface];
}
/*
@@ -2438,12 +2435,10 @@
* to its ifnet structure.
*/
if (mreq.ipv6mr_interface != 0) {
- if (if_indexlim <= mreq.ipv6mr_interface ||
- !ifindex2ifnet[mreq.ipv6mr_interface]) {
+ if ((ifp = if_byindex(mreq.ipv6mr_interface)) == NULL) {
error = ENXIO; /* XXX EINVAL? */
break;
}
- ifp = ifindex2ifnet[mreq.ipv6mr_interface];
} else
ifp = NULL;
@@ -2737,12 +2732,9 @@
return (EINVAL);
}
- /* validate the interface index if specified. */
- if (pktinfo->ipi6_ifindex >= if_indexlim) {
- return (ENXIO);
- }
+ /* Validate the interface index if specified. */
if (pktinfo->ipi6_ifindex) {
- ifp = ifindex2ifnet[pktinfo->ipi6_ifindex];
+ ifp = if_byindex(pktinfo->ipi6_ifindex);
if (ifp == NULL)
return (ENXIO);
}
diff -r d30769b8cf36 -r f24c15a569d1 sys/netinet6/nd6_rtr.c
--- a/sys/netinet6/nd6_rtr.c Sat May 17 21:22:56 2014 +0000
+++ b/sys/netinet6/nd6_rtr.c Sat May 17 21:26:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nd6_rtr.c,v 1.90 2013/09/14 21:08:35 martin Exp $ */
+/* $NetBSD: nd6_rtr.c,v 1.91 2014/05/17 21:26:20 rmind 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.90 2013/09/14 21:08:35 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.91 2014/05/17 21:26:20 rmind Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -2162,19 +2162,15 @@
int
nd6_setdefaultiface(int ifindex)
{
+ ifnet_t *ifp;
int error = 0;
- if (ifindex < 0 || if_indexlim <= ifindex)
- return (EINVAL);
- if (ifindex != 0 && !ifindex2ifnet[ifindex])
- return (EINVAL);
-
+ if ((ifp = if_byindex(ifindex)) == NULL) {
+ return EINVAL;
+ }
if (nd6_defifindex != ifindex) {
nd6_defifindex = ifindex;
- if (nd6_defifindex > 0) {
- nd6_defifp = ifindex2ifnet[nd6_defifindex];
- } else
- nd6_defifp = NULL;
+ nd6_defifp = nd6_defifindex > 0 ? ifp : NULL;
/*
* Our current implementation assumes one-to-one maping between
diff -r d30769b8cf36 -r f24c15a569d1 sys/netinet6/scope6.c
--- a/sys/netinet6/scope6.c Sat May 17 21:22:56 2014 +0000
+++ b/sys/netinet6/scope6.c Sat May 17 21:26:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: scope6.c,v 1.8 2009/09/11 22:06:29 dyoung Exp $ */
+/* $NetBSD: scope6.c,v 1.9 2014/05/17 21:26:20 rmind Exp $ */
/* $KAME$ */
/*-
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scope6.c,v 1.8 2009/09/11 22:06:29 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scope6.c,v 1.9 2014/05/17 21:26:20 rmind Exp $");
#include <sys/param.h>
#include <sys/malloc.h>
@@ -130,7 +130,7 @@
return (EINVAL);
if (i == IPV6_ADDR_SCOPE_LINKLOCAL &&
- idlist->s6id_list[i] >= if_indexlim) {
+ !if_byindex(idlist->s6id_list[i])) {
/*
* XXX: theoretically, there should be no
* relationship between link IDs and interface
@@ -309,14 +309,8 @@
* zone IDs assuming a one-to-one mapping between interfaces
* and links.
*/
- if (if_indexlim <= zoneid)
- return (ENXIO);
-#ifdef __FreeBSD__
Home |
Main Index |
Thread Index |
Old Index