Native fixed get uid logging, refactoring

This commit is contained in:
M66B 2016-02-15 08:01:25 +01:00
parent c137d98dbd
commit 4ab9ebbfd8
2 changed files with 16 additions and 12 deletions

View File

@ -282,7 +282,7 @@ void handle_ip(const struct arguments *args,
if (protocol == IPPROTO_ICMP || protocol == IPPROTO_ICMPV6 || if (protocol == IPPROTO_ICMP || protocol == IPPROTO_ICMPV6 ||
(protocol == IPPROTO_UDP && !has_udp_session(args, pkt, payload)) || (protocol == IPPROTO_UDP && !has_udp_session(args, pkt, payload)) ||
(protocol == IPPROTO_TCP && syn)) (protocol == IPPROTO_TCP && syn))
uid = get_uid_retry(protocol, version, saddr, sport); uid = get_uid_retry(version, protocol, saddr, sport);
log_android(ANDROID_LOG_DEBUG, log_android(ANDROID_LOG_DEBUG,
"Packet v%d %s/%u > %s/%u proto %d flags %s uid %d", "Packet v%d %s/%u > %s/%u proto %d flags %s uid %d",
@ -337,9 +337,11 @@ void handle_ip(const struct arguments *args,
#endif #endif
} }
jint get_uid_retry(const int protocol, const int version, jint get_uid_retry(const int version, const int protocol,
const void *saddr, const uint16_t sport) { const void *saddr, const uint16_t sport) {
log_android(ANDROID_LOG_INFO, "get uid v%d p%d %s/%u", version, protocol, saddr, sport); char source[INET6_ADDRSTRLEN + 1];
inet_ntop(version == 4 ? AF_INET : AF_INET6, saddr, source, sizeof(source));
log_android(ANDROID_LOG_INFO, "get uid v%d p%d %s/%u", version, protocol, source, sport);
jint uid = -1; jint uid = -1;
int tries = 0; int tries = 0;
@ -352,29 +354,30 @@ jint get_uid_retry(const int protocol, const int version,
saddr128[10] = (uint8_t) 0xFF; saddr128[10] = (uint8_t) 0xFF;
saddr128[11] = (uint8_t) 0xFF; saddr128[11] = (uint8_t) 0xFF;
memcpy(saddr128 + 12, saddr, 4); memcpy(saddr128 + 12, saddr, 4);
uid = get_uid(protocol, 6, saddr128, sport, tries == UID_MAXTRY); uid = get_uid(6, protocol, saddr128, sport, tries == UID_MAXTRY);
} }
if (uid < 0) if (uid < 0)
uid = get_uid(protocol, version, saddr, sport, tries == UID_MAXTRY); uid = get_uid(version, protocol, saddr, sport, tries == UID_MAXTRY);
// Retry delay // Retry delay
if (uid < 0 && tries < UID_MAXTRY) { if (uid < 0 && tries < UID_MAXTRY) {
log_android(ANDROID_LOG_WARN, "get uid v%d p%d %s/%u try %d", log_android(ANDROID_LOG_WARN, "get uid v%d p%d %s/%u try %d",
version, protocol, saddr, sport, tries); version, protocol, source, sport, tries);
usleep(1000 * UID_DELAYTRY); usleep(1000 * UID_DELAYTRY);
} }
} }
if (uid < 0) if (uid < 0)
log_android(ANDROID_LOG_ERROR, "uid v%d p%d %s/%u not found", log_android(ANDROID_LOG_ERROR, "uid v%d p%d %s/%u not found",
version, protocol, saddr, sport); version, protocol, source, sport);
return uid; return uid;
} }
jint get_uid(const int protocol, const int version, jint get_uid(const int version, const int protocol,
const void *saddr, const uint16_t sport, int dump) { const void *saddr, const uint16_t sport,
int dump) {
char line[250]; char line[250];
char hex[16 * 2 + 1]; char hex[16 * 2 + 1];
int fields; int fields;

View File

@ -419,11 +419,12 @@ uint8_t char2nible(const char c);
void hex2bytes(const char *hex, uint8_t *buffer); void hex2bytes(const char *hex, uint8_t *buffer);
jint get_uid_retry(const int protocol, const int version, jint get_uid_retry(const int version, const int protocol,
const void *saddr, const uint16_t sport); const void *saddr, const uint16_t sport);
jint get_uid(const int protocol, const int version, jint get_uid(const int version, const int protocol,
const void *saddr, const uint16_t sport, int dump); const void *saddr, const uint16_t sport,
int dump);
int protect_socket(const struct arguments *args, int socket); int protect_socket(const struct arguments *args, int socket);