cmd/tailscale/cli,ipn,all: make peer relay server port a *uint16
In preparation for exposing its configuration via ipn.ConfigVAlpha,
change {Masked}Prefs.RelayServerPort from *int to *uint16. This takes a
defensive stance against invalid inputs at JSON decode time.
'tailscale set --relay-server-port' is currently the only input to this
pref, and has always sanitized input to fit within a uint16.
Updates tailscale/corp#34591
Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
committed by
Jordan Whited
parent
53476ce872
commit
824027305a
+1
-1
@@ -102,7 +102,7 @@ var _PrefsCloneNeedsRegeneration = Prefs(struct {
|
||||
PostureChecking bool
|
||||
NetfilterKind string
|
||||
DriveShares []*drive.Share
|
||||
RelayServerPort *int
|
||||
RelayServerPort *uint16
|
||||
RelayServerStaticEndpoints []netip.AddrPort
|
||||
AllowSingleHosts marshalAsTrueInJSON
|
||||
Persist *persist.Persist
|
||||
|
||||
+3
-5
@@ -441,10 +441,8 @@ func (v PrefsView) DriveShares() views.SliceView[*drive.Share, drive.ShareView]
|
||||
// RelayServerPort is the UDP port number for the relay server to bind to,
|
||||
// on all interfaces. A non-nil zero value signifies a random unused port
|
||||
// should be used. A nil value signifies relay server functionality
|
||||
// should be disabled. This field is currently experimental, and therefore
|
||||
// no guarantees are made about its current naming and functionality when
|
||||
// non-nil/enabled.
|
||||
func (v PrefsView) RelayServerPort() views.ValuePointer[int] {
|
||||
// should be disabled.
|
||||
func (v PrefsView) RelayServerPort() views.ValuePointer[uint16] {
|
||||
return views.ValuePointerOf(v.ж.RelayServerPort)
|
||||
}
|
||||
|
||||
@@ -506,7 +504,7 @@ var _PrefsViewNeedsRegeneration = Prefs(struct {
|
||||
PostureChecking bool
|
||||
NetfilterKind string
|
||||
DriveShares []*drive.Share
|
||||
RelayServerPort *int
|
||||
RelayServerPort *uint16
|
||||
RelayServerStaticEndpoints []netip.AddrPort
|
||||
AllowSingleHosts marshalAsTrueInJSON
|
||||
Persist *persist.Persist
|
||||
|
||||
+4
-6
@@ -283,10 +283,8 @@ type Prefs struct {
|
||||
// RelayServerPort is the UDP port number for the relay server to bind to,
|
||||
// on all interfaces. A non-nil zero value signifies a random unused port
|
||||
// should be used. A nil value signifies relay server functionality
|
||||
// should be disabled. This field is currently experimental, and therefore
|
||||
// no guarantees are made about its current naming and functionality when
|
||||
// non-nil/enabled.
|
||||
RelayServerPort *int `json:",omitempty"`
|
||||
// should be disabled.
|
||||
RelayServerPort *uint16 `json:",omitempty"`
|
||||
|
||||
// RelayServerStaticEndpoints are static IP:port endpoints to advertise as
|
||||
// candidates for relay connections. Only relevant when RelayServerPort is
|
||||
@@ -694,7 +692,7 @@ func (p *Prefs) Equals(p2 *Prefs) bool {
|
||||
p.PostureChecking == p2.PostureChecking &&
|
||||
slices.EqualFunc(p.DriveShares, p2.DriveShares, drive.SharesEqual) &&
|
||||
p.NetfilterKind == p2.NetfilterKind &&
|
||||
compareIntPtrs(p.RelayServerPort, p2.RelayServerPort) &&
|
||||
compareUint16Ptrs(p.RelayServerPort, p2.RelayServerPort) &&
|
||||
slices.Equal(p.RelayServerStaticEndpoints, p2.RelayServerStaticEndpoints)
|
||||
}
|
||||
|
||||
@@ -715,7 +713,7 @@ func (ap AppConnectorPrefs) Pretty() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func compareIntPtrs(a, b *int) bool {
|
||||
func compareUint16Ptrs(a, b *uint16) bool {
|
||||
if (a == nil) != (b == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ func TestPrefsEqual(t *testing.T) {
|
||||
have, prefsHandles)
|
||||
}
|
||||
|
||||
relayServerPort := func(port int) *int {
|
||||
relayServerPort := func(port uint16) *uint16 {
|
||||
return &port
|
||||
}
|
||||
nets := func(strs ...string) (ns []netip.Prefix) {
|
||||
|
||||
Reference in New Issue
Block a user