Help us shape the future of Go! Take the 2026 Go Developer Survey

vpn

package
v1.3.100 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: AGPL-3.0 Imports: 54 Imported by: 0

Documentation

Overview

Package vpn pkg/vpn/client.go c4-app-vpn

Package vpn pkg/vpn/client_config.go c4-app-vpn

Package vpn pkg/vpn/client_embed.go c2-app-vpn

In-process embedding entry for the VPN client. The standard construction path (NewClient + Serve) is an APP: it reads the appserver environment for direct-route IPs, reports status over the app RPC, and dials the server through the app client. An embedder — the wasm visor's in-tab VPN instance is the driving case — has none of that: it dials the vpn-server route group itself and owns the lifecycle. NewClientEmbedded skips the environment and RPC coupling entirely (nil appCl; the status setters no-op), and ServeConn runs one VPN session over the conn the embedder dialed: handshake, TUN (on js the gVisor netstack, netstack_tun.go), and the packet copy loops.

Package vpn pkg/vpn/client_hello.go c4-app-vpn

Package vpn pkg/vpn/client_unix.go c4-app-vpn

Package vpn pkg/vpn/const.go c4-app-vpn

Package vpn pkg/vpn/env.go c4-app-vpn

Package vpn pkg/vpn/errors.go c4-app-vpn

Package vpn pkg/vpn/firewall_iptables_linux.go c4-app-vpn

The default firewall backend: iptables shell-outs, identical to what the router has always done. Each installed rule's full argv is recorded so teardown can remove it with the matching `-D`. This is the fleet path; the pure-Go nftables backend (firewall_nftfw_linux.go) replaces it only under the `nftfw` build tag.

Package vpn pkg/vpn/firewall_linux.go c4-app-vpn

firewall abstracts the vpn-router's packet-filter / NAT rules behind a small interface with two build-tagged backends, so the SAME router code runs either with iptables (default — the fleet's proven path) or with a pure-Go nftables backend (build tag `nftfw`, for the gokrazy appliance, which ships no iptables binary). Each backend tracks the rules it installs and removes them all in teardown(). See firewall_iptables_linux.go and firewall_nftfw_linux.go.

Package vpn pkg/vpn/handshake_status.go c4-app-vpn

Package vpn pkg/vpn/ip_generator.go c4-app-vpn

Package vpn pkg/vpn/mesh_client_linux.go c4-app-vpn

Package vpn pkg/vpn/mesh_gateway_standalone_linux.go c4-app-vpn

Standalone mesh gateway: the mesh-name resolver + transparent proxy of the full vpn-router (setupMeshGateway), but WITHOUT taking over the LAN. It runs no DHCP, assigns no address, brings up no tunnel — it only serves `.dmsg` / `.skynet` DNS and REDIRECTs synthetic-pool TCP into the mesh.

This is the "board behind your existing router" topology: a small appliance on the LAN gives every other device transparent, zero-per-device access to dmsg/skynet by name, while the household's own OpenWRT / DD-WRT router keeps doing DHCP and the default route. Two router-side settings wire it up:

  • DNS forward: `.dmsg` / `.skynet` queries → this board's DNS (below).
  • static route: the synthetic pool (default 100.64.0.0/16) → this board.

A LAN client then resolves `reward.dmsg` via the router → this board's DNS → a synthetic IP; its packets to that IP are static-routed here; PREROUTING REDIRECT lands them on the transparent proxy, which reads SO_ORIGINAL_DST and dials the encoded PK over the mesh (bypassing any VPN tunnel). Same mechanism as setupMeshGateway, minus the router role — see meshgw and router_linux.go.

Package vpn pkg/vpn/meshapp.go c4-app-vpn

Shared mesh-gateway wiring for the vpn-router and vpn-client apps: build the MeshDial from an app.Client, parse operator-supplied aliases, and load-or-mint the TLS CA. Kept here so both apps configure the gateway identically.

Package vpn pkg/vpn/net.go c4-app-vpn

Package vpn pkg/vpn/netstack_tun.go c4-app-vpn

A gVisor userspace netstack behind the same TUNDevice seam the platform TUNs implement. On js/wasm it IS the TUN (a browser has no L3 interface to open — newTUNDevice in tun_device_js.go builds one of these), but the type is pure Go and compiles everywhere: the VPN data plane only needs something that emits one IP packet per Read and accepts one IP packet per Write, and the netstack's channel endpoint is exactly that. In-tab (or in-process) dialers open TCP/UDP connections INSIDE this stack via Client.NetstackDial; the stack turns them into IP packets; the unchanged client serve loop copies those to the vpn-server over the route group, which does the real clearnet egress. The server cannot tell such a client from a native one, and no privileges are involved anywhere — no root, no device node.

