diff --git a/core/internal/engine/dns_flow_windows_test.go b/core/internal/engine/dns_flow_windows_test.go index e74c76e..bfd466e 100644 --- a/core/internal/engine/dns_flow_windows_test.go +++ b/core/internal/engine/dns_flow_windows_test.go @@ -303,3 +303,28 @@ func TestUDPFlowWithoutRegionalResolverUsesTheVPN(t *testing.T) { t.Fatal("a direct flow was opened without a resolver") } } + +// A name that goes through a VPN without IPv6 gets no IPv6 addresses: AAAA is answered here with no data, A goes on. +func TestUDPFlowAnswersAAAAWithNoDataWhenTheVPNHasNoIPv6(t *testing.T) { + rig := newDNSRig(t, func(string) (bool, netip.AddrPort) { return false, netip.AddrPort{} }) + rig.flow.noVPN6 = func() bool { return true } + rig.ask(t, dnsQuery(t, 0x0C0D, "site.example", dnsmessage.TypeAAAA, dnsmessage.ClassINET)) + var parser dnsmessage.Parser + header, err := parser.Start(rig.heard(t)) + if err != nil || header.ID != 0x0C0D || !header.Response || header.RCode != dnsmessage.RCodeSuccess { + t.Fatalf("answer header = %+v, %v", header, err) + } + if err := parser.SkipAllQuestions(); err != nil { + t.Fatal(err) + } + if _, err := parser.AnswerHeader(); err != dnsmessage.ErrSectionDone { + t.Fatalf("the answer has a record: %v", err) + } + nothingSent(t, rig.vpn) + + query := dnsQuery(t, 0x0C0E, "site.example", dnsmessage.TypeA, dnsmessage.ClassINET) + rig.ask(t, query) + if got, _ := recvPacket(t, rig.vpn); string(got) != string(query) { + t.Fatal("the A question did not go through the VPN") + } +} diff --git a/core/internal/engine/outbound_windows_test.go b/core/internal/engine/outbound_windows_test.go index 9a09684..bf984ca 100644 --- a/core/internal/engine/outbound_windows_test.go +++ b/core/internal/engine/outbound_windows_test.go @@ -9,6 +9,8 @@ import ( "sync/atomic" "testing" "time" + + "github.com/mistgate/mistgate-client/core/internal/profile" ) type countOutbound struct { @@ -190,3 +192,26 @@ func TestIPv6IntoAVPNWithoutIPv6IsADeadEnd(t *testing.T) { } } } + +// An AmneziaWG path whose panel says no IPv6 leaves runs behind the forwarder, which turns IPv6 away; otherwise only +// the other reasons put it there. +func TestAWGStackForAPathWithoutIPv6(t *testing.T) { + v4 := &profile.AWG{Addresses: []netip.Prefix{netip.MustParsePrefix("192.0.2.2/32")}} + v6 := &profile.AWG{Addresses: []netip.Prefix{netip.MustParsePrefix("192.0.2.2/32"), netip.MustParsePrefix("2001:db8::2/128")}} + for _, c := range []struct { + name string + forwarder bool + p profile.Profile + want bool + }{ + {"IPv4 only, IPv6 allowed", false, profile.Profile{AWG: v4}, false}, + {"IPv4 only, no IPv6 egress", false, profile.Profile{AWG: v4, NoIPv6: true}, true}, + {"IPv6 address", false, profile.Profile{AWG: v6}, true}, + {"ad block", false, profile.Profile{AWG: v4, PanelBlockAds: true}, true}, + {"smart routing", true, profile.Profile{AWG: v4}, true}, + } { + if got := awgNeedsStack(c.forwarder, c.p); got != c.want { + t.Errorf("%s: awgNeedsStack = %v, want %v", c.name, got, c.want) + } + } +} diff --git a/core/internal/engine/real_windows.go b/core/internal/engine/real_windows.go index 9a909c8..8371151 100644 --- a/core/internal/engine/real_windows.go +++ b/core/internal/engine/real_windows.go @@ -782,7 +782,9 @@ func (r *Real) Start(ctx context.Context, target Target, report func(Step)) (inf // send IPv6 into a path that carries nothing, and an app without an IPv4 fallback would hang. // ponytail: costs the second stack's throughput; a probe on the plain adapter that drops its IPv6 route if this shows. // The panel's ad block lives in the forwarder too: only its DNS answers can drop a name, the plain adapter has none. - awgStack = useForwarder || selected.PanelBlockAds || slices.ContainsFunc(selected.AWG.Addresses, func(a netip.Prefix) bool { return a.Addr().Is6() }) + // So does a path the panel says carries no IPv6: only the forwarder answers its AAAA with no data and turns IPv6 + // flows away; on the plain adapter they would run into the allowed ::/0 and wait. + awgStack = awgNeedsStack(useForwarder, selected) if awgStack { // ponytail: two stacks in a row cost throughput; a packet-level split would be faster. addresses := make([]netip.Addr, 0, len(selected.AWG.Addresses)) @@ -1985,3 +1987,8 @@ func awgHandshakeSeen(text, serverKey string) bool { } return false } + +// awgNeedsStack says whether an AmneziaWG path runs its own stack behind the forwarder instead of on the plain adapter. +func awgNeedsStack(useForwarder bool, p profile.Profile) bool { + return useForwarder || p.PanelBlockAds || p.NoIPv6 || slices.ContainsFunc(p.AWG.Addresses, func(a netip.Prefix) bool { return a.Addr().Is6() }) +}