netfilter: add raw table and no-op CT target for Istio DNS capture#12722
Merged
copybara-service[bot] merged 2 commits intomasterfrom Mar 31, 2026
Merged
netfilter: add raw table and no-op CT target for Istio DNS capture#12722copybara-service[bot] merged 2 commits intomasterfrom
copybara-service[bot] merged 2 commits intomasterfrom
Conversation
555eb07 to
08441de
Compare
Add the iptables `raw` table and a no-op `CT` (conntrack) target to gVisor's netfilter implementation. This enables Istio's istio-init container to successfully apply iptables rules when DNS capture is enabled (ISTIO_META_DNS_CAPTURE=true). When DNS capture is enabled, Istio generates iptables-restore input containing both `* nat` and `* raw` table sections. The raw table rules use `-j CT --zone N` for conntrack zone isolation. Previously, gVisor only implemented nat, mangle, and filter tables, causing iptables-restore to fail with "unable to initialize table 'raw'". Changes: - Add RawID to the TableID enum with default PREROUTING and OUTPUT hooks, matching Linux's raw table - Wire raw table into CheckPrerouting() and CheckOutput() as the first table checked (before mangle), matching Linux's hook order - Add EmptyRawTable() for SetEntries() to use when receiving rules - Add CTTarget as a no-op target that returns RuleAccept (gVisor's conntrack does not implement zones, but accepting the rules allows iptables-restore to succeed) - Add XTCTTargetInfoV0 ABI struct matching Linux's xt_ct_target_info - Register CT target maker for both IPv4 and IPv6 - Add C++ tests for raw table initial state and CT target revision The CT target is intentionally a no-op: it stores the zone value but does not modify conntrack behavior. DNS redirection still works via the nat table's REDIRECT rules. The lack of zone tracking may cause rare conntrack collisions but is acceptable for gVisor's use case. Fixes: #12685 Signed-off-by: amiralavi7@gmail.com
08441de to
09c6ead
Compare
PiperOrigin-RevId: 892481181
09c6ead to
d8c35ef
Compare
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.
netfilter: add raw table and no-op CT target for Istio DNS capture
Summary
Add the iptables
rawtable and a no-opCT(conntrack zone) target to gVisor's netfilter implementation. This enables Istio'sistio-initcontainer to apply iptables rules when DNS capture is enabled (ISTIO_META_DNS_CAPTURE=true).Problem
When Istio DNS capture is enabled,
istio-iptablesgeneratesiptables-restoreinput containing both* natand* rawtable sections. Therawtable rules use-j CT --zone Ntargets for conntrack zone isolation between Envoy's DNS queries and application DNS queries. gVisor previously only implementednat,mangle, andfiltertables, causingiptables-restoreto fail with:This blocks Istio service mesh adoption on gVisor when DNS capture is required.
Approach
Raw table: Added as a new
TableID(RawID) withPREROUTINGandOUTPUThooks, matching the Linux kernel's raw table. Wired intoCheckPrerouting()andCheckOutput()as the first table checked (before mangle), matching Linux's netfilter hook priority ordering:CT target: Implemented as a no-op that accepts packets without modifying conntrack behavior. The target parses the
xt_ct_target_info(revision 0) struct from userspace, stores the zone value, but does not apply zone-based conntrack isolation. This is intentional:nattable'sREDIRECTrules to port 15053How Linux and other runtimes handle this:
rawtable withCT --zonesupport vianf_conntrack_zonesChanges
pkg/tcpip/stack/iptables.go: AddRawIDtoTableIDenum,EmptyRawTable(), default table entries for IPv4/IPv6, wire intoCheckPrerouting()andCheckOutput()pkg/tcpip/stack/iptables_targets.go: AddCTTargetstruct with no-opAction()returningRuleAcceptpkg/abi/linux/netfilter.go: AddXTCTTargetInfoV0ABI struct (72 bytes) matching Linux'sxt_ct_target_infopkg/sentry/socket/netfilter/netfilter.go: Registerrawtable innameToID,SetEntries, andDefaultLinuxTablespkg/sentry/socket/netfilter/ct_target.go: New file —ctTargetwrapper andctTargetMakerwith marshal/unmarshalpkg/sentry/socket/netfilter/targets.go: RegisterctTargetMakerfor IPv4 and IPv6pkg/sentry/socket/netfilter/BUILD: Addct_target.goto srcstest/syscalls/linux/iptables.cc: AddRawTableInitialStatetest (gVisor-only) andCTTargetGetRevisiontestTesting
RawTableInitialState: VerifiesIPT_SO_GET_INFOfor the "raw" table returns correctvalid_hooks(PREROUTING + OUTPUT),num_entries(3), and entry sizesCTTargetGetRevision: VerifiesIPT_SO_GET_REVISION_TARGETfor "CT" target revision 0 succeedsrunscwith this change (plus fix(setsockopt): increase maxOptLen from 8KB to 32KB #12686), deployed to an aarch64 node, and verified Istioistio-initwithISTIO_META_DNS_CAPTURE=truecompletes successfully — the fulliptables-restoreinput including both* natand* rawsections is applied without errorRelated
FUTURE_COPYBARA_INTEGRATE_REVIEW=#12688 from a7i:fix/raw-table-ct-target 7c0fde8