You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using veth to connect containers without any bridges:
ip link add veth1a type veth peer name veth1b
configuration:
# some real adapter
lxc.net.0.type = phys
lxc.net.0.name = enx
lxc.net.0.link = enx00e053e6155c
# veth as phys
lxc.net.1.type = phys
lxc.net.1.name = ethv
lxc.net.1.link = veth1a
If everything else is okay this woks like a charm. However, if container configuration is wrong, for example, add a nonsense to reproduce:
lxc.hook.mount = xxx
then veth pair gets deleted from the system.
Basically, I suppose such a deletion is a kernel feature which seems to be difficult to work around in LXC, if possible at all.
But it's very annoying to me to restore interfaces each time I make a mistake in config. Plus to restart a container that used the peer. Some simple re-arrangements could make life a bit easier and I'd appreciate to see them implemented in the upstream someday. Below are just suggestions.
The main change is to move lxc_restore_phys_nics_to_netns call to the finalization of lxc_spawn, because it is not called in case of failure and adapters aren't moved back. Physical adapters survive, virtual ones do not.
The next change is invoking lxc_network_recv_name_and_ifindex_from_child immediatelly after sending interface names to the child.
I love the look of counterpart piece after making the change:
ret=lxc_network_recv_from_parent(handler);
if (ret<0)
returnlog_error(-1, "Failed to receive veth names from parent");
ret=lxc_setup_network_in_child_namespaces(lxc_conf);
if (ret<0)
returnlog_error(-1, "Failed to setup network");
ret=lxc_network_send_name_and_ifindex_to_parent(handler);
Everything is in one place. I have a gut feeling this is exact look of LXC code in early days before things get complicated.
However, for proper sequencing the data over sockets I had to move this block before lxc_rootfs_prepare_child.
I don't know if this move has any implications, it's was the simplest way for me. You might have better ideas with sync sugar.
Also note I had to swap indexes of handler->data_sock to make it working, I have no idea why above changes broke it, must be a serious flaw in my patch. Same for ERROR vs SYSERROR and syserror vs syserror_ret vs log_error. Not sure which one is correct in particular places.
Finally, the result of if_nametoindex is not checked in lxc_delete_network_priv, that looks a bit weird, and I haven't seen this
Have you tried to use lxc.net.X.type = veth ? In this case LXC will create veth-pair for you. You can instruct LXC to add this veth device in the bridge (use something like lxc.net.X.link = br0).
1. Have you tried to use `lxc.net.X.type = veth` ?
Honestly, I haven't. If I went this way one container would be the creator of veth pair and the other would use it. Too weird dependency to easily handle especially with many containers. What if I need to restart the creator and don't want peers to notice this? Pre-created pairs make things easier.
2. your veth pair is getting removed because veth device can only exist when it has a pair.
Basically that's not a problem, The problem is they gets deleted by lxc-start when they should not.
I feel myself stumbled upon an undocumented (unless I missed the doc, that's quite possible) interprocess protocol which is fragile and my attempt to make changes led to weird things such as the need for swapping socket pairs. If I worked at work I'd be forced to review, write documentation and/or comments, refactor the code, and then try fixing the problem. I tried the latter in the first place and this only spotted the problem. My personal workaround for now is not to make mistakes in the configuration files when I use veth.
I'm using veth to connect containers without any bridges:
configuration:
If everything else is okay this woks like a charm. However, if container configuration is wrong, for example, add a nonsense to reproduce:
then veth pair gets deleted from the system.
Basically, I suppose such a deletion is a kernel feature which seems to be difficult to work around in LXC, if possible at all.
But it's very annoying to me to restore interfaces each time I make a mistake in config. Plus to restart a container that used the peer. Some simple re-arrangements could make life a bit easier and I'd appreciate to see them implemented in the upstream someday. Below are just suggestions.
The main change is to move
lxc_restore_phys_nics_to_netns
call to the finalization oflxc_spawn
, because it is not called in case of failure and adapters aren't moved back. Physical adapters survive, virtual ones do not.The next change is invoking
lxc_network_recv_name_and_ifindex_from_child
immediatelly after sending interface names to the child.I love the look of counterpart piece after making the change:
Everything is in one place. I have a gut feeling this is exact look of LXC code in early days before things get complicated.
However, for proper sequencing the data over sockets I had to move this block before
lxc_rootfs_prepare_child
.I don't know if this move has any implications, it's was the simplest way for me. You might have better ideas with sync sugar.
Also note I had to swap indexes of
handler->data_sock
to make it working, I have no idea why above changes broke it, must be a serious flaw in my patch. Same for ERROR vs SYSERROR and syserror vs syserror_ret vs log_error. Not sure which one is correct in particular places.Finally, the result of
if_nametoindex
is not checked inlxc_delete_network_priv
, that looks a bit weird, and I haven't seen thislxc/src/lxc/network.c
Line 3655 in 8dd40b5
Here's the full patch:
The text was updated successfully, but these errors were encountered: