mafintosh / dns-packet

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

Edns0options #47

Closed hildjj closed 5 years ago

hildjj commented 5 years ago

Fixes #46. Adds support for several relevant EDNS0 types. Updates tests. Updates README.

silverwind commented 5 years ago

What do you think about these? 1:1 mapping of code to name only:

case 'OPTION_0': return 0
case 'LLQ': return 1
case 'UL': return 2
case 'NSID': return 3
case 'OPTION_4': return 4
case 'DAU': return 5
case 'DHU': return 6
case 'N3U': return 7
case 'CLIENT_SUBNET': return 8
case 'EXPIRE': return 9
case 'COOKIE': return 10
case 'TCP_KEEPALIVE': return 11
case 'PADDING': return 12
case 'CHAIN': return 13
case 'KEY_TAG': return 14
case 'DEVICEID': return 26946
case 'OPTION_65535': return 65535

Again, if you like to use ECS for option 8, I'm also happy to use it. I don't like ambiguity so I think we should not take multiple names for the same option.

edit: replaced dashes with underscores.

silverwind commented 5 years ago

Generally looking good to me, except the naming thing above.

titanism commented 1 year ago

@hildjj @silverwind @imcotton can you share an example of implementing this for a A type lookup, similarly to the implementation here https://github.com/song940/node-dns/blob/28fd77405b98081ac1efb41d0c800e827c1cf6ff/client/doh.js#L33-L37 with modifying additionals?

Basically, what would packet.additionals.push({ ... }) look like while using dns-packet? It wasn't clear how to do it from the README, however it looks like using code: 'CLIENT_SUBNET' might be something related?

Example:

    const dnsPacket = require('dns-packet');

    // ...

    const packet = {
      type: 'query',
      id: getRandomInt(1, 65534),
      questions: [{ type, name }],
      flags: dnsPacket.RECURSION_DESIRED
    };

    // TODO: improve/refactor this to use "code: 'CLIENT_SUBNET'" from `dns-package`
    if (ip)
      packet.additionals.push(
        // eslint-disable-next-line new-cap
        DNS.Packet.Resource.EDNS([DNS.Packet.Resource.EDNS.ECS(ip)])
      );

    // ...
hildjj commented 1 year ago

This is what I do in dohdec, which may be more or less what you want: https://github.com/hildjj/dohdec/blob/43564118c40f2127af871bdb4d40f615409d4b9c/pkg/dohdec/lib/dnsUtils.js#L192