libtailscale

package
v0.1.5-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: AGPL-3.0 Imports: 66 Imported by: 0

Documentation

Overview

Copyright (c) Tailscale Inc & contributors SPDX-License-Identifier: BSD-3-Clause

Portions Copyright (c) BARGHEST SPDX-License-Identifier: AGPL-3.0-or-later

This file contains code originally from Tailscale (BSD-3-Clause) with modifications by BARGHEST. The modified version is licensed under AGPL-3.0-or-later. See LICENSE for details.

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)

func SetShareFileHelper

func SetShareFileHelper(fileHelper ShareFileHelper)

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)

	// GetStateStoreKeysJson retrieves all keys stored in the encrypted SharedPreferences,
	// strips off the "statestore-" prefix, and returns them as a JSON array.
	GetStateStoreKeysJSON() string

	// 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)

	// Methods used to implement key.HardwareAttestationKey using the Android
	// KeyStore.
	HardwareAttestationKeySupported() bool
	HardwareAttestationKeyCreate() (id string, err error)
	HardwareAttestationKeyRelease(id string) error
	HardwareAttestationKeyPublic(id string) (pub []byte, err error)
	HardwareAttestationKeySign(id string, data []byte) (sig []byte, err error)
	HardwareAttestationKeyLoad(id 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, hwAttestationPref bool, 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 OutputStream

type OutputStream interface {
	Write([]byte) (int, error)
	Close() error
}

OutputStream provides an adapter between Java's OutputStream and Go's io.WriteCloser.

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 ShareFileHelper

type ShareFileHelper interface {
	// OpenFileWriter creates or truncates a file named fileName at a given offset,
	// returning an OutputStream for writing. Returns an error if the file cannot be opened.
	OpenFileWriter(fileName string, offset int64) (stream OutputStream, err error)

	// GetFileURI returns the SAF URI string for the file named fileName,
	// or an error if the file cannot be resolved.
	GetFileURI(fileName string) (uri string, err error)

	// RenameFile renames the file at oldPath (a SAF URI) into the Taildrop directory,
	// giving it the new targetName. Returns the SAF URI of the renamed file, or an error.
	RenameFile(oldPath string, targetName string) (newURI string, err error)

	// ListFilesJSON returns a JSON-encoded list of filenames in the Taildrop directory
	// that end with the specified suffix. If the suffix is empty, it returns all files.
	// Returns an error if no matching files are found or the directory cannot be accessed.
	ListFilesJSON(suffix string) (json string, err error)

	// OpenFileReader opens the file with the given name (typically a .partial file)
	// and returns an InputStream for reading its contents.
	// Returns an error if the file cannot be opened.
	OpenFileReader(name string) (stream InputStream, err error)

	// DeleteFile deletes the file identified by the given SAF URI string.
	// Returns an error if the file could not be deleted.
	DeleteFile(uri string) error

	// GetFileInfo returns a JSON-encoded string containing metadata for fileName,
	// matching the fields of androidFileInfo (name, size, modTime).
	// Returns an error if the file does not exist or cannot be accessed.
	GetFileInfo(fileName string) (json string, err error)
}

ShareFileHelper corresponds to the Kotlin ShareFileHelper class

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