Skip to content

Commit 41ab80f

Browse files
committed
review 2
1 parent 416b5ff commit 41ab80f

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

cli/cliui/agent.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,9 @@ func ConnDiagnostics(w io.Writer, d ConnDiags) {
377377

378378
if d.PingP2P {
379379
_, _ = fmt.Fprint(w, "✔ You are connected directly (p2p)\n")
380+
} else {
381+
_, _ = fmt.Fprint(w, "❗ You are connected via a DERP relay, not directly (p2p)\n")
380382
}
381-
_, _ = fmt.Fprint(w, "❗ You are connected via a DERP relay, not directly (p2p)\n")
382383

383384
if d.DisableDirect {
384385
_, _ = fmt.Fprint(w, "❗ Direct connections are disabled locally, by `--disable-direct` or `CODER_DISABLE_DIRECT`\n")

cli/cliutil/awscheck.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ func FetchAWSIPRanges(ctx context.Context, url string) (*AWSIPRanges, error) {
7171
if err != nil {
7272
return nil, xerrors.Errorf("parse ip prefix: %w", err)
7373
}
74+
if prefix.Addr().Is6() {
75+
return nil, xerrors.Errorf("ipv4 prefix contains ipv6 address: %s", p.Prefix)
76+
}
7477
out.V4 = append(out.V4, prefix)
7578
}
7679

@@ -79,6 +82,9 @@ func FetchAWSIPRanges(ctx context.Context, url string) (*AWSIPRanges, error) {
7982
if err != nil {
8083
return nil, xerrors.Errorf("parse ip prefix: %w", err)
8184
}
85+
if prefix.Addr().Is4() {
86+
return nil, xerrors.Errorf("ipv6 prefix contains ipv4 address: %s", p.Prefix)
87+
}
8288
out.V6 = append(out.V6, prefix)
8389
}
8490

cli/ping.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,17 @@ func (r *RootCmd) ping() *serpent.Command {
224224
}
225225

226226
func isAWSIP(awsRanges *cliutil.AWSIPRanges, ni *tailcfg.NetInfo) bool {
227-
checkIP := func(ipStr string) bool {
228-
ip, err := netip.ParseAddr(ipStr)
229-
return err == nil && awsRanges.CheckIP(ip)
227+
if ni.GlobalV4 != "" {
228+
ip, err := netip.ParseAddr(ni.GlobalV4)
229+
if err == nil && awsRanges.CheckIP(ip) {
230+
return true
231+
}
230232
}
231-
232-
return checkIP(ni.GlobalV4) || checkIP(ni.GlobalV6)
233+
if ni.GlobalV6 != "" {
234+
ip, err := netip.ParseAddr(ni.GlobalV6)
235+
if err == nil && awsRanges.CheckIP(ip) {
236+
return true
237+
}
238+
}
239+
return false
233240
}

0 commit comments

Comments
 (0)