-
-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract private upstream for iOS and fix function headers for other OS
- Loading branch information
1 parent
5f96c56
commit ad1cf38
Showing
8 changed files
with
68 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |