From owner-svn-src-stable@FreeBSD.ORG Sat May 18 05:41:01 2013 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 0C360563; Sat, 18 May 2013 05:41:01 +0000 (UTC) (envelope-from melifaro@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id E28A51A1; Sat, 18 May 2013 05:41:00 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r4I5f0tn003668; Sat, 18 May 2013 05:41:00 GMT (envelope-from melifaro@svn.freebsd.org) Received: (from melifaro@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r4I5f0Aa003646; Sat, 18 May 2013 05:41:00 GMT (envelope-from melifaro@svn.freebsd.org) Message-Id: <201305180541.r4I5f0Aa003646@svn.freebsd.org> From: "Alexander V. Chernikov" Date: Sat, 18 May 2013 05:41:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r250761 - stable/9/sys/netpfil/ipfw X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 May 2013 05:41:01 -0000 Author: melifaro Date: Sat May 18 05:40:59 2013 New Revision: 250761 URL: http://svnweb.freebsd.org/changeset/base/250761 Log: MFC r243711. Use common macros for working with rule/dynamic counters. This is done as preparation to introduce per-cpu ipfw counters. Modified: stable/9/sys/netpfil/ipfw/ip_fw2.c stable/9/sys/netpfil/ipfw/ip_fw_dynamic.c stable/9/sys/netpfil/ipfw/ip_fw_private.h stable/9/sys/netpfil/ipfw/ip_fw_sockopt.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/netpfil/ipfw/ip_fw2.c ============================================================================== --- stable/9/sys/netpfil/ipfw/ip_fw2.c Sat May 18 05:31:17 2013 (r250760) +++ stable/9/sys/netpfil/ipfw/ip_fw2.c Sat May 18 05:40:59 2013 (r250761) @@ -2056,8 +2056,7 @@ do { \ * the parent rule by setting * f, cmd, l and clearing cmdlen. */ - q->pcnt++; - q->bcnt += pktlen; + IPFW_INC_DYN_COUNTER(q, pktlen); /* XXX we would like to have f_pos * readily accessible in the dynamic * rule, instead of having to @@ -2116,16 +2115,12 @@ do { \ break; case O_COUNT: - f->pcnt++; /* update stats */ - f->bcnt += pktlen; - f->timestamp = time_uptime; + IPFW_INC_RULE_COUNTER(f, pktlen); l = 0; /* exit inner loop */ break; case O_SKIPTO: - f->pcnt++; /* update stats */ - f->bcnt += pktlen; - f->timestamp = time_uptime; + IPFW_INC_RULE_COUNTER(f, pktlen); f_pos = jump_fast(chain, f, cmd->arg1, tablearg, 0); /* * Skip disabled rules, and re-enter @@ -2201,9 +2196,7 @@ do { \ break; } - f->pcnt++; /* update stats */ - f->bcnt += pktlen; - f->timestamp = time_uptime; + IPFW_INC_RULE_COUNTER(f, pktlen); stack = (uint16_t *)(mtag + 1); /* @@ -2337,9 +2330,7 @@ do { \ case O_SETFIB: { uint32_t fib; - f->pcnt++; /* update stats */ - f->bcnt += pktlen; - f->timestamp = time_uptime; + IPFW_INC_RULE_COUNTER(f, pktlen); fib = IP_FW_ARG_TABLEARG(cmd->arg1); if (fib >= rt_numfibs) fib = 0; @@ -2387,8 +2378,7 @@ do { \ case O_REASS: { int ip_off; - f->pcnt++; - f->bcnt += pktlen; + IPFW_INC_RULE_COUNTER(f, pktlen); l = 0; /* in any case exit inner loop */ ip_off = ntohs(ip->ip_off); @@ -2457,9 +2447,7 @@ do { \ if (done) { struct ip_fw *rule = chain->map[f_pos]; /* Update statistics */ - rule->pcnt++; - rule->bcnt += pktlen; - rule->timestamp = time_uptime; + IPFW_INC_RULE_COUNTER(rule, pktlen); } else { retval = IP_FW_DENY; printf("ipfw: ouch!, skip past end of rules, denying packet\n"); Modified: stable/9/sys/netpfil/ipfw/ip_fw_dynamic.c ============================================================================== --- stable/9/sys/netpfil/ipfw/ip_fw_dynamic.c Sat May 18 05:31:17 2013 (r250760) +++ stable/9/sys/netpfil/ipfw/ip_fw_dynamic.c Sat May 18 05:40:59 2013 (r250761) @@ -594,7 +594,7 @@ add_dyn_rule(struct ipfw_flow_id *id, in r->expire = time_uptime + V_dyn_syn_lifetime; r->rule = rule; r->dyn_type = dyn_type; - r->pcnt = r->bcnt = 0; + IPFW_ZERO_DYN_COUNTER(r); r->count = 0; r->bucket = i; Modified: stable/9/sys/netpfil/ipfw/ip_fw_private.h ============================================================================== --- stable/9/sys/netpfil/ipfw/ip_fw_private.h Sat May 18 05:31:17 2013 (r250760) +++ stable/9/sys/netpfil/ipfw/ip_fw_private.h Sat May 18 05:40:59 2013 (r250761) @@ -236,6 +236,28 @@ struct ip_fw_chain { struct sockopt; /* used by tcp_var.h */ +/* Macro for working with various counters */ +#define IPFW_INC_RULE_COUNTER(_cntr, _bytes) do { \ + (_cntr)->pcnt++; \ + (_cntr)->bcnt += _bytes; \ + (_cntr)->timestamp = time_uptime; \ + } while (0) + +#define IPFW_INC_DYN_COUNTER(_cntr, _bytes) do { \ + (_cntr)->pcnt++; \ + (_cntr)->bcnt += _bytes; \ + } while (0) + +#define IPFW_ZERO_RULE_COUNTER(_cntr) do { \ + (_cntr)->pcnt = 0; \ + (_cntr)->bcnt = 0; \ + (_cntr)->timestamp = 0; \ + } while (0) + +#define IPFW_ZERO_DYN_COUNTER(_cntr) do { \ + (_cntr)->pcnt = 0; \ + (_cntr)->bcnt = 0; \ + } while (0) #define IP_FW_ARG_TABLEARG(a) ((a) == IP_FW_TABLEARG) ? tablearg : (a) /* Modified: stable/9/sys/netpfil/ipfw/ip_fw_sockopt.c ============================================================================== --- stable/9/sys/netpfil/ipfw/ip_fw_sockopt.c Sat May 18 05:31:17 2013 (r250760) +++ stable/9/sys/netpfil/ipfw/ip_fw_sockopt.c Sat May 18 05:40:59 2013 (r250761) @@ -177,9 +177,7 @@ ipfw_add_rule(struct ip_fw_chain *chain, /* clear fields not settable from userland */ rule->x_next = NULL; rule->next_rule = NULL; - rule->pcnt = 0; - rule->bcnt = 0; - rule->timestamp = 0; + IPFW_ZERO_RULE_COUNTER(rule); if (V_autoinc_step < 1) V_autoinc_step = 1; @@ -442,10 +440,8 @@ clear_counters(struct ip_fw *rule, int l { ipfw_insn_log *l = (ipfw_insn_log *)ACTION_PTR(rule); - if (log_only == 0) { - rule->bcnt = rule->pcnt = 0; - rule->timestamp = 0; - } + if (log_only == 0) + IPFW_ZERO_RULE_COUNTER(rule); if (l->o.opcode == O_LOG) l->log_left = l->max_log; }