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

How do I turn dns_parser::Packet back into bytes? #40

Open
vi opened this issue Nov 30, 2018 · 4 comments
Open

How do I turn dns_parser::Packet back into bytes? #40

vi opened this issue Nov 30, 2018 · 4 comments

Comments

@vi
Copy link

vi commented Nov 30, 2018

How do I serialize it back?

I want the library to be able to round-trip DNS packet from bytes to structured representation and back.

@tailhook
Copy link
Owner

There is no such thing out of the box. We can probably add one, but I guess there are few more complications:

  1. Some hop-by-hop things might need to be changed when forwarding, like EDNS0 records
  2. AA bit and authority header might need to be changed as far as I understand
  3. And request_id have to be updated
  4. Also, the structure of Packet itself doesn't make it easy to edit things in the packet (i.e. slices pointing to the original buffer)

All of that makes it doubtful to have a generic round-trip function. But it should be easy enough to write the one for your specific use case. We might provide some helper functions, though. So contributions are welcome.

@vi
Copy link
Author

vi commented Nov 30, 2018

Is owned, static PacketBuf and corresponding bytes generation function, maybe with "forwarding helper" function which modifies things as you suggested in scope of this crate of better be done as separate crate?

@vi
Copy link
Author

vi commented Dec 6, 2018

Implemented deep_clone on multiple types, leading to parallel hierarchy of PacketBuf, QuesitonBuf, ResourceRecordBuf, RDataBuf and so on. Started implementing write_to that converts those types back into bytes.

Is pull request welcome or it's better to have it in a separate fork to avoid cluttering dns-parser?

vi added a commit to vi/dns-parser that referenced this issue Dec 6, 2018
Not tested, allocation-intensive.

Resolves tailhook#40.
vi added a commit to vi/dns-parser that referenced this issue Dec 8, 2018
Not tested, allocation-intensive.

Resolves tailhook#40.
@tailhook
Copy link
Owner

tailhook commented Dec 8, 2018

Hi!

Sorry, for a late response. Please open a PR! It's easier to judge looking at the code.

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

No branches or pull requests

2 participants