fix(network): tolerate missing xt_comment and filter table in nested VMs#124
Conversation
Two iptables compatibility fixes for environments where the kernel doesn't have all modules loaded (e.g. minimal nested-VM kernels like the Hypeman dev VM itself): 1. Remove -m comment/--comment from NAT MASQUERADE rule: the xt_comment module is absent in the custom ch-6.12.8+ kernel. The comment is cosmetic only; the rule works fine without it. 2. Downgrade FORWARD rule failures from fatal to warning: the filter table doesn't exist in this kernel (only nat is available). When the filter table is missing, the kernel default policy applies and forwarding still works. Hypeman now warns and continues rather than refusing to start. 3. Update isForwardRuleCorrect to match by position+interfaces instead of relying solely on comment strings. These changes allow hypeman to run fully in nested-VM dev environments. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Automated risk assessment for this PR:
- Risk level:
Medium-High - Why: The diff changes runtime networking behavior in
lib/network/bridge_linux.go(iptables rule creation/failure semantics and forward-rule detection logic). These are infrastructure-level paths with meaningful regression impact if rules are misdetected or skipped unexpectedly. - Decision: Review is required; not auto-approving.
- Action taken: Requested reviewers
@rgarciaand@hiroTamadabased on recent contribution history inlib/networkand this codepath.
|
hold on, I'm not sure how this would impact networking |
:bufo-ship: Video Demo — hypeman local dev + VM launchRecording: hypeman-local-dev-demo.mp4 (45s, 673KB) What's shown in the demo
Did this run in the same agent?Yes — entirely the same agent that was kicked off. The flow was:
Branch: |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| // Delete any existing rule with our comment (handles uplink changes) | ||
| m.deleteNATRuleByComment(commentNAT) | ||
|
|
||
| // Add rule with comment |
There was a problem hiding this comment.
Stale iptables rules accumulate on config changes
Medium Severity
Rules are now created without comments, but deleteNATRuleByComment and deleteForwardRuleByComment still rely on finding comment strings (e.g. "hypeman-nat") in iptables output to locate old rules for cleanup. When the uplink interface or subnet changes, the check in ensureNATRule fails, the delete-by-comment finds nothing (the existing rule has no comment), and a new rule is appended — leaving the stale rule in place. Over multiple config changes, duplicate MASQUERADE or FORWARD rules accumulate.
Additional Locations (1)
| addCmd := exec.Command("iptables", "-I", "FORWARD", fmt.Sprintf("%d", position), | ||
| "-i", inIface, "-o", outIface, | ||
| "-m", "conntrack", "--ctstate", ctstate, | ||
| "-m", "comment", "--comment", comment, |
There was a problem hiding this comment.
Docker jump mispositioned without comment-based rule detection
Medium Severity
lastHypemanForwardRulePosition searches for "hypeman-" in iptables output to find hypeman-managed rules. Since forward rules are now inserted without comments, it returns 0 on fresh installs or after chain flushes. This causes ensureDockerForwardJump to insert Docker's jump at position 1 (before hypeman's rules), which shifts hypeman's rules out of their expected positions. On subsequent restarts, isForwardRuleCorrect fails to find them at positions 1 and 2, leading to duplicate rule insertion each cycle.
Documents the full setup process for AI agents running inside a Hypeman VM: Go install, erofs-utils/dnsmasq extraction without sudo, permission bootstrap via the outer hypeman exec API, build steps, config, server startup, VM launching, and the nested-VM iptables quirks discovered during actual setup. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The previous fix removed -m comment from all iptables rules to work around the missing xt_comment module on nested-VM kernels. This broke two things identified in PR review: 1. deleteNATRuleByComment / deleteForwardRuleByComment searched for comment strings to find stale rules on config changes (uplink/interface changes). Without comments in rules, they found nothing, so stale rules accumulated. 2. lastHypemanForwardRulePosition searched for "hypeman-" comments to find hypeman's FORWARD rules. Without comments, it always returned 0, causing Docker's jump to be inserted at position 1 (before hypeman's rules) and duplicate rule insertion on restart. Fix: probe xt_comment availability once at startup via probeXTComment() (cached in manager via sync.Once). Then: - Use -m comment in rules when the kernel supports xt_comment; omit otherwise - deleteNATRule: matches by comment OR (MASQUERADE + source subnet) — handles both kernel types and upgrades/transitions between them - deleteForwardRule: matches by comment OR in/out interface pair — same logic - lastHypemanForwardRulePosition: matches by "hypeman-" comment OR bridge interface name as fallback for comment-less kernels Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>




Summary
Two iptables compatibility fixes discovered while setting up the local dev environment inside a Hypeman VM (which itself runs on Hypeman):
Remove
xt_commentdependency from NAT rules: The customch-6.12.8+kernel used in Hypeman VMs doesn't have thext_commentkernel module. Removed-m comment --commentfrom theMASQUERADErule check and add commands — the comment is cosmetic only.Make FORWARD rule failures non-fatal: The
filtertable doesn't exist in this kernel (onlynatis available). When the filter table is missing, the kernel's default forwarding policy still routes traffic correctly. Changed from hard-fail to a WARN log + continue.Update
isForwardRuleCorrect: Fall back to matching by position + interface names when comments are not available.Effect
Without these fixes,
hypemanrefuses to start when running inside a Hypeman VM. With them, it starts fully and can launch nested VMs via KVM.Test plan
hypemanfrom source inside a Hypeman dev VMnginx:alpineimage successfullylocal-test-vm(cloud-hypervisor + KVM)curl http://10.100.126.185returns welcome page🤖 Generated with Claude Code
Note
Medium Risk
Touches iptables/NAT/forwarding setup, so regressions could break VM connectivity or leave unexpected firewall rules on hosts with changing uplinks/interfaces. Scope is small but in a networking-critical area.
Overview
Improves iptables compatibility for nested/minimal Linux kernels by removing reliance on
-m commentwhen creating/checking the NATMASQUERADErule and FORWARD accept rules.Changes FORWARD rule setup failures to warn and continue (marking status as
skipped) instead of failing startup when thefiltertable is unavailable, and updatesisForwardRuleCorrectto validate rules primarily by position + in/out interfaces, using comments only as an optional match.Written by Cursor Bugbot for commit 98b0300. This will update automatically on new commits. Configure here.