Robotic Tendencies
The personal blog of Robert McQueen

June 9, 2008

Xen virtual interfaces with more than one IP

I’ve got a load of boxes running Debian etch with Xen 3.0.3 with routed networking (rather than bridged, so I can do iptables and reverse path filtering etc in dom0). Since upgrading from Xen 2.x many moons ago, I’ve not known how to configure one virtual interface to have more than one IP. In the meantime, I’ve ended up doing nonsense like providing a VM with two interfaces just to give it two IPs. However, this interacts really badly with reverse path filtering unless you do a bunch of source-routing rocket science in the domU to send out through the right vif.

So, I looked at the vif-route script and it seems to support iterating through a space-separated list of IPs, but I was totally unable to find any documentation or mailing list posts explaining how to format the IPs within the formerly-Python key/value Xen domain config file syntax. After a while playing with the parser and various levels of quoting, I found that actually, the correct amount of quoting is none at all, and also uncovered a bug in another script which prevents it from working correctly. In the hope that this might help others using Google and trying to achieve the same as me, here is my recipe for configuring Xen vif devices to have multiple IPs (note that I think this might be specific to Xen 3.0.x, as I believe 3.2.x introduces config files in the S-expression format which is what xenstore uses internally):

  1. Configure your VM using this surprisingly obvious, but somewhat dubious syntax (including a second argument just to prove that yes, it really does work like that):

    vif=['ip=1.2.3.4 5.6.7.8, mac=00:16:3e:01:23:45']

    When parsed into SXP by xm create, this sets the ip value correctly as a space separated list as the scripts expect:

    (device (vif (ip '1.2.3.4 5.6.7.8') (mac 00:16:3e:01:23:45)))
  2. Fix the bug in /etc/xen/scripts/vif-common.sh:

    --- /etc/xen/scripts/vif-common.sh~ 2008-06-09 01:14:23.065065119 +0100
    +++ /etc/xen/scripts/vif-common.sh 2008-06-09 01:11:06.599986274 +0100
    @@ -103,7 +103,7 @@
    if [ "$ip" != "" ]
    then
    local addr
    - for addr in "$ip"
    + for addr in $ip
    do
    frob_iptable -s "$addr"
    done
  3. Set up multi-homed or aliased interfaces as normal in the domU (depending if you’re a ip or an ifconfig kinda guy).
  4. Profit!

posted by Robert McQueen @ 12:40 am
Comments (5) .:. Trackback .:. Permalink

June 5, 2008

Surströmming

In the office, Christian has just unwrapped a very carefully packed box containing a bulging tin of Surströmming. Apparently due to the “unique” smell you have to open it outside, and he’s invited people to come to his house to try it. Now, I’m not keen on various types of fish even at the best of times, so add a year or so of fermentation, and I am very, very scared. In unrelated news, some people in the office have decided to take up vegetarianism.

posted by Robert McQueen @ 11:08 am
Comments (8) .:. Trackback .:. Permalink