Skip to content

Commit

Permalink
add randomport feature to capability map
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Sep 27, 2023
1 parent b256f3a commit e703868
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions hscontrol/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func (m *Mapper) fullMapResponse(
peers,
m.baseDomain,
m.dnsCfg,
m.randomClientPort,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -329,6 +330,7 @@ func (m *Mapper) PeerChangedResponse(
changed,
m.baseDomain,
m.dnsCfg,
m.randomClientPort,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -515,7 +517,7 @@ func (m *Mapper) baseWithConfigMapResponse(
) (*tailcfg.MapResponse, error) {
resp := m.baseMapResponse()

tailnode, err := tailNode(node, m.capVer, pol, m.dnsCfg, m.baseDomain)
tailnode, err := tailNode(node, m.capVer, pol, m.dnsCfg, m.baseDomain, m.randomClientPort)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -569,6 +571,7 @@ func appendPeerChanges(
changed types.Nodes,
baseDomain string,
dnsCfg *tailcfg.DNSConfig,
randomClientPort bool,
) error {
fullChange := len(peers) == len(changed)

Expand Down Expand Up @@ -599,7 +602,7 @@ func appendPeerChanges(
peers,
)

tailPeers, err := tailNodes(changed, capVer, pol, dnsCfg, baseDomain)
tailPeers, err := tailNodes(changed, capVer, pol, dnsCfg, baseDomain, randomClientPort)
if err != nil {
return err
}
Expand Down
11 changes: 11 additions & 0 deletions hscontrol/mapper/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func tailNodes(
pol *policy.ACLPolicy,
dnsConfig *tailcfg.DNSConfig,
baseDomain string,
randomClientPort bool,
) ([]*tailcfg.Node, error) {
tNodes := make([]*tailcfg.Node, len(nodes))

Expand All @@ -29,6 +30,7 @@ func tailNodes(
pol,
dnsConfig,
baseDomain,
randomClientPort,
)
if err != nil {
return nil, err
Expand All @@ -48,6 +50,7 @@ func tailNode(
pol *policy.ACLPolicy,
dnsConfig *tailcfg.DNSConfig,
baseDomain string,
randomClientPort bool,
) (*tailcfg.Node, error) {
nodeKey, err := node.NodePublicKey()
if err != nil {
Expand Down Expand Up @@ -146,12 +149,20 @@ func tailNode(
tailcfg.CapabilityAdmin: []tailcfg.RawMessage{},
tailcfg.CapabilitySSH: []tailcfg.RawMessage{},
}

if randomClientPort {
tNode.CapMap[tailcfg.NodeAttrRandomizeClientPort] = []tailcfg.RawMessage{}
}
} else {
tNode.Capabilities = []tailcfg.NodeCapability{
tailcfg.CapabilityFileSharing,
tailcfg.CapabilityAdmin,
tailcfg.CapabilitySSH,
}

if randomClientPort {
tNode.Capabilities = append(tNode.Capabilities, tailcfg.NodeAttrRandomizeClientPort)
}
}

// - 72: 2023-08-23: TS-2023-006 UPnP issue fixed; UPnP can now be used again
Expand Down
1 change: 1 addition & 0 deletions hscontrol/mapper/tail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func TestTailNode(t *testing.T) {
tt.pol,
tt.dnsConfig,
tt.baseDomain,
false,
)

if (err != nil) != tt.wantErr {
Expand Down

0 comments on commit e703868

Please sign in to comment.