Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions core/internal/engine/dns_flow_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
25 changes: 25 additions & 0 deletions core/internal/engine/outbound_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"sync/atomic"
"testing"
"time"

"github.com/mistgate/mistgate-client/core/internal/profile"
)

type countOutbound struct {
Expand Down Expand Up @@ -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)
}
}
}
9 changes: 8 additions & 1 deletion core/internal/engine/real_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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() })
}
Loading