Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/netinet6/ip6_input.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/netinet6/ip6_input.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.113.12.3 retrieving revision 1.114 diff -u -p -r1.113.12.3 -r1.114 --- src/sys/netinet6/ip6_input.c 2008/09/28 10:40:59 1.113.12.3 +++ src/sys/netinet6/ip6_input.c 2008/02/27 19:40:56 1.114 @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_input.c,v 1.113.12.3 2008/09/28 10:40:59 mjf Exp $ */ +/* $NetBSD: ip6_input.c,v 1.114 2008/02/27 19:40:56 matt Exp $ */ /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ /* @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.113.12.3 2008/09/28 10:40:59 mjf Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.114 2008/02/27 19:40:56 matt Exp $"); #include "opt_inet.h" #include "opt_inet6.h" @@ -102,7 +102,6 @@ __KERNEL_RCSID(0, "$NetBSD: ip6_input.c, #include #include #include -#include #include #include #include @@ -111,7 +110,6 @@ __KERNEL_RCSID(0, "$NetBSD: ip6_input.c, #ifdef IPSEC #include -#include #endif #ifdef FAST_IPSEC @@ -148,7 +146,7 @@ int ip6_sourcecheck_interval; /* XXX */ struct pfil_head inet6_pfil_hook; #endif -percpu_t *ip6stat_percpu; +struct ip6stat ip6stat; static void ip6_init2(void *); static struct m_tag *ip6_setdstifaddr(struct mbuf *, const struct in6_ifaddr *); @@ -197,8 +195,6 @@ ip6_init(void) printf("ip6_init: WARNING: unable to register pfil hook, " "error %d\n", i); #endif /* PFIL_HOOKS */ - - ip6stat_percpu = percpu_alloc(sizeof(uint64_t) * IP6_NSTATS); } static void @@ -206,11 +202,11 @@ ip6_init2(void *dummy) { /* nd6_timer_init */ - callout_init(&nd6_timer_ch, CALLOUT_MPSAFE); + callout_init(&nd6_timer_ch, 0); callout_reset(&nd6_timer_ch, hz, nd6_timer, NULL); /* timer for regeneranation of temporary addresses randomize ID */ - callout_init(&in6_tmpaddrtimer_ch, CALLOUT_MPSAFE); + callout_init(&in6_tmpaddrtimer_ch, 0); callout_reset(&in6_tmpaddrtimer_ch, (ip6_temp_preferred_lifetime - ip6_desync_factor - ip6_temp_regen_advance) * hz, @@ -226,23 +222,19 @@ ip6intr(void) int s; struct mbuf *m; - mutex_enter(softnet_lock); - KERNEL_LOCK(1, NULL); for (;;) { s = splnet(); IF_DEQUEUE(&ip6intrq, m); splx(s); if (m == 0) - break; + return; /* drop the packet if IPv6 operation is disabled on the IF */ if ((ND_IFINFO(m->m_pkthdr.rcvif)->flags & ND6_IFF_IFDISABLED)) { m_freem(m); - break; + return; } ip6_input(m); } - KERNEL_UNLOCK_ONE(NULL); - mutex_exit(softnet_lock); } extern struct route ip6_forward_rt; @@ -288,26 +280,25 @@ ip6_input(struct mbuf *m) */ if (m->m_flags & M_EXT) { if (m->m_next) - IP6_STATINC(IP6_STAT_MEXT2M); + ip6stat.ip6s_mext2m++; else - IP6_STATINC(IP6_STAT_MEXT1); + ip6stat.ip6s_mext1++; } else { -#define M2MMAX 32 +#define M2MMAX __arraycount(ip6stat.ip6s_m2m) if (m->m_next) { 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 - IP6_STATINC(IP6_STAT_M2M); + ip6stat.ip6s_m2m[lo0ifp->if_index]++; /* XXX */ + } else if (m->m_pkthdr.rcvif->if_index < M2MMAX) + ip6stat.ip6s_m2m[m->m_pkthdr.rcvif->if_index]++; + else + ip6stat.ip6s_m2m[0]++; } else - IP6_STATINC(IP6_STAT_M1); + ip6stat.ip6s_m1++; #undef M2MMAX } in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_receive); - IP6_STATINC(IP6_STAT_TOTAL); + ip6stat.ip6s_total++; /* * If the IPv6 header is not aligned, slurp it up into a new @@ -320,14 +311,14 @@ ip6_input(struct mbuf *m) if ((m = m_copyup(m, sizeof(struct ip6_hdr), (max_linkhdr + 3) & ~3)) == NULL) { /* XXXJRT new stat, please */ - IP6_STATINC(IP6_STAT_TOOSMALL); + ip6stat.ip6s_toosmall++; in6_ifstat_inc(inifp, 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); + ip6stat.ip6s_toosmall++; in6_ifstat_inc(inifp, ifs6_in_hdrerr); return; } @@ -336,7 +327,7 @@ ip6_input(struct mbuf *m) ip6 = mtod(m, struct ip6_hdr *); if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) { - IP6_STATINC(IP6_STAT_BADVERS); + ip6stat.ip6s_badvers++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr); goto bad; } @@ -385,7 +376,7 @@ ip6_input(struct mbuf *m) } #endif /* PFIL_HOOKS */ - IP6_STATINC(IP6_STAT_NXTHIST + ip6->ip6_nxt); + ip6stat.ip6s_nxthist[ip6->ip6_nxt]++; #ifdef ALTQ if (altq_input != NULL && (*altq_input)(m, AF_INET6) == 0) { @@ -402,7 +393,7 @@ ip6_input(struct mbuf *m) /* * XXX: "badscope" is not very suitable for a multicast source. */ - IP6_STATINC(IP6_STAT_BADSCOPE); + ip6stat.ip6s_badscope++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); goto bad; } @@ -420,7 +411,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); + ip6stat.ip6s_badscope++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); goto bad; } @@ -434,7 +425,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); + ip6stat.ip6s_badscope++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); goto bad; } @@ -455,12 +446,12 @@ ip6_input(struct mbuf *m) goto bad; ip6 = mtod(m, struct ip6_hdr *); if (in6_clearscope(&ip6->ip6_src) || in6_clearscope(&ip6->ip6_dst)) { - IP6_STATINC(IP6_STAT_BADSCOPE); /* XXX */ + ip6stat.ip6s_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)) { - IP6_STATINC(IP6_STAT_BADSCOPE); + ip6stat.ip6s_badscope++; goto bad; } @@ -479,10 +470,8 @@ ip6_input(struct mbuf *m) if (in6m) ours = 1; else if (!ip6_mrouter) { - uint64_t *ip6s = IP6_STAT_GETREF(); - ip6s[IP6_STAT_NOTMEMBER]++; - ip6s[IP6_STAT_CANTFORWARD]++; - IP6_STAT_PUTREF(); + ip6stat.ip6s_notmember++; + ip6stat.ip6s_cantforward++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard); goto bad; } @@ -497,9 +486,9 @@ ip6_input(struct mbuf *m) */ rt = rtcache_lookup2(&ip6_forward_rt, &u.dst, 1, &hit); if (hit) - IP6_STATINC(IP6_STAT_FORWARD_CACHEHIT); + ip6stat.ip6s_forward_cachehit++; else - IP6_STATINC(IP6_STAT_FORWARD_CACHEMISS); + ip6stat.ip6s_forward_cachemiss++; #define rt6_getkey(__rt) satocsin6(rt_getkey(__rt)) @@ -589,7 +578,7 @@ ip6_input(struct mbuf *m) * and we're not a router. */ if (!ip6_forwarding) { - IP6_STATINC(IP6_STAT_CANTFORWARD); + ip6stat.ip6s_cantforward++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard); goto bad; } @@ -644,7 +633,7 @@ ip6_input(struct mbuf *m) * contained, ip6_hopopts_input() must set a valid * (non-zero) payload length to the variable plen. */ - IP6_STATINC(IP6_STAT_BADOPTIONS); + ip6stat.ip6s_badoptions++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard); in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr); icmp6_error(m, ICMP6_PARAM_PROB, @@ -655,7 +644,7 @@ ip6_input(struct mbuf *m) IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr), sizeof(struct ip6_hbh)); if (hbh == NULL) { - IP6_STATINC(IP6_STAT_TOOSHORT); + ip6stat.ip6s_tooshort++; return; } KASSERT(IP6_HDR_ALIGNED_P(hbh)); @@ -677,7 +666,7 @@ ip6_input(struct mbuf *m) * Drop packet if shorter than we expect. */ if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) { - IP6_STATINC(IP6_STAT_TOOSHORT); + ip6stat.ip6s_tooshort++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); goto bad; } @@ -702,7 +691,7 @@ ip6_input(struct mbuf *m) * must be discarded, else it may be accepted below. */ if (ip6_mrouter && ip6_mforward(ip6, m->m_pkthdr.rcvif, m)) { - IP6_STATINC(IP6_STAT_CANTFORWARD); + ip6stat.ip6s_cantforward++; m_freem(m); return; } @@ -728,7 +717,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); + ip6stat.ip6s_badscope++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); goto bad; } @@ -744,14 +733,14 @@ ip6_input(struct mbuf *m) ia6->ia_ifa.ifa_data.ifad_inbytes += m->m_pkthdr.len; } #endif - IP6_STATINC(IP6_STAT_DELIVERED); + ip6stat.ip6s_delivered++; in6_ifstat_inc(deliverifp, ifs6_in_deliver); nest = 0; rh_present = 0; while (nxt != IPPROTO_DONE) { if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) { - IP6_STATINC(IP6_STAT_TOOMANYHDR); + ip6stat.ip6s_toomanyhdr++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr); goto bad; } @@ -761,7 +750,7 @@ ip6_input(struct mbuf *m) * more sanity checks in header chain processing. */ if (m->m_pkthdr.len < off) { - IP6_STATINC(IP6_STAT_TOOSHORT); + ip6stat.ip6s_tooshort++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); goto bad; } @@ -770,7 +759,7 @@ ip6_input(struct mbuf *m) if (rh_present++) { in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr); - IP6_STATINC(IP6_STAT_BADOPTIONS); + ip6stat.ip6s_badoptions++; goto bad; } } @@ -783,7 +772,7 @@ ip6_input(struct mbuf *m) */ if ((inet6sw[ip6_protox[nxt]].pr_flags & PR_LASTHDR) != 0 && ipsec6_in_reject(m, NULL)) { - IPSEC6_STATINC(IPSEC_STAT_IN_POLVIO); + ipsec6stat.in_polvio++; goto bad; } #endif @@ -884,14 +873,14 @@ ip6_hopopts_input(u_int32_t *plenp, u_in IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr), sizeof(struct ip6_hbh)); if (hbh == NULL) { - IP6_STATINC(IP6_STAT_TOOSHORT); + ip6stat.ip6s_tooshort++; return -1; } hbhlen = (hbh->ip6h_len + 1) << 3; IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr), hbhlen); if (hbh == NULL) { - IP6_STATINC(IP6_STAT_TOOSHORT); + ip6stat.ip6s_tooshort++; return -1; } KASSERT(IP6_HDR_ALIGNED_P(hbh)); @@ -935,7 +924,7 @@ ip6_process_hopopts(struct mbuf *m, u_in break; case IP6OPT_PADN: if (hbhlen < IP6OPT_MINLEN) { - IP6_STATINC(IP6_STAT_TOOSMALL); + ip6stat.ip6s_toosmall++; goto bad; } optlen = *(opt + 1) + 2; @@ -943,7 +932,7 @@ ip6_process_hopopts(struct mbuf *m, u_in case IP6OPT_RTALERT: /* XXX may need check for alignment */ if (hbhlen < IP6OPT_RTALERT_LEN) { - IP6_STATINC(IP6_STAT_TOOSMALL); + ip6stat.ip6s_toosmall++; goto bad; } if (*(opt + 1) != IP6OPT_RTALERT_LEN - 2) { @@ -960,7 +949,7 @@ ip6_process_hopopts(struct mbuf *m, u_in case IP6OPT_JUMBO: /* XXX may need check for alignment */ if (hbhlen < IP6OPT_JUMBO_LEN) { - IP6_STATINC(IP6_STAT_TOOSMALL); + ip6stat.ip6s_toosmall++; goto bad; } if (*(opt + 1) != IP6OPT_JUMBO_LEN - 2) { @@ -978,7 +967,7 @@ ip6_process_hopopts(struct mbuf *m, u_in */ ip6 = mtod(m, struct ip6_hdr *); if (ip6->ip6_plen) { - IP6_STATINC(IP6_STAT_BADOPTIONS); + ip6stat.ip6s_badoptions++; icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, erroff + opt - opthead); @@ -1002,7 +991,7 @@ ip6_process_hopopts(struct mbuf *m, u_in * there's no explicit mention in specification. */ if (*plenp != 0) { - IP6_STATINC(IP6_STAT_BADOPTIONS); + ip6stat.ip6s_badoptions++; icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, erroff + opt + 2 - opthead); @@ -1014,7 +1003,7 @@ ip6_process_hopopts(struct mbuf *m, u_in * jumbo payload length must be larger than 65535. */ if (jumboplen <= IPV6_MAXPACKET) { - IP6_STATINC(IP6_STAT_BADOPTIONS); + ip6stat.ip6s_badoptions++; icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, erroff + opt + 2 - opthead); @@ -1025,7 +1014,7 @@ ip6_process_hopopts(struct mbuf *m, u_in break; default: /* unknown option */ if (hbhlen < IP6OPT_MINLEN) { - IP6_STATINC(IP6_STAT_TOOSMALL); + ip6stat.ip6s_toosmall++; goto bad; } optlen = ip6_unknown_opt(opt, m, @@ -1062,11 +1051,11 @@ ip6_unknown_opt(u_int8_t *optp, struct m m_freem(m); return (-1); case IP6OPT_TYPE_FORCEICMP: /* send ICMP even if multicasted */ - IP6_STATINC(IP6_STAT_BADOPTIONS); + ip6stat.ip6s_badoptions++; icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_OPTION, off); return (-1); case IP6OPT_TYPE_ICMP: /* send ICMP if not multicasted */ - IP6_STATINC(IP6_STAT_BADOPTIONS); + ip6stat.ip6s_badoptions++; ip6 = mtod(m, struct ip6_hdr *); if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) || (m->m_flags & (M_BCAST|M_MCAST))) @@ -1181,14 +1170,14 @@ ip6_savecontrol(struct in6pcb *in6p, str ext = ip6_pullexthdr(m, sizeof(struct ip6_hdr), xip6->ip6_nxt); if (ext == NULL) { - IP6_STATINC(IP6_STAT_TOOSHORT); + ip6stat.ip6s_tooshort++; return; } hbh = mtod(ext, struct ip6_hbh *); hbhlen = (hbh->ip6h_len + 1) << 3; if (hbhlen != ext->m_len) { m_freem(ext); - IP6_STATINC(IP6_STAT_TOOSHORT); + ip6stat.ip6s_tooshort++; return; } @@ -1240,7 +1229,7 @@ ip6_savecontrol(struct in6pcb *in6p, str ext = ip6_pullexthdr(m, off, nxt); if (ext == NULL) { - IP6_STATINC(IP6_STAT_TOOSHORT); + ip6stat.ip6s_tooshort++; return; } ip6e = mtod(ext, struct ip6_ext *); @@ -1250,7 +1239,7 @@ ip6_savecontrol(struct in6pcb *in6p, str elen = (ip6e->ip6e_len + 1) << 3; if (elen != ext->m_len) { m_freem(ext); - IP6_STATINC(IP6_STAT_TOOSHORT); + ip6stat.ip6s_tooshort++; return; } KASSERT(IP6_HDR_ALIGNED_P(ip6e)); @@ -1595,21 +1584,17 @@ ip6_delaux(struct mbuf *m) static int sysctl_net_inet6_ip6_maxflows(SYSCTLFN_ARGS) { - int error; + int s; - error = sysctl_lookup(SYSCTLFN_CALL(rnode)); - if (error || newp == NULL) - return (error); + s = sysctl_lookup(SYSCTLFN_CALL(rnode)); + if (s || newp == NULL) + return (s); - mutex_enter(softnet_lock); - KERNEL_LOCK(1, NULL); - - ip6flow_reap(0); - - KERNEL_UNLOCK_ONE(NULL); - mutex_exit(softnet_lock); + s = splsoftnet(); + ip6flow_reap(0); + splx(s); - return (0); + return (0); } static int @@ -1629,21 +1614,16 @@ sysctl_net_inet6_ip6_hashsize(SYSCTLFN_A /* * Can only fail due to malloc() */ - mutex_enter(softnet_lock); - KERNEL_LOCK(1, NULL); - - error = ip6flow_invalidate_all(tmp); - - KERNEL_UNLOCK_ONE(NULL); - mutex_exit(softnet_lock); + if (ip6flow_invalidate_all(tmp)) + return ENOMEM; } else { /* * EINVAL if not a power of 2 - */ - error = EINVAL; + */ + return EINVAL; } - return error; + return (0); } #endif /* GATEWAY */ @@ -1651,7 +1631,7 @@ sysctl_net_inet6_ip6_hashsize(SYSCTLFN_A * System control for IP6 */ -const u_char inet6ctlerrmap[PRC_NCMDS] = { +u_char inet6ctlerrmap[PRC_NCMDS] = { 0, 0, 0, 0, 0, EMSGSIZE, EHOSTDOWN, EHOSTUNREACH, EHOSTUNREACH, EHOSTUNREACH, ECONNREFUSED, ECONNREFUSED, @@ -1660,13 +1640,6 @@ const u_char inet6ctlerrmap[PRC_NCMDS] = ENOPROTOOPT }; -static int -sysctl_net_inet6_ip6_stats(SYSCTLFN_ARGS) -{ - - return (NETSTAT_SYSCTL(ip6stat_percpu, IP6_NSTATS)); -} - SYSCTL_SETUP(sysctl_net_inet6_ip6_setup, "sysctl net.inet6.ip6 subtree setup") { #ifdef RFC2292 @@ -1920,7 +1893,7 @@ SYSCTL_SETUP(sysctl_net_inet6_ip6_setup, CTLFLAG_PERMANENT, CTLTYPE_STRUCT, "stats", SYSCTL_DESCR("IPv6 statistics"), - sysctl_net_inet6_ip6_stats, 0, NULL, 0, + NULL, 0, &ip6stat, sizeof(ip6stat), CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_STATS, CTL_EOL); sysctl_createv(clog, 0, NULL, NULL, @@ -1954,11 +1927,3 @@ SYSCTL_SETUP(sysctl_net_inet6_ip6_setup, CTL_CREATE, CTL_EOL); #endif } - -void -ip6_statinc(u_int stat) -{ - - KASSERT(stat < IP6_NSTATS); - IP6_STATINC(stat); -}