Package vpn pkg/vpn/os.go c4-app-vpn

Package vpn pkg/vpn/os_client_linux.go c4-app-vpn

Package vpn pkg/vpn/os_linux.go c4-app-vpn

Package vpn pkg/vpn/os_server_linux.go c4-app-vpn

Package vpn pkg/vpn/router.go c4-app-vpn

Package vpn pkg/vpn/router_linux.go c4-app-vpn

Package vpn pkg/vpn/server.go c4-app-vpn

Package vpn pkg/vpn/server_config.go c4-app-vpn

Package vpn pkg/vpn/server_hello.go c4-app-vpn

Package vpn pkg/vpn/share.go c4-app-vpn

Sharing the tunnel with other devices — the phone's VPN hotspot.

On a phone the tunnel is the TUN the system hands out, and the kernel routes into it only what apps ON the phone send. A device on the phone's hotspot never reaches it: tethered traffic is forwarded below VpnService, straight to the uplink, and no unprivileged app can change that. The one process that could proxy for such a device — this one — is excluded from its own tunnel, because its dmsg traffic is what carries the tunnel.

So shared traffic enters the tunnel beside the kernel instead of through it: a userspace netstack (netstack_tun.go) that carries the SAME address the server assigned to this client. Its packets reach the server over the same route-group conn as the kernel's, and the server cannot tell them apart — which is what keeps its per-client rules applying to them (the secure mode's local-network block is keyed on that one address). Replies are told apart by destination port: the netstack takes its ephemeral ports from [shareFirstPort, shareLastPort], above the kernel's own range (32768–60999), so a reply to one of those ports is the netstack's and every other packet is the kernel's.

The proxy in front of it speaks SOCKS5 and HTTP on one connection (pkg/proxyfront), resolves names through the tunnel too, and dials nothing but the netstack: with no tunnel up a shared connection fails, it never leaves by the phone's own uplink.

Package vpn pkg/vpn/share_other.go c4-app-vpn

Package vpn pkg/vpn/share_unix.go c4-app-vpn

Package vpn pkg/vpn/skydns.go c4-app-vpn

Package vpn pkg/vpn/skydns_linux.go c4-app-vpn

Package vpn pkg/vpn/subnet_ip_incrementer.go c4-app-vpn

Package vpn pkg/vpn/tun_device.go c4-app-vpn

Package vpn pkg/vpn/tun_device_unix.go c4-app-vpn

Index

Constants

View Source
const (
	// TUNNetmaskCIDR is a general netmask used for all TUN interfaces in CIDR format (only suffix).
	TUNNetmaskCIDR = "/29"
	// TUNMTU is MTU value used for all TUN interfaces.
	TUNMTU = 1500
)
View Source
const (
	// DmsgAddrsCountEnvKey is env arg holding Dmsg servers count.
	DmsgAddrsCountEnvKey = "DMSG_SRV_COUNT"
	// DmsgAddrEnvPrefix is prefix for each env arg holding Dmsg server address.
	DmsgAddrEnvPrefix = "ADDR_DMSG_SRV_"

	// DmsgDiscAddrEnvKey is env arg holding Dmsg discovery address.
	DmsgDiscAddrEnvKey = "ADDR_DMSG_DISC"
	// TPDiscAddrEnvKey is env arg holding TP discovery address.
	TPDiscAddrEnvKey = "ADDR_TP_DISC"
	// AddressResolverAddrEnvKey is env arg holding address resolver address.
	AddressResolverAddrEnvKey = "ADDR_ADDRESS_RESOLVER"
	// RFAddrEnvKey is env arg holding RF address.
	RFAddrEnvKey = "ADDR_RF"
	// UptimeTrackerAddrEnvKey is env arg holding uptime tracker address.
	UptimeTrackerAddrEnvKey = "ADDR_UPTIME_TRACKER"

	// STCPTableLenEnvKey is env arg holding Stcp table length.
	STCPTableLenEnvKey = "STCP_TABLE_LEN"
	// STCPKeyEnvPrefix is prefix for each env arg holding Skywire-TCP entity key.
	STCPKeyEnvPrefix = "STCP_TABLE_KEY_"
	// STCPValueEnvPrefix is prefix for each env arg holding Skywire-TCP entity value.
	STCPValueEnvPrefix = "STCP_TABLE_"

	// TPRemoteIPsLenEnvKey is env arg holding TP remote IPs length.
	TPRemoteIPsLenEnvKey = "TP_REMOTE_IPS_LEN"
	// TPRemoteIPsEnvPrefix is prefix for each env arg holding TP remote IP.
	TPRemoteIPsEnvPrefix = "ADDR_TP_REMOTE_"
)

