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

Bypass LAN and reserved subnets in the VPN #311

Merged
merged 8 commits into from
Oct 16, 2018
Merged

Conversation

alalamav
Copy link
Contributor

@alalamav alalamav commented Oct 9, 2018

  • Excludes special registry subnets from the VPN. This includes LAN and reserved subnets.
    • Apple: NetworkExtension APIs support excluding subnets from the VPN.
    • Android: VpnService APIs support only subnet inclusion, so we have computed the subnet compliment of the reserved subnets.
    • Windows: OutlineService adds direct routes to the default gateway for the bypassed subnets.

@alalamav alalamav self-assigned this Oct 9, 2018
@alalamav alalamav requested review from bemasc and trevj October 9, 2018 16:31
// retrieve the list of subnets that excludes those reserved for special use.
final ArrayList<Subnet> reservedBypassSubnets = getReservedBypassSubnets();
for (Subnet subnet : reservedBypassSubnets) {
builder.addRoute(subnet.address, subnet.prefix);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be builder = builder.addRoute(...)? (I expect it works either way.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary to get the builder reference - works as is.

/* Returns a subnet list that excludes reserved subnets. */
private ArrayList<Subnet> getReservedBypassSubnets() {
final String[] subnetStrings = vpnService.getResources().getStringArray(
vpnService.getResourceId(PRIVATE_LAN_BYPASS_SUBNETS_ID, "array"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand, why isn't this just R.array.reserved_bypass_subnets or whatever?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, we cannot access the generated R class from Cordova plugins. Therefore we resort to retrieving resources via the Resources class.

private ArrayList<Subnet> getReservedBypassSubnets() {
final String[] subnetStrings = vpnService.getResources().getStringArray(
vpnService.getResourceId(PRIVATE_LAN_BYPASS_SUBNETS_ID, "array"));
ArrayList<Subnet> subnets = new ArrayList<Subnet>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like people generally prefer to omit the second type (new ArrayList<>()) and include an initial capacity (new ArrayList<>(subnetStrings.length)).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -157,4 +167,42 @@ public void disconnectTunnel() {
private String selectDnsResolverAddress() {
return DNS_RESOLVER_IP_ADDRESSES[new Random().nextInt(DNS_RESOLVER_IP_ADDRESSES.length)];
}

/* Returns a subnet list that excludes reserved subnets. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixing comment styles is odd.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been using /**/ for method and class level comments, and // for comments in the code. I can change them all to long comments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, I would recommend using /** */ in Javadoc style.

@@ -530,7 +530,7 @@ private void startForegroundWithNotification(
builder = new Notification.Builder(this);
}
try {
builder.setSmallIcon(getResourceIdForDrawable("small_icon"));
builder.setSmallIcon(getResourceId("small_icon", "drawable"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just R.drawable.small_icon?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See answer above.

public func IPv4String() -> String {
let ip = self
let byte1 = UInt8(ip & 0xff)
let byte2 = UInt8((ip>>8) & 0xff)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces around >>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

let byte2 = UInt8((ip>>8) & 0xff)
let byte3 = UInt8((ip>>16) & 0xff)
let byte4 = UInt8((ip>>24) & 0xff)
return "\(byte1).\(byte2).\(byte3).\(byte4)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This order is backwards compared to the way we normally handle IPv4 addresses. Assuming it's correct, it deserves a comment explaining why it's backwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! It was backwards, now fixed.

@alalamav
Copy link
Contributor Author

alalamav commented Oct 9, 2018

Thank you both for the review! I have addressed your comments, PTAL.

Copy link
Contributor

@trevj trevj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved for Windows!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants