mirror of https://github.com/M66B/NetGuard.git
Native report fragmentation, unknown protocols
This commit is contained in:
parent
db43a95de3
commit
19b0fe25a5
|
@ -62,6 +62,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
private static final String TAG = "NetGuard.Main";
|
||||
|
||||
private boolean running = false;
|
||||
private SwitchCompat swEnabled;
|
||||
private SwipeRefreshLayout swipeRefresh;
|
||||
private AdapterRule adapter = null;
|
||||
private MenuItem menuSearch = null;
|
||||
|
@ -81,10 +82,12 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
public static final String ACTION_RULES_CHANGED = "eu.faircode.netguard.ACTION_RULES_CHANGED";
|
||||
public static final String EXTRA_SEARCH = "Search";
|
||||
public static final String EXTRA_APPROVE = "Approve";
|
||||
public static final String EXTRA_LOGCAT = "Logcat";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "Create");
|
||||
Util.logExtras(getIntent());
|
||||
|
||||
if (Build.VERSION.SDK_INT < MIN_SDK) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -114,7 +117,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
|
||||
// Action bar
|
||||
View actionView = getLayoutInflater().inflate(R.layout.action, null, false);
|
||||
SwitchCompat swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled);
|
||||
swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled);
|
||||
|
||||
getSupportActionBar().setDisplayShowCustomEnabled(true);
|
||||
getSupportActionBar().setCustomView(actionView);
|
||||
|
@ -283,19 +286,34 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
}
|
||||
|
||||
// Approve request
|
||||
if (getIntent().hasExtra(EXTRA_APPROVE) && !enabled) {
|
||||
Log.i(TAG, "Requesting VPN approval");
|
||||
swEnabled.toggle();
|
||||
}
|
||||
checkExtras(getIntent());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
Log.i(TAG, "New intent");
|
||||
Util.logExtras(intent);
|
||||
super.onNewIntent(intent);
|
||||
if (Build.VERSION.SDK_INT >= MIN_SDK)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= MIN_SDK) {
|
||||
updateApplicationList(intent.getStringExtra(EXTRA_SEARCH));
|
||||
checkExtras(intent);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkExtras(Intent intent) {
|
||||
// Approve request
|
||||
if (intent.hasExtra(EXTRA_APPROVE)) {
|
||||
Log.i(TAG, "Requesting VPN approval");
|
||||
swEnabled.toggle();
|
||||
}
|
||||
|
||||
if (intent.hasExtra(EXTRA_LOGCAT)) {
|
||||
Log.i(TAG, "Requesting logcat");
|
||||
Intent logcat = getIntentLogcat();
|
||||
if (logcat.resolveActivity(getPackageManager()) != null)
|
||||
startActivityForResult(logcat, REQUEST_LOGCAT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -120,8 +120,9 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
private static final int NOTIFY_WAITING = 2;
|
||||
private static final int NOTIFY_DISABLED = 3;
|
||||
private static final int NOTIFY_AUTOSTART = 4;
|
||||
private static final int NOTIFY_ERROR = 5;
|
||||
private static final int NOTIFY_TRAFFIC = 6;
|
||||
private static final int NOTIFY_EXIT = 5;
|
||||
private static final int NOTIFY_ERROR = 6;
|
||||
private static final int NOTIFY_TRAFFIC = 7;
|
||||
|
||||
public static final String EXTRA_COMMAND = "Command";
|
||||
private static final String EXTRA_REASON = "Reason";
|
||||
|
@ -307,7 +308,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
} catch (Throwable ex) {
|
||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
|
||||
showErrorNotification(ex.toString());
|
||||
showExitNotification(ex.toString());
|
||||
|
||||
if (!(ex instanceof IllegalStateException)) {
|
||||
// Disable firewall
|
||||
|
@ -1175,13 +1176,14 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
if (reason != null) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
prefs.edit().putBoolean("enabled", false).apply();
|
||||
showErrorNotification(reason);
|
||||
showExitNotification(reason);
|
||||
}
|
||||
}
|
||||
|
||||
// Called from native code
|
||||
private void nativeError(String message) {
|
||||
Log.e(TAG, "Native error message=" + message);
|
||||
Log.w(TAG, "Native message=" + message);
|
||||
showErrorNotification(message);
|
||||
}
|
||||
|
||||
// Called from native code
|
||||
|
@ -1693,7 +1695,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
private void showAutoStartNotification() {
|
||||
Intent main = new Intent(this, ActivityMain.class);
|
||||
main.putExtra(ActivityMain.EXTRA_APPROVE, true);
|
||||
PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
PendingIntent pi = PendingIntent.getActivity(this, NOTIFY_AUTOSTART, main, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
TypedValue tv = new TypedValue();
|
||||
getTheme().resolveAttribute(R.attr.colorOff, tv, true);
|
||||
|
@ -1717,7 +1719,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
NotificationManagerCompat.from(this).notify(NOTIFY_AUTOSTART, notification.build());
|
||||
}
|
||||
|
||||
private void showErrorNotification(String reason) {
|
||||
private void showExitNotification(String reason) {
|
||||
Intent main = new Intent(this, ActivityMain.class);
|
||||
PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
|
@ -1741,6 +1743,33 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
notification.bigText(getString(R.string.msg_error));
|
||||
notification.setSummaryText(reason);
|
||||
|
||||
NotificationManagerCompat.from(this).notify(NOTIFY_EXIT, notification.build());
|
||||
}
|
||||
|
||||
private void showErrorNotification(String message) {
|
||||
Intent main = new Intent(this, ActivityMain.class);
|
||||
main.putExtra(ActivityMain.EXTRA_LOGCAT, true);
|
||||
PendingIntent pi = PendingIntent.getActivity(this, NOTIFY_ERROR, main, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
TypedValue tv = new TypedValue();
|
||||
getTheme().resolveAttribute(R.attr.colorOff, tv, true);
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
|
||||
.setSmallIcon(R.drawable.ic_error_white_24dp)
|
||||
.setContentTitle(getString(R.string.app_name))
|
||||
.setContentText(message)
|
||||
.setContentIntent(pi)
|
||||
.setColor(tv.data)
|
||||
.setOngoing(false)
|
||||
.setAutoCancel(true);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
builder.setCategory(Notification.CATEGORY_STATUS)
|
||||
.setVisibility(Notification.VISIBILITY_SECRET);
|
||||
}
|
||||
|
||||
NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
|
||||
notification.bigText(message);
|
||||
|
||||
NotificationManagerCompat.from(this).notify(NOTIFY_ERROR, notification.build());
|
||||
}
|
||||
|
||||
|
|
|
@ -139,6 +139,7 @@ void handle_ip(const struct arguments *args,
|
|||
if (ip4hdr->frag_off & IP_MF) {
|
||||
log_android(ANDROID_LOG_ERROR, "IP fragment offset %u", ip4hdr->frag_off & IP_OFFMASK);
|
||||
flags[flen++] = '+';
|
||||
report_error(args, "TCP fragmentation");
|
||||
}
|
||||
|
||||
uint8_t ipoptlen = (uint8_t) ((ip4hdr->ihl - 5) * 4);
|
||||
|
@ -259,6 +260,9 @@ void handle_ip(const struct arguments *args,
|
|||
|
||||
// TODO checksum
|
||||
}
|
||||
else if (protocol)
|
||||
report_error(args, "Unknown protocol %d", protocol);
|
||||
|
||||
flags[flen] = 0;
|
||||
|
||||
// Limit number of sessions
|
||||
|
|
|
@ -338,6 +338,28 @@ void report_exit(const struct arguments *args, const char *fmt, ...) {
|
|||
(*args->env)->DeleteLocalRef(args->env, cls);
|
||||
}
|
||||
|
||||
void report_error(const struct arguments *args, const char *fmt, ...) {
|
||||
jclass cls = (*args->env)->GetObjectClass(args->env, args->instance);
|
||||
jmethodID mid = jniGetMethodID(args->env, cls, "nativeError", "(Ljava/lang/String;)V");
|
||||
|
||||
jstring jreason = NULL;
|
||||
if (fmt != NULL) {
|
||||
char line[1024];
|
||||
va_list argptr;
|
||||
va_start(argptr, fmt);
|
||||
vsprintf(line, fmt, argptr);
|
||||
jreason = (*args->env)->NewStringUTF(args->env, line);
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
(*args->env)->CallVoidMethod(args->env, args->instance, mid, jreason);
|
||||
jniCheckException(args->env);
|
||||
|
||||
if (jreason != NULL)
|
||||
(*args->env)->DeleteLocalRef(args->env, jreason);
|
||||
(*args->env)->DeleteLocalRef(args->env, cls);
|
||||
}
|
||||
|
||||
static jmethodID midProtect = NULL;
|
||||
|
||||
int protect_socket(const struct arguments *args, int socket) {
|
||||
|
|
|
@ -285,6 +285,8 @@ void *handle_events(void *a);
|
|||
|
||||
void report_exit(const struct arguments *args, const char *fmt, ...);
|
||||
|
||||
void report_error(const struct arguments *args, const char *fmt, ...);
|
||||
|
||||
void check_allowed(const struct arguments *args);
|
||||
|
||||
void check_icmp_sessions(const struct arguments *args, int sessions, int maxsessions);
|
||||
|
|
Loading…
Reference in New Issue