Source-Changes-HG archive

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

[src/trunk]: src/sys/netinet inet: reduce silent packet discards



details:   https://anonhg.NetBSD.org/src/rev/4b0279f0c5d4
branches:  trunk
changeset: 943168:4b0279f0c5d4
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Fri Aug 28 06:31:42 2020 +0000

description:
inet: reduce silent packet discards

diffstat:

 sys/netinet/ip_input.c  |  12 +++++++++---
 sys/netinet/ip_output.c |  17 ++++++++++++++---
 sys/netinet/ip_var.h    |   9 +++++++--
 3 files changed, 30 insertions(+), 8 deletions(-)

diffs (176 lines):

diff -r 203ab9044884 -r 4b0279f0c5d4 sys/netinet/ip_input.c
--- a/sys/netinet/ip_input.c    Fri Aug 28 06:30:08 2020 +0000
+++ b/sys/netinet/ip_input.c    Fri Aug 28 06:31:42 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_input.c,v 1.396 2020/08/28 06:30:08 ozaki-r Exp $   */
+/*     $NetBSD: ip_input.c,v 1.397 2020/08/28 06:31:42 ozaki-r Exp $   */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.396 2020/08/28 06:30:08 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.397 2020/08/28 06:31:42 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -404,6 +404,7 @@
 
                ifp = m_get_rcvif_psref(m, &psref);
                if (__predict_false(ifp == NULL)) {
+                       IP_STATINC(IP_STAT_IFDROP);
                        m_freem(m);
                        continue;
                }
@@ -440,8 +441,11 @@
         * are receiving, can't do anything with incoming packets yet.
         * Note: we pre-check without locks held.
         */
-       if (IN_ADDRLIST_READER_EMPTY())
+       if (IN_ADDRLIST_READER_EMPTY()) {
+               IP_STATINC(IP_STAT_IFDROP);
                goto out;
+       }
+
        IP_STATINC(IP_STAT_TOTAL);
 
        /*
@@ -1363,6 +1367,7 @@
        }
 
        if (ip->ip_ttl <= IPTTLDEC) {
+               IP_STATINC(IP_STAT_TIMXCEED);
                icmp_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, dest, 0);
                return;
        }
@@ -1373,6 +1378,7 @@
        rt = rtcache_lookup(ro, &u.dst);
        if (rt == NULL) {
                rtcache_percpu_putref(ipforward_rt_percpu);
+               IP_STATINC(IP_STAT_NOROUTE);
                icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, dest, 0);
                return;
        }
diff -r 203ab9044884 -r 4b0279f0c5d4 sys/netinet/ip_output.c
--- a/sys/netinet/ip_output.c   Fri Aug 28 06:30:08 2020 +0000
+++ b/sys/netinet/ip_output.c   Fri Aug 28 06:31:42 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_output.c,v 1.317 2020/08/28 06:22:25 ozaki-r Exp $  */
+/*     $NetBSD: ip_output.c,v 1.318 2020/08/28 06:31:42 ozaki-r Exp $  */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.317 2020/08/28 06:22:25 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.318 2020/08/28 06:31:42 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -202,6 +202,7 @@
        if (rt != NULL) {
                error = rt_check_reject_route(rt, ifp);
                if (error != 0) {
+                       IP_STATINC(IP_STAT_RTREJECT);
                        m_freem(m);
                        return error;
                }
@@ -312,8 +313,10 @@
            (rt = rtcache_update(ro, 1)) == NULL) {
                dst = &udst.sin;
                error = rtcache_setdst(ro, &udst.sa);
-               if (error != 0)
+               if (error != 0) {
+                       IP_STATINC(IP_STAT_ODROPPED);
                        goto bad;
+               }
        }
 
        /*
@@ -346,6 +349,7 @@
                mtu = ifp->if_mtu;
                ia = in_get_ia_from_ifp_psref(ifp, &psref_ia);
                if (ia == NULL) {
+                       IP_STATINC(IP_STAT_IFNOADDR);
                        error = EADDRNOTAVAIL;
                        goto bad;
                }
@@ -451,6 +455,7 @@
 
                        xia = in_get_ia_from_ifp_psref(ifp, &_psref);
                        if (!xia) {
+                               IP_STATINC(IP_STAT_IFNOADDR);
                                error = EADDRNOTAVAIL;
                                goto bad;
                        }
@@ -460,6 +465,7 @@
                                /* FIXME ifa_getifa is NOMPSAFE */
                                xia = ifatoia((*xifa->ifa_getifa)(xifa, rdst));
                                if (xia == NULL) {
+                                       IP_STATINC(IP_STAT_IFNOADDR);
                                        error = EADDRNOTAVAIL;
                                        goto bad;
                                }
@@ -511,6 +517,7 @@
                 * destination group on the loopback interface.
                 */
                if (ip->ip_ttl == 0 || (ifp->if_flags & IFF_LOOPBACK) != 0) {
+                       IP_STATINC(IP_STAT_ODROPPED);
                        m_freem(m);
                        goto done;
                }
@@ -554,15 +561,18 @@
         */
        if (isbroadcast) {
                if ((ifp->if_flags & IFF_BROADCAST) == 0) {
+                       IP_STATINC(IP_STAT_BCASTDENIED);
                        error = EADDRNOTAVAIL;
                        goto bad;
                }
                if ((flags & IP_ALLOWBROADCAST) == 0) {
+                       IP_STATINC(IP_STAT_BCASTDENIED);
                        error = EACCES;
                        goto bad;
                }
                /* don't allow broadcast messages to be fragmented */
                if (ntohs(ip->ip_len) > ifp->if_mtu) {
+                       IP_STATINC(IP_STAT_BCASTDENIED);
                        error = EMSGSIZE;
                        goto bad;
                }
@@ -840,6 +850,7 @@
 
        len = (mtu - hlen) &~ 7;
        if (len < 8) {
+               IP_STATINC(IP_STAT_CANTFRAG);
                m_freem(m);
                return EMSGSIZE;
        }
diff -r 203ab9044884 -r 4b0279f0c5d4 sys/netinet/ip_var.h
--- a/sys/netinet/ip_var.h      Fri Aug 28 06:30:08 2020 +0000
+++ b/sys/netinet/ip_var.h      Fri Aug 28 06:31:42 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_var.h,v 1.129 2020/08/28 06:19:13 ozaki-r Exp $     */
+/*     $NetBSD: ip_var.h,v 1.130 2020/08/28 06:31:42 ozaki-r Exp $     */
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -151,8 +151,13 @@
 #define        IP_STAT_PFILDROP_OUT    33      /* dropped by pfil (PFIL_OUT) */
 #define        IP_STAT_IPSECDROP_IN    34      /* dropped by IPsec SP check */
 #define        IP_STAT_IPSECDROP_OUT   35      /* dropped by IPsec SP check */
+#define        IP_STAT_IFDROP          36      /* dropped due to interface state */
+#define        IP_STAT_TIMXCEED        37      /* time to live exceeded */
+#define        IP_STAT_IFNOADDR        38      /* interface has no IP address */
+#define        IP_STAT_RTREJECT        39      /* rejected by route */
+#define        IP_STAT_BCASTDENIED     40      /* broadcast prohibited */
 
-#define        IP_NSTATS               36
+#define        IP_NSTATS               41
 
 #ifdef _KERNEL
 



Home | Main Index | Thread Index | Old Index