Skip to content

Tsi: handle protocol field to make DGRAM+ICMP ping work #690

Draft
mtjhrc wants to merge 5 commits into
containers:mainfrom
mtjhrc:tsi-icmp-ping
Draft

Tsi: handle protocol field to make DGRAM+ICMP ping work #690
mtjhrc wants to merge 5 commits into
containers:mainfrom
mtjhrc:tsi-icmp-ping

Conversation

@mtjhrc
Copy link
Copy Markdown
Collaborator

@mtjhrc mtjhrc commented May 21, 2026

Three things were missing for ping to work through TSI:

  1. 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

  2. Guest used to reject SOCK_DGRAM+ICMP with EACCES — init now sets ping_group_range

  3. 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.

mtjhrc added 5 commits May 21, 2026 17:58
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant