dnstunnel

package
v0.2.2-dev.6 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dnstunnel is the panel half of the DNS tunnel protocol plugin (experimental, off unless an owner makes a profile of it). The node answers one DNS zone on UDP and TCP port 53 and carries a device's connections inside the DNS queries that the device's recursive resolvers deliver to it, so it works where only DNS gets out (a mobile network in "white list" mode). Only the first-party Mistgate app can use it: no link format carries it.

The profile names a base domain. Every inbound gets a label of its own (InitInbound), so its zone is <label>.<base domain>, and the owner delegates that zone to the node with two records (records.go). The node engine is internal/node/dnstunnel.

Index

Constants

View Source
const (
	StateUnchecked    = "unchecked"
	StateFound        = "found"
	StateMissing      = "missing"
	StateOtherValue   = "other_value"
	StateTaken        = "taken"
	StateLookupFailed = "lookup_failed"
)

Record states, per record. "taken" is the zone's NS record only.

View Source
const (
	VerdictOK           = "ok"
	VerdictTaken        = "taken"         // the zone or its name server belongs to another server of this panel
	VerdictLookupFailed = "lookup_failed" // a lookup could not be made: nothing is known
	VerdictNoNS         = "no_ns"         // the zone has no NS record
	VerdictWrongNS      = "wrong_ns"      // the zone is delegated to another name
	VerdictNoA          = "no_a"          // the name server has no address
	VerdictWrongA       = "wrong_a"       // the name server's address is not the node's
	VerdictHasAAAA      = "has_aaaa"      // the name server has an IPv6 address, which the node does not serve
	VerdictNotReached   = "not_reached"   // the records are right, but a query for the zone did not come to this node
)

Verdicts of a check, the first that applies.

View Source
const (
	ReachedYes       = "yes"
	ReachedNo        = "no"
	ReachedUnchecked = "unchecked"
)

Reached says whether a query for the zone, made through the public resolvers, was answered by this node.

View Source
const FormatVersion = 1

FormatVersion is the "v" of the path settings the app reads.

ID is the plugin id; protocols.DNSTunnelID is the same string for the code that must not import this package.

View Source
const (
	// Port is the port of the zone's authoritative server: a recursive resolver asks port 53 and nothing else.
	Port = 53
)
View Source
const SystemResolver = "system"

SystemResolver stands for the resolver of the person's own network in the list the app gets.

Variables

This section is empty.

Functions

func NSName

func NSName(baseDomain, label string) string

NSName is the name server of the zone, written beside the zone and not inside it, so that no glue record is needed.

func NodeIPv4

func NodeIPv4(ctx context.Context, r Resolver, address string) netip.Addr

NodeIPv4 is the node's IPv4 address as the panel has it: the address itself, or the first IPv4 address of the name (the zero value when there is none or the lookup failed).

func ValidResolver

func ValidResolver(r string) bool

ValidResolver says whether r is "system" or a public IPv4 address.

func Zone

func Zone(baseDomain, label string) string

Zone is the zone of one inbound: its label in front of the profile's base domain.

Types

type CheckInput

type CheckInput struct {
	Zone, NSName string
	NodeIPv4     netip.Addr
	// CheckKey is the inbound's delegation check key (the node answers _mgchk-<nonce>.<zone> with hex HMAC-SHA256 of the nonce):
	// a right answer proves that a query for the zone, through the public resolvers, reached this very node. Empty: not asked.
	CheckKey []byte
	// Nonce is the 8 to 32 characters [a-z0-9] of the check name; empty makes a random one.
	Nonce  string
	Others []Other
}

CheckInput is what a check compares the DNS with.

type NodeCredential

type NodeCredential struct {
	KID string `json:"kid"`
	Key string `json:"key"`
}

NodeCredential is the byte-stable UserCred.Data the node engine reads: the device id and its key.

type NodeSettings

type NodeSettings struct {
	Zone        string `json:"zone"`
	NSName      string `json:"ns_name"`
	NSAddress   string `json:"ns_address,omitempty"`
	CheckKey    string `json:"check_key"`
	MaxSessions int    `json:"max_sessions"`
}

NodeSettings is the byte-stable InboundSpec.Settings the node engine reads (internal/node/dnstunnel settings.go).

type Other

