Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Mar 2016 12:57:23 -0600
From:      James Gritton <jamie@freebsd.org>
To:        freebsd-questions@freebsd.org
Cc:        Niklaas Baudet von Gersdorff <stdin@niklaas.eu>
Subject:   Re: Variables substitution in jail.conf
Message-ID:  <859c4fbee2fd75910dcc4b85dd2c7f8e@gritton.org>
In-Reply-To: <7fbd35d23c23fb734bc10643a06f2d78@gritton.org>
References:  <7fbd35d23c23fb734bc10643a06f2d78@gritton.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Niklaas Baudet von Gersdorff <stdin@niklaas.eu> wrote::
> James Gritton [2016-03-30 07:47 -0600] :
> > Niklaas Baudet von Gersdorff <stdin@niklaas.eu> wrote:
> >
> > >     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}";
> > > }
> 
> > 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}";
> 
> Indeed, that was it. Thanks. Four eyes see more than two. Anyway, that 
> leaves
> me with the problem that the variables expand to lo1|something and
> vtnet0|something. I tried to set custom variables but that's not 
> possible, is
> it?

Sure, you've already got some custom variables in the jail definition,
$id and $network.  You can also have some on the global side.
Something like:

     $addr4 = "10.15.$network.$id";
     $addr6 = "2a00:XXX:XXXX:XXXX:X::$network:$id";
     ip4.addr = "lo1|$addr4";
     ip6.addr = "vnet0|$addr6";

     www {
         $id = 1;
         $network = 1;
         exec.poststart = "pfctl -t www -T add $addr4 $addr6"
         exec.poststop = "pfctl -t www -T delete $addr4 $addr6"
     }

I haven't tested that, so I'm not sure it's 100% correct, but something 
along
those lines should work.

- Jamie



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?859c4fbee2fd75910dcc4b85dd2c7f8e>