From owner-svn-src-all@FreeBSD.ORG Thu Dec 10 15:17:35 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 125AC106568B; Thu, 10 Dec 2009 15:17:35 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 013098FC24; Thu, 10 Dec 2009 15:17:35 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBAFHYNe067206; Thu, 10 Dec 2009 15:17:34 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBAFHYhN067204; Thu, 10 Dec 2009 15:17:34 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912101517.nBAFHYhN067204@svn.freebsd.org> From: Luigi Rizzo Date: Thu, 10 Dec 2009 15:17:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200358 - head/sys/netinet/ipfw X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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, 10 Dec 2009 15:17:35 -0000 Author: luigi Date: Thu Dec 10 15:17:34 2009 New Revision: 200358 URL: http://svn.freebsd.org/changeset/base/200358 Log: centralize the code to free a packet (or a chain) while in dummynet. Remove an old macro and its stale comment. Modified: head/sys/netinet/ipfw/ip_dummynet.c Modified: head/sys/netinet/ipfw/ip_dummynet.c ============================================================================== --- head/sys/netinet/ipfw/ip_dummynet.c Thu Dec 10 14:54:29 2009 (r200357) +++ head/sys/netinet/ipfw/ip_dummynet.c Thu Dec 10 15:17:34 2009 (r200358) @@ -461,6 +461,27 @@ heap_free(struct dn_heap *h) */ /* + * Dispose a packet in dummynet. Use an inline functions so if we + * need to free extra state associated to a packet, this is a + * central point to do it. + */ +static __inline void *dn_free_pkt(struct mbuf *m) +{ + m_freem(m); + return NULL; +} + +static __inline void dn_free_pkts(struct mbuf *mnext) +{ + struct mbuf *m; + + while ((m = mnext) != NULL) { + mnext = m->m_nextpkt; + dn_free_pkt(m); + } +} + +/* * Return the mbuf tag holding the dummynet state. As an optimization * this is assumed to be the first tag on the list. If this turns out * wrong we'll need to search the list. @@ -1009,12 +1030,12 @@ dummynet_send(struct mbuf *m) case DN_TO_DROP: /* drop the packet after some time */ - m_freem(m); + dn_free_pkt(m); break; default: printf("dummynet: bad switch %d!\n", pkt->dn_dir); - m_freem(m); + dn_free_pkt(m); break; } } @@ -1553,20 +1574,11 @@ dropit: if (q) q->drops++; DUMMYNET_UNLOCK(); - m_freem(m); - *m0 = NULL; + *m0 = dn_free_pkt(m); return ((fs && (fs->flags_fs & DN_NOERROR)) ? 0 : ENOBUFS); } /* - * Below, the rt_unref is only needed when (pkt->dn_dir == DN_TO_IP_OUT) - * Doing this would probably save us the initial bzero of dn_pkt - */ -#define DN_FREE_PKT(_m) do { \ - m_freem(_m); \ -} while (0) - -/* * Dispose all packets and flow_queues on a flow_set. * If all=1, also remove red lookup table and other storage, * including the descriptor itself. @@ -1582,13 +1594,7 @@ purge_flow_set(struct dn_flow_set *fs, i for (i = 0; i <= fs->rq_size; i++) { for (q = fs->rq[i]; q != NULL; q = qn) { - struct mbuf *m, *mnext; - - mnext = q->head; - while ((m = mnext) != NULL) { - mnext = m->m_nextpkt; - DN_FREE_PKT(m); - } + dn_free_pkts(q->head); qn = q->next; free(q, M_DUMMYNET); } @@ -1616,15 +1622,10 @@ purge_flow_set(struct dn_flow_set *fs, i static void purge_pipe(struct dn_pipe *pipe) { - struct mbuf *m, *mnext; purge_flow_set( &(pipe->fs), 1 ); - mnext = pipe->head; - while ((m = mnext) != NULL) { - mnext = m->m_nextpkt; - DN_FREE_PKT(m); - } + dn_free_pkts(pipe->head); heap_free( &(pipe->scheduler_heap) ); heap_free( &(pipe->not_eligible_heap) ); @@ -1974,7 +1975,6 @@ dummynet_drain(void) { struct dn_flow_set *fs; struct dn_pipe *pipe; - struct mbuf *m, *mnext; int i; DUMMYNET_LOCK_ASSERT(); @@ -1990,12 +1990,7 @@ dummynet_drain(void) for (i = 0; i < HASHSIZE; i++) { SLIST_FOREACH(pipe, &pipehash[i], next) { purge_flow_set(&(pipe->fs), 0); - - mnext = pipe->head; - while ((m = mnext) != NULL) { - mnext = m->m_nextpkt; - DN_FREE_PKT(m); - } + dn_free_pkt(pipe->head); pipe->head = pipe->tail = NULL; } }