Module Name: src Committed By: ozaki-r Date: Fri Aug 28 06:31:42 UTC 2020
Modified Files: src/sys/netinet: ip_input.c ip_output.c ip_var.h Log Message: inet: reduce silent packet discards To generate a diff of this commit: cvs rdiff -u -r1.396 -r1.397 src/sys/netinet/ip_input.c cvs rdiff -u -r1.317 -r1.318 src/sys/netinet/ip_output.c cvs rdiff -u -r1.129 -r1.130 src/sys/netinet/ip_var.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/netinet/ip_input.c diff -u src/sys/netinet/ip_input.c:1.396 src/sys/netinet/ip_input.c:1.397 --- src/sys/netinet/ip_input.c:1.396 Fri Aug 28 06:30:08 2020 +++ src/sys/netinet/ip_input.c Fri Aug 28 06:31:42 2020 @@ -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 @@ ipintr(void *arg __unused) 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 @@ ip_input(struct mbuf *m, struct ifnet *i * 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 @@ ip_forward(struct mbuf *m, int srcrt, st } 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 @@ ip_forward(struct mbuf *m, int srcrt, st 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; } Index: src/sys/netinet/ip_output.c diff -u src/sys/netinet/ip_output.c:1.317 src/sys/netinet/ip_output.c:1.318 --- src/sys/netinet/ip_output.c:1.317 Fri Aug 28 06:22:25 2020 +++ src/sys/netinet/ip_output.c Fri Aug 28 06:31:42 2020 @@ -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 @@ ip_if_output(struct ifnet * const ifp, s 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 @@ ip_output(struct mbuf *m0, struct mbuf * (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 @@ ip_output(struct mbuf *m0, struct mbuf * 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 @@ ip_output(struct mbuf *m0, struct mbuf * xia = in_get_ia_from_ifp_psref(ifp, &_psref); if (!xia) { + IP_STATINC(IP_STAT_IFNOADDR); error = EADDRNOTAVAIL; goto bad; } @@ -460,6 +465,7 @@ ip_output(struct mbuf *m0, struct mbuf * /* 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 @@ ip_output(struct mbuf *m0, struct mbuf * * 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 @@ ip_output(struct mbuf *m0, struct mbuf * */ 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 @@ ip_fragment(struct mbuf *m, struct ifnet len = (mtu - hlen) &~ 7; if (len < 8) { + IP_STATINC(IP_STAT_CANTFRAG); m_freem(m); return EMSGSIZE; } Index: src/sys/netinet/ip_var.h diff -u src/sys/netinet/ip_var.h:1.129 src/sys/netinet/ip_var.h:1.130 --- src/sys/netinet/ip_var.h:1.129 Fri Aug 28 06:19:13 2020 +++ src/sys/netinet/ip_var.h Fri Aug 28 06:31:42 2020 @@ -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 @@ struct ip_pktopts { #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