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

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

Test: Add a DoH test for RESET_STREAM am: e9ff0021 am: e7eb4bab

parents 05b7b4e3 e7eb4bab
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -103,6 +103,11 @@ bool frontend_set_max_streams_bidi(DohFrontend* doh, uint64_t value);
/// Sets the `DohFrontend` to block or unblock sending any data.
bool frontend_block_sending(DohFrontend* doh, bool block);

/// If this function is called, the `DohFrontend` will send RESET_STREAM frame as a response
/// instead of a DoH answer on the stream |stream_id|. This will make the client fail to receive
/// this DoH answer.
bool frontend_set_reset_stream_id(DohFrontend* doh, uint64_t stream_id);

/// Gets the statistics of the `DohFrontend` and writes the result to |out|.
bool frontend_stats(DohFrontend* doh, Stats* out);

+13 −1
Original line number Diff line number Diff line
@@ -127,7 +127,11 @@ impl Client {
    }

    // Converts the clear-text DNS response to a DoH response, and sends it to the quiche.
    pub fn handle_backend_message(&mut self, response: &[u8]) -> Result<()> {
    pub fn handle_backend_message(
        &mut self,
        response: &[u8],
        send_reset_stream: Option<u64>,
    ) -> Result<()> {
        ensure!(self.h3_conn.is_some(), "HTTP/3 connection not created");
        ensure!(response.len() >= DNS_HEADER_SIZE, "Insufficient bytes of DNS response");

@@ -146,6 +150,14 @@ impl Client {
            .remove(&[response[0], response[1]])
            .ok_or_else(|| anyhow!("query_id {:x} not found", query_id))?;

        if let Some(send_reset_stream) = send_reset_stream {
            if send_reset_stream == stream_id {
                self.conn.stream_shutdown(stream_id, quiche::Shutdown::Write, 99)?;
                info!("Preparing RESET_FRAME on stream {}", stream_id);
                return Ok(());
            }
        }

        info!("Preparing HTTP/3 response {:?} on stream {}", headers, stream_id);

        h3_conn.send_response(&mut self.conn, stream_id, &headers, false)?;
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ pub struct Config {
    pub max_idle_timeout: u64,
    pub max_buffer_size: u64,
    pub max_streams_bidi: u64,
    pub reset_stream_id: Option<u64>,
}

impl Config {
+7 −1
Original line number Diff line number Diff line
@@ -187,6 +187,11 @@ impl DohFrontend {
        Ok(())
    }

    pub fn set_reset_stream_id(&self, value: u64) -> Result<()> {
        self.config.lock().unwrap().reset_stream_id = Some(value);
        Ok(())
    }

    pub fn request_stats(&mut self) -> Result<Stats> {
        ensure!(
            self.command_tx.is_some(),
@@ -360,7 +365,8 @@ async fn worker_thread(params: WorkerParams) -> Result<()> {
                let query_id = [backend_buf[0], backend_buf[1]];
                for (_, client) in clients.iter_mut() {
                    if client.is_waiting_for_query(&query_id) {
                        if let Err(e) = client.handle_backend_message(&backend_buf[..len]) {
                        let reset_stream_id = config.lock().unwrap().reset_stream_id;
                        if let Err(e) = client.handle_backend_message(&backend_buf[..len], reset_stream_id) {
                            error!("Failed to handle message from backend: {}", e);
                        }
                        let connection_id = client.connection_id().clone();
+8 −0
Original line number Diff line number Diff line
@@ -153,6 +153,14 @@ pub extern "C" fn frontend_block_sending(doh: &mut DohFrontend, block: bool) ->
    doh.block_sending(block).or_else(logging_and_return_err).is_ok()
}

/// If this function is called, the `DohFrontend` will send RESET_STREAM frame as a response
/// instead of a DoH answer on the stream |stream_id|. This will make the client fail to receive
/// this DoH answer.
#[no_mangle]
pub extern "C" fn frontend_set_reset_stream_id(doh: &mut DohFrontend, stream_id: u64) -> bool {
    doh.set_reset_stream_id(stream_id).or_else(logging_and_return_err).is_ok()
}

/// Gets the statistics of the `DohFrontend` and writes the result to |out|.
#[no_mangle]
pub extern "C" fn frontend_stats(doh: &mut DohFrontend, out: &mut Stats) -> bool {
Loading