mirror of
https://github.com/safing/portmaster
synced 2025-09-02 18:49:14 +00:00
Resolve hostname to localhost
This commit is contained in:
parent
8794d72318
commit
e092ab9831
2 changed files with 11 additions and 2 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/safing/portbase/log"
|
"github.com/safing/portbase/log"
|
||||||
|
@ -46,6 +47,12 @@ func start() error {
|
||||||
return fmt.Errorf("failed to parse nameserver listen address: %w", err)
|
return fmt.Errorf("failed to parse nameserver listen address: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hostname, err = os.Hostname()
|
||||||
|
if err != nil {
|
||||||
|
log.Warningf("nameserver: failed to get hostname: %s", err)
|
||||||
|
}
|
||||||
|
hostname += "."
|
||||||
|
|
||||||
// Start listener(s).
|
// Start listener(s).
|
||||||
if ip2 == nil {
|
if ip2 == nil {
|
||||||
// Start a single listener.
|
// Start a single listener.
|
||||||
|
|
|
@ -19,6 +19,8 @@ import (
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var hostname string
|
||||||
|
|
||||||
func handleRequestAsWorker(w dns.ResponseWriter, query *dns.Msg) {
|
func handleRequestAsWorker(w dns.ResponseWriter, query *dns.Msg) {
|
||||||
err := module.RunWorker("dns request", func(ctx context.Context) error {
|
err := module.RunWorker("dns request", func(ctx context.Context) error {
|
||||||
return handleRequest(ctx, w, query)
|
return handleRequest(ctx, w, query)
|
||||||
|
@ -87,8 +89,8 @@ func handleRequest(ctx context.Context, w dns.ResponseWriter, request *dns.Msg)
|
||||||
return reply(nsutil.Refused("unsupported qclass"))
|
return reply(nsutil.Refused("unsupported qclass"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle request for localhost.
|
// Handle request for localhost and the hostname.
|
||||||
if strings.HasSuffix(q.FQDN, "localhost.") {
|
if strings.HasSuffix(q.FQDN, "localhost.") || q.FQDN == hostname {
|
||||||
tracer.Tracef("nameserver: returning localhost records")
|
tracer.Tracef("nameserver: returning localhost records")
|
||||||
return reply(nsutil.Localhost())
|
return reply(nsutil.Localhost())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue