Diff below reduce the number of m->m_pkthdr.rcvif usage in icmp{,6}
code.  Should introduce no functional change but that will help me
with upcoming pointer -> index conversion.

ok?

Index: netinet/ip_icmp.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/ip_icmp.c,v
retrieving revision 1.121
diff -u -p -r1.121 ip_icmp.c
--- netinet/ip_icmp.c   21 Apr 2014 12:22:26 -0000      1.121
+++ netinet/ip_icmp.c   6 May 2014 09:23:11 -0000
@@ -305,6 +305,7 @@ icmp_error(struct mbuf *n, int type, int
 void
 icmp_input(struct mbuf *m, ...)
 {
+       struct ifnet *ifp;
        struct icmp *icp;
        struct ip *ip = mtod(m, struct ip *);
        struct sockaddr_in sin;
@@ -318,6 +319,8 @@ icmp_input(struct mbuf *m, ...)
        hlen = va_arg(ap, int);
        va_end(ap);
 
+       ifp = m->m_pkthdr.rcvif;
+
        /*
         * Locate icmp structure in mbuf, and check
         * that not corrupted and of at least minimum length.
@@ -480,7 +483,7 @@ icmp_input(struct mbuf *m, ...)
                sin.sin_len = sizeof(struct sockaddr_in);
                sin.sin_addr = icp->icmp_ip.ip_dst;
 #if NCARP > 0
-               if (m->m_pkthdr.rcvif->if_type == IFT_CARP &&
+               if (ifp->if_type == IFT_CARP &&
                    carp_lsdrop(m, AF_INET, &sin.sin_addr.s_addr,
                    &ip->ip_dst.s_addr))
                        goto freeit;
@@ -545,10 +548,9 @@ icmp_input(struct mbuf *m, ...)
                        sin.sin_addr = ip->ip_src;
                else
                        sin.sin_addr = ip->ip_dst;
-               if (m->m_pkthdr.rcvif == NULL)
+               if (ifp == NULL)
                        break;
-               ia = ifatoia(ifaof_ifpforaddr(sintosa(&sin),
-                   m->m_pkthdr.rcvif));
+               ia = ifatoia(ifaof_ifpforaddr(sintosa(&sin), ifp));
                if (ia == 0)
                        break;
                icp->icmp_type = ICMP_MASKREPLY;
@@ -565,7 +567,7 @@ icmp_input(struct mbuf *m, ...)
                }
 reflect:
 #if NCARP > 0
-               if (m->m_pkthdr.rcvif->if_type == IFT_CARP &&
+               if (ifp->if_type == IFT_CARP &&
                    carp_lsdrop(m, AF_INET, &ip->ip_src.s_addr,
                    &ip->ip_dst.s_addr))
                        goto freeit;
@@ -631,7 +633,7 @@ reflect:
 #endif
 
 #if NCARP > 0
-               if (m->m_pkthdr.rcvif->if_type == IFT_CARP &&
+               if (ifp->if_type == IFT_CARP &&
                    carp_lsdrop(m, AF_INET, &sdst.sin_addr.s_addr,
                    &ip->ip_dst.s_addr))
                        goto freeit;
Index: netinet6/icmp6.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet6/icmp6.c,v
retrieving revision 1.143
diff -u -p -r1.143 icmp6.c
--- netinet6/icmp6.c    18 Apr 2014 10:48:30 -0000      1.143
+++ netinet6/icmp6.c    6 May 2014 09:23:11 -0000
@@ -385,6 +385,7 @@ icmp6_error(struct mbuf *m, int type, in
 int
 icmp6_input(struct mbuf **mp, int *offp, int proto)
 {
+       struct ifnet *ifp;
        struct mbuf *m = *mp, *n;
        struct ip6_hdr *ip6, *nip6;
        struct icmp6_hdr *icmp6, *nicmp6;
@@ -393,7 +394,9 @@ icmp6_input(struct mbuf **mp, int *offp,
        int code, sum, noff;
        char src[INET6_ADDRSTRLEN], dst[INET6_ADDRSTRLEN];
 
-       icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_msg);
+       ifp = m->m_pkthdr.rcvif;
+
+       icmp6_ifstat_inc(ifp, ifs6_in_msg);
 
        /*
         * Locate icmp6 structure in mbuf, and check
@@ -403,7 +406,7 @@ icmp6_input(struct mbuf **mp, int *offp,
        ip6 = mtod(m, struct ip6_hdr *);
        if (icmp6len < sizeof(struct icmp6_hdr)) {
                icmp6stat.icp6s_tooshort++;
-               icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_error);
+               icmp6_ifstat_inc(ifp, ifs6_in_error);
                goto freeit;
        }
 
@@ -423,7 +426,7 @@ icmp6_input(struct mbuf **mp, int *offp,
                    icmp6->icmp6_type, sum,
                    inet_ntop(AF_INET6, &ip6->ip6_src, src, sizeof(src))));
                icmp6stat.icp6s_checksum++;
-               icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_error);
+               icmp6_ifstat_inc(ifp, ifs6_in_error);
                goto freeit;
        }
 
@@ -446,7 +449,7 @@ icmp6_input(struct mbuf **mp, int *offp,
 #endif /* NPF */
 
 #if NCARP > 0
-       if (m->m_pkthdr.rcvif->if_type == IFT_CARP &&
+       if (ifp->if_type == IFT_CARP &&
            icmp6->icmp6_type == ICMP6_ECHO_REQUEST &&
            carp_lsdrop(m, AF_INET6, ip6->ip6_src.s6_addr32,
            ip6->ip6_dst.s6_addr32))
@@ -456,13 +459,13 @@ icmp6_input(struct mbuf **mp, int *offp,
 
        switch (icmp6->icmp6_type) {
        case ICMP6_DST_UNREACH:
-               icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_dstunreach);
+               icmp6_ifstat_inc(ifp, ifs6_in_dstunreach);
                switch (code) {
                case ICMP6_DST_UNREACH_NOROUTE:
                        code = PRC_UNREACH_NET;
                        break;
                case ICMP6_DST_UNREACH_ADMIN:
-                       icmp6_ifstat_inc(m->m_pkthdr.rcvif, 
ifs6_in_adminprohib);
+                       icmp6_ifstat_inc(ifp, ifs6_in_adminprohib);
                        code = PRC_UNREACH_PROTOCOL; /* is this a good code? */
                        break;
                case ICMP6_DST_UNREACH_ADDR:
@@ -487,7 +490,7 @@ icmp6_input(struct mbuf **mp, int *offp,
                goto deliver;
 
        case ICMP6_PACKET_TOO_BIG:
-               icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_pkttoobig);
+               icmp6_ifstat_inc(ifp, ifs6_in_pkttoobig);
 
                /* MTU is checked in icmp6_mtudisc_update. */
                code = PRC_MSGSIZE;
@@ -499,7 +502,7 @@ icmp6_input(struct mbuf **mp, int *offp,
                goto deliver;
 
        case ICMP6_TIME_EXCEEDED:
-               icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_timeexceed);
+               icmp6_ifstat_inc(ifp, ifs6_in_timeexceed);
                switch (code) {
                case ICMP6_TIME_EXCEED_TRANSIT:
                        code = PRC_TIMXCEED_INTRANS;
@@ -513,7 +516,7 @@ icmp6_input(struct mbuf **mp, int *offp,
                goto deliver;
 
        case ICMP6_PARAM_PROB:
-               icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_paramprob);
+               icmp6_ifstat_inc(ifp, ifs6_in_paramprob);
                switch (code) {
                case ICMP6_PARAMPROB_NEXTHEADER:
                        code = PRC_UNREACH_PROTOCOL;
@@ -528,7 +531,7 @@ icmp6_input(struct mbuf **mp, int *offp,
                goto deliver;
 
        case ICMP6_ECHO_REQUEST:
-               icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_echo);
+               icmp6_ifstat_inc(ifp, ifs6_in_echo);
                if (code != 0)
                        goto badcode;
                /*
@@ -614,7 +617,7 @@ icmp6_input(struct mbuf **mp, int *offp,
                break;
 
        case ICMP6_ECHO_REPLY:
-               icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_echoreply);
+               icmp6_ifstat_inc(ifp, ifs6_in_echoreply);
                if (code != 0)
                        goto badcode;
                break;
@@ -624,9 +627,9 @@ icmp6_input(struct mbuf **mp, int *offp,
                if (icmp6len < sizeof(struct mld_hdr))
                        goto badlen;
                if (icmp6->icmp6_type == MLD_LISTENER_QUERY) /* XXX: ugly... */
-                       icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mldquery);
+                       icmp6_ifstat_inc(ifp, ifs6_in_mldquery);
                else
-                       icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mldreport);
+                       icmp6_ifstat_inc(ifp, ifs6_in_mldreport);
                if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
                        /* give up local */
                        mld6_input(m, off);
@@ -638,7 +641,7 @@ icmp6_input(struct mbuf **mp, int *offp,
                break;
 
        case MLD_LISTENER_DONE:
-               icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mlddone);
+               icmp6_ifstat_inc(ifp, ifs6_in_mlddone);
                if (icmp6len < sizeof(struct mld_hdr))  /* necessary? */
                        goto badlen;
                break;          /* nothing to be done in kernel */
@@ -735,7 +738,7 @@ icmp6_input(struct mbuf **mp, int *offp,
                break;
 
        case ND_ROUTER_SOLICIT:
-               icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_routersolicit);
+               icmp6_ifstat_inc(ifp, ifs6_in_routersolicit);
                if (code != 0)
                        goto badcode;
                if (icmp6len < sizeof(struct nd_router_solicit))
@@ -751,7 +754,7 @@ icmp6_input(struct mbuf **mp, int *offp,
                break;
 
        case ND_ROUTER_ADVERT:
-               icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_routeradvert);
+               icmp6_ifstat_inc(ifp, ifs6_in_routeradvert);
                if (code != 0)
                        goto badcode;
                if (icmp6len < sizeof(struct nd_router_advert))
@@ -767,7 +770,7 @@ icmp6_input(struct mbuf **mp, int *offp,
                break;
 
        case ND_NEIGHBOR_SOLICIT:
-               icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_neighborsolicit);
+               icmp6_ifstat_inc(ifp, ifs6_in_neighborsolicit);
                if (code != 0)
                        goto badcode;
                if (icmp6len < sizeof(struct nd_neighbor_solicit))
@@ -783,7 +786,7 @@ icmp6_input(struct mbuf **mp, int *offp,
                break;
 
        case ND_NEIGHBOR_ADVERT:
-               icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_neighboradvert);
+               icmp6_ifstat_inc(ifp, ifs6_in_neighboradvert);
                if (code != 0)
                        goto badcode;
                if (icmp6len < sizeof(struct nd_neighbor_advert))
@@ -799,7 +802,7 @@ icmp6_input(struct mbuf **mp, int *offp,
                break;
 
        case ND_REDIRECT:
-               icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_redirect);
+               icmp6_ifstat_inc(ifp, ifs6_in_redirect);
                if (code != 0)
                        goto badcode;
                if (icmp6len < sizeof(struct nd_redirect))
@@ -828,7 +831,7 @@ icmp6_input(struct mbuf **mp, int *offp,
                    icmp6->icmp6_type,
                    inet_ntop(AF_INET6, &ip6->ip6_src, src, sizeof(src)),
                    inet_ntop(AF_INET6, &ip6->ip6_dst, dst, sizeof(dst)),
-                   m->m_pkthdr.rcvif ? m->m_pkthdr.rcvif->if_index : 0));
+                   ifp ? ifp->if_index : 0));
                if (icmp6->icmp6_type < ICMP6_ECHO_REQUEST) {
                        /* ICMPv6 error: MUST deliver it by spec... */
                        code = PRC_NCMDS;

Reply via email to