Replacing Swisscom router by a Linux box

Vincent Bernat

I have re­cently moved to Lau­sanne, Switzer­land. Broad­band In­ter­net ac­cess is not as cheap as in France. Free, a French ISP, is pro­vid­ing an FTTH ac­cess with a band­width of 1 Gbps1 for about €38 (in­clud­ing TV and phone ser­vice), Swiss­com is pro­vid­ing roughly the same ser­vice for about €200.2 Swiss­com fiber ac­cess was avail­able for my apart­ment and I chose the 40 Mbps con­tract with­out phone ser­vice for about €80.

Like many ISP, Swiss­com pro­vides an In­ter­net box with an ad­di­tional box for TV. I did not un­pack the TV box as I have no use for it. The In­ter­net box comes with some nice fea­tures like the abil­ity to set up fire­wall rules, a guest wire­less ac­cess and some file shar­ing pos­si­bil­i­ties. No shell access!

I have bought a small PC to act as router and re­place the In­ter­net box. I have loaded the up­com­ing De­bian Jessie on it. You can find the whole soft­ware con­fig­u­ra­tion in a Git repository.

This blog post only cov­ers the Swiss­com-spe­cific setup (and QoS). Have a look at these two blog posts for re­lated topics:

Ethernet#

The In­ter­net box is packed with a Sili­gence-branded 1000BX SFP.3 This SFP re­ceives and trans­mits data on the same fiber us­ing a dif­fer­ent wave­length for each di­rection.

In­stead of us­ing a net­work card with an SFP port, I bought a Net­gear GS110TP which comes with 8 gi­ga­bit cop­per ports and 2 fiber SFP ports. It is a cheap switch bun­dled with many in­ter­est­ing fea­tures like VLAN and LLDP. It works fine if you do not ex­pect too much from it.

IPv4#

IPv4 con­nec­tiv­ity is pro­vided over VLAN 10. A DHCP client is manda­tory. More­over, the DHCP ven­dor class iden­ti­fier op­tion (op­tion 60) needs to be ad­ver­tised. This can be done by adding the fol­low­ing line to /etc/​dhcp/​dhclient.​conf when us­ing the ISC DHCP client:

send vendor-class-identifier "100008,0001,,Debian";

The first two num­bers are here to iden­tify the ser­vice you are re­quest­ing. I sup­pose this can be read as re­quest­ing the Swiss­com res­i­den­tial ac­cess ser­vice. You can put what­ever you want af­ter that. Once you get a lease, you need to use a browser to iden­tify your­self to Swiss­com on the first use.

IPv6#

Swiss­com pro­vides IPv6 ac­cess through the 6rd pro­to­col. This is a tun­nel­ing mech­a­nism to fa­cil­i­tate IPv6 de­ploy­ment across an IPv4 in­fra­struc­ture. This kind of tun­nel is na­tively sup­ported by Linux since ker­nel ver­sion 2.6.33.

To set up IPv6, you need the base IPv6 pre­fix and the 6rd gate­way. Some ISP are pro­vid­ing these val­ues through DHCP (op­tion 212) but this is not the case for Swiss­com. The gate­way is 6rd.​swisscom.​com and the pre­fix is 2a02:1200::/28. Af­ter ap­pend­ing the IPv4 ad­dress to the pre­fix, you still get 4 bits for in­ter­nal subnets.

Swiss­com does not pro­vide a fixed IPv4 ad­dress. There­fore, it is not pos­si­ble to pre­com­pute the IPv6 pre­fix. When in­stalled as a DHCP hook (in /etc/​dhcp/​dhclient-exit-hooks.​d/6rd), the fol­low­ing script con­fig­ures the tunnel:

sixrd_iface=internet6
sixrd_mtu=1472                  # This is 1500 - 20 - 8 (PPPoE header)
sixrd_ttl=64
sixrd_prefix=2a02:1200::/28     # No way to guess, just have to know it.
sixrd_br=193.5.29.1             # That's "6rd.swisscom.com"

sixrd_down() {
    ip tunnel del ${sixrd_iface} || true
}

sixrd_up() {
    ipv4=${new_ip_address:-$old_ip_address}

    sixrd_subnet=$(ruby <<EOF
require 'ipaddr'
prefix = IPAddr.new "${sixrd_prefix}", Socket::AF_INET6
prefixlen = ${sixrd_prefix#*/}
ipv4 = IPAddr.new "${ipv4}", Socket::AF_INET
ipv6 = IPAddr.new (prefix.to_i + (ipv4.to_i << (64 + 32 - prefixlen))), Socket::AF_INET6
puts ipv6
EOF
)

    # Let's configure the tunnel
    ip tunnel add ${sixrd_iface} mode sit local $ipv4 ttl $sixrd_ttl
    ip tunnel 6rd dev ${sixrd_iface} 6rd-prefix ${sixrd_prefix}
    ip addr add ${sixrd_subnet}1/64 dev ${sixrd_iface}
    ip link set mtu ${sixrd_mtu} dev ${sixrd_iface}
    ip link set ${sixrd_iface} up
    ip route add default via ::${sixrd_br} dev ${sixrd_iface}
}

case $reason in
    BOUND|REBOOT)
        sixrd_down
        sixrd_up
        ;;
    RENEW|REBIND)
        if [ "$new_ip_address" != "$old_ip_address" ]; then
            sixrd_down
            sixrd_up
        fi
        ;;
    STOP|EXPIRE|FAIL|RELEASE)
        sixrd_down
        ;;
esac

The com­pu­ta­tion of the IPv6 pre­fix is off­loaded to Ruby in­stead of try­ing to use the shell for that. Even if the ipaddr mod­ule is pretty “ba­sic,” it suits the job.

Swiss­com is us­ing the same MTU for all clients. Be­cause some of them are us­ing PPPoE, the MTU is 1472 in­stead of 1480. You can eas­ily check your MTU with this handy on­line MTU test tool.

It is not un­com­mon that PMTUD is bro­ken on some parts of the In­ter­net. While not ideal, set­ting up TCP MSS will al­le­vi­ate any prob­lem you may run into with an MTU less than 1500:

ip6tables -t mangle -A POSTROUTING -o internet6 \
          -p tcp --tcp-flags SYN,RST SYN \
          -j TCPMSS --clamp-mss-to-pmtu

QoS#

Up­date (2014-11)

Un­for­tu­nately, this sec­tion was in­cor­rect, in­clud­ing its premise. Have a look at Dave Taht com­ment for more de­tails. As an al­ter­na­tive, Gen­too’s wiki con­tains sim­ple in­struc­tions to set up ef­fec­tive traf­fic shaping.