Commit Graph

28 Commits

Author SHA1 Message Date
Alexandr Stelnykovych b543aba6cf fix(resolver): ask failing DNS servers last instead of skipping them
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
2026-10-21 13:49:01 +03:00
Alexandr Stelnykovych 99069f94bb fix(resolver): clear a failing DNS server when it answers the recovery check
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
2026-10-15 16:13:42 +03:00
Alexandr Stelnykovych d268851b99 fix(resolver): ask failing DNS servers when no other server can be asked
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
2026-10-15 16:13:02 +03:00
Alexandr Stelnykovych 13a86a43cc fix(nameserver; resolver): bound the wait for in-flight DNS requests on shutdown
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.
2026-10-02 17:43:59 +03:00
Alexandr Stelnykovych 0761ba7b1e fix(resolver): bind local port before pre-authenticating it (#2066)
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>
2026-09-25 17:20:36 +03:00
Alexandr Stelnykovych 176add81ce fix: use static sentinel errors instead of inline errors.New (err113)
Replace dynamic errors.New calls in worker_test.go and resolver-mdns.go
with package-level sentinel error variables to satisfy the err113 linter rule.
2026-08-14 15:15:21 +03:00
Alexandr Stelnykovych 19c71d3148 Merge pull request #2229 from safing/fix/1959-mdns
fix(resolver/mdns): fix multiple mDNS reliability and correctness issues
2026-08-14 14:50:56 +03:00
Alexandr Stelnykovych 1ab6ade246 resolver: enable HTTP/2 for DoH resolvers
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.
2026-08-14 12:56:55 +03:00
Alexandr Stelnykovych d98c726691 fix(resolver/mdns): try unicast resolvers before mDNS for .local domains
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
2026-08-12 17:56:13 +03:00
Alexandr Stelnykovych dfc7005db0 fix(resolver/mdns): fix scavenged records stored under wrong type in cache
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.
2026-08-12 17:14:58 +03:00
Alexandr Stelnykovych 687c85c4d3 fix(resolver/mdns): don't abort query on single-protocol send failure
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.
2026-08-12 16:04:17 +03:00
Alexandr Stelnykovych 5c42b4e125 fix(resolver/mdns): reject foreign responses that reuse a pending query's message ID
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
2026-08-12 14:37:05 +03:00
Alexandr Stelnykovych 1826a46a36 fix(resolver): mDNS 1s latency on every cache-miss query
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
2026-08-12 11:07:22 +03:00
Alexandr Stelnykovych 7fca633cd8 test(resolver): TestResolveIPAndValidate fix 2026-04-13 18:17:20 +03:00
Alexandr Stelnykovych 0c83c5c1b9 test(resolver): refresh public suffix expectations after x/net PSL update 2026-04-13 17:22:14 +03:00
Alexandr Stelnykovych d07da4e350 feat(resolver): persist stale cache notification suppression
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
2026-03-10 00:18:53 +02:00
Alexandr Stelnykovych 58f4058633 v2 tests fix (#1956)
* v2 tests fix
* test: added tests for sqlite
2025-08-07 02:04:38 +03:00
Alexandr Stelnykovych 6c98755c77 fix: Deadlock in TCP resolver 2025-05-07 17:33:55 +03:00
Daniel Hååvi 03da033cd2 Only use stale dns cache entries when the query result was successful
(cherry picked from commit f233a56eea)
2025-05-07 17:30:36 +03:00
Vladimir Stoilov 5039e9efca Merge branch 'develop' into feature/new-installer 2025-01-14 16:59:21 +02:00
Alexandr Stelnykovych 692838b696 [fix] Logical mistake while determining local resolvers 2024-12-13 17:02:38 +02:00
Vladimir Stoilov 374c1c2748 Merge branch 'develop' into feature/new-installer 2024-11-28 13:23:13 +02:00
Vladimir Stoilov 1a1bc14804 Feature/systemd query events (#1728)
* [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
2024-11-27 17:10:47 +02:00
Daniel 0f3f3c360f [WIP] Simplify update system 2024-10-31 16:38:12 +01:00
Vladimir Stoilov a874ec9412 [WIP] Fix unit tests 2024-10-08 14:13:08 +03:00
Daniel Hååvi 80664d1a27 Restructure modules (#1572)
* 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>
2024-08-09 18:15:48 +03:00
Daniel 42e725921b Add option to DNS server to ignore them when they are not available via an interface network 2024-07-03 17:17:51 +02:00
Patrick Pacher 8579430db9 wip: migrate to mono-repo. SPN has already been moved to spn/ 2024-03-20 09:45:32 +01:00