Bug 1389 - [PATCH][PVE] debian-add_ip.sh script inserts /etc/interfaces.tail in wrong place
[PATCH][PVE] debian-add_ip.sh script inserts /etc/interfaces.tail in wrong place
Product: OpenVZ
Classification: Unclassified
Component: vzctl
All Debian
: P2 normal
Assigned To: Kir Kolyshkin
: 1362 (view as bug list)
Depends on:
  Show dependency treegraph
Reported: 2009-12-22 11:45 EST by Patryk "LeadMan" Benderz
Modified: 2011-05-25 13:36 EDT (History)
3 users (show)

See Also:

Modifies /etc/vz/dists/scripts/debian-add_ip.sh script to add /etc/iinterfaces.tail properly (532 bytes, patch)
2009-12-22 11:45 EST, Patryk "LeadMan" Benderz
Details | Diff
Modifies /etc/vz/dists/scripts/debian-add_ip.sh script to add /etc/iinterfaces.tail properly (615 bytes, patch)
2010-01-05 05:26 EST, Dietmar Maurer
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Patryk "LeadMan" Benderz 2009-12-22 11:45:24 EST
Created attachment 1110 [details]
Modifies /etc/vz/dists/scripts/debian-add_ip.sh script to add /etc/iinterfaces.tail properly

Hi all,
while testing Proxmox PVE I found misbehavior of /etc/vz/dists/scripts/debian-add_ip.sh . Putting post-up routing rules into /etc/interfaces.tail does not work. If i do it this way i get correct routing table but cannot ping any host in these networks. My attempts to fix this:

1) I had to delete /etc/interfaces.tail and make additional init script
which is started after all (including venet0:0, 0:1, etc) interfaces are
up and running. This works fine, although i am not 100% satisfied with
this solution, as it is not "native". 

2) I have noticed, that /etc/interfaces.tail is inserted somewhere in the middle of /etc/interfaces instead of at the end. It looks like /etc/vz/dists/scripts/debian-add_ip.sh around line 64, adds interfaces.tail, and after that /usr/lib/vzctl/scripts/vps_functions (or other scripts) adds venet0:0,0:1, etc. entries at end of /etc/interfaces.
    Following this trace, i have moved "tail" section in debian-add_ip.sh
to add_ip() function. This attempt worked like a charm and now i am able
to reach all networks automatically after start/reboot of guest. This fixes /etc/interfaces.tail to be added at the end of /etc/interfaces as it should be done.
    I was asked on PVE mailing list to report this as a bug to openvz bugzilla. I did not test or check other similar scripts for other distros. Anyone interested, please test patch supplied in attachment. It was generated with:
# cd /etc/vz/dists/scripts
# diff -Naur debian-add_ip.sh debian-add_ip.sh_modified_tail_behavior > debian-add_ip.sh_modified_tail_behavior.diff

Procedure to make a backup and apply patch:
1)copy .diff to your pve host (not guest) to /etc/vz/dists/scripts/
2)ssh to your pve host
3)# cd /etc/vz/dists/scripts/
4)# patch -b < debian-add_ip.sh_modified_tail_behavior.diff

P.S. I am not sure if I choose "component" field correctly while filling this bug report.
Comment 1 Kir Kolyshkin 2009-12-23 06:43:23 EST

I have checked vzctl git and debian-add_ip.sh looks perfectly fine there. So I guess it's a bug of PVE.
Comment 2 Dietmar Maurer 2009-12-23 09:07:03 EST
I also checked git, and I see the same bug there. create_config() is called after setup_network().

Cant you reproduce the bug?
Comment 3 Dietmar Maurer 2009-12-28 03:13:38 EST
I just tested with latest git - interfaces.tail does not even work when using a single IP address.
Comment 4 Patryk "LeadMan" Benderz 2009-12-30 09:32:21 EST
(In reply to comment #1)
> Patryk,
> I have checked vzctl git and debian-add_ip.sh looks perfectly fine there. So I
> guess it's a bug of PVE.

Do i still need to do something, despite Dietmar Maurer confirmed this bug?
Comment 5 Dietmar Maurer 2010-01-05 05:26:57 EST
Created attachment 1115 [details]
Modifies /etc/vz/dists/scripts/debian-add_ip.sh script to add /etc/iinterfaces.tail properly

slightly modifies previous patch - adds tail before the network is actually restarted
Comment 6 Kir Kolyshkin 2010-01-25 07:34:40 EST
I stared at the code for some time, here's what I figured out.

In order for interfaces.tail to work as designed (i.e. always be inserted at the end of file) we need to recreate /etc/network/interfaces from scratch every time we add a new IP. The thing that we need to recreate it from scratch means we should know all the IP addresses a VE should have.

This is incompatible with the current vzctl design/architecture:

(1) When a container is running with some IP addresses and we use vzctl set $CTID --ipadd $ADDR, only $ADDR is passed to the add_ip script, not all addresses of this CT. This means we have to add the new IP incrementally, not rewrite the file completely.

(2) When we add a new IP to /etc/network/interfaces, we add it to the end of file.

So far I can only solve this by removing support for /etc/network/interfaces.tail since I can not make it work properly...
Comment 7 Dietmar Maurer 2010-01-25 07:39:28 EST
OK, understand that now - thanks for the explaination.

So I guess it is best to keep the current behaviour - better than nothing ;-)
Comment 8 Kir Kolyshkin 2010-01-25 07:41:26 EST
(In reply to comment #6)

> So far I can only solve this by removing support for
> /etc/network/interfaces.tail since I can not make it work properly...

Or let it stay but do not guarantee its contents will be at the end of file and/or updated when you add a new IP.
Comment 9 Kir Kolyshkin 2010-01-25 08:28:36 EST
OK, then let it stay as is.

adds a note that we can not guarantee having contents of interfaces.tail at the end of file.

Closing as wontfix, reasons specified in comment #6.

PS commit message contains some thoughts about how this could be solved properly, if one has the courage to do that. But it looks like the game is not worth the candle.
Comment 10 Kir Kolyshkin 2011-05-25 13:36:04 EDT
*** Bug 1362 has been marked as a duplicate of this bug. ***