<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>www.cardus.com &#187; BSD</title>
	<atom:link href="http://www.cardus.com/category/tech/bsd/feed" rel="self" type="application/rss+xml" />
	<link>http://www.cardus.com</link>
	<description>Sean Cardus&#039;s Website</description>
	<lastBuildDate>Mon, 19 Jul 2010 10:11:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Building a transparent traffic-shaping bridge</title>
		<link>http://www.cardus.com/2007/09/24/building-a-transparent-traffic-shaping-bridge</link>
		<comments>http://www.cardus.com/2007/09/24/building-a-transparent-traffic-shaping-bridge#comments</comments>
		<pubDate>Mon, 24 Sep 2007 09:38:34 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[BSD]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://www.cardus.com/2007/09/24/building-a-transparent-traffic-shaping-bridge/</guid>
		<description><![CDATA[I&#8217;ve recently had the need to create a box capable of transparently traffic-shaping traffic across a single ethernet connection. Normally, I&#8217;d go for some kind of Linux solution, but after doing a bit of research it looked like one of the BSD&#8217;s with pf/ALTQ would be the way to go. After trying out a couple [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently had the need to create a box capable of transparently traffic-shaping traffic across a single ethernet connection.</p>
<p>Normally, I&#8217;d go for some kind of Linux solution, but after doing a bit of research it looked like one of the BSD&#8217;s with pf/ALTQ would be the way to go.  After trying out a couple of popular ready-made &#8220;appliances&#8221; (m0n0wall, pfsense) I decided that the best, most flexible way, would be to get my hands dirty and roll my own.</p>
<p>This post is just a quick summary of the active configuration at the time of writing, mainly for my future reference.  So, without further ado, here&#8217;s what I came up with&#8230;</p>
<p>[<strong>Updated</strong>]</p>
<p><span id="more-117"></span></p>
<p>I decided to go for OpenBSD, grabbed the ISO, burnt it to CD and made a standard installation (minus the games.tgz package).  The server I&#8217;m using has 2 on-board NIC&#8217;s and a 4-port PCI NIC card.  During installation I configured one of the on-board ports as my servers main Internet/management interface.</p>
<p>Next I configured a couple of the ports on the PCI card to act as bridged interfaces:</p>
<blockquote><p>/etc/hostname.vr0 :<br />
up</p>
<p>/etc/hostname.vr3 :<br />
up</p>
<p>/etc/bridgename.bridge0 :<br />
add vr0<br />
add vr3<br />
up</p></blockquote>
<p>Now it was time to configure pf, the ALTQ traffic queues and some rules to assign packets to queues.  The server is going to act as a transparent bridge between the internet-facing 100Mb switchport and the LAN.  The &#8220;LAN&#8221; is all public IP addressable, so no NAT rules/translation etc is needed here.  The LAN should also only be allowed 10Mb of Internet bandwidth.  Here&#8217;s the current configuration after a bit of playing around and tuning:</p>
<blockquote><p>/etc/pf.conf :</p>
<p># Define the interface aliases<br />
ext_if=&#8221;vr3&#8243; # External WAN-facing interface<br />
int_if=&#8221;vr0&#8243; # Internal LAN-facing interface</p>
<p># Leecher IP addresses &#8211; These are punished with a shared low-bandwidth queue<br />
# Separate addresses/CIDR ranges with commas.<br />
#<br />
table &lt;leechers&gt; persist { }</p>
<p># Enable ALTQ on the internal interface, assign the root queue and<br />
# ultimate bandwidth limit<br />
altq on $int_if hfsc bandwidth 10Mb queue { int_root }</p>
<p># Define the interface queues<br />
queue int_root bandwidth 100% priority 0 hfsc {default_out, penalty_out, acks_out, normal_out, high_out}<br />
queue default_out bandwidth 1% priority 1 qlimit 500 hfsc (default realtime 1% red ecn)<br />
queue penalty_out bandwidth 1% priority 2 qlimit 500 hfsc (upperlimit 1Mb red ecn)<br />
queue acks_out bandwidth 30% priority 7 qlimit 500 hfsc (realtime 10% red ecn)<br />
queue normal_out bandwidth 20% priority 3 qlimit 500 hfsc (realtime 1Kb red ecn)<br />
queue high_out bandwidth 45% priority 4 qlimit 500 hfsc (realtime 1Kb red ecn)</p>
<p># Enable ALTQ on the external interface, assign the root queue and<br />
# ultimate bandwidth limit<br />
altq on $ext_if hfsc bandwidth 10Mb queue { ext_root }</p>
<p># Define the interface queues<br />
queue ext_root bandwidth 100% priority 0 hfsc {default_in, penalty_in, acks_in,normal_in, high_in}<br />
queue default_in bandwidth 1% priority 1 qlimit 500 hfsc (default realtime 1% red ecn)<br />
queue penalty_in bandwidth 1% priority 2 qlimit 500 hfsc (upperlimit 1Mb red ecn)<br />
queue acks_in bandwidth 30% priority 7 qlimit 500 hfsc (realtime 10% red ecn)<br />
queue normal_in bandwidth 20% priority 3 qlimit 500 hfsc (realtime 1Kb red ecn)<br />
queue high_in bandwidth 45% priority 4 qlimit 500 hfsc (realtime 1Kb red ecn)</p>
<p>###<br />
# Packet matching rules &#8211; A match will assign a packet to a given queue<br />
###</p>
<p># Put leeching mofo&#8217;s into the penalty queue<br />
pass in quick on $int_if from { &lt;leechers&gt; } to any queue penalty_out<br />
pass in quick on $ext_if from any to { &lt;leechers&gt; } queue penalty_in</p>
<p># Give ICMP packets high(er) priority<br />
pass in quick on $int_if proto icmp all queue high_out<br />
pass in quick on $ext_if proto icmp all queue high_in</p>
<p># Give VPN, RDP, SSH &amp; DNS packets high(er) priority<br />
pass in quick on $int_if proto ah all queue (high_out, acks_out)<br />
pass in quick on $ext_if proto ah all queue (high_in, acks_in)<br />
pass in quick on $int_if proto esp all queue (high_out, acks_out)<br />
pass in quick on $ext_if proto esp all queue (high_in, acks_in)<br />
pass in quick on $int_if proto gre all queue (high_out, acks_out)<br />
pass in quick on $ext_if proto gre all queue (high_in, acks_in)</p>
<p>pass in quick on $int_if proto tcp from any to any port 3389 queue (high_out, acks_out)<br />
pass in quick on $ext_if proto tcp from any to any port 3389 queue (high_in, acks_in)<br />
pass in quick on $int_if proto tcp from any to any port 22 queue (high_out, acks_out)<br />
pass in quick on $ext_if proto tcp from any to any port 22 queue (high_in, acks_in)<br />
pass in quick on $int_if proto tcp from any to any port 53 queue (high_out, acks_out)<br />
pass in quick on $ext_if proto tcp from any to any port 53 queue (high_in, acks_in)<br />
pass in quick on $int_if proto udp from any to any port 53 queue (high_out, acks_out)<br />
pass in quick on $ext_if proto udp from any to any port 53 queue (high_in, acks_in)</p>
<p># Assign standard web &amp; mail traffic to the &#8220;normal&#8221; queue<br />
pass in quick on $int_if proto tcp from any to any port 80 queue (normal_out, acks_out)<br />
pass in quick on $ext_if proto tcp from any to any port 80 queue (normal_in, acks_in)<br />
pass in quick on $int_if proto tcp from any to any port 443 queue (normal_out, acks_out)<br />
pass in quick on $ext_if proto tcp from any to any port 443 queue (normal_in, acks_in)<br />
pass in quick on $int_if proto tcp from any to any port 25 queue (normal_out, acks_out)<br />
pass in quick on $ext_if proto tcp from any to any port 25 queue (normal_in, acks_in)<br />
pass in quick on $int_if proto tcp from any to any port 110 queue (normal_out, acks_out)<br />
pass in quick on $ext_if proto tcp from any to any port 110 queue (normal_in, acks_in)<br />
pass in quick on $int_if proto tcp from any to any port 143 queue (normal_out, acks_out)<br />
pass in quick on $ext_if proto tcp from any to any port 143 queue (normal_in, acks_in)</p>
<p># Stick everything else into the default queue<br />
pass in quick on $int_if all queue (default_out, acks_out)<br />
pass in quick on $ext_if all queue (default_in, acks_in)</p></blockquote>
<p>A quick check with &#8220;pftop&#8221; shows that traffic is being queued &amp; shaped correctly&#8230;</p>
<blockquote>
<pre>QUEUE               BW SCH  PR  PKTS BYTES DROP_P DROP_B QLEN BORR SUSP P/S  B/S
root_vr0           10M hfsc  0     0     0      0      0    0             0    0
 int_root          10M hfsc  0     0     0      0      0    0             0    0
  default_out     100K hfsc     565K  358M      0      0    0           284 316K
  penalty_out     100K hfsc  2     0     0      0      0    0             0    0
  acks_out       3000K hfsc  7  454K   25M      0      0    0           113 6417
  normal_out     2000K hfsc  3 1119K 1405M      0      0    0           277 364K
  high_out       4500K hfsc  4  219K   65M      0      0    0            78  42K
root_vr3           10M hfsc  0     0     0      0      0    0             0    0
 ext_root          10M hfsc  0     0     0      0      0    0             0    0
  default_in      100K hfsc    1839K  878M     15  17364    4           566 301K
  penalty_in      100K hfsc  2     0     0      0      0    0             0    0
  acks_in        3000K hfsc  7 56271 3425K      0      0    0             5  396
  normal_in      2000K hfsc  3 76830   81M     10  15140    0             7 4698
  high_in        4500K hfsc  4  163K   39M      0      0    0            71  22K</pre>
</blockquote>
<p>Hopefully someone somewhere will find this useful.  If anyone has any ideas to fine-tune my config, please feel free to let me know <img src='http://www.cardus.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>UPDATE 1:</strong> The above installation was made onto a standard IDE harddisk, but I intend to replace the disk with a 256MB IDE flash card.  If anyone has any advice for getting a small OpenBSD installation onto one of these, please drop me a line.  Thanks <img src='http://www.cardus.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>UPDATE 2</strong>: It turns out installing onto flash was easier than I expected it to be.  I fired up the installation CD, partitioned the flash drive with one large 256MB partition and then only installed the bsd, base41 &amp; etc41 packages.  Once that lot installed I created /proto/var &amp; /proto/dev, re-created the device nodes in /proto/dev and copied /var into /proto/var.  All that was left was to edit /etc/fstab to mount /var and /dev from the prototype dirs as ramdisks.  Job&#8217;s a goodun!&#8230;</p>
<blockquote><p>/etc/fstab :</p>
<p>/dev/wd0a / ffs rw,noatime 1 1<br />
swap /var mfs rw,-P/proto/var,-s=65535,noexec,nosuid,nodev,noauto 0 0<br />
swap /dev mfs rw,-P/proto/dev,-s=1200,-i=128,noexec,nosuid 0 0</p></blockquote>
<p>This last piece of advice was taken from this website: <a title="http://www.kaschwig.net/projects/openbsd/wrap/" href="http://www.kaschwig.net/projects/openbsd/wrap/">http://www.kaschwig.net/projects/openbsd/wrap/</a></p>



Share:


	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.cardus.com%2F2007%2F09%2F24%2Fbuilding-a-transparent-traffic-shaping-bridge&amp;title=Building%20a%20transparent%20traffic-shaping%20bridge&amp;annotation=I%27ve%20recently%20had%20the%20need%20to%20create%20a%20box%20capable%20of%20transparently%20traffic-shaping%20traffic%20across%20a%20single%20ethernet%20connection.%0D%0A%0D%0ANormally%2C%20I%27d%20go%20for%20some%20kind%20of%20Linux%20solution%2C%20but%20after%20doing%20a%20bit%20of%20research%20it%20looked%20like%20one%20of%20the%20BSD%27s%20wi" title="Google Bookmarks"><img src="http://www.cardus.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.cardus.com%2F2007%2F09%2F24%2Fbuilding-a-transparent-traffic-shaping-bridge&amp;t=Building%20a%20transparent%20traffic-shaping%20bridge" title="Facebook"><img src="http://www.cardus.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.cardus.com%2F2007%2F09%2F24%2Fbuilding-a-transparent-traffic-shaping-bridge&amp;title=Building%20a%20transparent%20traffic-shaping%20bridge" title="Live"><img src="http://www.cardus.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.cardus.com%2F2007%2F09%2F24%2Fbuilding-a-transparent-traffic-shaping-bridge&amp;title=Building%20a%20transparent%20traffic-shaping%20bridge&amp;bodytext=I%27ve%20recently%20had%20the%20need%20to%20create%20a%20box%20capable%20of%20transparently%20traffic-shaping%20traffic%20across%20a%20single%20ethernet%20connection.%0D%0A%0D%0ANormally%2C%20I%27d%20go%20for%20some%20kind%20of%20Linux%20solution%2C%20but%20after%20doing%20a%20bit%20of%20research%20it%20looked%20like%20one%20of%20the%20BSD%27s%20wi" title="Digg"><img src="http://www.cardus.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.cardus.com%2F2007%2F09%2F24%2Fbuilding-a-transparent-traffic-shaping-bridge&amp;title=Building%20a%20transparent%20traffic-shaping%20bridge&amp;notes=I%27ve%20recently%20had%20the%20need%20to%20create%20a%20box%20capable%20of%20transparently%20traffic-shaping%20traffic%20across%20a%20single%20ethernet%20connection.%0D%0A%0D%0ANormally%2C%20I%27d%20go%20for%20some%20kind%20of%20Linux%20solution%2C%20but%20after%20doing%20a%20bit%20of%20research%20it%20looked%20like%20one%20of%20the%20BSD%27s%20wi" title="del.icio.us"><img src="http://www.cardus.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.cardus.com%2F2007%2F09%2F24%2Fbuilding-a-transparent-traffic-shaping-bridge" title="Technorati"><img src="http://www.cardus.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.cardus.com%2F2007%2F09%2F24%2Fbuilding-a-transparent-traffic-shaping-bridge&amp;title=Building%20a%20transparent%20traffic-shaping%20bridge" title="StumbleUpon"><img src="http://www.cardus.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Building%20a%20transparent%20traffic-shaping%20bridge%20-%20http%3A%2F%2Fwww.cardus.com%2F2007%2F09%2F24%2Fbuilding-a-transparent-traffic-shaping-bridge" title="Twitter"><img src="http://www.cardus.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.cardus.com/2007/09/24/building-a-transparent-traffic-shaping-bridge/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
