Imported Upstream version 1.2.4
[archive/platform/upstream/libvirt.git] / docs / formatnwfilter.html.in
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4   <body>
5     <h1>Network Filters</h1>
6
7     <ul id="toc">
8     </ul>
9
10     <p>
11       This page provides an introduction to libvirt's network filters,
12       their goals, concepts and XML format.
13     </p>
14
15     <h2><a name="goals">Goals and background</a></h2>
16
17     <p>
18       The goal of the network filtering XML is to enable administrators
19       of a virtualized system to configure and enforce network traffic
20       filtering rules on virtual
21       machines and manage the parameters of network traffic that
22       virtual machines
23       are allowed to send or receive.
24       The network traffic filtering rules are
25       applied on the host when a virtual machine is started. Since the
26       filtering rules
27       cannot be circumvented from within
28       the virtual machine, it makes them mandatory from the point of
29       view of a virtual machine user.
30       <br/><br/>
31       The network filter subsystem allows each virtual machine's network
32       traffic filtering rules to be configured individually on a per
33       interface basis. The rules are
34       applied on the host when the virtual machine is started and can be modified
35       while the virtual machine is running. The latter can be achieved by
36       modifying the XML description of a network filter.
37       <br/><br/>
38       Multiple virtual machines can make use of the same generic network filter.
39       When such a filter is modified, the network traffic filtering rules
40       of all running virtual machines that reference this filter are updated.
41       <br/><br/>
42       Network filtering support is available <span class="since">since 0.8.1
43       (Qemu, KVM)</span>
44     </p>
45
46     <h2><a name="nwfconcepts">Concepts</a></h2>
47     <p>
48       The network traffic filtering subsystem enables configuration
49       of network traffic filtering rules on individual network
50       interfaces that are configured for certain types of
51       network configurations. Supported network types are
52     </p>
53       <ul>
54        <li><code>network</code></li>
55        <li><code>ethernet</code> -- must be used in bridging mode</li>
56        <li><code>bridge</code></li>
57       </ul>
58     <p>
59     The interface XML is used to reference a top-level filter. In the
60     following example, the interface description references
61     the filter <code>clean-traffic</code>.
62     </p>
63 <pre>
64   ...
65   &lt;devices&gt;
66     &lt;interface type='bridge'&gt;
67       &lt;mac address='00:16:3e:5d:c7:9e'/&gt;
68       &lt;filterref filter='clean-traffic'/&gt;
69     &lt;/interface&gt;
70   &lt;/devices&gt;
71   ...</pre>
72
73     <p>
74     Network filters are written in XML and may either contain references
75     to other filters, contain rules for traffic filtering, or
76     hold a combination of both. The above referenced filter
77     <code>clean-traffic </code> is a filter that only contains references to
78     other filters and no actual filtering rules. Since references to
79     other filters can be used, a <i>tree</i> of filters can be built.
80     The <code>clean-traffic</code> filter can be viewed using the
81     command <code>virsh nwfilter-dumpxml clean-traffic</code>.
82     <br/><br/>
83     As previously mentioned, a single network filter can be referenced
84     by multiple virtual machines. Since interfaces will typically
85     have individual parameters associated with their respective traffic
86     filtering rules, the rules described in a filter XML can
87     be parameterized with variables. In this case, the variable name
88     is used in the filter XML and the name and value are provided at the
89     place where the filter is referenced. In the
90     following example, the interface description has been extended with
91     the parameter <code>IP</code> and a dotted IP address as value.
92     </p>
93 <pre>
94   ...
95   &lt;devices&gt;
96     &lt;interface type='bridge'&gt;
97       &lt;mac address='00:16:3e:5d:c7:9e'/&gt;
98       &lt;filterref filter='clean-traffic'&gt;
99         &lt;parameter name='IP' value='10.0.0.1'/&gt;
100       &lt;/filterref&gt;
101     &lt;/interface&gt;
102   &lt;/devices&gt;
103   ...</pre>
104
105     <p>
106       In this particular example, the <code>clean-traffic</code> network
107       traffic filter will be instantiated with the IP address parameter
108       10.0.0.1 and enforce that the traffic from this interface will
109       always be using 10.0.0.1 as the source IP address, which is
110       one of the purposes of this particular filter.
111       <br/><br/>
112     </p>
113
114     <h3><a name="nwfconceptschains">Filtering chains</a></h3>
115     <p>
116       Filtering rules are organized in filter chains. These chains can be
117       thought of as having a tree structure with packet
118       filtering rules as entries in individual chains (branches). <br/>
119       Packets start their filter evaluation in the <code>root</code> chain
120       and can then continue their evaluation in other chains, return from
121       those chains back into the <code>root</code> chain or be
122       dropped or accepted by a filtering rule in one of the traversed chains.
123       <br/>
124       Libvirt's network filtering system automatically creates individual
125       <code>root</code> chains for every virtual machine's network interface
126       on which the user chooses to activate traffic filtering.
127       The user may write filtering rules that are either directly instantiated
128       in the <code>root</code> chain or may create protocol-specific
129       filtering chains for efficient evaluation of protocol-specific rules.
130       The following chains exist:
131     </p>
132     <ul>
133      <li>root</li>
134      <li>mac <span class="since">(since 0.9.8)</span></li>
135      <li>stp (spanning tree protocol)
136          <span class="since">(since 0.9.8)</span></li>
137      <li>vlan (802.1Q) <span class="since">(since 0.9.8)</span></li>
138      <li>arp, rarp</li>
139      <li>ipv4</li>
140      <li>ipv6</li>
141     </ul>
142     <p>
143       <span class="since">Since 0.9.8</span> multiple chains evaluating the
144       <code>mac</code>, <code>stp</code>, <code>vlan</code>,
145       <code>arp</code>, <code>rarp</code>, <code>ipv4</code>, or
146       <code>ipv6</code> protocol can be created using
147       the protocol name only as a prefix in the chain's name. This for
148       examples allows chains with names <code>arp-xyz</code> or
149       <code>arp-test</code> to be specified and have ARP protocol packets
150       evaluated in those chains.
151     <br/><br/>
152       The following filter shows an example of filtering ARP traffic
153       in the <code>arp</code> chain.
154     </p>
155 <pre>
156 &lt;filter name='no-arp-spoofing' chain='arp' priority='-500'&gt;
157   &lt;uuid&gt;f88f1932-debf-4aa1-9fbe-f10d3aa4bc95&lt;/uuid&gt;
158   &lt;rule action='drop' direction='out' priority='300'&gt;
159     &lt;mac match='no' srcmacaddr='$MAC'/&gt;
160   &lt;/rule&gt;
161   &lt;rule action='drop' direction='out' priority='350'&gt;
162     &lt;arp match='no' arpsrcmacaddr='$MAC'/&gt;
163   &lt;/rule&gt;
164   &lt;rule action='drop' direction='out' priority='400'&gt;
165     &lt;arp match='no' arpsrcipaddr='$IP'/&gt;
166   &lt;/rule&gt;
167   &lt;rule action='drop' direction='in' priority='450'&gt;
168     &lt;arp opcode='Reply'/&gt;
169     &lt;arp match='no' arpdstmacaddr='$MAC'/&gt;
170   &lt;/rule&gt;
171   &lt;rule action='drop' direction='in' priority='500'&gt;
172     &lt;arp match='no' arpdstipaddr='$IP'/&gt;
173   &lt;/rule&gt;
174   &lt;rule action='accept' direction='inout' priority='600'&gt;
175     &lt;arp opcode='Request'/&gt;
176   &lt;/rule&gt;
177   &lt;rule action='accept' direction='inout' priority='650'&gt;
178     &lt;arp opcode='Reply'/&gt;
179   &lt;/rule&gt;
180   &lt;rule action='drop' direction='inout' priority='1000'/&gt;
181 &lt;/filter&gt;
182 </pre>
183     <p>
184       The consequence of putting ARP-specific rules in the <code>arp</code>
185       chain, rather than for example in the <code>root</code> chain, is that
186       packets for any other protocol than ARP do not need to be evaluated by
187       ARP protocol-specific rules. This improves the efficiency
188       of the traffic filtering. However, one must then pay attention to only
189       put filtering rules for the given protocol into the chain since
190       any other rules will not be evaluated, i.e., an IPv4 rule will not
191       be evaluated in the ARP chain since no IPv4 protocol packets will
192       traverse the ARP chain.
193       <br/><br/>
194     </p>
195     <h3><a name="nwfconceptschainpriorities">Filtering chain priorities</a></h3>
196     <p>
197       All chains are connected to the <code>root</code> chain. The order in
198       which those chains are accessed is influenced by the priority of the
199       chain. The following table shows the chains that can be assigned a
200       priority and their default priorities.
201     </p>
202       <table class="top_table">
203        <tr>
204          <th> Chain (prefix) </th>
205          <th> Default priority </th>
206        </tr>
207        <tr>
208          <td>stp</td><td>-810</td>
209        </tr>
210        <tr>
211          <td>mac</td><td>-800</td>
212        </tr>
213        <tr>
214          <td>vlan</td><td>-750</td>
215        </tr>
216        <tr>
217          <td>ipv4</td><td>-700</td>
218        </tr>
219        <tr>
220          <td>ipv6</td><td>-600</td>
221        </tr>
222        <tr>
223          <td>arp</td><td>-500</td>
224        </tr>
225        <tr>
226          <td>rarp</td><td>-400</td>
227        </tr>
228       </table>
229     <p>
230       A chain with a lower priority value is accessed before one with a
231       higher value.
232       <br/>
233       <span class="since">Since 0.9.8</span> the above listed chains
234       can be assigned custom priorities by writing a value in the
235       range [-1000, 1000] into the priority (XML) attribute in the filter
236       node. The above example filter shows the default priority of -500
237       for <code>arp</code> chains.
238     </p>
239     <h3><a name="nwfconceptsvars">Usage of variables in filters</a></h3>
240     <p>
241
242       Two variables names have so far been reserved for usage by the
243       network traffic filtering subsystem: <code>MAC</code> and
244       <code>IP</code>.
245       <br/><br/>
246       <code>MAC</code> is the MAC address of the
247       network interface. A filtering rule that references this variable
248       will automatically be instantiated with the MAC address of the
249       interface. This works without the user having to explicitly provide
250       the MAC parameter. Even though it is possible to specify the MAC
251       parameter similar to the IP parameter above, it is discouraged
252       since libvirt knows what MAC address an interface will be using.
253       <br/><br/>
254       The parameter <code>IP</code> represents the IP address
255       that the operating system inside the virtual machine is expected
256       to use on the given interface. The <code>IP</code> parameter
257       is special in so far as the libvirt daemon will try to determine
258       the IP address (and thus the IP parameter's value) that is being
259       used on an interface if the parameter
260       is not explicitly provided but referenced.
261       For current limitations on IP address detection, consult the
262       <a href="#nwflimits">section on limitations</a> on how to use this
263       feature and what to expect when using it.
264       <br/><br/>
265       The above-shown network filer <code>no-arp-spoofing</code>
266       is an example of
267       a network filter XML referencing the <code>MAC</code> and
268       <code>IP</code> variables.
269       <br/><br/>
270       Note that referenced variables are always prefixed with the
271       $ (dollar) sign. The format of the value of a variable
272       must be of the type expected by the filter attribute in the
273       XML. In the above example, the <code>IP</code> parameter
274       must hold a dotted IP address in decimal numbers format.
275       Failure to  provide the correct
276       value type will result in the filter not being instantiatable
277       and will prevent a virtual machine from starting or the
278       interface from attaching when hotplugging is used. The types
279       that are expected for each XML attribute are shown
280       below.
281       <br/><br/>
282       <span class="since">Since 0.9.8</span> variables can contain lists of
283       elements, e.g., the variable <code>IP</code> can contain multiple IP
284       addresses that are valid on a particular interface. The notation for
285       providing multiple elements for the IP variable is:
286     </p>
287 <pre>
288   ...
289   &lt;devices&gt;
290     &lt;interface type='bridge'&gt;
291       &lt;mac address='00:16:3e:5d:c7:9e'/&gt;
292       &lt;filterref filter='clean-traffic'&gt;
293         &lt;parameter name='IP' value='10.0.0.1'/&gt;
294         &lt;parameter name='IP' value='10.0.0.2'/&gt;
295         &lt;parameter name='IP' value='10.0.0.3'/&gt;
296       &lt;/filterref&gt;
297     &lt;/interface&gt;
298   &lt;/devices&gt;
299   ...</pre>
300     <p>
301       This then allows filters to enable multiple IP addresses
302       per interface. Therefore, with the list
303       of IP address shown above, the following rule will create 3
304       individual filtering rules, one for each IP address.
305     </p>
306 <pre>
307   ...
308   &lt;rule action='accept' direction='in' priority='500'&gt;
309     &lt;tcp srpipaddr='$IP'/&gt;
310   &lt;/rule&gt;
311   ...
312 </pre>
313     <p>
314       <span class="since">Since 0.9.10</span> it is possible to access
315       individual elements of a variable holding a list of elements.
316       A filtering rule like the following accesses the 2nd element
317       of the variable DSTPORTS.
318     </p>
319 <pre>
320   ...
321   &lt;rule action='accept' direction='in' priority='500'&gt;
322     &lt;udp dstportstart='$DSTPORTS[1]'/&gt;
323   &lt;/rule&gt;
324   ...
325 </pre>
326     <p>
327       <span class="since">Since 0.9.10</span> it is possible to create
328       filtering rules that instantiate all combinations of rules from
329       different lists using the notation of
330       <code>$VARIABLE[@&lt;iterator ID&gt;]</code>.
331       The following rule allows a virtual machine to
332       receive traffic on a set of ports, which are specified in DSTPORTS,
333       from the set of source IP address specified in SRCIPADDRESSES.
334       The rule generates all combinations of elements of the variable
335       DSTPORT with those of SRCIPADDRESSES by using two independent
336       iterators to access their elements.
337     </p>
338 <pre>
339   ...
340   &lt;rule action='accept' direction='in' priority='500'&gt;
341     &lt;ip srcipaddr='$SRCIPADDRESSES[@1]' dstportstart='$DSTPORTS[@2]'/&gt;
342   &lt;/rule&gt;
343   ...
344 </pre>
345
346     <p>
347       In an example we assign concrete values to SRCIPADDRESSES and DSTPORTS
348     </p>
349 <pre>
350   SRCIPADDRESSES = [ 10.0.0.1, 11.1.2.3 ]
351   DSTPORTS = [ 80, 8080 ]
352 </pre>
353     <p>
354       Accessing the variables using $SRCIPADDRESSES[@1] and $DSTPORTS[@2] would
355       then result in all combinations of addresses and ports being created:
356     </p>
357 <pre>
358   10.0.0.1, 80
359   10.0.0.1, 8080
360   11.1.2.3, 80
361   11.1.2.3, 8080
362 </pre>
363     <p>
364       Accessing the same variables using a single iterator, for example by using
365       the notation $SRCIPADDRESSES[@1] and $DSTPORTS[@1], would result in
366       parallel access to both lists and result in the following combinations:
367     </p>
368 <pre>
369   10.0.0.1, 80
370   11.1.2.3, 8080
371 </pre>
372     <p>
373       Further, the notation of $VARIABLE is short-hand for $VARIABLE[@0]. The
374       former notation always assumes the iterator with Id '0'.
375     </p>
376
377     <h3><a name="nwfelemsRulesAdvIPAddrDetection">Automatic IP address detection</a></h3>
378     <p>
379        The detection of IP addresses used on a virtual machine's interface
380        is automatically activated if the variable <code>IP</code> is referenced
381        but no value has been assigned to it.
382        <span class="since">Since 0.9.13</span>
383        the variable <code>CTRL_IP_LEARNING</code> can be used to specify
384        the IP address learning method to use. Valid values are <code>any</code>,
385        <code>dhcp</code>, or <code>none</code>.
386        <br/><br/>
387        The value <code>any</code> means that libvirt may use any packet to
388        determine the address in use by a virtual machine, which is the default
389        behavior if the variable <code>CTRL_IP_LEARNING</code> is not set. This method
390        will only detect a single IP address on an interface.
391        Once a VM's IP address has been detected, its IP network traffic
392        will be locked to that address, if for example IP address spoofing
393        is prevented by one of its filters. In that case the user of the VM
394        will not be able to change the IP address on the interface inside
395        the VM, which would be considered IP address spoofing.
396        When a VM is migrated to another host or resumed after a suspend operation,
397        the first packet sent by the VM will again determine the IP address it can
398        use on a particular interface.
399        <br/>
400        A value of <code>dhcp</code> specifies that libvirt should only honor DHCP
401        server-assigned addresses with valid leases. This method supports the detection
402        and usage of multiple IP address per interface.
403        When a VM is resumed after a suspend operation, still valid IP address leases
404        are applied to its filters. Otherwise the VM is expected to again use DHCP to obtain new
405        IP addresses. The migration of a VM to another physical host requires that
406        the VM again runs the DHCP protocol.
407        <br/><br/>
408        Use of <code>CTRL_IP_LEARNING=dhcp</code> (DHCP snooping) provides additional
409        anti-spoofing security, especially when combined with a filter allowing
410        only trusted DHCP servers to assign addresses. To enable this, set the
411        variable <code>DHCPSERVER</code> to the IP address of a valid DHCP server
412        and provide filters that use this variable to filter incoming DHCP responses.
413        <br/><br/>
414        When DHCP snooping is enabled and the DHCP lease expires,
415        the VM will no longer be able to use the IP address until it acquires a
416        new, valid lease from a DHCP server. If the VM is migrated, it must get
417        a new valid DHCP lease to use an IP address (e.g., by
418        bringing the VM interface down and up again).
419        <br/><br/>
420        Note that automatic DHCP detection listens to the DHCP traffic
421        the VM exchanges with the DHCP server of the infrastructure. To avoid
422        denial-of-service attacks on libvirt, the evaluation of those packets
423        is rate-limited, meaning that a VM sending an excessive number of DHCP
424        packets per second on an interface will not have all of those packets
425        evaluated and thus filters may not get adapted. Normal DHCP client
426        behavior is assumed to send a low number of DHCP packets per second.
427        Further, it is important to setup appropriate filters on all VMs in
428        the infrastructure to avoid them  being able to send DHCP
429        packets. Therefore VMs must either be prevented from sending UDP and TCP
430        traffic from port 67 to port 68 or the <code>DHCPSERVER</code>
431        variable should be used on all VMs to restrict DHCP server messages to
432        only be allowed to originate from trusted DHCP servers. At the same
433        time anti-spoofing prevention must be enabled on all VMs in the subnet.
434        <br/><br/>
435        If <code>CTRL_IP_LEARNING</code> is set to <code>none</code>, libvirt does not do
436        IP address learning and referencing <code>IP</code> without assigning it an
437        explicit value is an error.
438        <br/><br/>
439        The following XML provides an example for the activation of IP address learning
440        using the DHCP snooping method:
441     </p>
442 <pre>
443     &lt;interface type='bridge'&gt;
444       &lt;source bridge='virbr0'/&gt;
445       &lt;filterref filter='clean-traffic'&gt;
446         &lt;parameter name='CTRL_IP_LEARNING' value='dhcp'/&gt;
447       &lt;/filterref&gt;
448     &lt;/interface&gt;
449 </pre>
450
451     <h3><a name="nwfelemsReservedVars">Reserved Variables</a></h3>
452     <p>
453       The following table lists reserved variables in use by libvirt.
454     </p>
455       <table class="top_table">
456        <tr>
457          <th> Variable Name </th>
458          <th> Semantics </th>
459        </tr>
460        <tr>
461          <td> MAC </td>
462          <td> The MAC address of the interface </td>
463        </tr>
464        <tr>
465          <td> IP </td>
466          <td> The list of IP addresses in use by an interface </td>
467        </tr>
468        <tr>
469          <td> IPV6 </td>
470          <td> Not currently implemented:
471               the list of IPV6 addresses in use by an interface </td>
472        </tr>
473        <tr>
474          <td> DHCPSERVER </td>
475          <td> The list of IP addresses of trusted DHCP servers</td>
476        </tr>
477        <tr>
478          <td> DHCPSERVERV6 </td>
479          <td> Not currently implemented:
480               The list of IPv6 addresses of trusted DHCP servers</td>
481        </tr>
482        <tr>
483          <td> CTRL_IP_LEARNING </td>
484          <td> The choice of the IP address detection mode </td>
485        </tr>
486       </table>
487
488     <h2><a name="nwfelems">Element and attribute overview</a></h2>
489
490     <p>
491       The root element required for all network filters is
492       named <code>filter</code> with two possible attributes. The
493       <code>name</code> attribute provides a unique name of the
494       given filter. The <code>chain</code> attribute is optional but
495       allows certain filters to be better organized for more efficient
496       processing by the firewall subsystem of the underlying host.
497       Currently the system only supports the chains <code>root,
498       ipv4, ipv6, arp and rarp</code>.
499     </p>
500
501     <h3><a name="nwfelemsRefs">References to other filters</a></h3>
502     <p>
503      Any filter may hold references to other filters. Individual
504      filters may be referenced multiple times in a filter tree but
505      references between filters must not introduce loops (directed
506      acyclic graph).
507      <br/><br/>
508      The following shows the XML of the <code>clean-traffic</code>
509      network filter referencing several other filters.
510     </p>
511 <pre>
512 &lt;filter name='clean-traffic'&gt;
513   &lt;uuid&gt;6ef53069-ba34-94a0-d33d-17751b9b8cb1&lt;/uuid&gt;
514   &lt;filterref filter='no-mac-spoofing'/&gt;
515   &lt;filterref filter='no-ip-spoofing'/&gt;
516   &lt;filterref filter='allow-incoming-ipv4'/&gt;
517   &lt;filterref filter='no-arp-spoofing'/&gt;
518   &lt;filterref filter='no-other-l2-traffic'/&gt;
519   &lt;filterref filter='qemu-announce-self'/&gt;
520 &lt;/filter&gt;
521 </pre>
522
523     <p>
524     To reference another filter, the XML node <code>filterref</code>
525     needs to be provided inside a <code>filter</code> node. This
526     node must have the attribute <code>filter</code> whose value contains
527     the name of the filter to be referenced.
528     <br/><br/>
529     New network filters can be defined at any time and
530     may contain references to network filters that are
531     not known to libvirt, yet. However, once a virtual machine
532     is started or a network interface
533     referencing a filter is to be hotplugged, all network filters
534     in the filter tree must be available. Otherwise the virtual
535     machine will not start or the network interface cannot be
536     attached.
537     </p>
538
539     <h3><a name="nwfelemsRules">Filter rules</a></h3>
540     <p>
541     The following XML shows a simple example of a network
542     traffic filter implementing a rule to drop traffic if
543     the IP address (provided through the value of the
544     variable IP) in an outgoing IP packet is not the expected
545     one, thus preventing IP address spoofing by the VM.
546     </p>
547 <pre>
548 &lt;filter name='no-ip-spoofing' chain='ipv4'&gt;
549   &lt;uuid&gt;fce8ae33-e69e-83bf-262e-30786c1f8072&lt;/uuid&gt;
550   &lt;rule action='drop' direction='out' priority='500'&gt;
551     &lt;ip match='no' srcipaddr='$IP'/&gt;
552   &lt;/rule&gt;
553 &lt;/filter&gt;
554 </pre>
555
556     <p>
557      A traffic filtering rule starts with the <code>rule</code>
558      node. This node may contain up to three attributes
559     </p>
560     <ul>
561      <li>
562         action -- mandatory; must either be <code>drop</code>
563         (matching the rule silently discards the packet with no
564         further analysis),
565         <code>reject</code> (matching the rule generates an ICMP
566         reject message with no further analysis) <span class="since">(since
567         0.9.0)</span>, <code>accept</code> (matching the rule accepts
568         the packet with no further analysis), <code>return</code>
569         (matching the rule passes this filter, but returns control to
570         the calling filter for further
571         analysis) <span class="since">(since 0.9.7)</span>,
572         or <code>continue</code> (matching the rule goes on to the next
573         rule for further analysis) <span class="since">(since
574         0.9.7)</span>.
575      </li>
576      <li>
577         direction -- mandatory; must either be <code>in</code>, <code>out</code> or
578          <code>inout</code> if the rule is for incoming,
579          outgoing or incoming-and-outgoing traffic
580      </li>
581      <li>
582         priority -- optional; the priority of the rule controls the order in
583         which the rule will be instantiated relative to other rules.
584         Rules with lower value will be instantiated before rules with higher
585         values.
586         Valid values are in the range of 0 to 1000.
587         <span class="since">Since 0.9.8</span> this has been extended to cover
588         the range of -1000 to 1000. If this attribute is not
589         provided, priority 500 will automatically be assigned.
590         <br/>
591         Note that filtering rules in the <code>root</code> chain are sorted
592         with filters connected to the <code>root</code> chain following
593         their priorities. This allows to interleave filtering rules with
594         access to filter chains.
595         (See also section on
596          <a href="#nwfconceptschainpriorities">
597            filtering chain priorities
598          </a>.)
599      </li>
600      <li>
601         statematch -- optional; possible values are '0' or 'false' to
602         turn the underlying connection state matching off; default is 'true'
603         <br/>
604         Also read the section on <a href="#nwfelemsRulesAdv">advanced configuration</a>
605         topics.
606      </li>
607     </ul>
608     <p>
609      The above example indicates that the traffic of type <code>ip</code>
610      will be associated with the chain 'ipv4' and the rule will have
611      priority 500. If for example another filter is referenced whose
612      traffic of type <code>ip</code> is also associated with the chain
613      'ipv4' then that filter's rules will be ordered relative to the priority
614      500 of the shown rule.
615      <br/><br/>
616      A rule may contain a single rule for filtering of traffic. The
617      above example shows that traffic of type <code>ip</code> is to be
618      filtered.
619     </p>
620
621     <h4><a name="nwfelemsRulesProto">Supported protocols</a></h4>
622     <p>
623      The following sections enumerate the list of protocols that
624      are supported by the network filtering subsystem. The
625      type of traffic a rule is supposed to filter on is provided
626      in the <code>rule</code> node as a nested node. Depending
627      on the traffic type a rule is filtering, the attributes are
628      different. The above example showed the single
629      attribute <code>srcipaddr</code> that is valid inside the
630      <code>ip</code> traffic filtering node. The following sections
631      show what attributes are valid and what type of data they are
632      expecting. The following datatypes are available:
633     </p>
634     <ul>
635      <li>UINT8 : 8 bit integer; range 0-255</li>
636      <li>UINT16: 16 bit integer; range 0-65535</li>
637      <li>MAC_ADDR: MAC address in dotted decimal format, i.e., 00:11:22:33:44:55</li>
638      <li>MAC_MASK: MAC address mask in MAC address format, i.e., FF:FF:FF:FC:00:00</li>
639      <li>IP_ADDR: IP address in dotted decimal format, i.e., 10.1.2.3</li>
640      <li>IP_MASK: IP address mask in either dotted decimal format (255.255.248.0) or CIDR mask (0-32)</li>
641      <li>IPV6_ADDR: IPv6 address in numbers format, i.e., FFFF::1</li>
642      <li>IPV6_MASK: IPv6 mask in numbers format (FFFF:FFFF:FC00::) or CIDR mask (0-128)</li>
643      <li>STRING: A string</li>
644      <li>BOOLEAN: 'true', 'yes', '1' or 'false', 'no', '0'</li>
645      <li>IPSETFLAGS: The source and destination flags of the ipset described
646          by up to 6 'src' or 'dst' elements selecting features from either
647          the source or destination part of the packet header; example:
648          src,src,dst. The number of 'selectors' to provide here depends
649          on the type of ipset that is referenced.</li>
650     </ul>
651     <p>
652      <br/><br/>
653      Every attribute except for those of type IP_MASK or IPV6_MASK can
654      be negated using the <code>match</code>
655      attribute with value <code>no</code>. Multiple negated attributes
656      may be grouped together. The following
657      XML fragment shows such an example using abstract attributes.
658     </p>
659 <pre>
660 [...]
661   &lt;rule action='drop' direction='in'&gt;
662     &lt;protocol match='no' attribute1='value1' attribute2='value2'/&gt;
663     &lt;protocol attribute3='value3'/&gt;
664   &lt;/rule&gt;
665 [...]
666 </pre>
667     <p>
668      Rules perform a logical AND evaluation on all values of the given
669      protocol attributes. Thus, if a single attribute's value does not match
670      the one given in the rule, the whole rule will be skipped during
671      evaluation. Therefore, in the above example incoming traffic
672      will only be dropped if
673      the protocol property attribute1 does not match value1 AND
674      the protocol property attribute2 does not match value2 AND
675      the protocol property attribute3 matches value3.
676      <br/><br/>
677     </p>
678
679
680     <h5><a name="nwfelemsRulesProtoMAC">MAC (Ethernet)</a></h5>
681     <p>
682       Protocol ID: <code>mac</code>
683       <br/>
684       Note: Rules of this type should go into the <code>root</code> chain.
685     </p>
686       <table class="top_table">
687        <tr>
688          <th> Attribute </th>
689          <th> Datatype </th>
690          <th> Semantics </th>
691        </tr>
692        <tr>
693          <td>srcmacaddr</td>
694          <td>MAC_ADDR</td>
695          <td>MAC address of sender</td>
696        </tr>
697        <tr>
698          <td>srcmacmask</td>
699          <td>MAC_MASK</td>
700          <td>Mask applied to MAC address of sender</td>
701        </tr>
702        <tr>
703          <td>dstmacaddr</td>
704          <td>MAC_ADDR</td>
705          <td>MAC address of destination</td>
706        </tr>
707        <tr>
708          <td>dstmacmask</td>
709          <td>MAC_MASK</td>
710          <td>Mask applied to MAC address of destination</td>
711        </tr>
712        <tr>
713          <td>protocolid</td>
714          <td>UINT16 (0x600-0xffff), STRING</td>
715          <td>Layer 3 protocol ID</td>
716        </tr>
717        <tr>
718          <td>comment <span class="since">(Since 0.8.5)</span></td>
719          <td>STRING</td>
720          <td>text with max. 256 characters</td>
721        </tr>
722       </table>
723     <p>
724       Valid Strings for <code>protocolid</code> are: arp, rarp, ipv4, ipv6
725     </p>
726 <pre>
727 [...]
728 &lt;mac match='no' srcmacaddr='$MAC'/&gt;
729 [...]
730 </pre>
731
732     <h5><a name="nwfelemsRulesProtoVLAN">VLAN (802.1Q)</a>
733       <span class="since">(Since 0.9.8)</span>
734     </h5>
735     <p>
736       Protocol ID: <code>vlan</code>
737       <br/>
738       Note: Rules of this type should go either into the <code>root</code> or
739       <code>vlan</code> chain.
740     </p>
741       <table class="top_table">
742        <tr>
743          <th> Attribute </th>
744          <th> Datatype </th>
745          <th> Semantics </th>
746        </tr>
747        <tr>
748          <td>srcmacaddr</td>
749          <td>MAC_ADDR</td>
750          <td>MAC address of sender</td>
751        </tr>
752        <tr>
753          <td>srcmacmask</td>
754          <td>MAC_MASK</td>
755          <td>Mask applied to MAC address of sender</td>
756        </tr>
757        <tr>
758          <td>dstmacaddr</td>
759          <td>MAC_ADDR</td>
760          <td>MAC address of destination</td>
761        </tr>
762        <tr>
763          <td>dstmacmask</td>
764          <td>MAC_MASK</td>
765          <td>Mask applied to MAC address of destination</td>
766        </tr>
767        <tr>
768          <td>vlan-id</td>
769          <td>UINT16 (0x0-0xfff, 0 - 4095)</td>
770          <td>VLAN ID</td>
771        </tr>
772        <tr>
773          <td>encap-protocol</td>
774          <td>UINT16 (0x03c-0xfff), String</td>
775          <td>Encapsulated layer 3 protocol ID</td>
776        </tr>
777        <tr>
778          <td>comment </td>
779          <td>STRING</td>
780          <td>text with max. 256 characters</td>
781        </tr>
782       </table>
783     <p>
784       Valid Strings for <code>encap-protocol</code> are: arp, ipv4, ipv6
785     </p>
786
787     <h5><a name="nwfelemsRulesProtoSTP">STP (Spanning Tree Protocol)</a>
788       <span class="since">(Since 0.9.8)</span>
789     </h5>
790     <p>
791       Protocol ID: <code>stp</code>
792       <br/>
793       Note: Rules of this type should go either into the <code>root</code> or
794       <code>stp</code> chain.
795     </p>
796       <table class="top_table">
797        <tr>
798          <th> Attribute </th>
799          <th> Datatype </th>
800          <th> Semantics </th>
801        </tr>
802        <tr>
803          <td>srcmacaddr</td>
804          <td>MAC_ADDR</td>
805          <td>MAC address of sender</td>
806        </tr>
807        <tr>
808          <td>srcmacmask</td>
809          <td>MAC_MASK</td>
810          <td>Mask applied to MAC address of sender</td>
811        </tr>
812        <tr>
813          <td>type</td>
814          <td>UINT8</td>
815          <td>Bridge Protocol Data Unit (BPDU) type</td>
816        </tr>
817        <tr>
818          <td>flags</td>
819          <td>UINT8</td>
820          <td>BPDU flag</td>
821        </tr>
822        <tr>
823          <td>root-priority</td>
824          <td>UINT16</td>
825          <td>Root priority (range start)</td>
826        </tr>
827        <tr>
828          <td>root-priority-hi</td>
829          <td>UINT16</td>
830          <td>Root priority range end</td>
831        </tr>
832        <tr>
833          <td>root-address</td>
834          <td>MAC_ADDRESS</td>
835          <td>Root MAC address</td>
836        </tr>
837        <tr>
838          <td>root-address-mask</td>
839          <td>MAC_MASK</td>
840          <td>Root MAC address mask</td>
841        </tr>
842        <tr>
843          <td>root-cost</td>
844          <td>UINT32</td>
845          <td>Root path cost (range start)</td>
846        </tr>
847        <tr>
848          <td>root-cost-hi</td>
849          <td>UINT32</td>
850          <td>Root path cost range end</td>
851        </tr>
852        <tr>
853          <td>sender-priority</td>
854          <td>UINT16</td>
855          <td>Sender priority (range start)</td>
856        </tr>
857        <tr>
858          <td>sender-priority-hi</td>
859          <td>UINT16</td>
860          <td>Sender priority range end</td>
861        </tr>
862        <tr>
863          <td>sender-address</td>
864          <td>MAC_ADDRESS</td>
865          <td>BPDU sender MAC address</td>
866        </tr>
867        <tr>
868          <td>sender-address-mask</td>
869          <td>MAC_MASK</td>
870          <td>BPDU sender MAC address mask</td>
871        </tr>
872        <tr>
873          <td>port</td>
874          <td>UINT16</td>
875          <td>Port identifier (range start)</td>
876        </tr>
877        <tr>
878          <td>port_hi</td>
879          <td>UINT16</td>
880          <td>Port identifier range end</td>
881        </tr>
882        <tr>
883          <td>msg-age</td>
884          <td>UINT16</td>
885          <td>Message age timer (range start)</td>
886        </tr>
887        <tr>
888          <td>msg-age-hi</td>
889          <td>UINT16</td>
890          <td>Message age timer range end</td>
891        </tr>
892        <tr>
893          <td>max-age</td>
894          <td>UINT16</td>
895          <td>Maximum age timer (range start)</td>
896        </tr>
897        <tr>
898          <td>max-age-hi</td>
899          <td>UINT16</td>
900          <td>Maximum age timer range end</td>
901        </tr>
902        <tr>
903          <td>hello-time</td>
904          <td>UINT16</td>
905          <td>Hello time timer (range start)</td>
906        </tr>
907        <tr>
908          <td>hello-time-hi</td>
909          <td>UINT16</td>
910          <td>Hello time timer range end</td>
911        </tr>
912        <tr>
913          <td>forward-delay</td>
914          <td>UINT16</td>
915          <td>Forward delay (range start)</td>
916        </tr>
917        <tr>
918          <td>forward-delay-hi</td>
919          <td>UINT16</td>
920          <td>Forward delay range end</td>
921        </tr>
922        <tr>
923          <td>comment</td>
924          <td>STRING</td>
925          <td>text with max. 256 characters</td>
926        </tr>
927       </table>
928
929     <h5><a name="nwfelemsRulesProtoARP">ARP/RARP</a></h5>
930     <p>
931       Protocol ID: <code>arp</code> or <code>rarp</code>
932       <br/>
933       Note: Rules of this type should either go into the
934       <code>root</code> or <code>arp/rarp</code> chain.
935     </p>
936       <table class="top_table">
937        <tr>
938          <th> Attribute </th>
939          <th> Datatype </th>
940          <th> Semantics </th>
941        </tr>
942        <tr>
943          <td>srcmacaddr</td>
944          <td>MAC_ADDR</td>
945          <td>MAC address of sender</td>
946        </tr>
947        <tr>
948          <td>srcmacmask</td>
949          <td>MAC_MASK</td>
950          <td>Mask applied to MAC address of sender</td>
951        </tr>
952        <tr>
953          <td>dstmacaddr</td>
954          <td>MAC_ADDR</td>
955          <td>MAC address of destination</td>
956        </tr>
957        <tr>
958          <td>dstmacmask</td>
959          <td>MAC_MASK</td>
960          <td>Mask applied to MAC address of destination</td>
961        </tr>
962        <tr>
963          <td>hwtype</td>
964          <td>UINT16</td>
965          <td>Hardware type</td>
966        </tr>
967        <tr>
968          <td>protocoltype</td>
969          <td>UINT16</td>
970          <td>Protocol type</td>
971        </tr>
972        <tr>
973          <td>opcode</td>
974          <td>UINT16, STRING</td>
975          <td>Opcode</td>
976        </tr>
977        <tr>
978          <td>arpsrcmacaddr</td>
979          <td>MAC_ADDR</td>
980          <td>Source MAC address in ARP/RARP packet</td>
981        </tr>
982        <tr>
983          <td>arpdstmacaddr</td>
984          <td>MAC_ADDR</td>
985          <td>Destination MAC address in ARP/RARP packet</td>
986        </tr>
987        <tr>
988          <td>arpsrcipaddr</td>
989          <td>IP_ADDR</td>
990          <td>Source IP address in ARP/RARP packet</td>
991        </tr>
992        <tr>
993          <td>arpsrcipmask <span class="since">(Since 1.2.3)</span></td>
994          <td>IP_MASK</td>
995          <td>Source IP mask</td>
996        </tr>
997        <tr>
998          <td>arpdstipaddr</td>
999          <td>IP_ADDR</td>
1000          <td>Destination IP address in ARP/RARP packet</td>
1001        </tr>
1002        <tr>
1003          <td>arpdstipmask <span class="since">(Since 1.2.3)</span></td>
1004          <td>IP_MASK</td>
1005          <td>Destination IP mask</td>
1006        </tr>
1007        <tr>
1008          <td>comment <span class="since">(Since 0.8.5)</span></td>
1009          <td>STRING</td>
1010          <td>text with max. 256 characters</td>
1011        </tr>
1012        <tr>
1013          <td>gratuitous <span class="since">(Since 0.9.2)</span></td>
1014          <td>BOOLEAN</td>
1015          <td>boolean indicating whether to check for gratuitous ARP packet</td>
1016        </tr>
1017       </table>
1018     <p>
1019       Valid strings for the <code>Opcode</code> field are:
1020        Request, Reply, Request_Reverse, Reply_Reverse, DRARP_Request,
1021        DRARP_Reply, DRARP_Error, InARP_Request, ARP_NAK
1022       <br/><br/>
1023     </p>
1024
1025     <h5><a name="nwfelemsRulesProtoIP">IPv4</a></h5>
1026     <p>
1027       Protocol ID: <code>ip</code>
1028       <br/>
1029       Note: Rules of this type should either go into the
1030       <code>root</code> or <code>ipv4</code> chain.
1031     </p>
1032       <table class="top_table">
1033        <tr>
1034          <th> Attribute </th>
1035          <th> Datatype </th>
1036          <th> Semantics </th>
1037        </tr>
1038        <tr>
1039          <td>srcmacaddr</td>
1040          <td>MAC_ADDR</td>
1041          <td>MAC address of sender</td>
1042        </tr>
1043        <tr>
1044          <td>srcmacmask</td>
1045          <td>MAC_MASK</td>
1046          <td>Mask applied to MAC address of sender</td>
1047        </tr>
1048        <tr>
1049          <td>dstmacaddr</td>
1050          <td>MAC_ADDR</td>
1051          <td>MAC address of destination</td>
1052        </tr>
1053        <tr>
1054          <td>dstmacmask</td>
1055          <td>MAC_MASK</td>
1056          <td>Mask applied to MAC address of destination</td>
1057        </tr>
1058        <tr>
1059          <td>srcipaddr</td>
1060          <td>IP_ADDR</td>
1061          <td>Source IP address</td>
1062        </tr>
1063        <tr>
1064          <td>srcipmask</td>
1065          <td>IP_MASK</td>
1066          <td>Mask applied to source IP address</td>
1067        </tr>
1068        <tr>
1069          <td>dstipaddr</td>
1070          <td>IP_ADDR</td>
1071          <td>Destination IP address</td>
1072        </tr>
1073        <tr>
1074          <td>dstipmask</td>
1075          <td>IP_MASK</td>
1076          <td>Mask applied to destination IP address</td>
1077        </tr>
1078        <tr>
1079          <td>protocol</td>
1080          <td>UINT8, STRING</td>
1081          <td>Layer 4 protocol identifier</td>
1082        </tr>
1083        <tr>
1084          <td>srcportstart</td>
1085          <td>UINT16</td>
1086          <td>Start of range of valid source ports; requires <code>protocol</code></td>
1087        </tr>
1088        <tr>
1089          <td>srcportend</td>
1090          <td>UINT16</td>
1091          <td>End of range of valid source ports; requires <code>protocol</code></td>
1092        </tr>
1093        <tr>
1094          <td>dstportstart</td>
1095          <td>UINT16</td>
1096          <td>Start of range of valid destination ports; requires <code>protocol</code></td>
1097        </tr>
1098        <tr>
1099          <td>dstportend</td>
1100          <td>UINT16</td>
1101          <td>End of range of valid destination ports; requires <code>protocol</code></td>
1102        </tr>
1103        <tr>
1104          <td>comment <span class="since">(Since 0.8.5)</span></td>
1105          <td>STRING</td>
1106          <td>text with max. 256 characters</td>
1107        </tr>
1108       </table>
1109     <p>
1110       Valid strings for <code>protocol</code> are:
1111          tcp, udp, udplite, esp, ah, icmp, igmp, sctp
1112       <br/><br/>
1113     </p>
1114
1115
1116     <h5><a name="nwfelemsRulesProtoIPv6">IPv6</a></h5>
1117     <p>
1118       Protocol ID: <code>ipv6</code>
1119       <br/>
1120       Note: Rules of this type should either go into the
1121       <code>root</code> or <code>ipv6</code> chain.
1122     </p>
1123       <table class="top_table">
1124        <tr>
1125          <th> Attribute </th>
1126          <th> Datatype </th>
1127          <th> Semantics </th>
1128        </tr>
1129        <tr>
1130          <td>srcmacaddr</td>
1131          <td>MAC_ADDR</td>
1132          <td>MAC address of sender</td>
1133        </tr>
1134        <tr>
1135          <td>srcmacmask</td>
1136          <td>MAC_MASK</td>
1137          <td>Mask applied to MAC address of sender</td>
1138        </tr>
1139        <tr>
1140          <td>dstmacaddr</td>
1141          <td>MAC_ADDR</td>
1142          <td>MAC address of destination</td>
1143        </tr>
1144        <tr>
1145          <td>dstmacmask</td>
1146          <td>MAC_MASK</td>
1147          <td>Mask applied to MAC address of destination</td>
1148        </tr>
1149        <tr>
1150          <td>srcipaddr</td>
1151          <td>IPV6_ADDR</td>
1152          <td>Source IPv6 address</td>
1153        </tr>
1154        <tr>
1155          <td>srcipmask</td>
1156          <td>IPV6_MASK</td>
1157          <td>Mask applied to source IPv6 address</td>
1158        </tr>
1159        <tr>
1160          <td>dstipaddr</td>
1161          <td>IPV6_ADDR</td>
1162          <td>Destination IPv6 address</td>
1163        </tr>
1164        <tr>
1165          <td>dstipmask</td>
1166          <td>IPV6_MASK</td>
1167          <td>Mask applied to destination IPv6 address</td>
1168        </tr>
1169        <tr>
1170          <td>protocol</td>
1171          <td>UINT8</td>
1172          <td>Layer 4 protocol identifier</td>
1173        </tr>
1174        <tr>
1175          <td>srcportstart</td>
1176          <td>UINT16</td>
1177          <td>Start of range of valid source ports; requires <code>protocol</code></td>
1178        </tr>
1179        <tr>
1180          <td>srcportend</td>
1181          <td>UINT16</td>
1182          <td>End of range of valid source ports; requires <code>protocol</code></td>
1183        </tr>
1184        <tr>
1185          <td>dstportstart</td>
1186          <td>UINT16</td>
1187          <td>Start of range of valid destination ports; requires <code>protocol</code></td>
1188        </tr>
1189        <tr>
1190          <td>dstportend</td>
1191          <td>UINT16</td>
1192          <td>End of range of valid destination ports; requires <code>protocol</code></td>
1193        </tr>
1194        <tr>
1195          <td>comment <span class="since">(Since 0.8.5)</span></td>
1196          <td>STRING</td>
1197          <td>text with max. 256 characters</td>
1198        </tr>
1199       </table>
1200     <p>
1201       Valid strings for <code>protocol</code> are:
1202          tcp, udp, udplite, esp, ah, icmpv6, sctp
1203       <br/><br/>
1204     </p>
1205
1206     <h5><a name="nwfelemsRulesProtoTCP-ipv4">TCP/UDP/SCTP</a></h5>
1207     <p>
1208       Protocol ID: <code>tcp</code>, <code>udp</code>, <code>sctp</code>
1209       <br/>
1210       Note: The chain parameter is ignored for this type of traffic
1211       and should either be omitted or set to <code>root</code>.
1212     </p>
1213       <table class="top_table">
1214        <tr>
1215          <th> Attribute </th>
1216          <th> Datatype </th>
1217          <th> Semantics </th>
1218        </tr>
1219        <tr>
1220          <td>srcmacaddr</td>
1221          <td>MAC_ADDR</td>
1222          <td>MAC address of sender</td>
1223        </tr>
1224        <tr>
1225          <td>srcipaddr</td>
1226          <td>IP_ADDR</td>
1227          <td>Source IP address</td>
1228        </tr>
1229        <tr>
1230          <td>srcipmask</td>
1231          <td>IP_MASK</td>
1232          <td>Mask applied to source IP address</td>
1233        </tr>
1234        <tr>
1235          <td>dstipaddr</td>
1236          <td>IP_ADDR</td>
1237          <td>Destination IP address</td>
1238        </tr>
1239        <tr>
1240          <td>dstipmask</td>
1241          <td>IP_MASK</td>
1242          <td>Mask applied to destination IP address</td>
1243        </tr>
1244
1245        <tr>
1246          <td>srcipfrom</td>
1247          <td>IP_ADDR</td>
1248          <td>Start of range of source IP address</td>
1249        </tr>
1250        <tr>
1251          <td>srcipto</td>
1252          <td>IP_ADDR</td>
1253          <td>End of range of source IP address</td>
1254        </tr>
1255        <tr>
1256          <td>dstipfrom</td>
1257          <td>IP_ADDR</td>
1258          <td>Start of range of destination IP address</td>
1259        </tr>
1260        <tr>
1261          <td>dstipto</td>
1262          <td>IP_ADDR</td>
1263          <td>End of range of destination IP address</td>
1264        </tr>
1265
1266        <tr>
1267          <td>srcportstart</td>
1268          <td>UINT16</td>
1269          <td>Start of range of valid source ports</td>
1270        </tr>
1271        <tr>
1272          <td>srcportend</td>
1273          <td>UINT16</td>
1274          <td>End of range of valid source ports</td>
1275        </tr>
1276        <tr>
1277          <td>dstportstart</td>
1278          <td>UINT16</td>
1279          <td>Start of range of valid destination ports</td>
1280        </tr>
1281        <tr>
1282          <td>dstportend</td>
1283          <td>UINT16</td>
1284          <td>End of range of valid destination ports</td>
1285        </tr>
1286        <tr>
1287          <td>comment <span class="since">(Since 0.8.5)</span></td>
1288          <td>STRING</td>
1289          <td>text with max. 256 characters</td>
1290        </tr>
1291        <tr>
1292          <td>state <span class="since">(Since 0.8.5)</span></td>
1293          <td>STRING</td>
1294          <td>comma separated list of NEW,ESTABLISHED,RELATED,INVALID or NONE</td>
1295        </tr>
1296        <tr>
1297          <td>flags <span class="since">(Since 0.9.1)</span></td>
1298          <td>STRING</td>
1299          <td>TCP-only: format of mask/flags with mask and flags each being a comma separated list of SYN,ACK,URG,PSH,FIN,RST or NONE or ALL</td>
1300        </tr>
1301        <tr>
1302          <td>ipset <span class="since">(Since 0.9.13)</span></td>
1303          <td>STRING</td>
1304          <td>The name of an IPSet managed outside of libvirt</td>
1305        </tr>
1306        <tr>
1307          <td>ipsetflags <span class="since">(Since 0.9.13)</span></td>
1308          <td>IPSETFLAGS</td>
1309          <td>flags for the IPSet; requires ipset attribute</td>
1310        </tr>
1311       </table>
1312     <p>
1313       <br/><br/>
1314     </p>
1315
1316
1317     <h5><a name="nwfelemsRulesProtoICMP">ICMP</a></h5>
1318     <p>
1319       Protocol ID: <code>icmp</code>
1320       <br/>
1321       Note: The chain parameter is ignored for this type of traffic
1322       and should either be omitted or set to <code>root</code>.
1323     </p>
1324       <table class="top_table">
1325        <tr>
1326          <th> Attribute </th>
1327          <th> Datatype </th>
1328          <th> Semantics </th>
1329        </tr>
1330        <tr>
1331          <td>srcmacaddr</td>
1332          <td>MAC_ADDR</td>
1333          <td>MAC address of sender</td>
1334        </tr>
1335        <tr>
1336          <td>srcmacmask</td>
1337          <td>MAC_MASK</td>
1338          <td>Mask applied to MAC address of sender</td>
1339        </tr>
1340        <tr>
1341          <td>dstmacaddr</td>
1342          <td>MAC_ADDR</td>
1343          <td>MAC address of destination</td>
1344        </tr>
1345        <tr>
1346          <td>dstmacmask</td>
1347          <td>MAC_MASK</td>
1348          <td>Mask applied to MAC address of destination</td>
1349        </tr>
1350        <tr>
1351          <td>srcipaddr</td>
1352          <td>IP_ADDR</td>
1353          <td>Source IP address</td>
1354        </tr>
1355        <tr>
1356          <td>srcipmask</td>
1357          <td>IP_MASK</td>
1358          <td>Mask applied to source IP address</td>
1359        </tr>
1360        <tr>
1361          <td>dstipaddr</td>
1362          <td>IP_ADDR</td>
1363          <td>Destination IP address</td>
1364        </tr>
1365        <tr>
1366          <td>dstipmask</td>
1367          <td>IP_MASK</td>
1368          <td>Mask applied to destination IP address</td>
1369        </tr>
1370
1371        <tr>
1372          <td>srcipfrom</td>
1373          <td>IP_ADDR</td>
1374          <td>Start of range of source IP address</td>
1375        </tr>
1376        <tr>
1377          <td>srcipto</td>
1378          <td>IP_ADDR</td>
1379          <td>End of range of source IP address</td>
1380        </tr>
1381        <tr>
1382          <td>dstipfrom</td>
1383          <td>IP_ADDR</td>
1384          <td>Start of range of destination IP address</td>
1385        </tr>
1386        <tr>
1387          <td>dstipto</td>
1388          <td>IP_ADDR</td>
1389          <td>End of range of destination IP address</td>
1390        </tr>
1391        <tr>
1392          <td>type</td>
1393          <td>UINT16</td>
1394          <td>ICMP type</td>
1395        </tr>
1396        <tr>
1397          <td>code</td>
1398          <td>UINT16</td>
1399          <td>ICMP code</td>
1400        </tr>
1401        <tr>
1402          <td>comment <span class="since">(Since 0.8.5)</span></td>
1403          <td>STRING</td>
1404          <td>text with max. 256 characters</td>
1405        </tr>
1406        <tr>
1407          <td>state <span class="since">(Since 0.8.5)</span></td>
1408          <td>STRING</td>
1409          <td>comma separated list of NEW,ESTABLISHED,RELATED,INVALID or NONE</td>
1410        </tr>
1411        <tr>
1412          <td>ipset <span class="since">(Since 0.9.13)</span></td>
1413          <td>STRING</td>
1414          <td>The name of an IPSet managed outside of libvirt</td>
1415        </tr>
1416        <tr>
1417          <td>ipsetflags <span class="since">(Since 0.9.13)</span></td>
1418          <td>IPSETFLAGS</td>
1419          <td>flags for the IPSet; requires ipset attribute</td>
1420        </tr>
1421       </table>
1422     <p>
1423       <br/><br/>
1424     </p>
1425
1426     <h5><a name="nwfelemsRulesProtoMisc">IGMP, ESP, AH, UDPLITE, 'ALL'</a></h5>
1427     <p>
1428       Protocol ID: <code>igmp</code>, <code>esp</code>, <code>ah</code>, <code>udplite</code>, <code>all</code>
1429       <br/>
1430       Note: The chain parameter is ignored for this type of traffic
1431       and should either be omitted or set to <code>root</code>.
1432     </p>
1433       <table class="top_table">
1434        <tr>
1435          <th> Attribute </th>
1436          <th> Datatype </th>
1437          <th> Semantics </th>
1438        </tr>
1439        <tr>
1440          <td>srcmacaddr</td>
1441          <td>MAC_ADDR</td>
1442          <td>MAC address of sender</td>
1443        </tr>
1444        <tr>
1445          <td>srcmacmask</td>
1446          <td>MAC_MASK</td>
1447          <td>Mask applied to MAC address of sender</td>
1448        </tr>
1449        <tr>
1450          <td>dstmacaddr</td>
1451          <td>MAC_ADDR</td>
1452          <td>MAC address of destination</td>
1453        </tr>
1454        <tr>
1455          <td>dstmacmask</td>
1456          <td>MAC_MASK</td>
1457          <td>Mask applied to MAC address of destination</td>
1458        </tr>
1459        <tr>
1460          <td>srcipaddr</td>
1461          <td>IP_ADDR</td>
1462          <td>Source IP address</td>
1463        </tr>
1464        <tr>
1465          <td>srcipmask</td>
1466          <td>IP_MASK</td>
1467          <td>Mask applied to source IP address</td>
1468        </tr>
1469        <tr>
1470          <td>dstipaddr</td>
1471          <td>IP_ADDR</td>
1472          <td>Destination IP address</td>
1473        </tr>
1474        <tr>
1475          <td>dstipmask</td>
1476          <td>IP_MASK</td>
1477          <td>Mask applied to destination IP address</td>
1478        </tr>
1479
1480        <tr>
1481          <td>srcipfrom</td>
1482          <td>IP_ADDR</td>
1483          <td>Start of range of source IP address</td>
1484        </tr>
1485        <tr>
1486          <td>srcipto</td>
1487          <td>IP_ADDR</td>
1488          <td>End of range of source IP address</td>
1489        </tr>
1490        <tr>
1491          <td>dstipfrom</td>
1492          <td>IP_ADDR</td>
1493          <td>Start of range of destination IP address</td>
1494        </tr>
1495        <tr>
1496          <td>dstipto</td>
1497          <td>IP_ADDR</td>
1498          <td>End of range of destination IP address</td>
1499        </tr>
1500        <tr>
1501          <td>comment <span class="since">(Since 0.8.5)</span></td>
1502          <td>STRING</td>
1503          <td>text with max. 256 characters</td>
1504        </tr>
1505        <tr>
1506          <td>state <span class="since">(Since 0.8.5)</span></td>
1507          <td>STRING</td>
1508          <td>comma separated list of NEW,ESTABLISHED,RELATED,INVALID or NONE</td>
1509        </tr>
1510        <tr>
1511          <td>ipset <span class="since">(Since 0.9.13)</span></td>
1512          <td>STRING</td>
1513          <td>The name of an IPSet managed outside of libvirt</td>
1514        </tr>
1515        <tr>
1516          <td>ipsetflags <span class="since">(Since 0.9.13)</span></td>
1517          <td>IPSETFLAGS</td>
1518          <td>flags for the IPSet; requires ipset attribute</td>
1519        </tr>
1520       </table>
1521     <p>
1522       <br/><br/>
1523     </p>
1524
1525
1526     <h5><a name="nwfelemsRulesProtoTCP-ipv6">TCP/UDP/SCTP over IPV6</a></h5>
1527     <p>
1528       Protocol ID: <code>tcp-ipv6</code>, <code>udp-ipv6</code>, <code>sctp-ipv6</code>
1529       <br/>
1530       Note: The chain parameter is ignored for this type of traffic
1531       and should either be omitted or set to <code>root</code>.
1532     </p>
1533       <table class="top_table">
1534        <tr>
1535          <th> Attribute </th>
1536          <th> Datatype </th>
1537          <th> Semantics </th>
1538        </tr>
1539        <tr>
1540          <td>srcmacaddr</td>
1541          <td>MAC_ADDR</td>
1542          <td>MAC address of sender</td>
1543        </tr>
1544        <tr>
1545          <td>srcipaddr</td>
1546          <td>IPV6_ADDR</td>
1547          <td>Source IP address</td>
1548        </tr>
1549        <tr>
1550          <td>srcipmask</td>
1551          <td>IPV6_MASK</td>
1552          <td>Mask applied to source IP address</td>
1553        </tr>
1554        <tr>
1555          <td>dstipaddr</td>
1556          <td>IPV6_ADDR</td>
1557          <td>Destination IP address</td>
1558        </tr>
1559        <tr>
1560          <td>dstipmask</td>
1561          <td>IPV6_MASK</td>
1562          <td>Mask applied to destination IP address</td>
1563        </tr>
1564
1565        <tr>
1566          <td>srcipfrom</td>
1567          <td>IPV6_ADDR</td>
1568          <td>Start of range of source IP address</td>
1569        </tr>
1570        <tr>
1571          <td>srcipto</td>
1572          <td>IPV6_ADDR</td>
1573          <td>End of range of source IP address</td>
1574        </tr>
1575        <tr>
1576          <td>dstipfrom</td>
1577          <td>IPV6_ADDR</td>
1578          <td>Start of range of destination IP address</td>
1579        </tr>
1580        <tr>
1581          <td>dstipto</td>
1582          <td>IPV6_ADDR</td>
1583          <td>End of range of destination IP address</td>
1584        </tr>
1585
1586        <tr>
1587          <td>srcportstart</td>
1588          <td>UINT16</td>
1589          <td>Start of range of valid source ports</td>
1590        </tr>
1591        <tr>
1592          <td>srcportend</td>
1593          <td>UINT16</td>
1594          <td>End of range of valid source ports</td>
1595        </tr>
1596        <tr>
1597          <td>dstportstart</td>
1598          <td>UINT16</td>
1599          <td>Start of range of valid destination ports</td>
1600        </tr>
1601        <tr>
1602          <td>dstportend</td>
1603          <td>UINT16</td>
1604          <td>End of range of valid destination ports</td>
1605        </tr>
1606        <tr>
1607          <td>comment <span class="since">(Since 0.8.5)</span></td>
1608          <td>STRING</td>
1609          <td>text with max. 256 characters</td>
1610        </tr>
1611        <tr>
1612          <td>state <span class="since">(Since 0.8.5)</span></td>
1613          <td>STRING</td>
1614          <td>comma separated list of NEW,ESTABLISHED,RELATED,INVALID or NONE</td>
1615        </tr>
1616        <tr>
1617          <td>flags <span class="since">(Since 0.9.1)</span></td>
1618          <td>STRING</td>
1619          <td>TCP-only: format of mask/flags with mask and flags each being a comma separated list of SYN,ACK,URG,PSH,FIN,RST or NONE or ALL</td>
1620        </tr>
1621        <tr>
1622          <td>ipset <span class="since">(Since 0.9.13)</span></td>
1623          <td>STRING</td>
1624          <td>The name of an IPSet managed outside of libvirt</td>
1625        </tr>
1626        <tr>
1627          <td>ipsetflags <span class="since">(Since 0.9.13)</span></td>
1628          <td>IPSETFLAGS</td>
1629          <td>flags for the IPSet; requires ipset attribute</td>
1630        </tr>
1631       </table>
1632     <p>
1633       <br/><br/>
1634     </p>
1635
1636
1637     <h5><a name="nwfelemsRulesProtoICMPv6">ICMPv6</a></h5>
1638     <p>
1639       Protocol ID: <code>icmpv6</code>
1640       <br/>
1641       Note: The chain parameter is ignored for this type of traffic
1642       and should either be omitted or set to <code>root</code>.
1643     </p>
1644       <table class="top_table">
1645        <tr>
1646          <th> Attribute </th>
1647          <th> Datatype </th>
1648          <th> Semantics </th>
1649        </tr>
1650        <tr>
1651          <td>srcmacaddr</td>
1652          <td>MAC_ADDR</td>
1653          <td>MAC address of sender</td>
1654        </tr>
1655        <tr>
1656          <td>srcipaddr</td>
1657          <td>IPV6_ADDR</td>
1658          <td>Source IPv6 address</td>
1659        </tr>
1660        <tr>
1661          <td>srcipmask</td>
1662          <td>IPV6_MASK</td>
1663          <td>Mask applied to source IPv6 address</td>
1664        </tr>
1665        <tr>
1666          <td>dstipaddr</td>
1667          <td>IPV6_ADDR</td>
1668          <td>Destination IPv6 address</td>
1669        </tr>
1670        <tr>
1671          <td>dstipmask</td>
1672          <td>IPV6_MASK</td>
1673          <td>Mask applied to destination IPv6 address</td>
1674        </tr>
1675
1676        <tr>
1677          <td>srcipfrom</td>
1678          <td>IPV6_ADDR</td>
1679          <td>Start of range of source IP address</td>
1680        </tr>
1681        <tr>
1682          <td>srcipto</td>
1683          <td>IPV6_ADDR</td>
1684          <td>End of range of source IP address</td>
1685        </tr>
1686        <tr>
1687          <td>dstipfrom</td>
1688          <td>IPV6_ADDR</td>
1689          <td>Start of range of destination IP address</td>
1690        </tr>
1691        <tr>
1692          <td>dstipto</td>
1693          <td>IPV6_ADDR</td>
1694          <td>End of range of destination IP address</td>
1695        </tr>
1696
1697        <tr>
1698          <td>type</td>
1699          <td>UINT16</td>
1700          <td>ICMPv6 type</td>
1701        </tr>
1702        <tr>
1703          <td>code</td>
1704          <td>UINT16</td>
1705          <td>ICMPv6 code</td>
1706        </tr>
1707        <tr>
1708          <td>comment <span class="since">(Since 0.8.5)</span></td>
1709          <td>STRING</td>
1710          <td>text with max. 256 characters</td>
1711        </tr>
1712        <tr>
1713          <td>state <span class="since">(Since 0.8.5)</span></td>
1714          <td>STRING</td>
1715          <td>comma separated list of NEW,ESTABLISHED,RELATED,INVALID or NONE</td>
1716        </tr>
1717        <tr>
1718          <td>ipset <span class="since">(Since 0.9.13)</span></td>
1719          <td>STRING</td>
1720          <td>The name of an IPSet managed outside of libvirt</td>
1721        </tr>
1722        <tr>
1723          <td>ipsetflags <span class="since">(Since 0.9.13)</span></td>
1724          <td>IPSETFLAGS</td>
1725          <td>flags for the IPSet; requires ipset attribute</td>
1726        </tr>
1727       </table>
1728     <p>
1729       <br/><br/>
1730     </p>
1731
1732     <h5><a name="nwfelemsRulesProtoMiscv6">IGMP, ESP, AH, UDPLITE, 'ALL' over IPv6</a></h5>
1733     <p>
1734       Protocol ID: <code>igmp-ipv6</code>, <code>esp-ipv6</code>, <code>ah-ipv6</code>, <code>udplite-ipv6</code>, <code>all-ipv6</code>
1735       <br/>
1736       Note: The chain parameter is ignored for this type of traffic
1737       and should either be omitted or set to <code>root</code>.
1738     </p>
1739       <table class="top_table">
1740        <tr>
1741          <th> Attribute </th>
1742          <th> Datatype </th>
1743          <th> Semantics </th>
1744        </tr>
1745        <tr>
1746          <td>srcmacaddr</td>
1747          <td>MAC_ADDR</td>
1748          <td>MAC address of sender</td>
1749        </tr>
1750        <tr>
1751          <td>srcipaddr</td>
1752          <td>IPV6_ADDR</td>
1753          <td>Source IPv6 address</td>
1754        </tr>
1755        <tr>
1756          <td>srcipmask</td>
1757          <td>IPV6_MASK</td>
1758          <td>Mask applied to source IPv6 address</td>
1759        </tr>
1760        <tr>
1761          <td>dstipaddr</td>
1762          <td>IPV6_ADDR</td>
1763          <td>Destination IPv6 address</td>
1764        </tr>
1765        <tr>
1766          <td>dstipmask</td>
1767          <td>IPV6_MASK</td>
1768          <td>Mask applied to destination IPv6 address</td>
1769        </tr>
1770
1771        <tr>
1772          <td>srcipfrom</td>
1773          <td>IPV6_ADDR</td>
1774          <td>Start of range of source IP address</td>
1775        </tr>
1776        <tr>
1777          <td>srcipto</td>
1778          <td>IPV6_ADDR</td>
1779          <td>End of range of source IP address</td>
1780        </tr>
1781        <tr>
1782          <td>dstipfrom</td>
1783          <td>IPV6_ADDR</td>
1784          <td>Start of range of destination IP address</td>
1785        </tr>
1786        <tr>
1787          <td>dstipto</td>
1788          <td>IPV6_ADDR</td>
1789          <td>End of range of destination IP address</td>
1790        </tr>
1791        <tr>
1792          <td>comment <span class="since">(Since 0.8.5)</span></td>
1793          <td>STRING</td>
1794          <td>text with max. 256 characters</td>
1795        </tr>
1796        <tr>
1797          <td>state <span class="since">(Since 0.8.5)</span></td>
1798          <td>STRING</td>
1799          <td>comma separated list of NEW,ESTABLISHED,RELATED,INVALID or NONE</td>
1800        </tr>
1801        <tr>
1802          <td>ipset <span class="since">(Since 0.9.13)</span></td>
1803          <td>STRING</td>
1804          <td>The name of an IPSet managed outside of libvirt</td>
1805        </tr>
1806        <tr>
1807          <td>ipsetflags <span class="since">(Since 0.9.13)</span></td>
1808          <td>IPSETFLAGS</td>
1809          <td>flags for the IPSet; requires ipset attribute</td>
1810        </tr>
1811       </table>
1812     <p>
1813       <br/><br/>
1814     </p>
1815
1816     <h3><a name="nwfelemsRulesAdv">Advanced Filter Configuration Topics</a></h3>
1817     <p>
1818      The following sections discuss advanced filter configuration
1819      topics.
1820     </p>
1821
1822     <h4><a name="nwfelemsRulesAdvTracking">Connection tracking</a></h4>
1823     <p>
1824      The network filtering subsystem (on Linux) makes use of the connection
1825      tracking support of iptables. This helps in enforcing the
1826      directionality of network traffic (state match) as well as
1827      counting and limiting the number of simultaneous connections towards
1828      a VM. As an example, if a VM has TCP port 8080
1829      open as a server, clients may connect to the VM on port 8080.
1830      Connection tracking and enforcement of directionality then prevents
1831      the VM from initiating a connection from
1832      (TCP client) port 8080 to the host back to a remote host.
1833      More importantly, tracking helps to prevent
1834      remote attackers from establishing a connection back to a VM. For example,
1835      if the user inside the VM established a connection to
1836      port 80 on an attacker site, then the attacker will not be able to
1837      initiate a connection from TCP port 80 back towards the VM.
1838      By default the connection state match that enables connection tracking
1839      and then enforcement of directionality of traffic is turned on. <br/>
1840      The following shows an example XML fragment where this feature has been
1841      turned off for incoming connections to TCP port 12345.
1842     </p>
1843 <pre>
1844    [...]
1845     &lt;rule direction='in' action='accept' statematch='false'&gt;
1846       &lt;tcp dstportstart='12345'/&gt;
1847     &lt;/rule&gt;
1848    [...]
1849 </pre>
1850     <p>
1851      This now allows incoming traffic to TCP port 12345, but would also
1852      enable the initiation from (client) TCP port 12345 within the VM,
1853      which may or may not be desirable.
1854     </p>
1855
1856     <h4><a name="nwfelemsRulesAdvLimiting">Limiting Number of Connections</a></h4>
1857     <p>
1858      To limit the number of connections a VM may establish, a rule must
1859      be provided that sets a limit of connections for a given
1860      type of traffic. If for example a VM
1861      is supposed to be allowed to only ping one other IP address at a time
1862      and is supposed to have only one active incoming ssh connection at a
1863      time, the following XML fragment can be used to achieve this.
1864     </p>
1865 <pre>
1866   [...]
1867   &lt;rule action='drop' direction='in' priority='400'&gt;
1868     &lt;tcp connlimit-above='1'/&gt;
1869   &lt;/rule&gt;
1870   &lt;rule action='accept' direction='in' priority='500'&gt;
1871     &lt;tcp dstportstart='22'/&gt;
1872   &lt;/rule&gt;
1873   &lt;rule action='drop' direction='out' priority='400'&gt;
1874     &lt;icmp connlimit-above='1'/&gt;
1875   &lt;/rule&gt;
1876   &lt;rule action='accept' direction='out' priority='500'&gt;
1877     &lt;icmp/&gt;
1878   &lt;/rule&gt;
1879   &lt;rule action='accept' direction='out' priority='500'&gt;
1880     &lt;udp dstportstart='53'/&gt;
1881   &lt;/rule&gt;
1882   &lt;rule action='drop' direction='inout' priority='1000'&gt;
1883     &lt;all/&gt;
1884   &lt;/rule&gt;
1885   [...]
1886 </pre>
1887     <p>
1888      Note that the rule for the limit has to logically appear
1889      before the rule for accepting the traffic.<br/>
1890      An additional rule for letting DNS traffic to port 22
1891      go out the VM has been added to avoid ssh sessions not
1892      getting established for reasons related to DNS lookup failures
1893      by the ssh daemon. Leaving this rule out may otherwise lead to
1894      fun-filled debugging joy (symptom: ssh client seems to hang
1895      while trying to connect).
1896      <br/><br/>
1897      Lot of care must be taken with timeouts related
1898      to tracking of traffic. An ICMP ping that
1899      the user may have terminated inside the VM may have a long
1900      timeout in the host's connection tracking system and therefore
1901      not allow another ICMP ping to go through for a while. Therefore,
1902      the timeouts have to be tuned in the host's sysfs, i.e.,
1903     </p>
1904
1905 <pre>
1906   echo 3 > /proc/sys/net/netfilter/nf_conntrack_icmp_timeout
1907 </pre>
1908     <p>
1909       sets the ICMP connection tracking timeout to 3 seconds. The
1910       effect of this is that once one ping is terminated, another
1911       one can start after 3 seconds.<br/>
1912       Further, we want to point out that a client that for whatever
1913       reason has not properly closed a TCP connection may cause a
1914       connection to be held open for a longer period of time,
1915       depending to what timeout the <code>TCP established</code> state
1916       timeout has been set to on the host. Also, idle connections may time
1917       out in the connection tracking system but can be reactivated once
1918       packets are exchanged. However, a newly initiated connection may force
1919       an idle connection into TCP backoff if the number of allowed connections
1920       is set to a too low limit, the new connection is established
1921       and hits (not exceeds) the limit of allowed connections and for
1922       example a key is pressed on the old ssh session, which now has become
1923       unresponsive due to its traffic being dropped.
1924       Therefore, the limit of connections should be rather high so that
1925       fluctuations in new TCP connections don't cause odd
1926       traffic behavior in relation to idle connections.
1927     </p>
1928
1929     <h2><a name="nwfcli">Command line tools</a></h2>
1930     <p>
1931       The libvirt command line tool <code>virsh</code> has been extended
1932       with life-cycle support for network filters. All commands related
1933       to the network filtering subsystem start with the prefix
1934       <code>nwfilter</code>. The following commands are available:
1935     </p>
1936     <ul>
1937      <li>nwfilter-list : list UUIDs and names of all network filters</li>
1938      <li>nwfilter-define : define a new network filter or update an existing one</li>
1939      <li>nwfilter-undefine : delete a network filter given its name; it must not be currently in use</li>
1940      <li>nwfilter-dumpxml : display a network filter given its name</li>
1941      <li>nwfilter-edit : edit a network filter given its name</li>
1942     </ul>
1943
1944     <h2><a name="nwfexamples">Pre-existing network filters</a></h2>
1945     <p>
1946      The following is a list of example network filters that are
1947      automatically installed with libvirt.</p>
1948       <table class="top_table">
1949        <tr>
1950          <th> Name </th>
1951          <th> Description </th>
1952        </tr>
1953        <tr>
1954          <td> no-arp-spoofing </td>
1955          <td> Prevent a VM from spoofing ARP traffic; this filter
1956               only allows ARP request and reply messages and enforces
1957               that those packets contain the MAC and IP addresses
1958               of the VM.</td>
1959       </tr>
1960        <tr>
1961          <td> allow-dhcp </td>
1962          <td> Allow a VM to request an IP address via DHCP (from any
1963               DHCP server)</td>
1964       </tr>
1965        <tr>
1966          <td> allow-dhcp-server </td>
1967          <td> Allow a VM to request an IP address from a specified
1968               DHCP server. The dotted decimal IP address of the DHCP
1969               server must be provided in a reference to this filter.
1970               The name of the variable must be <i>DHCPSERVER</i>.</td>
1971       </tr>
1972        <tr>
1973          <td> no-ip-spoofing </td>
1974          <td> Prevent a VM from sending of IP packets with
1975               a source IP address different from the one
1976               in the packet. </td>
1977       </tr>
1978        <tr>
1979          <td> no-ip-multicast </td>
1980          <td> Prevent a VM from sending IP multicast packets. </td>
1981       </tr>
1982        <tr>
1983          <td> clean-traffic </td>
1984          <td> Prevent MAC, IP and ARP spoofing. This filter references
1985               several other filters as building blocks. </td>
1986       </tr>
1987       </table>
1988     <p>
1989      Note that most of the above filters are only building blocks and
1990      require a combination with other filters to provide useful network
1991      traffic filtering.
1992      The most useful one in the above list is the <i>clean-traffic</i>
1993      filter. This filter itself can for example be combined with the
1994      <i>no-ip-multicast</i>
1995      filter to prevent virtual machines from sending IP multicast traffic
1996      on top of the prevention of packet spoofing.
1997     </p>
1998
1999     <h2><a name="nwfwrite">Writing your own filters</a></h2>
2000
2001     <p>
2002      Since libvirt only provides a couple of example networking filters, you
2003      may consider writing your own. When planning on doing so
2004      there are a couple of things
2005      you may need to know regarding the network filtering subsystem and how
2006      it works internally. Certainly you also have to know and understand
2007      the protocols very well that you want to be filtering on so that
2008      no further traffic than what you want can pass and that in fact the
2009      traffic you want to allow does pass.
2010      <br/><br/>
2011      The network filtering subsystem is currently only available on
2012      Linux hosts and only works for Qemu and KVM type of virtual machines.
2013      On Linux
2014      it builds upon the support for <code>ebtables</code>, <code>iptables
2015      </code> and <code>ip6tables</code> and makes use of their features.
2016      From the above list of supported protocols the following ones are
2017      implemented using <code>ebtables</code>:
2018     </p>
2019     <ul>
2020      <li>mac</li>
2021      <li>stp (spanning tree protocol)</li>
2022      <li>vlan (802.1Q)</li>
2023      <li>arp, rarp</li>
2024      <li>ipv4</li>
2025      <li>ipv6</li>
2026     </ul>
2027
2028     <p>
2029     All other protocols over IPv4 are supported using iptables, those over
2030     IPv6 are implemented using ip6tables.
2031     <br/><br/>
2032     On a Linux host, all traffic filtering instantiated by libvirt's network
2033     filter subsystem first passes through the filtering support implemented
2034     by ebtables and only then through iptables or ip6tables filters. If
2035     a filter tree has rules with the protocols <code>mac</code>,
2036     <code>stp</code>, <code>vlan</code>
2037     <code>arp</code>, <code>rarp</code>, <code>ipv4</code>,
2038     or <code>ipv6</code> ebtables rules will automatically be instantiated.
2039     <br/>
2040     The role of the <code>chain</code> attribute in the network filter
2041     XML is that internally a new user-defined ebtables table is created
2042     that then for example receives all <code>arp</code> traffic coming
2043     from or going to a virtual machine if the chain <code>arp</code>
2044     has been specified. Further, a rule is generated in an interface's
2045     <code>root</code> chain that directs all ipv4 traffic into the
2046     user-defined chain. Therefore, all ARP traffic rules should then be
2047     placed into filters specifying this chain. This type of branching
2048     into user-defined tables is only supported with filtering on the ebtables
2049     layer.
2050     <br/>
2051     <span class="since">Since 0.9.8</span> multiple chains for the same
2052     protocol can be created. For this the name of the chain must have
2053     a prefix of one of the previously enumerated protocols. To create an
2054     additional chain for handling of ARP traffic, a chain with name
2055     <code>arp-test</code> can be specified.
2056     <br/>
2057     As an example, it is
2058     possible to filter on UDP traffic by source and destination ports using
2059     the <code>ip</code> protocol filter and specifying attributes for the
2060     protocol, source and destination IP addresses and ports of UDP packets
2061     that are to be accepted. This allows
2062     early filtering of UDP traffic with ebtables. However, once an IP or IPv6
2063     packet, such as a UDP packet,
2064     has passed the ebtables layer and there is at least one rule in a filter
2065     tree that instantiates iptables or ip6tables rules, a rule to let
2066     the UDP packet pass will also be necessary to be provided for those
2067     filtering layers. This can be
2068     achieved with a rule containing an appropriate <code>udp</code> or
2069     <code>udp-ipv6</code> traffic filtering node.
2070     </p>
2071
2072     <h3><a name="nwfwriteexample">Example custom filter</a></h3>
2073     <p>
2074      As an example we want to now build a filter that fulfills the following
2075      list of requirements:
2076     </p>
2077     <ul>
2078      <li>prevents a VM's interface from MAC, IP and ARP spoofing</li>
2079      <li>opens only TCP ports 22 and 80 of a VM's interface</li>
2080      <li>allows the VM to send ping traffic from an interface
2081         but not let the VM be pinged on the interface</li>
2082      <li>allows the VM to do DNS lookups (UDP towards port 53)</li>
2083     </ul>
2084     <p>
2085      The requirement to prevent spoofing is fulfilled by the existing
2086      <code>clean-traffic</code> network filter, thus we will reference this
2087      filter from our custom filter.
2088      <br/>
2089      To enable traffic for TCP ports 22 and 80 we will add 2 rules to
2090      enable this type of traffic. To allow the VM to send ping traffic
2091      we will add a rule for ICMP traffic. For simplicity reasons
2092      we allow general ICMP traffic to be initiated from the VM, not
2093      just ICMP echo request and response messages. To then
2094      disallow all other traffic to reach or be initiated by the
2095      VM we will then need to add a rule that drops all other traffic.
2096      Assuming our VM is called <i>test</i> and
2097      the interface we want to associate our filter with is called <i>eth0</i>,
2098      we name our filter <i>test-eth0</i>.
2099      The result of these considerations is the following network filter XML:
2100     </p>
2101 <pre>
2102 &lt;filter name='test-eth0'&gt;
2103   &lt;!-- reference the clean traffic filter to prevent
2104        MAC, IP and ARP spoofing. By not providing
2105        and IP address parameter, libvirt will detect the
2106        IP address the VM is using. --&gt;
2107   &lt;filterref filter='clean-traffic'/&gt;
2108
2109   &lt;!-- enable TCP ports 22 (ssh) and 80 (http) to be reachable --&gt;
2110   &lt;rule action='accept' direction='in'&gt;
2111     &lt;tcp dstportstart='22'/&gt;
2112   &lt;/rule&gt;
2113
2114   &lt;rule action='accept' direction='in'&gt;
2115     &lt;tcp dstportstart='80'/&gt;
2116   &lt;/rule&gt;
2117
2118   &lt;!-- enable general ICMP traffic to be initiated by the VM;
2119        this includes ping traffic --&gt;
2120   &lt;rule action='accept' direction='out'&gt;
2121     &lt;icmp/&gt;
2122   &lt;/rule&gt;
2123
2124   &lt;!-- enable outgoing DNS lookups using UDP --&gt;
2125   &lt;rule action='accept' direction='out'&gt;
2126     &lt;udp dstportstart='53'/&gt;
2127   &lt;/rule&gt;
2128
2129   &lt;!-- drop all other traffic --&gt;
2130   &lt;rule action='drop' direction='inout'&gt;
2131     &lt;all/&gt;
2132   &lt;/rule&gt;
2133
2134 &lt;/filter&gt;
2135 </pre>
2136     <p>
2137      Note that none of the rules in the above XML contain the
2138      IP address of the VM as either source or destination address, yet
2139      the filtering of the traffic works correctly. The reason is that
2140      the evaluation  of the rules internally happens on a
2141      per-interface basis and the rules are evaluated based on the knowledge
2142      about which (tap) interface has sent or will receive the packet rather
2143      than what their source or destination IP address may be.
2144      <br/><br/>
2145      An XML fragment for a possible network interface description inside
2146      the domain XML of the <code>test</code> VM could then look like this:
2147     </p>
2148 <pre>
2149    [...]
2150     &lt;interface type='bridge'&gt;
2151       &lt;source bridge='mybridge'/&gt;
2152       &lt;filterref filter='test-eth0'/&gt;
2153     &lt;/interface&gt;
2154    [...]
2155 </pre>
2156
2157     <p>
2158      To more strictly control the ICMP traffic and enforce that only
2159      ICMP echo requests can be sent from the VM
2160      and only ICMP echo responses be received by the VM, the above
2161      <code>ICMP</code> rule can be replaced with the following two rules:
2162     </p>
2163 <pre>
2164   &lt;!-- enable outgoing ICMP echo requests--&gt;
2165   &lt;rule action='accept' direction='out'&gt;
2166     &lt;icmp type='8'/&gt;
2167   &lt;/rule&gt;
2168
2169   &lt;!-- enable incoming ICMP echo replies--&gt;
2170   &lt;rule action='accept' direction='in'&gt;
2171     &lt;icmp type='0'/&gt;
2172   &lt;/rule&gt;
2173 </pre>
2174
2175     <h3><a name="nwfwriteexample2nd">Second example custom filter</a></h3>
2176     <p>
2177      In this example we now want to build a similar filter as in the
2178      example above, but extend the list of requirements with an
2179      ftp server located inside the VM. Further, we will be using features
2180      that have been added in <span class="since">version 0.8.5</span>.
2181      The requirements for this filter are:
2182     </p>
2183     <ul>
2184      <li>prevents a VM's interface from MAC, IP and ARP spoofing</li>
2185      <li>opens only TCP ports 22 and 80 of a VM's interface</li>
2186      <li>allows the VM to send ping traffic from an interface
2187         but not let the VM be pinged on the interface</li>
2188      <li>allows the VM to do DNS lookups (UDP towards port 53)</li>
2189      <li>enable an ftp server (in active mode) to be run inside the VM</li>
2190     </ul>
2191     <p>
2192      The additional requirement of allowing an ftp server to be run inside
2193      the VM maps into the requirement of allowing port 21 to be reachable
2194      for ftp control traffic as well as enabling the VM to establish an
2195      outgoing tcp connection originating from the VM's TCP port 20 back to
2196      the ftp client (ftp active mode). There are several ways of how this
2197      filter can be written and we present 2 solutions.
2198      <br/><br/>
2199      The 1st solution makes use of the <code>state</code> attribute of
2200      the TCP protocol that gives us a hook into the connection tracking
2201      framework of the Linux host. For the VM-initiated ftp data connection
2202      (ftp active mode) we use the <code>RELATED</code> state that allows
2203      us to detect that the VM-initiated ftp data connection is a consequence of
2204      ( or 'has a relationship with' ) an existing ftp control connection,
2205      thus we want to allow it to let packets
2206      pass the firewall. The <code>RELATED</code> state, however, is only
2207      valid for the very first packet of the outgoing TCP connection for the
2208      ftp data path. Afterwards, the state to compare against is
2209      <code>ESTABLISHED</code>, which then applies equally
2210      to the incoming and outgoing direction. All this is related to the ftp
2211      data traffic originating from TCP port 20 of the VM. This then leads to
2212      the following solution
2213      <span class="since">(since 0.8.5 (Qemu, KVM, UML))</span>:
2214     </p>
2215 <pre>
2216 &lt;filter name='test-eth0'&gt;
2217   &lt;!-- reference the clean traffic filter to prevent
2218        MAC, IP and ARP spoofing. By not providing
2219        and IP address parameter, libvirt will detect the
2220        IP address the VM is using. --&gt;
2221   &lt;filterref filter='clean-traffic'/&gt;
2222
2223   &lt;!-- enable TCP port 21 (ftp-control) to be reachable --&gt;
2224   &lt;rule action='accept' direction='in'&gt;
2225     &lt;tcp dstportstart='21'/&gt;
2226   &lt;/rule&gt;
2227
2228   &lt;!-- enable TCP port 20 for VM-initiated ftp data connection
2229        related to an existing ftp control connection --&gt;
2230   &lt;rule action='accept' direction='out'&gt;
2231     &lt;tcp srcportstart='20' state='RELATED,ESTABLISHED'/&gt;
2232   &lt;/rule&gt;
2233
2234   &lt;!-- accept all packets from client on the ftp data connection --&gt;
2235   &lt;rule action='accept' direction='in'&gt;
2236     &lt;tcp dstportstart='20' state='ESTABLISHED'/&gt;
2237   &lt;/rule&gt;
2238
2239   &lt;!-- enable TCP ports 22 (ssh) and 80 (http) to be reachable --&gt;
2240   &lt;rule action='accept' direction='in'&gt;
2241     &lt;tcp dstportstart='22'/&gt;
2242   &lt;/rule&gt;
2243
2244   &lt;rule action='accept' direction='in'&gt;
2245     &lt;tcp dstportstart='80'/&gt;
2246   &lt;/rule&gt;
2247
2248   &lt;!-- enable general ICMP traffic to be initiated by the VM;
2249        this includes ping traffic --&gt;
2250   &lt;rule action='accept' direction='out'&gt;
2251     &lt;icmp/&gt;
2252   &lt;/rule&gt;
2253
2254   &lt;!-- enable outgoing DNS lookups using UDP --&gt;
2255   &lt;rule action='accept' direction='out'&gt;
2256     &lt;udp dstportstart='53'/&gt;
2257   &lt;/rule&gt;
2258
2259   &lt;!-- drop all other traffic --&gt;
2260   &lt;rule action='drop' direction='inout'&gt;
2261     &lt;all/&gt;
2262   &lt;/rule&gt;
2263
2264 &lt;/filter&gt;
2265 </pre>
2266     <p>
2267      Before trying out a filter using the <code>RELATED</code> state,
2268      you have to make sure that the appropriate connection tracking module
2269      has been loaded into the host's kernel. Depending on the version of the
2270      kernel, you must run either one of the following two commands before
2271      the ftp connection with the VM is established.
2272     </p>
2273 <pre>
2274     modprobe nf_conntrack_ftp   # where available  or
2275
2276     modprobe ip_conntrack_ftp   # if above is not available
2277 </pre>
2278     <p>
2279      If other protocols than ftp are to be used in conjunction with the
2280      <code>RELATED</code> state, their corresponding module must be loaded.
2281      Modules exist at least for the protocols ftp, tftp, irc, sip,
2282      sctp, and amanda.
2283     </p>
2284     <p>
2285      The 2nd solution makes uses the state flags of connections more
2286      than the previous solution did.
2287      In this solution we take advantage of the fact that the
2288      <code>NEW</code> state of a connection is valid when the very
2289      first packet of a traffic flow is seen. Subsequently, if the very first
2290      packet of a flow is accepted, the flow becomes a connection and enters
2291      the <code>ESTABLISHED</code> state. This allows us to write a general
2292      rule for allowing packets of <code>ESTABLISHED</code> connections to
2293      reach the VM or be sent by the VM.
2294      We write specific rules for the very first packets identified by the
2295      <code>NEW</code> state and for which ports they are acceptable. All
2296      packets for ports that are not explicitly accepted will be dropped and
2297      therefore the connection will not go into the <code>ESTABLISHED</code>
2298      state and any subsequent packets be dropped.
2299     </p>
2300
2301 <pre>
2302 &lt;filter name='test-eth0'&gt;
2303   &lt;!-- reference the clean traffic filter to prevent
2304        MAC, IP and ARP spoofing. By not providing
2305        and IP address parameter, libvirt will detect the
2306        IP address the VM is using. --&gt;
2307   &lt;filterref filter='clean-traffic'/&gt;
2308
2309   &lt;!-- let the packets of all previously accepted connections reach the VM --&gt;
2310   &lt;rule action='accept' direction='in'&gt;
2311     &lt;all state='ESTABLISHED'/&gt;
2312   &lt;/rule&gt;
2313
2314   &lt;!-- let the packets of all previously accepted and related connections be sent from the VM --&gt;
2315   &lt;rule action='accept' direction='out'&gt;
2316     &lt;all state='ESTABLISHED,RELATED'/&gt;
2317   &lt;/rule&gt;
2318
2319   &lt;!-- enable traffic towards port 21 (ftp), 22 (ssh) and 80 (http) --&gt;
2320   &lt;rule action='accept' direction='in'&gt;
2321     &lt;tcp dstportstart='21' dstportend='22' state='NEW'/&gt;
2322   &lt;/rule&gt;
2323
2324   &lt;rule action='accept' direction='in'&gt;
2325     &lt;tcp dstportstart='80' state='NEW'/&gt;
2326   &lt;/rule&gt;
2327
2328   &lt;!-- enable general ICMP traffic to be initiated by the VM;
2329        this includes ping traffic --&gt;
2330   &lt;rule action='accept' direction='out'&gt;
2331     &lt;icmp state='NEW'/&gt;
2332   &lt;/rule&gt;
2333
2334   &lt;!-- enable outgoing DNS lookups using UDP --&gt;
2335   &lt;rule action='accept' direction='out'&gt;
2336     &lt;udp dstportstart='53' state='NEW'/&gt;
2337   &lt;/rule&gt;
2338
2339   &lt;!-- drop all other traffic --&gt;
2340   &lt;rule action='drop' direction='inout'&gt;
2341     &lt;all/&gt;
2342   &lt;/rule&gt;
2343
2344 &lt;/filter&gt;
2345
2346 </pre>
2347
2348     <h2><a name="nwflimits">Limitations</a></h2>
2349     <p>
2350      The following sections list (current) limitations of the network
2351      filtering subsystem.
2352     </p>
2353
2354     <h3><a name="nwflimitsmigr">VM Migration</a></h3>
2355      <p>
2356       VM migration is only supported if the whole filter tree
2357       that is referenced by a virtual machine's top level filter
2358       is also available on the target host. The network filter
2359       <i>clean-traffic</i>
2360       for example should be available on all libvirt installations
2361       of version 0.8.1 or later and thus enable migration of VMs that
2362       for example reference this filter. All other
2363       custom filters must be migrated using higher layer software. It is
2364       outside the scope of libvirt to ensure that referenced filters
2365       on the source system are equivalent to those on the target system
2366       and vice versa.
2367       <br/><br/>
2368       Migration must occur between libvirt installations of version
2369       0.8.1 or later in order not to lose the network traffic filters
2370       associated with an interface.
2371      </p>
2372     <h3><a name="nwflimitsvlan">VLAN filtering on Linux</a></h3>
2373      <p>
2374       VLAN (802.1Q) packets, if sent by a virtual machine, cannot be filtered
2375       with rules for protocol IDs <code>arp</code>, <code>rarp</code>,
2376       <code>ipv4</code> and <code>ipv6</code> but only
2377       with protocol IDs <code>mac</code> and <code>vlan</code>. Therefore,
2378       the example filter <code>clean-traffic</code> will not work as expected.
2379      </p>
2380   </body>
2381 </html>