Skip to content

Commit

Permalink
Add AllowDefaultDNSResolverWithBindToDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
rod-hynes committed Jul 5, 2022
1 parent 5d41f51 commit bcc9be8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
18 changes: 13 additions & 5 deletions MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,12 @@ + (NSString * _Nullable)buildPsiphonConfig:(id _Nonnull)configObject
// Indicate whether UseNoticeFiles is set
*usingNoticeFiles = (config[@"UseNoticeFiles"] != nil);

// For iOS VPN, the standard library system resolver will automatically be
// routed outside the VPN.
if (*tunnelWholeDevice) {
config[@"AllowDefaultDNSResolverWithBindToDevice"] = @YES;
}

NSString *finalConfigStr = [[[SBJson4Writer alloc] init] stringWithObject:config];

if (finalConfigStr == nil) {
Expand Down Expand Up @@ -1242,13 +1248,15 @@ - (NSString *)bindToDevice:(long)fileDescriptor error:(NSError **)error {
}

- (NSString *)getDNSServersAsString {
// TODO: Implement correctly

if (atomic_load(&self->useInitialDNS)) {
return self->initialDNSCache;
} else {
// Alternate DNS servers will be provided by psiphon-tunnel-core
// config or tactics.
// Alternate DNS servers may be provided by psiphon-tunnel-core config
// or tactics, or the system default resolver may be used (Go on iOS
// uses the C standard library resolver via CGO, and iOS ensures
// those calls are routed outside of the VPN when invoked from a VPN
// extension).
return @"";
}
}
Expand Down Expand Up @@ -1470,11 +1478,11 @@ - (void)internetReachabilityChanged:(NSNotification *)note {
// bootstrapped. See comment in startInternetReachabilityMonitoring.
@synchronized (PsiphonTunnel.self) {
// Invalidate initialDNSCache due to limitations documented in
// getDNSServers.
// getSystemDNSServers.
//
// TODO: consider at least reverting to using the initialDNSCache when a
// new network ID matches the initial network ID -- i.e., when the device
// is back on the initial network -- even though those DNS server _may_
// is back on the initial network -- even though those DNS servers _may_
// have changed.
atomic_store(&self->useInitialDNS, FALSE);

Expand Down
7 changes: 6 additions & 1 deletion psiphon/common/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ type NetworkConfig struct {
// excluded from VPN routing. BindToDevice may be nil.
BindToDevice func(fd int) (string, error)

// AllowDefaultResolverWithBindToDevice indicates that it's safe to use
// the default resolver when BindToDevice is configured, as the host OS
// will automatically exclude DNS requests from the VPN.
AllowDefaultResolverWithBindToDevice bool

// IPv6Synthesize should apply NAT64 synthesis to the input IPv4 address,
// returning a synthesized IPv6 address that will route to the same
// endpoint. IPv6Synthesize may be nil.
Expand Down Expand Up @@ -130,7 +135,7 @@ type NetworkConfig struct {
func (c *NetworkConfig) allowDefaultResolver() bool {
// When BindToDevice is configured, the standard library resolver is not
// used, as the system resolver may not route outside of the VPN.
return c.BindToDevice == nil
return c.BindToDevice == nil || c.AllowDefaultResolverWithBindToDevice
}

func (c *NetworkConfig) logWarning(err error) {
Expand Down
5 changes: 5 additions & 0 deletions psiphon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ type Config struct {
// when reporting ClientFeatures.
DeviceBinder DeviceBinder

// AllowDefaultDNSResolverWithBindToDevice indicates that it's safe to use
// the default resolver when DeviceBinder is configured, as the host OS
// will automatically exclude DNS requests from the VPN.
AllowDefaultDNSResolverWithBindToDevice bool

// IPv6Synthesizer is an interface that allows tunnel-core to call into
// the host application to synthesize IPv6 addresses. See: IPv6Synthesizer
// doc.
Expand Down
2 changes: 2 additions & 0 deletions psiphon/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ func NewResolver(config *Config, useBindToDevice bool) *resolver.Resolver {

if useBindToDevice && config.DeviceBinder != nil {
networkConfig.BindToDevice = config.DeviceBinder.BindToDevice
networkConfig.AllowDefaultResolverWithBindToDevice =
config.AllowDefaultDNSResolverWithBindToDevice
}

if config.IPv6Synthesizer != nil {
Expand Down

0 comments on commit bcc9be8

Please sign in to comment.