Tsi: handle protocol field to make DGRAM+ICMP ping work #690
Draft
mtjhrc wants to merge 5 commits into
Draft
Conversation
Read the protocol field from TsiProxyCreate (backward compatible — old guests that don't send it get 0, treated as default/UDP). When protocol is IPPROTO_ICMP or IPPROTO_ICMPV6, create a ping socket (SOCK_DGRAM + IPPROTO_ICMP) on the host instead of a plain UDP socket. This enables rootless ping through TSI. Only works for ping implementations using SOCK_DGRAM ping sockets (iputils on Fedora, Ubuntu, etc.). SOCK_RAW-based ping (busybox, alpine) is not supported as TSI only hijacks SOCK_STREAM and SOCK_DGRAM. Assisted-by: OpenCode:claude-opus-4.6 Signed-off-by: Matej Hrica <mhrica@redhat.com>
Tests that need real network connectivity (e.g. external ping) can return true from needs_host_network() to skip the unshare --net namespace isolation automatically. Assisted-by: OpenCode:claude-opus-4.6 Signed-off-by: Matej Hrica <mhrica@redhat.com>
Run Fedora's /usr/bin/ping against 8.8.8.8 from inside the guest to verify SOCK_DGRAM+IPPROTO_ICMP is properly proxied through TSI. Uses needs_host_network() since the test requires real connectivity. Assisted-by: OpenCode:claude-opus-4.6 Signed-off-by: Matej Hrica <mhrica@redhat.com>
Set /proc/sys/net/ipv4/ping_group_range to allow all GIDs when TSI is enabled. Without this, the guest kernel rejects SOCK_DGRAM + IPPROTO_ICMP sockets with EACCES, preventing TSI from hijacking them. Assisted-by: OpenCode:claude-opus-4.6 Signed-off-by: Matej Hrica <mhrica@redhat.com>
macOS DGRAM ICMP sockets include the IP header in recv, unlike Linux which strips it. Detect this and remove the IP header before forwarding to the guest so the guest sees the same format as a Linux ping socket. Assisted-by: OpenCode:claude-opus-4.6 Signed-off-by: Matej Hrica <mhrica@redhat.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three things were missing for ping to work through TSI:
Host used to create UDP sockets instead of ICMP — now reads the protocol field from the guest - needs tsi: forward protocol field in proxy create enabling DGRAM+ICMP ping libkrunfw#127
Guest used to reject SOCK_DGRAM+ICMP with EACCES — init now sets ping_group_range
macOS host includes the IP header in ICMP recv — we need to strip it before forwarding to guest
NOTE: This only works with modern ping implementations using DGRAM+ICMP "ping" sockets ( works on modern Fedora, Ubuntu). Busybox ping uses SOCK_RAW which TSI doesn't hijack.