Variables

This section is empty.

Functions

func AllowIPToLocalNetwork

func AllowIPToLocalNetwork(src, _ net.IP) error

AllowIPToLocalNetwork allows all the packets coming from `source` to private IP ranges.

func AppEnvArgs

func AppEnvArgs(config DirectRoutesEnvConfig) map[string]string

AppEnvArgs forms env args to pass to the app process.

func BlockIPToLocalNetwork

func BlockIPToLocalNetwork(src, _ net.IP) error

BlockIPToLocalNetwork blocks all the packets coming from `source` to private IP ranges.

func DefaultNetworkGateway

func DefaultNetworkGateway() (net.IP, error)

DefaultNetworkGateway fetches system's default network gateway.

func DisableIPMasquerading

func DisableIPMasquerading(ifcName string) error

DisableIPMasquerading disables IP masquerading for the interface with name `ifcName`.

func EnableIPMasquerading

func EnableIPMasquerading(ifcName string) error

EnableIPMasquerading enables IP masquerading for the interface with name `ifcName`.

func EnableIPv4Forwarding

func EnableIPv4Forwarding() error

EnableIPv4Forwarding enables IPv4 forwarding.

func EnableIPv6Forwarding

func EnableIPv6Forwarding() error

EnableIPv6Forwarding enables IPv6 forwarding.

func GetIPTablesForwardPolicy

func GetIPTablesForwardPolicy() (string, error)

GetIPTablesForwardPolicy gets current policy for iptables `forward` chain.

func GetIPv4ForwardingValue

func GetIPv4ForwardingValue() (string, error)

GetIPv4ForwardingValue gets current value of IPv4 forwarding (via /proc — no sysctl binary needed).

func GetIPv6ForwardingValue

func GetIPv6ForwardingValue() (string, error)

GetIPv6ForwardingValue gets current value of IPv6 forwarding (via /proc).

func IPFromEnv

func IPFromEnv(key string) (net.IP, bool, error)

IPFromEnv gets IP address from the env arg `key`. Env value may be one of: - full URL with port; - full URL without port; - domain with port; - domain without port; - IP with port; - IP without port. In case domain is provided instead of an IP address, a DNS lookup is also performed to resolve the actual IP address

func LoadOrCreateMeshCA

func LoadOrCreateMeshCA(certPath, keyPath, defaultDir string) (skynetca.LeafMinter, error)

LoadOrCreateMeshCA loads the mesh-gateway CA from certPath/keyPath, generating and persisting a fresh one (permitting .dmsg/.skynet) if absent. Empty paths default under defaultDir. It prints the cert path + fingerprint so the operator can install it as trusted on the clients that will use the gateway.

func MeshDialer

func MeshDialer(appCl *app.Client) meshgw.MeshDial

