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

Commit a49cc9f5 authored by Luke Huang's avatar Luke Huang Committed by Automerger Merge Worker
Browse files

Merge "Refactor DoH implementation" am: 5d811e85 am: 6bd1af11

Original change: https://android-review.googlesource.com/c/platform/packages/modules/DnsResolver/+/1745461

Change-Id: I90be14946a9032422db12bec740237ba6a290915
parents c9b3fadf 6bd1af11
Loading
Loading
Loading
Loading
+6 −3
Original line number Original line Diff line number Diff line
@@ -331,7 +331,8 @@ rust_ffi_static {
    rlibs: [
    rlibs: [
        "libandroid_logger",
        "libandroid_logger",
        "libanyhow",
        "libanyhow",
        "liblazy_static",
        "libbase64_rust",
        "libfutures",
        "liblibc",
        "liblibc",
        "liblog_rust",
        "liblog_rust",
        "libquiche",
        "libquiche",
@@ -366,7 +367,8 @@ rust_test {
    rustlibs: [
    rustlibs: [
        "libandroid_logger",
        "libandroid_logger",
        "libanyhow",
        "libanyhow",
        "liblazy_static",
        "libbase64_rust",
        "libfutures",
        "liblibc",
        "liblibc",
        "liblog_rust",
        "liblog_rust",
        "libquiche_static",
        "libquiche_static",
@@ -387,7 +389,8 @@ rust_ffi_static {
    rlibs: [
    rlibs: [
        "libandroid_logger",
        "libandroid_logger",
        "libanyhow",
        "libanyhow",
        "liblazy_static",
        "libbase64_rust",
        "libfutures",
        "liblibc",
        "liblibc",
        "liblog_rust",
        "liblog_rust",
        "libquiche_static",
        "libquiche_static",
+48 −13
Original line number Original line Diff line number Diff line
@@ -20,28 +20,63 @@


#pragma once
#pragma once


/* Generated with cbindgen:0.15.0 */
/* Generated with cbindgen:0.17.0 */


#include <stdint.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/types.h>


/// Context for a running DoH engine and associated thread.
/// The return code of doh_query means that there is no answer.
struct DohServer;
static const ssize_t RESULT_INTERNAL_ERROR = -1;


extern "C" {
/// The return code of doh_query means that query can't be sent.
static const ssize_t RESULT_CAN_NOT_SEND = -2;

/// The return code of doh_query to indicate that the query timed out.
static const ssize_t RESULT_TIMEOUT = -255;


/// Performs static initialization fo the DoH engine.
/// Context for a running DoH engine.
const char* doh_init();
struct DohDispatcher;


using ValidationCallback = void (*)(uint32_t net_id, bool success, const char* ip_addr,
                                    const char* host);

extern "C" {

/// Performs static initialization for the DoH engine.
/// Creates and returns a DoH engine instance.
/// Creates and returns a DoH engine instance.
/// The returned object must be freed with doh_delete().
DohDispatcher* doh_dispatcher_new(ValidationCallback ptr);
DohServer* doh_new(const char* url, const char* ip_addr, uint32_t mark, const char* cert_path);

/// Deletes a DoH engine created by doh_dispatcher_new().
/// # Safety
/// `doh` must be a non-null pointer previously created by `doh_dispatcher_new()`
/// and not yet deleted by `doh_dispatcher_delete()`.
void doh_dispatcher_delete(DohDispatcher* doh);

/// Probes and stores the DoH server with the given configurations.
/// Use the negative errno-style codes as the return value to represent the result.
/// # Safety
/// `doh` must be a non-null pointer previously created by `doh_dispatcher_new()`
/// and not yet deleted by `doh_dispatcher_delete()`.
/// `url`, `domain`, `ip_addr`, `cert_path` are null terminated strings.
int32_t doh_net_new(DohDispatcher* doh, uint32_t net_id, const char* url, const char* domain,
                    const char* ip_addr, uint32_t sk_mark, const char* cert_path,
                    uint64_t timeout_ms);


/// Deletes a DoH engine created by doh_new().
/// Sends a DNS query via the network associated to the given |net_id| and waits for the response.
void doh_delete(DohServer* doh);
/// The return code should be either one of the public constant RESULT_* to indicate the error or
/// the size of the answer.
/// # Safety
/// `doh` must be a non-null pointer previously created by `doh_dispatcher_new()`
/// and not yet deleted by `doh_dispatcher_delete()`.
/// `dns_query` must point to a buffer at least `dns_query_len` in size.
/// `response` must point to a buffer at least `response_len` in size.
ssize_t doh_query(DohDispatcher* doh, uint32_t net_id, uint8_t* dns_query, size_t dns_query_len,
                  uint8_t* response, size_t response_len, uint64_t timeout_ms);


/// Sends a DNS query and waits for the response.
/// Clears the DoH servers associated with the given |netid|.
ssize_t doh_query(DohServer* doh, uint8_t* query, size_t query_len, uint8_t* response,
/// # Safety
                  size_t response_len);
/// `doh` must be a non-null pointer previously created by `doh_dispatcher_new()`
/// and not yet deleted by `doh_dispatcher_delete()`.
void doh_net_delete(DohDispatcher* doh, uint32_t net_id);


}  // extern "C"
}  // extern "C"