]> git.meshlink.io Git - catta/blob - rr.h
some preliminary work for adding legacy unicast and unicast response support
[catta] / rr.h
1 #ifndef foorrhfoo
2 #define foorrhfoo
3
4 #include <glib.h>
5
6 #include "strlst.h"
7 #include "address.h"
8
9 enum {
10     FLX_DNS_TYPE_A = 0x01,
11     FLX_DNS_TYPE_NS = 0x02,
12     FLX_DNS_TYPE_CNAME = 0x05,
13     FLX_DNS_TYPE_SOA = 0x06,
14     FLX_DNS_TYPE_PTR = 0x0C,
15     FLX_DNS_TYPE_HINFO = 0x0D,
16     FLX_DNS_TYPE_MX = 0x0F,
17     FLX_DNS_TYPE_TXT = 0x10,
18     FLX_DNS_TYPE_AAAA = 0x1C,
19     FLX_DNS_TYPE_SRV = 0x21,
20     FLX_DNS_TYPE_ANY = 0xFF
21 };
22
23 enum {
24     FLX_DNS_CLASS_IN = 0x01,
25     FLX_DNS_CACHE_FLUSH = 0x8000,
26     FLX_DNS_UNICAST_RESPONSE = 0x8000
27 };
28
29 #define FLX_DEFAULT_TTL (120*60)
30
31 typedef struct {
32     guint ref;
33     gchar *name;
34     guint16 class;
35     guint16 type;
36 } flxKey;
37
38 typedef struct  {
39     guint ref;
40     flxKey *key;
41     
42     guint32 ttl;
43
44     union {
45         struct {
46             gpointer data;
47             guint16 size;
48         } generic;
49
50         struct {
51             guint16 priority;
52             guint16 weight;
53             guint16 port;
54             gchar *name;
55         } srv;
56
57         struct {
58             gchar *name;
59         } ptr; /* and cname */
60
61         struct {
62             gchar *cpu;
63             gchar *os;
64         } hinfo;
65
66         struct {
67             flxStringList *string_list;
68         } txt;
69
70         struct {
71             flxIPv4Address address;
72         } a;
73
74         struct {
75             flxIPv6Address address;
76         } aaaa;
77
78     } data;
79     
80 } flxRecord;
81
82 flxKey *flx_key_new(const gchar *name, guint16 class, guint16 type);
83 flxKey *flx_key_ref(flxKey *k);
84 void flx_key_unref(flxKey *k);
85
86 gboolean flx_key_equal(const flxKey *a, const flxKey *b);  /* Treat FLX_DNS_CLASS_ANY like any other type */
87 gboolean flx_key_pattern_match(const flxKey *pattern, const flxKey *k); /* If pattern.type is FLX_DNS_CLASS_ANY, k.type is ignored */
88
89 gboolean flx_key_is_pattern(const flxKey *k);
90
91 guint flx_key_hash(const flxKey *k);
92
93 flxRecord *flx_record_new(flxKey *k);
94 flxRecord *flx_record_new_full(const gchar *name, guint16 class, guint16 type);
95 flxRecord *flx_record_ref(flxRecord *r);
96 void flx_record_unref(flxRecord *r);
97
98 const gchar *flx_dns_class_to_string(guint16 class);
99 const gchar *flx_dns_type_to_string(guint16 type);
100
101 gchar *flx_key_to_string(const flxKey *k); /* g_free() the result! */
102 gchar *flx_record_to_string(const flxRecord *r);  /* g_free() the result! */
103
104 gboolean flx_record_equal_no_ttl(const flxRecord *a, const flxRecord *b);
105
106 flxRecord *flx_record_copy(flxRecord *r);
107
108 /* returns a maximum estimate for the space that is needed to store
109  * this key in a DNS packet */
110 guint flx_key_get_estimate_size(flxKey *k);
111
112 /* ditto */
113 guint flx_record_get_estimate_size(flxRecord *r);
114
115 gint flx_record_lexicographical_compare(flxRecord *a, flxRecord *b);
116
117 #endif