MeshDialer adapts an app.Client to meshgw.MeshDial: scheme ("dmsg" / "skynet") is the appnet network type; port is the mesh routing port (the client's original destination port).

func ParseIP

func ParseIP(addr string) (net.IP, bool, error)

ParseIP parses IP string `addr`. `addr` may be on of: - full URL with port; - full URL without port; - domain with port; - domain without port; - IP with port; - IP without port. - dmshhttp url with port; - dmshhttp url without port. In case domain is provided instead of an IP address, a DNS lookup is also performed to resolve the actual IP address

func ParseMeshAliases

func ParseMeshAliases(in []string) (map[string]cipher.PubKey, error)

ParseMeshAliases turns repeated `name=<pk>` strings into a friendly-name → PK map for the mesh gateway.

func ReadJSON

func ReadJSON(conn net.Conn, data interface{}) error

ReadJSON reads portion of data from the `conn` and unmarshals it into `data`.

func ReadJSONWithTimeout

func ReadJSONWithTimeout(conn net.Conn, data interface{}, timeout time.Duration) error

ReadJSONWithTimeout reads portion of data from the `conn` and unmarshals it into `data` with the specified read `timeout`.

func RunMeshGatewayOnly

func RunMeshGatewayOnly(ctx context.Context, cfg MeshGatewayConfig, log logrus.FieldLogger) error

RunMeshGatewayOnly runs a standalone mesh gateway until ctx is canceled, then tears its state (firewall REDIRECT + IPv4 forwarding) back down. It reuses the same firewall backend (iptables, or nftables under -tags nftfw) and meshgw engine as the full router; it just skips the DHCP/DNS-server-owns-the-LAN, interface, WiFi, and tunnel-NAT roles.

func RunSkyDNS added in v1.3.100

func RunSkyDNS(ctx context.Context, cfg SkyDNSConfig) error

RunSkyDNS serves SkyDNS on a tunnel of its own until ctx ends. Only skydns.Range is routed into it. The host asks it for .dmsg and .skynet names through systemd-resolved where that runs, and through resolv.conf otherwise.

func SetIPTablesForwardAcceptPolicy

func SetIPTablesForwardAcceptPolicy() error

SetIPTablesForwardAcceptPolicy sets ACCEPT policy for iptables `forward` chain.

func SetIPTablesForwardPolicy

func SetIPTablesForwardPolicy(policy string) error

SetIPTablesForwardPolicy sets `policy` for iptables `forward` chain.

func SetIPv4ForwardingValue

func SetIPv4ForwardingValue(val string) error

SetIPv4ForwardingValue sets `val` value of IPv4 forwarding (via /proc).

func SetIPv6ForwardingValue

func SetIPv6ForwardingValue(val string) error

SetIPv6ForwardingValue sets `val` value of IPv6 forwarding (via /proc).

func WriteJSON

func WriteJSON(conn net.Conn, data interface{}) error

WriteJSON marshals `data` and sends it over the `conn`.

func WriteJSONWithTimeout

func WriteJSONWithTimeout(conn net.Conn, data interface{}, timeout time.Duration) error

WriteJSONWithTimeout marshals `data` and sends it over the `conn` with the specified write `timeout`.

Types

type Client

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

Client is a VPN client.

func NewClient

func NewClient(cfg ClientConfig, appCl *app.Client) (*Client, error)

NewClient creates VPN client instance.

func NewClientEmbedded

func NewClientEmbedded(cfg ClientConfig) *Client

NewClientEmbedded constructs a Client for in-process use: no app environment, no app RPC, no direct-route management. The zero directIPs set is correct for the browser (there is no OS routing table to protect), and acceptable for any embedder that manages its own underlay reachability.

func (*Client) AddDirectRoute

func (c *Client) AddDirectRoute(ip net.IP) error

AddDirectRoute counts one more user of a direct route to ip — packets to it go directly, ignoring the VPN — installing it on the first.

func (*Client) AddRoute

func (c *Client) AddRoute(ip, gateway string) error

AddRoute adds route to `ip` with `netmask` through the `gateway` to the OS routing table.

func (*Client) ChangeRoute

func (c *Client) ChangeRoute(ip, gateway string) error

ChangeRoute changes current route to `ip` to go through the `gateway` in the OS routing table.

func (*Client) Close

func (c *Client) Close()

Close closes client.

func (*Client) DeleteRoute

func (c *Client) DeleteRoute(ip, gateway string) error

DeleteRoute removes route to `ip` with `netmask` through the `gateway` from the OS routing table.

func (*Client) ListenIPC

func (c *Client) ListenIPC(client *ipc.Client)

ListenIPC starts named-pipe based connection server for windows or unix socket in Linux/Mac

func (*Client) NetstackDial

func (c *Client) NetstackDial(ctx context.Context, network, address string) (net.Conn, error)

NetstackDial dials network ("tcp"/"udp") address host:port THROUGH the tunnel: the connection originates inside the netstack and its packets ride the VPN to the server's clearnet egress. host must be an IPv4 literal — name resolution belongs to the caller (resolve over NetstackDial UDP :53, or via whatever resolver the app already uses).

func (*Client) RemoveDirectRoute

func (c *Client) RemoveDirectRoute(ip net.IP) error

RemoveDirectRoute counts one user fewer, removing the route when none is left — unless the visor named the IP at start, whose route stays.

func (*Client) RevertDNS

func (c *Client) RevertDNS()

RevertDNS trying to revert DNS values same as before starting vpn-client if it changed

func (*Client) Serve

func (c *Client) Serve() error

Serve dials VPN server, sets up TUN and establishes VPN session.

func (*Client) ServeConn

func (c *Client) ServeConn(conn net.Conn) error

ServeConn runs a single VPN session over an already-dialed connection to the vpn-server. It blocks until the session ends (server close, conn failure, or Close). The TUN persists across calls so an embedder may re-dial and call ServeConn again on reconnect, exactly like the app's own serve loop does.

func (*Client) SetupDNS

func (c *Client) SetupDNS() error

SetupDNS set dns address for TUN device on tun0

func (*Client) SetupTUN

func (c *Client) SetupTUN(ifcName, ipCIDR, gateway string, mtu int) error

SetupTUN sets the allocated TUN interface up, setting its IP, gateway, netmask and MTU.

func (*Client) TunReady

func (c *Client) TunReady() bool

TunReady reports whether the tunnel device exists — it flips once the server handshake assigned an address and the TUN (on js, the netstack) came up, which is the earliest NetstackDial can succeed. Embedders poll it to learn when a launched session is usable.

type ClientConfig

type ClientConfig struct {
	Killswitch bool
	ServerPK   cipher.PubKey
	DNSAddr    string
	// MuxRoutes, when > 1, dials the server over that many parallel
	// (multiplexed) routes. MinHops, when >= 2, forces the route through
	// at least that many intermediate visors (multihop) instead of a
	// direct path. Both default to 0 (the plain single-route dial).
	MuxRoutes int
	MinHops   int
	// DmsgFallback, when true, dials the VPN server over a direct dmsg stream if
	// the skynet (route) dial fails. Opt-in: dmsg relays through a dmsg server, so
	// the fallback trades higher latency and a metadata downgrade (the dmsg server
	// sees both endpoint PKs, unlike a source-routed multihop skynet path) for the
	// resilience of an always-available baseline. Default off keeps the plain
	// skynet-only dial.
	DmsgFallback bool

	// MeshGateway, when true (Linux only), additionally runs a local MESH
	// GATEWAY: the host resolves *.dmsg / *.skynet by name and those connections
	// are proxied over the mesh (bypassing the tunnel), the single-machine
	// counterpart of the vpn-router's LAN gateway. MeshDial must be set.
	MeshGateway bool
	// MeshGatewayCIDR is the synthetic-IP pool (empty = 100.64.0.0/16).
	MeshGatewayCIDR string
	// MeshDial performs the mesh dial for resolved names; the vpn-client app
	// wires it to its app.Client. Required when MeshGateway is true.
	MeshDial meshgw.MeshDial
	// MeshAliases maps friendly names to PKs (reach http://<alias>.dmsg). Optional.
	MeshAliases map[string]cipher.PubKey
	// MeshTLSMinter, when set, enables TLS-MITM for HTTPS to *.dmsg / *.skynet.
	// The host must trust the minter's CA. Optional.
	MeshTLSMinter skynetca.LeafMinter
}

ClientConfig is a configuration for VPN client.

type ClientHello

type ClientHello struct {
	UnavailablePrivateIPs []net.IP `json:"unavailable_private_ips"`
}

ClientHello is a message sent by client during the Client/Server handshake.

type DirectRoutesEnvConfig

type DirectRoutesEnvConfig struct {
	DmsgDiscovery   string
	DmsgServers     []string
	TPDiscovery     string
	RF              string
	UptimeTracker   string
	AddressResolver string
	TPRemoteIPs     []string
	STCPTable       map[cipher.PubKey]string
}

DirectRoutesEnvConfig contains all the addresses which need to be communicated directly, not through the VPN service.

type HandshakeStatus

type HandshakeStatus int

HandshakeStatus is a status of Client/Server handshake.

const (
	// HandshakeStatusOK is returned on successful handshake.
	HandshakeStatusOK HandshakeStatus = iota
	// HandshakeStatusBadRequest is returned if Client hello message was malformed.
	HandshakeStatusBadRequest
	// HandshakeNoFreeIPs is returned if no free IPs left to assign to TUNs.
	HandshakeNoFreeIPs
	// HandshakeStatusInternalError is returned in all other cases when some server error occurred.
	HandshakeStatusInternalError
	// HandshakeStatusForbidden is returned if client is not in the server's whitelist.
	HandshakeStatusForbidden
)

func (HandshakeStatus) String

func (hs HandshakeStatus) String() string

type IPGenerator

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

IPGenerator is used to generate IPs for TUN interfaces.

func NewIPGenerator

func NewIPGenerator() *IPGenerator

NewIPGenerator creates IP generator.

func (*IPGenerator) Next

func (g *IPGenerator) Next() (net.IP, error)

Next gets next available IP.

func (*IPGenerator) Reserve

func (g *IPGenerator) Reserve(ip net.IP) error

Reserve reserves `ip` so it will be excluded from the IP generation.

type MeshGatewayConfig

type MeshGatewayConfig struct {
	// LANInterface is the interface LAN traffic arrives on — the `iif` the
	// PREROUTING REDIRECT matches. Required: the REDIRECT must be pinned to the
	// downstream link so it never catches the board's own upstream traffic.
	LANInterface string

	// BindIP is the address the DNS server and transparent proxy listen on.
	// Nil / unspecified = all interfaces (0.0.0.0). Set it to the board's LAN IP
	// to avoid exposing DNS on other interfaces.
	BindIP net.IP

	// DNSPort is the mesh-name DNS port. 0 = defaultMeshGatewayDNSPort (53).
	DNSPort int

	// CIDR is the synthetic-IP pool leased to `.dmsg` / `.skynet` names. Empty =
	// defaultMeshGatewayCIDR (100.64.0.0/16). This is the range the upstream
	// router must static-route to this board.
	CIDR string

	// MeshDial dials the mesh for a resolved (scheme, pk, port). Required — from
	// the vpn-router app it is vpn.MeshDialer(appClient).
	MeshDial meshgw.MeshDial

	// Aliases (optional) maps friendly names → PK for names that aren't a raw PK.
	Aliases map[string]cipher.PubKey

	// TLSMinter (optional) enables TLS-MITM for HTTPS to `.dmsg` / `.skynet`
	// (port 443). LAN clients must trust the minter's CA.
	TLSMinter skynetca.LeafMinter
}

MeshGatewayConfig configures a standalone mesh gateway (RunMeshGatewayOnly).

type Router

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

Router orchestrates the downstream interface, the DHCP/DNS + optional WiFi AP daemons, and the forwarding/NAT into the mesh-VPN tunnel. Construct with NewRouter, then Run.

func NewRouter

func NewRouter(cfg RouterConfig, log logrus.FieldLogger) (*Router, error)

NewRouter validates cfg and returns a Router ready to Run. It does not touch any system state.

func (*Router) Run

func (r *Router) Run(ctx context.Context) error

Run sets the router up and blocks until ctx is canceled, then tears everything back down. It returns the setup error (after best-effort teardown) or nil on clean shutdown.

type RouterConfig

type RouterConfig struct {
	// LANInterface is the downstream interface that serves clients — a wired NIC
	// (e.g. "eth1") for the ethernet-out variant, or an AP-capable wireless NIC
	// (e.g. "wlan0") for the WiFi-out variant.
	LANInterface string

	// TUNInterface is the upstream mesh-VPN tunnel to masquerade into (e.g.
	// "tun0"), owned by the vpn-client app. Empty = auto-detect the first tun*
	// interface once vpn-client has brought it up.
	TUNInterface string

	// Gateway is the router's own address on the downstream subnet (the default
	// gateway handed to clients), e.g. 192.168.42.1.
	Gateway net.IP

	// Subnet is the downstream network in CIDR form, e.g. 192.168.42.0/24.
	Subnet *net.IPNet

	// DHCPStart and DHCPEnd bound the DHCP address pool. Both must lie inside
	// Subnet. Zero values default to .10 … .254 of the subnet.
	DHCPStart net.IP
	DHCPEnd   net.IP

	// DNS is the resolver advertised to clients over DHCP (e.g. 1.1.1.1). Zero
	// value defaults to the Gateway (dnsmasq then resolves for clients).
	DNS net.IP

	// LeaseTime is the DHCP lease duration in dnsmasq form (e.g. "12h"). Empty
	// defaults to "12h".
	LeaseTime string

	// WiFi, when non-nil, additionally runs hostapd to create a WiFi AP on
	// LANInterface. Nil = ethernet-out (no AP).
	WiFi *WiFiConfig

	// MeshDial, when non-nil, enables the MESH GATEWAY: the router's DNS answers
	// *.dmsg / *.skynet with synthetic IPs, and a transparent proxy dials those
	// targets over the mesh via this func — so any downstream client can reach
	// dmsg/skynet services by name. The vpn-router app supplies a dialer backed
	// by its app.Client. Nil = mesh gateway off. See pkg/vpnrouter/meshgw.
	MeshDial meshgw.MeshDial

	// MeshGatewayCIDR is the private range the mesh gateway leases synthetic IPs
	// from. Empty defaults to defaultMeshGatewayCIDR. Ignored when MeshDial nil.
	MeshGatewayCIDR string

	// MeshAliases maps friendly names to destination PKs, so a client can reach
	// `http://<alias>.dmsg` instead of the raw `<pk-label>.dmsg`. May be nil.
	// Ignored when MeshDial nil.
	MeshAliases map[string]cipher.PubKey

	// MeshTLSMinter, when non-nil (and MeshDial set), enables TLS-MITM for the
	// mesh gateway: HTTPS to *.dmsg / *.skynet is terminated with a leaf minted
	// here and bridged to the plain-HTTP mesh upstream, so browsers get a secure
	// context. LAN clients must trust the minter's CA. Ignored when MeshDial nil.
	MeshTLSMinter skynetca.LeafMinter
}

RouterConfig is the platform-neutral configuration for a VPN router.

type Server

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

Server is a VPN server.

func NewServer

func NewServer(cfg ServerConfig, appCl *app.Client) (*Server, error)

NewServer creates VPN server instance.

func (*Server) AddRoute

func (s *Server) AddRoute(ip, gateway string) error

AddRoute adds route to `ip` with `netmask` through the `gateway` to the OS routing table.

func (*Server) Close

func (s *Server) Close() error

Close shuts server down.

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Serve accepts connections from `l` and serves them.

func (*Server) SetupTUN

func (s *Server) SetupTUN(ifcName, ipCIDR, gateway string, mtu int) error

SetupTUN sets the allocated TUN interface up, setting its IP, gateway, netmask and MTU.

type ServerConfig

type ServerConfig struct {
	Whitelist        []cipher.PubKey
	Secure           bool
	NetworkInterface string
}

ServerConfig is a configuration for VPN server.

type ServerHello

type ServerHello struct {
	Status     HandshakeStatus `json:"status"`
	TUNIP      net.IP          `json:"tun_ip"`
	TUNGateway net.IP          `json:"tun_gateway"`
}

ServerHello is a message sent by server during the Client/Server handshake.

type SkyDNSConfig added in v1.3.100

type SkyDNSConfig struct {
	// Dial carries connections to mesh names. See MeshDialer.
	Dial meshgw.MeshDial
	// Upstream is the resolver for every other name, an IP. Empty means the
	// phone's own, as the app reports them.
	Upstream string
	Log      logrus.FieldLogger
}

SkyDNSConfig is SkyDNS on a tunnel of its own, with no VPN server behind it.

type TUNDevice

type TUNDevice interface {
	io.ReadWriteCloser
	Name() string
}

TUNDevice is a wrapper for TUN interface.

type WiFiConfig

type WiFiConfig struct {
	SSID string
	// Passphrase is the WPA2 pre-shared key (8–63 chars). Empty = open network
	// (allowed but strongly discouraged; validate() warns via error unless
	// explicitly opened with AllowOpen).
	Passphrase string
	// Band is "2.4" or "5". Selects hostapd hw_mode (g / a).
	Band string
	// Channel is the 802.11 channel. 0 = a sensible default for the band
	// (channel 6 on 2.4 GHz, 36 on 5 GHz).
	Channel int
	// CountryCode is the regulatory domain (e.g. "US"). Empty = "US".
	CountryCode string
	// AllowOpen permits an empty Passphrase (open network) without erroring.
	AllowOpen bool
}

WiFiConfig configures the hostapd access point for the WiFi-out variant.

func (WiFiConfig) HostapdConf

func (w WiFiConfig) HostapdConf(iface string) string

HostapdConf renders the hostapd configuration for the WiFi-out variant. It is pure (no I/O). iface is the wireless interface the AP runs on.

Directories

Path Synopsis
Package netctl pkg/vpn/netctl/netctl_linux.go c4-app-vpn
Package netctl pkg/vpn/netctl/netctl_linux.go c4-app-vpn

Jump to

Keyboard shortcuts

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