Sophie

Sophie

distrib > Mandriva > mes5 > x86_64 > by-pkgid > 45723c51178a73df679c2a8284d8eeff > files > 41

shorewall-doc-4.0.15-0.2mdvmes5.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Shorewall-perl</title><link rel="stylesheet" href="html.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /></head><body><div class="article" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="id257527"></a>Shorewall-perl</h2></div><div><div class="authorgroup"><div class="author"><h3 class="author"><span class="firstname">Tom</span> <span class="surname">Eastep</span></h3></div></div></div><div><p class="copyright">Copyright © 2007 Thomas M. Eastep</p></div><div><div class="legalnotice"><a id="id292634"></a><p>Permission is granted to copy, distribute and/or modify this
      document under the terms of the GNU Free Documentation License, Version
      1.2 or any later version published by the Free Software Foundation; with
      no Invariant Sections, with no Front-Cover, and with no Back-Cover
      Texts. A copy of the license is included in the section entitled
      “<span class="quote"><a class="ulink" href="GnuCopyright.htm" target="_self">GNU Free Documentation
      License</a></span>”.</p></div></div><div><p class="pubdate">2008/12/15</p></div></div><hr /></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#What">Shorewall-perl - What is it?</a></span></dt><dt><span class="section"><a href="#DownSide">Shorewall-perl - The down side</a></span></dt><dd><dl><dt><span class="section"><a href="#Incompatibilities">Incompatibilities</a></span></dt><dt><span class="section"><a href="#PerlDep">Dependence on Perl</a></span></dt></dl></dd><dt><span class="section"><a href="#Prerequisites">Shorewall-perl - Prerequisites</a></span></dt><dt><span class="section"><a href="#Install">Shorewall-perl - Installation</a></span></dt><dt><span class="section"><a href="#Using">Using Shorewall-perl</a></span></dt><dt><span class="section"><a href="#Modules">The Shorewall Perl Modules</a></span></dt><dd><dl><dt><span class="section"><a href="#compiler.pl">/usr/share/shorewall-perl/compiler.pl</a></span></dt><dt><span class="section"><a href="#Compiler">Shorewall::Compiler</a></span></dt><dd><dl><dt><span class="section"><a href="#Compiler-4.0">Shorewall 4.0</a></span></dt><dt><span class="section"><a href="#id302969">Shorewall 4.2 and Later</a></span></dt></dl></dd><dt><span class="section"><a href="#Chains">Shorewall::Chains</a></span></dt><dt><span class="section"><a href="#Config">Shorewall::Config</a></span></dt></dl></dd></dl></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="What"></a>Shorewall-perl - What is it?</h2></div></div></div><p>Shorewall-perl is a companion product to Shorewall.</p><p>Shorewall-perl contains a re-implementation of the Shorewall
    compiler written in Perl. The advantages of using Shorewall-perl over
    Shorewall-shell (the shell-based compiler included in earlier Shorewall
    3.x releases) are:</p><div class="itemizedlist"><ul type="disc"><li><p>The Shorewall-perl compiler is much faster.</p></li><li><p>The script generated by the compiler uses
        <span class="command"><strong>iptables-restore</strong></span> to instantiate the Netfilter
        configuration. So it runs much faster than the script generated by the
        Shorewall-shell compiler.</p></li><li><p>The Shorewall-perl compiler does more thorough checking of the
        configuration than the Shorewall-shell compiler does.</p></li><li><p>The error messages produced by the compiler are better, more
        consistent and always include the file name and line number where the
        error was detected.</p></li><li><p>Going forward, the Shorewall-perl compiler will get all
        enhancements; the Shorewall-shell compiler will only get those
        enhancements that are easy to retrofit.</p></li></ul></div></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="DownSide"></a>Shorewall-perl - The down side</h2></div></div></div><p>While there are advantages to using Shorewall-perl, there are also
    disadvantages.</p><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="Incompatibilities"></a>Incompatibilities</h3></div></div></div><p>There are a number of incompatibilities between the Shorewall-perl
      compiler and the earlier one.</p><div class="orderedlist"><ol type="1"><li><p>The Perl-based compiler requires the following capabilities in
          your kernel and iptables.</p><div class="itemizedlist"><ul type="disc"><li><p>addrtype match (Restriction relaxed in Shorewall-perl
              4.0.1)</p></li><li><p>multiport match (will not be relaxed)</p></li></ul></div><p>These capabilities are in current distributions.</p></li><li><p>Now that Netfilter has features to deal reasonably with port
          lists, I see no reason to duplicate those features in Shorewall. The
          Shorewall-shell compiler goes to great pain (in some cases) to break
          very long port lists ( &gt; 15 where port ranges in lists count as
          two ports) into individual rules. In the new compiler, I'm avoiding
          the ugliness required to do that. The new compiler just generates an
          error if your list is too long. It will also produce an error if you
          insert a port range into a port list and you don't have extended
          multiport support.</p></li><li><p>BRIDGING=Yes is not supported. The kernel code necessary to
          support this option was removed in Linux kernel 2.6.20. <a class="ulink" href="bridge-Shorewall-perl.html" target="_self">Alternative bridge support</a>
          is provided by Shorewall-perl.</p></li><li><p>The BROADCAST column in the interfaces file is essentially
          unused if your kernel/iptables has Address Type Match support. If
          that support is present and you enter anything in this column but
          '-' or 'detect', you will receive a warning.</p></li><li><p>The 'refresh' command is now similar to restart with the
          exceptions that:</p><div class="itemizedlist"><ul type="disc"><li><p>The command fails if Shorewall is not running.</p></li><li><p>A directory name cannot be specified in the
              command.</p></li><li><p>The refresh command does not alter the Netfilter
              configuration except for the static blacklist.</p></li></ul></div></li><li><p>With the shell-based compiler, extension scripts were copied
          into the compiled script and executed at run-time. In many cases,
          this approach doesn't work with Shorewall Perl because (almost) the
          entire rule set is built by the compiler. As a result,
          Shorewall-perl runs some extension scripts at compile-time rather
          than at run-time. Because the compiler is written in Perl, your
          extension scripts from earlier versions will no longer work.</p><p>The following table summarizes when the various extension
          scripts are run:</p><div class="informaltable"><table border="1"><colgroup><col /><col /><col /></colgroup><tbody><tr><td><span class="bold"><strong>Compile-time (Must be written
                    in Perl)</strong></span></td><td><span class="bold"><strong>Run-time</strong></span></td><td><span class="bold"><strong>Eliminated</strong></span></td></tr><tr><td>initdone</td><td>clear</td><td>continue</td></tr><tr><td>maclog</td><td>initdone</td><td> </td></tr><tr><td>Per-chain (including those associated with
                    actions)</td><td>start</td><td> </td></tr><tr><td> </td><td>started</td><td> </td></tr><tr><td> </td><td>stop</td><td> </td></tr><tr><td> </td><td>stopped</td><td> </td></tr><tr><td> </td><td>tcclear</td><td> </td></tr></tbody></table></div><p>Compile-time extension scripts are executed using the Perl
          'eval `cat &lt;file&gt;`' mechanism. Be sure that each script
          returns a 'true' value; otherwise, the compiler will assume that the
          script failed and will abort the compilation.</p><p>When a script is invoked, the <span class="bold"><strong>$chainref</strong></span> scalar variable will usually hold a
          reference to a chain table entry.</p><table class="simplelist" border="0" summary="Simple list"><tr><td><span class="bold"><strong>$chainref-&gt;{name}</strong></span>
            contains the name of the chain</td></tr><tr><td><span class="bold"><strong>$chainref-&gt;{table}</strong></span>
            holds the table name</td></tr></table><p>To add a rule to the chain:</p><table class="simplelist" border="0" summary="Simple list"><tr><td>add_rule $chainref,
            <em class="replaceable"><code>the-rule</code></em></td></tr></table><p>Where</p><table class="simplelist" border="0" summary="Simple list"><tr><td><em class="replaceable"><code>the rule</code></em> is a scalar argument
            holding the rule text. Do not include "-A
            <em class="replaceable"><code>chain-name</code></em>"</td></tr></table><p>Example:</p><table class="simplelist" border="0" summary="Simple list"><tr><td>add_rule $chainref, '-j ACCEPT';</td></tr></table><p>To insert a rule into the chain:</p><table class="simplelist" border="0" summary="Simple list"><tr><td>insert_rule $chainref, <em class="replaceable"><code>rulenum</code></em>,
            <em class="replaceable"><code>the-rule</code></em></td></tr></table><p>The log_rule_limit function works like it does in the shell
          compiler with three exceptions:</p><div class="itemizedlist"><ul type="disc"><li><p>You pass the chain reference rather than the name of the
              chain.</p></li><li><p>The commands are 'add' and 'insert' rather than '-A' and
              '-I'.</p></li><li><p>There is only a single "pass as-is to iptables" argument
              (so you must quote that part</p></li></ul></div><p>Example:</p><pre class="programlisting">    log_rule_limit
              'info' , 
              $chainref , 
              $chainref-&gt;{name},
              'DROP' , 
              '',    #Limit
              '' ,   #Log tag
              'add'
              '-p tcp ';         </pre><p>Here is an example of an actual initdone script used with
          Shorewall 3.4:</p><pre class="programlisting">run_iptables -t mangle -I PREROUTING -p esp -j MARK --set-mark 0x50
run_iptables -t filter -I INPUT -p udp --dport 1701 -m mark --mark 0x50 -j ACCEPT
run_iptables -t filter -I OUTPUT -p udp --sport 1701 -j ACCEPT
</pre><p>Here is the corresponding script used with
          Shorewall-perl:</p><pre class="programlisting">use Shorewall::Chains;

insert_rule $mangle_table-&gt;{PREROUTING}, 1, "-p esp -j MARK --set-mark 0x50";
insert_rule $filter_table-&gt;{INPUT},      1, "-p udp --dport 1701 -m mark --mark 0x50 -j ACCEPT";
insert_rule $filter_table-&gt;{OUTPUT},     1, "-p udp --sport 1701 -j ACCEPT";

1;</pre><p>The initdone script is unique because the $chainref variable
          is not set before the script is called. The above script illustrates
          how the $mangle_table, $filter_table, and $nat_table references can
          be used to add or insert rules in arbitrary chains.</p></li><li><p>The <code class="filename">/etc/shorewall/tos</code> file now has
          zone-independent SOURCE and DEST columns as do all other files
          except the rules and policy files.</p><p>The SOURCE column may be one of the following:</p><table class="simplelist" border="0" summary="Simple list"><tr><td>[<span class="command"><strong>all</strong></span>:]&lt;<em class="replaceable"><code>address</code></em>&gt;[,...]</td></tr><tr><td>[<span class="command"><strong>all</strong></span>:]&lt;<em class="replaceable"><code>interface</code></em>&gt;[:&lt;<em class="replaceable"><code>address</code></em>&gt;[,...]]</td></tr><tr><td><span class="command"><strong>$FW</strong></span>[:&lt;<em class="replaceable"><code>address</code></em>&gt;[,...]]</td></tr></table><p>The DEST column may be one of the following:</p><table class="simplelist" border="0" summary="Simple list"><tr><td>[<span class="command"><strong>all</strong></span>:]&lt;<em class="replaceable"><code>address</code></em>&gt;[,...]</td></tr><tr><td>[<span class="command"><strong>all</strong></span>:]&lt;<em class="replaceable"><code>interface</code></em>&gt;[:&lt;<em class="replaceable"><code>address</code></em>&gt;[,...]]</td></tr></table><p>This is a permanent change. The old zone-based rules have
          never worked right and this is a good time to replace them. I've
          tried to make the new syntax cover the most common cases without
          requiring change to existing files. In particular, it will handle
          the tos file released with Shorewall 1.4 and earlier.</p></li><li><p>Shorewall-perl insists that ipset names begin with a letter
          and be composed of alphanumeric characters and underscores (_). When
          used in a Shorewall configuration file, the name must be preceded by
          a plus sign (+) as with the shell-based compiler.</p><p>Shorewall is now out of the ipset load/reload business. With
          scripts generated by the Perl-based Compiler, the Netfilter rule set
          is never cleared. That means that there is no opportunity for
          Shorewall to load/reload your ipsets since that cannot be done while
          there are any current rules using ipsets.</p><p>So:</p><div class="orderedlist"><ol type="I"><li><p>Your ipsets must be loaded before Shorewall starts. You
              are free to try to do that with the following code in
              <code class="filename">/etc/shorewall/init (it works for me; your mileage may
              vary)</code>:</p><pre class="programlisting">if [ "$COMMAND" = start ]; then
    ipset -U :all: :all:
    ipset -U :all: :default:
    ipset -F
    ipset -X
    ipset -R &lt; /etc/shorewall/ipsets
fi</pre><p>The file <code class="filename">/etc/shorewall/ipsets</code> will
              normally be produced using the <span class="command"><strong>ipset -S</strong></span>
              command.</p><p>The above will work most of the time but will fail in a
              <span class="command"><strong>shorewall stop</strong></span> - <span class="command"><strong>shorewall
              start</strong></span> sequence if you use ipsets in your routestopped
              file (see below).</p></li><li><p>Your ipsets may not be reloaded until Shorewall is stopped
              or cleared.</p></li><li><p>If you specify ipsets in your routestopped file then
              Shorewall must be cleared in order to reload your ipsets.</p></li></ol></div><p>As a consequence, scripts generated by the Perl-based compiler
          will ignore <code class="filename">/etc/shorewall/ipsets</code> and will
          issue a warning if you set SAVE_IPSETS=Yes in
          <code class="filename">shorewall.conf</code>.</p></li><li><p>Because the configuration files (with the exception of
          <code class="filename">/etc/shorewall/params</code>) are now processed by the
          Shorewall-perl compiler rather than by the shell, only the basic
          forms of Shell expansion ($variable and ${variable}) are supported.
          The more exotic forms such as ${variable:=default} are not
          supported. Both variables defined in /etc/shorewall/params and
          environmental variables (exported by the shell) can be used in
          configuration files.</p></li><li><p>USE_ACTIONS=No is not supported. That option is intended to
          minimize Shorewall's footprint in embedded applications. As a
          consequence, Default Macros are not supported.</p></li><li><p>DELAYBLACKLISTLOAD=Yes is not supported. The entire rule set
          is atomically loaded with one execution of
          <span class="command"><strong>iptables-restore</strong></span>.</p></li><li><p>MAPOLDACTIONS=Yes is not supported. People should have
          converted to using macros by now.</p></li><li><p>The pre Shorewall-3.0 format of the zones file is not
          supported (IPSECFILE=ipsec); neither is the
          <code class="filename">/etc/shorewall/ipsec</code> file.</p></li><li><p>BLACKLISTNEWONLY=No is not permitted with FASTACCEPT=Yes. This
          combination doesn't work in previous versions of Shorewall so the
          Perl-based compiler simply rejects it.</p></li><li><p>Shorewall-perl has a single rule generator that is used for
          all rule-oriented files. So it is important that the syntax is
          consistent between files.</p><p>With shorewall-shell, there is a special syntax in the SOURCE
          column of /etc/shorewall/masq to designate "all traffic entering the
          firewall on this interface except...".</p><p>Example:</p><pre class="programlisting">#INTERFACE       SOURCE                  ADDRESSES
eth0             eth1!192.168.4.9        ...</pre><p>Shorewall-perl
          uses syntax that is consistent with the rest of
          Shorewall:</p><pre class="programlisting">#INTERFACE       SOURCE                  ADDRESSES
eth0             eth1:!192.168.4.9       ...</pre></li><li><p>The 'allowoutUPnP' built-in action is no longer supported. In
          kernel 2.6.14, the Netfilter team have removed support for '-m owner
          --owner-cmd' which that action depended on.</p></li><li><p>The PKTTYPE option is ignored by Shorewall-perl.
          Shorewall-perl 4.0.0 requires Address type match. Shorewall-perl
          versions 4.0.1 and later will use Address type match if it is
          available; otherwise, they will behave as if PKTTYPE=No had been
          specified.</p></li><li><p>Shorewall-perl detects dead policy file entries that result
          when an entry is masked by an earlier more general entry.</p><p>Example:</p><pre class="programlisting">#SOURCE DEST     POLICY    LOG LEVEL
all     all      REJECT    info
loc     net      ACCEPT</pre></li><li><p>In the SOURCE column of the rules file, when an interface name
          is followed by a list of IP addresses, the behavior of
          Shorewall-perl differs from that of Shorewall-shell.</p><p>Example:</p><pre class="programlisting">#ACTION SOURCE                                 DEST PROTO DEST
#                                                         PORT(S)
ACCEPT  loc:eth0:192.168.1.3,192.168.1.5       $FW  tcp   22</pre><p>With
          Shorewall-shell, this rule accepts SSH connection to the firewall
          from 192.168.1.3 through eth0 or from 192.168.1.5 through any
          interface. With Shorewall-perl, the rule accepts SSH connections
          through eth0 from 192.168.1.3 and through eth0 from 192.168.1.5.
          Shorewall-shell supports this syntax that gives the same result as
          Shorewall-perl.</p><pre class="programlisting">#ACTION SOURCE                                 DEST PROTO DEST
#                                                         PORT(S)
ACCEPT loc:eth0:192.168.1.3,eth0:192.168.1.5   $fw  tcp   22</pre><p>
          Shorewall-perl does not support this alternative syntax.</p></li></ol></div></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="PerlDep"></a>Dependence on Perl</h3></div></div></div><p>Shorewall-perl is dependent on Perl (see the next section) which
      has a large disk footprint. This makes Shorewall-perl less desirable in
      an embedded environment.</p></div></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="Prerequisites"></a>Shorewall-perl - Prerequisites</h2></div></div></div><div class="itemizedlist"><ul type="disc"><li><p>Perl (I use Perl 5.8.8 but other 5.8 or later versions should
        work fine)</p></li><li><p>Perl Cwd Module</p></li><li><p>Perl File::Basename Module</p></li><li><p>Perl File::Temp Module</p></li><li><p>Perl Getopt::Long Module</p></li><li><p>Perl Carp Module</p></li><li><p>Perl FindBin Module (Shorewall 4.0.3 and later)</p></li><li><p>Perl Scalar::Util Module (Shorewall 4.0.6 and later)</p></li></ul></div></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="Install"></a>Shorewall-perl - Installation</h2></div></div></div><p>Either</p><pre class="programlisting"><span class="command"><strong>tar -jxf shorewall-perl-4.0.x.tar.bz2</strong></span>
<span class="command"><strong>cd shorewall-perl-4.0.x</strong></span>
<span class="command"><strong>./install.sh</strong></span></pre><p>or</p><pre class="programlisting"><span class="command"><strong>rpm -ivh shorewall-perl-4.0.x.noarch.rpm</strong></span></pre></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="Using"></a>Using Shorewall-perl</h2></div></div></div><p>If you only install one compiler, then that compiler will be
    used.</p><p>If you install both compilers, then the compiler actually used
    depends on the SHOREWALL_COMPILER setting in
    <code class="filename">shorewall.conf</code>. The value of this option can be
    either 'perl' or 'shell'.</p><p>If you add 'SHOREWALL_COMPILER=perl' to
    <code class="filename">/etc/shorewall/shorewall.conf</code> then by default, the
    new compiler will be used on the system. If you add it to
    <code class="filename">shorewall.conf</code> in a separate directory (such as a
    Shorewall-lite export directory) then the new compiler will only be used
    when you compile from that directory.</p><p>If you only install one compiler, it is suggested that you do not
    set SHOREWALL_COMPILER.</p><p>You may also select the compiler to use on the command line using
    the 'C option:</p><table class="simplelist" border="0" summary="Simple list"><tr><td>'-C shell' means use the shell compiler</td></tr><tr><td>'-C perl' means use the perl compiler</td></tr></table><p>The -C option overrides the setting in
    shorewall.conf.</p><p>Example:</p><pre class="programlisting"><span class="command"><strong>shorewall restart -C perl</strong></span></pre><p>When the Shorewall-perl compiler has been selected, the
    <code class="filename">params</code> file is processed twice, the second time using
    the <code class="option">-a</code> option which causes all variables set within the
    file to be exported automatically by the shell. The Shorewall-perl
    compiler uses the current environmental variables to perform variable
    expansion within the other Shorewall configuration files.</p></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="Modules"></a>The Shorewall Perl Modules</h2></div></div></div><p>Shorewall's Perl modules are installed in
    /usr/share/shorewall-perl/Shorewall and the names of the packages are of
    the form Shorewall::<em class="firstterm">name</em>. So by using this
    directive</p><pre class="programlisting">use lib '/usr/share/shorewall-perl';</pre><p>You can then load the modules via normal Perl use statements.</p><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="compiler.pl"></a>/usr/share/shorewall-perl/compiler.pl</h3></div></div></div><p>While the compiler is normally run indirectly using
      /sbin/shorewall, it can be run directly as well.</p><pre class="programlisting"><span class="command"><strong>compiler.pl</strong></span> [ <span class="emphasis"><em>option</em></span> ... ] [ <span class="emphasis"><em>filename</em></span> ]</pre><p>If a <span class="emphasis"><em>filename</em></span> is given, then the
      configuration will be compiled and the output placed in the named file.
      If <span class="emphasis"><em>filename</em></span> is not given, then the configuration
      will simply be syntax checked.</p><p>Options are:</p><table class="simplelist" border="0" summary="Simple list"><tr><td><span class="command"><strong>-v</strong></span>&lt;<span class="emphasis"><em>verbosity</em></span>&gt;</td></tr><tr><td><span class="command"><strong>--verbosity=</strong></span>&lt;<span class="emphasis"><em>verbosity</em></span>&gt;</td></tr></table><p>The &lt;<span class="emphasis"><em>verbosity</em></span>&gt; is a number
      between 0 and 2 and corresponds to the VERBOSITY setting in
      <code class="filename">shorewall.conf</code>. This setting controls the verbosity
      of the compiler itself.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>The VERBOSITY setting in the
          <code class="filename">shorewall.conf</code> file read by the compiler will
          determine the default verbosity for the compiled program.</p></div><table class="simplelist" border="0" summary="Simple list"><tr><td><span class="bold"><strong>-e</strong></span></td></tr><tr><td><span class="bold"><strong>--export</strong></span></td></tr></table><p>If given, the configuration will be compiled for export
      to another system.</p><table class="simplelist" border="0" summary="Simple list"><tr><td><span class="bold"><strong>-d</strong></span>
          &lt;<span class="emphasis"><em>directory</em></span>&gt;</td></tr><tr><td><span class="bold"><strong>--directory=</strong></span>&lt;<span class="emphasis"><em>directory</em></span>&gt;</td></tr></table><p>If this option is omitted, the configuration in
      /etc/shorewall is compiled/checked. Otherwise, the configuration in the
      named directory will be compiled/checked.</p><table class="simplelist" border="0" summary="Simple list"><tr><td><span class="bold"><strong>-t</strong></span></td></tr><tr><td><span class="bold"><strong>--timestamp</strong></span></td></tr></table><p>If given, each progress message issued by the compiler
      and by the compiled program will be timestamped.</p><table class="simplelist" border="0" summary="Simple list"><tr><td><span class="bold"><strong>--debug</strong></span></td></tr></table><p>If given, when a warning or error message is issued, it
      is supplemented with a stack trace. Requires the Carp Perl
      module.</p><table class="simplelist" border="0" summary="Simple list"><tr><td><span class="bold"><strong>--refresh=</strong></span>&lt;<span class="emphasis"><em>chainlist</em></span>&gt;</td></tr></table><p>If given, the compiled script's 'refresh' command will
      refresh the chains in the comma-separated
      &lt;<span class="emphasis"><em>chainlist</em></span>&gt; rather than
      'blacklst'.</p><table class="simplelist" border="0" summary="Simple list"><tr><td><span class="bold"><strong>--log</strong></span>=&lt;logfile&gt;</td></tr></table><p>Added in Shorewall 4.2. If given, compiler will log to this file
      provider that --log_verbosity is &gt; -1.</p><table class="simplelist" border="0" summary="Simple list"><tr><td><span class="bold"><strong>--log_verbosity</strong></span>=-1|0|1|2</td></tr></table><p>Added in Shorewall 4.1. If given, controls the verbosity of
      logging to the log specified by the --log parameter.</p><p>Example (compiles the configuration in the current directory
      generating a script named 'firewall' and using VERBOSITY
      2).</p><pre class="programlisting"><span class="bold"><strong>/usr/share/shorewall-perl/compiler.pl -v 2 -d . firewall</strong></span></pre><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>The Perl-based compiler does not process
          <code class="filename">/etc/shorewall/params</code>. To include definitions
          in that file, you would need to do something like the
          following:</p><pre class="programlisting"><span class="command"><strong>. /usr/share/shorewall/lib.base  # In case /etc/shorewall/params does INCLUDE
set -a                           # Export all variables set in /etc/shorewall/params
. /etc/shorewall/params
set +a
/usr/share/shorewall-perl/compiler.pl ...</strong></span></pre></div></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="Compiler"></a>Shorewall::Compiler</h3></div></div></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h4 class="title"><a id="Compiler-4.0"></a>Shorewall 4.0</h4></div></div></div><pre class="programlisting"> use lib '/usr/share/shorewall-perl';
 use Shorewall::Compiler;
        
 compiler $filename, $directory, $verbose, $options $chains</pre><p>Arguments
        to the compiler are:</p><div class="variablelist"><dl><dt><span class="term">$filename</span></dt><dd><p>Name of the compiled script to be created. If the
              arguments evaluates to false, the configuration is syntax
              checked.</p></dd><dt><span class="term">$directory</span></dt><dd><p>The directory containing the configuration. If passed as
              '', then <code class="filename">/etc/shorewall/</code>
              is assumed.</p></dd><dt><span class="term">$verbose</span></dt><dd><p>The verbosity level that the compiler will run with
              (0-2).</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>The VERBOSITY setting in the
                  <code class="filename">shorewall.conf</code> file read by the
                  compiler will determine the default verbosity for the
                  compiled program.</p></div></dd><dt><span class="term">$options</span></dt><dd><p>A bitmap of options. Shorewall::Compiler exports three
              constants to help building this argument:</p><table class="simplelist" border="0" summary="Simple list"><tr><td>EXPORT = 0x01</td></tr><tr><td>TIMESTAMP = 0x02</td></tr><tr><td>DEBUG = 0x04</td></tr></table></dd><dt><span class="term">$chains</span></dt><dd><p>A comma-separated list of chains that the generated
              script's 'refresh' command will reload. If passed as an empty
              string, then 'blacklist' is assumed.</p></dd></dl></div><p>The compiler raises an exception with 'die' if it encounters an
        error; $@ contains the 'ERROR' messages describing the problem. The
        compiler function can be called repeatedly with different
        inputs.</p></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h4 class="title"><a id="id302969"></a>Shorewall 4.2 and Later</h4></div></div></div><p>To avoid a proliferation of parameters to
        Shorewall::Compiler::compile(), that function has been changed to use
        named parameters. Parameter names are:</p><div class="variablelist"><dl><dt><span class="term">object</span></dt><dd><p>Object file. If omitted or '', the configuration is syntax
              checked.</p></dd><dt><span class="term">directory</span></dt><dd><p>Directory. If omitted or '', configuration files are
              located using CONFIG_PATH. Otherwise, the directory named by
              this parameter is searched first.</p></dd><dt><span class="term">verbosity</span></dt><dd><p>Verbosity; range -1 to 2</p></dd><dt><span class="term">timestamp</span></dt><dd><p>0|1 -- timestamp messages.</p></dd><dt><span class="term">debug</span></dt><dd><p>0|1 -- include stack trace in warning/error
              messages.</p></dd><dt><span class="term">export</span></dt><dd><p>0|1 -- compile for export.</p></dd><dt><span class="term">chains</span></dt><dd><p>List of chains to be reloaded by 'refresh'</p></dd><dt><span class="term">log</span></dt><dd><p>File to log compiler messages to.</p></dd><dt><span class="term">log_verbosity</span></dt><dd><p>Log Verbosity; range -1 to 2.</p></dd></dl></div><p>Those parameters that are supplied must have defined values.
        Defaults are: </p><table class="simplelist" border="0" summary="Simple list"><tr><td>object '' ('check' command)</td></tr><tr><td>directory ''</td></tr><tr><td>verbosity 1</td></tr><tr><td>timestamp 0</td></tr><tr><td>debug 0</td></tr><tr><td>export 0</td></tr><tr><td>chains ''</td></tr><tr><td>log ''</td></tr><tr><td>log_verbosity -1</td></tr></table><p>Example: </p><pre class="programlisting">use lib '/usr/share/shorewall-perl/';
use Shorewall::Compiler;

compiler( object =&gt; '/root/firewall', log =&gt; '/root/compile.log', log_verbosity =&gt; 2 ); </pre></div></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="Chains"></a>Shorewall::Chains</h3></div></div></div><pre class="programlisting">use lib '/usr/share/shorewall-perl';
use Shorewall::Chains;

my $chainref1 = chain_new $table, $name1;
add_rule $chainref1, $rule;
insert_rule $chainref1, $ordinal, $rule;
my $chainref2 = new_manual_chain $name3;
my $chainref3 = ensure_manual_chain $name;
log_rule_limit $level, $chainref3, $name, $disposition, $limit, $tag, $command, $predicates;


my $chainref4 = $chain_table{$table}{$name};
my $chainref5 = $nat_table{$name};
my $chainref6 = $mangle_table{$name};
my $chainref7 = $filter_table{$name};</pre><p>Shorewall::Chains is
      Shorewall-perl's interface to iptables/netfilter. It creates a
      <em class="firstterm">chain table</em> (%chain_table) which is populated as
      the various tables are processed. The table (actually a hash) is
      two-dimensional with the first dimension being the Netfilter table name
      (raw, mangle, nat and filter) and the second dimension being the chain
      name. Each table is a hash reference -- the hash defines the attributes
      of the chain. See the large comment at the beginning of the module
      (<code class="filename">/usr/share/shorewall-perl/Shorewall/Chains.pm</code>).</p><p>The module export the chain table along with three hash references
      into the table:<code class="literal"></code></p><div class="variablelist"><dl><dt><span class="term">$nat_table</span></dt><dd><p>Reference to the 'nat' portion of the table
            ($chain_table{nat}). This is a hash whose key is the chain
            name.</p></dd><dt><span class="term">$mangle_table</span></dt><dd><p>Reference to the 'mangle' portion of the table
            ($chain_table{mangle}). This is a hash whose key is the chain
            name.</p></dd><dt><span class="term">$filter</span></dt><dd><p>Reference to the 'filter' portion of the table
            ($chain_table{filter}). This is a hash whose key is the chain
            name.</p></dd></dl></div><p>You can create a new chain in any of the tables using <span class="bold"><strong>new_chain()</strong></span>. Arguments to the function
      are:</p><div class="variablelist"><dl><dt><span class="term">$table</span></dt><dd><p>'nat', 'mangle', or 'filter'.</p></dd><dt><span class="term">$name</span></dt><dd><p>Name of the chain to create.</p></dd></dl></div><p>The function creates a hash at $chain_table{$table}{$name} and
      populates the hash with default values. A reference to the hash is
      returned.</p><p>Each chain table entry includes a list of rules to be added to the
      chain. These rules are written to the iptables-restore input file when
      the resulting script is executed. To append a rule to that list, call
      <span class="bold"><strong>add_rule()</strong></span>. Arguments are:</p><div class="variablelist"><dl><dt><span class="term">$chainref</span></dt><dd><p>A reference to the chain table entry.</p></dd><dt><span class="term">$rule</span></dt><dd><p>The rule to add. Do not include the leading '-A ' in this
            argument -- it will be supplied by the function.</p></dd></dl></div><p>To insert a rule into that list, call <span class="bold"><strong>insert_rule()</strong></span>. Arguments are:</p><div class="variablelist"><dl><dt><span class="term">$chainref</span></dt><dd><p>A reference to the chain table entry.</p></dd><dt><span class="term">$ordinal</span></dt><dd><p>The position of the inserted rule in the list. A value of 1
            inserts the rule at the head of the list, a value of 2 places the
            rule second in the list, and so on.</p></dd><dt><span class="term">$rule</span></dt><dd><p>The rule to add. Do not include the leading '-I' in this
            argument -- it will be supplied by the function.</p></dd></dl></div><p>To create a <a class="ulink" href="ManualChains.html" target="_self">manual chain</a>,
      use the new_manual_chain() function. The function accepts a single
      argument which is the name of the chain. The function returns a
      reference to the resulting chain table entry.</p><p>A companion function, <span class="bold"><strong>ensure_manual_chain()</strong></span>, can be called when a
      manual chain of the desired name may have already been created. If a
      manual chain table entry with the passed name already exists, a
      reference to the chain table entry is returned. Otherwise, the function
      calls <span class="bold"><strong>new_manual_chain()</strong></span> and returns
      the result.</p><p>To create a logging rule, call <span class="bold"><strong>log_rule_limit()</strong></span>. Arguments are:</p><div class="variablelist"><dl><dt><span class="term">$level</span></dt><dd><p>The log level. May be specified as a name or as a
            number.</p></dd><dt><span class="term">$chainref</span></dt><dd><p>Chain table reference for the chain to which the rule is to
            be added.</p></dd><dt><span class="term">$name</span></dt><dd><p>The chain name to be reported in the log message (see
            LOGFORMAT in <a class="ulink" href="manpages/shorewall.conf.html" target="_self">shorewall.conf</a>(5)).</p></dd><dt><span class="term">$disposition</span></dt><dd><p>The disposition to be reported in the log message (see
            LOGFORMAT in <a class="ulink" href="manpages/shorewall.conf.html" target="_self">shorewall.conf</a>(5)).</p></dd><dt><span class="term">$limit</span></dt><dd><p>Rate limiting match. If an empty string is passed, the
            LOGRATE/LOGBURST (<a class="ulink" href="manpages/shorewall.conf.html" target="_self">shorewall.conf</a>(5)) is
            used.</p></dd><dt><span class="term">$tag</span></dt><dd><p>Log tag.</p></dd><dt><span class="term">$command</span></dt><dd><p>If 'add', append the log rule to the chain. If 'insert',
            then insert the rule at the beginning of the chain.</p></dd><dt><span class="term">$predicates</span></dt><dd><p>Any additional matches that are to be applied to the
            rule.</p></dd></dl></div></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="Config"></a>Shorewall::Config</h3></div></div></div><pre class="programlisting">use lib '/usr/share/shorewall-perl';
use Shorewall::Config;

warning message "This entry is bogus";
fatal_error "You have made an error";

progress_message  "This will only be seen if VERBOSITY &gt;= 2";
progress_message2 "This will only be seen if VERBOSITY &gt;= 1";
progress_message3 "This will be seen unless VERBOSITY &lt; 0";
</pre><p>The <span class="bold"><strong>shorewall()</strong></span> function may
      be optionally included.</p><pre class="programlisting">use lib '/usr/share/shorewall-perl';
use Shorewall::Config qw/shorewall/;

shorewall $config_file_entry;</pre><p>The Shorewall::Config module
      provides basic services to Shorewall-perl. By default, it exports the
      functions that produce progress messages and warning/error
      messages.</p><p>To issue a warning message, call <span class="bold"><strong>warning_message()</strong></span>. The single argument describes
      the warning.</p><p>To raise a fatal error, call <span class="bold"><strong>fatal_error()</strong></span>. Again, the single argument
      described the error.</p><p>In both cases, the function will augment the warning/error with
      the current configuration file and line number, if any. <span class="bold"><strong>fatal_error()</strong></span> raised an exception via either
      <span class="bold"><strong>confess()</strong></span> or <span class="bold"><strong>die()</strong></span>, depending on whether the debugging stack
      trace is enabled or not..</p><p>The three 'progress message' functions conditionally produce
      output depending on the current verbosity setting.</p><p>The <span class="bold"><strong>shorewall()</strong></span> function is used
      by <a class="ulink" href="configuration_file_basics.htm#Embedded" target="_self">embedded Perl
      scripts</a> to generate entries to be included in the current
      configuration file.</p></div></div></div></body></html>