test-dns-domain.c revision eb241cdbeea092d891137c018cacf919a895e6a6
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering This file is part of systemd.
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering Copyright 2014 Lennart Poettering
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering systemd is free software; you can redistribute it and/or modify it
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering under the terms of the GNU Lesser General Public License as published by
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering (at your option) any later version.
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering systemd is distributed in the hope that it will be useful, but
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering Lesser General Public License for more details.
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering You should have received a copy of the GNU Lesser General Public License
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poetteringstatic void test_dns_label_unescape_one(const char *what, const char *expect, size_t buffer_sz, int ret) {
718db96199eb307751264e4163555662c9a389faLennart Poettering r = dns_label_unescape(&what, buffer, buffer_sz);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poetteringstatic void test_dns_label_unescape(void) {
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering test_dns_label_unescape_one("hallo", "hallo", 6, 5);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering test_dns_label_unescape_one("hallo", "hallo", 4, -ENOBUFS);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering test_dns_label_unescape_one("", "", 10, 0);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering test_dns_label_unescape_one("hallo\\.foobar", "hallo.foobar", 20, 12);
718db96199eb307751264e4163555662c9a389faLennart Poettering test_dns_label_unescape_one("hallo.foobar", "hallo", 10, 5);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering test_dns_label_unescape_one("hallo\n.foobar", "hallo", 20, -EINVAL);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering test_dns_label_unescape_one("hallo\\", "hallo", 20, -EINVAL);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering test_dns_label_unescape_one("hallo\\032 ", "hallo ", 20, 7);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering test_dns_label_unescape_one(".", "", 20, 0);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering test_dns_label_unescape_one("..", "", 20, -EINVAL);
bc432dc7eb62c5671f2b741a86a66393adb350dcLennart Poettering test_dns_label_unescape_one(".foobar", "", 20, -EINVAL);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering test_dns_label_unescape_one("foobar.", "foobar", 20, 6);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poetteringstatic void test_dns_name_to_wire_format_one(const char *what, const char *expect, size_t buffer_sz, int ret) {
static void test_dns_name_to_wire_format(void) {
static const char out0[] = { 0 };
test_dns_name_to_wire_format_one("a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a123", NULL, 500, -EINVAL);
test_dns_name_to_wire_format_one("a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12", out4, sizeof(out4), sizeof(out4));
static void test_dns_label_unescape_suffix_one(const char *what, const char *expect1, const char *expect2, size_t buffer_sz, int ret1, int ret2) {
const char *label;
static void test_dns_label_unescape_suffix(void) {
static void test_dns_label_escape(void) {
test_dns_label_escape_one("hallo hallo.foobar,waldi", 24, "hallo\\032hallo\\.foobar\\044waldi", 31);
static void test_dns_name_normalize(void) {
r = dns_name_equal(a, b);
r = dns_name_equal(b, a);
static void test_dns_name_equal(void) {
r = dns_name_between(a, b, c);
r = dns_name_between(c, b, a);
if (ret >= 0)
assert_se(r == 0);
static void test_dns_name_between(void) {
/* see https://tools.ietf.org/html/rfc4034#section-6.1
static void test_dns_name_endswith(void) {
static void test_dns_name_startswith(void) {
static void test_dns_name_is_root(void) {
static void test_dns_name_is_single_label(void) {
union in_addr_union a, b = {};
static void test_dns_name_reverse(void) {
test_dns_name_reverse_one("fe80::47", "7.4.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa");
test_dns_name_reverse_one("::1", "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa");
static void test_dns_name_concat(void) {
static void test_dns_name_is_valid(void) {
test_dns_name_is_valid_one("a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345", 0);
test_dns_name_is_valid_one("a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a1234", 0);
test_dns_name_is_valid_one("a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a123", 0);
test_dns_name_is_valid_one("a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12345678.a12", 1);
static void test_dns_service_name_is_valid(void) {
assert_se(!dns_service_name_is_valid("this is an overly long string that is certainly longer than 63 characters"));
static void test_dns_srv_type_is_valid(void) {
static void test_dns_service_join_one(const char *a, const char *b, const char *c, int r, const char *d) {
static void test_dns_service_join(void) {
test_dns_service_join_one("Lennart's PC", "_pc._tcp", "foo.bar.com", 0, "Lennart\\039s\\032PC._pc._tcp.foo.bar.com");
static void test_dns_service_split_one(const char *joined, const char *a, const char *b, const char *c, int r) {
static void test_dns_service_split(void) {
test_dns_service_split_one("Wuff\\032Wuff._foo._bar.waldo.com", "Wuff Wuff", "_foo._bar", "waldo.com", 0);
static void test_dns_name_change_suffix_one(const char *name, const char *old_suffix, const char *new_suffix, int r, const char *result) {
static void test_dns_name_change_suffix(void) {
test_dns_name_change_suffix_one("foo.bar.waldi.quux", "foo.bar.waldi.quux", "piff.paff", 1, "piff.paff");
test_dns_name_change_suffix_one("foo.bar.waldi.quux", "bar.waldi.quux", "piff.paff", 1, "foo.piff.paff");
test_dns_name_change_suffix_one("foo.bar.waldi.quux", "waldi.quux", "piff.paff", 1, "foo.bar.piff.paff");
test_dns_name_change_suffix_one("foo.bar.waldi.quux", "quux", "piff.paff", 1, "foo.bar.waldi.piff.paff");
test_dns_name_change_suffix_one("foo.bar.waldi.quux", "", "piff.paff", 1, "foo.bar.waldi.quux.piff.paff");
static void test_dns_name_suffix_one(const char *name, unsigned n_labels, const char *result, int ret) {
const char *p = NULL;
static void test_dns_name_suffix(void) {
static void test_dns_name_count_labels(void) {
static void test_dns_name_equal_skip_one(const char *a, unsigned n_labels, const char *b, int ret) {
static void test_dns_name_equal_skip(void) {
static void test_dns_name_compare_func(void) {