<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jiufpt</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jiufpt"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Jiufpt"/>
	<updated>2026-04-30T15:32:30Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8396</id>
		<title>Alpine Wall User&#039;s Guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8396"/>
		<updated>2012-09-13T22:33:39Z</updated>

		<summary type="html">&lt;p&gt;Jiufpt: /* Rules */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Configuration File Processing ==&lt;br /&gt;
&lt;br /&gt;
[[Alpine Wall]] (awall) reads its configuration from multiple&lt;br /&gt;
JSON-formatted files, called &#039;&#039;policy files&#039;&#039;. The processing starts&lt;br /&gt;
from directory &amp;lt;tt&amp;gt;/usr/share/awall/mandatory&amp;lt;/tt&amp;gt;, which contains&lt;br /&gt;
mandatory policy files shipped with APK packages. After that,&lt;br /&gt;
installation-specific policy files in &amp;lt;tt&amp;gt;/etc/awall&amp;lt;/tt&amp;gt; are&lt;br /&gt;
processed.&lt;br /&gt;
&lt;br /&gt;
The latter directory may also contain symbolic links to policy files&lt;br /&gt;
located in &amp;lt;tt&amp;gt;/usr/share/awall/optional&amp;lt;/tt&amp;gt;. These are optional&lt;br /&gt;
policies, which can be enabled on need basis. Such symbolic links are&lt;br /&gt;
easily created and destroyed using the &amp;lt;tt&amp;gt;awall enable&amp;lt;/tt&amp;gt; and &lt;br /&gt;
&amp;lt;tt&amp;gt;awall disable&amp;lt;/tt&amp;gt; commands. &amp;lt;tt&amp;gt;awall list&amp;lt;/tt&amp;gt; shows which&lt;br /&gt;
optional policies are enabled and disabled. The command also prints&lt;br /&gt;
the description of the optional policy if defined in the file using&lt;br /&gt;
a top-level attribute named &#039;&#039;&#039;description&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Sometimes a policy file depends on other policy files. In this case,&lt;br /&gt;
the policy file must have a top-level attribute &#039;&#039;&#039;import&#039;&#039;&#039;, the&lt;br /&gt;
value of which is a list of policy names, which correspond to the file&lt;br /&gt;
names without the &amp;lt;tt&amp;gt;.json&amp;lt;/tt&amp;gt; suffix. By default, the policies&lt;br /&gt;
listed there are processed before the importing policy.&lt;br /&gt;
&lt;br /&gt;
The order of the generated iptables rules generally reflects the&lt;br /&gt;
processing order of their corresponding awall policies. The processing&lt;br /&gt;
order of policies can be adjusted by defining top-level attributes&lt;br /&gt;
&#039;&#039;&#039;after&#039;&#039;&#039; and &#039;&#039;&#039;before&#039;&#039;&#039; in policy files. These attributes are&lt;br /&gt;
lists of policies, after or before which the declaring policy shall be&lt;br /&gt;
processed. Putting a policy name to either of these lists does not by&lt;br /&gt;
itself import the policy. The ordering directives are ignored with&lt;br /&gt;
respect to those policies that are not enabled by the user or imported&lt;br /&gt;
by other policies. If not defined, &#039;&#039;&#039;after&#039;&#039;&#039; is assumed to be equal&lt;br /&gt;
to the &#039;&#039;&#039;import&#039;&#039;&#039; definition of the policy.&lt;br /&gt;
&lt;br /&gt;
As the import directive does not require the path name to be&lt;br /&gt;
specified, awall expects policies to have unique names, even if&lt;br /&gt;
located in different directories. It is allowed to import optional&lt;br /&gt;
policies that are not explicitly enabled by the user. Such policies&lt;br /&gt;
show up with the &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; status in the output of &amp;lt;tt&amp;gt;awall&lt;br /&gt;
list&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== List Parameters ==&lt;br /&gt;
&lt;br /&gt;
Several awall parameters are defined as lists of values. In order to&lt;br /&gt;
facilitate manual editing of policy files, awall also accepts single&lt;br /&gt;
values in place of lists. Such values are semantically equivalent to&lt;br /&gt;
lists containing one element.&lt;br /&gt;
&lt;br /&gt;
== Variable Expansion ==&lt;br /&gt;
&lt;br /&gt;
Awall allows variable definitions in policy files. The top-level&lt;br /&gt;
attribute &#039;&#039;&#039;variable&#039;&#039;&#039; is a dictionary containing the&lt;br /&gt;
definitions. The value of a variable can be of any type (string,&lt;br /&gt;
integer, list, or dictionary).&lt;br /&gt;
&lt;br /&gt;
A variable is referenced in policy files by a string which equals the&lt;br /&gt;
variable name prepended with the &#039;&#039;&#039;$&#039;&#039;&#039; character. If the value of&lt;br /&gt;
the variable is a string, the reference can be embedded into a longer&lt;br /&gt;
string in order to substitute some part of that string (in shell&lt;br /&gt;
style). Variable references can be used when defining other variables,&lt;br /&gt;
as long as the definitions are not circular.&lt;br /&gt;
&lt;br /&gt;
Policy files can reference variables defined in other policy&lt;br /&gt;
files. Policy files can also override variables defined elsewhere by&lt;br /&gt;
redefining them. In this case, the new definition affects all policy&lt;br /&gt;
files, also those processed before the overriding policy. Awall&lt;br /&gt;
variables are in fact simple macros, since each variable remains&lt;br /&gt;
constant thoughout a single processing round. If multiple files define&lt;br /&gt;
the same variable, the definition in the file processed last takes&lt;br /&gt;
effect.&lt;br /&gt;
&lt;br /&gt;
If defined as an empty string, all non-embedded references to a&lt;br /&gt;
variable evaluate as if the attribute in question was not present in&lt;br /&gt;
the configuration. This is also the case when a string containing&lt;br /&gt;
embedded variable references finally evaluates to an empty string.&lt;br /&gt;
&lt;br /&gt;
== Configuration Objects ==&lt;br /&gt;
&lt;br /&gt;
Configuration objects can be divided into two main types.&lt;br /&gt;
&#039;&#039;Auxiliary objects&#039;&#039; model high-level concepts such as services and&lt;br /&gt;
zones. &#039;&#039;Rule objects&#039;&#039; translate into one or more iptables rules, and&lt;br /&gt;
are often defined with the help of some auxiliary objects.&lt;br /&gt;
&lt;br /&gt;
=== Services ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;service&#039;&#039; represents a set of network protocols. A top-level&lt;br /&gt;
attribute &#039;&#039;&#039;service&#039;&#039;&#039; is a dictionary that maps service names to&lt;br /&gt;
service definition objects, or lists thereof in more complex cases.&lt;br /&gt;
&lt;br /&gt;
A service definition object contains an attribute named &#039;&#039;&#039;proto&#039;&#039;&#039;,&lt;br /&gt;
which corresponds to the &amp;lt;tt&amp;gt;--protocol&amp;lt;/tt&amp;gt; option of iptables. The&lt;br /&gt;
protocol can be defined as a numerical value or string as defined in&lt;br /&gt;
&amp;lt;tt&amp;gt;/etc/protocols&amp;lt;/tt&amp;gt;. If the protocol is &#039;&#039;&#039;tcp&#039;&#039;&#039; or &#039;&#039;&#039;udp&#039;&#039;&#039;,&lt;br /&gt;
the scope of the service definition may be constrained by defining an&lt;br /&gt;
attribute named &#039;&#039;&#039;port&#039;&#039;&#039;, which is a list of TCP or UDP port numbers&lt;br /&gt;
or ranges thereof, separated by the &#039;&#039;&#039;-&#039;&#039;&#039; character. If the protocol&lt;br /&gt;
is &#039;&#039;&#039;icmp&#039;&#039;&#039; or &#039;&#039;&#039;icmpv6&#039;&#039;&#039;, an analogous &#039;&#039;&#039;icmp-type&#039;&#039;&#039; attribute&lt;br /&gt;
may be used. In addition, the scope of the rule is also automatically&lt;br /&gt;
limited to IPv4 or IPv6, respectively.&lt;br /&gt;
&lt;br /&gt;
=== Zones ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;zone&#039;&#039; represents a set of network hosts. A top-level attribute &lt;br /&gt;
&#039;&#039;&#039;zone&#039;&#039;&#039; is a dictionary that maps zone names to zone objects. A&lt;br /&gt;
zone object has an attribute named &#039;&#039;&#039;iface&#039;&#039;&#039;, &#039;&#039;&#039;addr&#039;&#039;&#039;, or&lt;br /&gt;
both. &#039;&#039;&#039;iface&#039;&#039;&#039; is a list of network interfaces and &#039;&#039;&#039;addr&#039;&#039;&#039; is a&lt;br /&gt;
list of IPv4/IPv6 host and network addresses (CIDR&lt;br /&gt;
notation). &#039;&#039;&#039;addr&#039;&#039;&#039; may also contain domain names, which are&lt;br /&gt;
expanded to IP addresses using DNS resolution. If not defined,&lt;br /&gt;
&#039;&#039;&#039;addr&#039;&#039;&#039; defaults to the entire address space and &#039;&#039;&#039;iface&#039;&#039;&#039; to all&lt;br /&gt;
interfaces. An empty zone can be defined by setting either &#039;&#039;&#039;addr&#039;&#039;&#039;&lt;br /&gt;
or &#039;&#039;&#039;iface&#039;&#039;&#039; to an empty list.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Rule objects contain two attributes, &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;, which are&lt;br /&gt;
lists of zone names. These attributes control whether a packet matches&lt;br /&gt;
the rule or not. If a particular zone is referenced by the &#039;&#039;&#039;in&#039;&#039;&#039; &lt;br /&gt;
attribute, the rule applies to packets whose ingress interface and&lt;br /&gt;
source address are covered by the zone definition. Correspondingly, if&lt;br /&gt;
a zone is referenced by the &#039;&#039;&#039;out&#039;&#039;&#039; attribute, the rule applies to&lt;br /&gt;
packets whose egress interface and destination address are included in&lt;br /&gt;
the zone. If both &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; are defined, the packet must&lt;br /&gt;
fulfill both criteria in order to match the rule.&lt;br /&gt;
&lt;br /&gt;
The firewall host itself can be referred to using the special value&lt;br /&gt;
&#039;&#039;&#039;_fw&#039;&#039;&#039; as the zone name.&lt;br /&gt;
&lt;br /&gt;
=== Logging Classes ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;logging class&#039;&#039; specifies how packets matching certain rules are&lt;br /&gt;
logged. A top-level attribute &#039;&#039;&#039;log&#039;&#039;&#039; is a dictionary that maps&lt;br /&gt;
logging class names to setting objects.&lt;br /&gt;
&lt;br /&gt;
A setting object may have an attribute named &#039;&#039;&#039;mode&#039;&#039;&#039;, which&lt;br /&gt;
specifies which logging facility to use. Allowed values are &#039;&#039;&#039;log&#039;&#039;&#039;,&lt;br /&gt;
&#039;&#039;&#039;nflog&#039;&#039;&#039;, and &#039;&#039;&#039;ulog&#039;&#039;&#039;. The default is &#039;&#039;&#039;log&#039;&#039;&#039;, i.e. in-kernel&lt;br /&gt;
logging. The object may also have a &#039;&#039;&#039;limit&#039;&#039;&#039; attribute, which is an&lt;br /&gt;
integer specifying the maximum number of matching packets to be logged&lt;br /&gt;
per second per rule. Optionally, the log entries are prefixed with a&lt;br /&gt;
string configured using the &#039;&#039;&#039;prefix&#039;&#039;&#039; attribute.&lt;br /&gt;
&lt;br /&gt;
Filter and policy rules can have an attribute named &#039;&#039;&#039;log&#039;&#039;&#039;. If it&lt;br /&gt;
is a string, it is interpreted as a reference to a logging class, and&lt;br /&gt;
logging is performed according to the definitions. If the value of the&lt;br /&gt;
&#039;&#039;&#039;log&#039;&#039;&#039; attribute is &#039;&#039;&#039;true&#039;&#039;&#039; (boolean), logging is done using&lt;br /&gt;
default settings. If the value is &#039;&#039;&#039;false&#039;&#039;&#039; (boolean), logging is&lt;br /&gt;
disabled for the rule. If &#039;&#039;&#039;log&#039;&#039;&#039; is not defined, logging is done&lt;br /&gt;
using the default settings except for accept rules, for which logging&lt;br /&gt;
is omitted.&lt;br /&gt;
&lt;br /&gt;
Default logging settings can be set by defining a logging class named&lt;br /&gt;
&#039;&#039;&#039;_default&#039;&#039;&#039;. Normally, default logging uses the &#039;&#039;&#039;log&#039;&#039;&#039; mode with&lt;br /&gt;
packets limited to one per second.&lt;br /&gt;
&lt;br /&gt;
=== Rules ===&lt;br /&gt;
&lt;br /&gt;
There are six types of rule objects:&lt;br /&gt;
* Filters rules&lt;br /&gt;
* Policies rules&lt;br /&gt;
* NAT rules&lt;br /&gt;
* Packet Marking rules&lt;br /&gt;
* MSS Clamping rules&lt;br /&gt;
* Connection Tracking Bypass rules&lt;br /&gt;
&lt;br /&gt;
All rule objects can have the &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; attributes&lt;br /&gt;
referring to zones as described in the previous section. In addition,&lt;br /&gt;
the scope of the rule can be further constrained with the following&lt;br /&gt;
attributes:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Attribute!!Value format!!Effect&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;src&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s source address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;dest&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s destination address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipset&#039;&#039;&#039;&lt;br /&gt;
|Object containing two attributes: &#039;&#039;&#039;name&#039;&#039;&#039; referring to an IP set and &#039;&#039;&#039;args&#039;&#039;&#039;, which is a list of strings &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|Packet matches the IP set referred here when the match arguments are taken from the source (&#039;&#039;&#039;in&#039;&#039;&#039;) and destination (&#039;&#039;&#039;out&#039;&#039;&#039;) address or port in the order specified by &#039;&#039;&#039;args&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipsec&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;in&#039;&#039;&#039; or &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|IPsec decapsulation perfomed on ingress (&#039;&#039;&#039;in&#039;&#039;&#039;) or encapsulation performed on egress (&#039;&#039;&#039;out&#039;&#039;&#039;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects are declared in type-specific top-level dictionaries in&lt;br /&gt;
awall policy files. If a packet matches multiple rules, the one&lt;br /&gt;
appearing earlier in the list takes precedence. If the matching rules&lt;br /&gt;
are defined in different policy files, the one that was processed&lt;br /&gt;
earlier takes precedence in the current implementation, but this may&lt;br /&gt;
change in future versions.&lt;br /&gt;
&lt;br /&gt;
==== Filters Rules ====&lt;br /&gt;
&lt;br /&gt;
Filter objects specify an action for packets fulfilling certain&lt;br /&gt;
criteria. The top-level attribute &#039;&#039;&#039;filter&#039;&#039;&#039; is a list of filter&lt;br /&gt;
objects. The precedence rules are similar to those of policy objects.&lt;br /&gt;
&lt;br /&gt;
In addition to the common rule attributes, filter objects can have a &lt;br /&gt;
&#039;&#039;&#039;service&#039;&#039;&#039; attribute constraining the scope to specific services&lt;br /&gt;
only. This attribute is a list of service names, referring to the&lt;br /&gt;
keys of the top-level &#039;&#039;&#039;service&#039;&#039;&#039; dictionary.&lt;br /&gt;
&lt;br /&gt;
Filter objects must have an attribute named &#039;&#039;&#039;action&#039;&#039;&#039;, the value of&lt;br /&gt;
which can be one of the following:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Value!!Action&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;accept&#039;&#039;&#039;&lt;br /&gt;
|Accept the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;reject&#039;&#039;&#039;&lt;br /&gt;
|Reject the packet with an ICMP error message&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;drop&#039;&#039;&#039;&lt;br /&gt;
|Silently drop the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;tarpit&#039;&#039;&#039;&lt;br /&gt;
|Put incoming TCP connections into persist state and ignore attempts to close them. Silently drop non-TCP packets. (Connection tracking bypass is automatically enabled for the matching packets.)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Filter objects, the action of which is &#039;&#039;&#039;accept&#039;&#039;&#039;, may also contain&lt;br /&gt;
limits for packet flow or new connections. These are specified with&lt;br /&gt;
the &#039;&#039;&#039;flow-limit&#039;&#039;&#039; and &#039;&#039;&#039;conn-limit&#039;&#039;&#039; attributes,&lt;br /&gt;
respectively. The values of these attributes are limit objects that&lt;br /&gt;
have two attributes: &#039;&#039;&#039;count&#039;&#039;&#039; and &#039;&#039;&#039;interval&#039;&#039;&#039;. &#039;&#039;&#039;count&#039;&#039;&#039;&lt;br /&gt;
specifies how many new connections or packets are allowed within the&lt;br /&gt;
time frame specified by &#039;&#039;&#039;interval&#039;&#039;&#039; (in seconds). The &#039;&#039;&#039;logdrop&#039;&#039;&#039;&lt;br /&gt;
action is applied to the packets exceeding the limit.&lt;br /&gt;
&lt;br /&gt;
Filter objects may have an attribute named &#039;&#039;&#039;dnat&#039;&#039;&#039;, the value of&lt;br /&gt;
which is an IPv4 address. If defined, this enables destination NAT for&lt;br /&gt;
all IPv4 packets matching the rule, such that the specified address&lt;br /&gt;
replaces the original destination address. This option has no effect&lt;br /&gt;
on IPv6 packets.&lt;br /&gt;
&lt;br /&gt;
Filter objects may have a boolean attribute named &#039;&#039;&#039;no-track&#039;&#039;&#039;. If&lt;br /&gt;
set to &#039;&#039;&#039;true&#039;&#039;&#039;, connection tracking is bypassed for the matching&lt;br /&gt;
packets. In addition, if &#039;&#039;&#039;action&#039;&#039;&#039; is set to &#039;&#039;&#039;accept&#039;&#039;&#039;, the&lt;br /&gt;
corresponding packets travelling to the reverse direction are also&lt;br /&gt;
allowed.&lt;br /&gt;
&lt;br /&gt;
==== Policies Rules ====&lt;br /&gt;
&lt;br /&gt;
Policy objects describe the default action for packets that did not&lt;br /&gt;
match any filter. The top-level attribute &#039;&#039;&#039;policy&#039;&#039;&#039; is a list of&lt;br /&gt;
policy objects.&lt;br /&gt;
&lt;br /&gt;
Policy objects must have the &#039;&#039;&#039;action&#039;&#039;&#039; attribute defined. The&lt;br /&gt;
possible values and their semantics are the same as in filter objects.&lt;br /&gt;
&lt;br /&gt;
==== NAT Rules ====&lt;br /&gt;
&lt;br /&gt;
NAT rules come in two flavors: &#039;&#039;source NAT rules&#039;&#039; and&lt;br /&gt;
&#039;&#039;destination NAT rules&#039;&#039;. These are contained in two top-level lists&lt;br /&gt;
named &#039;&#039;&#039;snat&#039;&#039;&#039; and &#039;&#039;&#039;dnat&#039;&#039;&#039;, respectively.&lt;br /&gt;
&lt;br /&gt;
Each NAT rule may have an attribute named &#039;&#039;&#039;to-addr&#039;&#039;&#039; that&lt;br /&gt;
specifies the IPv4 address range to which the original source or&lt;br /&gt;
destination address is mapped. The value can be a single IPv4 address&lt;br /&gt;
or a range specified by two addresses, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character. If not defined, it defaults to the primary address of the&lt;br /&gt;
ingress interface in case of destination NAT, or that of the egress&lt;br /&gt;
interface in case of source NAT.&lt;br /&gt;
&lt;br /&gt;
Optionally, a NAT rule can specify the TCP and UDP port range to which&lt;br /&gt;
the original source or destination port is mapped. The attribute is&lt;br /&gt;
named &#039;&#039;&#039;to-port&#039;&#039;&#039;, and the value can be a single port number or a&lt;br /&gt;
range specified by two numbers, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character. If &#039;&#039;&#039;to-port&#039;&#039;&#039; is not specified, the original port number&lt;br /&gt;
is kept intact.&lt;br /&gt;
&lt;br /&gt;
Like filters, NAT rules can have a &#039;&#039;&#039;service&#039;&#039;&#039; attribute&lt;br /&gt;
constraining their scope to specific services.&lt;br /&gt;
&lt;br /&gt;
NAT rules may have an &#039;&#039;&#039;action&#039;&#039;&#039; attribute set to value&lt;br /&gt;
&#039;&#039;&#039;accept&#039;&#039;&#039;. In this case, NAT is not performed on the packets&lt;br /&gt;
reaching and matching this rule.&lt;br /&gt;
&lt;br /&gt;
==== Packet Marking Rules ====&lt;br /&gt;
&lt;br /&gt;
Packet marking rules are used to mark incoming packets matching the&lt;br /&gt;
specified criteria. The mark can be used as a basis for the routing&lt;br /&gt;
decision. Each marking rule must specify the mark using the &#039;&#039;&#039;mark&#039;&#039;&#039;&lt;br /&gt;
attribute, which is a 32-bit integer.&lt;br /&gt;
&lt;br /&gt;
Normal marking rules are contained by the top-level list attribute&lt;br /&gt;
named &#039;&#039;&#039;mark&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
There is another top-level list attribute, named &#039;&#039;&#039;route-track&#039;&#039;&#039;,&lt;br /&gt;
which contains route tracking rules. These are special marking rules&lt;br /&gt;
which cause all the subsequent packets related to the same connection&lt;br /&gt;
to be marked according to the rule.&lt;br /&gt;
&lt;br /&gt;
==== MSS Clamping Rules ====&lt;br /&gt;
&lt;br /&gt;
MSS Clamping Rules are used to deal with ISPs that block ICMP&lt;br /&gt;
Fragmentation Needed or ICMPv6 Packet Too Big packets. An MSS clamping&lt;br /&gt;
rule overwrites the MSS option with a value specified with the&lt;br /&gt;
&#039;&#039;&#039;mss&#039;&#039;&#039; attribute for the matching TCP connections. If &#039;&#039;&#039;mss&#039;&#039;&#039; is&lt;br /&gt;
not specified, a suitable value is automatically determined from the&lt;br /&gt;
path MTU.&lt;br /&gt;
&lt;br /&gt;
==== Connection Tracking Bypass Rules ====&lt;br /&gt;
&lt;br /&gt;
Connection tracking bypass rules are used to disable connection&lt;br /&gt;
tracking for packets matching the specified criteria. The top-level&lt;br /&gt;
attribute &#039;&#039;&#039;no-track&#039;&#039;&#039; is a list of such rules.&lt;br /&gt;
&lt;br /&gt;
Connection tracking bypass rules may have an &#039;&#039;&#039;action&#039;&#039;&#039; attribute&lt;br /&gt;
set to value &#039;&#039;&#039;accept&#039;&#039;&#039;. The effect is similar to corresponding NAT&lt;br /&gt;
rules, i.e. connection tracking is not bypassed for the matching&lt;br /&gt;
packets.&lt;br /&gt;
&lt;br /&gt;
=== IP Sets ===&lt;br /&gt;
&lt;br /&gt;
Any IP set referenced by rule objects should be created by&lt;br /&gt;
awall. Auxiliary &#039;&#039;IP set&#039;&#039; objects are used to defined them in awall&lt;br /&gt;
policy files. The top-level attribute &#039;&#039;&#039;ipset&#039;&#039;&#039; is a dictionary, the&lt;br /&gt;
keys of which are IP set names. The values are IP set objects, which&lt;br /&gt;
have two mandatory attributes. The attribute named &#039;&#039;&#039;type&#039;&#039;&#039; &lt;br /&gt;
corresponds to the type argument of the &amp;lt;tt&amp;gt;ipset create&amp;lt;/tt&amp;gt; &lt;br /&gt;
command. &#039;&#039;&#039;family&#039;&#039;&#039; specifies whether the set is for IPv4 or IPv6&lt;br /&gt;
addresses, and the possible values are &#039;&#039;&#039;inet&#039;&#039;&#039; and &#039;&#039;&#039;inet6&#039;&#039;&#039;,&lt;br /&gt;
correspondingly.&lt;br /&gt;
&lt;br /&gt;
== Command Line Syntax ==&lt;br /&gt;
&lt;br /&gt;
=== Translating Policy Files to Firewall Configuration Files ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall translate&#039;&#039;&#039; [&#039;&#039;&#039;-o&#039;&#039;&#039;|&#039;&#039;&#039;--output&#039;&#039;&#039; DIRECTORY] [&#039;&#039;&#039;-V&#039;&#039;&#039;|&#039;&#039;&#039;--verify&#039;&#039;&#039;]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--verify&amp;lt;/tt&amp;gt; option makes awall verify the configuration&lt;br /&gt;
using the test mode of iptables-restore before overwriting the old&lt;br /&gt;
files.&lt;br /&gt;
&lt;br /&gt;
Specifying the output directory allows testing awall policies without&lt;br /&gt;
overwriting the current iptables and ipset configuration files. By&lt;br /&gt;
default, awall generates the configuration to &amp;lt;tt&amp;gt;/etc/iptables&amp;lt;/tt&amp;gt; &lt;br /&gt;
and &amp;lt;tt&amp;gt;/etc/ipset.d&amp;lt;/tt&amp;gt;, which are read by the init scripts.&lt;br /&gt;
&lt;br /&gt;
=== Run-Time Configuration of Firewall ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall activate&#039;&#039;&#039; [&#039;&#039;&#039;-f&#039;&#039;&#039;|&#039;&#039;&#039;--force&#039;&#039;&#039;]&lt;br /&gt;
&lt;br /&gt;
This command genereates firewall configuration from the policy files&lt;br /&gt;
and enables it. If the user confirms the new configuration by hitting&lt;br /&gt;
the Return key within 10 seconds or the &amp;lt;tt&amp;gt;--force&amp;lt;/tt&amp;gt; option is&lt;br /&gt;
used, the configuration is saved to the files. Otherwise, the old&lt;br /&gt;
configuration is restored.&lt;br /&gt;
&lt;br /&gt;
There is also a command for deleting all firewall rules:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall flush&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This command configures the firewall to drop all packets.&lt;br /&gt;
&lt;br /&gt;
=== Optional Policies ===&lt;br /&gt;
&lt;br /&gt;
Optional policies can be enabled or disabled using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall&#039;&#039;&#039; {&#039;&#039;&#039;enable&#039;&#039;&#039;|&#039;&#039;&#039;disable&#039;&#039;&#039;} POLICY...&lt;br /&gt;
&lt;br /&gt;
Optional policies can be listed using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall list&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;enabled&#039;&#039;&#039; status means that the policy has been enabled by the&lt;br /&gt;
user. The &#039;&#039;&#039;disabled&#039;&#039;&#039; status means that the policy is not in&lt;br /&gt;
use. The &#039;&#039;&#039;required&#039;&#039;&#039; status means that the policy has not been&lt;br /&gt;
enabled by the user but is in use because it is required by another&lt;br /&gt;
policy which is in use.&lt;br /&gt;
&lt;br /&gt;
=== Debugging Policies ===&lt;br /&gt;
&lt;br /&gt;
This command can be used to dump variable, zone, and other definitions&lt;br /&gt;
as well as their source policies:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall dump&#039;&#039;&#039; [LEVEL]&lt;br /&gt;
&lt;br /&gt;
The level is an integer in range 0&amp;amp;ndash;5 and defaults to 0. More&lt;br /&gt;
information is displayed on higher levels.&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;br /&gt;
[[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Jiufpt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8053</id>
		<title>Alpine Wall User&#039;s Guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8053"/>
		<updated>2012-05-16T18:59:15Z</updated>

		<summary type="html">&lt;p&gt;Jiufpt: /* Translating Policy Files to Firewall Configuration Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Configuration File Processing ==&lt;br /&gt;
&lt;br /&gt;
[[Alpine Wall]] (awall) reads its configuration from multiple&lt;br /&gt;
JSON-formatted files, called &#039;&#039;policy files&#039;&#039;. The processing starts&lt;br /&gt;
from directory &amp;lt;tt&amp;gt;/usr/share/awall/mandatory&amp;lt;/tt&amp;gt;, which contains&lt;br /&gt;
mandatory policy files shipped with APK packages. After that,&lt;br /&gt;
installation-specific policy files in &amp;lt;tt&amp;gt;/etc/awall&amp;lt;/tt&amp;gt; are&lt;br /&gt;
processed.&lt;br /&gt;
&lt;br /&gt;
The latter directory may also contain symbolic links to policy files&lt;br /&gt;
located in &amp;lt;tt&amp;gt;/usr/share/awall/optional&amp;lt;/tt&amp;gt;. These are optional&lt;br /&gt;
policies, which can be enabled on need basis. Such symbolic links are&lt;br /&gt;
easily created and destroyed using the &amp;lt;tt&amp;gt;awall enable&amp;lt;/tt&amp;gt; and &lt;br /&gt;
&amp;lt;tt&amp;gt;awall disable&amp;lt;/tt&amp;gt; commands. &amp;lt;tt&amp;gt;awall list&amp;lt;/tt&amp;gt; shows which&lt;br /&gt;
optional policies are enabled and disabled. The command also prints&lt;br /&gt;
the description of the optional policy if defined in the file using&lt;br /&gt;
a top-level attribute named &#039;&#039;&#039;description&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Sometimes a policy file depends on other policy files. In this case,&lt;br /&gt;
the policy file must have a top-level attribute &#039;&#039;&#039;import&#039;&#039;&#039;, the&lt;br /&gt;
value of which is a list of policy names, which correspond to the file&lt;br /&gt;
names without the &amp;lt;tt&amp;gt;.json&amp;lt;/tt&amp;gt; suffix. The policies listed there are&lt;br /&gt;
always processed before the importing policy. The order of the&lt;br /&gt;
generated iptables rules generally reflects the processing order of&lt;br /&gt;
their corresponding awall policies.&lt;br /&gt;
&lt;br /&gt;
As the import directive does not require the path name to be&lt;br /&gt;
specified, awall expects policies to have unique names, even if&lt;br /&gt;
located in different directories. It is allowed to import optional&lt;br /&gt;
policies that are not explicitly enabled by the user. Such policies&lt;br /&gt;
show up with the &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; status in the output of &amp;lt;tt&amp;gt;awall&lt;br /&gt;
list&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== List Parameters ==&lt;br /&gt;
&lt;br /&gt;
Several awall parameters are defined as lists of values. In order to&lt;br /&gt;
facilitate manual editing of policy files, awall also accepts single&lt;br /&gt;
values in place of lists. Such values are semantically equivalent to&lt;br /&gt;
lists containing one element.&lt;br /&gt;
&lt;br /&gt;
== Variable Expansion ==&lt;br /&gt;
&lt;br /&gt;
Awall allows variable definitions in policy files. The top-level&lt;br /&gt;
attribute &#039;&#039;&#039;variable&#039;&#039;&#039; is a dictionary containing the&lt;br /&gt;
definitions. The value of a variable can be of any type (string,&lt;br /&gt;
integer, list, or dictionary).&lt;br /&gt;
&lt;br /&gt;
A variable is referenced in policy files by a string which equals the&lt;br /&gt;
variable name prepended with the &#039;&#039;&#039;$&#039;&#039;&#039; character. If the value of&lt;br /&gt;
the variable is a string, the reference can be embedded into a longer&lt;br /&gt;
string in order to substitute some part of that string (in shell&lt;br /&gt;
style). Variable references can be used when defining other variables,&lt;br /&gt;
as long as the definitions are not circular.&lt;br /&gt;
&lt;br /&gt;
Policy files can reference variables defined in other policy&lt;br /&gt;
files. Policy files can also override variables defined elsewhere by&lt;br /&gt;
redefining them. In this case, the new definition affects all policy&lt;br /&gt;
files, also those processed before the overriding policy. Awall&lt;br /&gt;
variables are in fact simple macros, since each variable remains&lt;br /&gt;
constant thoughout a single processing round. If multiple files define&lt;br /&gt;
the same variable, the definition in the file processed last takes&lt;br /&gt;
effect.&lt;br /&gt;
&lt;br /&gt;
If defined as an empty string, all non-embedded references to a&lt;br /&gt;
variable evaluate as if the attribute in question was not present in&lt;br /&gt;
the configuration. This is also the case when a string containing&lt;br /&gt;
embedded variable references finally evaluates to an empty string.&lt;br /&gt;
&lt;br /&gt;
== Configuration Objects ==&lt;br /&gt;
&lt;br /&gt;
Configuration objects can be divided into two main types.&lt;br /&gt;
&#039;&#039;Auxiliary objects&#039;&#039; model high-level concepts such as services and&lt;br /&gt;
zones. &#039;&#039;Rule objects&#039;&#039; translate into one or more iptables rules, and&lt;br /&gt;
are often defined with the help of some auxiliary objects.&lt;br /&gt;
&lt;br /&gt;
=== Services ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;service&#039;&#039; represents a set of network protocols. A top-level&lt;br /&gt;
attribute &#039;&#039;&#039;service&#039;&#039;&#039; is a dictionary that maps service names to&lt;br /&gt;
service definition objects, or lists thereof in more complex cases.&lt;br /&gt;
&lt;br /&gt;
A service definition object contains an attribute named &#039;&#039;&#039;proto&#039;&#039;&#039;,&lt;br /&gt;
which corresponds to the &amp;lt;tt&amp;gt;--protocol&amp;lt;/tt&amp;gt; option of iptables. The&lt;br /&gt;
protocol can be defined as a numerical value or string as defined in&lt;br /&gt;
&amp;lt;tt&amp;gt;/etc/protocols&amp;lt;/tt&amp;gt;. If the protocol is &#039;&#039;&#039;tcp&#039;&#039;&#039; or &#039;&#039;&#039;udp&#039;&#039;&#039;,&lt;br /&gt;
the scope of the service definition may be constrained by defining an&lt;br /&gt;
attribute named &#039;&#039;&#039;port&#039;&#039;&#039;, which is a list of TCP or UDP port&lt;br /&gt;
numbers. If the protocol is &#039;&#039;&#039;icmp&#039;&#039;&#039; or &#039;&#039;&#039;icmpv6&#039;&#039;&#039;, an analogous &lt;br /&gt;
&#039;&#039;&#039;icmp-type&#039;&#039;&#039; attribute may be used. In addition, the scope of the&lt;br /&gt;
rule is also automatically limited to IPv4 or IPv6, respectively.&lt;br /&gt;
&lt;br /&gt;
=== Zones ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;zone&#039;&#039; represents a set of network hosts. A top-level attribute &lt;br /&gt;
&#039;&#039;&#039;zone&#039;&#039;&#039; is a dictionary that maps zone names to zone objects. A&lt;br /&gt;
zone object has an attribute named &#039;&#039;&#039;iface&#039;&#039;&#039;, &#039;&#039;&#039;addr&#039;&#039;&#039;, or&lt;br /&gt;
both. &#039;&#039;&#039;iface&#039;&#039;&#039; is a list of network interfaces and &#039;&#039;&#039;addr&#039;&#039;&#039; is a&lt;br /&gt;
list of IPv4/IPv6 host and network addresses (CIDR&lt;br /&gt;
notation). &#039;&#039;&#039;addr&#039;&#039;&#039; may also contain domain names, which are&lt;br /&gt;
expanded to IP addresses using DNS resolution. If not defined,&lt;br /&gt;
&#039;&#039;&#039;addr&#039;&#039;&#039; defaults to the entire address space and &#039;&#039;&#039;iface&#039;&#039;&#039; to all&lt;br /&gt;
interfaces.&lt;br /&gt;
&lt;br /&gt;
Rule objects contain two attributes, &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;, which are&lt;br /&gt;
lists of zone names. These attributes control whether a packet matches&lt;br /&gt;
the rule or not. If a particular zone is referenced by the &#039;&#039;&#039;in&#039;&#039;&#039; &lt;br /&gt;
attribute, the rule applies to packets whose ingress interface and&lt;br /&gt;
source address are covered by the zone definition. Correspondingly, if&lt;br /&gt;
a zone is referenced by the &#039;&#039;&#039;out&#039;&#039;&#039; attribute, the rule applies to&lt;br /&gt;
packets whose egress interface and destination address are included in&lt;br /&gt;
the zone. If both &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; are defined, the packet must&lt;br /&gt;
fulfill both criteria in order to match the rule.&lt;br /&gt;
&lt;br /&gt;
=== Rules ===&lt;br /&gt;
&lt;br /&gt;
There are three types of rule objects: &#039;&#039;policies&#039;&#039;, &#039;&#039;filters&#039;&#039;, and &lt;br /&gt;
&#039;&#039;NAT rules&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
All rule objects can have the &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; attributes&lt;br /&gt;
referring to zones as described in the previous section. In addition,&lt;br /&gt;
the scope of the rule can be further constrained with the following&lt;br /&gt;
attributes:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Attribute!!Value format!!Effect&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;src&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s source address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;dest&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s destination address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipset&#039;&#039;&#039;&lt;br /&gt;
|Object containing two attributes: &#039;&#039;&#039;name&#039;&#039;&#039; referring to an IP set and &#039;&#039;&#039;args&#039;&#039;&#039;, which is a list of strings &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|Packet matches the IP set referred here when the match arguments are taken from the source (&#039;&#039;&#039;in&#039;&#039;&#039;) and destination (&#039;&#039;&#039;out&#039;&#039;&#039;) address or port in the order specified by &#039;&#039;&#039;args&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipsec&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;in&#039;&#039;&#039; or &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|IPsec decapsulation perfomed on ingress (&#039;&#039;&#039;in&#039;&#039;&#039;) or encapsulation performed on egress (&#039;&#039;&#039;out&#039;&#039;&#039;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects must have an attribute named &#039;&#039;&#039;action&#039;&#039;&#039;, the value of&lt;br /&gt;
which can be one of the following:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Value!!Action&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;accept&#039;&#039;&#039;&lt;br /&gt;
|Accept the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;reject&#039;&#039;&#039;&lt;br /&gt;
|Reject the packet with an ICMP error message&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;drop&#039;&#039;&#039;&lt;br /&gt;
|Silently drop the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;logreject&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;reject&#039;&#039;&#039; but with kernel logging&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;logdrop&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;drop&#039;&#039;&#039; but with kernel logging&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects are declared in type-specific top-level dictionaries in&lt;br /&gt;
awall policy files. If a packet matches multiple rules, the one&lt;br /&gt;
appearing earlier in the list takes precedence. If the matching rules&lt;br /&gt;
are defined in different policy files, the one that was processed&lt;br /&gt;
earlier takes precedence in the current implementation, but this may&lt;br /&gt;
change in future versions.&lt;br /&gt;
&lt;br /&gt;
==== Filters ====&lt;br /&gt;
&lt;br /&gt;
Filter objects specify an action for packets fulfilling certain&lt;br /&gt;
criteria. The top-level attribute &#039;&#039;&#039;filter&#039;&#039;&#039; is a list of filter&lt;br /&gt;
objects. The precedence rules are similar to those of policy objects.&lt;br /&gt;
&lt;br /&gt;
In addition to the common rule attributes, filter objects can have a &lt;br /&gt;
&#039;&#039;&#039;service&#039;&#039;&#039; attribute constraining the scope to specific services&lt;br /&gt;
only. This attribute is a list of service names, referring to the&lt;br /&gt;
keys of the top-level &#039;&#039;&#039;service&#039;&#039;&#039; dictionary.&lt;br /&gt;
&lt;br /&gt;
Filter objects may also contain limits for packet flow or new&lt;br /&gt;
connections. These are specified with the &#039;&#039;&#039;flow-limit&#039;&#039;&#039; and&lt;br /&gt;
&#039;&#039;&#039;conn-limit&#039;&#039;&#039; attributes, respectively. The values of these&lt;br /&gt;
attributes are limit objects that have two attributes: &#039;&#039;&#039;count&#039;&#039;&#039; and&lt;br /&gt;
&#039;&#039;&#039;interval&#039;&#039;&#039;. &#039;&#039;&#039;count&#039;&#039;&#039; specifies how many new connections or&lt;br /&gt;
packets are allowed within the time frame specified by &#039;&#039;&#039;interval&#039;&#039;&#039; &lt;br /&gt;
(in seconds). The &#039;&#039;&#039;logdrop&#039;&#039;&#039; action is applied to the packets&lt;br /&gt;
exceeding the limit.&lt;br /&gt;
&lt;br /&gt;
Filter objects may have an attribute named &#039;&#039;&#039;dnat&#039;&#039;&#039;, the value of&lt;br /&gt;
which is an IPv4 address. If defined, this enables destination NAT for&lt;br /&gt;
all IPv4 packets matching the rule, such that the specified address&lt;br /&gt;
replaces the original destination address. This option has no effect&lt;br /&gt;
on IPv6 packets.&lt;br /&gt;
&lt;br /&gt;
==== Policies ====&lt;br /&gt;
&lt;br /&gt;
Policy objects describe the default action for packets that did not&lt;br /&gt;
match any filter. The top-level attribute &#039;&#039;&#039;policy&#039;&#039;&#039; is a list of&lt;br /&gt;
policy objects. Policy objects do not have other attributes than those&lt;br /&gt;
common to all rule objects.&lt;br /&gt;
&lt;br /&gt;
==== NAT Rules ====&lt;br /&gt;
&lt;br /&gt;
NAT rules come in two flavors: &#039;&#039;source NAT rules&#039;&#039; and&lt;br /&gt;
&#039;&#039;destination NAT rules&#039;&#039;. These are contained in two top-level lists&lt;br /&gt;
named &#039;&#039;&#039;snat&#039;&#039;&#039; and &#039;&#039;&#039;dnat&#039;&#039;&#039;, respectively.&lt;br /&gt;
&lt;br /&gt;
Each NAT rule must have an attribute named &#039;&#039;&#039;ip-range&#039;&#039;&#039; that&lt;br /&gt;
specifies the IPv4 address range to which the original source or&lt;br /&gt;
destinatinon address is mapped. The value can be a single IPv4 address&lt;br /&gt;
or a range specified by two addresses, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character.&lt;br /&gt;
&lt;br /&gt;
Optionally, a NAT rule can specify the TCP and UDP port range to which&lt;br /&gt;
the original source or destination port is mapped. The attribute is&lt;br /&gt;
named &#039;&#039;&#039;port-range&#039;&#039;&#039;, and the value can be a single port number or a&lt;br /&gt;
range specified by two numbers, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character. If &#039;&#039;&#039;port-range&#039;&#039;&#039; is not specified, the original port&lt;br /&gt;
number is kept intact.&lt;br /&gt;
&lt;br /&gt;
Like filters, NAT rules can have a &#039;&#039;&#039;service&#039;&#039;&#039; attribute&lt;br /&gt;
constraining their scope to specific services.&lt;br /&gt;
&lt;br /&gt;
=== IP Sets ===&lt;br /&gt;
&lt;br /&gt;
Any IP set referenced by rule objects should be created by&lt;br /&gt;
awall. Auxiliary &#039;&#039;IP set&#039;&#039; objects are used to defined them in awall&lt;br /&gt;
policy files. The top-level attribute &#039;&#039;&#039;ipset&#039;&#039;&#039; is a dictionary, the&lt;br /&gt;
keys of which are IP set names. The values are IP set objects, which&lt;br /&gt;
have two mandatory attributes. The attribute named &#039;&#039;&#039;type&#039;&#039;&#039; &lt;br /&gt;
corresponds to the type argument of the &amp;lt;tt&amp;gt;ipset create&amp;lt;/tt&amp;gt; &lt;br /&gt;
command. &#039;&#039;&#039;family&#039;&#039;&#039; specifies whether the set is for IPv4 or IPv6&lt;br /&gt;
addresses, and the possible values are &#039;&#039;&#039;inet&#039;&#039;&#039; and &#039;&#039;&#039;inet6&#039;&#039;&#039;,&lt;br /&gt;
correspondingly.&lt;br /&gt;
&lt;br /&gt;
== Command Line Syntax ==&lt;br /&gt;
&lt;br /&gt;
=== Translating Policy Files to Firewall Configuration Files ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall translate&#039;&#039;&#039; [&#039;&#039;&#039;-o&#039;&#039;&#039;|&#039;&#039;&#039;--output&#039;&#039;&#039; DIRECTORY] [&#039;&#039;&#039;-V&#039;&#039;&#039;|&#039;&#039;&#039;--verify&#039;&#039;&#039;]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--verify&amp;lt;/tt&amp;gt; option makes awall verify the configuration&lt;br /&gt;
using the test mode of iptables-restore before overwriting the old&lt;br /&gt;
files.&lt;br /&gt;
&lt;br /&gt;
Specifying the output directory allows testing awall policies without&lt;br /&gt;
overwriting the current iptables and ipset configuration files. By&lt;br /&gt;
default, awall generates the configuration to &amp;lt;tt&amp;gt;/etc/iptables&amp;lt;/tt&amp;gt; &lt;br /&gt;
and &amp;lt;tt&amp;gt;/etc/ipset.d&amp;lt;/tt&amp;gt;, which are read by the init scripts.&lt;br /&gt;
&lt;br /&gt;
=== Run-Time Activation of New Firewall Configuration ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall activate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This command genereates firewall configuration from the policy files&lt;br /&gt;
and enables it. If the user confirms the new configuration by hitting&lt;br /&gt;
the Return key within 10 seconds, the configuration is saved to the&lt;br /&gt;
files. Otherwise, the old configuration is restored.&lt;br /&gt;
&lt;br /&gt;
=== Optional Policies ===&lt;br /&gt;
&lt;br /&gt;
Optional policies can be enabled or disabled using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall&#039;&#039;&#039; {&#039;&#039;&#039;enable&#039;&#039;&#039;|&#039;&#039;&#039;disable&#039;&#039;&#039;} POLICY...&lt;br /&gt;
&lt;br /&gt;
Optional policies can be listed using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall list&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;enabled&#039;&#039;&#039; status means that the policy has been enabled by the&lt;br /&gt;
user. The &#039;&#039;&#039;disabled&#039;&#039;&#039; status means that the policy is not in&lt;br /&gt;
use. The &#039;&#039;&#039;required&#039;&#039;&#039; status means that the policy has not been&lt;br /&gt;
enabled by the user but is in use because it is required by another&lt;br /&gt;
policy which is in use.&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;/div&gt;</summary>
		<author><name>Jiufpt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8052</id>
		<title>Alpine Wall User&#039;s Guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8052"/>
		<updated>2012-05-16T18:58:24Z</updated>

		<summary type="html">&lt;p&gt;Jiufpt: /* IP Sets */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Configuration File Processing ==&lt;br /&gt;
&lt;br /&gt;
[[Alpine Wall]] (awall) reads its configuration from multiple&lt;br /&gt;
JSON-formatted files, called &#039;&#039;policy files&#039;&#039;. The processing starts&lt;br /&gt;
from directory &amp;lt;tt&amp;gt;/usr/share/awall/mandatory&amp;lt;/tt&amp;gt;, which contains&lt;br /&gt;
mandatory policy files shipped with APK packages. After that,&lt;br /&gt;
installation-specific policy files in &amp;lt;tt&amp;gt;/etc/awall&amp;lt;/tt&amp;gt; are&lt;br /&gt;
processed.&lt;br /&gt;
&lt;br /&gt;
The latter directory may also contain symbolic links to policy files&lt;br /&gt;
located in &amp;lt;tt&amp;gt;/usr/share/awall/optional&amp;lt;/tt&amp;gt;. These are optional&lt;br /&gt;
policies, which can be enabled on need basis. Such symbolic links are&lt;br /&gt;
easily created and destroyed using the &amp;lt;tt&amp;gt;awall enable&amp;lt;/tt&amp;gt; and &lt;br /&gt;
&amp;lt;tt&amp;gt;awall disable&amp;lt;/tt&amp;gt; commands. &amp;lt;tt&amp;gt;awall list&amp;lt;/tt&amp;gt; shows which&lt;br /&gt;
optional policies are enabled and disabled. The command also prints&lt;br /&gt;
the description of the optional policy if defined in the file using&lt;br /&gt;
a top-level attribute named &#039;&#039;&#039;description&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Sometimes a policy file depends on other policy files. In this case,&lt;br /&gt;
the policy file must have a top-level attribute &#039;&#039;&#039;import&#039;&#039;&#039;, the&lt;br /&gt;
value of which is a list of policy names, which correspond to the file&lt;br /&gt;
names without the &amp;lt;tt&amp;gt;.json&amp;lt;/tt&amp;gt; suffix. The policies listed there are&lt;br /&gt;
always processed before the importing policy. The order of the&lt;br /&gt;
generated iptables rules generally reflects the processing order of&lt;br /&gt;
their corresponding awall policies.&lt;br /&gt;
&lt;br /&gt;
As the import directive does not require the path name to be&lt;br /&gt;
specified, awall expects policies to have unique names, even if&lt;br /&gt;
located in different directories. It is allowed to import optional&lt;br /&gt;
policies that are not explicitly enabled by the user. Such policies&lt;br /&gt;
show up with the &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; status in the output of &amp;lt;tt&amp;gt;awall&lt;br /&gt;
list&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== List Parameters ==&lt;br /&gt;
&lt;br /&gt;
Several awall parameters are defined as lists of values. In order to&lt;br /&gt;
facilitate manual editing of policy files, awall also accepts single&lt;br /&gt;
values in place of lists. Such values are semantically equivalent to&lt;br /&gt;
lists containing one element.&lt;br /&gt;
&lt;br /&gt;
== Variable Expansion ==&lt;br /&gt;
&lt;br /&gt;
Awall allows variable definitions in policy files. The top-level&lt;br /&gt;
attribute &#039;&#039;&#039;variable&#039;&#039;&#039; is a dictionary containing the&lt;br /&gt;
definitions. The value of a variable can be of any type (string,&lt;br /&gt;
integer, list, or dictionary).&lt;br /&gt;
&lt;br /&gt;
A variable is referenced in policy files by a string which equals the&lt;br /&gt;
variable name prepended with the &#039;&#039;&#039;$&#039;&#039;&#039; character. If the value of&lt;br /&gt;
the variable is a string, the reference can be embedded into a longer&lt;br /&gt;
string in order to substitute some part of that string (in shell&lt;br /&gt;
style). Variable references can be used when defining other variables,&lt;br /&gt;
as long as the definitions are not circular.&lt;br /&gt;
&lt;br /&gt;
Policy files can reference variables defined in other policy&lt;br /&gt;
files. Policy files can also override variables defined elsewhere by&lt;br /&gt;
redefining them. In this case, the new definition affects all policy&lt;br /&gt;
files, also those processed before the overriding policy. Awall&lt;br /&gt;
variables are in fact simple macros, since each variable remains&lt;br /&gt;
constant thoughout a single processing round. If multiple files define&lt;br /&gt;
the same variable, the definition in the file processed last takes&lt;br /&gt;
effect.&lt;br /&gt;
&lt;br /&gt;
If defined as an empty string, all non-embedded references to a&lt;br /&gt;
variable evaluate as if the attribute in question was not present in&lt;br /&gt;
the configuration. This is also the case when a string containing&lt;br /&gt;
embedded variable references finally evaluates to an empty string.&lt;br /&gt;
&lt;br /&gt;
== Configuration Objects ==&lt;br /&gt;
&lt;br /&gt;
Configuration objects can be divided into two main types.&lt;br /&gt;
&#039;&#039;Auxiliary objects&#039;&#039; model high-level concepts such as services and&lt;br /&gt;
zones. &#039;&#039;Rule objects&#039;&#039; translate into one or more iptables rules, and&lt;br /&gt;
are often defined with the help of some auxiliary objects.&lt;br /&gt;
&lt;br /&gt;
=== Services ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;service&#039;&#039; represents a set of network protocols. A top-level&lt;br /&gt;
attribute &#039;&#039;&#039;service&#039;&#039;&#039; is a dictionary that maps service names to&lt;br /&gt;
service definition objects, or lists thereof in more complex cases.&lt;br /&gt;
&lt;br /&gt;
A service definition object contains an attribute named &#039;&#039;&#039;proto&#039;&#039;&#039;,&lt;br /&gt;
which corresponds to the &amp;lt;tt&amp;gt;--protocol&amp;lt;/tt&amp;gt; option of iptables. The&lt;br /&gt;
protocol can be defined as a numerical value or string as defined in&lt;br /&gt;
&amp;lt;tt&amp;gt;/etc/protocols&amp;lt;/tt&amp;gt;. If the protocol is &#039;&#039;&#039;tcp&#039;&#039;&#039; or &#039;&#039;&#039;udp&#039;&#039;&#039;,&lt;br /&gt;
the scope of the service definition may be constrained by defining an&lt;br /&gt;
attribute named &#039;&#039;&#039;port&#039;&#039;&#039;, which is a list of TCP or UDP port&lt;br /&gt;
numbers. If the protocol is &#039;&#039;&#039;icmp&#039;&#039;&#039; or &#039;&#039;&#039;icmpv6&#039;&#039;&#039;, an analogous &lt;br /&gt;
&#039;&#039;&#039;icmp-type&#039;&#039;&#039; attribute may be used. In addition, the scope of the&lt;br /&gt;
rule is also automatically limited to IPv4 or IPv6, respectively.&lt;br /&gt;
&lt;br /&gt;
=== Zones ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;zone&#039;&#039; represents a set of network hosts. A top-level attribute &lt;br /&gt;
&#039;&#039;&#039;zone&#039;&#039;&#039; is a dictionary that maps zone names to zone objects. A&lt;br /&gt;
zone object has an attribute named &#039;&#039;&#039;iface&#039;&#039;&#039;, &#039;&#039;&#039;addr&#039;&#039;&#039;, or&lt;br /&gt;
both. &#039;&#039;&#039;iface&#039;&#039;&#039; is a list of network interfaces and &#039;&#039;&#039;addr&#039;&#039;&#039; is a&lt;br /&gt;
list of IPv4/IPv6 host and network addresses (CIDR&lt;br /&gt;
notation). &#039;&#039;&#039;addr&#039;&#039;&#039; may also contain domain names, which are&lt;br /&gt;
expanded to IP addresses using DNS resolution. If not defined,&lt;br /&gt;
&#039;&#039;&#039;addr&#039;&#039;&#039; defaults to the entire address space and &#039;&#039;&#039;iface&#039;&#039;&#039; to all&lt;br /&gt;
interfaces.&lt;br /&gt;
&lt;br /&gt;
Rule objects contain two attributes, &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;, which are&lt;br /&gt;
lists of zone names. These attributes control whether a packet matches&lt;br /&gt;
the rule or not. If a particular zone is referenced by the &#039;&#039;&#039;in&#039;&#039;&#039; &lt;br /&gt;
attribute, the rule applies to packets whose ingress interface and&lt;br /&gt;
source address are covered by the zone definition. Correspondingly, if&lt;br /&gt;
a zone is referenced by the &#039;&#039;&#039;out&#039;&#039;&#039; attribute, the rule applies to&lt;br /&gt;
packets whose egress interface and destination address are included in&lt;br /&gt;
the zone. If both &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; are defined, the packet must&lt;br /&gt;
fulfill both criteria in order to match the rule.&lt;br /&gt;
&lt;br /&gt;
=== Rules ===&lt;br /&gt;
&lt;br /&gt;
There are three types of rule objects: &#039;&#039;policies&#039;&#039;, &#039;&#039;filters&#039;&#039;, and &lt;br /&gt;
&#039;&#039;NAT rules&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
All rule objects can have the &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; attributes&lt;br /&gt;
referring to zones as described in the previous section. In addition,&lt;br /&gt;
the scope of the rule can be further constrained with the following&lt;br /&gt;
attributes:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Attribute!!Value format!!Effect&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;src&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s source address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;dest&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s destination address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipset&#039;&#039;&#039;&lt;br /&gt;
|Object containing two attributes: &#039;&#039;&#039;name&#039;&#039;&#039; referring to an IP set and &#039;&#039;&#039;args&#039;&#039;&#039;, which is a list of strings &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|Packet matches the IP set referred here when the match arguments are taken from the source (&#039;&#039;&#039;in&#039;&#039;&#039;) and destination (&#039;&#039;&#039;out&#039;&#039;&#039;) address or port in the order specified by &#039;&#039;&#039;args&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipsec&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;in&#039;&#039;&#039; or &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|IPsec decapsulation perfomed on ingress (&#039;&#039;&#039;in&#039;&#039;&#039;) or encapsulation performed on egress (&#039;&#039;&#039;out&#039;&#039;&#039;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects must have an attribute named &#039;&#039;&#039;action&#039;&#039;&#039;, the value of&lt;br /&gt;
which can be one of the following:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Value!!Action&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;accept&#039;&#039;&#039;&lt;br /&gt;
|Accept the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;reject&#039;&#039;&#039;&lt;br /&gt;
|Reject the packet with an ICMP error message&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;drop&#039;&#039;&#039;&lt;br /&gt;
|Silently drop the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;logreject&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;reject&#039;&#039;&#039; but with kernel logging&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;logdrop&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;drop&#039;&#039;&#039; but with kernel logging&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects are declared in type-specific top-level dictionaries in&lt;br /&gt;
awall policy files. If a packet matches multiple rules, the one&lt;br /&gt;
appearing earlier in the list takes precedence. If the matching rules&lt;br /&gt;
are defined in different policy files, the one that was processed&lt;br /&gt;
earlier takes precedence in the current implementation, but this may&lt;br /&gt;
change in future versions.&lt;br /&gt;
&lt;br /&gt;
==== Filters ====&lt;br /&gt;
&lt;br /&gt;
Filter objects specify an action for packets fulfilling certain&lt;br /&gt;
criteria. The top-level attribute &#039;&#039;&#039;filter&#039;&#039;&#039; is a list of filter&lt;br /&gt;
objects. The precedence rules are similar to those of policy objects.&lt;br /&gt;
&lt;br /&gt;
In addition to the common rule attributes, filter objects can have a &lt;br /&gt;
&#039;&#039;&#039;service&#039;&#039;&#039; attribute constraining the scope to specific services&lt;br /&gt;
only. This attribute is a list of service names, referring to the&lt;br /&gt;
keys of the top-level &#039;&#039;&#039;service&#039;&#039;&#039; dictionary.&lt;br /&gt;
&lt;br /&gt;
Filter objects may also contain limits for packet flow or new&lt;br /&gt;
connections. These are specified with the &#039;&#039;&#039;flow-limit&#039;&#039;&#039; and&lt;br /&gt;
&#039;&#039;&#039;conn-limit&#039;&#039;&#039; attributes, respectively. The values of these&lt;br /&gt;
attributes are limit objects that have two attributes: &#039;&#039;&#039;count&#039;&#039;&#039; and&lt;br /&gt;
&#039;&#039;&#039;interval&#039;&#039;&#039;. &#039;&#039;&#039;count&#039;&#039;&#039; specifies how many new connections or&lt;br /&gt;
packets are allowed within the time frame specified by &#039;&#039;&#039;interval&#039;&#039;&#039; &lt;br /&gt;
(in seconds). The &#039;&#039;&#039;logdrop&#039;&#039;&#039; action is applied to the packets&lt;br /&gt;
exceeding the limit.&lt;br /&gt;
&lt;br /&gt;
Filter objects may have an attribute named &#039;&#039;&#039;dnat&#039;&#039;&#039;, the value of&lt;br /&gt;
which is an IPv4 address. If defined, this enables destination NAT for&lt;br /&gt;
all IPv4 packets matching the rule, such that the specified address&lt;br /&gt;
replaces the original destination address. This option has no effect&lt;br /&gt;
on IPv6 packets.&lt;br /&gt;
&lt;br /&gt;
==== Policies ====&lt;br /&gt;
&lt;br /&gt;
Policy objects describe the default action for packets that did not&lt;br /&gt;
match any filter. The top-level attribute &#039;&#039;&#039;policy&#039;&#039;&#039; is a list of&lt;br /&gt;
policy objects. Policy objects do not have other attributes than those&lt;br /&gt;
common to all rule objects.&lt;br /&gt;
&lt;br /&gt;
==== NAT Rules ====&lt;br /&gt;
&lt;br /&gt;
NAT rules come in two flavors: &#039;&#039;source NAT rules&#039;&#039; and&lt;br /&gt;
&#039;&#039;destination NAT rules&#039;&#039;. These are contained in two top-level lists&lt;br /&gt;
named &#039;&#039;&#039;snat&#039;&#039;&#039; and &#039;&#039;&#039;dnat&#039;&#039;&#039;, respectively.&lt;br /&gt;
&lt;br /&gt;
Each NAT rule must have an attribute named &#039;&#039;&#039;ip-range&#039;&#039;&#039; that&lt;br /&gt;
specifies the IPv4 address range to which the original source or&lt;br /&gt;
destinatinon address is mapped. The value can be a single IPv4 address&lt;br /&gt;
or a range specified by two addresses, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character.&lt;br /&gt;
&lt;br /&gt;
Optionally, a NAT rule can specify the TCP and UDP port range to which&lt;br /&gt;
the original source or destination port is mapped. The attribute is&lt;br /&gt;
named &#039;&#039;&#039;port-range&#039;&#039;&#039;, and the value can be a single port number or a&lt;br /&gt;
range specified by two numbers, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character. If &#039;&#039;&#039;port-range&#039;&#039;&#039; is not specified, the original port&lt;br /&gt;
number is kept intact.&lt;br /&gt;
&lt;br /&gt;
Like filters, NAT rules can have a &#039;&#039;&#039;service&#039;&#039;&#039; attribute&lt;br /&gt;
constraining their scope to specific services.&lt;br /&gt;
&lt;br /&gt;
=== IP Sets ===&lt;br /&gt;
&lt;br /&gt;
Any IP set referenced by rule objects should be created by&lt;br /&gt;
awall. Auxiliary &#039;&#039;IP set&#039;&#039; objects are used to defined them in awall&lt;br /&gt;
policy files. The top-level attribute &#039;&#039;&#039;ipset&#039;&#039;&#039; is a dictionary, the&lt;br /&gt;
keys of which are IP set names. The values are IP set objects, which&lt;br /&gt;
have two mandatory attributes. The attribute named &#039;&#039;&#039;type&#039;&#039;&#039; &lt;br /&gt;
corresponds to the type argument of the &amp;lt;tt&amp;gt;ipset create&amp;lt;/tt&amp;gt; &lt;br /&gt;
command. &#039;&#039;&#039;family&#039;&#039;&#039; specifies whether the set is for IPv4 or IPv6&lt;br /&gt;
addresses, and the possible values are &#039;&#039;&#039;inet&#039;&#039;&#039; and &#039;&#039;&#039;inet6&#039;&#039;&#039;,&lt;br /&gt;
correspondingly.&lt;br /&gt;
&lt;br /&gt;
== Command Line Syntax ==&lt;br /&gt;
&lt;br /&gt;
=== Translating Policy Files to Firewall Configuration Files ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall translate&#039;&#039;&#039; [&#039;&#039;&#039;-o&#039;&#039;&#039;|&#039;&#039;&#039;--output&#039;&#039;&#039; DIRECTORY] [&#039;&#039;&#039;-V&#039;&#039;&#039;|&#039;&#039;&#039;--verify&#039;&#039;&#039;]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--verify&amp;lt;/tt&amp;gt; option makes awall verify the configuration&lt;br /&gt;
using the test mode of iptables-restore before overwriting the old&lt;br /&gt;
files.&lt;br /&gt;
&lt;br /&gt;
Specifying the output directory allows testing awall policies without&lt;br /&gt;
overwriting the current iptables and ipset configuration files. By&lt;br /&gt;
default, awall generates the configuration to &amp;lt;tt&amp;gt;/etc/iptables&amp;lt;/tt&amp;gt;&lt;br /&gt;
and &amp;lt;tt&amp;gt;/etc/ipset.d&amp;lt;/tt&amp;gt;, which are read by the init scripts.&lt;br /&gt;
&lt;br /&gt;
=== Run-Time Activation of New Firewall Configuration ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall activate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This command genereates firewall configuration from the policy files&lt;br /&gt;
and enables it. If the user confirms the new configuration by hitting&lt;br /&gt;
the Return key within 10 seconds, the configuration is saved to the&lt;br /&gt;
files. Otherwise, the old configuration is restored.&lt;br /&gt;
&lt;br /&gt;
=== Optional Policies ===&lt;br /&gt;
&lt;br /&gt;
Optional policies can be enabled or disabled using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall&#039;&#039;&#039; {&#039;&#039;&#039;enable&#039;&#039;&#039;|&#039;&#039;&#039;disable&#039;&#039;&#039;} POLICY...&lt;br /&gt;
&lt;br /&gt;
Optional policies can be listed using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall list&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;enabled&#039;&#039;&#039; status means that the policy has been enabled by the&lt;br /&gt;
user. The &#039;&#039;&#039;disabled&#039;&#039;&#039; status means that the policy is not in&lt;br /&gt;
use. The &#039;&#039;&#039;required&#039;&#039;&#039; status means that the policy has not been&lt;br /&gt;
enabled by the user but is in use because it is required by another&lt;br /&gt;
policy which is in use.&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;/div&gt;</summary>
		<author><name>Jiufpt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8051</id>
		<title>Alpine Wall User&#039;s Guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8051"/>
		<updated>2012-05-16T18:56:24Z</updated>

		<summary type="html">&lt;p&gt;Jiufpt: /* Filters */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Configuration File Processing ==&lt;br /&gt;
&lt;br /&gt;
[[Alpine Wall]] (awall) reads its configuration from multiple&lt;br /&gt;
JSON-formatted files, called &#039;&#039;policy files&#039;&#039;. The processing starts&lt;br /&gt;
from directory &amp;lt;tt&amp;gt;/usr/share/awall/mandatory&amp;lt;/tt&amp;gt;, which contains&lt;br /&gt;
mandatory policy files shipped with APK packages. After that,&lt;br /&gt;
installation-specific policy files in &amp;lt;tt&amp;gt;/etc/awall&amp;lt;/tt&amp;gt; are&lt;br /&gt;
processed.&lt;br /&gt;
&lt;br /&gt;
The latter directory may also contain symbolic links to policy files&lt;br /&gt;
located in &amp;lt;tt&amp;gt;/usr/share/awall/optional&amp;lt;/tt&amp;gt;. These are optional&lt;br /&gt;
policies, which can be enabled on need basis. Such symbolic links are&lt;br /&gt;
easily created and destroyed using the &amp;lt;tt&amp;gt;awall enable&amp;lt;/tt&amp;gt; and &lt;br /&gt;
&amp;lt;tt&amp;gt;awall disable&amp;lt;/tt&amp;gt; commands. &amp;lt;tt&amp;gt;awall list&amp;lt;/tt&amp;gt; shows which&lt;br /&gt;
optional policies are enabled and disabled. The command also prints&lt;br /&gt;
the description of the optional policy if defined in the file using&lt;br /&gt;
a top-level attribute named &#039;&#039;&#039;description&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Sometimes a policy file depends on other policy files. In this case,&lt;br /&gt;
the policy file must have a top-level attribute &#039;&#039;&#039;import&#039;&#039;&#039;, the&lt;br /&gt;
value of which is a list of policy names, which correspond to the file&lt;br /&gt;
names without the &amp;lt;tt&amp;gt;.json&amp;lt;/tt&amp;gt; suffix. The policies listed there are&lt;br /&gt;
always processed before the importing policy. The order of the&lt;br /&gt;
generated iptables rules generally reflects the processing order of&lt;br /&gt;
their corresponding awall policies.&lt;br /&gt;
&lt;br /&gt;
As the import directive does not require the path name to be&lt;br /&gt;
specified, awall expects policies to have unique names, even if&lt;br /&gt;
located in different directories. It is allowed to import optional&lt;br /&gt;
policies that are not explicitly enabled by the user. Such policies&lt;br /&gt;
show up with the &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; status in the output of &amp;lt;tt&amp;gt;awall&lt;br /&gt;
list&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== List Parameters ==&lt;br /&gt;
&lt;br /&gt;
Several awall parameters are defined as lists of values. In order to&lt;br /&gt;
facilitate manual editing of policy files, awall also accepts single&lt;br /&gt;
values in place of lists. Such values are semantically equivalent to&lt;br /&gt;
lists containing one element.&lt;br /&gt;
&lt;br /&gt;
== Variable Expansion ==&lt;br /&gt;
&lt;br /&gt;
Awall allows variable definitions in policy files. The top-level&lt;br /&gt;
attribute &#039;&#039;&#039;variable&#039;&#039;&#039; is a dictionary containing the&lt;br /&gt;
definitions. The value of a variable can be of any type (string,&lt;br /&gt;
integer, list, or dictionary).&lt;br /&gt;
&lt;br /&gt;
A variable is referenced in policy files by a string which equals the&lt;br /&gt;
variable name prepended with the &#039;&#039;&#039;$&#039;&#039;&#039; character. If the value of&lt;br /&gt;
the variable is a string, the reference can be embedded into a longer&lt;br /&gt;
string in order to substitute some part of that string (in shell&lt;br /&gt;
style). Variable references can be used when defining other variables,&lt;br /&gt;
as long as the definitions are not circular.&lt;br /&gt;
&lt;br /&gt;
Policy files can reference variables defined in other policy&lt;br /&gt;
files. Policy files can also override variables defined elsewhere by&lt;br /&gt;
redefining them. In this case, the new definition affects all policy&lt;br /&gt;
files, also those processed before the overriding policy. Awall&lt;br /&gt;
variables are in fact simple macros, since each variable remains&lt;br /&gt;
constant thoughout a single processing round. If multiple files define&lt;br /&gt;
the same variable, the definition in the file processed last takes&lt;br /&gt;
effect.&lt;br /&gt;
&lt;br /&gt;
If defined as an empty string, all non-embedded references to a&lt;br /&gt;
variable evaluate as if the attribute in question was not present in&lt;br /&gt;
the configuration. This is also the case when a string containing&lt;br /&gt;
embedded variable references finally evaluates to an empty string.&lt;br /&gt;
&lt;br /&gt;
== Configuration Objects ==&lt;br /&gt;
&lt;br /&gt;
Configuration objects can be divided into two main types.&lt;br /&gt;
&#039;&#039;Auxiliary objects&#039;&#039; model high-level concepts such as services and&lt;br /&gt;
zones. &#039;&#039;Rule objects&#039;&#039; translate into one or more iptables rules, and&lt;br /&gt;
are often defined with the help of some auxiliary objects.&lt;br /&gt;
&lt;br /&gt;
=== Services ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;service&#039;&#039; represents a set of network protocols. A top-level&lt;br /&gt;
attribute &#039;&#039;&#039;service&#039;&#039;&#039; is a dictionary that maps service names to&lt;br /&gt;
service definition objects, or lists thereof in more complex cases.&lt;br /&gt;
&lt;br /&gt;
A service definition object contains an attribute named &#039;&#039;&#039;proto&#039;&#039;&#039;,&lt;br /&gt;
which corresponds to the &amp;lt;tt&amp;gt;--protocol&amp;lt;/tt&amp;gt; option of iptables. The&lt;br /&gt;
protocol can be defined as a numerical value or string as defined in&lt;br /&gt;
&amp;lt;tt&amp;gt;/etc/protocols&amp;lt;/tt&amp;gt;. If the protocol is &#039;&#039;&#039;tcp&#039;&#039;&#039; or &#039;&#039;&#039;udp&#039;&#039;&#039;,&lt;br /&gt;
the scope of the service definition may be constrained by defining an&lt;br /&gt;
attribute named &#039;&#039;&#039;port&#039;&#039;&#039;, which is a list of TCP or UDP port&lt;br /&gt;
numbers. If the protocol is &#039;&#039;&#039;icmp&#039;&#039;&#039; or &#039;&#039;&#039;icmpv6&#039;&#039;&#039;, an analogous &lt;br /&gt;
&#039;&#039;&#039;icmp-type&#039;&#039;&#039; attribute may be used. In addition, the scope of the&lt;br /&gt;
rule is also automatically limited to IPv4 or IPv6, respectively.&lt;br /&gt;
&lt;br /&gt;
=== Zones ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;zone&#039;&#039; represents a set of network hosts. A top-level attribute &lt;br /&gt;
&#039;&#039;&#039;zone&#039;&#039;&#039; is a dictionary that maps zone names to zone objects. A&lt;br /&gt;
zone object has an attribute named &#039;&#039;&#039;iface&#039;&#039;&#039;, &#039;&#039;&#039;addr&#039;&#039;&#039;, or&lt;br /&gt;
both. &#039;&#039;&#039;iface&#039;&#039;&#039; is a list of network interfaces and &#039;&#039;&#039;addr&#039;&#039;&#039; is a&lt;br /&gt;
list of IPv4/IPv6 host and network addresses (CIDR&lt;br /&gt;
notation). &#039;&#039;&#039;addr&#039;&#039;&#039; may also contain domain names, which are&lt;br /&gt;
expanded to IP addresses using DNS resolution. If not defined,&lt;br /&gt;
&#039;&#039;&#039;addr&#039;&#039;&#039; defaults to the entire address space and &#039;&#039;&#039;iface&#039;&#039;&#039; to all&lt;br /&gt;
interfaces.&lt;br /&gt;
&lt;br /&gt;
Rule objects contain two attributes, &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;, which are&lt;br /&gt;
lists of zone names. These attributes control whether a packet matches&lt;br /&gt;
the rule or not. If a particular zone is referenced by the &#039;&#039;&#039;in&#039;&#039;&#039; &lt;br /&gt;
attribute, the rule applies to packets whose ingress interface and&lt;br /&gt;
source address are covered by the zone definition. Correspondingly, if&lt;br /&gt;
a zone is referenced by the &#039;&#039;&#039;out&#039;&#039;&#039; attribute, the rule applies to&lt;br /&gt;
packets whose egress interface and destination address are included in&lt;br /&gt;
the zone. If both &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; are defined, the packet must&lt;br /&gt;
fulfill both criteria in order to match the rule.&lt;br /&gt;
&lt;br /&gt;
=== Rules ===&lt;br /&gt;
&lt;br /&gt;
There are three types of rule objects: &#039;&#039;policies&#039;&#039;, &#039;&#039;filters&#039;&#039;, and &lt;br /&gt;
&#039;&#039;NAT rules&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
All rule objects can have the &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; attributes&lt;br /&gt;
referring to zones as described in the previous section. In addition,&lt;br /&gt;
the scope of the rule can be further constrained with the following&lt;br /&gt;
attributes:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Attribute!!Value format!!Effect&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;src&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s source address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;dest&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s destination address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipset&#039;&#039;&#039;&lt;br /&gt;
|Object containing two attributes: &#039;&#039;&#039;name&#039;&#039;&#039; referring to an IP set and &#039;&#039;&#039;args&#039;&#039;&#039;, which is a list of strings &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|Packet matches the IP set referred here when the match arguments are taken from the source (&#039;&#039;&#039;in&#039;&#039;&#039;) and destination (&#039;&#039;&#039;out&#039;&#039;&#039;) address or port in the order specified by &#039;&#039;&#039;args&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipsec&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;in&#039;&#039;&#039; or &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|IPsec decapsulation perfomed on ingress (&#039;&#039;&#039;in&#039;&#039;&#039;) or encapsulation performed on egress (&#039;&#039;&#039;out&#039;&#039;&#039;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects must have an attribute named &#039;&#039;&#039;action&#039;&#039;&#039;, the value of&lt;br /&gt;
which can be one of the following:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Value!!Action&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;accept&#039;&#039;&#039;&lt;br /&gt;
|Accept the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;reject&#039;&#039;&#039;&lt;br /&gt;
|Reject the packet with an ICMP error message&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;drop&#039;&#039;&#039;&lt;br /&gt;
|Silently drop the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;logreject&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;reject&#039;&#039;&#039; but with kernel logging&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;logdrop&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;drop&#039;&#039;&#039; but with kernel logging&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects are declared in type-specific top-level dictionaries in&lt;br /&gt;
awall policy files. If a packet matches multiple rules, the one&lt;br /&gt;
appearing earlier in the list takes precedence. If the matching rules&lt;br /&gt;
are defined in different policy files, the one that was processed&lt;br /&gt;
earlier takes precedence in the current implementation, but this may&lt;br /&gt;
change in future versions.&lt;br /&gt;
&lt;br /&gt;
==== Filters ====&lt;br /&gt;
&lt;br /&gt;
Filter objects specify an action for packets fulfilling certain&lt;br /&gt;
criteria. The top-level attribute &#039;&#039;&#039;filter&#039;&#039;&#039; is a list of filter&lt;br /&gt;
objects. The precedence rules are similar to those of policy objects.&lt;br /&gt;
&lt;br /&gt;
In addition to the common rule attributes, filter objects can have a &lt;br /&gt;
&#039;&#039;&#039;service&#039;&#039;&#039; attribute constraining the scope to specific services&lt;br /&gt;
only. This attribute is a list of service names, referring to the&lt;br /&gt;
keys of the top-level &#039;&#039;&#039;service&#039;&#039;&#039; dictionary.&lt;br /&gt;
&lt;br /&gt;
Filter objects may also contain limits for packet flow or new&lt;br /&gt;
connections. These are specified with the &#039;&#039;&#039;flow-limit&#039;&#039;&#039; and&lt;br /&gt;
&#039;&#039;&#039;conn-limit&#039;&#039;&#039; attributes, respectively. The values of these&lt;br /&gt;
attributes are limit objects that have two attributes: &#039;&#039;&#039;count&#039;&#039;&#039; and&lt;br /&gt;
&#039;&#039;&#039;interval&#039;&#039;&#039;. &#039;&#039;&#039;count&#039;&#039;&#039; specifies how many new connections or&lt;br /&gt;
packets are allowed within the time frame specified by &#039;&#039;&#039;interval&#039;&#039;&#039; &lt;br /&gt;
(in seconds). The &#039;&#039;&#039;logdrop&#039;&#039;&#039; action is applied to the packets&lt;br /&gt;
exceeding the limit.&lt;br /&gt;
&lt;br /&gt;
Filter objects may have an attribute named &#039;&#039;&#039;dnat&#039;&#039;&#039;, the value of&lt;br /&gt;
which is an IPv4 address. If defined, this enables destination NAT for&lt;br /&gt;
all IPv4 packets matching the rule, such that the specified address&lt;br /&gt;
replaces the original destination address. This option has no effect&lt;br /&gt;
on IPv6 packets.&lt;br /&gt;
&lt;br /&gt;
==== Policies ====&lt;br /&gt;
&lt;br /&gt;
Policy objects describe the default action for packets that did not&lt;br /&gt;
match any filter. The top-level attribute &#039;&#039;&#039;policy&#039;&#039;&#039; is a list of&lt;br /&gt;
policy objects. Policy objects do not have other attributes than those&lt;br /&gt;
common to all rule objects.&lt;br /&gt;
&lt;br /&gt;
==== NAT Rules ====&lt;br /&gt;
&lt;br /&gt;
NAT rules come in two flavors: &#039;&#039;source NAT rules&#039;&#039; and&lt;br /&gt;
&#039;&#039;destination NAT rules&#039;&#039;. These are contained in two top-level lists&lt;br /&gt;
named &#039;&#039;&#039;snat&#039;&#039;&#039; and &#039;&#039;&#039;dnat&#039;&#039;&#039;, respectively.&lt;br /&gt;
&lt;br /&gt;
Each NAT rule must have an attribute named &#039;&#039;&#039;ip-range&#039;&#039;&#039; that&lt;br /&gt;
specifies the IPv4 address range to which the original source or&lt;br /&gt;
destinatinon address is mapped. The value can be a single IPv4 address&lt;br /&gt;
or a range specified by two addresses, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character.&lt;br /&gt;
&lt;br /&gt;
Optionally, a NAT rule can specify the TCP and UDP port range to which&lt;br /&gt;
the original source or destination port is mapped. The attribute is&lt;br /&gt;
named &#039;&#039;&#039;port-range&#039;&#039;&#039;, and the value can be a single port number or a&lt;br /&gt;
range specified by two numbers, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character. If &#039;&#039;&#039;port-range&#039;&#039;&#039; is not specified, the original port&lt;br /&gt;
number is kept intact.&lt;br /&gt;
&lt;br /&gt;
Like filters, NAT rules can have a &#039;&#039;&#039;service&#039;&#039;&#039; attribute&lt;br /&gt;
constraining their scope to specific services.&lt;br /&gt;
&lt;br /&gt;
=== IP Sets ===&lt;br /&gt;
&lt;br /&gt;
Any IP set referenced by rule objects should be created by&lt;br /&gt;
awall. Auxiliary &#039;&#039;IP set&#039;&#039; objects are used to defined them in awall&lt;br /&gt;
policy files. The top-level attribute &#039;&#039;&#039;ipset&#039;&#039;&#039; is a dictionary, the&lt;br /&gt;
keys of which are IP set names. The values are IP set objects, which&lt;br /&gt;
have two mandatory attributes. The attribute named &#039;&#039;&#039;type&#039;&#039;&#039;&lt;br /&gt;
corresponds to the type argument of the &amp;lt;tt&amp;gt;ipset create&amp;lt;/tt&amp;gt;&lt;br /&gt;
command. &#039;&#039;&#039;family&#039;&#039;&#039; specifies whether the set is for IPv4 or IPv6&lt;br /&gt;
addresses, and the possible values are &#039;&#039;&#039;inet&#039;&#039;&#039; and &#039;&#039;&#039;inet6&#039;&#039;&#039;,&lt;br /&gt;
correspondingly.&lt;br /&gt;
&lt;br /&gt;
== Command Line Syntax ==&lt;br /&gt;
&lt;br /&gt;
=== Translating Policy Files to Firewall Configuration Files ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall translate&#039;&#039;&#039; [&#039;&#039;&#039;-o&#039;&#039;&#039;|&#039;&#039;&#039;--output&#039;&#039;&#039; DIRECTORY] [&#039;&#039;&#039;-V&#039;&#039;&#039;|&#039;&#039;&#039;--verify&#039;&#039;&#039;]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--verify&amp;lt;/tt&amp;gt; option makes awall verify the configuration&lt;br /&gt;
using the test mode of iptables-restore before overwriting the old&lt;br /&gt;
files.&lt;br /&gt;
&lt;br /&gt;
Specifying the output directory allows testing awall policies without&lt;br /&gt;
overwriting the current iptables and ipset configuration files. By&lt;br /&gt;
default, awall generates the configuration to &amp;lt;tt&amp;gt;/etc/iptables&amp;lt;/tt&amp;gt;&lt;br /&gt;
and &amp;lt;tt&amp;gt;/etc/ipset.d&amp;lt;/tt&amp;gt;, which are read by the init scripts.&lt;br /&gt;
&lt;br /&gt;
=== Run-Time Activation of New Firewall Configuration ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall activate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This command genereates firewall configuration from the policy files&lt;br /&gt;
and enables it. If the user confirms the new configuration by hitting&lt;br /&gt;
the Return key within 10 seconds, the configuration is saved to the&lt;br /&gt;
files. Otherwise, the old configuration is restored.&lt;br /&gt;
&lt;br /&gt;
=== Optional Policies ===&lt;br /&gt;
&lt;br /&gt;
Optional policies can be enabled or disabled using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall&#039;&#039;&#039; {&#039;&#039;&#039;enable&#039;&#039;&#039;|&#039;&#039;&#039;disable&#039;&#039;&#039;} POLICY...&lt;br /&gt;
&lt;br /&gt;
Optional policies can be listed using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall list&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;enabled&#039;&#039;&#039; status means that the policy has been enabled by the&lt;br /&gt;
user. The &#039;&#039;&#039;disabled&#039;&#039;&#039; status means that the policy is not in&lt;br /&gt;
use. The &#039;&#039;&#039;required&#039;&#039;&#039; status means that the policy has not been&lt;br /&gt;
enabled by the user but is in use because it is required by another&lt;br /&gt;
policy which is in use.&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;/div&gt;</summary>
		<author><name>Jiufpt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8050</id>
		<title>Alpine Wall User&#039;s Guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8050"/>
		<updated>2012-05-16T18:54:24Z</updated>

		<summary type="html">&lt;p&gt;Jiufpt: /* Rules */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Configuration File Processing ==&lt;br /&gt;
&lt;br /&gt;
[[Alpine Wall]] (awall) reads its configuration from multiple&lt;br /&gt;
JSON-formatted files, called &#039;&#039;policy files&#039;&#039;. The processing starts&lt;br /&gt;
from directory &amp;lt;tt&amp;gt;/usr/share/awall/mandatory&amp;lt;/tt&amp;gt;, which contains&lt;br /&gt;
mandatory policy files shipped with APK packages. After that,&lt;br /&gt;
installation-specific policy files in &amp;lt;tt&amp;gt;/etc/awall&amp;lt;/tt&amp;gt; are&lt;br /&gt;
processed.&lt;br /&gt;
&lt;br /&gt;
The latter directory may also contain symbolic links to policy files&lt;br /&gt;
located in &amp;lt;tt&amp;gt;/usr/share/awall/optional&amp;lt;/tt&amp;gt;. These are optional&lt;br /&gt;
policies, which can be enabled on need basis. Such symbolic links are&lt;br /&gt;
easily created and destroyed using the &amp;lt;tt&amp;gt;awall enable&amp;lt;/tt&amp;gt; and &lt;br /&gt;
&amp;lt;tt&amp;gt;awall disable&amp;lt;/tt&amp;gt; commands. &amp;lt;tt&amp;gt;awall list&amp;lt;/tt&amp;gt; shows which&lt;br /&gt;
optional policies are enabled and disabled. The command also prints&lt;br /&gt;
the description of the optional policy if defined in the file using&lt;br /&gt;
a top-level attribute named &#039;&#039;&#039;description&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Sometimes a policy file depends on other policy files. In this case,&lt;br /&gt;
the policy file must have a top-level attribute &#039;&#039;&#039;import&#039;&#039;&#039;, the&lt;br /&gt;
value of which is a list of policy names, which correspond to the file&lt;br /&gt;
names without the &amp;lt;tt&amp;gt;.json&amp;lt;/tt&amp;gt; suffix. The policies listed there are&lt;br /&gt;
always processed before the importing policy. The order of the&lt;br /&gt;
generated iptables rules generally reflects the processing order of&lt;br /&gt;
their corresponding awall policies.&lt;br /&gt;
&lt;br /&gt;
As the import directive does not require the path name to be&lt;br /&gt;
specified, awall expects policies to have unique names, even if&lt;br /&gt;
located in different directories. It is allowed to import optional&lt;br /&gt;
policies that are not explicitly enabled by the user. Such policies&lt;br /&gt;
show up with the &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; status in the output of &amp;lt;tt&amp;gt;awall&lt;br /&gt;
list&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== List Parameters ==&lt;br /&gt;
&lt;br /&gt;
Several awall parameters are defined as lists of values. In order to&lt;br /&gt;
facilitate manual editing of policy files, awall also accepts single&lt;br /&gt;
values in place of lists. Such values are semantically equivalent to&lt;br /&gt;
lists containing one element.&lt;br /&gt;
&lt;br /&gt;
== Variable Expansion ==&lt;br /&gt;
&lt;br /&gt;
Awall allows variable definitions in policy files. The top-level&lt;br /&gt;
attribute &#039;&#039;&#039;variable&#039;&#039;&#039; is a dictionary containing the&lt;br /&gt;
definitions. The value of a variable can be of any type (string,&lt;br /&gt;
integer, list, or dictionary).&lt;br /&gt;
&lt;br /&gt;
A variable is referenced in policy files by a string which equals the&lt;br /&gt;
variable name prepended with the &#039;&#039;&#039;$&#039;&#039;&#039; character. If the value of&lt;br /&gt;
the variable is a string, the reference can be embedded into a longer&lt;br /&gt;
string in order to substitute some part of that string (in shell&lt;br /&gt;
style). Variable references can be used when defining other variables,&lt;br /&gt;
as long as the definitions are not circular.&lt;br /&gt;
&lt;br /&gt;
Policy files can reference variables defined in other policy&lt;br /&gt;
files. Policy files can also override variables defined elsewhere by&lt;br /&gt;
redefining them. In this case, the new definition affects all policy&lt;br /&gt;
files, also those processed before the overriding policy. Awall&lt;br /&gt;
variables are in fact simple macros, since each variable remains&lt;br /&gt;
constant thoughout a single processing round. If multiple files define&lt;br /&gt;
the same variable, the definition in the file processed last takes&lt;br /&gt;
effect.&lt;br /&gt;
&lt;br /&gt;
If defined as an empty string, all non-embedded references to a&lt;br /&gt;
variable evaluate as if the attribute in question was not present in&lt;br /&gt;
the configuration. This is also the case when a string containing&lt;br /&gt;
embedded variable references finally evaluates to an empty string.&lt;br /&gt;
&lt;br /&gt;
== Configuration Objects ==&lt;br /&gt;
&lt;br /&gt;
Configuration objects can be divided into two main types.&lt;br /&gt;
&#039;&#039;Auxiliary objects&#039;&#039; model high-level concepts such as services and&lt;br /&gt;
zones. &#039;&#039;Rule objects&#039;&#039; translate into one or more iptables rules, and&lt;br /&gt;
are often defined with the help of some auxiliary objects.&lt;br /&gt;
&lt;br /&gt;
=== Services ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;service&#039;&#039; represents a set of network protocols. A top-level&lt;br /&gt;
attribute &#039;&#039;&#039;service&#039;&#039;&#039; is a dictionary that maps service names to&lt;br /&gt;
service definition objects, or lists thereof in more complex cases.&lt;br /&gt;
&lt;br /&gt;
A service definition object contains an attribute named &#039;&#039;&#039;proto&#039;&#039;&#039;,&lt;br /&gt;
which corresponds to the &amp;lt;tt&amp;gt;--protocol&amp;lt;/tt&amp;gt; option of iptables. The&lt;br /&gt;
protocol can be defined as a numerical value or string as defined in&lt;br /&gt;
&amp;lt;tt&amp;gt;/etc/protocols&amp;lt;/tt&amp;gt;. If the protocol is &#039;&#039;&#039;tcp&#039;&#039;&#039; or &#039;&#039;&#039;udp&#039;&#039;&#039;,&lt;br /&gt;
the scope of the service definition may be constrained by defining an&lt;br /&gt;
attribute named &#039;&#039;&#039;port&#039;&#039;&#039;, which is a list of TCP or UDP port&lt;br /&gt;
numbers. If the protocol is &#039;&#039;&#039;icmp&#039;&#039;&#039; or &#039;&#039;&#039;icmpv6&#039;&#039;&#039;, an analogous &lt;br /&gt;
&#039;&#039;&#039;icmp-type&#039;&#039;&#039; attribute may be used. In addition, the scope of the&lt;br /&gt;
rule is also automatically limited to IPv4 or IPv6, respectively.&lt;br /&gt;
&lt;br /&gt;
=== Zones ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;zone&#039;&#039; represents a set of network hosts. A top-level attribute &lt;br /&gt;
&#039;&#039;&#039;zone&#039;&#039;&#039; is a dictionary that maps zone names to zone objects. A&lt;br /&gt;
zone object has an attribute named &#039;&#039;&#039;iface&#039;&#039;&#039;, &#039;&#039;&#039;addr&#039;&#039;&#039;, or&lt;br /&gt;
both. &#039;&#039;&#039;iface&#039;&#039;&#039; is a list of network interfaces and &#039;&#039;&#039;addr&#039;&#039;&#039; is a&lt;br /&gt;
list of IPv4/IPv6 host and network addresses (CIDR&lt;br /&gt;
notation). &#039;&#039;&#039;addr&#039;&#039;&#039; may also contain domain names, which are&lt;br /&gt;
expanded to IP addresses using DNS resolution. If not defined,&lt;br /&gt;
&#039;&#039;&#039;addr&#039;&#039;&#039; defaults to the entire address space and &#039;&#039;&#039;iface&#039;&#039;&#039; to all&lt;br /&gt;
interfaces.&lt;br /&gt;
&lt;br /&gt;
Rule objects contain two attributes, &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;, which are&lt;br /&gt;
lists of zone names. These attributes control whether a packet matches&lt;br /&gt;
the rule or not. If a particular zone is referenced by the &#039;&#039;&#039;in&#039;&#039;&#039; &lt;br /&gt;
attribute, the rule applies to packets whose ingress interface and&lt;br /&gt;
source address are covered by the zone definition. Correspondingly, if&lt;br /&gt;
a zone is referenced by the &#039;&#039;&#039;out&#039;&#039;&#039; attribute, the rule applies to&lt;br /&gt;
packets whose egress interface and destination address are included in&lt;br /&gt;
the zone. If both &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; are defined, the packet must&lt;br /&gt;
fulfill both criteria in order to match the rule.&lt;br /&gt;
&lt;br /&gt;
=== Rules ===&lt;br /&gt;
&lt;br /&gt;
There are three types of rule objects: &#039;&#039;policies&#039;&#039;, &#039;&#039;filters&#039;&#039;, and &lt;br /&gt;
&#039;&#039;NAT rules&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
All rule objects can have the &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; attributes&lt;br /&gt;
referring to zones as described in the previous section. In addition,&lt;br /&gt;
the scope of the rule can be further constrained with the following&lt;br /&gt;
attributes:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Attribute!!Value format!!Effect&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;src&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s source address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;dest&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s destination address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipset&#039;&#039;&#039;&lt;br /&gt;
|Object containing two attributes: &#039;&#039;&#039;name&#039;&#039;&#039; referring to an IP set and &#039;&#039;&#039;args&#039;&#039;&#039;, which is a list of strings &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|Packet matches the IP set referred here when the match arguments are taken from the source (&#039;&#039;&#039;in&#039;&#039;&#039;) and destination (&#039;&#039;&#039;out&#039;&#039;&#039;) address or port in the order specified by &#039;&#039;&#039;args&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipsec&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;in&#039;&#039;&#039; or &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|IPsec decapsulation perfomed on ingress (&#039;&#039;&#039;in&#039;&#039;&#039;) or encapsulation performed on egress (&#039;&#039;&#039;out&#039;&#039;&#039;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects must have an attribute named &#039;&#039;&#039;action&#039;&#039;&#039;, the value of&lt;br /&gt;
which can be one of the following:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Value!!Action&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;accept&#039;&#039;&#039;&lt;br /&gt;
|Accept the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;reject&#039;&#039;&#039;&lt;br /&gt;
|Reject the packet with an ICMP error message&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;drop&#039;&#039;&#039;&lt;br /&gt;
|Silently drop the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;logreject&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;reject&#039;&#039;&#039; but with kernel logging&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;logdrop&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;drop&#039;&#039;&#039; but with kernel logging&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects are declared in type-specific top-level dictionaries in&lt;br /&gt;
awall policy files. If a packet matches multiple rules, the one&lt;br /&gt;
appearing earlier in the list takes precedence. If the matching rules&lt;br /&gt;
are defined in different policy files, the one that was processed&lt;br /&gt;
earlier takes precedence in the current implementation, but this may&lt;br /&gt;
change in future versions.&lt;br /&gt;
&lt;br /&gt;
==== Filters ====&lt;br /&gt;
&lt;br /&gt;
Filter objects specify an action for packets fulfilling certain&lt;br /&gt;
criteria. The top-level attribute &#039;&#039;&#039;filter&#039;&#039;&#039; is a list of filter&lt;br /&gt;
objects. The precedence rules are similar to those of policy objects.&lt;br /&gt;
&lt;br /&gt;
In addition to the common rule attributes, filter objects can have a&lt;br /&gt;
&#039;&#039;&#039;service&#039;&#039;&#039; attribute constraining the scope to specific services&lt;br /&gt;
only. This attribute is a list of service names, referring to the&lt;br /&gt;
keys of the top-level &#039;&#039;&#039;service&#039;&#039;&#039; dictionary.&lt;br /&gt;
&lt;br /&gt;
Filter objects may also contain limits for packet flow or new&lt;br /&gt;
connections. These are specified with the &#039;&#039;&#039;flow-limit&#039;&#039;&#039; and&lt;br /&gt;
&#039;&#039;&#039;conn-limit&#039;&#039;&#039; attributes, respectively. The values of these&lt;br /&gt;
attributes are limit objects that have two attributes: &#039;&#039;&#039;count&#039;&#039;&#039; and&lt;br /&gt;
&#039;&#039;&#039;interval&#039;&#039;&#039;. &#039;&#039;&#039;count&#039;&#039;&#039; specifies how many new connections or&lt;br /&gt;
packets are allowed within the time frame specified by &#039;&#039;&#039;interval&#039;&#039;&#039;&lt;br /&gt;
(in seconds). The &#039;&#039;&#039;logdrop&#039;&#039;&#039; action is applied to the packets&lt;br /&gt;
exceeding the limit.&lt;br /&gt;
&lt;br /&gt;
Filter objects may have an attribute named &#039;&#039;&#039;dnat&#039;&#039;&#039;, the value of&lt;br /&gt;
which is an IPv4 address. If defined, this enables destination NAT for&lt;br /&gt;
all IPv4 packets matching the rule, such that the specified address&lt;br /&gt;
replaces the original destination address. This option has no effect&lt;br /&gt;
on IPv6 packets.&lt;br /&gt;
&lt;br /&gt;
==== Policies ====&lt;br /&gt;
&lt;br /&gt;
Policy objects describe the default action for packets that did not&lt;br /&gt;
match any filter. The top-level attribute &#039;&#039;&#039;policy&#039;&#039;&#039; is a list of&lt;br /&gt;
policy objects. Policy objects do not have other attributes than those&lt;br /&gt;
common to all rule objects.&lt;br /&gt;
&lt;br /&gt;
==== NAT Rules ====&lt;br /&gt;
&lt;br /&gt;
NAT rules come in two flavors: &#039;&#039;source NAT rules&#039;&#039; and&lt;br /&gt;
&#039;&#039;destination NAT rules&#039;&#039;. These are contained in two top-level lists&lt;br /&gt;
named &#039;&#039;&#039;snat&#039;&#039;&#039; and &#039;&#039;&#039;dnat&#039;&#039;&#039;, respectively.&lt;br /&gt;
&lt;br /&gt;
Each NAT rule must have an attribute named &#039;&#039;&#039;ip-range&#039;&#039;&#039; that&lt;br /&gt;
specifies the IPv4 address range to which the original source or&lt;br /&gt;
destinatinon address is mapped. The value can be a single IPv4 address&lt;br /&gt;
or a range specified by two addresses, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character.&lt;br /&gt;
&lt;br /&gt;
Optionally, a NAT rule can specify the TCP and UDP port range to which&lt;br /&gt;
the original source or destination port is mapped. The attribute is&lt;br /&gt;
named &#039;&#039;&#039;port-range&#039;&#039;&#039;, and the value can be a single port number or a&lt;br /&gt;
range specified by two numbers, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character. If &#039;&#039;&#039;port-range&#039;&#039;&#039; is not specified, the original port&lt;br /&gt;
number is kept intact.&lt;br /&gt;
&lt;br /&gt;
Like filters, NAT rules can have a &#039;&#039;&#039;service&#039;&#039;&#039; attribute&lt;br /&gt;
constraining their scope to specific services.&lt;br /&gt;
&lt;br /&gt;
=== IP Sets ===&lt;br /&gt;
&lt;br /&gt;
Any IP set referenced by rule objects should be created by&lt;br /&gt;
awall. Auxiliary &#039;&#039;IP set&#039;&#039; objects are used to defined them in awall&lt;br /&gt;
policy files. The top-level attribute &#039;&#039;&#039;ipset&#039;&#039;&#039; is a dictionary, the&lt;br /&gt;
keys of which are IP set names. The values are IP set objects, which&lt;br /&gt;
have two mandatory attributes. The attribute named &#039;&#039;&#039;type&#039;&#039;&#039;&lt;br /&gt;
corresponds to the type argument of the &amp;lt;tt&amp;gt;ipset create&amp;lt;/tt&amp;gt;&lt;br /&gt;
command. &#039;&#039;&#039;family&#039;&#039;&#039; specifies whether the set is for IPv4 or IPv6&lt;br /&gt;
addresses, and the possible values are &#039;&#039;&#039;inet&#039;&#039;&#039; and &#039;&#039;&#039;inet6&#039;&#039;&#039;,&lt;br /&gt;
correspondingly.&lt;br /&gt;
&lt;br /&gt;
== Command Line Syntax ==&lt;br /&gt;
&lt;br /&gt;
=== Translating Policy Files to Firewall Configuration Files ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall translate&#039;&#039;&#039; [&#039;&#039;&#039;-o&#039;&#039;&#039;|&#039;&#039;&#039;--output&#039;&#039;&#039; DIRECTORY] [&#039;&#039;&#039;-V&#039;&#039;&#039;|&#039;&#039;&#039;--verify&#039;&#039;&#039;]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--verify&amp;lt;/tt&amp;gt; option makes awall verify the configuration&lt;br /&gt;
using the test mode of iptables-restore before overwriting the old&lt;br /&gt;
files.&lt;br /&gt;
&lt;br /&gt;
Specifying the output directory allows testing awall policies without&lt;br /&gt;
overwriting the current iptables and ipset configuration files. By&lt;br /&gt;
default, awall generates the configuration to &amp;lt;tt&amp;gt;/etc/iptables&amp;lt;/tt&amp;gt;&lt;br /&gt;
and &amp;lt;tt&amp;gt;/etc/ipset.d&amp;lt;/tt&amp;gt;, which are read by the init scripts.&lt;br /&gt;
&lt;br /&gt;
=== Run-Time Activation of New Firewall Configuration ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall activate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This command genereates firewall configuration from the policy files&lt;br /&gt;
and enables it. If the user confirms the new configuration by hitting&lt;br /&gt;
the Return key within 10 seconds, the configuration is saved to the&lt;br /&gt;
files. Otherwise, the old configuration is restored.&lt;br /&gt;
&lt;br /&gt;
=== Optional Policies ===&lt;br /&gt;
&lt;br /&gt;
Optional policies can be enabled or disabled using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall&#039;&#039;&#039; {&#039;&#039;&#039;enable&#039;&#039;&#039;|&#039;&#039;&#039;disable&#039;&#039;&#039;} POLICY...&lt;br /&gt;
&lt;br /&gt;
Optional policies can be listed using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall list&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;enabled&#039;&#039;&#039; status means that the policy has been enabled by the&lt;br /&gt;
user. The &#039;&#039;&#039;disabled&#039;&#039;&#039; status means that the policy is not in&lt;br /&gt;
use. The &#039;&#039;&#039;required&#039;&#039;&#039; status means that the policy has not been&lt;br /&gt;
enabled by the user but is in use because it is required by another&lt;br /&gt;
policy which is in use.&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;/div&gt;</summary>
		<author><name>Jiufpt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8049</id>
		<title>Alpine Wall User&#039;s Guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8049"/>
		<updated>2012-05-16T18:53:33Z</updated>

		<summary type="html">&lt;p&gt;Jiufpt: /* Zones */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Configuration File Processing ==&lt;br /&gt;
&lt;br /&gt;
[[Alpine Wall]] (awall) reads its configuration from multiple&lt;br /&gt;
JSON-formatted files, called &#039;&#039;policy files&#039;&#039;. The processing starts&lt;br /&gt;
from directory &amp;lt;tt&amp;gt;/usr/share/awall/mandatory&amp;lt;/tt&amp;gt;, which contains&lt;br /&gt;
mandatory policy files shipped with APK packages. After that,&lt;br /&gt;
installation-specific policy files in &amp;lt;tt&amp;gt;/etc/awall&amp;lt;/tt&amp;gt; are&lt;br /&gt;
processed.&lt;br /&gt;
&lt;br /&gt;
The latter directory may also contain symbolic links to policy files&lt;br /&gt;
located in &amp;lt;tt&amp;gt;/usr/share/awall/optional&amp;lt;/tt&amp;gt;. These are optional&lt;br /&gt;
policies, which can be enabled on need basis. Such symbolic links are&lt;br /&gt;
easily created and destroyed using the &amp;lt;tt&amp;gt;awall enable&amp;lt;/tt&amp;gt; and &lt;br /&gt;
&amp;lt;tt&amp;gt;awall disable&amp;lt;/tt&amp;gt; commands. &amp;lt;tt&amp;gt;awall list&amp;lt;/tt&amp;gt; shows which&lt;br /&gt;
optional policies are enabled and disabled. The command also prints&lt;br /&gt;
the description of the optional policy if defined in the file using&lt;br /&gt;
a top-level attribute named &#039;&#039;&#039;description&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Sometimes a policy file depends on other policy files. In this case,&lt;br /&gt;
the policy file must have a top-level attribute &#039;&#039;&#039;import&#039;&#039;&#039;, the&lt;br /&gt;
value of which is a list of policy names, which correspond to the file&lt;br /&gt;
names without the &amp;lt;tt&amp;gt;.json&amp;lt;/tt&amp;gt; suffix. The policies listed there are&lt;br /&gt;
always processed before the importing policy. The order of the&lt;br /&gt;
generated iptables rules generally reflects the processing order of&lt;br /&gt;
their corresponding awall policies.&lt;br /&gt;
&lt;br /&gt;
As the import directive does not require the path name to be&lt;br /&gt;
specified, awall expects policies to have unique names, even if&lt;br /&gt;
located in different directories. It is allowed to import optional&lt;br /&gt;
policies that are not explicitly enabled by the user. Such policies&lt;br /&gt;
show up with the &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; status in the output of &amp;lt;tt&amp;gt;awall&lt;br /&gt;
list&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== List Parameters ==&lt;br /&gt;
&lt;br /&gt;
Several awall parameters are defined as lists of values. In order to&lt;br /&gt;
facilitate manual editing of policy files, awall also accepts single&lt;br /&gt;
values in place of lists. Such values are semantically equivalent to&lt;br /&gt;
lists containing one element.&lt;br /&gt;
&lt;br /&gt;
== Variable Expansion ==&lt;br /&gt;
&lt;br /&gt;
Awall allows variable definitions in policy files. The top-level&lt;br /&gt;
attribute &#039;&#039;&#039;variable&#039;&#039;&#039; is a dictionary containing the&lt;br /&gt;
definitions. The value of a variable can be of any type (string,&lt;br /&gt;
integer, list, or dictionary).&lt;br /&gt;
&lt;br /&gt;
A variable is referenced in policy files by a string which equals the&lt;br /&gt;
variable name prepended with the &#039;&#039;&#039;$&#039;&#039;&#039; character. If the value of&lt;br /&gt;
the variable is a string, the reference can be embedded into a longer&lt;br /&gt;
string in order to substitute some part of that string (in shell&lt;br /&gt;
style). Variable references can be used when defining other variables,&lt;br /&gt;
as long as the definitions are not circular.&lt;br /&gt;
&lt;br /&gt;
Policy files can reference variables defined in other policy&lt;br /&gt;
files. Policy files can also override variables defined elsewhere by&lt;br /&gt;
redefining them. In this case, the new definition affects all policy&lt;br /&gt;
files, also those processed before the overriding policy. Awall&lt;br /&gt;
variables are in fact simple macros, since each variable remains&lt;br /&gt;
constant thoughout a single processing round. If multiple files define&lt;br /&gt;
the same variable, the definition in the file processed last takes&lt;br /&gt;
effect.&lt;br /&gt;
&lt;br /&gt;
If defined as an empty string, all non-embedded references to a&lt;br /&gt;
variable evaluate as if the attribute in question was not present in&lt;br /&gt;
the configuration. This is also the case when a string containing&lt;br /&gt;
embedded variable references finally evaluates to an empty string.&lt;br /&gt;
&lt;br /&gt;
== Configuration Objects ==&lt;br /&gt;
&lt;br /&gt;
Configuration objects can be divided into two main types.&lt;br /&gt;
&#039;&#039;Auxiliary objects&#039;&#039; model high-level concepts such as services and&lt;br /&gt;
zones. &#039;&#039;Rule objects&#039;&#039; translate into one or more iptables rules, and&lt;br /&gt;
are often defined with the help of some auxiliary objects.&lt;br /&gt;
&lt;br /&gt;
=== Services ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;service&#039;&#039; represents a set of network protocols. A top-level&lt;br /&gt;
attribute &#039;&#039;&#039;service&#039;&#039;&#039; is a dictionary that maps service names to&lt;br /&gt;
service definition objects, or lists thereof in more complex cases.&lt;br /&gt;
&lt;br /&gt;
A service definition object contains an attribute named &#039;&#039;&#039;proto&#039;&#039;&#039;,&lt;br /&gt;
which corresponds to the &amp;lt;tt&amp;gt;--protocol&amp;lt;/tt&amp;gt; option of iptables. The&lt;br /&gt;
protocol can be defined as a numerical value or string as defined in&lt;br /&gt;
&amp;lt;tt&amp;gt;/etc/protocols&amp;lt;/tt&amp;gt;. If the protocol is &#039;&#039;&#039;tcp&#039;&#039;&#039; or &#039;&#039;&#039;udp&#039;&#039;&#039;,&lt;br /&gt;
the scope of the service definition may be constrained by defining an&lt;br /&gt;
attribute named &#039;&#039;&#039;port&#039;&#039;&#039;, which is a list of TCP or UDP port&lt;br /&gt;
numbers. If the protocol is &#039;&#039;&#039;icmp&#039;&#039;&#039; or &#039;&#039;&#039;icmpv6&#039;&#039;&#039;, an analogous &lt;br /&gt;
&#039;&#039;&#039;icmp-type&#039;&#039;&#039; attribute may be used. In addition, the scope of the&lt;br /&gt;
rule is also automatically limited to IPv4 or IPv6, respectively.&lt;br /&gt;
&lt;br /&gt;
=== Zones ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;zone&#039;&#039; represents a set of network hosts. A top-level attribute &lt;br /&gt;
&#039;&#039;&#039;zone&#039;&#039;&#039; is a dictionary that maps zone names to zone objects. A&lt;br /&gt;
zone object has an attribute named &#039;&#039;&#039;iface&#039;&#039;&#039;, &#039;&#039;&#039;addr&#039;&#039;&#039;, or&lt;br /&gt;
both. &#039;&#039;&#039;iface&#039;&#039;&#039; is a list of network interfaces and &#039;&#039;&#039;addr&#039;&#039;&#039; is a&lt;br /&gt;
list of IPv4/IPv6 host and network addresses (CIDR&lt;br /&gt;
notation). &#039;&#039;&#039;addr&#039;&#039;&#039; may also contain domain names, which are&lt;br /&gt;
expanded to IP addresses using DNS resolution. If not defined,&lt;br /&gt;
&#039;&#039;&#039;addr&#039;&#039;&#039; defaults to the entire address space and &#039;&#039;&#039;iface&#039;&#039;&#039; to all&lt;br /&gt;
interfaces.&lt;br /&gt;
&lt;br /&gt;
Rule objects contain two attributes, &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;, which are&lt;br /&gt;
lists of zone names. These attributes control whether a packet matches&lt;br /&gt;
the rule or not. If a particular zone is referenced by the &#039;&#039;&#039;in&#039;&#039;&#039; &lt;br /&gt;
attribute, the rule applies to packets whose ingress interface and&lt;br /&gt;
source address are covered by the zone definition. Correspondingly, if&lt;br /&gt;
a zone is referenced by the &#039;&#039;&#039;out&#039;&#039;&#039; attribute, the rule applies to&lt;br /&gt;
packets whose egress interface and destination address are included in&lt;br /&gt;
the zone. If both &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; are defined, the packet must&lt;br /&gt;
fulfill both criteria in order to match the rule.&lt;br /&gt;
&lt;br /&gt;
=== Rules ===&lt;br /&gt;
&lt;br /&gt;
There are three types of rule objects: &#039;&#039;policies&#039;&#039;, &#039;&#039;filters&#039;&#039;, and&lt;br /&gt;
&#039;&#039;NAT rules&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
All rule objects can have the &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; attributes&lt;br /&gt;
referring to zones as described in the previous section. In addition,&lt;br /&gt;
the scope of the rule can be further constrained with the following&lt;br /&gt;
attributes:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Attribute!!Value format!!Effect&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;src&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s source address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;dest&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s destination address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipset&#039;&#039;&#039;&lt;br /&gt;
|Object containing two attributes: &#039;&#039;&#039;name&#039;&#039;&#039; referring to an IP set and &#039;&#039;&#039;args&#039;&#039;&#039;, which is a list of strings &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|Packet matches the IP set referred here when the match arguments are taken from the source (&#039;&#039;&#039;in&#039;&#039;&#039;) and destination (&#039;&#039;&#039;out&#039;&#039;&#039;) address or port in the order specified by &#039;&#039;&#039;args&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipsec&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;in&#039;&#039;&#039; or &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|IPsec decapsulation perfomed on ingress (&#039;&#039;&#039;in&#039;&#039;&#039;) or encapsulation performed on egress (&#039;&#039;&#039;out&#039;&#039;&#039;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects must have an attribute named &#039;&#039;&#039;action&#039;&#039;&#039;, the value of&lt;br /&gt;
which can be one of the following:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Value!!Action&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;accept&#039;&#039;&#039;&lt;br /&gt;
|Accept the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;reject&#039;&#039;&#039;&lt;br /&gt;
|Reject the packet with an ICMP error message&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;drop&#039;&#039;&#039;&lt;br /&gt;
|Silently drop the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;logreject&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;reject&#039;&#039;&#039; but with kernel logging&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;logdrop&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;drop&#039;&#039;&#039; but with kernel logging&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects are declared in type-specific top-level dictionaries in&lt;br /&gt;
awall policy files. If a packet matches multiple rules, the one&lt;br /&gt;
appearing earlier in the list takes precedence. If the matching rules&lt;br /&gt;
are defined in different policy files, the one that was processed&lt;br /&gt;
earlier takes precedence in the current implementation, but this may&lt;br /&gt;
change in future versions.&lt;br /&gt;
&lt;br /&gt;
==== Filters ====&lt;br /&gt;
&lt;br /&gt;
Filter objects specify an action for packets fulfilling certain&lt;br /&gt;
criteria. The top-level attribute &#039;&#039;&#039;filter&#039;&#039;&#039; is a list of filter&lt;br /&gt;
objects. The precedence rules are similar to those of policy objects.&lt;br /&gt;
&lt;br /&gt;
In addition to the common rule attributes, filter objects can have a&lt;br /&gt;
&#039;&#039;&#039;service&#039;&#039;&#039; attribute constraining the scope to specific services&lt;br /&gt;
only. This attribute is a list of service names, referring to the&lt;br /&gt;
keys of the top-level &#039;&#039;&#039;service&#039;&#039;&#039; dictionary.&lt;br /&gt;
&lt;br /&gt;
Filter objects may also contain limits for packet flow or new&lt;br /&gt;
connections. These are specified with the &#039;&#039;&#039;flow-limit&#039;&#039;&#039; and&lt;br /&gt;
&#039;&#039;&#039;conn-limit&#039;&#039;&#039; attributes, respectively. The values of these&lt;br /&gt;
attributes are limit objects that have two attributes: &#039;&#039;&#039;count&#039;&#039;&#039; and&lt;br /&gt;
&#039;&#039;&#039;interval&#039;&#039;&#039;. &#039;&#039;&#039;count&#039;&#039;&#039; specifies how many new connections or&lt;br /&gt;
packets are allowed within the time frame specified by &#039;&#039;&#039;interval&#039;&#039;&#039;&lt;br /&gt;
(in seconds). The &#039;&#039;&#039;logdrop&#039;&#039;&#039; action is applied to the packets&lt;br /&gt;
exceeding the limit.&lt;br /&gt;
&lt;br /&gt;
Filter objects may have an attribute named &#039;&#039;&#039;dnat&#039;&#039;&#039;, the value of&lt;br /&gt;
which is an IPv4 address. If defined, this enables destination NAT for&lt;br /&gt;
all IPv4 packets matching the rule, such that the specified address&lt;br /&gt;
replaces the original destination address. This option has no effect&lt;br /&gt;
on IPv6 packets.&lt;br /&gt;
&lt;br /&gt;
==== Policies ====&lt;br /&gt;
&lt;br /&gt;
Policy objects describe the default action for packets that did not&lt;br /&gt;
match any filter. The top-level attribute &#039;&#039;&#039;policy&#039;&#039;&#039; is a list of&lt;br /&gt;
policy objects. Policy objects do not have other attributes than those&lt;br /&gt;
common to all rule objects.&lt;br /&gt;
&lt;br /&gt;
==== NAT Rules ====&lt;br /&gt;
&lt;br /&gt;
NAT rules come in two flavors: &#039;&#039;source NAT rules&#039;&#039; and&lt;br /&gt;
&#039;&#039;destination NAT rules&#039;&#039;. These are contained in two top-level lists&lt;br /&gt;
named &#039;&#039;&#039;snat&#039;&#039;&#039; and &#039;&#039;&#039;dnat&#039;&#039;&#039;, respectively.&lt;br /&gt;
&lt;br /&gt;
Each NAT rule must have an attribute named &#039;&#039;&#039;ip-range&#039;&#039;&#039; that&lt;br /&gt;
specifies the IPv4 address range to which the original source or&lt;br /&gt;
destinatinon address is mapped. The value can be a single IPv4 address&lt;br /&gt;
or a range specified by two addresses, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character.&lt;br /&gt;
&lt;br /&gt;
Optionally, a NAT rule can specify the TCP and UDP port range to which&lt;br /&gt;
the original source or destination port is mapped. The attribute is&lt;br /&gt;
named &#039;&#039;&#039;port-range&#039;&#039;&#039;, and the value can be a single port number or a&lt;br /&gt;
range specified by two numbers, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character. If &#039;&#039;&#039;port-range&#039;&#039;&#039; is not specified, the original port&lt;br /&gt;
number is kept intact.&lt;br /&gt;
&lt;br /&gt;
Like filters, NAT rules can have a &#039;&#039;&#039;service&#039;&#039;&#039; attribute&lt;br /&gt;
constraining their scope to specific services.&lt;br /&gt;
&lt;br /&gt;
=== IP Sets ===&lt;br /&gt;
&lt;br /&gt;
Any IP set referenced by rule objects should be created by&lt;br /&gt;
awall. Auxiliary &#039;&#039;IP set&#039;&#039; objects are used to defined them in awall&lt;br /&gt;
policy files. The top-level attribute &#039;&#039;&#039;ipset&#039;&#039;&#039; is a dictionary, the&lt;br /&gt;
keys of which are IP set names. The values are IP set objects, which&lt;br /&gt;
have two mandatory attributes. The attribute named &#039;&#039;&#039;type&#039;&#039;&#039;&lt;br /&gt;
corresponds to the type argument of the &amp;lt;tt&amp;gt;ipset create&amp;lt;/tt&amp;gt;&lt;br /&gt;
command. &#039;&#039;&#039;family&#039;&#039;&#039; specifies whether the set is for IPv4 or IPv6&lt;br /&gt;
addresses, and the possible values are &#039;&#039;&#039;inet&#039;&#039;&#039; and &#039;&#039;&#039;inet6&#039;&#039;&#039;,&lt;br /&gt;
correspondingly.&lt;br /&gt;
&lt;br /&gt;
== Command Line Syntax ==&lt;br /&gt;
&lt;br /&gt;
=== Translating Policy Files to Firewall Configuration Files ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall translate&#039;&#039;&#039; [&#039;&#039;&#039;-o&#039;&#039;&#039;|&#039;&#039;&#039;--output&#039;&#039;&#039; DIRECTORY] [&#039;&#039;&#039;-V&#039;&#039;&#039;|&#039;&#039;&#039;--verify&#039;&#039;&#039;]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--verify&amp;lt;/tt&amp;gt; option makes awall verify the configuration&lt;br /&gt;
using the test mode of iptables-restore before overwriting the old&lt;br /&gt;
files.&lt;br /&gt;
&lt;br /&gt;
Specifying the output directory allows testing awall policies without&lt;br /&gt;
overwriting the current iptables and ipset configuration files. By&lt;br /&gt;
default, awall generates the configuration to &amp;lt;tt&amp;gt;/etc/iptables&amp;lt;/tt&amp;gt;&lt;br /&gt;
and &amp;lt;tt&amp;gt;/etc/ipset.d&amp;lt;/tt&amp;gt;, which are read by the init scripts.&lt;br /&gt;
&lt;br /&gt;
=== Run-Time Activation of New Firewall Configuration ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall activate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This command genereates firewall configuration from the policy files&lt;br /&gt;
and enables it. If the user confirms the new configuration by hitting&lt;br /&gt;
the Return key within 10 seconds, the configuration is saved to the&lt;br /&gt;
files. Otherwise, the old configuration is restored.&lt;br /&gt;
&lt;br /&gt;
=== Optional Policies ===&lt;br /&gt;
&lt;br /&gt;
Optional policies can be enabled or disabled using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall&#039;&#039;&#039; {&#039;&#039;&#039;enable&#039;&#039;&#039;|&#039;&#039;&#039;disable&#039;&#039;&#039;} POLICY...&lt;br /&gt;
&lt;br /&gt;
Optional policies can be listed using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall list&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;enabled&#039;&#039;&#039; status means that the policy has been enabled by the&lt;br /&gt;
user. The &#039;&#039;&#039;disabled&#039;&#039;&#039; status means that the policy is not in&lt;br /&gt;
use. The &#039;&#039;&#039;required&#039;&#039;&#039; status means that the policy has not been&lt;br /&gt;
enabled by the user but is in use because it is required by another&lt;br /&gt;
policy which is in use.&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;/div&gt;</summary>
		<author><name>Jiufpt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8048</id>
		<title>Alpine Wall User&#039;s Guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8048"/>
		<updated>2012-05-16T18:49:55Z</updated>

		<summary type="html">&lt;p&gt;Jiufpt: /* Zones */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Configuration File Processing ==&lt;br /&gt;
&lt;br /&gt;
[[Alpine Wall]] (awall) reads its configuration from multiple&lt;br /&gt;
JSON-formatted files, called &#039;&#039;policy files&#039;&#039;. The processing starts&lt;br /&gt;
from directory &amp;lt;tt&amp;gt;/usr/share/awall/mandatory&amp;lt;/tt&amp;gt;, which contains&lt;br /&gt;
mandatory policy files shipped with APK packages. After that,&lt;br /&gt;
installation-specific policy files in &amp;lt;tt&amp;gt;/etc/awall&amp;lt;/tt&amp;gt; are&lt;br /&gt;
processed.&lt;br /&gt;
&lt;br /&gt;
The latter directory may also contain symbolic links to policy files&lt;br /&gt;
located in &amp;lt;tt&amp;gt;/usr/share/awall/optional&amp;lt;/tt&amp;gt;. These are optional&lt;br /&gt;
policies, which can be enabled on need basis. Such symbolic links are&lt;br /&gt;
easily created and destroyed using the &amp;lt;tt&amp;gt;awall enable&amp;lt;/tt&amp;gt; and &lt;br /&gt;
&amp;lt;tt&amp;gt;awall disable&amp;lt;/tt&amp;gt; commands. &amp;lt;tt&amp;gt;awall list&amp;lt;/tt&amp;gt; shows which&lt;br /&gt;
optional policies are enabled and disabled. The command also prints&lt;br /&gt;
the description of the optional policy if defined in the file using&lt;br /&gt;
a top-level attribute named &#039;&#039;&#039;description&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Sometimes a policy file depends on other policy files. In this case,&lt;br /&gt;
the policy file must have a top-level attribute &#039;&#039;&#039;import&#039;&#039;&#039;, the&lt;br /&gt;
value of which is a list of policy names, which correspond to the file&lt;br /&gt;
names without the &amp;lt;tt&amp;gt;.json&amp;lt;/tt&amp;gt; suffix. The policies listed there are&lt;br /&gt;
always processed before the importing policy. The order of the&lt;br /&gt;
generated iptables rules generally reflects the processing order of&lt;br /&gt;
their corresponding awall policies.&lt;br /&gt;
&lt;br /&gt;
As the import directive does not require the path name to be&lt;br /&gt;
specified, awall expects policies to have unique names, even if&lt;br /&gt;
located in different directories. It is allowed to import optional&lt;br /&gt;
policies that are not explicitly enabled by the user. Such policies&lt;br /&gt;
show up with the &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; status in the output of &amp;lt;tt&amp;gt;awall&lt;br /&gt;
list&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== List Parameters ==&lt;br /&gt;
&lt;br /&gt;
Several awall parameters are defined as lists of values. In order to&lt;br /&gt;
facilitate manual editing of policy files, awall also accepts single&lt;br /&gt;
values in place of lists. Such values are semantically equivalent to&lt;br /&gt;
lists containing one element.&lt;br /&gt;
&lt;br /&gt;
== Variable Expansion ==&lt;br /&gt;
&lt;br /&gt;
Awall allows variable definitions in policy files. The top-level&lt;br /&gt;
attribute &#039;&#039;&#039;variable&#039;&#039;&#039; is a dictionary containing the&lt;br /&gt;
definitions. The value of a variable can be of any type (string,&lt;br /&gt;
integer, list, or dictionary).&lt;br /&gt;
&lt;br /&gt;
A variable is referenced in policy files by a string which equals the&lt;br /&gt;
variable name prepended with the &#039;&#039;&#039;$&#039;&#039;&#039; character. If the value of&lt;br /&gt;
the variable is a string, the reference can be embedded into a longer&lt;br /&gt;
string in order to substitute some part of that string (in shell&lt;br /&gt;
style). Variable references can be used when defining other variables,&lt;br /&gt;
as long as the definitions are not circular.&lt;br /&gt;
&lt;br /&gt;
Policy files can reference variables defined in other policy&lt;br /&gt;
files. Policy files can also override variables defined elsewhere by&lt;br /&gt;
redefining them. In this case, the new definition affects all policy&lt;br /&gt;
files, also those processed before the overriding policy. Awall&lt;br /&gt;
variables are in fact simple macros, since each variable remains&lt;br /&gt;
constant thoughout a single processing round. If multiple files define&lt;br /&gt;
the same variable, the definition in the file processed last takes&lt;br /&gt;
effect.&lt;br /&gt;
&lt;br /&gt;
If defined as an empty string, all non-embedded references to a&lt;br /&gt;
variable evaluate as if the attribute in question was not present in&lt;br /&gt;
the configuration. This is also the case when a string containing&lt;br /&gt;
embedded variable references finally evaluates to an empty string.&lt;br /&gt;
&lt;br /&gt;
== Configuration Objects ==&lt;br /&gt;
&lt;br /&gt;
Configuration objects can be divided into two main types.&lt;br /&gt;
&#039;&#039;Auxiliary objects&#039;&#039; model high-level concepts such as services and&lt;br /&gt;
zones. &#039;&#039;Rule objects&#039;&#039; translate into one or more iptables rules, and&lt;br /&gt;
are often defined with the help of some auxiliary objects.&lt;br /&gt;
&lt;br /&gt;
=== Services ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;service&#039;&#039; represents a set of network protocols. A top-level&lt;br /&gt;
attribute &#039;&#039;&#039;service&#039;&#039;&#039; is a dictionary that maps service names to&lt;br /&gt;
service definition objects, or lists thereof in more complex cases.&lt;br /&gt;
&lt;br /&gt;
A service definition object contains an attribute named &#039;&#039;&#039;proto&#039;&#039;&#039;,&lt;br /&gt;
which corresponds to the &amp;lt;tt&amp;gt;--protocol&amp;lt;/tt&amp;gt; option of iptables. The&lt;br /&gt;
protocol can be defined as a numerical value or string as defined in&lt;br /&gt;
&amp;lt;tt&amp;gt;/etc/protocols&amp;lt;/tt&amp;gt;. If the protocol is &#039;&#039;&#039;tcp&#039;&#039;&#039; or &#039;&#039;&#039;udp&#039;&#039;&#039;,&lt;br /&gt;
the scope of the service definition may be constrained by defining an&lt;br /&gt;
attribute named &#039;&#039;&#039;port&#039;&#039;&#039;, which is a list of TCP or UDP port&lt;br /&gt;
numbers. If the protocol is &#039;&#039;&#039;icmp&#039;&#039;&#039; or &#039;&#039;&#039;icmpv6&#039;&#039;&#039;, an analogous &lt;br /&gt;
&#039;&#039;&#039;icmp-type&#039;&#039;&#039; attribute may be used. In addition, the scope of the&lt;br /&gt;
rule is also automatically limited to IPv4 or IPv6, respectively.&lt;br /&gt;
&lt;br /&gt;
=== Zones ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;zone&#039;&#039; represents a set of network hosts. A top-level attribute &lt;br /&gt;
&#039;&#039;&#039;zone&#039;&#039;&#039; is a dictionary that maps zone names to zone objects. A&lt;br /&gt;
zone object has an attribute named &#039;&#039;&#039;iface&#039;&#039;&#039;, &#039;&#039;&#039;addr&#039;&#039;&#039;, or&lt;br /&gt;
both. &#039;&#039;&#039;iface&#039;&#039;&#039; is a list of network interfaces and &#039;&#039;&#039;addr&#039;&#039;&#039; is a&lt;br /&gt;
list of IPv4/IPv6 host and network addresses (CIDR&lt;br /&gt;
notation). &#039;&#039;&#039;addr&#039;&#039;&#039; may also contain domain names, which are&lt;br /&gt;
expanded to IP addresses using DNS resolution. If not defined,&lt;br /&gt;
&#039;&#039;&#039;addr&#039;&#039;&#039; defaults to the entire address space and &#039;&#039;&#039;iface&#039;&#039;&#039; to all&lt;br /&gt;
interfaces.&lt;br /&gt;
&lt;br /&gt;
Rule objects contain two attributes, &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;, which are&lt;br /&gt;
lists of zone names. These attributes control whether a packet matches&lt;br /&gt;
the rule or not. If a particular zone is referenced by the &#039;&#039;&#039;in&#039;&#039;&#039;&lt;br /&gt;
attribute, the rule applies to packets whose ingress interface and&lt;br /&gt;
source address are covered by the zone definition. Correspondingly, if&lt;br /&gt;
a zone is referenced by the &#039;&#039;&#039;out&#039;&#039;&#039; attribute, the rule applies to&lt;br /&gt;
packets whose egress interface and destination address are included in&lt;br /&gt;
the zone. If both &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; are defined, the packet must&lt;br /&gt;
fulfill both criteria in order to match the rule.&lt;br /&gt;
&lt;br /&gt;
=== Rules ===&lt;br /&gt;
&lt;br /&gt;
There are three types of rule objects: &#039;&#039;policies&#039;&#039;, &#039;&#039;filters&#039;&#039;, and&lt;br /&gt;
&#039;&#039;NAT rules&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
All rule objects can have the &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; attributes&lt;br /&gt;
referring to zones as described in the previous section. In addition,&lt;br /&gt;
the scope of the rule can be further constrained with the following&lt;br /&gt;
attributes:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Attribute!!Value format!!Effect&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;src&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s source address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;dest&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s destination address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipset&#039;&#039;&#039;&lt;br /&gt;
|Object containing two attributes: &#039;&#039;&#039;name&#039;&#039;&#039; referring to an IP set and &#039;&#039;&#039;args&#039;&#039;&#039;, which is a list of strings &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|Packet matches the IP set referred here when the match arguments are taken from the source (&#039;&#039;&#039;in&#039;&#039;&#039;) and destination (&#039;&#039;&#039;out&#039;&#039;&#039;) address or port in the order specified by &#039;&#039;&#039;args&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipsec&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;in&#039;&#039;&#039; or &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|IPsec decapsulation perfomed on ingress (&#039;&#039;&#039;in&#039;&#039;&#039;) or encapsulation performed on egress (&#039;&#039;&#039;out&#039;&#039;&#039;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects must have an attribute named &#039;&#039;&#039;action&#039;&#039;&#039;, the value of&lt;br /&gt;
which can be one of the following:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Value!!Action&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;accept&#039;&#039;&#039;&lt;br /&gt;
|Accept the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;reject&#039;&#039;&#039;&lt;br /&gt;
|Reject the packet with an ICMP error message&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;drop&#039;&#039;&#039;&lt;br /&gt;
|Silently drop the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;logreject&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;reject&#039;&#039;&#039; but with kernel logging&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;logdrop&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;drop&#039;&#039;&#039; but with kernel logging&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects are declared in type-specific top-level dictionaries in&lt;br /&gt;
awall policy files. If a packet matches multiple rules, the one&lt;br /&gt;
appearing earlier in the list takes precedence. If the matching rules&lt;br /&gt;
are defined in different policy files, the one that was processed&lt;br /&gt;
earlier takes precedence in the current implementation, but this may&lt;br /&gt;
change in future versions.&lt;br /&gt;
&lt;br /&gt;
==== Filters ====&lt;br /&gt;
&lt;br /&gt;
Filter objects specify an action for packets fulfilling certain&lt;br /&gt;
criteria. The top-level attribute &#039;&#039;&#039;filter&#039;&#039;&#039; is a list of filter&lt;br /&gt;
objects. The precedence rules are similar to those of policy objects.&lt;br /&gt;
&lt;br /&gt;
In addition to the common rule attributes, filter objects can have a&lt;br /&gt;
&#039;&#039;&#039;service&#039;&#039;&#039; attribute constraining the scope to specific services&lt;br /&gt;
only. This attribute is a list of service names, referring to the&lt;br /&gt;
keys of the top-level &#039;&#039;&#039;service&#039;&#039;&#039; dictionary.&lt;br /&gt;
&lt;br /&gt;
Filter objects may also contain limits for packet flow or new&lt;br /&gt;
connections. These are specified with the &#039;&#039;&#039;flow-limit&#039;&#039;&#039; and&lt;br /&gt;
&#039;&#039;&#039;conn-limit&#039;&#039;&#039; attributes, respectively. The values of these&lt;br /&gt;
attributes are limit objects that have two attributes: &#039;&#039;&#039;count&#039;&#039;&#039; and&lt;br /&gt;
&#039;&#039;&#039;interval&#039;&#039;&#039;. &#039;&#039;&#039;count&#039;&#039;&#039; specifies how many new connections or&lt;br /&gt;
packets are allowed within the time frame specified by &#039;&#039;&#039;interval&#039;&#039;&#039;&lt;br /&gt;
(in seconds). The &#039;&#039;&#039;logdrop&#039;&#039;&#039; action is applied to the packets&lt;br /&gt;
exceeding the limit.&lt;br /&gt;
&lt;br /&gt;
Filter objects may have an attribute named &#039;&#039;&#039;dnat&#039;&#039;&#039;, the value of&lt;br /&gt;
which is an IPv4 address. If defined, this enables destination NAT for&lt;br /&gt;
all IPv4 packets matching the rule, such that the specified address&lt;br /&gt;
replaces the original destination address. This option has no effect&lt;br /&gt;
on IPv6 packets.&lt;br /&gt;
&lt;br /&gt;
==== Policies ====&lt;br /&gt;
&lt;br /&gt;
Policy objects describe the default action for packets that did not&lt;br /&gt;
match any filter. The top-level attribute &#039;&#039;&#039;policy&#039;&#039;&#039; is a list of&lt;br /&gt;
policy objects. Policy objects do not have other attributes than those&lt;br /&gt;
common to all rule objects.&lt;br /&gt;
&lt;br /&gt;
==== NAT Rules ====&lt;br /&gt;
&lt;br /&gt;
NAT rules come in two flavors: &#039;&#039;source NAT rules&#039;&#039; and&lt;br /&gt;
&#039;&#039;destination NAT rules&#039;&#039;. These are contained in two top-level lists&lt;br /&gt;
named &#039;&#039;&#039;snat&#039;&#039;&#039; and &#039;&#039;&#039;dnat&#039;&#039;&#039;, respectively.&lt;br /&gt;
&lt;br /&gt;
Each NAT rule must have an attribute named &#039;&#039;&#039;ip-range&#039;&#039;&#039; that&lt;br /&gt;
specifies the IPv4 address range to which the original source or&lt;br /&gt;
destinatinon address is mapped. The value can be a single IPv4 address&lt;br /&gt;
or a range specified by two addresses, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character.&lt;br /&gt;
&lt;br /&gt;
Optionally, a NAT rule can specify the TCP and UDP port range to which&lt;br /&gt;
the original source or destination port is mapped. The attribute is&lt;br /&gt;
named &#039;&#039;&#039;port-range&#039;&#039;&#039;, and the value can be a single port number or a&lt;br /&gt;
range specified by two numbers, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character. If &#039;&#039;&#039;port-range&#039;&#039;&#039; is not specified, the original port&lt;br /&gt;
number is kept intact.&lt;br /&gt;
&lt;br /&gt;
Like filters, NAT rules can have a &#039;&#039;&#039;service&#039;&#039;&#039; attribute&lt;br /&gt;
constraining their scope to specific services.&lt;br /&gt;
&lt;br /&gt;
=== IP Sets ===&lt;br /&gt;
&lt;br /&gt;
Any IP set referenced by rule objects should be created by&lt;br /&gt;
awall. Auxiliary &#039;&#039;IP set&#039;&#039; objects are used to defined them in awall&lt;br /&gt;
policy files. The top-level attribute &#039;&#039;&#039;ipset&#039;&#039;&#039; is a dictionary, the&lt;br /&gt;
keys of which are IP set names. The values are IP set objects, which&lt;br /&gt;
have two mandatory attributes. The attribute named &#039;&#039;&#039;type&#039;&#039;&#039;&lt;br /&gt;
corresponds to the type argument of the &amp;lt;tt&amp;gt;ipset create&amp;lt;/tt&amp;gt;&lt;br /&gt;
command. &#039;&#039;&#039;family&#039;&#039;&#039; specifies whether the set is for IPv4 or IPv6&lt;br /&gt;
addresses, and the possible values are &#039;&#039;&#039;inet&#039;&#039;&#039; and &#039;&#039;&#039;inet6&#039;&#039;&#039;,&lt;br /&gt;
correspondingly.&lt;br /&gt;
&lt;br /&gt;
== Command Line Syntax ==&lt;br /&gt;
&lt;br /&gt;
=== Translating Policy Files to Firewall Configuration Files ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall translate&#039;&#039;&#039; [&#039;&#039;&#039;-o&#039;&#039;&#039;|&#039;&#039;&#039;--output&#039;&#039;&#039; DIRECTORY] [&#039;&#039;&#039;-V&#039;&#039;&#039;|&#039;&#039;&#039;--verify&#039;&#039;&#039;]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--verify&amp;lt;/tt&amp;gt; option makes awall verify the configuration&lt;br /&gt;
using the test mode of iptables-restore before overwriting the old&lt;br /&gt;
files.&lt;br /&gt;
&lt;br /&gt;
Specifying the output directory allows testing awall policies without&lt;br /&gt;
overwriting the current iptables and ipset configuration files. By&lt;br /&gt;
default, awall generates the configuration to &amp;lt;tt&amp;gt;/etc/iptables&amp;lt;/tt&amp;gt;&lt;br /&gt;
and &amp;lt;tt&amp;gt;/etc/ipset.d&amp;lt;/tt&amp;gt;, which are read by the init scripts.&lt;br /&gt;
&lt;br /&gt;
=== Run-Time Activation of New Firewall Configuration ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall activate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This command genereates firewall configuration from the policy files&lt;br /&gt;
and enables it. If the user confirms the new configuration by hitting&lt;br /&gt;
the Return key within 10 seconds, the configuration is saved to the&lt;br /&gt;
files. Otherwise, the old configuration is restored.&lt;br /&gt;
&lt;br /&gt;
=== Optional Policies ===&lt;br /&gt;
&lt;br /&gt;
Optional policies can be enabled or disabled using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall&#039;&#039;&#039; {&#039;&#039;&#039;enable&#039;&#039;&#039;|&#039;&#039;&#039;disable&#039;&#039;&#039;} POLICY...&lt;br /&gt;
&lt;br /&gt;
Optional policies can be listed using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall list&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;enabled&#039;&#039;&#039; status means that the policy has been enabled by the&lt;br /&gt;
user. The &#039;&#039;&#039;disabled&#039;&#039;&#039; status means that the policy is not in&lt;br /&gt;
use. The &#039;&#039;&#039;required&#039;&#039;&#039; status means that the policy has not been&lt;br /&gt;
enabled by the user but is in use because it is required by another&lt;br /&gt;
policy which is in use.&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;/div&gt;</summary>
		<author><name>Jiufpt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8047</id>
		<title>Alpine Wall User&#039;s Guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8047"/>
		<updated>2012-05-16T18:49:24Z</updated>

		<summary type="html">&lt;p&gt;Jiufpt: /* Services */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Configuration File Processing ==&lt;br /&gt;
&lt;br /&gt;
[[Alpine Wall]] (awall) reads its configuration from multiple&lt;br /&gt;
JSON-formatted files, called &#039;&#039;policy files&#039;&#039;. The processing starts&lt;br /&gt;
from directory &amp;lt;tt&amp;gt;/usr/share/awall/mandatory&amp;lt;/tt&amp;gt;, which contains&lt;br /&gt;
mandatory policy files shipped with APK packages. After that,&lt;br /&gt;
installation-specific policy files in &amp;lt;tt&amp;gt;/etc/awall&amp;lt;/tt&amp;gt; are&lt;br /&gt;
processed.&lt;br /&gt;
&lt;br /&gt;
The latter directory may also contain symbolic links to policy files&lt;br /&gt;
located in &amp;lt;tt&amp;gt;/usr/share/awall/optional&amp;lt;/tt&amp;gt;. These are optional&lt;br /&gt;
policies, which can be enabled on need basis. Such symbolic links are&lt;br /&gt;
easily created and destroyed using the &amp;lt;tt&amp;gt;awall enable&amp;lt;/tt&amp;gt; and &lt;br /&gt;
&amp;lt;tt&amp;gt;awall disable&amp;lt;/tt&amp;gt; commands. &amp;lt;tt&amp;gt;awall list&amp;lt;/tt&amp;gt; shows which&lt;br /&gt;
optional policies are enabled and disabled. The command also prints&lt;br /&gt;
the description of the optional policy if defined in the file using&lt;br /&gt;
a top-level attribute named &#039;&#039;&#039;description&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Sometimes a policy file depends on other policy files. In this case,&lt;br /&gt;
the policy file must have a top-level attribute &#039;&#039;&#039;import&#039;&#039;&#039;, the&lt;br /&gt;
value of which is a list of policy names, which correspond to the file&lt;br /&gt;
names without the &amp;lt;tt&amp;gt;.json&amp;lt;/tt&amp;gt; suffix. The policies listed there are&lt;br /&gt;
always processed before the importing policy. The order of the&lt;br /&gt;
generated iptables rules generally reflects the processing order of&lt;br /&gt;
their corresponding awall policies.&lt;br /&gt;
&lt;br /&gt;
As the import directive does not require the path name to be&lt;br /&gt;
specified, awall expects policies to have unique names, even if&lt;br /&gt;
located in different directories. It is allowed to import optional&lt;br /&gt;
policies that are not explicitly enabled by the user. Such policies&lt;br /&gt;
show up with the &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; status in the output of &amp;lt;tt&amp;gt;awall&lt;br /&gt;
list&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== List Parameters ==&lt;br /&gt;
&lt;br /&gt;
Several awall parameters are defined as lists of values. In order to&lt;br /&gt;
facilitate manual editing of policy files, awall also accepts single&lt;br /&gt;
values in place of lists. Such values are semantically equivalent to&lt;br /&gt;
lists containing one element.&lt;br /&gt;
&lt;br /&gt;
== Variable Expansion ==&lt;br /&gt;
&lt;br /&gt;
Awall allows variable definitions in policy files. The top-level&lt;br /&gt;
attribute &#039;&#039;&#039;variable&#039;&#039;&#039; is a dictionary containing the&lt;br /&gt;
definitions. The value of a variable can be of any type (string,&lt;br /&gt;
integer, list, or dictionary).&lt;br /&gt;
&lt;br /&gt;
A variable is referenced in policy files by a string which equals the&lt;br /&gt;
variable name prepended with the &#039;&#039;&#039;$&#039;&#039;&#039; character. If the value of&lt;br /&gt;
the variable is a string, the reference can be embedded into a longer&lt;br /&gt;
string in order to substitute some part of that string (in shell&lt;br /&gt;
style). Variable references can be used when defining other variables,&lt;br /&gt;
as long as the definitions are not circular.&lt;br /&gt;
&lt;br /&gt;
Policy files can reference variables defined in other policy&lt;br /&gt;
files. Policy files can also override variables defined elsewhere by&lt;br /&gt;
redefining them. In this case, the new definition affects all policy&lt;br /&gt;
files, also those processed before the overriding policy. Awall&lt;br /&gt;
variables are in fact simple macros, since each variable remains&lt;br /&gt;
constant thoughout a single processing round. If multiple files define&lt;br /&gt;
the same variable, the definition in the file processed last takes&lt;br /&gt;
effect.&lt;br /&gt;
&lt;br /&gt;
If defined as an empty string, all non-embedded references to a&lt;br /&gt;
variable evaluate as if the attribute in question was not present in&lt;br /&gt;
the configuration. This is also the case when a string containing&lt;br /&gt;
embedded variable references finally evaluates to an empty string.&lt;br /&gt;
&lt;br /&gt;
== Configuration Objects ==&lt;br /&gt;
&lt;br /&gt;
Configuration objects can be divided into two main types.&lt;br /&gt;
&#039;&#039;Auxiliary objects&#039;&#039; model high-level concepts such as services and&lt;br /&gt;
zones. &#039;&#039;Rule objects&#039;&#039; translate into one or more iptables rules, and&lt;br /&gt;
are often defined with the help of some auxiliary objects.&lt;br /&gt;
&lt;br /&gt;
=== Services ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;service&#039;&#039; represents a set of network protocols. A top-level&lt;br /&gt;
attribute &#039;&#039;&#039;service&#039;&#039;&#039; is a dictionary that maps service names to&lt;br /&gt;
service definition objects, or lists thereof in more complex cases.&lt;br /&gt;
&lt;br /&gt;
A service definition object contains an attribute named &#039;&#039;&#039;proto&#039;&#039;&#039;,&lt;br /&gt;
which corresponds to the &amp;lt;tt&amp;gt;--protocol&amp;lt;/tt&amp;gt; option of iptables. The&lt;br /&gt;
protocol can be defined as a numerical value or string as defined in&lt;br /&gt;
&amp;lt;tt&amp;gt;/etc/protocols&amp;lt;/tt&amp;gt;. If the protocol is &#039;&#039;&#039;tcp&#039;&#039;&#039; or &#039;&#039;&#039;udp&#039;&#039;&#039;,&lt;br /&gt;
the scope of the service definition may be constrained by defining an&lt;br /&gt;
attribute named &#039;&#039;&#039;port&#039;&#039;&#039;, which is a list of TCP or UDP port&lt;br /&gt;
numbers. If the protocol is &#039;&#039;&#039;icmp&#039;&#039;&#039; or &#039;&#039;&#039;icmpv6&#039;&#039;&#039;, an analogous &lt;br /&gt;
&#039;&#039;&#039;icmp-type&#039;&#039;&#039; attribute may be used. In addition, the scope of the&lt;br /&gt;
rule is also automatically limited to IPv4 or IPv6, respectively.&lt;br /&gt;
&lt;br /&gt;
=== Zones ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;zone&#039;&#039; represents a set of network hosts. A top-level attribute&lt;br /&gt;
&#039;&#039;&#039;zone&#039;&#039;&#039; is a dictionary that maps zone names to zone objects. A&lt;br /&gt;
zone object has an attribute named &#039;&#039;&#039;iface&#039;&#039;&#039;, &#039;&#039;&#039;addr&#039;&#039;&#039;, or&lt;br /&gt;
both. &#039;&#039;&#039;iface&#039;&#039;&#039; is a list of network interfaces and &#039;&#039;&#039;addr&#039;&#039;&#039; is a&lt;br /&gt;
list of IPv4/IPv6 host and network addresses (CIDR&lt;br /&gt;
notation). &#039;&#039;&#039;addr&#039;&#039;&#039; may also contain domain names, which are&lt;br /&gt;
expanded to IP addresses using DNS resolution. If not defined,&lt;br /&gt;
&#039;&#039;&#039;addr&#039;&#039;&#039; defaults to the entire address space and &#039;&#039;&#039;iface&#039;&#039;&#039; to all&lt;br /&gt;
interfaces.&lt;br /&gt;
&lt;br /&gt;
Rule objects contain two attributes, &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;, which are&lt;br /&gt;
lists of zone names. These attributes control whether a packet matches&lt;br /&gt;
the rule or not. If a particular zone is referenced by the &#039;&#039;&#039;in&#039;&#039;&#039;&lt;br /&gt;
attribute, the rule applies to packets whose ingress interface and&lt;br /&gt;
source address are covered by the zone definition. Correspondingly, if&lt;br /&gt;
a zone is referenced by the &#039;&#039;&#039;out&#039;&#039;&#039; attribute, the rule applies to&lt;br /&gt;
packets whose egress interface and destination address are included in&lt;br /&gt;
the zone. If both &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; are defined, the packet must&lt;br /&gt;
fulfill both criteria in order to match the rule.&lt;br /&gt;
&lt;br /&gt;
=== Rules ===&lt;br /&gt;
&lt;br /&gt;
There are three types of rule objects: &#039;&#039;policies&#039;&#039;, &#039;&#039;filters&#039;&#039;, and&lt;br /&gt;
&#039;&#039;NAT rules&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
All rule objects can have the &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; attributes&lt;br /&gt;
referring to zones as described in the previous section. In addition,&lt;br /&gt;
the scope of the rule can be further constrained with the following&lt;br /&gt;
attributes:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Attribute!!Value format!!Effect&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;src&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s source address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;dest&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s destination address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipset&#039;&#039;&#039;&lt;br /&gt;
|Object containing two attributes: &#039;&#039;&#039;name&#039;&#039;&#039; referring to an IP set and &#039;&#039;&#039;args&#039;&#039;&#039;, which is a list of strings &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|Packet matches the IP set referred here when the match arguments are taken from the source (&#039;&#039;&#039;in&#039;&#039;&#039;) and destination (&#039;&#039;&#039;out&#039;&#039;&#039;) address or port in the order specified by &#039;&#039;&#039;args&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipsec&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;in&#039;&#039;&#039; or &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|IPsec decapsulation perfomed on ingress (&#039;&#039;&#039;in&#039;&#039;&#039;) or encapsulation performed on egress (&#039;&#039;&#039;out&#039;&#039;&#039;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects must have an attribute named &#039;&#039;&#039;action&#039;&#039;&#039;, the value of&lt;br /&gt;
which can be one of the following:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Value!!Action&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;accept&#039;&#039;&#039;&lt;br /&gt;
|Accept the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;reject&#039;&#039;&#039;&lt;br /&gt;
|Reject the packet with an ICMP error message&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;drop&#039;&#039;&#039;&lt;br /&gt;
|Silently drop the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;logreject&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;reject&#039;&#039;&#039; but with kernel logging&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;logdrop&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;drop&#039;&#039;&#039; but with kernel logging&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects are declared in type-specific top-level dictionaries in&lt;br /&gt;
awall policy files. If a packet matches multiple rules, the one&lt;br /&gt;
appearing earlier in the list takes precedence. If the matching rules&lt;br /&gt;
are defined in different policy files, the one that was processed&lt;br /&gt;
earlier takes precedence in the current implementation, but this may&lt;br /&gt;
change in future versions.&lt;br /&gt;
&lt;br /&gt;
==== Filters ====&lt;br /&gt;
&lt;br /&gt;
Filter objects specify an action for packets fulfilling certain&lt;br /&gt;
criteria. The top-level attribute &#039;&#039;&#039;filter&#039;&#039;&#039; is a list of filter&lt;br /&gt;
objects. The precedence rules are similar to those of policy objects.&lt;br /&gt;
&lt;br /&gt;
In addition to the common rule attributes, filter objects can have a&lt;br /&gt;
&#039;&#039;&#039;service&#039;&#039;&#039; attribute constraining the scope to specific services&lt;br /&gt;
only. This attribute is a list of service names, referring to the&lt;br /&gt;
keys of the top-level &#039;&#039;&#039;service&#039;&#039;&#039; dictionary.&lt;br /&gt;
&lt;br /&gt;
Filter objects may also contain limits for packet flow or new&lt;br /&gt;
connections. These are specified with the &#039;&#039;&#039;flow-limit&#039;&#039;&#039; and&lt;br /&gt;
&#039;&#039;&#039;conn-limit&#039;&#039;&#039; attributes, respectively. The values of these&lt;br /&gt;
attributes are limit objects that have two attributes: &#039;&#039;&#039;count&#039;&#039;&#039; and&lt;br /&gt;
&#039;&#039;&#039;interval&#039;&#039;&#039;. &#039;&#039;&#039;count&#039;&#039;&#039; specifies how many new connections or&lt;br /&gt;
packets are allowed within the time frame specified by &#039;&#039;&#039;interval&#039;&#039;&#039;&lt;br /&gt;
(in seconds). The &#039;&#039;&#039;logdrop&#039;&#039;&#039; action is applied to the packets&lt;br /&gt;
exceeding the limit.&lt;br /&gt;
&lt;br /&gt;
Filter objects may have an attribute named &#039;&#039;&#039;dnat&#039;&#039;&#039;, the value of&lt;br /&gt;
which is an IPv4 address. If defined, this enables destination NAT for&lt;br /&gt;
all IPv4 packets matching the rule, such that the specified address&lt;br /&gt;
replaces the original destination address. This option has no effect&lt;br /&gt;
on IPv6 packets.&lt;br /&gt;
&lt;br /&gt;
==== Policies ====&lt;br /&gt;
&lt;br /&gt;
Policy objects describe the default action for packets that did not&lt;br /&gt;
match any filter. The top-level attribute &#039;&#039;&#039;policy&#039;&#039;&#039; is a list of&lt;br /&gt;
policy objects. Policy objects do not have other attributes than those&lt;br /&gt;
common to all rule objects.&lt;br /&gt;
&lt;br /&gt;
==== NAT Rules ====&lt;br /&gt;
&lt;br /&gt;
NAT rules come in two flavors: &#039;&#039;source NAT rules&#039;&#039; and&lt;br /&gt;
&#039;&#039;destination NAT rules&#039;&#039;. These are contained in two top-level lists&lt;br /&gt;
named &#039;&#039;&#039;snat&#039;&#039;&#039; and &#039;&#039;&#039;dnat&#039;&#039;&#039;, respectively.&lt;br /&gt;
&lt;br /&gt;
Each NAT rule must have an attribute named &#039;&#039;&#039;ip-range&#039;&#039;&#039; that&lt;br /&gt;
specifies the IPv4 address range to which the original source or&lt;br /&gt;
destinatinon address is mapped. The value can be a single IPv4 address&lt;br /&gt;
or a range specified by two addresses, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character.&lt;br /&gt;
&lt;br /&gt;
Optionally, a NAT rule can specify the TCP and UDP port range to which&lt;br /&gt;
the original source or destination port is mapped. The attribute is&lt;br /&gt;
named &#039;&#039;&#039;port-range&#039;&#039;&#039;, and the value can be a single port number or a&lt;br /&gt;
range specified by two numbers, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character. If &#039;&#039;&#039;port-range&#039;&#039;&#039; is not specified, the original port&lt;br /&gt;
number is kept intact.&lt;br /&gt;
&lt;br /&gt;
Like filters, NAT rules can have a &#039;&#039;&#039;service&#039;&#039;&#039; attribute&lt;br /&gt;
constraining their scope to specific services.&lt;br /&gt;
&lt;br /&gt;
=== IP Sets ===&lt;br /&gt;
&lt;br /&gt;
Any IP set referenced by rule objects should be created by&lt;br /&gt;
awall. Auxiliary &#039;&#039;IP set&#039;&#039; objects are used to defined them in awall&lt;br /&gt;
policy files. The top-level attribute &#039;&#039;&#039;ipset&#039;&#039;&#039; is a dictionary, the&lt;br /&gt;
keys of which are IP set names. The values are IP set objects, which&lt;br /&gt;
have two mandatory attributes. The attribute named &#039;&#039;&#039;type&#039;&#039;&#039;&lt;br /&gt;
corresponds to the type argument of the &amp;lt;tt&amp;gt;ipset create&amp;lt;/tt&amp;gt;&lt;br /&gt;
command. &#039;&#039;&#039;family&#039;&#039;&#039; specifies whether the set is for IPv4 or IPv6&lt;br /&gt;
addresses, and the possible values are &#039;&#039;&#039;inet&#039;&#039;&#039; and &#039;&#039;&#039;inet6&#039;&#039;&#039;,&lt;br /&gt;
correspondingly.&lt;br /&gt;
&lt;br /&gt;
== Command Line Syntax ==&lt;br /&gt;
&lt;br /&gt;
=== Translating Policy Files to Firewall Configuration Files ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall translate&#039;&#039;&#039; [&#039;&#039;&#039;-o&#039;&#039;&#039;|&#039;&#039;&#039;--output&#039;&#039;&#039; DIRECTORY] [&#039;&#039;&#039;-V&#039;&#039;&#039;|&#039;&#039;&#039;--verify&#039;&#039;&#039;]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--verify&amp;lt;/tt&amp;gt; option makes awall verify the configuration&lt;br /&gt;
using the test mode of iptables-restore before overwriting the old&lt;br /&gt;
files.&lt;br /&gt;
&lt;br /&gt;
Specifying the output directory allows testing awall policies without&lt;br /&gt;
overwriting the current iptables and ipset configuration files. By&lt;br /&gt;
default, awall generates the configuration to &amp;lt;tt&amp;gt;/etc/iptables&amp;lt;/tt&amp;gt;&lt;br /&gt;
and &amp;lt;tt&amp;gt;/etc/ipset.d&amp;lt;/tt&amp;gt;, which are read by the init scripts.&lt;br /&gt;
&lt;br /&gt;
=== Run-Time Activation of New Firewall Configuration ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall activate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This command genereates firewall configuration from the policy files&lt;br /&gt;
and enables it. If the user confirms the new configuration by hitting&lt;br /&gt;
the Return key within 10 seconds, the configuration is saved to the&lt;br /&gt;
files. Otherwise, the old configuration is restored.&lt;br /&gt;
&lt;br /&gt;
=== Optional Policies ===&lt;br /&gt;
&lt;br /&gt;
Optional policies can be enabled or disabled using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall&#039;&#039;&#039; {&#039;&#039;&#039;enable&#039;&#039;&#039;|&#039;&#039;&#039;disable&#039;&#039;&#039;} POLICY...&lt;br /&gt;
&lt;br /&gt;
Optional policies can be listed using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall list&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;enabled&#039;&#039;&#039; status means that the policy has been enabled by the&lt;br /&gt;
user. The &#039;&#039;&#039;disabled&#039;&#039;&#039; status means that the policy is not in&lt;br /&gt;
use. The &#039;&#039;&#039;required&#039;&#039;&#039; status means that the policy has not been&lt;br /&gt;
enabled by the user but is in use because it is required by another&lt;br /&gt;
policy which is in use.&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;/div&gt;</summary>
		<author><name>Jiufpt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8046</id>
		<title>Alpine Wall User&#039;s Guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall_User%27s_Guide&amp;diff=8046"/>
		<updated>2012-05-16T18:48:10Z</updated>

		<summary type="html">&lt;p&gt;Jiufpt: /* Configuration File Processing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Configuration File Processing ==&lt;br /&gt;
&lt;br /&gt;
[[Alpine Wall]] (awall) reads its configuration from multiple&lt;br /&gt;
JSON-formatted files, called &#039;&#039;policy files&#039;&#039;. The processing starts&lt;br /&gt;
from directory &amp;lt;tt&amp;gt;/usr/share/awall/mandatory&amp;lt;/tt&amp;gt;, which contains&lt;br /&gt;
mandatory policy files shipped with APK packages. After that,&lt;br /&gt;
installation-specific policy files in &amp;lt;tt&amp;gt;/etc/awall&amp;lt;/tt&amp;gt; are&lt;br /&gt;
processed.&lt;br /&gt;
&lt;br /&gt;
The latter directory may also contain symbolic links to policy files&lt;br /&gt;
located in &amp;lt;tt&amp;gt;/usr/share/awall/optional&amp;lt;/tt&amp;gt;. These are optional&lt;br /&gt;
policies, which can be enabled on need basis. Such symbolic links are&lt;br /&gt;
easily created and destroyed using the &amp;lt;tt&amp;gt;awall enable&amp;lt;/tt&amp;gt; and &lt;br /&gt;
&amp;lt;tt&amp;gt;awall disable&amp;lt;/tt&amp;gt; commands. &amp;lt;tt&amp;gt;awall list&amp;lt;/tt&amp;gt; shows which&lt;br /&gt;
optional policies are enabled and disabled. The command also prints&lt;br /&gt;
the description of the optional policy if defined in the file using&lt;br /&gt;
a top-level attribute named &#039;&#039;&#039;description&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Sometimes a policy file depends on other policy files. In this case,&lt;br /&gt;
the policy file must have a top-level attribute &#039;&#039;&#039;import&#039;&#039;&#039;, the&lt;br /&gt;
value of which is a list of policy names, which correspond to the file&lt;br /&gt;
names without the &amp;lt;tt&amp;gt;.json&amp;lt;/tt&amp;gt; suffix. The policies listed there are&lt;br /&gt;
always processed before the importing policy. The order of the&lt;br /&gt;
generated iptables rules generally reflects the processing order of&lt;br /&gt;
their corresponding awall policies.&lt;br /&gt;
&lt;br /&gt;
As the import directive does not require the path name to be&lt;br /&gt;
specified, awall expects policies to have unique names, even if&lt;br /&gt;
located in different directories. It is allowed to import optional&lt;br /&gt;
policies that are not explicitly enabled by the user. Such policies&lt;br /&gt;
show up with the &amp;lt;tt&amp;gt;required&amp;lt;/tt&amp;gt; status in the output of &amp;lt;tt&amp;gt;awall&lt;br /&gt;
list&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== List Parameters ==&lt;br /&gt;
&lt;br /&gt;
Several awall parameters are defined as lists of values. In order to&lt;br /&gt;
facilitate manual editing of policy files, awall also accepts single&lt;br /&gt;
values in place of lists. Such values are semantically equivalent to&lt;br /&gt;
lists containing one element.&lt;br /&gt;
&lt;br /&gt;
== Variable Expansion ==&lt;br /&gt;
&lt;br /&gt;
Awall allows variable definitions in policy files. The top-level&lt;br /&gt;
attribute &#039;&#039;&#039;variable&#039;&#039;&#039; is a dictionary containing the&lt;br /&gt;
definitions. The value of a variable can be of any type (string,&lt;br /&gt;
integer, list, or dictionary).&lt;br /&gt;
&lt;br /&gt;
A variable is referenced in policy files by a string which equals the&lt;br /&gt;
variable name prepended with the &#039;&#039;&#039;$&#039;&#039;&#039; character. If the value of&lt;br /&gt;
the variable is a string, the reference can be embedded into a longer&lt;br /&gt;
string in order to substitute some part of that string (in shell&lt;br /&gt;
style). Variable references can be used when defining other variables,&lt;br /&gt;
as long as the definitions are not circular.&lt;br /&gt;
&lt;br /&gt;
Policy files can reference variables defined in other policy&lt;br /&gt;
files. Policy files can also override variables defined elsewhere by&lt;br /&gt;
redefining them. In this case, the new definition affects all policy&lt;br /&gt;
files, also those processed before the overriding policy. Awall&lt;br /&gt;
variables are in fact simple macros, since each variable remains&lt;br /&gt;
constant thoughout a single processing round. If multiple files define&lt;br /&gt;
the same variable, the definition in the file processed last takes&lt;br /&gt;
effect.&lt;br /&gt;
&lt;br /&gt;
If defined as an empty string, all non-embedded references to a&lt;br /&gt;
variable evaluate as if the attribute in question was not present in&lt;br /&gt;
the configuration. This is also the case when a string containing&lt;br /&gt;
embedded variable references finally evaluates to an empty string.&lt;br /&gt;
&lt;br /&gt;
== Configuration Objects ==&lt;br /&gt;
&lt;br /&gt;
Configuration objects can be divided into two main types.&lt;br /&gt;
&#039;&#039;Auxiliary objects&#039;&#039; model high-level concepts such as services and&lt;br /&gt;
zones. &#039;&#039;Rule objects&#039;&#039; translate into one or more iptables rules, and&lt;br /&gt;
are often defined with the help of some auxiliary objects.&lt;br /&gt;
&lt;br /&gt;
=== Services ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;service&#039;&#039; represents a set of network protocols. A top-level&lt;br /&gt;
attribute &#039;&#039;&#039;service&#039;&#039;&#039; is a dictionary that maps service names to&lt;br /&gt;
service definition objects, or lists thereof in more complex cases.&lt;br /&gt;
&lt;br /&gt;
A service definition object contains an attribute named &#039;&#039;&#039;proto&#039;&#039;&#039;,&lt;br /&gt;
which corresponds to the &amp;lt;tt&amp;gt;--protocol&amp;lt;/tt&amp;gt; option of iptables. The&lt;br /&gt;
protocol can be defined as a numerical value or string as defined in&lt;br /&gt;
&amp;lt;tt&amp;gt;/etc/protocols&amp;lt;/tt&amp;gt;. If the protocol is &#039;&#039;&#039;tcp&#039;&#039;&#039; or &#039;&#039;&#039;udp&#039;&#039;&#039;,&lt;br /&gt;
the scope of the service definition may be constrained by defining an&lt;br /&gt;
attribute named &#039;&#039;&#039;port&#039;&#039;&#039;, which is a list of TCP or UDP port&lt;br /&gt;
numbers. If the protocol is &#039;&#039;&#039;icmp&#039;&#039;&#039; or &#039;&#039;&#039;icmpv6&#039;&#039;&#039;, an analogous&lt;br /&gt;
&#039;&#039;&#039;icmp-type&#039;&#039;&#039; attribute may be used. In addition, the scope of the&lt;br /&gt;
rule is also automatically limited to IPv4 or IPv6, respectively.&lt;br /&gt;
&lt;br /&gt;
=== Zones ===&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;zone&#039;&#039; represents a set of network hosts. A top-level attribute&lt;br /&gt;
&#039;&#039;&#039;zone&#039;&#039;&#039; is a dictionary that maps zone names to zone objects. A&lt;br /&gt;
zone object has an attribute named &#039;&#039;&#039;iface&#039;&#039;&#039;, &#039;&#039;&#039;addr&#039;&#039;&#039;, or&lt;br /&gt;
both. &#039;&#039;&#039;iface&#039;&#039;&#039; is a list of network interfaces and &#039;&#039;&#039;addr&#039;&#039;&#039; is a&lt;br /&gt;
list of IPv4/IPv6 host and network addresses (CIDR&lt;br /&gt;
notation). &#039;&#039;&#039;addr&#039;&#039;&#039; may also contain domain names, which are&lt;br /&gt;
expanded to IP addresses using DNS resolution. If not defined,&lt;br /&gt;
&#039;&#039;&#039;addr&#039;&#039;&#039; defaults to the entire address space and &#039;&#039;&#039;iface&#039;&#039;&#039; to all&lt;br /&gt;
interfaces.&lt;br /&gt;
&lt;br /&gt;
Rule objects contain two attributes, &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;, which are&lt;br /&gt;
lists of zone names. These attributes control whether a packet matches&lt;br /&gt;
the rule or not. If a particular zone is referenced by the &#039;&#039;&#039;in&#039;&#039;&#039;&lt;br /&gt;
attribute, the rule applies to packets whose ingress interface and&lt;br /&gt;
source address are covered by the zone definition. Correspondingly, if&lt;br /&gt;
a zone is referenced by the &#039;&#039;&#039;out&#039;&#039;&#039; attribute, the rule applies to&lt;br /&gt;
packets whose egress interface and destination address are included in&lt;br /&gt;
the zone. If both &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; are defined, the packet must&lt;br /&gt;
fulfill both criteria in order to match the rule.&lt;br /&gt;
&lt;br /&gt;
=== Rules ===&lt;br /&gt;
&lt;br /&gt;
There are three types of rule objects: &#039;&#039;policies&#039;&#039;, &#039;&#039;filters&#039;&#039;, and&lt;br /&gt;
&#039;&#039;NAT rules&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
All rule objects can have the &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039; attributes&lt;br /&gt;
referring to zones as described in the previous section. In addition,&lt;br /&gt;
the scope of the rule can be further constrained with the following&lt;br /&gt;
attributes:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Attribute!!Value format!!Effect&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;src&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s source address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;dest&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;addr&#039;&#039;&#039; attribute of zone objects&lt;br /&gt;
|Packet&#039;s destination address matches the value&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipset&#039;&#039;&#039;&lt;br /&gt;
|Object containing two attributes: &#039;&#039;&#039;name&#039;&#039;&#039; referring to an IP set and &#039;&#039;&#039;args&#039;&#039;&#039;, which is a list of strings &#039;&#039;&#039;in&#039;&#039;&#039; and &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|Packet matches the IP set referred here when the match arguments are taken from the source (&#039;&#039;&#039;in&#039;&#039;&#039;) and destination (&#039;&#039;&#039;out&#039;&#039;&#039;) address or port in the order specified by &#039;&#039;&#039;args&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;ipsec&#039;&#039;&#039;&lt;br /&gt;
|&#039;&#039;&#039;in&#039;&#039;&#039; or &#039;&#039;&#039;out&#039;&#039;&#039;&lt;br /&gt;
|IPsec decapsulation perfomed on ingress (&#039;&#039;&#039;in&#039;&#039;&#039;) or encapsulation performed on egress (&#039;&#039;&#039;out&#039;&#039;&#039;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects must have an attribute named &#039;&#039;&#039;action&#039;&#039;&#039;, the value of&lt;br /&gt;
which can be one of the following:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
!Value!!Action&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;accept&#039;&#039;&#039;&lt;br /&gt;
|Accept the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;reject&#039;&#039;&#039;&lt;br /&gt;
|Reject the packet with an ICMP error message&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;drop&#039;&#039;&#039;&lt;br /&gt;
|Silently drop the packet&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;logreject&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;reject&#039;&#039;&#039; but with kernel logging&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;logdrop&#039;&#039;&#039;&lt;br /&gt;
|Similar to &#039;&#039;&#039;drop&#039;&#039;&#039; but with kernel logging&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rule objects are declared in type-specific top-level dictionaries in&lt;br /&gt;
awall policy files. If a packet matches multiple rules, the one&lt;br /&gt;
appearing earlier in the list takes precedence. If the matching rules&lt;br /&gt;
are defined in different policy files, the one that was processed&lt;br /&gt;
earlier takes precedence in the current implementation, but this may&lt;br /&gt;
change in future versions.&lt;br /&gt;
&lt;br /&gt;
==== Filters ====&lt;br /&gt;
&lt;br /&gt;
Filter objects specify an action for packets fulfilling certain&lt;br /&gt;
criteria. The top-level attribute &#039;&#039;&#039;filter&#039;&#039;&#039; is a list of filter&lt;br /&gt;
objects. The precedence rules are similar to those of policy objects.&lt;br /&gt;
&lt;br /&gt;
In addition to the common rule attributes, filter objects can have a&lt;br /&gt;
&#039;&#039;&#039;service&#039;&#039;&#039; attribute constraining the scope to specific services&lt;br /&gt;
only. This attribute is a list of service names, referring to the&lt;br /&gt;
keys of the top-level &#039;&#039;&#039;service&#039;&#039;&#039; dictionary.&lt;br /&gt;
&lt;br /&gt;
Filter objects may also contain limits for packet flow or new&lt;br /&gt;
connections. These are specified with the &#039;&#039;&#039;flow-limit&#039;&#039;&#039; and&lt;br /&gt;
&#039;&#039;&#039;conn-limit&#039;&#039;&#039; attributes, respectively. The values of these&lt;br /&gt;
attributes are limit objects that have two attributes: &#039;&#039;&#039;count&#039;&#039;&#039; and&lt;br /&gt;
&#039;&#039;&#039;interval&#039;&#039;&#039;. &#039;&#039;&#039;count&#039;&#039;&#039; specifies how many new connections or&lt;br /&gt;
packets are allowed within the time frame specified by &#039;&#039;&#039;interval&#039;&#039;&#039;&lt;br /&gt;
(in seconds). The &#039;&#039;&#039;logdrop&#039;&#039;&#039; action is applied to the packets&lt;br /&gt;
exceeding the limit.&lt;br /&gt;
&lt;br /&gt;
Filter objects may have an attribute named &#039;&#039;&#039;dnat&#039;&#039;&#039;, the value of&lt;br /&gt;
which is an IPv4 address. If defined, this enables destination NAT for&lt;br /&gt;
all IPv4 packets matching the rule, such that the specified address&lt;br /&gt;
replaces the original destination address. This option has no effect&lt;br /&gt;
on IPv6 packets.&lt;br /&gt;
&lt;br /&gt;
==== Policies ====&lt;br /&gt;
&lt;br /&gt;
Policy objects describe the default action for packets that did not&lt;br /&gt;
match any filter. The top-level attribute &#039;&#039;&#039;policy&#039;&#039;&#039; is a list of&lt;br /&gt;
policy objects. Policy objects do not have other attributes than those&lt;br /&gt;
common to all rule objects.&lt;br /&gt;
&lt;br /&gt;
==== NAT Rules ====&lt;br /&gt;
&lt;br /&gt;
NAT rules come in two flavors: &#039;&#039;source NAT rules&#039;&#039; and&lt;br /&gt;
&#039;&#039;destination NAT rules&#039;&#039;. These are contained in two top-level lists&lt;br /&gt;
named &#039;&#039;&#039;snat&#039;&#039;&#039; and &#039;&#039;&#039;dnat&#039;&#039;&#039;, respectively.&lt;br /&gt;
&lt;br /&gt;
Each NAT rule must have an attribute named &#039;&#039;&#039;ip-range&#039;&#039;&#039; that&lt;br /&gt;
specifies the IPv4 address range to which the original source or&lt;br /&gt;
destinatinon address is mapped. The value can be a single IPv4 address&lt;br /&gt;
or a range specified by two addresses, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character.&lt;br /&gt;
&lt;br /&gt;
Optionally, a NAT rule can specify the TCP and UDP port range to which&lt;br /&gt;
the original source or destination port is mapped. The attribute is&lt;br /&gt;
named &#039;&#039;&#039;port-range&#039;&#039;&#039;, and the value can be a single port number or a&lt;br /&gt;
range specified by two numbers, separated with the &#039;&#039;&#039;-&#039;&#039;&#039;&lt;br /&gt;
character. If &#039;&#039;&#039;port-range&#039;&#039;&#039; is not specified, the original port&lt;br /&gt;
number is kept intact.&lt;br /&gt;
&lt;br /&gt;
Like filters, NAT rules can have a &#039;&#039;&#039;service&#039;&#039;&#039; attribute&lt;br /&gt;
constraining their scope to specific services.&lt;br /&gt;
&lt;br /&gt;
=== IP Sets ===&lt;br /&gt;
&lt;br /&gt;
Any IP set referenced by rule objects should be created by&lt;br /&gt;
awall. Auxiliary &#039;&#039;IP set&#039;&#039; objects are used to defined them in awall&lt;br /&gt;
policy files. The top-level attribute &#039;&#039;&#039;ipset&#039;&#039;&#039; is a dictionary, the&lt;br /&gt;
keys of which are IP set names. The values are IP set objects, which&lt;br /&gt;
have two mandatory attributes. The attribute named &#039;&#039;&#039;type&#039;&#039;&#039;&lt;br /&gt;
corresponds to the type argument of the &amp;lt;tt&amp;gt;ipset create&amp;lt;/tt&amp;gt;&lt;br /&gt;
command. &#039;&#039;&#039;family&#039;&#039;&#039; specifies whether the set is for IPv4 or IPv6&lt;br /&gt;
addresses, and the possible values are &#039;&#039;&#039;inet&#039;&#039;&#039; and &#039;&#039;&#039;inet6&#039;&#039;&#039;,&lt;br /&gt;
correspondingly.&lt;br /&gt;
&lt;br /&gt;
== Command Line Syntax ==&lt;br /&gt;
&lt;br /&gt;
=== Translating Policy Files to Firewall Configuration Files ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall translate&#039;&#039;&#039; [&#039;&#039;&#039;-o&#039;&#039;&#039;|&#039;&#039;&#039;--output&#039;&#039;&#039; DIRECTORY] [&#039;&#039;&#039;-V&#039;&#039;&#039;|&#039;&#039;&#039;--verify&#039;&#039;&#039;]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;--verify&amp;lt;/tt&amp;gt; option makes awall verify the configuration&lt;br /&gt;
using the test mode of iptables-restore before overwriting the old&lt;br /&gt;
files.&lt;br /&gt;
&lt;br /&gt;
Specifying the output directory allows testing awall policies without&lt;br /&gt;
overwriting the current iptables and ipset configuration files. By&lt;br /&gt;
default, awall generates the configuration to &amp;lt;tt&amp;gt;/etc/iptables&amp;lt;/tt&amp;gt;&lt;br /&gt;
and &amp;lt;tt&amp;gt;/etc/ipset.d&amp;lt;/tt&amp;gt;, which are read by the init scripts.&lt;br /&gt;
&lt;br /&gt;
=== Run-Time Activation of New Firewall Configuration ===&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall activate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This command genereates firewall configuration from the policy files&lt;br /&gt;
and enables it. If the user confirms the new configuration by hitting&lt;br /&gt;
the Return key within 10 seconds, the configuration is saved to the&lt;br /&gt;
files. Otherwise, the old configuration is restored.&lt;br /&gt;
&lt;br /&gt;
=== Optional Policies ===&lt;br /&gt;
&lt;br /&gt;
Optional policies can be enabled or disabled using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall&#039;&#039;&#039; {&#039;&#039;&#039;enable&#039;&#039;&#039;|&#039;&#039;&#039;disable&#039;&#039;&#039;} POLICY...&lt;br /&gt;
&lt;br /&gt;
Optional policies can be listed using this command:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;awall list&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;enabled&#039;&#039;&#039; status means that the policy has been enabled by the&lt;br /&gt;
user. The &#039;&#039;&#039;disabled&#039;&#039;&#039; status means that the policy is not in&lt;br /&gt;
use. The &#039;&#039;&#039;required&#039;&#039;&#039; status means that the policy has not been&lt;br /&gt;
enabled by the user but is in use because it is required by another&lt;br /&gt;
policy which is in use.&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;/div&gt;</summary>
		<author><name>Jiufpt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall&amp;diff=8045</id>
		<title>Alpine Wall</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall&amp;diff=8045"/>
		<updated>2012-05-16T18:41:39Z</updated>

		<summary type="html">&lt;p&gt;Jiufpt: /* Implementation Considerations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is a design and implementation plan for a new firewall&lt;br /&gt;
management framework. The new framework addresses the limitations&lt;br /&gt;
of Shorewall, which is probably the most common solution used&lt;br /&gt;
with Alpine.&lt;br /&gt;
&lt;br /&gt;
== Proposal ==&lt;br /&gt;
&lt;br /&gt;
We evaluated serveral existing open source projects, none of which&lt;br /&gt;
satisfied our demanding taste. The existing solutions are either too&lt;br /&gt;
tied to specific (router) distributions, targeted to home users (with&lt;br /&gt;
too many assumptions built-in), or depedent on bloated frameworks&lt;br /&gt;
(usually Perl). Moreover, we would like to keep management of firewall&lt;br /&gt;
settings and activation of such settings as two separate workflows,&lt;br /&gt;
which would facilitate centralized management of firewall rules.&lt;br /&gt;
&lt;br /&gt;
As no readily available solution was found, the proposal is to&lt;br /&gt;
implement a new management framework for &amp;lt;code&amp;gt;iptables&amp;lt;/code&amp;gt;, which&lt;br /&gt;
would integrate with the&lt;br /&gt;
[[Alpine Configuration Framework Design|Alpine Configuration&lt;br /&gt;
Framework]]&lt;br /&gt;
(ACF). The framework is hereafter referred to as the Alpine Wall&lt;br /&gt;
(awall).&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
Awall would consist of three major components: data model, front-end,&lt;br /&gt;
and back-end. It also implements a plug-in architecture, which allows&lt;br /&gt;
extending the data model and functionality, in order to simplify&lt;br /&gt;
common organization-specific administrative tasks.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;data model&#039;&#039;&#039; would describe the firewall configuration using&lt;br /&gt;
concepts and terminology that is roughly compatible with Shorewall. It&lt;br /&gt;
would also borrow some useful concepts from other firewall solutions&lt;br /&gt;
we evaluated, such as the Service concept as defined in the&lt;br /&gt;
[http://www.turtlefirewall.com/manual-en/x161.html Turtle Firewall]&lt;br /&gt;
(but generalized a bit). Awall plug-ins can contain schema extension&lt;br /&gt;
modules augmenting the basic model provided by the framework.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;back-end&#039;&#039;&#039; is responsible for translating the model&#039;s data&lt;br /&gt;
into configuration files, most notably the files that can be read by&lt;br /&gt;
&amp;lt;code&amp;gt;iptables-restore&amp;lt;/code&amp;gt; and&lt;br /&gt;
&amp;lt;code&amp;gt;ip6tables-restore&amp;lt;/code&amp;gt;. Moreover, it can produce files into&lt;br /&gt;
e.g. &amp;lt;code&amp;gt;/etc/modprobe.d&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;/etc/sysctl.d&amp;lt;/code&amp;gt; if&lt;br /&gt;
necessary. When a plug-in extends the data model, it must also provide&lt;br /&gt;
a back-end module that interprets model extension and translates the&lt;br /&gt;
data into &amp;lt;code&amp;gt;iptables&amp;lt;/code&amp;gt; and other rules. The framework&lt;br /&gt;
includes a module for interpreting the base model. The framework is&lt;br /&gt;
responsible for ordering and aggregating the results produced by all&lt;br /&gt;
modules into actual configuration files.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;front-end&#039;&#039;&#039; is essentially an ACF module which allows editing&lt;br /&gt;
the data model and activating the changes with the help of the&lt;br /&gt;
back-end. The front-end implements also a fallback mechanism that&lt;br /&gt;
prevents the operator from locking himself out by a faulty&lt;br /&gt;
configuration. The configuration data is stored in text files which&lt;br /&gt;
can be directly edited. The front-end provides a command line tool for&lt;br /&gt;
validating and activating the configuration after manual changes.&lt;br /&gt;
&lt;br /&gt;
== Base Model ==&lt;br /&gt;
&lt;br /&gt;
The basic data model could roughly look like as follows:&lt;br /&gt;
&lt;br /&gt;
;Zone&lt;br /&gt;
; &amp;lt;code&amp;gt;interface*, subnet*&amp;lt;/code&amp;gt;&lt;br /&gt;
;Service&lt;br /&gt;
; &amp;lt;code&amp;gt;(protocol, port*)+&amp;lt;/code&amp;gt;&lt;br /&gt;
;Forwarding policy&lt;br /&gt;
; &amp;lt;code&amp;gt;Zone:in*, Zone:out*, accept/reject/drop, masq_on/masq_off&amp;lt;/code&amp;gt;&lt;br /&gt;
;Filtering rule&lt;br /&gt;
; &amp;lt;code&amp;gt;Zone:in*, Zone:out*, Service+, accept/reject/drop, conn_limit?, flow_limit?&amp;lt;/code&amp;gt;&lt;br /&gt;
;NAT rule&lt;br /&gt;
; &amp;lt;code&amp;gt;snat/dnat, Zone:in*, Zone:out*, Service, ip4_range, port_range?&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Subnets in zone definitions can be declared using IPv4/IPv6 addresses&lt;br /&gt;
(CIDR notation), domain names, or as references to &lt;br /&gt;
[http://ipset.netfilter.org/ipset.man.html ipsets]. A domain name can&lt;br /&gt;
resolve to one or more IP addresses. The referred ipsets may be&lt;br /&gt;
managed manually or by some other tool.&lt;br /&gt;
&lt;br /&gt;
If a packet with source address &#039;&#039;a&#039;&#039; arrives on interface &#039;&#039;i&#039;&#039;, it&lt;br /&gt;
is considered to originate from zone &#039;&#039;Z = (I, S)&#039;&#039; (where &#039;&#039;I&#039;&#039; is&lt;br /&gt;
the set of interfaces and &#039;&#039;S&#039;&#039; is the set of subnets) if and only if &lt;br /&gt;
&#039;&#039;I&#039;&#039; includes &#039;&#039;i&#039;&#039;, and &#039;&#039;a&#039;&#039; belongs to any subnet of &#039;&#039;S&#039;&#039;. In&lt;br /&gt;
zone definitions, &#039;&#039;I&#039;&#039; would default to the set of all interfaces and &lt;br /&gt;
&#039;&#039;S&#039;&#039; to {0.0.0.0/0, ::}. The destination zone would be defined in a&lt;br /&gt;
similar way based on the packet&#039;s destination address and interface.&lt;br /&gt;
&lt;br /&gt;
== Implementation Considerations ==&lt;br /&gt;
&lt;br /&gt;
The data model should preferably be based on some existing format,&lt;br /&gt;
such as JSON, XML, or YAML. In order to allow extensions to the data&lt;br /&gt;
model, awall must define some kind of schema language. This language&lt;br /&gt;
would embed the necessary information the front-end needs to&lt;br /&gt;
automatically generate a user interface for the extension. For&lt;br /&gt;
example, the help texts shown to the user would be placed in the&lt;br /&gt;
schema modules.&lt;br /&gt;
&lt;br /&gt;
Ideally, the base model would be described using the very same&lt;br /&gt;
language as the model extensions, but it would impose quite demanding&lt;br /&gt;
requirements on the language, e.g. support for complex data types. If&lt;br /&gt;
we select this approach and model the data using XML, we could use XML&lt;br /&gt;
Schema as the basis. There is also an (expired) Internet Draft on &lt;br /&gt;
[http://tools.ietf.org/html/draft-zyp-json-schema-03 JSON Schema], but&lt;br /&gt;
there seems to be no existing validator implementation in C or Lua.&lt;br /&gt;
&lt;br /&gt;
Even though elegant from architecture point of view, it is unlikely&lt;br /&gt;
that support for complex data types would be required by typical&lt;br /&gt;
extensions. In most cases, a set of global variables of primitive&lt;br /&gt;
types would suffice. Therefore, we could just use a very simple&lt;br /&gt;
language for declaring such variables or implement support for a&lt;br /&gt;
limited subset of some well-known schema language. In this&lt;br /&gt;
alternative, the base model would not be described using this language&lt;br /&gt;
but rather hard-coded into the front-end.&lt;br /&gt;
&lt;br /&gt;
The back-end modules are responsible for translating the configuration&lt;br /&gt;
data into configuration file fragments. As regards their&lt;br /&gt;
implementation, we have two alternatives. The first alternative is to&lt;br /&gt;
implement them as Lua functions invoked by the framework in a defined&lt;br /&gt;
way. The framework would provide a library that allows the said&lt;br /&gt;
functions to access the data model, and also otherwise assists in&lt;br /&gt;
their implementation. The functions would report the results back to&lt;br /&gt;
the framework, which finally would translate them into target files.&lt;br /&gt;
&lt;br /&gt;
In the second alternative, the back-end modules would be implemented&lt;br /&gt;
using a template language rather than a general-purpose programming&lt;br /&gt;
language. An example of a firewall-related template language is&lt;br /&gt;
[http://ferm.foo-projects.org/download/2.1/ferm.html ferm], which&lt;br /&gt;
unfortunately is implemented in Perl. Ferm also lacks certain&lt;br /&gt;
capabilities required to implement e.g. the Zone and Service concepts&lt;br /&gt;
conveniently. However, we could introduce a new template language that&lt;br /&gt;
would better suit our purposes. Such a language would eliminate some&lt;br /&gt;
redundancy from the back-end modules which necessarily comes with the&lt;br /&gt;
use of a general-purpose language. On the other hand, developing and&lt;br /&gt;
maintaining such a language would take effort and might make the&lt;br /&gt;
framework initially more difficult to use.&lt;br /&gt;
&lt;br /&gt;
The back-end will contain functionality for domain name resolution. In&lt;br /&gt;
the data model, hosts of groups thereof can be identified by their&lt;br /&gt;
domain names. The back-end will resolve these to IP addresses, which&lt;br /&gt;
will be stored in the target files, so there will be no need to&lt;br /&gt;
resolve anything when activating the configuration during boot.&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]] [[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Jiufpt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall&amp;diff=8044</id>
		<title>Alpine Wall</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Alpine_Wall&amp;diff=8044"/>
		<updated>2012-05-16T18:40:18Z</updated>

		<summary type="html">&lt;p&gt;Jiufpt: /* Base Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is a design and implementation plan for a new firewall&lt;br /&gt;
management framework. The new framework addresses the limitations&lt;br /&gt;
of Shorewall, which is probably the most common solution used&lt;br /&gt;
with Alpine.&lt;br /&gt;
&lt;br /&gt;
== Proposal ==&lt;br /&gt;
&lt;br /&gt;
We evaluated serveral existing open source projects, none of which&lt;br /&gt;
satisfied our demanding taste. The existing solutions are either too&lt;br /&gt;
tied to specific (router) distributions, targeted to home users (with&lt;br /&gt;
too many assumptions built-in), or depedent on bloated frameworks&lt;br /&gt;
(usually Perl). Moreover, we would like to keep management of firewall&lt;br /&gt;
settings and activation of such settings as two separate workflows,&lt;br /&gt;
which would facilitate centralized management of firewall rules.&lt;br /&gt;
&lt;br /&gt;
As no readily available solution was found, the proposal is to&lt;br /&gt;
implement a new management framework for &amp;lt;code&amp;gt;iptables&amp;lt;/code&amp;gt;, which&lt;br /&gt;
would integrate with the&lt;br /&gt;
[[Alpine Configuration Framework Design|Alpine Configuration&lt;br /&gt;
Framework]]&lt;br /&gt;
(ACF). The framework is hereafter referred to as the Alpine Wall&lt;br /&gt;
(awall).&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
&lt;br /&gt;
Awall would consist of three major components: data model, front-end,&lt;br /&gt;
and back-end. It also implements a plug-in architecture, which allows&lt;br /&gt;
extending the data model and functionality, in order to simplify&lt;br /&gt;
common organization-specific administrative tasks.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;data model&#039;&#039;&#039; would describe the firewall configuration using&lt;br /&gt;
concepts and terminology that is roughly compatible with Shorewall. It&lt;br /&gt;
would also borrow some useful concepts from other firewall solutions&lt;br /&gt;
we evaluated, such as the Service concept as defined in the&lt;br /&gt;
[http://www.turtlefirewall.com/manual-en/x161.html Turtle Firewall]&lt;br /&gt;
(but generalized a bit). Awall plug-ins can contain schema extension&lt;br /&gt;
modules augmenting the basic model provided by the framework.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;back-end&#039;&#039;&#039; is responsible for translating the model&#039;s data&lt;br /&gt;
into configuration files, most notably the files that can be read by&lt;br /&gt;
&amp;lt;code&amp;gt;iptables-restore&amp;lt;/code&amp;gt; and&lt;br /&gt;
&amp;lt;code&amp;gt;ip6tables-restore&amp;lt;/code&amp;gt;. Moreover, it can produce files into&lt;br /&gt;
e.g. &amp;lt;code&amp;gt;/etc/modprobe.d&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;/etc/sysctl.d&amp;lt;/code&amp;gt; if&lt;br /&gt;
necessary. When a plug-in extends the data model, it must also provide&lt;br /&gt;
a back-end module that interprets model extension and translates the&lt;br /&gt;
data into &amp;lt;code&amp;gt;iptables&amp;lt;/code&amp;gt; and other rules. The framework&lt;br /&gt;
includes a module for interpreting the base model. The framework is&lt;br /&gt;
responsible for ordering and aggregating the results produced by all&lt;br /&gt;
modules into actual configuration files.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;front-end&#039;&#039;&#039; is essentially an ACF module which allows editing&lt;br /&gt;
the data model and activating the changes with the help of the&lt;br /&gt;
back-end. The front-end implements also a fallback mechanism that&lt;br /&gt;
prevents the operator from locking himself out by a faulty&lt;br /&gt;
configuration. The configuration data is stored in text files which&lt;br /&gt;
can be directly edited. The front-end provides a command line tool for&lt;br /&gt;
validating and activating the configuration after manual changes.&lt;br /&gt;
&lt;br /&gt;
== Base Model ==&lt;br /&gt;
&lt;br /&gt;
The basic data model could roughly look like as follows:&lt;br /&gt;
&lt;br /&gt;
;Zone&lt;br /&gt;
; &amp;lt;code&amp;gt;interface*, subnet*&amp;lt;/code&amp;gt;&lt;br /&gt;
;Service&lt;br /&gt;
; &amp;lt;code&amp;gt;(protocol, port*)+&amp;lt;/code&amp;gt;&lt;br /&gt;
;Forwarding policy&lt;br /&gt;
; &amp;lt;code&amp;gt;Zone:in*, Zone:out*, accept/reject/drop, masq_on/masq_off&amp;lt;/code&amp;gt;&lt;br /&gt;
;Filtering rule&lt;br /&gt;
; &amp;lt;code&amp;gt;Zone:in*, Zone:out*, Service+, accept/reject/drop, conn_limit?, flow_limit?&amp;lt;/code&amp;gt;&lt;br /&gt;
;NAT rule&lt;br /&gt;
; &amp;lt;code&amp;gt;snat/dnat, Zone:in*, Zone:out*, Service, ip4_range, port_range?&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Subnets in zone definitions can be declared using IPv4/IPv6 addresses&lt;br /&gt;
(CIDR notation), domain names, or as references to &lt;br /&gt;
[http://ipset.netfilter.org/ipset.man.html ipsets]. A domain name can&lt;br /&gt;
resolve to one or more IP addresses. The referred ipsets may be&lt;br /&gt;
managed manually or by some other tool.&lt;br /&gt;
&lt;br /&gt;
If a packet with source address &#039;&#039;a&#039;&#039; arrives on interface &#039;&#039;i&#039;&#039;, it&lt;br /&gt;
is considered to originate from zone &#039;&#039;Z = (I, S)&#039;&#039; (where &#039;&#039;I&#039;&#039; is&lt;br /&gt;
the set of interfaces and &#039;&#039;S&#039;&#039; is the set of subnets) if and only if &lt;br /&gt;
&#039;&#039;I&#039;&#039; includes &#039;&#039;i&#039;&#039;, and &#039;&#039;a&#039;&#039; belongs to any subnet of &#039;&#039;S&#039;&#039;. In&lt;br /&gt;
zone definitions, &#039;&#039;I&#039;&#039; would default to the set of all interfaces and &lt;br /&gt;
&#039;&#039;S&#039;&#039; to {0.0.0.0/0, ::}. The destination zone would be defined in a&lt;br /&gt;
similar way based on the packet&#039;s destination address and interface.&lt;br /&gt;
&lt;br /&gt;
== Implementation Considerations ==&lt;br /&gt;
&lt;br /&gt;
The data model should preferably be based on some existing format,&lt;br /&gt;
such as JSON, XML, or YAML. In order to allow extensions to the data&lt;br /&gt;
model, awall must define some kind of schema language. This language&lt;br /&gt;
would embed the necessary information the front-end needs to&lt;br /&gt;
automatically generate a user interface for the extension. For&lt;br /&gt;
example, the help texts shown to the user would be placed in the&lt;br /&gt;
schema modules.&lt;br /&gt;
&lt;br /&gt;
Ideally, the base model would be described using the very same&lt;br /&gt;
language as the model extensions, but it would impose quite demanding&lt;br /&gt;
requirements on the language, e.g. support for complex data types. If&lt;br /&gt;
we select this approach and model the data using XML, we could use XML&lt;br /&gt;
Schema as the basis. There is also an (expired) Internet Draft on&lt;br /&gt;
[http://tools.ietf.org/html/draft-zyp-json-schema-03 JSON Schema], but&lt;br /&gt;
there seems to be no existing validator implementation in C or Lua.&lt;br /&gt;
&lt;br /&gt;
Even though elegant from architecture point of view, it is unlikely&lt;br /&gt;
that support for complex data types would be required by typical&lt;br /&gt;
extensions. In most cases, a set of global variables of primitive&lt;br /&gt;
types would suffice. Therefore, we could just use a very simple&lt;br /&gt;
language for declaring such variables or implement support for a&lt;br /&gt;
limited subset of some well-known schema language. In this&lt;br /&gt;
alternative, the base model would not be described using this language&lt;br /&gt;
but rather hard-coded into the front-end.&lt;br /&gt;
&lt;br /&gt;
The back-end modules are responsible for translating the configuration&lt;br /&gt;
data into configuration file fragments. As regards their&lt;br /&gt;
implementation, we have two alternatives. The first alternative is to&lt;br /&gt;
implement them as Lua functions invoked by the framework in a defined&lt;br /&gt;
way. The framework would provide a library that allows the said&lt;br /&gt;
functions to access the data model, and also otherwise assists in&lt;br /&gt;
their implementation. The functions would report the results back to&lt;br /&gt;
the framework, which finally would translate them into target files.&lt;br /&gt;
&lt;br /&gt;
In the second alternative, the back-end modules would be implemented&lt;br /&gt;
using a template language rather than a general-purpose programming&lt;br /&gt;
language. An example of a firewall-related template language is&lt;br /&gt;
[http://ferm.foo-projects.org/download/2.1/ferm.html ferm], which&lt;br /&gt;
unfortunately is implemented in Perl. Ferm also lacks certain&lt;br /&gt;
capabilities required to implement e.g. the Zone and Service concepts&lt;br /&gt;
conveniently. However, we could introduce a new template language that&lt;br /&gt;
would better suit our purposes. Such a language would eliminate some&lt;br /&gt;
redundancy from the back-end modules which necessarily comes with the&lt;br /&gt;
use of a general-purpose language. On the other hand, developing and&lt;br /&gt;
maintaining such a language would take effort and might make the&lt;br /&gt;
framework initially more difficult to use.&lt;br /&gt;
&lt;br /&gt;
The back-end will contain functionality for domain name resolution. In&lt;br /&gt;
the data model, hosts of groups thereof can be identified by their&lt;br /&gt;
domain names. The back-end will resolve these to IP addresses, which&lt;br /&gt;
will be stored in the target files, so there will be no need to&lt;br /&gt;
resolve anything when activating the configuration during boot.&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]] [[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Jiufpt</name></author>
	</entry>
</feed>