Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc2e41bb authored by Mike Yu's avatar Mike Yu Committed by Automerger Merge Worker
Browse files

Merge "Log UID and PID when fail to send messages to dnsproxyd" am: 0986cbb7...

Merge "Log UID and PID when fail to send messages to dnsproxyd" am: 0986cbb7 am: aef43813 am: 6a73b133

Change-Id: I1069a0bf5564418c4b17fb548f6f0d587de9d990
parents 19a6caa9 6a73b133
Loading
Loading
Loading
Loading
+30 −11
Original line number Original line Diff line number Diff line
@@ -739,21 +739,25 @@ void DnsProxyListener::GetAddrInfoHandler::run() {
    event.set_event_type(EVENT_GETADDRINFO);
    event.set_event_type(EVENT_GETADDRINFO);
    event.set_hints_ai_flags((mHints ? mHints->ai_flags : 0));
    event.set_hints_ai_flags((mHints ? mHints->ai_flags : 0));


    bool success = true;
    if (rv) {
    if (rv) {
        // getaddrinfo failed
        // getaddrinfo failed
        mClient->sendBinaryMsg(ResponseCode::DnsProxyOperationFailed, &rv, sizeof(rv));
        success = !mClient->sendBinaryMsg(ResponseCode::DnsProxyOperationFailed, &rv, sizeof(rv));
    } else {
    } else {
        bool success = !mClient->sendCode(ResponseCode::DnsProxyQueryResult);
        success = !mClient->sendCode(ResponseCode::DnsProxyQueryResult);
        addrinfo* ai = result;
        addrinfo* ai = result;
        while (ai && success) {
        while (ai && success) {
            success = sendBE32(mClient, 1) && sendaddrinfo(mClient, ai);
            success = sendBE32(mClient, 1) && sendaddrinfo(mClient, ai);
            ai = ai->ai_next;
            ai = ai->ai_next;
        }
        }
        success = success && sendBE32(mClient, 0);
        success = success && sendBE32(mClient, 0);
        if (!success) {
            LOG(WARNING) << "GetAddrInfoHandler::run: Error writing DNS result to client";
    }
    }

    if (!success) {
        PLOG(WARNING) << "GetAddrInfoHandler::run: Error writing DNS result to client uid " << uid
                      << " pid " << mClient->getPid();
    }
    }

    std::vector<std::string> ip_addrs;
    std::vector<std::string> ip_addrs;
    const int total_ip_addr_count = extractGetAddrInfoAnswers(result, &ip_addrs);
    const int total_ip_addr_count = extractGetAddrInfoAnswers(result, &ip_addrs);
    reportDnsEvent(INetdEventListener::EVENT_GETADDRINFO, mNetContext, latencyUs, rv, event, mHost,
    reportDnsEvent(INetdEventListener::EVENT_GETADDRINFO, mNetContext, latencyUs, rv, event, mHost,
@@ -958,7 +962,10 @@ void DnsProxyListener::ResNSendHandler::run() {


    // Fail, send -errno
    // Fail, send -errno
    if (nsendAns < 0) {
    if (nsendAns < 0) {
        sendBE32(mClient, nsendAns);
        if (!sendBE32(mClient, nsendAns)) {
            PLOG(WARNING) << "ResNSendHandler::run: resnsend: failed to send errno to uid " << uid
                          << " pid " << mClient->getPid();
        }
        if (rr_type == ns_t_a || rr_type == ns_t_aaaa) {
        if (rr_type == ns_t_a || rr_type == ns_t_aaaa) {
            reportDnsEvent(INetdEventListener::EVENT_RES_NSEND, mNetContext, latencyUs,
            reportDnsEvent(INetdEventListener::EVENT_RES_NSEND, mNetContext, latencyUs,
                           resNSendToAiError(nsendAns, rcode), event, rr_name);
                           resNSendToAiError(nsendAns, rcode), event, rr_name);
@@ -968,14 +975,16 @@ void DnsProxyListener::ResNSendHandler::run() {


    // Send rcode
    // Send rcode
    if (!sendBE32(mClient, rcode)) {
    if (!sendBE32(mClient, rcode)) {
        PLOG(WARNING) << "ResNSendHandler::run: resnsend: failed to send rcode to uid " << uid;
        PLOG(WARNING) << "ResNSendHandler::run: resnsend: failed to send rcode to uid " << uid
                      << " pid " << mClient->getPid();
        return;
        return;
    }
    }


    // Restore query id and send answer
    // Restore query id and send answer
    if (!setQueryId(ansBuf.data(), nsendAns, original_query_id) ||
    if (!setQueryId(ansBuf.data(), nsendAns, original_query_id) ||
        !sendLenAndData(mClient, nsendAns, ansBuf.data())) {
        !sendLenAndData(mClient, nsendAns, ansBuf.data())) {
        PLOG(WARNING) << "ResNSendHandler::run: resnsend: failed to send answer to uid " << uid;
        PLOG(WARNING) << "ResNSendHandler::run: resnsend: failed to send answer to uid " << uid
                      << " pid " << mClient->getPid();
        return;
        return;
    }
    }


@@ -1033,7 +1042,15 @@ int DnsProxyListener::GetDnsNetIdCommand::runCommand(SocketClient* cli, int argc
        netcontext.app_netid |= NETID_USE_LOCAL_NAMESERVERS;
        netcontext.app_netid |= NETID_USE_LOCAL_NAMESERVERS;
    }
    }


    return sendCodeAndBe32(cli, ResponseCode::DnsProxyQueryResult, netcontext.app_netid) ? 0 : -1;
    const bool success =
            sendCodeAndBe32(cli, ResponseCode::DnsProxyQueryResult, netcontext.app_netid);
    if (!success) {
        PLOG(WARNING)
                << "GetDnsNetIdCommand::runCommand: getdnsnetid: failed to send result to uid "
                << uid << " pid " << cli->getPid();
    }

    return success ? 0 : -1;
}
}


/*******************************************************
/*******************************************************
@@ -1165,7 +1182,8 @@ void DnsProxyListener::GetHostByNameHandler::run() {
    }
    }


    if (!success) {
    if (!success) {
        LOG(WARNING) << "GetHostByNameHandler::run: Error writing DNS result to client";
        PLOG(WARNING) << "GetHostByNameHandler::run: Error writing DNS result to client uid " << uid
                      << " pid " << mClient->getPid();
    }
    }


    std::vector<std::string> ip_addrs;
    std::vector<std::string> ip_addrs;
@@ -1327,7 +1345,8 @@ void DnsProxyListener::GetHostByAddrHandler::run() {
    }
    }


    if (!success) {
    if (!success) {
        LOG(WARNING) << "GetHostByAddrHandler::run: Error writing DNS result to client";
        PLOG(WARNING) << "GetHostByAddrHandler::run: Error writing DNS result to client uid " << uid
                      << " pid " << mClient->getPid();
    }
    }


    reportDnsEvent(INetdEventListener::EVENT_GETHOSTBYADDR, mNetContext, latencyUs, rv, event,
    reportDnsEvent(INetdEventListener::EVENT_GETHOSTBYADDR, mNetContext, latencyUs, rv, event,