Module Name: src Committed By: ozaki-r Date: Fri Aug 28 06:32:24 UTC 2020
Modified Files: src/sys/netinet6: in6_src.c ip6_forward.c ip6_input.c ip6_output.c ip6_var.h Log Message: inet6: reduce silent packet discards To generate a diff of this commit: cvs rdiff -u -r1.86 -r1.87 src/sys/netinet6/in6_src.c \ src/sys/netinet6/ip6_var.h cvs rdiff -u -r1.101 -r1.102 src/sys/netinet6/ip6_forward.c cvs rdiff -u -r1.221 -r1.222 src/sys/netinet6/ip6_input.c cvs rdiff -u -r1.224 -r1.225 src/sys/netinet6/ip6_output.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/netinet6/in6_src.c diff -u src/sys/netinet6/in6_src.c:1.86 src/sys/netinet6/in6_src.c:1.87 --- src/sys/netinet6/in6_src.c:1.86 Wed Nov 13 02:51:22 2019 +++ src/sys/netinet6/in6_src.c Fri Aug 28 06:32:24 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: in6_src.c,v 1.86 2019/11/13 02:51:22 ozaki-r Exp $ */ +/* $NetBSD: in6_src.c,v 1.87 2020/08/28 06:32:24 ozaki-r 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.86 2019/11/13 02:51:22 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.87 2020/08/28 06:32:24 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -646,6 +646,7 @@ in6_selectroute(struct sockaddr_in6 *dst /* at this moment, we only support AF_INET6 next hops */ if (sin6_next->sin6_family != AF_INET6) { + IP6_STATINC(IP6_STAT_ODROPPED); error = EAFNOSUPPORT; /* or should we proceed? */ goto done; } Index: src/sys/netinet6/ip6_var.h diff -u src/sys/netinet6/ip6_var.h:1.86 src/sys/netinet6/ip6_var.h:1.87 --- src/sys/netinet6/ip6_var.h:1.86 Fri Aug 28 06:28:58 2020 +++ src/sys/netinet6/ip6_var.h Fri Aug 28 06:32:24 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_var.h,v 1.86 2020/08/28 06:28:58 ozaki-r Exp $ */ +/* $NetBSD: ip6_var.h,v 1.87 2020/08/28 06:32:24 ozaki-r Exp $ */ /* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */ /* @@ -190,8 +190,13 @@ struct ip6_pktopts { #define IP6_STAT_PFILDROP_OUT 404 /* dropped by pfil (PFIL_OUT) */ #define IP6_STAT_IPSECDROP_IN 405 /* dropped by IPsec SP check */ #define IP6_STAT_IPSECDROP_OUT 406 /* dropped by IPsec SP check */ +#define IP6_STAT_IFDROP 407 /* dropped due to inteface state */ +#define IP6_STAT_IDROPPED 408 /* lost packets due to nobufs, etc. */ +#define IP6_STAT_TIMXCEED 409 /* hop limit exceeded */ +#define IP6_STAT_TOOBIG 410 /* packet bigger than MTU */ +#define IP6_STAT_RTREJECT 411 /* rejected by route */ -#define IP6_NSTATS 407 +#define IP6_NSTATS 412 #define IP6FLOW_HASHBITS 6 /* should not be a multiple of 8 */ Index: src/sys/netinet6/ip6_forward.c diff -u src/sys/netinet6/ip6_forward.c:1.101 src/sys/netinet6/ip6_forward.c:1.102 --- src/sys/netinet6/ip6_forward.c:1.101 Fri Aug 28 06:28:58 2020 +++ src/sys/netinet6/ip6_forward.c Fri Aug 28 06:32:24 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_forward.c,v 1.101 2020/08/28 06:28:58 ozaki-r Exp $ */ +/* $NetBSD: ip6_forward.c,v 1.102 2020/08/28 06:32:24 ozaki-r Exp $ */ /* $KAME: ip6_forward.c,v 1.109 2002/09/11 08:10:17 sakane Exp $ */ /* @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.101 2020/08/28 06:28:58 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.102 2020/08/28 06:32:24 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_gateway.h" @@ -287,6 +287,7 @@ ip6_forward(struct mbuf *m, int srcrt, s } if (m->m_pkthdr.len > rt->rt_ifp->if_mtu) { + IP6_STATINC(IP6_STAT_TOOBIG); in6_ifstat_inc(rt->rt_ifp, ifs6_in_toobig); if (mcopy) icmp6_error(mcopy, ICMP6_PACKET_TOO_BIG, 0, Index: src/sys/netinet6/ip6_input.c diff -u src/sys/netinet6/ip6_input.c:1.221 src/sys/netinet6/ip6_input.c:1.222 --- src/sys/netinet6/ip6_input.c:1.221 Fri Aug 28 06:28:58 2020 +++ src/sys/netinet6/ip6_input.c Fri Aug 28 06:32:24 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_input.c,v 1.221 2020/08/28 06:28:58 ozaki-r Exp $ */ +/* $NetBSD: ip6_input.c,v 1.222 2020/08/28 06:32:24 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.221 2020/08/28 06:28:58 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.222 2020/08/28 06:32:24 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_gateway.h" @@ -227,6 +227,7 @@ ip6intr(void *arg __unused) struct ifnet *rcvif = m_get_rcvif_psref(m, &psref); if (rcvif == NULL) { + IP6_STATINC(IP6_STAT_IFDROP); m_freem(m); continue; } @@ -235,6 +236,7 @@ ip6intr(void *arg __unused) */ if ((ND_IFINFO(rcvif)->flags & ND6_IFF_IFDISABLED)) { m_put_rcvif_psref(rcvif, &psref); + IP6_STATINC(IP6_STAT_IFDROP); m_freem(m); continue; } @@ -396,8 +398,10 @@ ip6_input(struct mbuf *m, struct ifnet * * is not loopback. */ if (__predict_false( - m_makewritable(&m, 0, sizeof(struct ip6_hdr), M_DONTWAIT))) + m_makewritable(&m, 0, sizeof(struct ip6_hdr), M_DONTWAIT))) { + IP6_STATINC(IP6_STAT_IDROPPED); 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 */ @@ -505,6 +509,7 @@ ip6_input(struct mbuf *m, struct ifnet * IN6_PRINT(ip6bufs, &ip6->ip6_src), IN6_PRINT(ip6bufd, &ip6->ip6_dst)); + IP6_STATINC(IP6_STAT_IDROPPED); goto bad_unref; } } @@ -662,8 +667,10 @@ hbhcheck: goto bad; } } - if (!ours) + if (!ours) { + IP6_STATINC(IP6_STAT_CANTFORWARD); goto bad_unref; + } } else if (!ours) { rtcache_unref(rt, ro); rtcache_percpu_putref(ip6_forward_rt_percpu); @@ -930,7 +937,7 @@ ip6_process_hopopts(struct mbuf *m, u_in goto bad; } if (*(opt + 1) != IP6OPT_RTALERT_LEN - 2) { - /* XXX stat */ + IP6_STATINC(IP6_STAT_BADOPTIONS); icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, erroff + opt + 1 - opthead); @@ -947,7 +954,7 @@ ip6_process_hopopts(struct mbuf *m, u_in goto bad; } if (*(opt + 1) != IP6OPT_JUMBO_LEN - 2) { - /* XXX stat */ + IP6_STATINC(IP6_STAT_BADOPTIONS); icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, erroff + opt + 1 - opthead); Index: src/sys/netinet6/ip6_output.c diff -u src/sys/netinet6/ip6_output.c:1.224 src/sys/netinet6/ip6_output.c:1.225 --- src/sys/netinet6/ip6_output.c:1.224 Fri Aug 28 06:19:13 2020 +++ src/sys/netinet6/ip6_output.c Fri Aug 28 06:32:24 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_output.c,v 1.224 2020/08/28 06:19:13 ozaki-r Exp $ */ +/* $NetBSD: ip6_output.c,v 1.225 2020/08/28 06:32:24 ozaki-r 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.224 2020/08/28 06:19:13 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.225 2020/08/28 06:32:24 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -165,6 +165,7 @@ ip6_if_output(struct ifnet * const ifp, if (rt != NULL) { error = rt_check_reject_route(rt, ifp); if (error != 0) { + IP6_STATINC(IP6_STAT_RTREJECT); m_freem(m); return error; } @@ -313,6 +314,7 @@ ip6_output( */ if ((needipsec || optlen) && !hdrsplit) { if ((error = ip6_splithdr(m, &exthdrs)) != 0) { + IP6_STATINC(IP6_STAT_ODROPPED); m = NULL; goto freehdrs; } @@ -331,6 +333,7 @@ ip6_output( if (plen > IPV6_MAXPACKET) { if (!hdrsplit) { if ((error = ip6_splithdr(m, &exthdrs)) != 0) { + IP6_STATINC(IP6_STAT_ODROPPED); m = NULL; goto freehdrs; } @@ -339,8 +342,10 @@ ip6_output( } /* adjust pointer */ ip6 = mtod(m, struct ip6_hdr *); - if ((error = ip6_insert_jumboopt(&exthdrs, plen)) != 0) + if ((error = ip6_insert_jumboopt(&exthdrs, plen)) != 0) { + IP6_STATINC(IP6_STAT_ODROPPED); goto freehdrs; + } optlen += 8; /* XXX JUMBOOPTLEN */ ip6->ip6_plen = 0; } else @@ -418,8 +423,10 @@ ip6_output( rh = mtod(exthdrs.ip6e_rthdr, struct ip6_rthdr *); error = ip6_handle_rthdr(rh, ip6); - if (error != 0) + if (error != 0) { + IP6_STATINC(IP6_STAT_ODROPPED); goto bad; + } } /* Source address validation */ @@ -530,6 +537,7 @@ ip6_output( */ error = rtcache_setdst(ro, sin6tosa(&dst_sa)); if (error) { + IP6_STATINC(IP6_STAT_ODROPPED); goto bad; } } @@ -553,8 +561,10 @@ ip6_output( */ if (ia != NULL) { origifp = ia->ia_ifp; - if (if_is_deactivated(origifp)) + if (if_is_deactivated(origifp)) { + IP6_STATINC(IP6_STAT_ODROPPED); goto bad; + } if_acquire(origifp, &psref_ia); release_psref_ia = true; } else @@ -699,8 +709,7 @@ ip6_output( error = ip6_getpmtu(rt_pmtu, ifp, &mtu, &alwaysfrag); if (rt_pmtu != NULL && rt_pmtu != rt) rtcache_unref(rt_pmtu, ro_pmtu); - if (error != 0) - goto bad; + KASSERT(error == 0); /* ip6_getpmtu never fail if ifp is passed */ /* * The caller of this function may specify to use the minimum MTU @@ -792,6 +801,7 @@ ip6_output( if (dontfrag && alwaysfrag) { /* case 4 */ /* conflicting request - can't transmit */ + IP6_STATINC(IP6_STAT_CANTFRAG); error = EMSGSIZE; goto bad; } @@ -813,6 +823,7 @@ ip6_output( pfctlinput2(PRC_MSGSIZE, rtcache_getdst(ro_pmtu), &ip6cp); + IP6_STATINC(IP6_STAT_CANTFRAG); error = EMSGSIZE; goto bad; } @@ -857,6 +868,7 @@ ip6_output( } if (tso) { + IP6_STATINC(IP6_STAT_CANTFRAG); /* XXX */ error = EINVAL; /* XXX */ goto bad; } @@ -866,11 +878,13 @@ ip6_output( */ if (mtu < IPV6_MMTU) { /* path MTU cannot be less than IPV6_MMTU */ + IP6_STATINC(IP6_STAT_CANTFRAG); error = EMSGSIZE; in6_ifstat_inc(ifp, ifs6_out_fragfail); goto bad; } else if (ip6->ip6_plen == 0) { /* jumbo payload cannot be fragmented */ + IP6_STATINC(IP6_STAT_CANTFRAG); error = EMSGSIZE; in6_ifstat_inc(ifp, ifs6_out_fragfail); goto bad; @@ -889,6 +903,7 @@ ip6_output( */ len = (mtu - hlen - sizeof(struct ip6_frag)) & ~7; if (len < 8) { + IP6_STATINC(IP6_STAT_CANTFRAG); error = EMSGSIZE; in6_ifstat_inc(ifp, ifs6_out_fragfail); goto bad;