Failing servers were skipped whenever another server in scope was not
marked, even if that server did not answer either. A wrongly marked
server, e.g. after a short stall under load, then stayed unused until the
recovery check.
Ask failing servers after all others, only if none of them answered. An
answer clears the failing state right away. In scopes that continue after
"not found" (.lan, .local, ...), failing servers are skipped once any
server answered, so their timeout does not turn "not found" into a
failure.
https://github.com/safing/portmaster/issues/1891
A server is marked as failing when it does not answer: timeouts and
connection errors. The recovery check, however, only cleared the mark
when the online check domain resolved to exactly the expected IP. A
server that answers but filters or rewrites that name, for example a
blocklist, DNS rebind protection or a corporate resolver, stayed marked
until Portmaster restarted. With a working fallback configured, that
meant the LAN server and its filter were bypassed for good.
Clear the mark on any answer, whatever the answer is, which is the same
criterion normal queries already use. Timeouts and connection errors
keep the mark.
Issue: https://github.com/safing/portmaster/issues/1891
A DNS server is marked as failing after a few timeouts and then skipped.
When every server in scope is marked, no server is asked at all and the
query is answered with NXDOMAIN, which clients cache. A server that was
wrongly marked, for example after a short stall, therefore breaks name
resolution until the next recovery check or until Portmaster restarts.
Skip failing servers only while another server can still be asked, that
is, one that is neither failing nor an unavailable link-local server.
Otherwise ask the failing servers in their configured order. A successful
answer clears the failing state right away, as it does for normal queries.
Behaviour is unchanged whenever a healthy server is available. When every
server is marked and really down, the query now fails with SERVFAIL after
the timeout instead of an instant, wrong NXDOMAIN.
Issue: https://github.com/safing/portmaster/issues/1891
Related ticket: #2104
On shutdown the NameServer module stopped its listeners with
dns.Server.Shutdown, which waits without limit for all in-flight request
handlers to return. A handler can be stuck in an upstream connect that the
kernel never completes: a connection pended by a firewall driver cannot be
cancelled. In #2104 the pending driver was our own kext, because the
Interception module stops before Resolver and NameServer, so DoT dials
issued in that window had nobody left to answer their verdict. The module
Stop() has no time bound, so the whole shutdown stalled and the Windows
service stayed in "Stopping" until reboot.
- nameserver: stop listeners with ShutdownContext and a 10 second
timeout. Reading from the listener socket stops immediately; only the
wait for running handlers is bounded. Handlers still running
afterwards are cancelled and waited for by the module manager as
before.
- resolver: do not dial a new upstream connection once the instance
has started shutting down. The instance context is cancelled before
any module stops, so this closes the window in which a dial could be
pended after interception is gone. Existing pooled connections are
still used. The resolver instance interface gains ShuttingDown() for
this.
The kext-side part (do not pend new connections after the Shutdown
command) is a separate change that needs a signed driver release.
Portmaster pre-authenticated a randomly chosen local port for its own DNS
queries before binding it. When the port could not be bound, for example
because it lies in a Hyper-V excluded port range on Windows or is held by
another process, the query failed and counted against the resolver.
Plain DNS now binds a socket first, with a port chosen by the OS, and
pre-authenticates that port before sending. DNS over TCP and TLS retry
with another port when binding fails, and the failed port is skipped by
port selection for an hour. A bind failure no longer counts against the
resolver or the network state, as nothing left the host.
Pre-authentication entries that were never consumed are removed again.
Co-authored-by: DannyA <11684554+dannyagostinelli@users.noreply.github.com>
Enable ForceAttemptHTTP2 on the DoH HTTP transport. Go disables HTTP/2
negotiation by default when a custom TLSClientConfig is set; this flag
restores ALPN h2 negotiation, allowing compatibility with DoH servers
that require HTTP/2. Falls back to HTTP/1.1 transparently when the
server does not support it.
mDNS was tried first for all multicast domains (.local, etc.), causing
a mandatory 1-second timeout before unicast DNS got a turn. For domains
served by a DHCP-assigned DNS server (common in corporate and home
networks), mDNS has no authority and always times out. RFC 6762 §3
requires that .local queries are sent to mDNS multicast, which still
happens; this change only affects the order in which resolvers are
tried sequentially.
https://github.com/safing/portmaster/issues/1959
Passive mDNS records were cached using v.Header().Class instead of
v.Header().Rrtype as the Question type. ClassINET (1) equals TypeA (1)
by coincidence, so A records worked. AAAA (type 28) and PTR (type 12)
records were silently stored as type A and could never be retrieved.
Both SetWriteDeadline and WriteToUDP failures are now soft errors: the
failed protocol is logged as a warning and the other protocol is still
attempted. The query fails only if no protocol could send at all. This
prevents an IPv6 socket error from aborting a query after IPv4 already
sent successfully, which affected PTR, SRV, TXT and other record types
that are sent on both protocols.
When a unicast mDNS response has no Question section, validate that at
least one Answer record name matches the pending query's domain before
associating the response with that query.
Non-compliant devices may echo a multicast query's 16-bit ID in their own unrelated announcements;
without this check their records were stored under the wrong cache key.
https://github.com/safing/portmaster/issues/1959
questionsLock was held via defer for the full duration of
queryMulticastDNS, including the 1-second response wait. This had
two consequences: concurrent mDNS queries queued behind the lock
one-by-one (N queries × 1s each), and handleMDNSMessages could never
signal the response channel since it needs the same lock to look up
the pending question.
Release the lock immediately after registering the question.
https://github.com/safing/portmaster/issues/1959
Add "Don't show again" action to the stale cache notification.
Suppression state is stored in the database and checked on startup.
System notification is shown only on first occurrence.
Reset handler in broadcasts now also clears the suppression record.
https://github.com/safing/portmaster/issues/2061
* [service] Subscribe to systemd-resolver events
* [service] Add disabled state to the resolver
* [service] Add ETW DNS event listener
* [service] DNS listener refactoring
* [service] Add windows core dll project
* [service] DNSListener refactoring, small bugfixes
* [service] Change dns bypass rule
* [service] Update gitignore
* [service] Remove shim from integration module
* [service] Add DNS packet analyzer
* [service] Add self-check in dns monitor
* [service] Fix go linter errors
* [CI] Add github workflow for the windows core dll
* [service] Minor fixes to the dns monitor
* Move portbase into monorepo
* Add new simple module mgr
* [WIP] Switch to new simple module mgr
* Add StateMgr and more worker variants
* [WIP] Switch more modules
* [WIP] Switch more modules
* [WIP] swtich more modules
* [WIP] switch all SPN modules
* [WIP] switch all service modules
* [WIP] Convert all workers to the new module system
* [WIP] add new task system to module manager
* [WIP] Add second take for scheduling workers
* [WIP] Add FIXME for bugs in new scheduler
* [WIP] Add minor improvements to scheduler
* [WIP] Add new worker scheduler
* [WIP] Fix more bug related to new module system
* [WIP] Fix start handing of the new module system
* [WIP] Improve startup process
* [WIP] Fix minor issues
* [WIP] Fix missing subsystem in settings
* [WIP] Initialize managers in constructor
* [WIP] Move module event initialization to constrictors
* [WIP] Fix setting for enabling and disabling the SPN module
* [WIP] Move API registeration into module construction
* [WIP] Update states mgr for all modules
* [WIP] Add CmdLine operation support
* Add state helper methods to module group and instance
* Add notification and module status handling to status package
* Fix starting issues
* Remove pilot widget and update security lock to new status data
* Remove debug logs
* Improve http server shutdown
* Add workaround for cleanly shutting down firewall+netquery
* Improve logging
* Add syncing states with notifications for new module system
* Improve starting, stopping, shutdown; resolve FIXMEs/TODOs
* [WIP] Fix most unit tests
* Review new module system and fix minor issues
* Push shutdown and restart events again via API
* Set sleep mode via interface
* Update example/template module
* [WIP] Fix spn/cabin unit test
* Remove deprecated UI elements
* Make log output more similar for the logging transition phase
* Switch spn hub and observer cmds to new module system
* Fix log sources
* Make worker mgr less error prone
* Fix tests and minor issues
* Fix observation hub
* Improve shutdown and restart handling
* Split up big connection.go source file
* Move varint and dsd packages to structures repo
* Improve expansion test
* Fix linter warnings
* Fix interception module on windows
* Fix linter errors
---------
Co-authored-by: Vladimir Stoilov <vladimir@safing.io>