Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: change defaultNS of SystemDns and add log for reading system dns error #749

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/daeuniverse/dae/cmd/internal"
"github.com/daeuniverse/dae/common"
"github.com/daeuniverse/dae/common/consts"
"github.com/daeuniverse/dae/common/netutils"
"github.com/daeuniverse/dae/common/subscription"
"github.com/daeuniverse/dae/config"
"github.com/daeuniverse/dae/control"
Expand Down Expand Up @@ -249,6 +250,7 @@ loop:
logger.SetLogger(logrus.StandardLogger(), newConf.Global.LogLevel, disableTimestamp, nil)
log.SetOutput(oldLogOutput) // FIXME: THIS IS A HACK.
logrus.SetOutput(oldLogOutput)
netutils.SetLogger(log)

// New control plane.
obj := c.EjectBpf()
Expand Down
3 changes: 3 additions & 0 deletions common/netutils/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func tryUpdateSystemDnsElapse(k time.Duration) (err error) {

func tryUpdateSystemDns() (err error) {
dnsConf := dnsReadConfig("/etc/resolv.conf")
if dnsConf.err != nil {
logger.WithError(err).Warnln("dnsReadConfig(\"/etc/resolv.conf\")")
}
systemDns = netip.AddrPort{}
for _, s := range dnsConf.servers {
ipPort := netip.MustParseAddrPort(s)
Expand Down
4 changes: 3 additions & 1 deletion common/netutils/dnsconfig_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package netutils

import (
"bufio"
"fmt"
"net"
"net/netip"
"os"
Expand All @@ -27,7 +28,7 @@ import (
)

var (
defaultNS = []string{"127.0.0.1:53", "[::1]:53"}
defaultNS = []string{"119.29.29.29:53", "[2400:3200::1, 2400:3200:baba::1]:53"}
getHostname = os.Hostname // variable for testing
)

Expand Down Expand Up @@ -159,6 +160,7 @@ func dnsReadConfig(filename string) *dnsConfig {
}
if len(conf.servers) == 0 {
conf.servers = defaultNS
conf.err = fmt.Errorf("no servers read")
}
if len(conf.search) == 0 {
conf.search = dnsDefaultSearch()
Expand Down
19 changes: 7 additions & 12 deletions common/netutils/ip46.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/daeuniverse/outbound/netproxy"
dnsmessage "github.com/miekg/dns"
"github.com/sirupsen/logrus"
)

type Ip46 struct {
Expand All @@ -23,17 +22,13 @@ type Ip46 struct {
}

func ResolveIp46(ctx context.Context, dialer netproxy.Dialer, dns netip.AddrPort, host string, network string, race bool) (ipv46 *Ip46, err error) {
var log *logrus.Logger
if _log := ctx.Value("logger"); _log != nil {
log = _log.(*logrus.Logger)
defer func() {
if err == nil {
log.Tracef("ResolveIp46 %v using %v: A(%v) AAAA(%v)", host, systemDns, ipv46.Ip4, ipv46.Ip6)
} else {
log.Tracef("ResolveIp46 %v using %v: %v", host, systemDns, err)
}
}()
}
defer func() {
if err == nil {
logger.Tracef("ResolveIp46 %v using %v: A(%v) AAAA(%v)", host, systemDns, ipv46.Ip4, ipv46.Ip6)
} else {
logger.Tracef("ResolveIp46 %v using %v: %v", host, systemDns, err)
}
}()
var wg sync.WaitGroup
wg.Add(2)
var err4, err6 error
Expand Down
16 changes: 16 additions & 0 deletions common/netutils/netutils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) 2022-2025, daeuniverse Organization <[email protected]>
*/

package netutils

import "github.com/sirupsen/logrus"

var (
logger = logrus.StandardLogger()
)

func SetLogger(l *logrus.Logger) {
logger = l
}
1 change: 0 additions & 1 deletion component/outbound/dialer/connectivity_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ func (c *TcpCheckOptionRaw) Option() (opt *TcpCheckOption, err error) {
if c.opt == nil {
ctx, cancel := context.WithTimeout(context.TODO(), Timeout)
defer cancel()
ctx = context.WithValue(ctx, "logger", c.Log)
tcpCheckOption, err := ParseTcpCheckOption(ctx, c.Raw, c.Method, c.ResolverNetwork)
if err != nil {
return nil, fmt.Errorf("failed to parse tcp_check_url: %w", err)
Expand Down
Loading