{"id":326,"date":"2014-07-15T19:56:00","date_gmt":"2014-07-15T17:56:00","guid":{"rendered":"http:\/\/www.hauweele.net\/~gawen\/blog\/?p=326"},"modified":"2014-07-16T13:20:39","modified_gmt":"2014-07-16T11:20:39","slug":"source-based-routing","status":"publish","type":"post","link":"https:\/\/hauweele.net\/~gawen\/blog\/?p=326","title":{"rendered":"Source based routing"},"content":{"rendered":"<p>My two home servers are down for the moment. This also means that our two IPv6 SixXS tunnels are down which costs us 100 ISK\u00a0per week. Argh! I need to get these up and running as soon as possible. Fortunately we have another VPS on Linux that can save us. So we just have to enable the two tunnels there and make sure that we can ping to\/from both interfaces.<\/p>\n<p>Setting up the two tunnels is easy. Use one configuration file per tunnel. Ensure that you change the parameters &#8220;tunnel_id&#8221; to the tunnel associated to this configuration file, one &#8220;pidfile&#8221; and &#8220;ipv6_interface&#8221; for each tunnel and &#8220;defaultroute&#8221; to false because we already have a default IPv6 route. Now you can start\/stop each tunnel with:<\/p>\n<pre>aiccu start \/etc\/aiccu\/tunnel0.conf\r\naiccu start \/etc\/aiccu\/tunnel1.conf\r\n\r\naiccu stop  \/etc\/aiccu\/tunnel0.conf\r\naiccu stop  \/etc\/aiccu\/tunnel1.conf\r\n<\/pre>\n<p>Don&#8217;t forget to hack <em>\/etc\/init.d\/aiccu<\/em> to start\/stop both tunnel on each reboot. OK! So now ifconfig list the two interfaces, up and running sixxs0 and sixxs1. This is great but wait&#8230; Nobody outside can ping these interfaces. The tunnel must ping to be considered active by SixXS so we better get this running.<\/p>\n<p>For now we have these three interfaces and IPs (not the actual names\/IPs):<\/p>\n<ol>\n<li><strong>net0<\/strong>\u00a0(2001::1) default<\/li>\n<li><strong>sixxs0<\/strong> (2a02::1)<\/li>\n<li><strong>sixxs1<\/strong> (2a02::2)<\/li>\n<\/ol>\n<p>By default, all our IPv6 traffic goes through\u00a0net0. However and unsurprisingly our ISP filters the traffic\u00a0at the output of net0. So we cannot use this interface to answer the echo-requests. Actually, what we want is that traffic originating 2a02::1 goes through sixxs0 and from 2a02::2 goes through sixxs1. That is, one default route based on the source address.<\/p>\n<p>Linux\u00a0has long had support for multiple routing tables (CONFIG_IP_MULTIPLE_TABLES). Basically what we will do here:<\/p>\n<ul>\n<li>Create two routing tables for each tunnel interface\u00a0(sixxs0, sixxs1).<\/li>\n<li>Each table will have a default route through its interface.<\/li>\n<li>Lookup into one of the two tables according to the source IP.<\/li>\n<\/ul>\n<p>You can find some relevant documentation in <a title=\"Linux Advanced Routing &amp; Traffic Control, Chapter 4.\" href=\"http:\/\/tldp.org\/HOWTO\/Adv-Routing-HOWTO\/lartc.rpdb.html\">Linux Advanced Routing &amp; Traffic Control, Chapter 4<\/a>.<\/p>\n<p>We first list the actual rules:<\/p>\n<pre># ip rule list\r\n0:  from all lookup local\r\n32766:  from all lookup main\r\n32767:  from all lookup default\r\n<\/pre>\n<p>We can see that we have three routing tables. One for the local addresses, the normal routing table (what you get with <code>ip -6 route<\/code>) and\u00a0the fallback default table.<br \/>\nLet&#8217;s first check the local routing table (we are just curious):<\/p>\n<pre># ip -6 route list table local\r\nlocal ::1 via :: dev lo  proto none  metric 0  mtu 16436 advmss 16376 hoplimit 0\r\nlocal 2a02::1 via :: dev lo  proto none  metric 0  mtu 16436 advmss 16376 hoplimit 0\r\nlocal 2001::1 via :: dev lo  proto none  metric 0  mtu 16436 rtt 6ms rttvar 7ms cwnd 10 advmss 16376 hoplimit 0\r\nlocal 2a02::2 via :: dev lo  proto none  metric 0  mtu 16436 advmss 16376 hoplimit 0\r\nlocal fe80::1 via :: dev lo  proto none  metric 0  mtu 16436 advmss 16376 hoplimit 0\r\nlocal fe80::2 via :: dev lo  proto none  metric 0  mtu 16436 advmss 16376 hoplimit 0\r\nff00::\/8 dev net0  metric 256  mtu 1500 advmss 1440 hoplimit 0\r\nff00::\/8 dev sixxs1  metric 256  mtu 1280 advmss 1220 hoplimit 0\r\nff00::\/8 dev sixxs0  metric 256  mtu 1280 advmss 1220 hoplimit 0\r\n<\/pre>\n<p>So now you know what&#8217;s going on when you ping one of your local interfaces. But back to our point. We name our two new routing tables in\u00a0<em>\/etc\/iproute2\/rt_tables<\/em>:<\/p>\n<pre># SixXS tables\r\n200 sixxs0\r\n201 sixxs1\r\n<\/pre>\n<p>Now we add the default route in each of these two tables:<\/p>\n<pre>ip -6 route add default dev sixxs0 table sixxs0\r\nip -6 route add default dev sixxs1 table sixxs1\r\n<\/pre>\n<p>And finally we use two rules to map the source address to the correct routing table:<\/p>\n<pre># ip -6 rule add from 2a02::1 table sixxs0\r\n# ip -6 rule add from 2a02::2 table sixxs1\r\n# ip -6 rule list\r\n0:  from all lookup local\r\n16383:  from 2a02::1 lookup sixxs0\r\n16383:  from 2a02::2 lookup sixxs1\r\n32766:  from all lookup main\r\n32767:  from all lookup default\r\n<\/pre>\n<p>It should be OK but let&#8217;s check that. We can ping from the sixxs interfaces:<\/p>\n<pre>ping6 -c1 -I 2a02::1 www.kame.net\r\nping6 -c1 -I 2a02::2 www.kame.net\r\n<\/pre>\n<p>We also check that we can ping our interfaces from another host:<\/p>\n<pre>ping6 -c1 2a02::1\r\nping6 -c1 2a02::2\r\n<\/pre>\n<p>Everything works, that&#8217;s great! Finally we just hack\u00a0<em>\/etc\/init.d\/aiccu<\/em> to configure the routing tables on each reboot. Note that you need to sleep a bit when you issue the aiccu start because the daemon needs a bit of time to enable the tunnels. Also note that you must be careful when you test your script (quoting the SixXS FAQ):<\/p>\n<blockquote><p>&#8220;If a client connects more than 4 times in 60 seconds (1 minute) the client will not be allowed to connect again for the next 5 minutes. In case this threshold is exceeded more than once in 24 hours a client will be automatically blocked for a week.&#8221;<\/p><\/blockquote>\n<p>As you can guess, I have been blocked. Oops!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My two home servers are down for the moment. This also means that our two IPv6 SixXS tunnels are down which costs us 100 ISK\u00a0per week. Argh! I need to get these up and running as soon as possible. Fortunately &hellip; <a href=\"https:\/\/hauweele.net\/~gawen\/blog\/?p=326\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[408,410,84,6,141,404,406,160,409,405,407],"class_list":["post-326","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-aiccu","tag-based","tag-ip","tag-linux","tag-multiple","tag-routing","tag-rt","tag-sixxs","tag-source","tag-table","tag-tunnels"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts\/326","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=326"}],"version-history":[{"count":0,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts\/326\/revisions"}],"wp:attachment":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}