Replace open-coded access (and boundary checking) of ifindex2ifnet with
if_byindex() function.
This commit is contained in:
parent
169afaf534
commit
bc9504c95e
@ -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 @@ linux_getifname(struct lwp *l, register_t *retval, void *data)
|
||||
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;
|
||||
|
||||
|
@ -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 @@ linux32_getifname(struct lwp *l, register_t *retval, void *data)
|
||||
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;
|
||||
|
||||
|
@ -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 @@ ip_multicast_if(struct in_addr *a, int *ifindexp)
|
||||
*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)
|
||||
|
@ -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 @@ selectroute(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts,
|
||||
/* 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))) {
|
||||
|
@ -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 @@ add_m6if(struct mif6ctl *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_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) {
|
||||
|
@ -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 @@ ip6_setmoptions(const struct sockopt *sopt, struct ip6_moptions **im6op)
|
||||
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 @@ ip6_setmoptions(const struct sockopt *sopt, struct ip6_moptions **im6op)
|
||||
/*
|
||||
* 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 @@ ip6_setmoptions(const struct sockopt *sopt, struct ip6_moptions **im6op)
|
||||
* 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 @@ ip6_setpktopt(int optname, u_char *buf, int len, struct ip6_pktopts *opt,
|
||||
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);
|
||||
}
|
||||
|
@ -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 @@ rt6_deleteroute(struct rtentry *rt, void *arg)
|
||||
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
|
||||
|
@ -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 @@ scope6_set(struct ifnet *ifp, const struct scope6_id *idlist)
|
||||
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 @@ sa6_embedscope(struct sockaddr_in6 *sin6, int defaultok)
|
||||
* zone IDs assuming a one-to-one mapping between interfaces
|
||||
* and links.
|
||||
*/
|
||||
if (if_indexlim <= zoneid)
|
||||
return (ENXIO);
|
||||
#ifdef __FreeBSD__
|
||||
ifp = ifnet_byindex(zoneid);
|
||||
#else
|
||||
ifp = ifindex2ifnet[zoneid];
|
||||
#endif
|
||||
if (ifp == NULL) /* XXX: this can happen for some OS */
|
||||
ifp = if_byindex(zoneid);
|
||||
if (ifp == NULL)
|
||||
return (ENXIO);
|
||||
|
||||
/* XXX assignment to 16bit from 32bit variable */
|
||||
@ -363,14 +357,7 @@ sa6_recoverscope(struct sockaddr_in6 *sin6)
|
||||
*/
|
||||
zoneid = ntohs(sin6->sin6_addr.s6_addr16[1]);
|
||||
if (zoneid) {
|
||||
/* sanity check */
|
||||
if (/* zoneid < 0 || */ if_indexlim <= zoneid)
|
||||
return (ENXIO);
|
||||
#ifdef __FreeBSD__
|
||||
if (!ifnet_byindex(zoneid))
|
||||
#else
|
||||
if (!ifindex2ifnet[zoneid])
|
||||
#endif
|
||||
if (!if_byindex(zoneid))
|
||||
return (ENXIO);
|
||||
sin6->sin6_addr.s6_addr16[1] = 0;
|
||||
sin6->sin6_scope_id = zoneid;
|
||||
|
Loading…
Reference in New Issue
Block a user