Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/netinet6 inet6: reduce silent packet discards



details:   https://anonhg.NetBSD.org/src/rev/31b0f54a0700
branches:  trunk
changeset: 937858:31b0f54a0700
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Fri Aug 28 06:32:24 2020 +0000

description:
inet6: reduce silent packet discards

diffstat:

 sys/netinet6/in6_src.c     |   5 +++--
 sys/netinet6/ip6_forward.c |   5 +++--
 sys/netinet6/ip6_input.c   |  19 +++++++++++++------
 sys/netinet6/ip6_output.c  |  29 ++++++++++++++++++++++-------
 sys/netinet6/ip6_var.h     |   9 +++++++--
 5 files changed, 48 insertions(+), 19 deletions(-)

diffs (truncated from 302 to 300 lines):

diff -r dd16825d760f -r 31b0f54a0700 sys/netinet6/in6_src.c
--- a/sys/netinet6/in6_src.c    Fri Aug 28 06:31:42 2020 +0000
+++ b/sys/netinet6/in6_src.c    Fri Aug 28 06:32:24 2020 +0000
@@ -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 @@
 
                /* 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;
                }
diff -r dd16825d760f -r 31b0f54a0700 sys/netinet6/ip6_forward.c
--- a/sys/netinet6/ip6_forward.c        Fri Aug 28 06:31:42 2020 +0000
+++ b/sys/netinet6/ip6_forward.c        Fri Aug 28 06:32:24 2020 +0000
@@ -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 @@
        }
 
        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,
diff -r dd16825d760f -r 31b0f54a0700 sys/netinet6/ip6_input.c
--- a/sys/netinet6/ip6_input.c  Fri Aug 28 06:31:42 2020 +0000
+++ b/sys/netinet6/ip6_input.c  Fri Aug 28 06:32:24 2020 +0000
@@ -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 @@
                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 @@
                 */
                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 @@
         * 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 @@
                            IN6_PRINT(ip6bufs, &ip6->ip6_src),
                            IN6_PRINT(ip6bufd, &ip6->ip6_dst));
 
+                       IP6_STATINC(IP6_STAT_IDROPPED);
                        goto bad_unref;
                }
        }
@@ -662,8 +667,10 @@
                                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 @@
                                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 @@
                                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);
diff -r dd16825d760f -r 31b0f54a0700 sys/netinet6/ip6_output.c
--- a/sys/netinet6/ip6_output.c Fri Aug 28 06:31:42 2020 +0000
+++ b/sys/netinet6/ip6_output.c Fri Aug 28 06:32:24 2020 +0000
@@ -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 @@
        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 @@
         */
        if ((needipsec || optlen) && !hdrsplit) {
                if ((error = ip6_splithdr(m, &exthdrs)) != 0) {
+                       IP6_STATINC(IP6_STAT_ODROPPED);
                        m = NULL;
                        goto freehdrs;
                }
@@ -331,6 +333,7 @@
        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 @@
                }
                /* 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 @@
                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 @@
                 */
                error = rtcache_setdst(ro, sin6tosa(&dst_sa));
                if (error) {
+                       IP6_STATINC(IP6_STAT_ODROPPED);
                        goto bad;
                }
        }
@@ -553,8 +561,10 @@
         */
        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 @@
        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 @@
 
        if (dontfrag && alwaysfrag) {   /* case 4 */
                /* conflicting request - can't transmit */
+               IP6_STATINC(IP6_STAT_CANTFRAG);
                error = EMSGSIZE;
                goto bad;
        }
@@ -813,6 +823,7 @@
                pfctlinput2(PRC_MSGSIZE,
                    rtcache_getdst(ro_pmtu), &ip6cp);
 
+               IP6_STATINC(IP6_STAT_CANTFRAG);
                error = EMSGSIZE;
                goto bad;
        }
@@ -857,6 +868,7 @@
        }
 
        if (tso) {
+               IP6_STATINC(IP6_STAT_CANTFRAG); /* XXX */
                error = EINVAL; /* XXX */
                goto bad;
        }
@@ -866,11 +878,13 @@
         */
        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 @@
                 */
                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;
diff -r dd16825d760f -r 31b0f54a0700 sys/netinet6/ip6_var.h
--- a/sys/netinet6/ip6_var.h    Fri Aug 28 06:31:42 2020 +0000
+++ b/sys/netinet6/ip6_var.h    Fri Aug 28 06:32:24 2020 +0000
@@ -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 @@
 #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
 



Home | Main Index | Thread Index | Old Index