1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2025-01-04 06:23:04 +00:00

Get uid on source port on first try

This commit is contained in:
M66B 2017-03-26 09:02:29 +02:00
parent b933887214
commit c066ae6123
2 changed files with 13 additions and 31 deletions

View file

@ -351,11 +351,11 @@ jint get_uid_retry(const int version, const int protocol,
daddr128[10] = (uint8_t) 0xFF;
daddr128[11] = (uint8_t) 0xFF;
memcpy(daddr128 + 12, daddr, 4);
uid = get_uid(6, protocol, saddr, sport, daddr128, dport, tries == UID_MAXTRY);
uid = get_uid(6, protocol, saddr, sport, daddr128, dport);
}
if (uid < 0)
uid = get_uid(version, protocol, saddr, sport, daddr, dport, tries == UID_MAXTRY);
uid = get_uid(version, protocol, saddr, sport, daddr, dport);
// Retry delay
if (uid < 0 && tries < UID_MAXTRY) {
@ -374,8 +374,7 @@ jint get_uid_retry(const int version, const int protocol,
jint get_uid(const int version, const int protocol,
const void *saddr, const uint16_t sport,
const void *daddr, const uint16_t dport,
int lasttry) {
const void *daddr, const uint16_t dport) {
char line[250];
char hex[16 * 2 + 1];
int fields;
@ -406,12 +405,6 @@ jint get_uid(const int version, const int protocol,
else
return uid;
if (lasttry) {
char dest[INET6_ADDRSTRLEN + 1];
inet_ntop(version == 4 ? AF_INET : AF_INET6, daddr, dest, sizeof(dest));
log_android(ANDROID_LOG_WARN, "Searching %u > %s/%u in %s", sport, dest, dport, fn);
}
// Open proc file
FILE *fd = fopen(fn, "r");
if (fd == NULL) {
@ -439,8 +432,9 @@ jint get_uid(const int version, const int protocol,
line,
"%*d: %*X:%X %32s:%X %*X %*lX:%*lX %*X:%*X %*X %d %*d %*ld",
&_sport, hex, &_dport, &u);
if (fields == 4 && (version == 4 ? strlen(hex) == 8 : strlen(hex) == 32)) {
if (_sport > 0 && _dport > 0 && u >= 0) {
if (_sport > 0 && u >= 0) {
hex2bytes(hex, version == 4 ? _daddr4 : _daddr6);
if (version == 4)
((uint32_t *) _daddr4)[0] = htonl(((uint32_t *) _daddr4)[0]);
@ -448,23 +442,12 @@ jint get_uid(const int version, const int protocol,
for (int w = 0; w < 4; w++)
((uint32_t *) _daddr6)[w] = htonl(((uint32_t *) _daddr6)[w]);
if (lasttry) {
char dest[INET6_ADDRSTRLEN + 1];
inet_ntop(version == 4 ? AF_INET : AF_INET6,
version == 4 ? _daddr4 : _daddr6,
dest, sizeof(dest));
log_android(ANDROID_LOG_WARN, "%u > %s/%u %d %s",
_sport, dest, _dport, u, line);
}
if (_sport == sport &&
(lasttry || (_dport == dport &&
memcmp(version == 4
? _daddr4
: _daddr6, daddr,
version == 4 ? 4 : 16) == 0))) {
if (_sport == sport) {
uid = u;
break;
if (_dport == dport &&
memcmp(version == 4 ? _daddr4 : _daddr6, daddr,
version == 4 ? 4 : 16) == 0)
break;
}
}
}

View file

@ -56,8 +56,8 @@
// https://en.wikipedia.org/wiki/Maximum_segment_lifetime
#define UID_DELAY 1 // milliseconds
#define UID_DELAYTRY 10 // milliseconds
#define UID_MAXTRY 3
#define UID_DELAYTRY 1 // milliseconds
#define UID_MAXTRY 1
#define SOCKS5_NONE 1
#define SOCKS5_HELLO 2
@ -458,8 +458,7 @@ jint get_uid_retry(const int version, const int protocol,
jint get_uid(const int version, const int protocol,
const void *saddr, const uint16_t sport,
const void *daddr, const uint16_t dport,
int lasttry);
const void *daddr, const uint16_t dport);
int protect_socket(const struct arguments *args, int socket);