Background

Ubiquiti makes a line of highly integrated routers that are basically small, outdoor Linux machines with an 802.11a/n radio and a wired nic, some also come with a built in antenna, which makes setting up a long-distance outdoor network really easy and cheaply.

At NrVissing.Net which I do tech for we now have 25 Access points and 70 CPEs, all of them Ubiquiti NanoStation 5, NanoBridge 5M and other 5M gear. The APs are placed at 4 different physical locations and linked via 802.11n.

The problem that OSPF solves

The Ubiquiti gear works really well, but there's no redundancy, which means that I'm only one breakdown away from having 70 angry, Internet deprived neighbors. Another problem is that maintaining the routing is quickly becoming harder as more bits of network appears. The solution, as you might have guessed is called OSPF.

OSPF allows routers to figure out which links exist in the network topology for them selves and set up several routes that allow the kernel to balance the traffic between several routes and take down routes that have failed.

Implementing OSPF on Linux with Quagga

For Linux there is a popular package called Quagga, which has already been ported to openwrt, which AirOS V is based on, so adding it to the AirOS SDK was easy enough.

Inveneo did much the same work for the older non-openwrt-based AirOS, so for the older AirOS versions I've been using a solution based on their work.

Implementing OSPF on Linux with BIRD

Some people swear by BIRD, so I thought I'd take a stab at using it on AirOS, some random thoughts in this regard:

Dealing with the existing non-OSPF routers: CARP

I don't expect to be able to replace all the existing non-OSPF APs all at once, but I'd still like them to keep working if their default gateway goes down, for this I'm using CARP as implemented by the portable UCARP daemon to automatically switch the default gateway IP from one of the OSPF-enabled uplinks to another. Nobody has ported and published an openwrt port of ucarp before me, so for this bit I had to start from scratch, but since first doing this a port has appeared and I'm now using that.

Contents

What you get with my firmware mod are the following ingredients:

ComponentVersionWhat it is
AirOS 5.5 SDKExact version downloaded directly from ubnt.com
UCARP 1.5.2Exact version downloaded directly from the openwrt svn server.
BIRD 1.3.7Exact version downloaded directly from the openwrt svn server.
saveconfign/aA small script that does: 'cfgmtd -w -p /etc/'.
Patches 2012-08-31Patches to build and hook into the ubnt init.

Releases

VersionChanges
2010-01-30Initial release.
2010-02-10Configured Linux with multipath (aka. ECMP) support, without it routes would disappear if Quagga could see more than one route.
2010-02-14Ported BIRD 1.2.1 and added saveconfig.
2010-02-21Disabled the buggy and OOPSy CONFIG_IP_ROUTE_MULTIPATH_CACHED kernel option, multipath routing now works correctly.
2010-02-23Updated to SDK 5.1.2 and added a README file, no other changes.
2012-08-31Updated to SDK 5.5, removed Quagga, upgraded to newer versions of BIRD and UCARP, moved to github.

Getting and building the firmware

Rather than do all the work and distribute the resulting image, I'm publishing a small perl script which will do all the downloading, patching and building needed to get the finished image in about half an hour on a reasonable 64bit ubunutu 12.04 machine. Distributing the modification this way allows anybody to modify the parts they need and as it's a fairly minimal set of diffs, it allows me to upgrade the solution to a newer version of AirOS much easier.

  1. Download the script or check it out using git
  2. Check out the project from github here: airos-plus.tar.bz2 [16K]
  3. Unpack the zip file by running something like: unzip dren-dk-AirosPlus-b88fce9.zip
  4. cd to the created directory: cd dren-dk-AirosPlus-b88fce9
  5. If you have already downloaded the SDK run: ./plus path/to/SDK.UBNT.v5.5.tar.bz2
  6. If you don't have the SDK just run: ./plus get
  7. If you are missing any of the OS tools you need to build the firmware, the script will try to use sudo apt-get install ... to install the packages.
  8. Wait while the firmware is built.
  9. If all goes well you will end up with a new firmware file called something like: XM.ar7240.v5.5.plus-2012-08-27.12536.120831.2042.bin that you can update your M-series Ubiquiti router with.

Configuring BIRD

Once the firmware has been installed you need to configure at least BIRD, without it the daemon will not be started.

Create the config file called /etc/persistent/bird4.conf and run saveconfig, then reboot to have the BIRD daemon started.

If /etc/persistent/bird4.conf exists then init will be configured to keep bird running via /etc/inittab

Getting AirOS routes out of the way

No routes should be configured in AirOS, not even the default route, because those routes will not be distributed by OSPF and they will interfere, to get AirOS to stop creating any routes, set:

route.1.gw=
route.1.status=disabled

Configuring UCARP

UCARP is configured by a simple shell script named /etc/persistent/ucarp.conf, there is an example version of this file located in SDK.UBNT.v5.5/openwrt/package/ucarp/files/ucarp.conf once the script has patched it into the SDK. This is the example file:

# Usage for AirOS: 
# 1) Edit this file and copy it to /etc/persistent/ucarp.conf
# 2) Test: ucarp.init test
# 3) When it works run: saveconfig

# Run in background
BACKGROUND=1

# Interface to run CARP on
IF=eth0

# Virtual IP shared with the other system
VIP=10.0.0.117

# Size of the network mask for the virtual IP
VMASK=24

# Real, static IP of this host
MYIP=192.168.1.20

# Password shared with the other system
PASSWORD=love

# IP addresses to arping after taking over the shared IP,
# you should list all known systems, those not listed can
# take up to a minute to notice the change.
PINGIP="10.0.0.1 10.0.0.20"

# Set this instance to be the preferred master or an explicit backup:
# ROLE=master
# ROLE=backup

If you set ROLE=master on one router and ROLE=backup on another, then the master will always own the shared IP if it's online.

Tip jar?

I don't have a tip jar, but if you found something on this page useful then feel free to buy me a book from my Amazon wishlist.

© Flemming Frandsen