tailhook/dns-parser

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

Opened this issue · 4 comments

vi commented

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.

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 commented

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 commented

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?

Hi!

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