[ldns-users] NSID support

Vladimir Levijev vladimir.levijev at gmail.com
Mon Dec 2 16:28:05 UTC 2019


On Thu, Sep 5, 2019 at 6:23 PM Vladimir Levijev
<vladimir.levijev at gmail.com> wrote:

Hi,

Getting back to your example that fetches NSID from the target name
server (see question below).

> > I have attached a "small" example program (nsid-example.c) that
> > illustrates how to use the ldns_pkt_set_edns_data() and
> > ldns_pkt_edns_data() functions to set and get EDNS Options.
> > Here are some usage examples:
> >
> > $ ./nsid-example
> > ./nsid-example <upstream IP>
> >
> > $ ./nsid-example 193.0.14.129
> > upstream 193.0.14.129, returned NSID: "ns2.nl-ams.k.ripe.net"
> >
> > $ ./nsid-example 37.209.192.10
> > upstream 37.209.192.10, returned NSID: "dns5.mel"
> >
> > $ ./nsid-example 9.9.9.10
> > upstream 9.9.9.10, returned NSID: "res210.ams.rrdns.pch.net"
> >
> > $ ./nsid-example 8.8.8.8
> > Could not get EDNS data

One question regarding the part of the code where the NSID is fetched
from reply, specifically:

---------------------------------------------------------------------------------------
while (size >= 4) {
    /* Read option code */
    opt_code = ldns_read_uint16(data);
    size -= 2; data += 2;

    /* Read option length */
    opt_len  = ldns_read_uint16(data);
    size -= 2; data += 2;

    if (opt_code == LDNS_EDNS_NSID) {
        printf("upstream ");
        ldns_rdf_print(stdout, upstream);
        printf(", returned NSID: \"%.*s\"\n", (int)opt_len, data);
        break;
    }

   /* Next option */
    size = opt_len > size ? 0 : size - opt_len;
}
---------------------------------------------------------------------------------------

If `opt_code` is not `LDNS_EDNS_NSID` (commented as "Next option"),
shouldn't we skip `opt_len` bytes in `data`?

Cheers,

VL



More information about the ldns-users mailing list