Set search domain for systemd-resolved

This commit is contained in:
世界 2023-03-26 16:09:24 +08:00
parent 980d4bf9a3
commit 8848c0e4cb
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -5,6 +5,7 @@ import (
"net" "net"
"net/netip" "net/netip"
"os" "os"
"os/exec"
"runtime" "runtime"
"syscall" "syscall"
"unsafe" "unsafe"
@ -13,6 +14,7 @@ import (
"github.com/sagernet/sing/common" "github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions" E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/rw" "github.com/sagernet/sing/common/rw"
"github.com/sagernet/sing/common/shell"
"github.com/sagernet/sing/common/x/list" "github.com/sagernet/sing/common/x/list"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@ -165,6 +167,8 @@ func (t *NativeTun) configure(tunLink netlink.Link) error {
return err return err
} }
setSearchDomainForSystemdResolved(t.options.Name)
if t.options.AutoRoute && runtime.GOOS == "android" { if t.options.AutoRoute && runtime.GOOS == "android" {
t.interfaceCallback = t.options.InterfaceMonitor.RegisterCallback(t.routeUpdate) t.interfaceCallback = t.options.InterfaceMonitor.RegisterCallback(t.routeUpdate)
} }
@ -594,3 +598,11 @@ func (t *NativeTun) routeUpdate(event int) error {
} }
return nil return nil
} }
func setSearchDomainForSystemdResolved(interfaceName string) {
ctlPath, err := exec.LookPath("resolvectl")
if err != nil {
return
}
shell.Exec(ctlPath, "domain", interfaceName, "~.").Run()
}