libtailscale

package
v1.10.2-36fe8ad...-08a062b Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: BSD-3-Clause Imports: 55 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func OnDNSConfigChanged

func OnDNSConfigChanged(ifname string)

ifname is the interface name retrieved from LinkProperties on network change. An empty string is used if there is no network available.

func RequestVPN

func RequestVPN(service IPNService)

func SendLog

func SendLog(logstr []byte)

func ServiceDisconnect

func ServiceDisconnect(service IPNService)

Types

type App

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

func (*App) CallLocalAPI

func (app *App) CallLocalAPI(timeoutMillis int, method, endpoint string, body InputStream) (LocalAPIResponse, error)

CallLocalAPI is the method for making localapi calls from Kotlin. It calls the given endpoint on the local API using the given HTTP method and optionally sending the given body. It returns a Response representing the result of the call and an error if the call could not be completed or the local API returned a status code in the 400 series or greater. Note - Response includes a response body available from the Body method, it is the caller's responsibility to close this.

func (*App) CallLocalAPIMultipart

func (app *App) CallLocalAPIMultipart(timeoutMillis int, method, endpoint string, parts FileParts) (LocalAPIResponse, error)

CallLocalAPIMultipart is like CallLocalAPI, but instead of uploading a generic body, it uploads a multipart/form-encoded body consisting of the supplied parts.

func (*App) EditPrefs

func (app *App) EditPrefs(prefs ipn.MaskedPrefs) (LocalAPIResponse, error)

func (*App) NotifyPolicyChanged

func (app *App) NotifyPolicyChanged()

func (*App) WatchNotifications

func (app *App) WatchNotifications(mask int, cb NotificationCallback) NotificationManager

type AppContext

type AppContext interface {
	// Log logs the given tag and logLine
	Log(tag, logLine string)

	// EncryptToPref stores the given value to an encrypted preference at the
	// given key.
	EncryptToPref(key, value string) error

	// DecryptFromPref retrieves the given value from an encrypted preference
	// at the given key, or returns empty string if unset.
	DecryptFromPref(key string) (string, error)

	// GetOSVersion gets the Android version.
	GetOSVersion() (string, error)

	// GetModelName gets the Android device's model name.
	GetModelName() (string, error)

	// GetInstallSource gets information about how the app was installed or updated.
	GetInstallSource() string

	// ShouldUseGoogleDNSFallback reports whether or not to use Google for DNS fallback.
	ShouldUseGoogleDNSFallback() bool

	// IsChromeOS reports whether we're on a ChromeOS device.
	IsChromeOS() (bool, error)

	// GetInterfacesAsString gets a string representation of all network
	// interfaces.
	GetInterfacesAsString() (string, error)

	// GetPlatformDNSConfig gets a string representation of the current DNS
	// configuration.
	GetPlatformDNSConfig() string

	// GetSyspolicyStringValue returns the current string value for the given system policy.
	GetSyspolicyStringValue(key string) (string, error)

	// GetSyspolicyBooleanValue returns whether the given system policy is enabled.
	GetSyspolicyBooleanValue(key string) (bool, error)

	// GetSyspolicyStringArrayValue returns the current string array value for the given system policy,
	// expressed as a JSON string.
	GetSyspolicyStringArrayJSONValue(key string) (string, error)
}

AppContext provides a context within which the Application is running. This context is a hook into functionality that's implemented on the Java side.

type Application

type Application interface {
	// CallLocalAPI provides a mechanism for calling Tailscale's HTTP localapi
	// without having to call over the network.
	CallLocalAPI(timeoutMillis int, method, endpoint string, body InputStream) (LocalAPIResponse, error)

	// CallLocalAPIMultipart is like CallLocalAPI, but instead of a single body,
	// it accepts multiple FileParts that get encoded as multipart/form-data.
	CallLocalAPIMultipart(timeoutMillis int, method, endpoint string, parts FileParts) (LocalAPIResponse, error)

	// NotifyPolicyChanged notifies the backend about a changed MDM policy,
	// so it can re-read it via the [syspolicyHandler].
	NotifyPolicyChanged()

	// WatchNotifications provides a mechanism for subscribing to ipn.Notify
	// updates. The given NotificationCallback's OnNotify function is invoked
	// on every new ipn.Notify message. The returned NotificationManager
	// allows the watcher to stop watching notifications.
	WatchNotifications(mask int, cb NotificationCallback) NotificationManager
}

Application encapsulates the running Tailscale Application. There is only a single instance of Application per Android application.

func Start

func Start(dataDir, directFileRoot string, appCtx AppContext) Application

Start starts the application, storing state in the given dataDir and using the given appCtx.

type FilePart

type FilePart struct {
	ContentLength int64
	Filename      string
	Body          InputStream
	ContentType   string // optional MIME content type
}

FilePart is a multipart file that can be submitted via CallLocalAPIMultiPart.

type FileParts

type FileParts interface {
	Len() int32
	Get(int32) *FilePart
}

FileParts is an array of multiple FileParts.

type IPNService

