diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-12-02 20:47:11 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-12-02 22:50:11 +0100 |
commit | 3cd03457bd3546a9d54a17bc00dae2058b43081b (patch) | |
tree | c3e544f712e2222a03dc80e68e2b503ef5fb66ec /src/shared | |
parent | 92aea95e168f692803b30aaa72c9d1321632b6fd (diff) |
util-lib: update dns_name_to_wire_format() to optionally generate DNSSEC canonical names
We'll need this later when putting together RR serializations to
checksum.
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/dns-domain.c | 16 | ||||
-rw-r--r-- | src/shared/dns-domain.h | 2 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/shared/dns-domain.c b/src/shared/dns-domain.c index 5ac8ad5b7a..429aa6d2cb 100644 --- a/src/shared/dns-domain.c +++ b/src/shared/dns-domain.c @@ -865,7 +865,7 @@ bool dns_name_is_single_label(const char *name) { } /* Encode a domain name according to RFC 1035 Section 3.1, without compression */ -int dns_name_to_wire_format(const char *domain, uint8_t *buffer, size_t len) { +int dns_name_to_wire_format(const char *domain, uint8_t *buffer, size_t len, bool canonical) { uint8_t *label_length, *out; int r; @@ -890,6 +890,20 @@ int dns_name_to_wire_format(const char *domain, uint8_t *buffer, size_t len) { if (r < 0) return r; + if (canonical) { + size_t i; + + /* Optionally, output the name in DNSSEC + * canonical format, as described in RFC 4034, + * section 6.2. Or in other words: in + * lower-case. */ + + for (i = 0; i < (size_t) r; i++) { + if (out[i] >= 'A' && out[i] <= 'Z') + out[i] = out[i] - 'A' + 'a'; + } + } + /* Fill label length, move forward */ *label_length = r; out += r; diff --git a/src/shared/dns-domain.h b/src/shared/dns-domain.h index 44a9975541..17dab1da18 100644 --- a/src/shared/dns-domain.h +++ b/src/shared/dns-domain.h @@ -77,7 +77,7 @@ int dns_name_address(const char *p, int *family, union in_addr_union *a); bool dns_name_is_root(const char *name); bool dns_name_is_single_label(const char *name); -int dns_name_to_wire_format(const char *domain, uint8_t *buffer, size_t len); +int dns_name_to_wire_format(const char *domain, uint8_t *buffer, size_t len, bool canonical); bool dns_srv_type_is_valid(const char *name); bool dns_service_name_is_valid(const char *name); |