Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a new base module #474

Draft
wants to merge 78 commits into
base: main
Choose a base branch
from
Draft

Introduce a new base module #474

wants to merge 78 commits into from

Conversation

bal-e
Copy link
Contributor

@bal-e bal-e commented Dec 26, 2024

This introduces a new_base module as a potential candidate for replacing base. While it has a similar structure (although much is left to be filled out), it has three distinguishing features:

  1. It builds the foundation for a derive-based interface for easily and efficiently parsing (and possibly building) DNS messages.

  2. It introduces RevName, a more efficient type for domain names (where labels are stored in reverse order).

There's a lot more work to be done:

  • Define some record data types (probably those from RFC1035).
  • Define the OPT record data, and some EDNS option types.
  • Define some common message structures (including a generic fallback).
  • Update existing parts of the codebase to show the PR's benefits.
    • The client transports (... while remaining compatible?).
    • The stub resolver.
  • Try defining some derive macros for the parsing/building traits.

Note: this is a new version of #469 with a less problematic branch name.

bal-e added 30 commits December 6, 2024 16:46
It implements 'Hash' for the provided integer types.
@bal-e bal-e requested a review from tertsdiepraam January 6, 2025 11:33
src/new_base/build/mod.rs Outdated Show resolved Hide resolved
src/new_base/build/mod.rs Outdated Show resolved Hide resolved

//--- Impls for 'Option<T>'

impl<T: ParseQuestion> ParseQuestion for Option<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this one. Is this to say that the question might not match but it will still fail if no questions are given?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, it needs docs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see it just maps Some over the result? When is None returned?

Copy link
Contributor Author

@bal-e bal-e Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None is returned if the message was correctly formatted, but no matching T was found in it (e.g. if T is specifically an A record).

}

/// A type that can be constructed by parsing zero or more DNS questions.
pub trait ParseQuestions: Sized {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love a different name for this to differentiate with ParseQuestion. Maybe ParseManyQuestions.

src/new_base/question.rs Outdated Show resolved Hide resolved

//--- Parsing from bytes

impl<'a, N, D> SplitBytes<'a> for Record<N, D>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this is mostly the same as SplitFromMessage can't we implement that one in terms of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, both traits are necessary. SplitFromMessage gets used when parsing DNS messages from the wire. SplitBytes is also used when parsing from unknown record data (e.g. encoded in a zone file), where there isn't a containing Message and name compression is not allowed. I do want to add derives to make some of this easier.

src/new_rdata/mod.rs Outdated Show resolved Hide resolved
macros/src/data.rs Outdated Show resolved Hide resolved
bal-e added 9 commits January 6, 2025 14:42
This ended up collecting a lot of small changes as I tried to get
things to compile.

- All the bytes parsing/building traits have been moved to 'wire'.
- The 'wire::ints' module replaces 'U16' and 'U32' from 'zerocopy'.
- '{Parse,Split}BytesByRef' now support parsing from '&mut'.
- Every derive macro is documented under a re-export in 'wire'.

The remaining contents of 'new_base::{build, parse}' might get moved
into a shared 'message' module at some point.  We'll see.
Instead of passing the input selection as a range for parsing, the
whole message is cut (using 'Message::slice_to()') and only the start
is indicated.  This ensures that we never cross the end of the range.
It also implicitly dictates that compressed names are not allowed to
reference future locations in messages.

In addition, both the parsing traits now use offsets into the message
_contents_ rather than the whole message.  They can avoid 'as_bytes()'
everywhere and have better guarantees of success.  It also ensures the
message header can never be selected for parsing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking A PR that includes a breaking change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants