Multicast and Threading

I have two gateways at home, both running different operating systems. There are quite a few alternatives for router failover. However most opensource VRRP inplementations suck (keepalived, vrrpd, freevrrpd) as does CARP on linux (ucarp). Which is why I decided to scratch this itch by writing my own failover daemon in perl.

I quickly settled on multicast and a somewhat vrrp-like packet format with hmac to secure the messages. The send and receive tasks are handled by separate threads, which allows the main loop to just be a simple state machine. Installation is quite simple (if you have daemontools):


mkdir -p failoverd/bin
mkdir -p failoverd/env
mkdir -p failoverd/log/main

cat <failoverd/run
#!/bin/sh

exec 2>&1
exec envdir ./env ./bin/failoverd
EOF

cat <failoverd/log/run
#!/bin/sh
exec setuidgid nobody multilog t ./main
EOF

chmod +x failoverd/run failoverd/log/run
chown nobody failoverd/log/main

echo MYINTERFACE > failoverd/env/INTERFACE
echo MYPASSWORD > failoverd/env/SECRET
echo 100 > failoverd/env/PRIO
echo ./bin/backup > failoverd/env/BACKUP
echo ./bin/master > failoverd/env/MASTER

Download the daemon and put it in failoverd/bin, and write your own custom backup/master scripts.

Leave a Reply

Powered by WP Hashcash