From owner-freebsd-rc@FreeBSD.ORG Fri Jul 1 19:56:22 2011 Return-Path: Delivered-To: freebsd-rc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0611F1065677 for ; Fri, 1 Jul 2011 19:56:22 +0000 (UTC) (envelope-from jpaetzel@freebsd.org) Received: from out3.smtp.messagingengine.com (out3.smtp.messagingengine.com [66.111.4.27]) by mx1.freebsd.org (Postfix) with ESMTP id C7C7A8FC19 for ; Fri, 1 Jul 2011 19:56:21 +0000 (UTC) Received: from compute4.internal (compute4.nyi.mail.srv.osa [10.202.2.44]) by gateway1.messagingengine.com (Postfix) with ESMTP id B8F6720CD4 for ; Fri, 1 Jul 2011 15:16:12 -0400 (EDT) Received: from frontend1.messagingengine.com ([10.202.2.160]) by compute4.internal (MEProxy); Fri, 01 Jul 2011 15:16:12 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=messagingengine.com; h=message-id:date:from:mime-version:to:subject:content-type; s=smtpout; bh=pHSHKeKUT1zXwoILh/vRp8//Uq0=; b=j4uPN/Dnd6yyFUPlK4AYrrj7Aqx2zgETyl62Y0oiaVFw706XNJipl92woJHq5yd8zDkQTk04ZkypuVH0roZimaRVijda0CMUGTHqd1iR1dynSsO8w8QRtRs7rgxfzcu0cH4wksiKA8dees5Bry7O84mHhI4TiNG0IjVxG1I+hvo= X-Sasl-enc: FKVQ7v+OdHvzKBBhTm+YoRK9iiyvaOE+A2A7w/RMftFI 1309547772 Received: from [10.10.1.125] (74-34-17-154.dr01.rsmt.mn.frontiernet.net [74.34.17.154]) by mail.messagingengine.com (Postfix) with ESMTPSA id 0747F403ED0 for ; Fri, 1 Jul 2011 15:16:11 -0400 (EDT) Message-ID: <4E0E1CFA.1080904@freebsd.org> Date: Fri, 01 Jul 2011 14:16:10 -0500 From: Josh Paezel Organization: FreeBSD User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.2.17) Gecko/20110430 Thunderbird/3.1.10 MIME-Version: 1.0 To: freebsd-rc@freebsd.org X-Enigmail-Version: 1.1.2 Content-Type: multipart/mixed; boundary="------------020709020807010009090108" Subject: Fwd: Commit approval requested X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Jul 2011 19:56:22 -0000 This is a multi-part message in MIME format. --------------020709020807010009090108 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 This patch is in production at an organization which uses both single and multiple pflog devices on a range of devices. (eg: it doesn't break current configurations) It allows multiple pflog devices as well as multiple ftp-proxy instances. The patch was submitted as a PR conf/158181 I've applied the patch to a HEAD svn co and regenerated the patch with svn diff from that. Proposed commit message: (obviously the reviewed by depends :) The ftp-proxy and pflogd daemons both allow for multiple instances to be run simultaneously. However, the rc scripts that control the startup of these daemons have no concept of multiple instances. ftp-proxy requires a seperate instance for each "type" of proxying that you would like to perform. For example, two instances are required to allow operation through NAT for a group of internal servers connecting out, and an external server connecting inbound using active-mode FTP. pf allows logging to different target pflog interfaces, for more granular logging of traffic. This requires multiple pflogd instances, one to read each pflog interface. Contributed by: Thomas Johnson Approved by: kib (mentor) Reviewed by: freebsd-rc@freebsd.org Sponsored by: Claimlynx, Inc. MFC: 1 week PR: conf/158181 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJODhz6AAoJEKFq1/n1feG27+gH/RVftmVHbrzO3m9oZw3t/yMX voyxygRmGUSJiLfJE7mhKcEyBiAx2CAYOYn9lPgT3ZVAaW+EozHjlnN3/tsEss1y DyvwmtPGnKCul1qNRy2N6vri/DmXNN0lpVjhyZno7AKFps3ExH7Dhlm5aku1j8Lq l4Dp9IzYjOW6XYnO6e/qzFMpSG0saG+DorEYU1kuxYBkN/D5kcYqBHnBAgxJJZZ2 H7K1j/3J82izwqj2gKeFjdLaeI8Fntvwsjt2bbvsFIPHCh/8rD4RC5yTKeO0dME/ uEQjsdG2BcMUYyOnJ6U8EyW/mjTkGiz+KWcVosj16njPSJ6lvap++62/wCZQKJE= =kcA5 -----END PGP SIGNATURE----- --------------020709020807010009090108 Content-Type: text/plain; name="pflog.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="pflog.diff" Index: share/man/man5/rc.conf.5 =================================================================== --- share/man/man5/rc.conf.5 (revision 223711) +++ share/man/man5/rc.conf.5 (working copy) @@ -880,6 +880,33 @@ This variable contains additional flags passed to the .Xr pflogd 8 program. +.It Va pflog_instances +.Pq Vt str +If logging to more than one +.Xr pflog 4 +interface is desired, +.Va pflog_instances +is set to the list of +.Xr pflogd 8 +instances that should be started at system boot time. If +.Va pflog_instances +is set, for each whitespace-seperated +.Ar element +in the list, +.Ao Ar element Ac Ns Va _dev +and +.Ao Ar element Ac Ns Va _logfile +elements are assumed to exist. +.Ao Ar element Ac Ns Va _dev +must contain the +.Xr pflog 4 +interface to be watched by the named +.Xr pflogd 8 +instance. +.Ao Ar element Ac Ns Va _logfile +must contain the name of the logfile that will be used by the +.Xr pflogd 8 +instance. .It Va ftpproxy_enable .Pq Vt bool Set to @@ -898,6 +925,19 @@ This variable contains additional flags passed to the .Xr ftp-proxy 8 program. +.It Va ftpproxy_instances +.Pq Vt str +Empty by default. If multiple instances of +.Xr ftp-proxy 8 +are desired at boot time, +.Va ftpproxy_instances +should contain a whitespace-seperated list of instance names. For each +.Ar element +in the list, a variable named +.Ao Ar element Ac Ns Va _flags +should be defined, containing the command-line flags to be passed to the +.Xr ftp-proxy 8 +instance. .It Va pfsync_enable .Pq Vt bool Set to Index: etc/rc.d/pflog =================================================================== --- etc/rc.d/pflog (revision 223711) +++ etc/rc.d/pflog (working copy) @@ -24,25 +24,41 @@ { load_kld pflog || return 1 - # set pflog0 interface to up state - if ! ifconfig pflog0 up; then - warn 'could not bring up pflog0.' + # set pflog_dev interface to up state + if ! ifconfig $pflog_dev up; then + warn "could not bring up $pflog_dev." return 1 fi # prepare the command line for pflogd - rc_flags="-f $pflog_logfile $rc_flags" + rc_flags="-f $pflog_logfile -i $pflog_dev $rc_flags" # report we're ready to run pflogd return 0 } +pflog_poststart() { + # Allow child pflogd to settle + sleep 0.10 + # More elegant(?) method for getting a unique pid + if [ -f /var/run/pflogd.pid ]; then + mv /var/run/pflogd.pid $pidfile + else + warn "/var/run/pflogd.pid does not exist. Too fast." + fi +} + pflog_poststop() { - if ! ifconfig pflog0 down; then - warn 'could not bring down pflog0.' + if ! ifconfig $pflog_dev down; then + warn "could not bring down $pflog_dev." return 1 fi + + if [ "$pflog_instances" ] && [ -n "$pflog_instances" ]; then + rm $pidfile + fi + return 0 } @@ -53,4 +69,33 @@ } load_rc_config $name -run_rc_command "$1" + +# Check if spawning multiple pflogd +echo "Starting pflogd: $pflog_instances" +if [ "$pflog_instances" ] && [ -n "$pflog_instances" ]; then + start_postcmd="pflog_poststart" + # Interate through requested instances. + for i in $pflog_instances; do + # Set required variables + eval pflog_dev=\$pflog_${i}_dev + eval pflog_logfile=\$pflog_${i}_logfile + eval pflog_flags=\$pflog_${i}_flags + # Check that required vars have non-zero length, warn if not. + if [ -z $pflog_dev ]; then + warn "pflog_dev not set" + continue + fi + if [ -z $pflog_logfile ]; then + warn "pflog_logfile not set" + continue + fi + # pflogd sets a pidfile, but the name is hardcoded. Concoct a + # unique pidfile name. + pidfile="/var/run/pflogd.$i.pid" + run_rc_command "$1" + done +else + # Typical case, spawn single instance only. + pflog_dev=${pflog_dev:-"pflog0"} + run_rc_command "$1" +fi Index: etc/rc.d/ftp-proxy =================================================================== --- etc/rc.d/ftp-proxy (revision 223711) +++ etc/rc.d/ftp-proxy (working copy) @@ -14,4 +14,62 @@ command="/usr/sbin/ftp-proxy" load_rc_config $name -run_rc_command "$1" + +# +# manage_pid argument +# Create or remove a pidfile manually, for daemons that can't be bothered +# to do it themselves. Takes one argument, which is the argument provided +# to the rc script. The pidfile will be named /var/run/<$name>.pid, +# unless $pidfile is defined. +# +# The method used to determine the pid is rather hacky; grep ps output to +# find '$procname|$command', then grep for ${name}_flags. If at all +# possible, use another method if at all possible, to avoid that dirty- +# code feeling. +# +manage_pid() { + local search_string ps_pid + case $1 in + *start) + cmd_string=`basename ${procname:-${command}}` + eval flag_string=\"\$${name}_flags\" + # Determine the pid. + ps_pid=`ps ax -o pid= -o command= | grep $cmd_string | grep -e "$flag_string" | grep -v grep | awk '{ print $1 }'` + # Write the pidfile depending on $pidfile status. + echo $ps_pid > ${pidfile:-"/var/run/$name.pid"} + ;; + stop) + rm $pidfile + ;; + esac +} + +# Allow ftp-proxy to start up in two different ways. The typical behavior +# is to start up one instance of ftp-proxy by setting ftpproxy_enable and +# ftpproxy_flags. The alternate behavior allows multiple instances of ftp- +# proxy to be started, allowing different types of proxy behavior. To use the +# new behavior, a list of instances must be defined, and a list of flags for +# each instance. For example, if we want to start two instances of ftp-proxy, +# foo and bar, we would set the following vars. +# ftpproxy_enable="YES" +# ftpproxy_instances="foo bar" +# ftpproxy_foo="" +# ftpproxy_bar="" +# +# Starting more than one ftp-proxy? +if [ "$ftpproxy_instances" ] && [ -n "${ftpproxy_instances}" ]; then + # Iterate through instance list. + for i in $ftpproxy_instances; do + #eval ftpproxy_${i}_flags=\$ftpproxy_${i} + #eval name=ftpproxy_${i} + # Set flags for this instance. + eval ftpproxy_flags=\$ftpproxy_${i} + # Define a unique pid file name. + pidfile="/var/run/ftp-proxy.$i.pid" + run_rc_command "$1" + manage_pid $1 + done +else + # Traditional single-instance behavior + run_rc_command "$1" +fi --------------020709020807010009090108--