type Other struct {
	Zone, NSName string
	Node         string
}

Other is another DNS tunnel server of this panel: its zone and name server are not to be taken.

type Protocol

type Protocol struct{}

func New

func New() *Protocol

func (*Protocol) BuildInbound

func (*Protocol) BuildInbound(in protocols.InboundInput) (plugin.InboundSpec, error)

func (*Protocol) Clients

func (*Protocol) Clients() []plugin.ClientSupport

Clients: the first-party app only. No link format has a place for it.

func (*Protocol) DefaultSettings

func (*Protocol) DefaultSettings() (json.RawMessage, error)

DefaultSettings has no domain: a profile cannot be saved before the owner names one.

func (*Protocol) DisplayName

func (*Protocol) DisplayName() string

func (*Protocol) Doctor

func (*Protocol) Doctor() []protocols.Check

func (*Protocol) Experimental

func (*Protocol) Experimental() bool

func (*Protocol) ID

func (*Protocol) ID() string

func (*Protocol) InitInbound

InitInbound makes the zone label and the key of the delegation check once, when the inbound is created. The label is public (it is in the DNS records); the check key stays in the plugin state and goes to the node, which answers the check name with it.

func (*Protocol) IssueCredential

func (*Protocol) IssueCredential(protocols.IssueInput) (protocols.Issued, error)

IssueCredential makes a device's id (8 random bytes, 16 hex characters) and key (32 random bytes, 43 base64url characters). The device holds "<kid>.<key>"; the node gets both halves, as with any symmetric key of a proxy protocol.

func (*Protocol) Render

func (*Protocol) SettingsSchema

func (*Protocol) SettingsSchema() []byte

func (*Protocol) Summary

func (*Protocol) Summary(raw json.RawMessage) string

func (*Protocol) Validate

func (*Protocol) Validate(raw json.RawMessage) []protocols.FieldError

Validate is the pure part of the checks. What needs the rest of the panel (the domain is not the panel's own) is the access module's: access dnstunnel_rpc.go.

type Public

type Public struct {
	Label           string `json:"label"`
	ServerPublicKey string `json:"server_public_key,omitempty"`
}

Public is InboundInit.Public: what is not secret about one inbound. Label is made once; the server public key is the node's static key as the node reported it (the fleet writes it here), empty until the first report.

func ParsePublic

func ParsePublic(raw json.RawMessage) (Public, error)

ParsePublic reads an inbound's public document; a document without a usable label is an error.

type Record

type Record struct {
	Type  string // "NS" | "A"
	Name  string // the owner of the record, without a trailing dot
	Value string // the value, without a trailing dot; empty for an A record when the node's address is not known
	State string
	// Seen is what the lookup returned when it is not the expected value (State other_value).
	Seen []string
	// TakenBy is the node that holds the zone, when State is taken.
	TakenBy string
}

Record is one record the owner adds, and what a lookup found.

func Expected

func Expected(zone, nsName string, nodeIPv4 netip.Addr) []Record

Expected is the records to add for a zone. The A record's value is empty when the node's address is not known.

type Resolver

type Resolver interface {
	LookupNS(ctx context.Context, name string) ([]*net.NS, error)
	LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error)
	LookupTXT(ctx context.Context, name string) ([]string, error)
}

Resolver is what a check needs of a DNS client; *net.Resolver is one.

func PublicResolver

func PublicResolver() Resolver

PublicResolver asks 1.1.1.1 and 8.8.8.8 over UDP, in turn, instead of the host's own resolver: that one may cache an answer for the previous state of the owner's records, or sit behind a split-horizon of the panel's network.

type Result

type Result struct {
	Records []Record
	// Reached is the answer of the zone's delegation check name (see CheckInput.CheckKey).
	Reached string
	Verdict string
}

Result is a check of one inbound's records.

func Check

func Check(ctx context.Context, r Resolver, in CheckInput) Result

Check looks the records up and says what is wrong. It makes at most five lookups, each bounded by ctx.

type Settings

type Settings struct {
	BaseDomain      string   `json:"base_domain"`
	Egress          string   `json:"egress"` // direct | warp
	MaxSessions     int      `json:"max_sessions"`
	ClientResolvers []string `json:"client_resolvers"`
}

Settings is the merged profile settings document.

Jump to

Keyboard shortcuts

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