mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-23 02:36:42 +00:00
Extract private upstream for iOS and fix function headers for other OS
This commit is contained in:
@@ -138,7 +138,7 @@ func prepareResolvConfContent(searchDomains, nameServers, others []string) bytes
|
|||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
func searchDomains(config hostDNSConfig) []string {
|
func searchDomains(config HostDNSConfig) []string {
|
||||||
listOfDomains := make([]string, 0)
|
listOfDomains := make([]string, 0)
|
||||||
for _, dConf := range config.domains {
|
for _, dConf := range config.domains {
|
||||||
if dConf.matchOnly || dConf.disabled {
|
if dConf.matchOnly || dConf.disabled {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package dns
|
|||||||
type androidHostManager struct {
|
type androidHostManager struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newHostManager(wgInterface WGIface) (hostManager, error) {
|
func newHostManager(wgInterface WGIface, dnsManager IosDnsManager) (hostManager, error) {
|
||||||
return &androidHostManager{}, nil
|
return &androidHostManager{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ type systemConfigurator struct {
|
|||||||
createdKeys map[string]struct{}
|
createdKeys map[string]struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newHostManager(_ WGIface) (hostManager, error) {
|
func newHostManager(_ WGIface, dnsManager IosDnsManager) (hostManager, error) {
|
||||||
return &systemConfigurator{
|
return &systemConfigurator{
|
||||||
createdKeys: make(map[string]struct{}),
|
createdKeys: make(map[string]struct{}),
|
||||||
}, nil
|
}, nil
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const (
|
|||||||
|
|
||||||
type osManagerType int
|
type osManagerType int
|
||||||
|
|
||||||
func newHostManager(wgInterface WGIface) (hostManager, error) {
|
func newHostManager(wgInterface WGIface, dnsManager IosDnsManager) (hostManager, error) {
|
||||||
osManager, err := getOSDNSManagerType()
|
osManager, err := getOSDNSManagerType()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ type registryConfigurator struct {
|
|||||||
routingAll bool
|
routingAll bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newHostManager(wgInterface WGIface) (hostManager, error) {
|
func newHostManager(wgInterface WGIface, dnsManager IosDnsManager) (hostManager, error) {
|
||||||
guid, err := wgInterface.GetInterfaceGUIDString()
|
guid, err := wgInterface.GetInterfaceGUIDString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -8,13 +8,11 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cenkalti/backoff/v4"
|
"github.com/cenkalti/backoff/v4"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -85,38 +83,6 @@ func newUpstreamResolver(parentCTX context.Context, interfaceName string, wgAddr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// getClientPrivate returns a new DNS client bound to the local IP address of the Netbird interface
|
|
||||||
// This method is needed for iOS
|
|
||||||
func (u *upstreamResolver) getClientPrivate() *dns.Client {
|
|
||||||
dialer := &net.Dialer{
|
|
||||||
LocalAddr: &net.UDPAddr{
|
|
||||||
IP: u.lIP,
|
|
||||||
Port: 0, // Let the OS pick a free port
|
|
||||||
},
|
|
||||||
Timeout: upstreamTimeout,
|
|
||||||
Control: func(network, address string, c syscall.RawConn) error {
|
|
||||||
var operr error
|
|
||||||
fn := func(s uintptr) {
|
|
||||||
operr = unix.SetsockoptInt(int(s), unix.IPPROTO_IP, unix.IP_BOUND_IF, u.iIndex)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.Control(fn); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if operr != nil {
|
|
||||||
log.Errorf("error while setting socket option: %s", operr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return operr
|
|
||||||
},
|
|
||||||
}
|
|
||||||
client := &dns.Client{
|
|
||||||
Dialer: dialer,
|
|
||||||
}
|
|
||||||
return client
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *upstreamResolver) stop() {
|
func (u *upstreamResolver) stop() {
|
||||||
log.Debugf("stopping serving DNS for upstreams %s", u.upstreamServers)
|
log.Debugf("stopping serving DNS for upstreams %s", u.upstreamServers)
|
||||||
u.cancel()
|
u.cancel()
|
||||||
|
|||||||
44
client/internal/dns/upstream_ios.go
Normal file
44
client/internal/dns/upstream_ios.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
//go:build ios
|
||||||
|
|
||||||
|
package dns
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/miekg/dns"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
|
// getClientPrivate returns a new DNS client bound to the local IP address of the Netbird interface
|
||||||
|
// This method is needed for iOS
|
||||||
|
func (u *upstreamResolver) getClientPrivate() *dns.Client {
|
||||||
|
dialer := &net.Dialer{
|
||||||
|
LocalAddr: &net.UDPAddr{
|
||||||
|
IP: u.lIP,
|
||||||
|
Port: 0, // Let the OS pick a free port
|
||||||
|
},
|
||||||
|
Timeout: upstreamTimeout,
|
||||||
|
Control: func(network, address string, c syscall.RawConn) error {
|
||||||
|
var operr error
|
||||||
|
fn := func(s uintptr) {
|
||||||
|
operr = unix.SetsockoptInt(int(s), unix.IPPROTO_IP, unix.IP_BOUND_IF, u.iIndex)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.Control(fn); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if operr != nil {
|
||||||
|
log.Errorf("error while setting socket option: %s", operr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return operr
|
||||||
|
},
|
||||||
|
}
|
||||||
|
client := &dns.Client{
|
||||||
|
Dialer: dialer,
|
||||||
|
}
|
||||||
|
return client
|
||||||
|
}
|
||||||
19
client/internal/dns/upstream_nonios.go
Normal file
19
client/internal/dns/upstream_nonios.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
//go:build !ios
|
||||||
|
|
||||||
|
package dns
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"github.com/miekg/dns"
|
||||||
|
)
|
||||||
|
|
||||||
|
// getClientPrivate returns a new DNS client bound to the local IP address of the Netbird interface
|
||||||
|
// This method is needed for iOS
|
||||||
|
func (u *upstreamResolver) getClientPrivate() *dns.Client {
|
||||||
|
dialer := &net.Dialer{}
|
||||||
|
client := &dns.Client{
|
||||||
|
Dialer: dialer,
|
||||||
|
}
|
||||||
|
return client
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user