Skip to content

Commit

Permalink
chore: add missing netcheck report fields to netinfo (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanndickson authored Jul 2, 2024
1 parent 1ac63d3 commit 012f023
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
44 changes: 42 additions & 2 deletions tailcfg/tailcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,38 @@ type NetInfo struct {
// This should only be updated rarely, or when there's a
// material change, as any change here also gets uploaded to
// the control plane.
DERPLatency map[string]float64 `json:",omitempty"`
// Deprecated; use DERPLatencyV4 and DERPLatencyV6 instead.
DERPLatency map[string]float64 `json:",omitempty"`
DERPLatencyV4 map[int]float64 `json:",omitempty"`
DERPLatencyV6 map[int]float64 `json:",omitempty"`

// a UDP STUN round trip completed
UDP bool `json:",omitempty"`

// an IPv6 STUN round trip completed
IPv6 bool `json:",omitempty"`

// an IPv4 STUN round trip completed
IPv4 bool `json:",omitempty"`

// an IPv6 packet was able to be sent
IPv6CanSend bool `json:",omitempty"`

// an IPv4 packet was able to be sent
IPv4CanSend bool `json:",omitempty"`

// an ICMPv4 round trip completed
ICMPv4 bool

// ip:port of global IPv4
GlobalV4 string

// [ip]:port of global IPv6
GlobalV6 string

// CaptivePortal is set when we think there's a captive portal that is
// intercepting HTTP traffic.
CaptivePortal opt.Bool

// Update BasicallyEqual when adding fields.
}
Expand Down Expand Up @@ -793,7 +824,16 @@ func (ni *NetInfo) BasicallyEqual(ni2 *NetInfo) bool {
ni.PMP == ni2.PMP &&
ni.PCP == ni2.PCP &&
ni.PreferredDERP == ni2.PreferredDERP &&
ni.LinkType == ni2.LinkType
ni.LinkType == ni2.LinkType &&
ni.UDP == ni2.UDP &&
ni.IPv6 == ni2.IPv6 &&
ni.IPv4 == ni2.IPv4 &&
ni.IPv6CanSend == ni2.IPv6CanSend &&
ni.IPv4CanSend == ni2.IPv4CanSend &&
ni.ICMPv4 == ni2.ICMPv4 &&
ni.GlobalV4 == ni2.GlobalV4 &&
ni.GlobalV6 == ni2.GlobalV6 &&
ni.CaptivePortal == ni2.CaptivePortal
}

// Equal reports whether h and h2 are equal.
Expand Down
23 changes: 23 additions & 0 deletions tailcfg/tailcfg_clone.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion tailcfg/tailcfg_view.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions wgengine/magicsock/magicsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,11 +674,20 @@ func (c *Conn) updateNetInfo(ctx context.Context) (*netcheck.Report, error) {
PMP: report.PMP,
PCP: report.PCP,
HavePortMap: c.portMapper.HaveMapping(),
UDP: report.UDP,
IPv6: report.IPv6,
IPv4: report.IPv4,
IPv4CanSend: report.IPv4CanSend,
ICMPv4: report.ICMPv4,
GlobalV4: report.GlobalV4,
GlobalV6: report.GlobalV6,
}
for rid, d := range report.RegionV4Latency {
ni.DERPLatencyV4[rid] = d.Seconds()
ni.DERPLatency[fmt.Sprintf("%d-v4", rid)] = d.Seconds()
}
for rid, d := range report.RegionV6Latency {
ni.DERPLatencyV6[rid] = d.Seconds()
ni.DERPLatency[fmt.Sprintf("%d-v6", rid)] = d.Seconds()
}

Expand All @@ -687,6 +696,7 @@ func (c *Conn) updateNetInfo(ctx context.Context) (*netcheck.Report, error) {
ni.WorkingUDP.Set(report.UDP)
ni.WorkingICMPv4.Set(report.ICMPv4)
ni.PreferredDERP = report.PreferredDERP
ni.CaptivePortal = report.CaptivePortal

if ni.PreferredDERP == 0 {
// Perhaps UDP is blocked. Pick a deterministic but arbitrary
Expand Down

0 comments on commit 012f023

Please sign in to comment.