]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: move DNS class utilities to dns-type.c and add more helpers
authorLennart Poettering <lennart@poettering.net>
Fri, 18 Dec 2015 17:53:11 +0000 (18:53 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 18 Dec 2015 17:53:11 +0000 (18:53 +0100)
Let's make DNS class helpers more like DNS type helpers, let's move them
from resolved-dns-rr.[ch] into dns-type.[ch].

This also adds two new calls dns_class_is_pseudo() and
dns_class_is_valid_rr() which operate similar to dns_type_is_pseudo()
and dns_type_is_valid_rr() but for classes instead of types.

This should hopefully make handling of DNS classes and DNS types more
alike.

src/resolve-host/resolve-host.c
src/resolve/dns-type.c
src/resolve/dns-type.h
src/resolve/resolved-dns-rr.c
src/resolve/resolved-dns-rr.h

index 0f154d97988231b3b8c7adecad3be4716933dd4d..bcacb2595ce0ecdf38291215e2752bcafcc4b32b 100644 (file)
@@ -38,7 +38,7 @@
 
 static int arg_family = AF_UNSPEC;
 static int arg_ifindex = 0;
-static int arg_type = 0;
+static uint16_t arg_type = 0;
 static uint16_t arg_class = 0;
 static bool arg_legend = true;
 static uint64_t arg_flags = 0;
@@ -347,7 +347,6 @@ static int resolve_record(sd_bus *bus, const char *name) {
         if (r < 0)
                 return bus_log_create_error(r);
 
-        assert((uint16_t) arg_type == arg_type);
         r = sd_bus_message_append(req, "isqqt", arg_ifindex, name, arg_class, arg_type, arg_flags);
         if (r < 0)
                 return bus_log_create_error(r);
@@ -758,12 +757,13 @@ static int parse_argv(int argc, char *argv[]) {
                                 return 0;
                         }
 
-                        arg_type = dns_type_from_string(optarg);
-                        if (arg_type < 0) {
+                        r = dns_type_from_string(optarg);
+                        if (r < 0) {
                                 log_error("Failed to parse RR record type %s", optarg);
-                                return arg_type;
+                                return r;
                         }
-                        assert(arg_type > 0 && (uint16_t) arg_type == arg_type);
+                        arg_type = (uint16_t) r;
+                        assert((int) arg_type == r);
 
                         break;
 
@@ -773,11 +773,13 @@ static int parse_argv(int argc, char *argv[]) {
                                 return 0;
                         }
 
-                        r = dns_class_from_string(optarg, &arg_class);
+                        r = dns_class_from_string(optarg);
                         if (r < 0) {
                                 log_error("Failed to parse RR record class %s", optarg);
                                 return r;
                         }
+                        arg_class = (uint16_t) r;
+                        assert((int) arg_class == r);
 
                         break;
 
index 8281da3b7c9bc6c79bb20ffea48e1ae7a4bd956e..cc52ef9abe0ae76f75a28f922c23df6c64be65bc 100644 (file)
@@ -20,6 +20,7 @@
 ***/
 
 #include "dns-type.h"
+#include "string-util.h"
 
 typedef const struct {
         uint16_t type;
@@ -64,6 +65,10 @@ bool dns_type_is_pseudo(uint16_t type) {
         );
 }
 
+bool dns_class_is_pseudo(uint16_t class) {
+        return class == DNS_TYPE_ANY;
+}
+
 bool dns_type_is_valid_query(uint16_t type) {
 
         /* The types valid as questions in packets */
@@ -85,3 +90,34 @@ bool dns_type_is_valid_rr(uint16_t type) {
                        DNS_TYPE_AXFR,
                        DNS_TYPE_IXFR);
 }
+
+bool dns_class_is_valid_rr(uint16_t class) {
+        return class != DNS_CLASS_ANY;
+}
+
+const char *dns_class_to_string(uint16_t class) {
+
+        switch (class) {
+
+        case DNS_CLASS_IN:
+                return "IN";
+
+        case DNS_CLASS_ANY:
+                return "ANY";
+        }
+
+        return NULL;
+}
+
+int dns_class_from_string(const char *s) {
+
+        if (!s)
+                return _DNS_CLASS_INVALID;
+
+        if (strcaseeq(s, "IN"))
+                return DNS_CLASS_IN;
+        else if (strcaseeq(s, "ANY"))
+                return DNS_CLASS_ANY;
+
+        return _DNS_CLASS_INVALID;
+}
index 038a0d0e54605b4dcbbe90cdf92339593b653089..deb89e9b7e273be442ac7e09bcb4c61bbfb18d36 100644 (file)
@@ -122,3 +122,17 @@ enum {
 assert_cc(DNS_TYPE_SSHFP == 44);
 assert_cc(DNS_TYPE_TLSA == 52);
 assert_cc(DNS_TYPE_ANY == 255);
+
+/* DNS record classes, see RFC 1035 */
+enum {
+        DNS_CLASS_IN   = 0x01,
+        DNS_CLASS_ANY  = 0xFF,
+        _DNS_CLASS_MAX,
+        _DNS_CLASS_INVALID = -1
+};
+
+bool dns_class_is_pseudo(uint16_t class);
+bool dns_class_is_valid_rr(uint16_t class);
+
+const char *dns_class_to_string(uint16_t type);
+int dns_class_from_string(const char *name);
index 60a614fb6d417d08e2eff51ad9339448872eb46b..98a3a3351d92a18727ec9e01a36b4d088e12f814 100644 (file)
@@ -1074,34 +1074,6 @@ int dns_resource_record_to_wire_format(DnsResourceRecord *rr, bool canonical) {
         return 0;
 }
 
-const char *dns_class_to_string(uint16_t class) {
-
-        switch (class) {
-
-        case DNS_CLASS_IN:
-                return "IN";
-
-        case DNS_CLASS_ANY:
-                return "ANY";
-        }
-
-        return NULL;
-}
-
-int dns_class_from_string(const char *s, uint16_t *class) {
-        assert(s);
-        assert(class);
-
-        if (strcaseeq(s, "IN"))
-                *class = DNS_CLASS_IN;
-        else if (strcaseeq(s, "ANY"))
-                *class = DNS_CLASS_ANY;
-        else
-                return -EINVAL;
-
-        return 0;
-}
-
 DnsTxtItem *dns_txt_item_free_all(DnsTxtItem *i) {
         DnsTxtItem *n;
 
index 8d2bc2dc2134a38c56812c66b589f900603398c0..bb50cf6a340cfa2815bf90f2e912baa78e6c6c24 100644 (file)
@@ -33,14 +33,6 @@ typedef struct DnsResourceKey DnsResourceKey;
 typedef struct DnsResourceRecord DnsResourceRecord;
 typedef struct DnsTxtItem DnsTxtItem;
 
-/* DNS record classes, see RFC 1035 */
-enum {
-        DNS_CLASS_IN   = 0x01,
-        DNS_CLASS_ANY  = 0xFF,
-        _DNS_CLASS_MAX,
-        _DNS_CLASS_INVALID = -1
-};
-
 /* DNSKEY RR flags */
 #define DNSKEY_FLAG_ZONE_KEY (UINT16_C(1) << 8)
 #define DNSKEY_FLAG_SEP      (UINT16_C(1) << 0)
@@ -270,9 +262,6 @@ int dns_resource_record_to_wire_format(DnsResourceRecord *rr, bool canonical);
 DnsTxtItem *dns_txt_item_free_all(DnsTxtItem *i);
 bool dns_txt_item_equal(DnsTxtItem *a, DnsTxtItem *b);
 
-const char *dns_class_to_string(uint16_t type);
-int dns_class_from_string(const char *name, uint16_t *class);
-
 extern const struct hash_ops dns_resource_key_hash_ops;
 
 const char* dnssec_algorithm_to_string(int i) _const_;