From owner-freebsd-questions@freebsd.org Wed Mar 30 13:47:25 2016 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 97AB8AE336E for ; Wed, 30 Mar 2016 13:47:25 +0000 (UTC) (envelope-from jamie@freebsd.org) Received: from gritton.org (gritton.org [162.220.209.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "www.gritton.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 6D7B21BEB for ; Wed, 30 Mar 2016 13:47:25 +0000 (UTC) (envelope-from jamie@freebsd.org) Received: from gritton.org (gritton.org [162.220.209.3]) by gritton.org (8.15.2/8.15.2) with ESMTPS id u2UDlHvh008996 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 30 Mar 2016 07:47:17 -0600 (MDT) (envelope-from jamie@freebsd.org) Received: (from www@localhost) by gritton.org (8.15.2/8.15.2/Submit) id u2UDlGU5008995; Wed, 30 Mar 2016 07:47:16 -0600 (MDT) (envelope-from jamie@freebsd.org) X-Authentication-Warning: gritton.org: www set sender to jamie@freebsd.org using -f To: freebsd-questions@freebsd.org Subject: Re: Variables substitution in jail.conf X-PHP-Originating-Script: 0:rcube.php MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 30 Mar 2016 07:47:16 -0600 From: James Gritton Cc: Niklaas Baudet von Gersdorff Message-ID: <7fbd35d23c23fb734bc10643a06f2d78@gritton.org> X-Sender: jamie@freebsd.org User-Agent: Roundcube Webmail/1.1.2 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Mar 2016 13:47:25 -0000 Niklaas Baudet von Gersdorff wrote: > I am experimenting with jail.conf, trying to automate everything as > much as > I can. I would like to execute pfctl commands automatically once a jail > is > started or stopped; that is, adding the IP of the jail to a table that > passes > connection and deleting it again once it's no longer needed. This is my > jail.conf: > > host.hostname = "$name.box-fra-01.klaas"; > path = "/usr/local/jails/$name"; > ip4.addr = "lo1|10.15.$network.$id"; > ip6.addr = "vtnet0|2a00:XXX:XXXX:XXXX:X::$network:$id"; > mount = "/usr/local/jails/templates/base-10.2-RELEASE > /usr/local/jails/$name/ nullfs ro 0 0"; > mount += "/usr/local/jails/thinjails/$name > /usr/local/jails/$name/jail nullfs rw 0 0"; > mount.devfs; > > exec.start = "/bin/sh /etc/rc"; > exec.stop = "/bin/sh /etc/rc.shutdown"; > > exec.clean; > > www { > $id = 1; > $network = 1; > exec.poststart = "pfctl -t www -T add ${ip4.addr} {$ip6.addr}"; > exec.poststop = "pfctl -t www -T delete {$ip4.addr} > {$ip6.addr}"; > } > > However, I get an error that ip6 is not defined. I have already > realised that > pfctl will give an error (because ip{4,6}.addr includes {lo1,vtnet0}) > but what > I do not understand is why the parameter is not recognised. > > I also tried setting things up with additional variables my_ip4 and > my_ip6 but > that didn't work either. After reading jail.conf(5) I thought about > putting > everything in hierarchical jails but I am not sure whether that will > help to > make substitution work the way I want it to. > > I am happy for any advise. The problem is pretty simple - just a case of moving some brackets. In the definition of exec.poststart, you did ip4.addr right - ${ip4.addr}. But for ip6.addr, you moved the dollar sign inside the braces - {$ip6.addr}. That makes it look like the braces and the ".addr" are just part of the string, and only $ip6 is the variable to be substituted. So all you need is: exec.poststart = "pfctl -t www -T add ${ip4.addr} ${ip6.addr}"; exec.poststop = "pfctl -t www -T delete ${ip4.addr} ${ip6.addr}"; - Jamie