mirror of https://github.com/M66B/NetGuard.git
Native set tun blocking again
This commit is contained in:
parent
ff40aff6d8
commit
02640aea4b
|
@ -25,6 +25,7 @@
|
||||||
// TODO DHCP
|
// TODO DHCP
|
||||||
// TODO log allowed traffic
|
// TODO log allowed traffic
|
||||||
// TODO fix warnings
|
// TODO fix warnings
|
||||||
|
// TODO non blocking send/write, handle EAGAIN/EWOULDBLOCK
|
||||||
|
|
||||||
// Window size < 2^31: x <= y: (uint32_t)(y-x) < 0x80000000
|
// Window size < 2^31: x <= y: (uint32_t)(y-x) < 0x80000000
|
||||||
// It is assumed that no packets will get lost and that packets arrive in order
|
// It is assumed that no packets will get lost and that packets arrive in order
|
||||||
|
@ -819,7 +820,7 @@ void handle_tcp(const struct arguments *args, const uint8_t *buffer, uint16_t le
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
if (write_ack(cur, 1 + datalen, args->tun) >= 0) {
|
if (write_ack(cur, 1 + datalen, args->tun) >= 0) {
|
||||||
cur->remote_seq += (1 + datalen); // FIN + received from tun
|
cur->remote_seq += (1 + datalen); // FIN + data from tun
|
||||||
if (cur->state == TCP_ESTABLISHED /* && !tcphdr->ack */)
|
if (cur->state == TCP_ESTABLISHED /* && !tcphdr->ack */)
|
||||||
cur->state = TCP_CLOSE_WAIT;
|
cur->state = TCP_CLOSE_WAIT;
|
||||||
else if (cur->state == TCP_FIN_WAIT1 && tcphdr->ack)
|
else if (cur->state == TCP_FIN_WAIT1 && tcphdr->ack)
|
||||||
|
@ -834,10 +835,8 @@ void handle_tcp(const struct arguments *args, const uint8_t *buffer, uint16_t le
|
||||||
dest, ntohs(cur->dest), cur->lport,
|
dest, ntohs(cur->dest), cur->lport,
|
||||||
strstate(cur->state), tcphdr->ack);
|
strstate(cur->state), tcphdr->ack);
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
// Not OK
|
|
||||||
write_rst(cur, args->tun);
|
write_rst(cur, args->tun);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Special case or hack if you like
|
// Special case or hack if you like
|
||||||
|
@ -984,9 +983,9 @@ int open_socket(const struct session *cur, const struct arguments *args) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set non blocking
|
// Set tun blocking
|
||||||
uint8_t flags = fcntl(sock, F_GETFL, 0);
|
uint8_t flags = fcntl(sock, F_GETFL, 0);
|
||||||
if (flags < 0 || fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0) {
|
if (flags < 0 || fcntl(sock, F_SETFL, flags & ~O_NONBLOCK) < 0) {
|
||||||
log_android(ANDROID_LOG_ERROR, "fcntl socket O_NONBLOCK error %d: %s",
|
log_android(ANDROID_LOG_ERROR, "fcntl socket O_NONBLOCK error %d: %s",
|
||||||
errno, strerror(errno));
|
errno, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in New Issue