5 This file is part of catta.
7 catta is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of the
10 License, or (at your option) any later version.
12 catta is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15 Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with catta; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 /** \file rr.h Functions and definitions for manipulating DNS resource record (RR) data. */
26 #include <sys/types.h>
28 #include <catta/strlst.h>
29 #include <catta/address.h>
30 #include <catta/cdecl.h>
34 /** DNS record types, see RFC 1035, in addition to those defined in defs.h */
36 CATTA_DNS_TYPE_ANY = 0xFF, /**< Special query type for requesting all records */
37 CATTA_DNS_TYPE_OPT = 41, /**< EDNS0 option */
38 CATTA_DNS_TYPE_TKEY = 249,
39 CATTA_DNS_TYPE_TSIG = 250,
40 CATTA_DNS_TYPE_IXFR = 251,
41 CATTA_DNS_TYPE_AXFR = 252
44 /** DNS record classes, see RFC 1035, in addition to those defined in defs.h */
46 CATTA_DNS_CLASS_ANY = 0xFF, /**< Special query type for requesting all records */
47 CATTA_DNS_CACHE_FLUSH = 0x8000, /**< Not really a class but a bit which may be set in response packets, see mDNS spec for more information */
48 CATTA_DNS_UNICAST_RESPONSE = 0x8000 /**< Not really a class but a bit which may be set in query packets, see mDNS spec for more information */
51 /** Encapsulates a DNS query key consisting of class, type and
52 name. Use catta_key_ref()/catta_key_unref() for manipulating the
53 reference counter. The structure is intended to be treated as "immutable", no
54 changes should be imposed after creation */
55 typedef struct CattaKey {
56 int ref; /**< Reference counter */
57 char *name; /**< Record name */
58 uint16_t clazz; /**< Record class, one of the CATTA_DNS_CLASS_xxx constants */
59 uint16_t type; /**< Record type, one of the CATTA_DNS_TYPE_xxx constants */
62 /** Encapsulates a DNS resource record. The structure is intended to
63 * be treated as "immutable", no changes should be imposed after
65 typedef struct CattaRecord {
66 int ref; /**< Reference counter */
67 CattaKey *key; /**< Reference to the query key of this record */
69 uint32_t ttl; /**< DNS TTL of this record */
76 } generic; /**< Generic record data for unknown types */
83 } srv; /**< Data for SRV records */
87 } ptr, ns, cname; /**< Data for PTR, NS and CNAME records */
92 } hinfo; /**< Data for HINFO records */
95 CattaStringList *string_list;
96 } txt; /**< Data for TXT records */
99 CattaIPv4Address address;
100 } a; /**< Data for A records */
103 CattaIPv6Address address;
104 } aaaa; /**< Data for AAAA records */
106 } data; /**< Record data */
110 /** Create a new CattaKey object. The reference counter will be set to 1. */
111 CattaKey *catta_key_new(const char *name, uint16_t clazz, uint16_t type);
113 /** Increase the reference counter of an CattaKey object by one */
114 CattaKey *catta_key_ref(CattaKey *k);
116 /** Decrease the reference counter of an CattaKey object by one */
117 void catta_key_unref(CattaKey *k);
119 /** Check whether two CattaKey object contain the same
120 * data. CATTA_DNS_CLASS_ANY/CATTA_DNS_TYPE_ANY are treated like any
121 * other class/type. */
122 int catta_key_equal(const CattaKey *a, const CattaKey *b);
124 /** Return a numeric hash value for a key for usage in hash tables. */
125 unsigned catta_key_hash(const CattaKey *k);
127 /** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */
128 CattaRecord *catta_record_new(CattaKey *k, uint32_t ttl);
130 /** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */
131 CattaRecord *catta_record_new_full(const char *name, uint16_t clazz, uint16_t type, uint32_t ttl);
133 /** Increase the reference counter of an CattaRecord by one. */
134 CattaRecord *catta_record_ref(CattaRecord *r);
136 /** Decrease the reference counter of an CattaRecord by one. */
137 void catta_record_unref(CattaRecord *r);
139 /** Return a textual representation of the specified DNS class. The
140 * returned pointer points to a read only internal string. */
141 const char *catta_dns_class_to_string(uint16_t clazz);
143 /** Return a textual representation of the specified DNS class. The
144 * returned pointer points to a read only internal string. */
145 const char *catta_dns_type_to_string(uint16_t type);
147 /** Create a textual representation of the specified key. catta_free() the
149 char *catta_key_to_string(const CattaKey *k);
151 /** Create a textual representation of the specified record, similar
152 * in style to BIND zone file data. catta_free() the result! */
153 char *catta_record_to_string(const CattaRecord *r);
155 /** Check whether two records are equal (regardless of the TTL */
156 int catta_record_equal_no_ttl(const CattaRecord *a, const CattaRecord *b);
158 /** Check whether the specified key is valid */
159 int catta_key_is_valid(CattaKey *k);
161 /** Check whether the specified record is valid */
162 int catta_record_is_valid(CattaRecord *r);
164 /** Parse a binary rdata object and fill it into *record. This function is actually implemented in dns.c */
165 int catta_rdata_parse(CattaRecord *record, const void* rdata, size_t size);
167 /** Serialize an CattaRecord object into binary rdata. This function is actually implemented in dns.c */
168 size_t catta_rdata_serialize(CattaRecord *record, void *rdata, size_t max_size);
170 /** Return TRUE if the CattaRecord object is a link-local A or AAAA address */
171 int catta_record_is_link_local_address(const CattaRecord *r);