ietf
[Top] [All Lists]

Re: Last Call: draft-ietf-hip-dns (Host Identity Protocol (HIP) Domain Name System (DNS) Extensions) to Experimental RFC

2007-05-29 04:59:32
On Tue, May 29, 2007 at 08:23:49AM +0300,
 Pekka Savola <pekkas(_at_)netcore(_dot_)fi> wrote 
 a message of 187 lines which said:

5) HIP wire format vs zone representation
..
I may me misunderstanding this, but doesn't that imply that the
authoritative DNS servers must implement Base16 and Base64 decoding support
so that they can convert from BaseXX to the on-the-wire format?

First, there is traditionally no obligation, for a name server, to
support the zone file format. Many name servers take their data from
something else (a database, or a file with a different format). It is
not even clear if it was a good idea to specify one zone file format
in RFC 1035, since it is not "on the wire".

Second, a name server already needs a specific parser for each
resource record type. It does not seem it is different or more
complicated to parse Base64 than it is to parse a LOC record. See the
code in BIND's lib/dns/rdata/generic directory.

Some resource record types already require knowledge of Base 64, such
as CERT (RFC 4398) or DNSKEY (RFC 4034).

For fun, I included here the LOC parsing code of nsd :-)

/*
 * Parses a specific part of rdata.
 *
 * Returns:
 *
 *      number of elements parsed
 *      zero on error
 *
 */
uint16_t *
zparser_conv_loc(region_type *region, char *str)
{
        uint16_t *r;
        uint32_t *p;
        int i;
        int deg, min, secs;     /* Secs is stored times 1000.  */
        uint32_t lat = 0, lon = 0, alt = 0;
        /* encoded defaults: version=0 sz=1m hp=10000m vp=10m */
        uint8_t vszhpvp[4] = {0, 0x12, 0x16, 0x13};
        char *start;
        double d;
                        

        for(;;) {
                deg = min = secs = 0;
                
                /* Degrees */
                if (*str == '\0') {
                        zc_error_prev_line("unexpected end of LOC data");
                        return NULL;
                }

                if (!parse_int(str, &str, &deg, "degrees", 0, 180))
                        return NULL;
                if (!isspace(*str)) {
                        zc_error_prev_line("space expected after degrees");
                        return NULL;
                }
                ++str;
                
                /* Minutes? */
                if (isdigit(*str)) {
                        if (!parse_int(str, &str, &min, "minutes", 0, 60))
                                return NULL;
                        if (!isspace(*str)) {
                                zc_error_prev_line("space expected after 
minutes");
                                return NULL;
                        }
                        ++str;
                }
                
                /* Seconds? */
                if (isdigit(*str)) {
                        start = str;
                        if (!parse_int(str, &str, &i, "seconds", 0, 60)) {
                                return NULL;
                        }

                        if (*str == '.' && !parse_int(str + 1, &str, &i, 
"seconds fraction", 0, 999)) {
                                return NULL;
                        }

                        if (!isspace(*str)) {
                                zc_error_prev_line("space expected after 
seconds");
                                return NULL;
                        }

                        if (sscanf(start, "%lf", &d) != 1) {
                                zc_error_prev_line("error parsing seconds");
                        }

                        if (d < 0.0 || d > 60.0) {
                                zc_error_prev_line("seconds not in range 0.0 .. 
60.0");
                        }

                        secs = (int) (d * 1000.0 + 0.5);
                        ++str;
                }
                
                switch(*str) {
                case 'N':
                case 'n':
                        lat = ((uint32_t)1<<31) + (deg * 3600000 + min * 60000 
+ secs);
                        break;
                case 'E':
                case 'e':
                        lon = ((uint32_t)1<<31) + (deg * 3600000 + min * 60000 
+ secs);
                        break;
                case 'S':
                case 's':
                        lat = ((uint32_t)1<<31) - (deg * 3600000 + min * 60000 
+ secs);
                        break;
                case 'W':
                case 'w':
                        lon = ((uint32_t)1<<31) - (deg * 3600000 + min * 60000 
+ secs);
                        break;
                default:
                        zc_error_prev_line("invalid latitude/longtitude");
                        return NULL;
                }
                ++str;
                
                if (lat != 0 && lon != 0)
                        break;

                if (!isspace(*str)) {
                        zc_error_prev_line("space expected after 
latitude/longitude");
                        return NULL;
                }
                ++str;
        }

        /* Altitude */
        if (*str == '\0') {
                zc_error_prev_line("unexpected end of LOC data");
                return NULL;
        }

        if (!isspace(*str)) {
                zc_error_prev_line("space expected before altitude");
                return NULL;
        }
        ++str;

        start = str;

        /* Sign */
        if (*str == '+' || *str == '-') {
                ++str;
        }

        /* Meters of altitude... */
        (void)strtol(str, &str, 10);
        switch(*str) {
        case ' ':
        case '\0':
        case 'm':
                break;
        case '.':
                if (!parse_int(str + 1, &str, &i, "altitude fraction", 0, 99)) {
                        return NULL;
                }
                if (!isspace(*str) && *str != '\0' && *str != 'm') {
                        zc_error_prev_line("altitude fraction must be a 
number");
                        return NULL;
                }
                break;
        default:
                zc_error_prev_line("altitude must be expressed in meters");
                return NULL;
        }
        if (!isspace(*str) && *str != '\0')
                ++str;

        if (sscanf(start, "%lf", &d) != 1) {
                zc_error_prev_line("error parsing altitude");
        }
        
        alt = (uint32_t) (10000000.0 + d * 100 + 0.5);

        if (!isspace(*str) && *str != '\0') {
                zc_error_prev_line("unexpected character after altitude");
                return NULL;
        }

        /* Now parse size, horizontal precision and vertical precision if any */
        for(i = 1; isspace(*str) && i <= 3; i++) {
                vszhpvp[i] = precsize_aton(str + 1, &str);

                if (!isspace(*str) && *str != '\0') {
                        zc_error_prev_line("invalid size or precision");
                        return NULL;
                }
        }

        /* Allocate required space... */
        r = alloc_rdata(region, 16);
        p = (uint32_t *) (r + 1);

        memmove(p, vszhpvp, 4);
        write_uint32(p + 1, lat);
        write_uint32(p + 2, lon);
        write_uint32(p + 3, alt);

        return r;
}

_______________________________________________
Ietf mailing list
Ietf(_at_)ietf(_dot_)org
https://www1.ietf.org/mailman/listinfo/ietf