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

Limited implementation (no options) of EDNS #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

bortzmeyer
Copy link

Create and parse messages with EDNS. It only implements basic EDNS (no options).

Example:

    const edns = dns.EDNS{.bufsize = 568, .do_dnssec = false};
    const message = try dns.createEDNSQuery(allocator, "www.afnic.fr", .AAAA, edns);

@bortzmeyer
Copy link
Author

I added a new function createEDNSquery rather than adding the edns parameter to createQuery since I believe Zig has no way to specify default values for function parameters (so, every use of createQuery would have needed to be modified).

src/dns.zig Outdated
const domain = try DomainName.from_string(allocator, ".");
var flags: i32 = 0; // EDNS version 0 (RFC 6891)
if (edns.do_dnssec) {
flags = 0x8000;
Copy link
Owner

Choose a reason for hiding this comment

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

What do these flag values represent? It would be nice to have the flags represented by a packed struct to avoid unnamed constants.

Copy link
Author

Choose a reason for hiding this comment

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

What do these flag values represent? It would be nice to have the flags represented by a packed struct to avoid unnamed constants.

0x8000 is just the DO (DNSSEC OK) bit set, everything else clear (which means EDNS version 0). But I agree (it's in my second commit) that a packed struct would be nicer.

Copy link
Author

Choose a reason for hiding this comment

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

OK, next version will have:


pub const PackedEDNSTTL = packed struct(u32) {
    extendedRcode: u8 = 0,
    version: u8 = 0, // EDNS version 0 (RFC 6891)
    z1: u7 = 0, // Zig put fields in the unexpected order inside a byte.
    do: bool = true,
    z2: u8 = 0,
};

...

pub fn createEDNSQuery(allocator: mem.Allocator, address: []const u8, qtype: QType, edns: EDNS) !Message {
...
    var flags = PackedEDNSTTL{};
    flags.do = edns.do_dnssec;

No more 0x800. But I'm still struggling to produce a proper patch now that [read,write}IntBig disappeared and that non-mutated vars are forbidden. There are a lot of things to change.

Copy link
Owner

Choose a reason for hiding this comment

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

I must update the code to work with the latest Zig master release. Asking any PR to manage that migration on top of a new feature is a lot.

I have yet to have the time to work on this recently, but handling that migration is next on my list.

Copy link
Owner

Choose a reason for hiding this comment

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

I suspect most of my Zig projects need to be updated. Dealing with breaking changes every couple of months becomes overwhelming when you have a couple of larger projects you're working on in your spare time.

@bortzmeyer
Copy link
Author

OK, now without unnamed constants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants