From clive@FreeBSD.org  Mon Nov 15 04:17:14 2004
Return-Path: <clive@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 157A516A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 15 Nov 2004 04:17:14 +0000 (GMT)
Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21])
	by mx1.FreeBSD.org (Postfix) with ESMTP id EB62E43D2D
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 15 Nov 2004 04:17:13 +0000 (GMT)
	(envelope-from clive@FreeBSD.org)
Received: from freefall.freebsd.org (clive@localhost [127.0.0.1])
	by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id iAF4HDUf090427
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 15 Nov 2004 04:17:13 GMT
	(envelope-from clive@freefall.freebsd.org)
Received: (from clive@localhost)
	by freefall.freebsd.org (8.12.11/8.12.11/Submit) id iAF4HDbB090426;
	Mon, 15 Nov 2004 04:17:13 GMT
	(envelope-from clive)
Message-Id: <200411150417.iAF4HDbB090426@freefall.freebsd.org>
Date: Mon, 15 Nov 2004 04:17:13 GMT
From: Clive Lin <clive@freebsd.org>
Reply-To: Clive Lin <clive@freebsd.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Teach periodic(8) to understand pf(4) denied packets
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         73959
>Category:       conf
>Synopsis:       [patch] Teach periodic(8) to understand pf(4) denied packets
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    mlaier
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 15 04:20:24 GMT 2004
>Closed-Date:    Wed Dec 08 00:38:42 GMT 2004
>Last-Modified:  Wed Dec 08 00:38:42 GMT 2004
>Originator:     Clive Lin
>Release:        FreeBSD 6.0-CURRENT i386
>Organization:
FreeBSD.org
>Environment:
System: FreeBSD trex 5.3-RELEASE FreeBSD 5.3-RELEASE #1: Sun Nov 14 03:37:41 CST 2004     root@builder:/usr/obj/usr/src/sys/I686UP  i386


>Description:
	periodic(8) security output could display ipfw and ipf denied packets,
but not pf. Teach it to understand pf output.
>How-To-Repeat:
	Read periodic mails, subject "${hostname} security run output."
Number of denied packets by ipfw and ipf could be displayed, but not pf.
>Fix:


diff -ruN --exclude *CVS* /usr/src/etc/defaults/periodic.conf ./defaults/periodic.conf
--- /usr/src/etc/defaults/periodic.conf	Thu Sep 23 17:10:05 2004
+++ ./defaults/periodic.conf	Mon Nov 15 12:01:20 2004
@@ -150,6 +150,9 @@
 # 510.ipfdenied
 daily_status_security_ipfdenied_enable="YES"
 
+# 520.pfdenied
+daily_status_security_pfdenied_enable="YES"
+
 # 550.ipfwlimit
 daily_status_security_ipfwlimit_enable="YES"
 
diff -ruN --exclude *CVS* /usr/src/etc/periodic/security/520.pfdenied ./periodic/security/520.pfdenied
--- /usr/src/etc/periodic/security/520.pfdenied	Thu Jan  1 08:00:00 1970
+++ ./periodic/security/520.pfdenied	Mon Nov 15 12:00:12 2004
@@ -0,0 +1,53 @@
+#!/bin/sh -
+#
+# Copyright (c) 2001  The FreeBSD Project
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+
+# If there is a global system configuration file, suck it in.
+#
+if [ -r /etc/defaults/periodic.conf ]
+then
+    . /etc/defaults/periodic.conf
+    source_periodic_confs
+fi
+
+. /etc/periodic/security/security.functions
+
+rc=0
+
+case "$daily_status_security_pfdenied_enable" in
+    [Yy][Ee][Ss])
+	TMP=`mktemp -t security`
+	if pfctl -sr -v 2>/dev/null | nawk '{if (/^block/) {print $0;getline;print $0} }' > ${TMP}; then
+	  check_diff new_only pf ${TMP} "${host} pf denied packets:"
+	fi
+	rc=$?
+	rm -f ${TMP};;
+    *)	rc=0;;
+esac
+
+exit $rc
diff -ruN --exclude *CVS* /usr/src/etc/periodic/security/Makefile ./periodic/security/Makefile
--- /usr/src/etc/periodic/security/Makefile	Sun Oct 27 02:19:21 2002
+++ ./periodic/security/Makefile	Mon Nov 15 12:00:56 2004
@@ -6,6 +6,7 @@
 	400.passwdless \
 	500.ipfwdenied \
 	510.ipfdenied \
+	520.pfdenied \
 	550.ipfwlimit \
 	600.ip6fwdenied \
 	650.ip6fwlimit \


>Release-Note:
>Audit-Trail:

From: Giorgos Keramidas <keramida@freebsd.org>
To: Clive Lin <clive@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: misc/73959: Teach periodic(8) to understand pf(4) denied packets
Date: Mon, 15 Nov 2004 07:43:01 +0200

 On 2004-11-15 04:17, Clive Lin <clive@freebsd.org> wrote:
 > >Number:         73959
 > >Category:       misc
 > >Synopsis:       Teach periodic(8) to understand pf(4) denied packets
 
 > periodic(8) security output could display ipfw and ipf denied packets,
 > but not pf. Teach it to understand pf output.
 
 Good idea!  There are a few details that need to get polished, but
 AFAICT the added scripts look fine.
 
 : diff -ruN --exclude *CVS* /usr/src/etc/periodic/security/520.pfdenied ./periodic/security/520.pfdenied
 : --- /usr/src/etc/periodic/security/520.pfdenied	Thu Jan  1 08:00:00 1970
 : +++ ./periodic/security/520.pfdenied	Mon Nov 15 12:00:12 2004
 : @@ -0,0 +1,53 @@
 : +#!/bin/sh -
 : +#
 : +# Copyright (c) 2001  The FreeBSD Project
 : +# All rights reserved.
 
 The date is a bit off here :-)
 
 I only wanted to add that the periodic.conf.5 manpage must be updated
 too, if there are changes to the list of supported variables / options.
 

From: Clive Lin <clive@tongi.org>
To: Giorgos Keramidas <keramida@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: misc/73959: Teach periodic(8) to understand pf(4) denied packets
Date: Mon, 15 Nov 2004 15:59:14 +0800

 On Mon, Nov 15, 2004 at 07:43:01AM +0200, Giorgos Keramidas wrote:
 > : +# Copyright (c) 2001  The FreeBSD Project
 > : +# All rights reserved.
 > 
 > The date is a bit off here :-)
 > 
 > I only wanted to add that the periodic.conf.5 manpage must be updated
 > too, if there are changes to the list of supported variables / options.
 
 Argh. I missed both 2 parts.
 
 Alright, updated diff:
 
 http://people.freebsd.org/~clive/dist/periodic_security_520_pfdenied.diff
 http://people.freebsd.org/~clive/dist/periodic.conf.5.diff
 
 Previous version hides the rules. This one fixes that. The nawk stuff
 is, err, nasty, but the result should be acceptable:
 
  pf denied packets:
 > block drop log on rl0 proto tcp all [ Evaluations: 504986 Packets: 0 Bytes: 0 States: 0 ]
 > block drop log on rl0 all [ Evaluations: 18559 Packets: 427 Bytes: 140578 States: 0 ]
 
 -- 
 Clive Tong-I Lin | http://tongi.org | PGP KeyID: A008C03E
Responsible-Changed-From-To: freebsd-bugs->mlaier 
Responsible-Changed-By: mlaier 
Responsible-Changed-When: Wed Nov 24 18:00:03 GMT 2004 
Responsible-Changed-Why:  
pf care taker takes care ;) Looks very useful, thanks a lot! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=73959 
State-Changed-From-To: open->patched 
State-Changed-By: mlaier 
State-Changed-When: Wed Nov 24 18:42:02 GMT 2004 
State-Changed-Why:  
Committed to HEAD. PR will stay open until MFC in 2 weeks. Thanks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=73959 
State-Changed-From-To: patched->closed 
State-Changed-By: mlaier 
State-Changed-When: Wed Dec 8 00:38:18 GMT 2004 
State-Changed-Why:  
Done, thanks a lot! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=73959 
>Unformatted:
