Get rcvif once and reuse it

No functional change.
This commit is contained in:
ozaki-r 2016-05-19 08:53:25 +00:00
parent f058ef8fee
commit 9f10dc7910
1 changed files with 32 additions and 36 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip6_input.c,v 1.158 2016/04/04 07:37:07 ozaki-r Exp $ */
/* $NetBSD: ip6_input.c,v 1.159 2016/05/19 08:53:25 ozaki-r Exp $ */
/* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */
/*
@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.158 2016/04/04 07:37:07 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.159 2016/05/19 08:53:25 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_gateway.h"
@ -248,6 +248,7 @@ ip6_input(struct mbuf *m)
struct sockaddr dst;
struct sockaddr_in6 dst6;
} u;
struct ifnet *rcvif = m->m_pkthdr.rcvif;
/*
* make sure we don't have onion peering information into m_tag.
@ -265,19 +266,18 @@ ip6_input(struct mbuf *m)
} else {
#define M2MMAX 32
if (m->m_next) {
if (m->m_flags & M_LOOP) {
if (m->m_flags & M_LOOP)
/*XXX*/ IP6_STATINC(IP6_STAT_M2M + lo0ifp->if_index);
} else if (m->m_pkthdr.rcvif->if_index < M2MMAX) {
IP6_STATINC(IP6_STAT_M2M +
m->m_pkthdr.rcvif->if_index);
} else
else if (rcvif->if_index < M2MMAX)
IP6_STATINC(IP6_STAT_M2M + rcvif->if_index);
else
IP6_STATINC(IP6_STAT_M2M);
} else
IP6_STATINC(IP6_STAT_M1);
#undef M2MMAX
}
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_receive);
in6_ifstat_inc(rcvif, ifs6_in_receive);
IP6_STATINC(IP6_STAT_TOTAL);
/*
@ -287,19 +287,17 @@ ip6_input(struct mbuf *m)
* IPv6 header is in the first mbuf of the chain.
*/
if (IP6_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
struct ifnet *inifp = m->m_pkthdr.rcvif;
if ((m = m_copyup(m, sizeof(struct ip6_hdr),
(max_linkhdr + 3) & ~3)) == NULL) {
/* XXXJRT new stat, please */
IP6_STATINC(IP6_STAT_TOOSMALL);
in6_ifstat_inc(inifp, ifs6_in_hdrerr);
in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
return;
}
} else if (__predict_false(m->m_len < sizeof(struct ip6_hdr))) {
struct ifnet *inifp = m->m_pkthdr.rcvif;
if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) {
IP6_STATINC(IP6_STAT_TOOSMALL);
in6_ifstat_inc(inifp, ifs6_in_hdrerr);
in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
return;
}
}
@ -308,7 +306,7 @@ ip6_input(struct mbuf *m)
if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
IP6_STATINC(IP6_STAT_BADVERS);
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr);
in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
goto bad;
}
@ -338,8 +336,7 @@ ip6_input(struct mbuf *m)
struct in6_addr odst;
odst = ip6->ip6_dst;
if (pfil_run_hooks(inet6_pfil_hook, &m, m->m_pkthdr.rcvif,
PFIL_IN) != 0)
if (pfil_run_hooks(inet6_pfil_hook, &m, rcvif, PFIL_IN) != 0)
return;
if (m == NULL)
return;
@ -365,7 +362,7 @@ ip6_input(struct mbuf *m)
* XXX: "badscope" is not very suitable for a multicast source.
*/
IP6_STATINC(IP6_STAT_BADSCOPE);
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
in6_ifstat_inc(rcvif, ifs6_in_addrerr);
goto bad;
}
/*
@ -383,7 +380,7 @@ ip6_input(struct mbuf *m)
if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) ||
IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
IP6_STATINC(IP6_STAT_BADSCOPE);
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
in6_ifstat_inc(rcvif, ifs6_in_addrerr);
goto bad;
}
#if 0
@ -397,7 +394,7 @@ ip6_input(struct mbuf *m)
if (IN6_IS_ADDR_V4COMPAT(&ip6->ip6_src) ||
IN6_IS_ADDR_V4COMPAT(&ip6->ip6_dst)) {
IP6_STATINC(IP6_STAT_BADSCOPE);
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
in6_ifstat_inc(rcvif, ifs6_in_addrerr);
goto bad;
}
#endif
@ -420,8 +417,8 @@ ip6_input(struct mbuf *m)
IP6_STATINC(IP6_STAT_BADSCOPE); /* XXX */
goto bad;
}
if (in6_setscope(&ip6->ip6_src, m->m_pkthdr.rcvif, NULL) ||
in6_setscope(&ip6->ip6_dst, m->m_pkthdr.rcvif, NULL)) {
if (in6_setscope(&ip6->ip6_src, rcvif, NULL) ||
in6_setscope(&ip6->ip6_dst, rcvif, NULL)) {
IP6_STATINC(IP6_STAT_BADSCOPE);
goto bad;
}
@ -432,12 +429,12 @@ ip6_input(struct mbuf *m)
if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
struct in6_multi *in6m = 0;
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mcast);
in6_ifstat_inc(rcvif, ifs6_in_mcast);
/*
* See if we belong to the destination multicast group on the
* arrival interface.
*/
IN6_LOOKUP_MULTI(ip6->ip6_dst, m->m_pkthdr.rcvif, in6m);
IN6_LOOKUP_MULTI(ip6->ip6_dst, rcvif, in6m);
if (in6m)
ours = 1;
else if (!ip6_mrouter) {
@ -445,10 +442,10 @@ ip6_input(struct mbuf *m)
ip6s[IP6_STAT_NOTMEMBER]++;
ip6s[IP6_STAT_CANTFORWARD]++;
IP6_STAT_PUTREF();
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
in6_ifstat_inc(rcvif, ifs6_in_discard);
goto bad;
}
deliverifp = m->m_pkthdr.rcvif;
deliverifp = rcvif;
goto hbhcheck;
}
@ -530,7 +527,7 @@ ip6_input(struct mbuf *m)
* working right.
*/
struct ifaddr *ifa;
IFADDR_FOREACH(ifa, m->m_pkthdr.rcvif) {
IFADDR_FOREACH(ifa, rcvif) {
if (ifa->ifa_addr == NULL)
continue; /* just for safety */
if (ifa->ifa_addr->sa_family != AF_INET6)
@ -550,7 +547,7 @@ ip6_input(struct mbuf *m)
*/
if (!ip6_forwarding) {
IP6_STATINC(IP6_STAT_CANTFORWARD);
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
in6_ifstat_inc(rcvif, ifs6_in_discard);
goto bad;
}
@ -585,7 +582,7 @@ ip6_input(struct mbuf *m)
if (ip6_hopopts_input(&plen, &rtalert, &m, &off)) {
#if 0 /*touches NULL pointer*/
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
in6_ifstat_inc(rcvif, ifs6_in_discard);
#endif
return; /* m have already been freed */
}
@ -605,8 +602,8 @@ ip6_input(struct mbuf *m)
* (non-zero) payload length to the variable plen.
*/
IP6_STATINC(IP6_STAT_BADOPTIONS);
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr);
in6_ifstat_inc(rcvif, ifs6_in_discard);
in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
icmp6_error(m, ICMP6_PARAM_PROB,
ICMP6_PARAMPROB_HEADER,
(char *)&ip6->ip6_plen - (char *)ip6);
@ -638,7 +635,7 @@ ip6_input(struct mbuf *m)
*/
if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) {
IP6_STATINC(IP6_STAT_TOOSHORT);
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated);
in6_ifstat_inc(rcvif, ifs6_in_truncated);
goto bad;
}
if (m->m_pkthdr.len > sizeof(struct ip6_hdr) + plen) {
@ -661,7 +658,7 @@ ip6_input(struct mbuf *m)
* ip6_mforward() returns a non-zero value, the packet
* must be discarded, else it may be accepted below.
*/
if (ip6_mrouter && ip6_mforward(ip6, m->m_pkthdr.rcvif, m)) {
if (ip6_mrouter && ip6_mforward(ip6, rcvif, m)) {
IP6_STATINC(IP6_STAT_CANTFORWARD);
m_freem(m);
return;
@ -689,7 +686,7 @@ ip6_input(struct mbuf *m)
if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) ||
IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
IP6_STATINC(IP6_STAT_BADSCOPE);
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
in6_ifstat_inc(rcvif, ifs6_in_addrerr);
goto bad;
}
@ -712,7 +709,7 @@ ip6_input(struct mbuf *m)
while (nxt != IPPROTO_DONE) {
if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) {
IP6_STATINC(IP6_STAT_TOOMANYHDR);
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr);
in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
goto bad;
}
@ -722,14 +719,13 @@ ip6_input(struct mbuf *m)
*/
if (m->m_pkthdr.len < off) {
IP6_STATINC(IP6_STAT_TOOSHORT);
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated);
in6_ifstat_inc(rcvif, ifs6_in_truncated);
goto bad;
}
if (nxt == IPPROTO_ROUTING) {
if (rh_present++) {
in6_ifstat_inc(m->m_pkthdr.rcvif,
ifs6_in_hdrerr);
in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
IP6_STATINC(IP6_STAT_BADOPTIONS);
goto bad;
}