Skip to content

Commit

Permalink
Auto enable limited subnet routing on custom private DNS
Browse files Browse the repository at this point in the history
  • Loading branch information
M66B committed Feb 23, 2021
1 parent 93cd200 commit aacd96d
Showing 1 changed file with 64 additions and 53 deletions.
117 changes: 64 additions & 53 deletions app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,16 @@ private Builder getBuilder(List<Rule> listAllowed, List<Rule> listRule) {
}
}

boolean calling = true;
String dns_specifier = Util.getPrivateDnsSpecifier(ServiceSinkhole.this);
if (!filter && !subnet && !TextUtils.isEmpty(dns_specifier)) {
subnet = true;
tethering = false;
lan = false;
calling = false;
// always exclude broadcast
}

// Subnet routing
if (subnet) {
// Exclude IP ranges
Expand Down Expand Up @@ -1302,7 +1312,6 @@ private Builder getBuilder(List<Rule> listAllowed, List<Rule> listRule) {
if (dns instanceof Inet4Address)
listExclude.add(new IPUtil.CIDR(dns.getHostAddress(), 32));

String dns_specifier = Util.getPrivateDnsSpecifier(ServiceSinkhole.this);
if (!TextUtils.isEmpty(dns_specifier))
try {
Log.i(TAG, "Resolving private dns=" + dns_specifier);
Expand All @@ -1314,58 +1323,60 @@ private Builder getBuilder(List<Rule> listAllowed, List<Rule> listRule) {
}
}

// https://en.wikipedia.org/wiki/Mobile_country_code
Configuration config = getResources().getConfiguration();

// T-Mobile Wi-Fi calling
if (config.mcc == 310 && (config.mnc == 160 ||
config.mnc == 200 ||
config.mnc == 210 ||
config.mnc == 220 ||
config.mnc == 230 ||
config.mnc == 240 ||
config.mnc == 250 ||
config.mnc == 260 ||
config.mnc == 270 ||
config.mnc == 310 ||
config.mnc == 490 ||
config.mnc == 660 ||
config.mnc == 800)) {
listExclude.add(new IPUtil.CIDR("66.94.2.0", 24));
listExclude.add(new IPUtil.CIDR("66.94.6.0", 23));
listExclude.add(new IPUtil.CIDR("66.94.8.0", 22));
listExclude.add(new IPUtil.CIDR("208.54.0.0", 16));
}

// Verizon wireless calling
if ((config.mcc == 310 &&
(config.mnc == 4 ||
config.mnc == 5 ||
config.mnc == 6 ||
config.mnc == 10 ||
config.mnc == 12 ||
config.mnc == 13 ||
config.mnc == 350 ||
config.mnc == 590 ||
config.mnc == 820 ||
config.mnc == 890 ||
config.mnc == 910)) ||
(config.mcc == 311 && (config.mnc == 12 ||
config.mnc == 110 ||
(config.mnc >= 270 && config.mnc <= 289) ||
config.mnc == 390 ||
(config.mnc >= 480 && config.mnc <= 489) ||
config.mnc == 590)) ||
(config.mcc == 312 && (config.mnc == 770))) {
listExclude.add(new IPUtil.CIDR("66.174.0.0", 16)); // 66.174.0.0 - 66.174.255.255
listExclude.add(new IPUtil.CIDR("66.82.0.0", 15)); // 69.82.0.0 - 69.83.255.255
listExclude.add(new IPUtil.CIDR("69.96.0.0", 13)); // 69.96.0.0 - 69.103.255.255
listExclude.add(new IPUtil.CIDR("70.192.0.0", 11)); // 70.192.0.0 - 70.223.255.255
listExclude.add(new IPUtil.CIDR("97.128.0.0", 9)); // 97.128.0.0 - 97.255.255.255
listExclude.add(new IPUtil.CIDR("174.192.0.0", 9)); // 174.192.0.0 - 174.255.255.255
listExclude.add(new IPUtil.CIDR("72.96.0.0", 9)); // 72.96.0.0 - 72.127.255.255
listExclude.add(new IPUtil.CIDR("75.192.0.0", 9)); // 75.192.0.0 - 75.255.255.255
listExclude.add(new IPUtil.CIDR("97.0.0.0", 10)); // 97.0.0.0 - 97.63.255.255
if (calling) {
// https://en.wikipedia.org/wiki/Mobile_country_code
Configuration config = getResources().getConfiguration();

// T-Mobile Wi-Fi calling
if (config.mcc == 310 && (config.mnc == 160 ||
config.mnc == 200 ||
config.mnc == 210 ||
config.mnc == 220 ||
config.mnc == 230 ||
config.mnc == 240 ||
config.mnc == 250 ||
config.mnc == 260 ||
config.mnc == 270 ||
config.mnc == 310 ||
config.mnc == 490 ||
config.mnc == 660 ||
config.mnc == 800)) {
listExclude.add(new IPUtil.CIDR("66.94.2.0", 24));
listExclude.add(new IPUtil.CIDR("66.94.6.0", 23));
listExclude.add(new IPUtil.CIDR("66.94.8.0", 22));
listExclude.add(new IPUtil.CIDR("208.54.0.0", 16));
}

// Verizon wireless calling
if ((config.mcc == 310 &&
(config.mnc == 4 ||
config.mnc == 5 ||
config.mnc == 6 ||
config.mnc == 10 ||
config.mnc == 12 ||
config.mnc == 13 ||
config.mnc == 350 ||
config.mnc == 590 ||
config.mnc == 820 ||
config.mnc == 890 ||
config.mnc == 910)) ||
(config.mcc == 311 && (config.mnc == 12 ||
config.mnc == 110 ||
(config.mnc >= 270 && config.mnc <= 289) ||
config.mnc == 390 ||
(config.mnc >= 480 && config.mnc <= 489) ||
config.mnc == 590)) ||
(config.mcc == 312 && (config.mnc == 770))) {
listExclude.add(new IPUtil.CIDR("66.174.0.0", 16)); // 66.174.0.0 - 66.174.255.255
listExclude.add(new IPUtil.CIDR("66.82.0.0", 15)); // 69.82.0.0 - 69.83.255.255
listExclude.add(new IPUtil.CIDR("69.96.0.0", 13)); // 69.96.0.0 - 69.103.255.255
listExclude.add(new IPUtil.CIDR("70.192.0.0", 11)); // 70.192.0.0 - 70.223.255.255
listExclude.add(new IPUtil.CIDR("97.128.0.0", 9)); // 97.128.0.0 - 97.255.255.255
listExclude.add(new IPUtil.CIDR("174.192.0.0", 9)); // 174.192.0.0 - 174.255.255.255
listExclude.add(new IPUtil.CIDR("72.96.0.0", 9)); // 72.96.0.0 - 72.127.255.255
listExclude.add(new IPUtil.CIDR("75.192.0.0", 9)); // 75.192.0.0 - 75.255.255.255
listExclude.add(new IPUtil.CIDR("97.0.0.0", 10)); // 97.0.0.0 - 97.63.255.255
}
}

// Broadcast
Expand Down

0 comments on commit aacd96d

Please sign in to comment.