mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-23 01:11:40 +00:00
wgengine/magicsock: add an option to disable legacy peer handling.
Used in tests to ensure we're not relying on behavior we're going to remove eventually. Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
d456bfdc6d
commit
a2463e8948
@ -30,9 +30,16 @@ import (
|
|||||||
"tailscale.com/types/wgkey"
|
"tailscale.com/types/wgkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errNoDestinations = errors.New("magicsock: no destinations")
|
var (
|
||||||
|
errNoDestinations = errors.New("magicsock: no destinations")
|
||||||
|
errDisabled = errors.New("magicsock: legacy networking disabled")
|
||||||
|
)
|
||||||
|
|
||||||
func (c *Conn) createLegacyEndpointLocked(pk key.Public, addrs string) (conn.Endpoint, error) {
|
func (c *Conn) createLegacyEndpointLocked(pk key.Public, addrs string) (conn.Endpoint, error) {
|
||||||
|
if c.disableLegacy {
|
||||||
|
return nil, errDisabled
|
||||||
|
}
|
||||||
|
|
||||||
a := &addrSet{
|
a := &addrSet{
|
||||||
Logf: c.logf,
|
Logf: c.logf,
|
||||||
publicKey: pk,
|
publicKey: pk,
|
||||||
@ -78,6 +85,10 @@ func (c *Conn) createLegacyEndpointLocked(pk key.Public, addrs string) (conn.End
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) findLegacyEndpointLocked(ipp netaddr.IPPort, addr *net.UDPAddr, packet []byte) conn.Endpoint {
|
func (c *Conn) findLegacyEndpointLocked(ipp netaddr.IPPort, addr *net.UDPAddr, packet []byte) conn.Endpoint {
|
||||||
|
if c.disableLegacy {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Pre-disco: look up their addrSet.
|
// Pre-disco: look up their addrSet.
|
||||||
if as, ok := c.addrsByUDP[ipp]; ok {
|
if as, ok := c.addrsByUDP[ipp]; ok {
|
||||||
as.updateDst(addr)
|
as.updateDst(addr)
|
||||||
@ -139,6 +150,10 @@ func (c *Conn) resetAddrSetStatesLocked() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) sendAddrSet(b []byte, as *addrSet) error {
|
func (c *Conn) sendAddrSet(b []byte, as *addrSet) error {
|
||||||
|
if c.disableLegacy {
|
||||||
|
return errDisabled
|
||||||
|
}
|
||||||
|
|
||||||
var addrBuf [8]netaddr.IPPort
|
var addrBuf [8]netaddr.IPPort
|
||||||
dsts, roamAddr := as.appendDests(addrBuf[:0], b)
|
dsts, roamAddr := as.appendDests(addrBuf[:0], b)
|
||||||
|
|
||||||
|
@ -119,6 +119,7 @@ type Conn struct {
|
|||||||
packetListener nettype.PacketListener
|
packetListener nettype.PacketListener
|
||||||
noteRecvActivity func(tailcfg.DiscoKey) // or nil, see Options.NoteRecvActivity
|
noteRecvActivity func(tailcfg.DiscoKey) // or nil, see Options.NoteRecvActivity
|
||||||
simulatedNetwork bool
|
simulatedNetwork bool
|
||||||
|
disableLegacy bool
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
// No locking required to access these fields, either because
|
// No locking required to access these fields, either because
|
||||||
@ -382,6 +383,11 @@ type Options struct {
|
|||||||
// triggering macOS and Windows firwall dialog boxes during
|
// triggering macOS and Windows firwall dialog boxes during
|
||||||
// "go test").
|
// "go test").
|
||||||
SimulatedNetwork bool
|
SimulatedNetwork bool
|
||||||
|
|
||||||
|
// DisableLegacyNetworking disables legacy peer handling. When
|
||||||
|
// enabled, only active discovery-aware nodes will be able to
|
||||||
|
// communicate with Conn.
|
||||||
|
DisableLegacyNetworking bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Options) logf() logger.Logf {
|
func (o *Options) logf() logger.Logf {
|
||||||
@ -1600,7 +1606,9 @@ Top:
|
|||||||
c.logf("magicsock: DERP packet received from idle peer %v; created=%v", dm.src.ShortString(), ep != nil)
|
c.logf("magicsock: DERP packet received from idle peer %v; created=%v", dm.src.ShortString(), ep != nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !c.disableLegacy {
|
||||||
asEp = c.addrsByKey[dm.src]
|
asEp = c.addrsByKey[dm.src]
|
||||||
|
}
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
|
|
||||||
if discoEp != nil {
|
if discoEp != nil {
|
||||||
|
@ -1485,6 +1485,7 @@ func BenchmarkReceiveFrom(b *testing.B) {
|
|||||||
EndpointsFunc: func(eps []string) {
|
EndpointsFunc: func(eps []string) {
|
||||||
b.Logf("endpoints: %q", eps)
|
b.Logf("endpoints: %q", eps)
|
||||||
},
|
},
|
||||||
|
DisableLegacyNetworking: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user