type IPNService interface {
	// ID returns the unique ID of this instance of the IPNService. Every time
	// we start a new IPN service, it should have a new ID.
	ID() string

	// Protect protects socket identified by the given file descriptor from
	// being captured by the VPN. The return value indicates whether or not the
	// socket was successfully protected.
	Protect(fd int32) bool

	// NewBuilder creates a new VPNServiceBuilder in preparation for starting
	// the Android VPN.
	NewBuilder() VPNServiceBuilder

	Close()

	DisconnectVPN()

	UpdateVpnStatus(bool)
}

IPNService corresponds to our IPNService in Java.

type InputStream

type InputStream interface {
	Read() ([]byte, error)
	Close() error
}

InputStream provides an adapter between Java's InputStream and Go's io.Reader.

type LocalAPIResponse

type LocalAPIResponse interface {
	StatusCode() int
	BodyBytes() ([]byte, error)
	BodyInputStream() InputStream
}

LocalAPIResponse is a response to a localapi call, analogous to an http.Response.

type NotificationCallback

type NotificationCallback interface {
	OnNotify([]byte) error
}

NotificationCallback is callback for receiving ipn.Notify messages.

type NotificationManager

type NotificationManager interface {
	Stop()
}

NotificationManager provides a mechanism for a notification watcher to stop watching notifications.

type ParcelFileDescriptor

type ParcelFileDescriptor interface {
	Detach() (int32, error)
}

ParcelFileDescriptor corresponds to Android's ParcelFileDescriptor.

type Response

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

Response represents the result of processing an localAPI request. On completion, the response body can be read out of the bodyWriter.

func (*Response) Body

func (r *Response) Body() net.Conn

func (*Response) BodyBytes

func (r *Response) BodyBytes() ([]byte, error)

func (*Response) BodyInputStream

func (r *Response) BodyInputStream() InputStream

func (*Response) Flush

func (r *Response) Flush()

func (*Response) Header

func (r *Response) Header() http.Header

func (*Response) StatusCode

func (r *Response) StatusCode() int

func (*Response) Write

func (r *Response) Write(data []byte) (int, error)

Write writes the data to the response body which an then be read out as a json object.

func (*Response) WriteHeader

func (r *Response) WriteHeader(statusCode int)

type VPNFacade

type VPNFacade struct {
	SetBoth func(rcfg *router.Config, dcfg *dns.OSConfig) error

	// GetBaseConfigFunc optionally specifies a function to return the current DNS
	// config in response to GetBaseConfig.
	//
	// If nil, reading the current config isn't supported and GetBaseConfig()
	// will return ErrGetBaseConfigNotSupported.
	GetBaseConfigFunc func() (dns.OSConfig, error)

	// InitialMTU is the MTU the tun should be initialized with.
	// Zero means don't change the MTU from the default. This MTU
	// is applied only once, shortly after the TUN is created, and
	// ignored thereaftef.
	InitialMTU uint32
	// contains filtered or unexported fields
}

VPNFacade is an implementation of both wgengine.Router and dns.OSConfigurator. When ReconfigureVPN is called by the backend, SetBoth gets called.

func (*VPNFacade) Close

func (vf *VPNFacade) Close() error

Implements wgengine.router and dns.OSConfigurator.

func (*VPNFacade) GetBaseConfig

func (vf *VPNFacade) GetBaseConfig() (dns.OSConfig, error)

Implements dns.OSConfigurator.

func (*VPNFacade) ReconfigureVPN

func (vf *VPNFacade) ReconfigureVPN() error

ReconfigureVPN is the method value passed to wgengine.Config.ReconfigureVPN.

func (*VPNFacade) Set

func (vf *VPNFacade) Set(rcfg *router.Config) error

Set implements wgengine.router.

func (*VPNFacade) SetDNS

func (vf *VPNFacade) SetDNS(dcfg dns.OSConfig) error

SetDNS implements dns.OSConfigurator.

func (*VPNFacade) SupportsSplitDNS

func (vf *VPNFacade) SupportsSplitDNS() bool

Implements dns.OSConfigurator.

func (*VPNFacade) Up

func (vf *VPNFacade) Up() error

Up implements wgengine.router.

func (*VPNFacade) UpdateMagicsockPort

func (vf *VPNFacade) UpdateMagicsockPort(_ uint16, _ string) error

UpdateMagicsockPort implements wgengine.Router. This implementation does nothing and returns nil because this router does not currently need to know what the magicsock UDP port is.

type VPNServiceBuilder

type VPNServiceBuilder interface {
	SetMTU(int32) error
	AddDNSServer(string) error
	AddSearchDomain(string) error
	AddRoute(string, int32) error
	ExcludeRoute(string, int32) error
	AddAddress(string, int32) error
	Establish() (ParcelFileDescriptor, error)
}

VPNServiceBuilder corresponds to Android's VpnService.Builder.

type VpnService

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

VpnService contains the IPNService class from Android, the file descriptor, and whether the descriptor has been detached.

Jump to

Keyboard shortcuts

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