Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable ipv4 forwarding for docker managed bridge #1722

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bencord0
Copy link

When enabling packet forwarding for a bridge managed by docker, set the sysctl for the bridge.

The previous behaviour would set the forwarding flag for the global default. This patch unifies the behaviour between ipv4 and ipv6, since the ipv4 code path to set the forwarding behaviour explicitly for the bridge being managed.


Context: I can't find any design documents or tests around this area for what the expected behaviour is supposed to be. However, for me I see the following behaviour.

Using docker 17.04.0 with flannel 0.6.2 in host-gw mode ( {"Network": "10.0.0.0/16", "Backend": {"Type": "host-gw"}})

Docker is started (via systemd) using the following resulting command line.
/usr/bin/dockerd -H fd:// --bip=10.0.80.1/24 --ip-masq=true --mtu=1500

Start a container and grab it's IPAddress
docker inspect $(docker run -d nginx)|grep IPAddress

From another host (that is part of the flannel network, and has it's routes setup correctly)
ping $IPADDRESS or curl $IPADDRESS.

Expected results:
I can successfully ping/curl the container from another host.

Actual results:
The IP packets are for forwarded from the host interface, enp1s0, through to the docker0 interface. Using tcpdump, I can follow the packets entering the host's network interface (enp1s0 -> docker0), but response packets are not forwarded back (docker0 -> enp1s0).

This can be verified with
cat /proc/sys/net/ipv4/conf/docker0/forwarding -> 0


With this patch packet forwarding can be enabled after taking into account https://github.com/docker/libnetwork/blob/4dd9c0603ab3c0cf34e165f9678511c18b4f4f17/drivers/bridge/bridge.go#L756

/usr/bin/dockerd -H fd:// --bip=10.0.80.1/24 --ip-masq=true --mtu=1500 --icc=false

Now, forwarding is enabled.
cat /proc/sys/net/ipv4/conf/docker0/forwarding -> 1
and I can ping/curl the container from another host.

@bencord0 bencord0 force-pushed the bridge_forwarding branch from d82374a to d4e314b Compare April 17, 2017 14:36
@bencord0
Copy link
Author

You can also replicate the test without needing a second host using the -I (capital i) flag to ping.
e.g. ping -I enp1s0 $IPADDRESS

@bencord0
Copy link
Author

bencord0 commented Jan 8, 2018

flannel-io/flannel#872 May be of interest as an alternative workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants