mafintosh / dns-packet

An abstract-encoding compliant module for encoding / decoding DNS packets
MIT License
206 stars 71 forks source link

Add EDNS(0) OPT RR for UDP payload size in query. #34

Closed pusateri closed 6 years ago

pusateri commented 6 years ago

This adds support for indicating to the server that the client accepts responses larger than 512 octets over UDP by adding an additional record to the query with the UDP payload size:

{
  type: 'query',
  id: 1234,
  flags: packet.RECURSION_DESIRED,
  questions: [{
    type: 'A',
    name: 'google.com'
  }],
  additionals: [{
    type: 'OPT',
    name: '.',
    udp: 4096
  }]
}

The udp field is optional. The size defaults to 4096 if the 'OPT' resource record is present. Currently, the name MUST be specified and it must be '.' (root).

This also fixes a bug with the name encoding length of '.' (root). Previously, it always added 2 to the string length but this is incorrect for the case of root because it is encoded as a single 0x00.

This code does not yet support processing of EDNS(0) options. Those will be added in the future.

silverwind commented 6 years ago

This only adds partial support for the OPT RRTYPE, right? Care to add en/decoding of the attribute/value pairs in the RDATA too? We could use the IANA table to encode them:

https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-11 https://tools.ietf.org/html/rfc6891#page-7

silverwind commented 6 years ago

superceded by https://github.com/mafintosh/dns-packet/pull/37.

pusateri commented 6 years ago

Thanks for adding options processing to my original work. I was planning on doing it in phases and adding options as I needed them. And sorry for not responding for the past few days. I've been ill and am only now up and about.