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

wireguard: Set wireguard and route MTU to detected MTU #16020

Merged
merged 1 commit into from May 10, 2021

Conversation

joamaki
Copy link
Contributor

@joamaki joamaki commented May 5, 2021

For more optimal packet sizes in large MTU setups, set the
cilium_wg0 MTU based on the detected MTU minus overhead.

Additionally set the route MTU on container side to detected
MTU minus wireguard overhead when wireguard is enabled.

Tested manually with "--mtu 1400", causing cilium_wg0 and
route MTU to be set to 1320.

@joamaki joamaki added the release-note/minor This PR changes functionality that users may find relevant to operating Cilium. label May 5, 2021
@joamaki joamaki requested a review from brb May 5, 2021 09:38
@joamaki joamaki mentioned this pull request May 5, 2021
24 tasks
// wireguardOverhead is an approximation for the overhead of wireguard
// encapsulation.
//
// https://github.com/torvalds/linux/blob/master/drivers/net/wireguard/device.c#L262:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe you could pin the URL to a specific tag, e.g. 5.12.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -134,6 +146,12 @@ func (a *Agent) Init() error {
return err
}

linkMTU := mtuConfig.GetDeviceMTU() - wireguardOverhead
if err := netlink.LinkSetMTU(link, linkMTU); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not enough. We need to make sure that route MTU in pod netns is set accordingly (MTU minus the WG overhead), grep for GetRouteMTU. Maybe this is exactly the same what you went in:

Should pkg/mtu be refactored so that the overhead computation works for both IPsec and Wireguard?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep you're right. The route MTU was set too high. Modified pkg/mtu to handle the wireguard case. That package needs a rewrite soon, but as discussed with @brb this will be addressed in v1.11 anyway, so not worth addressing that now.

@joamaki joamaki force-pushed the jussi/pr/set-wireguard-mtu branch from e57aa86 to 21680e5 Compare May 5, 2021 12:59
@joamaki joamaki marked this pull request as ready for review May 5, 2021 14:41
@joamaki joamaki requested review from a team May 5, 2021 14:41
@joamaki joamaki requested a review from a team as a code owner May 5, 2021 14:41
@joamaki joamaki requested a review from aanm May 5, 2021 14:41
@joamaki
Copy link
Contributor Author

joamaki commented May 5, 2021

test-me-please

@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.10.0-rc2 May 5, 2021
@joamaki joamaki force-pushed the jussi/pr/set-wireguard-mtu branch from 21680e5 to 957f95f Compare May 5, 2021 17:07
@joamaki joamaki changed the title wireguard: Set wireguard device MTU to detected route MTU wireguard: Set wireguard and route MTU to detected MTU May 5, 2021
Copy link
Member

@joestringer joestringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I briefly glanced through, looks right to me - adjust route MTU by wireguard if that mode is configured, and set the wireguard interface MTU based on native device MTU minus wireguard overhead.

I assume we don't support wireguard + tunneling today (otherwise there'd be some extra changes lower in GetRouteMTU() where the encrypt+ipsec cases are handled).

@joamaki
Copy link
Contributor Author

joamaki commented May 6, 2021

test-runtime

@joamaki
Copy link
Contributor Author

joamaki commented May 6, 2021

test-net-next

Copy link
Member

@brb brb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks.

One question: have you tested that ping -c1 -s 1412 $REMOTE_POD_IP doesn't get fragmented, while ping -c1 -s 1413 $REMOTE_POD_IP does? -s 1412 because +8 for ICMP hdr.

encapEnabled bool
encryptEnabled bool
encapEnabled bool
encryptEnabled bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a follow up we should probably s/encryptEnabled/ipsecEnabled.

@brb
Copy link
Member

brb commented May 6, 2021

assume we don't support wireguard + tunneling today (otherwise there'd be some extra changes lower in GetRouteMTU() where the encrypt+ipsec cases are handled).

@joestringer We do, just that in the case of tunneling pod2pod traffic goes only via the wg tunnel, so it's encapsulated only once (#15716 (comment)).

@joamaki
Copy link
Contributor Author

joamaki commented May 6, 2021

Looks good, thanks.

One question: have you tested that ping -c1 -s 1412 $REMOTE_POD_IP doesn't get fragmented, while ping -c1 -s 1413 $REMOTE_POD_IP does? -s 1412 because +8 for ICMP hdr.

Yep, fragments as expected. Though there's odd issue with small fragments getting dropped. Not related to this issue though so I'll debug and fix that separately if I can.

EDIT: Figured out the cause. Documented here: #16036.

@joamaki
Copy link
Contributor Author

joamaki commented May 6, 2021

test-1.21-4.9

@joamaki
Copy link
Contributor Author

joamaki commented May 6, 2021

test-net-next

For more optimal packet sizes in large MTU setups, set the
cilium_wg0 MTU based on the detected MTU minus overhead.

Additionally set the route MTU on container side to detected
MTU minus wireguard overhead when wireguard is enabled.

Tested manually with "--mtu 1400", causing cilium_wg0 and
route MTU to be set to 1320.

Signed-off-by: Jussi Maki <jussi@isovalent.com>
@joamaki joamaki force-pushed the jussi/pr/set-wireguard-mtu branch from 957f95f to 5951163 Compare May 6, 2021 15:30
@brb
Copy link
Member

brb commented May 7, 2021

test-net-next

@joamaki joamaki added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label May 10, 2021
@ti-mo ti-mo merged commit 6ae08fd into cilium:master May 10, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from master to Backport pending to v1.10 in 1.10.0-rc2 May 12, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from master to Backport pending to v1.10 in 1.10.0-rc2 May 12, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.10 to Backport done to v1.10 in 1.10.0-rc2 May 13, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.10 to Backport done to v1.10 in 1.10.0-rc2 May 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/minor This PR changes functionality that users may find relevant to operating Cilium.
Projects
No open projects
1.10.0-rc2
Backport done to v1.10
Development

Successfully merging this pull request may close these issues.

None yet

7 participants