mirror of https://github.com/M66B/NetGuard.git
Native uid retry, ignore unknown sessions
This commit is contained in:
parent
49b15e261d
commit
12c74b24ab
|
@ -34,7 +34,8 @@
|
||||||
#define TCPTIMEOUT 300 // seconds ~net.inet.tcp.keepidle
|
#define TCPTIMEOUT 300 // seconds ~net.inet.tcp.keepidle
|
||||||
#define TCPTTL 64
|
#define TCPTTL 64
|
||||||
#define TCPWINDOW 32768
|
#define TCPWINDOW 32768
|
||||||
#define UIDDELAY 10 // milliseconds
|
#define UIDDELAY 100 // milliseconds
|
||||||
|
#define UIDTRIES 10
|
||||||
#define MAXPCAP 80
|
#define MAXPCAP 80
|
||||||
|
|
||||||
struct arguments {
|
struct arguments {
|
||||||
|
@ -659,19 +660,22 @@ void handle_ip(JNIEnv *env, jobject instance, const struct arguments *args,
|
||||||
// Get uid
|
// Get uid
|
||||||
jint uid = -1;
|
jint uid = -1;
|
||||||
if ((protocol == IPPROTO_TCP && syn) || protocol == IPPROTO_UDP) {
|
if ((protocol == IPPROTO_TCP && syn) || protocol == IPPROTO_UDP) {
|
||||||
// Sleep 10 ms
|
int tries = 0;
|
||||||
// TODO uid retry
|
while (tries++ < UIDTRIES && uid < 0) {
|
||||||
usleep(1000 * UIDDELAY);
|
// Lookup uid
|
||||||
|
uid = getUid(protocol, version, saddr, sport);
|
||||||
// Lookup uid
|
if (uid < 0 && version == 4) {
|
||||||
uid = getUid(protocol, version, saddr, sport);
|
int8_t saddr128[16];
|
||||||
if (uid < 0 && version == 4) {
|
memset(saddr128, 0, 10);
|
||||||
int8_t saddr128[16];
|
saddr128[10] = 0xFF;
|
||||||
memset(saddr128, 0, 10);
|
saddr128[11] = 0xFF;
|
||||||
saddr128[10] = 0xFF;
|
memcpy(saddr128 + 12, saddr, 4);
|
||||||
saddr128[11] = 0xFF;
|
uid = getUid(protocol, 6, saddr128, sport);
|
||||||
memcpy(saddr128 + 12, saddr, 4);
|
}
|
||||||
uid = getUid(protocol, 6, saddr128, sport);
|
if (uid < 0 && tries < UIDTRIES) {
|
||||||
|
ng_log("get uid try %d", tries);
|
||||||
|
usleep(1000 * UIDDELAY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -753,7 +757,7 @@ void handle_tcp(JNIEnv *env, jobject instance, const struct arguments *args,
|
||||||
|
|
||||||
if (cur == NULL) {
|
if (cur == NULL) {
|
||||||
if (tcphdr->syn) {
|
if (tcphdr->syn) {
|
||||||
ng_log(ANDROID_LOG_DEBUG, "New SYN");
|
ng_log(ANDROID_LOG_INFO, "New session %s/%u uid %d", dest, ntohs(tcphdr->dest), uid);
|
||||||
|
|
||||||
// Register session
|
// Register session
|
||||||
struct session *syn = malloc(sizeof(struct session));
|
struct session *syn = malloc(sizeof(struct session));
|
||||||
|
@ -799,6 +803,7 @@ void handle_tcp(JNIEnv *env, jobject instance, const struct arguments *args,
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ng_log(ANDROID_LOG_WARN, "Unknown session");
|
ng_log(ANDROID_LOG_WARN, "Unknown session");
|
||||||
|
/*
|
||||||
struct session rst;
|
struct session rst;
|
||||||
memset(&rst, 0, sizeof(struct session));
|
memset(&rst, 0, sizeof(struct session));
|
||||||
rst.saddr = iphdr->saddr;
|
rst.saddr = iphdr->saddr;
|
||||||
|
@ -810,6 +815,7 @@ void handle_tcp(JNIEnv *env, jobject instance, const struct arguments *args,
|
||||||
ng_log(ANDROID_LOG_ERROR,
|
ng_log(ANDROID_LOG_ERROR,
|
||||||
"write RST error %d: %s",
|
"write RST error %d: %s",
|
||||||
errno, strerror((errno)));
|
errno, strerror((errno)));
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue