portmapper

package
v1.14.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2021 License: BSD-3-Clause Imports: 24 Imported by: 15

Documentation

Overview

Package portmapper is a UDP port mapping client. It currently allows for mapping over NAT-PMP, UPnP, and PCP.

Index

Constants

This section is empty.

Variables

View Source
var (
	VerboseLogs bool

	DisableUPnP bool
	DisablePMP  bool
	DisablePCP  bool
)

Debug knobs for "tailscaled debug --portmap".

View Source
var (
	ErrNoPortMappingServices = errors.New("no port mapping services were found")
	ErrGatewayRange          = errors.New("skipping portmap; gateway range likely lacks support")
)

Functions

func IsNoMappingError

func IsNoMappingError(err error) bool

IsNoMappingError reports whether err is of type NoMappingError.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a port mapping client.

func NewClient

func NewClient(logf logger.Logf, onChange func()) *Client

NewClient returns a new portmapping client.

The optional onChange argument specifies a func to run in a new goroutine whenever the port mapping status has changed. If nil, it doesn't make a callback.

func (*Client) Close

func (c *Client) Close() error

func (*Client) GetCachedMappingOrStartCreatingOne added in v1.12.0

func (c *Client) GetCachedMappingOrStartCreatingOne() (external netaddr.IPPort, ok bool)

GetCachedMappingOrStartCreatingOne quickly returns with our current cached portmapping, if any. If there's not one, it starts up a background goroutine to create one. If the background goroutine ends up creating one, the onChange hook registered with the NewClient constructor (if any) will fire.

func (*Client) HaveMapping

func (c *Client) HaveMapping() bool

HaveMapping reports whether we have a current valid mapping.

func (*Client) NoteNetworkDown

func (c *Client) NoteNetworkDown()

NoteNetworkDown should be called when the network has transitioned to a down state. It's too late to release port mappings at this point (the user might've just turned off their wifi), but we can make sure we invalidate mappings for later when the network comes back.

func (*Client) Probe

func (c *Client) Probe(ctx context.Context) (res ProbeResult, err error)

Probe returns a summary of which port mapping services are available on the network.

If a probe has run recently and there haven't been any network changes since, the returned result might be server from the Client's cache, without sending any network traffic.

func (*Client) SetGatewayLookupFunc

func (c *Client) SetGatewayLookupFunc(f func() (gw, myIP netaddr.IP, ok bool))

SetGatewayLookupFunc set the func that returns the machine's default gateway IP, and the primary IP address for that gateway. It must be called before the client is used. If not called, interfaces.LikelyHomeRouterIP is used.

func (*Client) SetLocalPort

func (c *Client) SetLocalPort(localPort uint16)

SetLocalPort updates the local port number to which we want to port map UDP traffic.

type NoMappingError

type NoMappingError struct {
	// contains filtered or unexported fields
}

NoMappingError is returned when no NAT mapping could be done.

func (NoMappingError) Error

func (nme NoMappingError) Error() string

func (NoMappingError) Unwrap

func (nme NoMappingError) Unwrap() error

type ProbeResult

type ProbeResult struct {
	PCP  bool
	PMP  bool
	UPnP bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL