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
- func NSName(baseDomain, label string) string
- func NodeIPv4(ctx context.Context, r Resolver, address string) netip.Addr
- func ValidResolver(r string) bool
- func Zone(baseDomain, label string) string
- type CheckInput
- type NodeCredential
- type NodeSettings
- type Other
- type Protocol
- func (*Protocol) BuildInbound(in protocols.InboundInput) (plugin.InboundSpec, error)
- func (*Protocol) Clients() []plugin.ClientSupport
- func (*Protocol) DefaultSettings() (json.RawMessage, error)
- func (*Protocol) DisplayName() string
- func (*Protocol) Doctor() []protocols.Check
- func (*Protocol) Experimental() bool
- func (*Protocol) ID() string
- func (*Protocol) InitInbound(protocols.InboundInitInput) (protocols.InboundInit, error)
- func (*Protocol) IssueCredential(protocols.IssueInput) (protocols.Issued, error)
- func (*Protocol) Render(in protocols.RenderInput) (plugin.Fragment, bool)
- func (*Protocol) SettingsSchema() []byte
- func (*Protocol) Summary(raw json.RawMessage) string
- func (*Protocol) Validate(raw json.RawMessage) []protocols.FieldError
- type Public
- type Record
- type Resolver
- type Result
- type Settings
Constants ¶
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.
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.
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.
const FormatVersion = 1
FormatVersion is the "v" of the path settings the app reads.
const ID = protocols.DNSTunnelID
ID is the plugin id; protocols.DNSTunnelID is the same string for the code that must not import this package.
const (
// Port is the port of the zone's authoritative server: a recursive resolver asks port 53 and nothing else.
Port = 53
)
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 ¶
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 ¶
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 ¶
ValidResolver says whether r is "system" or a public IPv4 address.
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 ¶
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 ¶
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 (*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) Experimental ¶
func (*Protocol) InitInbound ¶
func (*Protocol) InitInbound(protocols.InboundInitInput) (protocols.InboundInit, error)
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 ¶
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) SettingsSchema ¶
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.
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.