Documentation
¶
Overview ¶
Package dns is the panel's DNS preset module: built-in and custom presets, the DnsService admin API, and the rule that picks the preset that applies to a user (user, then group, then the instance default, then the built-in default). Turning a preset into what a client understands lives next to it: the provider catalog (providers.go), Resolve (transport.go: which endpoints a given client gets for the preset's preferred transport), and HappRouting for Happ (happ.go); the Mihomo and AmneziaWG renderers only add callers of Effective and Preset.EndpointsFor.
The instance default is stored here (setting "dns.default_preset"); SubscriptionService reads and writes SubscriptionSettings.default_dns_preset_id through DefaultPresetID / SetDefaultPresetID so there is one source of truth.
Index ¶
- Constants
- Variables
- func Clean(name, description string, servers []Server, split []SplitRule) (n, d string, srv []Server, sp []SplitRule, err error)
- func HappRouting(p Preset) (string, error)
- func HappRoutingNotes(p Preset) []string
- func LookupVariant(id string) (Variant, Provider, bool)
- func NormalizeSuffix(s string) (string, error)
- type Category
- type Client
- type Endpoint
- type Kind
- type MihomoDNS
- type MihomoPolicy
- type NodeChoices
- func (c NodeChoices) Choice(nodeID string) string
- func (c NodeChoices) Default(nodeID string) string
- func (c NodeChoices) Effective(nodeID string) string
- func (c NodeChoices) Options(nodeID string) []string
- func (c NodeChoices) Pick(nodeID string) string
- func (c NodeChoices) UpdatedMs(nodeID string) int64
- type Preset
- type Provider
- type Server
- type Service
- func (s *Service) CreateDnsPreset(ctx context.Context, req *connect.Request[adminv1.CreateDnsPresetRequest]) (*connect.Response[adminv1.CreateDnsPresetResponse], error)
- func (s *Service) DefaultPresetID(ctx context.Context) (string, error)
- func (s *Service) DeleteDnsPreset(ctx context.Context, req *connect.Request[adminv1.DeleteDnsPresetRequest]) (*connect.Response[adminv1.DeleteDnsPresetResponse], error)
- func (s *Service) Effective(ctx context.Context, userID string) (Preset, Source, error)
- func (s *Service) EffectiveOnNode(ctx context.Context, userID, nodeID string) (Preset, error)
- func (s *Service) GetUserDnsChoices(ctx context.Context, req *connect.Request[adminv1.GetUserDnsChoicesRequest]) (*connect.Response[adminv1.GetUserDnsChoicesResponse], error)
- func (s *Service) Handler() (string, http.Handler)
- func (s *Service) ListDnsPresets(ctx context.Context, _ *connect.Request[adminv1.ListDnsPresetsRequest]) (*connect.Response[adminv1.ListDnsPresetsResponse], error)
- func (s *Service) ListNodeDnsOptions(ctx context.Context, _ *connect.Request[adminv1.ListNodeDnsOptionsRequest]) (*connect.Response[adminv1.ListNodeDnsOptionsResponse], error)
- func (s *Service) NodeChoices(ctx context.Context, userID string) (NodeChoices, error)
- func (s *Service) PresetByID(ctx context.Context, id string) (Preset, error)
- func (s *Service) ResetUserDnsChoices(ctx context.Context, req *connect.Request[adminv1.ResetUserDnsChoicesRequest]) (*connect.Response[adminv1.ResetUserDnsChoicesResponse], error)
- func (s *Service) SetDefaultPresetID(ctx context.Context, id string) error
- func (s *Service) SetNodeDnsOptions(ctx context.Context, req *connect.Request[adminv1.SetNodeDnsOptionsRequest]) (*connect.Response[adminv1.SetNodeDnsOptionsResponse], error)
- func (s *Service) UpdateDnsPreset(ctx context.Context, req *connect.Request[adminv1.UpdateDnsPresetRequest]) (*connect.Response[adminv1.UpdateDnsPresetResponse], error)
- type Source
- type SplitRule
- type Variant
Constants ¶
const ( MaxServers = 16 // main resolvers, and the servers of one split rule MaxSplitRules = 64 // split rules per preset MaxSuffixesPerRule = 256 // domain suffixes in one split rule )
Limits of a preset.
const CatalogVersion = "2026-09-30"
The provider catalog: well-known public resolvers with their plain, DoT and DoH endpoints. It ships with the panel and changes with releases; a preset server may point at a variant ("cloudflare/family") instead of carrying bare addresses, so a corrected address reaches every preset on the next upgrade.
CatalogVersion is the date every endpoint below was last checked against the provider's own documentation.
const HappProfileName = "DNS"
HappProfileName is the Name of the generated routing profile.
const MaxNodeOptions = 20
MaxNodeOptions is how many presets one node may offer.
Variables ¶
var Clients = []Client{ClientHapp, ClientMihomo, ClientAmneziaWG}
Clients lists the clients in display order.
var ErrUnknownPreset = errors.New("dns: unknown preset")
ErrUnknownPreset is returned when a preset id does not exist.
Functions ¶
func Clean ¶
func Clean(name, description string, servers []Server, split []SplitRule) (n, d string, srv []Server, sp []SplitRule, err error)
Clean validates and normalises the editable fields of a preset.
func HappRouting ¶
HappRouting returns the value of the `routing` header for a preset; its split becomes direct domains only when the preset's SplitDirect is on. An error means Happ cannot express any main server of the preset: the caller leaves the header out.
func HappRoutingNotes ¶
HappRoutingNotes lists, in English, which parts of the preset the Happ profile drops or changes.
func LookupVariant ¶
LookupVariant returns a catalog variant and its provider.
func NormalizeSuffix ¶
NormalizeSuffix validates a domain suffix: ".ru", "gosuslugi.ru", ".рф", "*.example.com". The result is lower case punycode; a leading dot is kept when given (".ru" and "ru" both match the domain and its subdomains, at a label boundary).
Types ¶
type Category ¶
type Category string
Category tells what a variant is for. The admin UI groups the catalog and filters the presets by it.
const ( CategoryRussia Category = "russia" // built for resolving Russian sites from inside Russia CategoryRegular Category = "regular" // no filtering CategoryNoAds Category = "no_ads" // blocks ads and trackers CategoryFamily Category = "family" // blocks adult content (and malware) CategorySecurity Category = "security" // blocks malware and phishing )
func CategoryOf ¶
CategoryOf is the category a preset is listed under.
type Client ¶
type Client string
Client is an app that carries the DNS of a subscription.
func (Client) IPv6 ¶
IPv6 reports whether IPv6 resolver addresses are usable: Mihomo takes them; Happ's profile and Amnezia's key and .conf are IPv4 only.
func (Client) Transports ¶
Transports is what a client can carry. Sources: the client config formats (Mihomo dns:, Amnezia dns1/dns2), happ.go (Happ has plain and DoH, no DoT).
type Endpoint ¶
type Endpoint struct {
Kind Kind // the transport actually used
Address string // plain: "ip" or "ip:port"; DoH: the URL; DoT: "host" or "host:port"
// IPs of the DoH/DoT host (Happ and Mihomo want an address next to a host name); empty for plain and for a host
// the catalog does not know.
IPs []string
// Variant is the catalog id it came from, "" for a custom server.
Variant string
}
Endpoint is one resolver as a client gets it.
func Resolve ¶
Resolve turns a server list (the main servers of a preset, or one split rule's) into the endpoints a client can carry, best first, plus notes (English) on what was dropped. pref is the preset's preferred transport, ipv4Only drops IPv6 addresses. The order follows the server list, round-robin: the first endpoint of every server, then the second of every server. A plain variant has two addresses, so the first two plain endpoints of [Cloudflare, Google] are 1.1.1.1 and 8.8.8.8 (what AmneziaWG's two-address DNS wants).
type Kind ¶
type Kind string
Kind is how a server is reached.
const ( KindPlain Kind = "plain" // UDP/TCP DNS: "77.88.8.8" or "77.88.8.8:53" KindDoH Kind = "doh" // DNS over HTTPS: "https://dns.example.com/dns-query" KindDoT Kind = "dot" // DNS over TLS: "dns.example.com" or "94.140.14.14:853" )
func NormalizeTransport ¶
NormalizeTransport validates a preferred transport; "" means plain.
type MihomoDNS ¶
type MihomoDNS struct {
Nameserver []string
DefaultNameserver []string // may be empty: the core's own defaults apply
ProxyServerNameserver []string // never empty ("system" at worst)
Policy []MihomoPolicy
// Direct are the suffix bodies (lower-case punycode, no leading dot) whose traffic goes DIRECT; they are exactly
// the suffixes of Policy.
Direct []string
// Notes (English) say what of the preset a Mihomo profile cannot carry.
Notes []string
}
MihomoDNS is the dns section and the direct suffixes of one preset.
type MihomoPolicy ¶
MihomoPolicy is one nameserver-policy entry: Domain is "+.<suffix>" (the suffix and its subdomains).
type NodeChoices ¶ added in v0.1.17
type NodeChoices struct {
// contains filtered or unexported fields
}
NodeChoices is what decides the DNS of one person on each node, read once: the offers of every node and the person's picks.
func NewNodeChoices ¶ added in v0.1.17
func NewNodeChoices(offers map[string][]store.NodeDNSOption, picks map[string]store.UserNodeDNS) NodeChoices
NewNodeChoices is NodeChoices over rows already read.
func (NodeChoices) Choice ¶ added in v0.1.17
func (c NodeChoices) Choice(nodeID string) string
Choice is the person's raw pick on the node, offered or not ("" = none).
func (NodeChoices) Default ¶ added in v0.1.17
func (c NodeChoices) Default(nodeID string) string
Default is the node's default preset ("" = none).
func (NodeChoices) Effective ¶ added in v0.1.17
func (c NodeChoices) Effective(nodeID string) string
Effective is the preset id that applies on the node by rules 1 and 2; "" when the node has no choice or no default and no pick (rule 3, the caller's fallback, applies).
func (NodeChoices) Options ¶ added in v0.1.17
func (c NodeChoices) Options(nodeID string) []string
Options lists the presets a node offers, in the owner's order; nil when it offers nothing.
func (NodeChoices) Pick ¶ added in v0.1.17
func (c NodeChoices) Pick(nodeID string) string
Pick is the person's pick on the node while the node still offers it, else "".
func (NodeChoices) UpdatedMs ¶ added in v0.1.17
func (c NodeChoices) UpdatedMs(nodeID string) int64
UpdatedMs is when the person picked on the node (Unix milliseconds, 0 = never).
type Preset ¶
type Preset struct {
ID, Name, Description string
Builtin bool
Servers []Server
Split []SplitRule
IPv4Only bool
// SplitDirect: the split rules' domains bypass the VPN (Happ can only send a split resolver's domains
// direct). Off = clients that cannot keep the split proxied ignore it.
SplitDirect bool
// Transport is the preferred transport (plain, dot, doh); see Resolve. Never empty for a stored preset.
Transport Kind
}
Preset is a DNS preset ready for use (validated, servers and split decoded).
func (Preset) DescriptionIn ¶ added in v0.1.17
DescriptionIn is the description in the language of the page. A built-in one is stored as "Russian\nEnglish" and is split; a description of an owner's own preset is one text, shown in any language.
func (Preset) EndpointsFor ¶
EndpointsFor is Resolve for the main servers of a preset: what the client gets for every domain that is not split off.
func (Preset) MihomoDNS ¶
MihomoDNS renders the preset for a Mihomo profile. group is the proxy group the main servers' queries go through ("" = no "#group", the queries use the core's own routing). An error means no main server can be expressed; the caller leaves the dns section out.
type Server ¶
type Server struct {
Kind Kind `json:"kind,omitempty"`
Address string `json:"address,omitempty"`
Variant string `json:"variant,omitempty"`
}
Server is one resolver: a catalog variant (Variant set, see providers.go) or a custom address (Kind and Address).
func NormalizeServer ¶
NormalizeServer validates a server and returns it in canonical form.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service implements DnsService and answers "which preset applies to this user".
func (*Service) CreateDnsPreset ¶
func (*Service) DefaultPresetID ¶
DefaultPresetID returns the instance default as chosen by the admin ("" = the built-in default, also when the stored id no longer exists).
func (*Service) DeleteDnsPreset ¶
func (*Service) Effective ¶
Effective returns the preset that applies to a user and where it comes from: the user's own, else the user's group's, else the instance default, else the built-in default. store.ErrNotFound for an unknown user.
func (*Service) EffectiveOnNode ¶ added in v0.1.17
EffectiveOnNode is the preset that applies to a person on a node (rules 1 to 3 above).
func (*Service) GetUserDnsChoices ¶ added in v0.1.17
func (*Service) Handler ¶
Handler returns the Connect path and handler of DnsService (session checks are added by the HTTP server).
func (*Service) ListDnsPresets ¶
func (*Service) ListNodeDnsOptions ¶ added in v0.1.17
func (*Service) NodeChoices ¶ added in v0.1.17
NodeChoices reads the offers of every node and the picks of one person.
func (*Service) PresetByID ¶ added in v0.1.17
PresetByID loads one preset; store.ErrNotFound when it is gone.
func (*Service) ResetUserDnsChoices ¶ added in v0.1.17
func (*Service) SetDefaultPresetID ¶
SetDefaultPresetID sets the instance default; "" selects the built-in default. ErrUnknownPreset when the id does not exist. A real change is written to the audit log (the settings page saves it with every edit).
func (*Service) SetNodeDnsOptions ¶ added in v0.1.17
func (*Service) UpdateDnsPreset ¶
type Source ¶
type Source string
Source tells where an effective preset comes from.
const ( SourceUser Source = store.DNSSourceUser SourceGroup Source = store.DNSSourceGroup SourceDefault Source = store.DNSSourceDefault )
type SplitRule ¶
SplitRule sends domains ending in one of Suffixes to Servers instead of the preset's main ones.
type Variant ¶
type Variant struct {
ID string // "provider/variant"
NameRU, NameEN string
Category Category
IPv4, IPv6 []string
NoPlain bool // the addresses do not answer plain DNS (they only bootstrap DoT/DoH)
DoTHost string // empty: no DoT endpoint
DoTPort int
DoHURL string // empty: no DoH endpoint
NoteRU, NoteEN string
}
Variant is one way to use a provider. The IP addresses answer plain DNS (primary first) and, being anycast addresses of the same service, also serve as the bootstrap addresses of the DoT and DoH host names.