<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>shorewall-tcrules</title><link rel="stylesheet" href="html.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /></head><body><div class="refentry" lang="en" xml:lang="en"><a id="id257171"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>tcrules — Shorewall Packet Marking rules file</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p><code class="command">/etc/shorewall/</code> </p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id257202"></a><h2>Description</h2><p>Entries in this file cause packets to be marked as a means of classifying them for traffic control or policy routing.</p><div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Important</h3><p>Unlike rules in the <a class="ulink" href="shorewall-rules.html" target="_self">shorewall-rules</a>(5) file, evaluation of rules in this file will continue after a match. So the final mark for each packet will be the one assigned by the LAST tcrule that matches.</p><p>If you use multiple internet providers with the 'track' option, in /etc/shorewall/providers be sure to read the restrictions at <a class="ulink" href="http://shorewall.net/MultiISP.html" target="_self">http://shorewall.net/MultiISP.html</a>.</p></div><p>The columns in the file are as follows.</p><div class="variablelist"><dl><dt><span class="term"><span class="bold"><strong>MARK/CLASSIFY</strong></span> - {<span class="emphasis"><em>value</em></span>|<span class="emphasis"><em>major</em></span><span class="bold"><strong>:</strong></span><span class="emphasis"><em>minor</em></span>|<span class="bold"><strong>RESTORE</strong></span>[<span class="bold"><strong>/</strong></span><span class="emphasis"><em>mask</em></span>]|<span class="bold"><strong>SAVE</strong></span>[<span class="bold"><strong>/</strong></span><span class="emphasis"><em>mask</em></span>]|<span class="bold"><strong>CONTINUE</strong></span>|<span class="bold"><strong>COMMENT</strong></span>}[<span class="bold"><strong>:</strong></span>{<span class="bold"><strong>C</strong></span>|<span class="bold"><strong>F</strong></span>|<span class="bold"><strong>P</strong></span>|<span class="bold"><strong>T</strong></span>|<span class="bold"><strong>CF</strong></span>|<span class="bold"><strong>CP</strong></span>|<span class="bold"><strong>CT</strong></span>}]</span></dt><dd><p>May assume one of the following values.</p><div class="orderedlist"><ol type="1"><li><p>A mark <span class="emphasis"><em>value</em></span> which is an integer in the range 1-255.</p><p>Normally will set the mark value. If preceded by a vertical bar ("|"), the mark value will be logically ORed with the current mark value to produce a new mark value. If preceded by an ampersand ("&"), will be logically ANDed with the current mark value to produce a new mark value.</p><p>Both "|" and "&" require Extended MARK Target support in your kernel and iptables; neither may be used with connection marks (see below).</p><p>May optionally be followed by <span class="bold"><strong>:P</strong></span>, <span class="bold"><strong>:F</strong></span> or <span class="bold"><strong>:T</strong></span> where<span class="bold"><strong> :P</strong></span> indicates that marking should occur in the PREROUTING chain, <span class="bold"><strong>:F</strong></span> indicates that marking should occur in the FORWARD chain and <span class="bold"><strong>:T</strong></span> indicates that marking should occur in the POSTROUTING chain. If neither <span class="bold"><strong>:P</strong></span>, <span class="bold"><strong>:F</strong></span> nor <span class="bold"><strong>:T</strong></span> follow the mark value then the chain is determined as follows:</p><p>- If the SOURCE is <span class="bold"><strong>$FW</strong></span>[<span class="bold"><strong>:</strong></span><span class="emphasis"><em>address-or-range</em></span>[,<span class="emphasis"><em>address-or-range</em></span>]...], then the rule is inserted into the OUTPUT chain.</p><p>- Otherwise, the chain is determined by the setting of MARK_IN_FORWARD_CHAIN in <a class="ulink" href="shorewall.conf.html" target="_self">shorewall.conf</a>(5).</p><p>If your kernel and iptables include CONNMARK support then you can also mark the connection rather than the packet.</p><p>The mark value may be optionally followed by "/" and a mask value (used to determine those bits of the connection mark to actually be set). The mark and optional mask are then followed by one of:+</p><div class="variablelist"><dl><dt><span class="term"><span class="bold"><strong>C</strong></span></span></dt><dd><p>Mark the connection in the chain determined by the setting of MARK_IN_FORWARD_CHAIN</p></dd><dt><span class="term"><span class="bold"><strong>CF</strong></span></span></dt><dd><p>Mark the connection in the FORWARD chain</p></dd><dt><span class="term"><span class="bold"><strong>CP</strong></span></span></dt><dd><p>Mark the connection in the PREROUTING chain.</p></dd><dt><span class="term">CT</span></dt><dd><p>Mark the connecdtion in the POSTROUTING chain</p></dd></dl></div><p><span class="bold"><strong>Special considerations for If HIGH_ROUTE_MARKS=Yes in <a class="ulink" href="shorewall.conf.html" target="_self">shorewall.conf</a>(5</strong></span>).</p><p>If HIGH_ROUTE_MARKS=Yes, then you may also specify a value in the range 0x0100-0xFF00 with the low-order byte being zero. Such values may only be used in the PREROUTING chain (value followed by <span class="bold"><strong>:P</strong></span> or you have set MARK_IN_FORWARD_CHAIN=No in <a class="ulink" href="shorewall.conf.html" target="_self">shorewall.conf</a>(5) and have not followed the value with <code class="option">:F</code>) or the OUTPUT chain (SOURCE is <span class="bold"><strong>$FW</strong></span>). With HIGH_ROUTE_MARKS=Yes, non-zero mark values less that 256 are not permitted. Shorewall 4.1 and later versions prohibit non-zero mark values less that 256 in the OUTPUT chain when HIGH_ROUTE_MARKS=Yes. While earlier versions allow such values in the OUTPUT chain, it is strongly recommended that with HIGH_ROUTE_MARKS=Yes, you use the POSTROUTING chain to apply traffic shaping marks/classification.</p></li><li><p>A classification Id (classid) of the form <span class="emphasis"><em>major</em></span>:<span class="emphasis"><em>minor</em></span> where <span class="emphasis"><em>major</em></span> and <span class="emphasis"><em>minor</em></span> are integers. Corresponds to the 'class' specification in these traffic shaping modules:</p><pre class="programlisting"> atm cbq dsmark pfifo_fast htb prio</pre><p>Classification occurs in the POSTROUTING chain except when the <span class="bold"><strong>SOURCE</strong></span> is <span class="bold"><strong>$FW</strong></span>[:<span class="emphasis"><em>address</em></span>] in which case classification occurs in the OUTPUT chain.</p><p>When using Shorewall's built-in traffic shaping tool, the <span class="emphasis"><em>major</em></span> class is the device number (the first device in <a class="ulink" href="shorewall-tcdevices.html" target="_self">shorewall-tcdevices</a>(5) is major class 1, the second device is major class 2, and so on) and the <span class="emphasis"><em>minor</em></span> class is the class's MARK value in <a class="ulink" href="shorewall-tcclasses.html" target="_self">shorewall-tcclasses</a>(5) preceded by the number 1 (MARK 1 corresponds to minor class 11, MARK 5 corresponds to minor class 15, MARK 22 corresponds to minor class 122, etc.).</p></li><li><p><span class="bold"><strong>RESTORE</strong></span>[/<span class="emphasis"><em>mask</em></span>] -- restore the packet's mark from the connection's mark using the supplied mask if any. Your kernel and iptables must include CONNMARK support.</p><p>As in 1) above, may be followed by <span class="bold"><strong>:P</strong></span> or <span class="bold"><strong>:F</strong></span></p></li><li><p><span class="bold"><strong>SAVE</strong></span>[/<span class="emphasis"><em>mask</em></span>] -- save the packet's mark to the connection's mark using the supplied mask if any. Your kernel and iptables must include CONNMARK support.</p><p>As in 1) above, may be followed by <span class="bold"><strong>:P</strong></span> or <span class="bold"><strong>:F</strong></span></p></li><li><p><span class="bold"><strong>CONTINUE</strong></span> Don't process any more marking rules in the table.</p><p>As in 1) above, may be followed by <span class="bold"><strong>:P</strong></span> or <span class="bold"><strong>:F</strong></span>. Currently, CONTINUE may not be used with <span class="emphasis"><em>exclusion</em></span> (see the SOURCE and DEST columns below); that restriction will be removed when iptables/Netfilter provides the necessary support.</p></li><li><p><span class="bold"><strong>COMMENT</strong></span> -- the rest of the line will be attached as a comment to the Netfilter rule(s) generated by the following entries. The comment will appear delimited by "/* ... */" in the output of <span class="command"><strong>shorewall show mangle</strong></span></p><p>To stop the comment from being attached to further rules, simply include COMMENT on a line by itself.</p></li></ol></div></dd><dt><span class="term"><span class="bold"><strong>SOURCE</strong></span> - {<span class="bold"><strong>-</strong></span>|{<span class="emphasis"><em>interface</em></span>|<span class="bold"><strong>$FW</strong></span>}|[{<span class="emphasis"><em>interface</em></span>|<span class="bold"><strong>$FW</strong></span>}:]<span class="emphasis"><em>address-or-range</em></span>[<span class="bold"><strong>,</strong></span><span class="emphasis"><em>address-or-range</em></span>]...}[<span class="emphasis"><em>exclusion</em></span>]</span></dt><dd><p>Source of the packet. A comma-separated list of interface names, IP addresses, MAC addresses and/or subnets for packets being routed through a common path. List elements may also consist of an interface name followed by ":" and an address (e.g., eth1:192.168.1.0/24). For example, all packets for connections masqueraded to eth0 from other interfaces can be matched in a single rule with several alternative SOURCE criteria. However, a connection whose packets gets to eth0 in a different way, e.g., direct from the firewall itself, needs a different rule.</p><p>Accordingly, use $<span class="bold"><strong>FW</strong></span> in its own separate rule for packets originating on the firewall. In such a rule, the MARK column may NOT specify either <span class="bold"><strong>:P</strong></span> or <span class="bold"><strong>:F</strong></span> because marking for firewall-originated packets always occurs in the OUTPUT chain.</p><p>MAC addresses must be prefixed with "~" and use "-" as a separator.</p><p>Example: ~00-A0-C9-15-39-78</p><p>You may exclude certain hosts from the set already defined through use of an <span class="emphasis"><em>exclusion</em></span> (see <a class="ulink" href="shorewall-exclusion.html" target="_self">shorewall-exclusion</a>(5)).</p></dd><dt><span class="term"><span class="bold"><strong>DEST</strong></span> - {<span class="bold"><strong>-</strong></span>|{<span class="emphasis"><em>interface</em></span>|[<span class="emphasis"><em>interface</em></span>:]<span class="emphasis"><em>address-or-range</em></span>[<span class="bold"><strong>,</strong></span><span class="emphasis"><em>address-or-range</em></span>]...}[<span class="emphasis"><em>exclusion</em></span>]</span></dt><dd><p>Destination of the packet. Comma separated list of IP addresses and/or subnets. If your kernel and iptables include iprange match support, IP address ranges are also allowed. List elements may also consist of an interface name followed by ":" and an address (e.g., eth1:192.168.1.0/24). If the <span class="bold"><strong>MARK</strong></span> column specificies a classification of the form <span class="emphasis"><em>major</em></span>:<span class="emphasis"><em>minor</em></span> then this column may also contain an interface name.</p><p>You may exclude certain hosts from the set already defined through use of an <span class="emphasis"><em>exclusion</em></span> (see <a class="ulink" href="shorewall-exclusion.html" target="_self">shorewall-exclusion</a>(5)).</p></dd><dt><span class="term"><span class="bold"><strong>PROTO</strong></span> - {<span class="bold"><strong>-</strong></span>|<span class="bold"><strong>tcp:syn</strong></span>|<span class="bold"><strong>ipp2p</strong></span>|<span class="bold"><strong>ipp2p:udp</strong></span>|<span class="bold"><strong>ipp2p:all</strong></span>|<span class="emphasis"><em>protocol-number</em></span>|<span class="emphasis"><em>protocol-name</em></span>|<span class="bold"><strong>all}</strong></span></span></dt><dd><p>Protocol - <span class="bold"><strong>ipp2p</strong></span> requires ipp2p match support in your kernel and iptables.</p></dd><dt><span class="term"><span class="bold"><strong>PORT(S)</strong></span> (Optional) - [<span class="bold"><strong>-</strong></span>|<span class="emphasis"><em>port-name-number-or-range</em></span>[<span class="bold"><strong>,</strong></span><span class="emphasis"><em>port-name-number-or-range</em></span>]...]</span></dt><dd><p>Destination Ports. A comma-separated list of Port names (from services(5)), <span class="emphasis"><em>port number</em></span>s or <span class="emphasis"><em>port range</em></span>s; if the protocol is <span class="bold"><strong>icmp</strong></span>, this column is interpreted as the destination icmp-type(s).</p><p>If the protocol is <span class="bold"><strong>ipp2p</strong></span>, this column is interpreted as an ipp2p option without the leading "--" (example <span class="bold"><strong>bit</strong></span> for bit-torrent). If no PORT is given, <span class="bold"><strong>ipp2p</strong></span> is assumed.</p><p>This column is ignored if PROTOCOL = all but must be entered if any of the following field is supplied. In that case, it is suggested that this field contain "-"</p></dd><dt><span class="term"><span class="bold"><strong>SOURCE PORT(S)</strong></span> (Optional) - [<span class="bold"><strong>-</strong></span>|<span class="emphasis"><em>port-name-number-or-range</em></span>[<span class="bold"><strong>,</strong></span><span class="emphasis"><em>port-name-number-or-range</em></span>]...]</span></dt><dd><p>Source port(s). If omitted, any source port is acceptable. Specified as a comma-separated list of port names, port numbers or port ranges.</p></dd><dt><span class="term"><span class="bold"><strong>USER</strong></span> (Optional) - [<span class="bold"><strong>!</strong></span>][<span class="emphasis"><em>user-name-or-number</em></span>][<span class="bold"><strong>:</strong></span><span class="emphasis"><em>group-name-or-number</em></span>][<span class="bold"><strong>+</strong></span><span class="emphasis"><em>program-name</em></span>]</span></dt><dd><p>This column may only be non-empty if the SOURCE is the firewall itself.</p><p>When this column is non-empty, the rule applies only if the program generating the output is running under the effective <span class="emphasis"><em>user</em></span> and/or <span class="emphasis"><em>group</em></span> specified (or is NOT running under that id if "!" is given).</p><p>Examples:</p><div class="variablelist"><dl><dt><span class="term">joe</span></dt><dd><p>program must be run by joe</p></dd><dt><span class="term">:kids</span></dt><dd><p>program must be run by a member of the 'kids' group</p></dd><dt><span class="term">!:kids</span></dt><dd><p>program must not be run by a member of the 'kids' group</p></dd><dt><span class="term">+upnpd</span></dt><dd><p>#program named upnpd</p><div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Important</h3><p>The ability to specify a program name was removed from Netfilter in kernel version 2.6.14.</p></div></dd></dl></div></dd><dt><span class="term"><span class="bold"><strong>TEST</strong></span> - [<span class="bold"><strong>!</strong></span>]<span class="emphasis"><em>value</em></span>[/<span class="emphasis"><em>mask</em></span>][<span class="bold"><strong>:C</strong></span>]</span></dt><dd><p>Defines a test on the existing packet or connection mark. The rule will match only if the test returns true.</p><p>If you don't want to define a test but need to specify anything in the following columns, place a "-" in this field.</p><div class="variablelist"><dl><dt><span class="term">!</span></dt><dd><p>Inverts the test (not equal)</p></dd><dt><span class="term"><span class="emphasis"><em>value</em></span></span></dt><dd><p>Value of the packet or connection mark.</p></dd><dt><span class="term"><span class="emphasis"><em>mask</em></span></span></dt><dd><p>A mask to be applied to the mark before testing.</p></dd><dt><span class="term"><span class="bold"><strong>:C</strong></span></span></dt><dd><p>Designates a connection mark. If omitted, the packet mark's value is tested.</p></dd></dl></div></dd><dt><span class="term"><span class="bold"><strong>LENGTH</strong></span> (Optional) - [<span class="emphasis"><em>length</em></span>|[<span class="emphasis"><em>min</em></span>]<span class="bold"><strong>:</strong></span>[<span class="emphasis"><em>max</em></span>]]</span></dt><dd><p>Packet Length. This field, if present allow you to match the length of a packet against a specific value or range of values. You must have iptables length support for this to work. A range is specified in the form <span class="emphasis"><em>min</em></span>:<span class="emphasis"><em>max</em></span> where either <span class="emphasis"><em>min</em></span> or <span class="emphasis"><em>max</em></span> (but not both) may be omitted. If <span class="emphasis"><em>min</em></span> is omitted, then 0 is assumed; if <span class="emphasis"><em>max</em></span> is omitted, than any packet that is <span class="emphasis"><em>min</em></span> or longer will match.</p></dd><dt><span class="term"><span class="bold"><strong>TOS</strong></span> - <span class="emphasis"><em>tos</em></span></span></dt><dd><p>Type of service. Either a standard name, or a numeric value to match.</p><pre class="programlisting"> <span class="bold"><strong>Minimize-Delay</strong></span> (16) <span class="bold"><strong>Maximize-Throughput</strong></span> (8) <span class="bold"><strong>Maximize-Reliability</strong></span> (4) <span class="bold"><strong>Minimize-Cost</strong></span> (2) <span class="bold"><strong>Normal-Service</strong></span> (0)</pre></dd></dl></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id258472"></a><h2>Example</h2><div class="variablelist"><dl><dt><span class="term">Example 1:</span></dt><dd><p>Mark all ICMP echo traffic with packet mark 1. Mark all peer to peer traffic with packet mark 4.</p><p>This is a little more complex than otherwise expected. Since the ipp2p module is unable to determine all packets in a connection are P2P packets, we mark the entire connection as P2P if any of the packets are determined to match.</p><p>We assume packet/connection mark 0 means unclassified.</p><pre class="programlisting"> #MARK/ SOURCE DEST PROTO PORT(S) SOURCE USER TEST #CLASSIFY PORT(S) 1 0.0.0.0/0 0.0.0.0/0 icmp echo-request 1 0.0.0.0/0 0.0.0.0/0 icmp echo-reply RESTORE 0.0.0.0/0 0.0.0.0/0 all - - - 0 CONTINUE 0.0.0.0/0 0.0.0.0/0 all - - - !0 4 0.0.0.0/0 0.0.0.0/0 ipp2p:all SAVE 0.0.0.0/0 0.0.0.0/0 all - - - !0</pre><p>If a packet hasn't been classifed (packet mark is 0), copy the connection mark to the packet mark. If the packet mark is set, we're done. If the packet is P2P, set the packet mark to 4. If the packet mark has been set, save it to the connection mark.</p></dd></dl></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id258518"></a><h2>FILES</h2><p>/etc/shorewall/tcrules</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id258528"></a><h2>See ALSO</h2><p><a class="ulink" href="http://shorewall.net/traffic_shaping.htm" target="_self">http://shorewall.net/traffic_shaping.htm</a></p><p><a class="ulink" href="http://shorewall.net/MultiISP.html" target="_self">http://shorewall.net/MultiISP.html</a></p><p><a class="ulink" href="http://shorewall.net/PacketMarking.html" target="_self">http://shorewall.net/PacketMarking.html</a></p><p>shorewall(8), shorewall-accounting(5), shorewall-actions(5), shorewall-blacklist(5), shorewall-ecn(5), shorewall-exclusion(5), shorewall-hosts(5), shorewall-interfaces(5), shorewall-ipsec(5), shorewall-maclist(5), shorewall-masq(5), shorewall-nat(5), shorewall-netmap(5), shorewall-params(5), shorewall-policy(5), shorewall-providers(5), shorewall-proxyarp(5), shorewall-route_rules(5), shorewall-routestopped(5), shorewall-rules(5), shorewall.conf(5), shorewall-tcclasses(5), shorewall-tcdevices(5), shorewall-tos(5), shorewall-tunnels(5), shorewall-zones(5)</p></div></div></body></html>