jpetazzo / pipework

Software-Defined Networking tools for LXC (LinuX Containers)
Apache License 2.0
4.21k stars 727 forks source link

have --wait also wait until interface is up #243

Closed laf0rge closed 5 months ago

laf0rge commented 3 years ago

I'm using pipework in automatic tests seups that realted to test suites executing on top of Linux HDLC net-devices. Pipework is used in a jenkins job to move those HDLC interfaces into docker containers that then run tests.

As somehow the netdev looses its configuration (state up/down, HDLC sub-protocol, ...) moving the interface to the containers is done as follows:

ip link set "$NETDEV" netns "$DOCKER_PID"
ip netns exec "$DOCKER_PID" sethdlc "$NETDEV" fr lmi none
ip netns exec "$DOCKER_PID" ip link set "$NETDEV" up

(which by the way pipework cannot do as it is Ethernet/IP-centric and has the assumption that all network devices have IP on top, but this is not the topic here)

From within the docker container (target netns), I use /usr/bin/pipework --wait -i ${WAIT_FOR_NETDEV}

However, when the application (using AF_PACKET sockets) wants to use the device, there is a race condition with the "ip link set up". So the application might get started before the device is up -> failure.

I think it would be great if pipework could not only wait for the device to exist, but also check if it was up. I'm right now doing this with an external script by checking /sys/class/net/${WAIT_FOR_NETDEV}/operstate but of course one could also parse the output of ip link, like pipework does.

I think this feature might be interesting to other use cases, too. After all, what matters is if the device is usable, not just if i t exists.

jpetazzo commented 3 years ago

Hi Harald!

At the moment, --wait checks if /sys/class/net/$CONTAINER_IFNAME/carrier exists (here), and falls back on ip link for compatibility with prehistoric kernels.

We could of course tweak that logic; but I'm a bit worried of breaking other folks' setups, because I know that some folks are waiting for the interface to exist, but then complete the interface setup in the container itself.

Let me know if you have a suggestion that would work for you, while limiting the risk for other users?

Also - note that I'm not actively maintaining pipework anymore, so I try to stick to very small, easy to review PRs. Lots of folks have preferred to work with their own fork (after all, it's just a few hundreds line of shell.

Thank you!