summaryrefslogtreecommitdiffstats
path: root/rr.h
blob: 465c3286de7972966b91d9965daedef615feb050 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef foorrhfoo
#define foorrhfoo

#include <glib.h>

#include "strlst.h"
#include "address.h"

enum {
    FLX_DNS_TYPE_A = 0x01,
    FLX_DNS_TYPE_NS = 0x02,
    FLX_DNS_TYPE_CNAME = 0x05,
    FLX_DNS_TYPE_SOA = 0x06,
    FLX_DNS_TYPE_PTR = 0x0C,
    FLX_DNS_TYPE_HINFO = 0x0D,
    FLX_DNS_TYPE_MX = 0x0F,
    FLX_DNS_TYPE_TXT = 0x10,
    FLX_DNS_TYPE_AAAA = 0x1C,
    FLX_DNS_TYPE_SRV = 0x21,
    FLX_DNS_TYPE_ANY = 0xFF
};

enum {
    FLX_DNS_CLASS_IN = 0x01,
    FLX_DNS_CACHE_FLUSH = 0x8000
};

#define FLX_DEFAULT_TTL (120*60)

typedef struct {
    guint ref;
    gchar *name;
    guint16 class;
    guint16 type;
} flxKey;

typedef struct  {
    guint ref;
    flxKey *key;
    
    guint32 ttl;

    union {
        struct {
            gpointer data;
            guint16 size;
        } generic;

        struct {
            guint16 priority;
            guint16 weight;
            guint16 port;
            gchar *name;
        } srv;

        struct {
            gchar *name;
        } ptr; /* and cname */

        struct {
            gchar *cpu;
            gchar *os;
        } hinfo;

        struct {
            flxStringList *string_list;
        } txt;

        struct {
            flxIPv4Address address;
        } a;

        struct {
            flxIPv6Address address;
        } aaaa;

    } data;
    
} flxRecord;

flxKey *flx_key_new(const gchar *name, guint16 class, guint16 type);
flxKey *flx_key_ref(flxKey *k);
void flx_key_unref(flxKey *k);

gboolean flx_key_equal(const flxKey *a, const flxKey *b);  /* Treat FLX_DNS_CLASS_ANY like any other type */
gboolean flx_key_pattern_match(const flxKey *pattern, const flxKey *k); /* If pattern.type is FLX_DNS_CLASS_ANY, k.type is ignored */

gboolean flx_key_is_pattern(const flxKey *k);

guint flx_key_hash(const flxKey *k);

flxRecord *flx_record_new(flxKey *k);
flxRecord *flx_record_new_full(const gchar *name, guint16 class, guint16 type);
flxRecord *flx_record_ref(flxRecord *r);
void flx_record_unref(flxRecord *r);

const gchar *flx_dns_class_to_string(guint16 class);
const gchar *flx_dns_type_to_string(guint16 type);

gchar *flx_key_to_string(const flxKey *k); /* g_free() the result! */
gchar *flx_record_to_string(const flxRecord *r);  /* g_free() the result! */

gboolean flx_record_equal_no_ttl(const flxRecord *a, const flxRecord *b);

flxRecord *flx_record_copy(flxRecord *r);

/* returns a maximum estimate for the space that is needed to store
 * this key in a DNS packet */
guint flx_key_get_estimate_size(flxKey *k);

/* ditto */
guint flx_record_get_estimate_size(flxRecord *r);

gint flx_record_lexicographical_compare(flxRecord *a, flxRecord *b);

#endif