debian-{add,del}_ip.sh: fix IPv6 wrt 2.6.32 kernel

When vzctl attempts to add an IPv6 address to a Debian Lenny container on
2.6.32 no error is returned but the IP address is not added to the container.

vz-1:~# vzctl set 228 --ipadd 2001:0DB8::1
Adding IP address(es): 2001:db8::1
WARNING: Settings were not saved and will be resetted to original values on
next start (use --save flag)
vz-1:~# vzctl enter 228
entered into VE 228
228:/# ifconfig
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

venet0    Link encap:UNSPEC  HWaddr
00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          inet addr:127.0.0.1  P-t-P:127.0.0.1  Bcast:0.0.0.0
Mask:255.255.255.255
          UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

This appears to be due to the way the interface is specified in
/etc/network/interfaces. The current script generates IPv6 configurations in
the following form:

iface venet0 inet6 static
    address ::1
    netmask 128
    up ifconfig venet0 add 2001:db8::1/0

However this does not work with the 2.6.32 kernel:

228:/# ifup -v venet0
Configuring interface venet0=venet0 (inet)
run-parts --verbose /etc/network/if-pre-up.d

ifconfig venet0 127.0.0.1 netmask 255.255.255.255 broadcast 0.0.0.0
up

route add default dev venet0
run-parts --verbose /etc/network/if-up.d
run-parts: executing /etc/network/if-up.d/mountnfs
run-parts: executing /etc/network/if-up.d/openssh-server
Configuring interface venet0=venet0 (inet6)
run-parts --verbose /etc/network/if-pre-up.d
ifconfig venet0    up
ifconfig venet0 add ::1/128
SIOCSIFADDR: Cannot assign requested address
Failed to bring up venet0.

This exact configuration stanza is fine under 2.6.26, however.

Some investigation shows that there is no obvious reason for assigning
127.0.0.1 or ::1/128 to venet0 interfaces inside CT.

Attached is a patch against the latest git versions of debian-add_ip.sh and
debian-del_ip.sh to fix IPv6 address handling and make IP handling on Debian
slightly more robust overall (removes the need for assigning 127.0.0.1 to
venet0, fixes a place where venet0 was hardcoded in the script)

This bug seems to be related to #1499 however this proposed patch doesn't
require the "ip" util and is thus more applicable to older versions of Debian
without hacks.

Tested here against Debian Lenny 5.0.6 with success.

http://bugzilla.openvz.org/1669
2 files changed