From owner-svn-src-all@FreeBSD.ORG Thu Apr 9 08:52:03 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 92998513; Thu, 9 Apr 2015 08:52:03 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 73D3CFCB; Thu, 9 Apr 2015 08:52:03 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t398q34r076501; Thu, 9 Apr 2015 08:52:03 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t398q3dB076500; Thu, 9 Apr 2015 08:52:03 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201504090852.t398q3dB076500@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Thu, 9 Apr 2015 08:52:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r281294 - head/sys/netinet X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Apr 2015 08:52:03 -0000 Author: glebius Date: Thu Apr 9 08:52:02 2015 New Revision: 281294 URL: https://svnweb.freebsd.org/changeset/base/281294 Log: o Since we always update either fragdrop or fragtimeout stat counter when we free a fragment, provide two inline functions that do that for us: ipq_drop() and ipq_timeout(). o Rename ip_free_f() to ipq_free() to match the name scheme of IP reassembly. o Remove assertion from ipq_free(), since it requires extra argument to be passed, but locking scheme is simple enough and function is static. Sponsored by: Nginx, Inc. Modified: head/sys/netinet/ip_input.c Modified: head/sys/netinet/ip_input.c ============================================================================== --- head/sys/netinet/ip_input.c Thu Apr 9 08:37:16 2015 (r281293) +++ head/sys/netinet/ip_input.c Thu Apr 9 08:52:02 2015 (r281294) @@ -177,11 +177,27 @@ static struct mtx_padalign ipqlock[IPREA #define IPQ_LOCK(i) mtx_lock(&ipqlock[(i)]) #define IPQ_UNLOCK(i) mtx_unlock(&ipqlock[(i)]) #define IPQ_LOCK_INIT(i) mtx_init(&ipqlock[(i)], "ipqlock", NULL, MTX_DEF) -#define IPQ_LOCK_ASSERT(i) mtx_assert(&ipqlock[(i)], MA_OWNED) static void maxnipq_update(void); static void ipq_zone_change(void *); static void ip_drain_vnet(void); +static void ipq_free(struct ipqhead *, struct ipq *); + +static inline void +ipq_timeout(struct ipqhead *head, struct ipq *fp) +{ + + IPSTAT_ADD(ips_fragtimeout, fp->ipq_nfrags); + ipq_free(head, fp); +} + +static inline void +ipq_drop(struct ipqhead *head, struct ipq *fp) +{ + + IPSTAT_ADD(ips_fragdropped, fp->ipq_nfrags); + ipq_free(head, fp); +} static VNET_DEFINE(int, maxnipq); /* Administrative limit on # reass queues. */ static VNET_DEFINE(int, nipq); /* Total # of reass queues */ @@ -209,8 +225,6 @@ SYSCTL_INT(_net_inet_ip, OID_AUTO, steal "IP stealth mode, no TTL decrementation on forwarding"); #endif -static void ip_freef(struct ipqhead *, int, struct ipq *); - /* * IP statistics are stored in the "array" of counter(9)s. */ @@ -881,9 +895,7 @@ ip_reass_purge_element(int skip_bucket) IPQ_LOCK(i); r = TAILQ_LAST(&V_ipq[i], ipqhead); if (r) { - IPSTAT_ADD(ips_fragtimeout, - r->ipq_nfrags); - ip_freef(&V_ipq[i], i, r); + ipq_timeout(&V_ipq[i], r); IPQ_UNLOCK(i); return (i); } @@ -964,10 +976,8 @@ ip_reass(struct mbuf *m) * lock is no longer held. */ do_purge = 1; - } else { - IPSTAT_ADD(ips_fragtimeout, q->ipq_nfrags); - ip_freef(head, hash, q); - } + } else + ipq_timeout(head, q); } found: @@ -1125,20 +1135,16 @@ found: next = 0; for (p = NULL, q = fp->ipq_frags; q; p = q, q = q->m_nextpkt) { if (ntohs(GETIP(q)->ip_off) != next) { - if (fp->ipq_nfrags > V_maxfragsperpacket) { - IPSTAT_ADD(ips_fragdropped, fp->ipq_nfrags); - ip_freef(head, hash, fp); - } + if (fp->ipq_nfrags > V_maxfragsperpacket) + ipq_drop(head, fp); goto done; } next += ntohs(GETIP(q)->ip_len); } /* Make sure the last packet didn't have the IP_MF flag */ if (p->m_flags & M_IP_FRAG) { - if (fp->ipq_nfrags > V_maxfragsperpacket) { - IPSTAT_ADD(ips_fragdropped, fp->ipq_nfrags); - ip_freef(head, hash, fp); - } + if (fp->ipq_nfrags > V_maxfragsperpacket) + ipq_drop(head, fp); goto done; } @@ -1149,8 +1155,7 @@ found: ip = GETIP(q); if (next + (ip->ip_hl << 2) > IP_MAXPACKET) { IPSTAT_INC(ips_toolong); - IPSTAT_ADD(ips_fragdropped, fp->ipq_nfrags); - ip_freef(head, hash, fp); + ipq_drop(head, fp); goto done; } @@ -1266,12 +1271,10 @@ done: * associated datagrams. */ static void -ip_freef(struct ipqhead *fhp, int i, struct ipq *fp) +ipq_free(struct ipqhead *fhp, struct ipq *fp) { struct mbuf *q; - IPQ_LOCK_ASSERT(i); - while (fp->ipq_frags) { q = fp->ipq_frags; fp->ipq_frags = q->m_nextpkt; @@ -1304,11 +1307,8 @@ ip_slowtimo(void) fpp = fp; fp = TAILQ_NEXT(fp, ipq_list); - if(--fpp->ipq_ttl == 0) { - IPSTAT_ADD(ips_fragtimeout, - fpp->ipq_nfrags); - ip_freef(&V_ipq[i], i, fpp); - } + if(--fpp->ipq_ttl == 0) + ipq_timeout(&V_ipq[i], fpp); } IPQ_UNLOCK(i); } @@ -1321,13 +1321,9 @@ ip_slowtimo(void) for (i = 0; i < IPREASS_NHASH; i++) { IPQ_LOCK(i); while (V_nipq > V_maxnipq && - !TAILQ_EMPTY(&V_ipq[i])) { - IPSTAT_ADD(ips_fragdropped, - TAILQ_FIRST(&V_ipq[i])->ipq_nfrags); - ip_freef(&V_ipq[i], - i, + !TAILQ_EMPTY(&V_ipq[i])) + ipq_drop(&V_ipq[i], TAILQ_FIRST(&V_ipq[i])); - } IPQ_UNLOCK(i); } } @@ -1346,11 +1342,8 @@ ip_drain_vnet(void) for (i = 0; i < IPREASS_NHASH; i++) { IPQ_LOCK(i); - while(!TAILQ_EMPTY(&V_ipq[i])) { - IPSTAT_ADD(ips_fragdropped, - TAILQ_FIRST(&V_ipq[i])->ipq_nfrags); - ip_freef(&V_ipq[i], i, TAILQ_FIRST(&V_ipq[i])); - } + while(!TAILQ_EMPTY(&V_ipq[i])) + ipq_drop(&V_ipq[i], TAILQ_FIRST(&V_ipq[i])); IPQ_UNLOCK(i); } }