Skip to content

Commit

Permalink
Added settings to filter UDP traffic
Browse files Browse the repository at this point in the history
  • Loading branch information
M66B committed May 21, 2019
1 parent 0e95b63 commit eba4e72
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public static void upgrade(boolean initialized, Context context) {

} else {
Log.i(TAG, "Initializing sdk=" + Build.VERSION.SDK_INT);
editor.putBoolean("filter_udp", true);
editor.putBoolean("whitelist_wifi", false);
editor.putBoolean("whitelist_other", false);
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,8 @@ private Allowed isAddressAllowed(Packet packet) {
lock.readLock().lock();

packet.allowed = false;
if (prefs.getBoolean("filter", false)) {
if (prefs.getBoolean("filter", false) &&
(packet.protocol != 17 || prefs.getBoolean("filter_udp", false))) {
// https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h
if (packet.uid < 2000 &&
!last_connected && isSupported(packet.protocol)) {
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/jni/netguard/ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,7 @@ jint get_uid_sub(const int version, const int protocol,
log_android(ANDROID_LOG_INFO, "uid v%d p%d %s/%u > %s/%u => %d (from cache)",
version, protocol, source, sport, dest, dport, uid_cache[i].uid);

if (protocol == IPPROTO_UDP)
return -2;
else
return uid_cache[i].uid;
return uid_cache[i].uid;
}

// Get proc file name
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<string name="setting_log_app">Log internet access</string>
<string name="setting_access">Notify on internet access</string>
<string name="setting_filter">Filter traffic</string>
<string name="setting_filter_udp">Filter UDP traffic</string>
<string name="setting_clear_onreload">Close connections on reload</string>
<string name="setting_lockdown">Lockdown traffic</string>
<string name="setting_track_usage">Track network usage</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml-v14/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
android:key="filter"
android:summary="@string/summary_filter"
android:title="@string/setting_filter" />
<CheckBoxPreference
android:defaultValue="false"
android:dependency="filter"
android:key="filter_udp"
android:title="@string/setting_filter_udp" />
<CheckBoxPreference
android:defaultValue="false"
android:dependency="filter"
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml-v21/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
android:key="filter"
android:summary="@string/summary_filter"
android:title="@string/setting_filter" />
<eu.faircode.netguard.SwitchPreference
android:defaultValue="false"
android:dependency="filter"
android:key="filter_udp"
android:title="@string/setting_filter_udp" />
<eu.faircode.netguard.SwitchPreference
android:defaultValue="false"
android:dependency="filter"
Expand Down

0 comments on commit eba4e72

Please sign in to comment.