aboutsummaryrefslogtreecommitdiff
path: root/doc/API.xml
blob: 3d873d88f49a81f4694fe69117b5d6bd9c18f6c0 (plain) (blame)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
<?xml version="1.0"?>

<!DOCTYPE rfc SYSTEM "rfc2629.dtd">
<!-- $Id -->

<?rfc toc="yes" ?>
<?rfc compact="yes" ?>
<?rfc editing="no" ?>
<?rfc iprnotified="no" ?>
<?rfc private="LibDNS API" ?>

<rfc ipr="none" category="info" docName="libdns-api-00.txt">

<front>
<title>LibDNS API</title>
    <author initials="R." surname="Gieben" fullname="Miek Gieben">
     <organization>NLnet Labs</organization>
      <address>
        <postal>
          <street>Kruislaan 419</street>
          <city>Amsterdam</city>
          <code>1098 VA</code>
          <country>The Netherlands</country>
        </postal>
        <email>miek@nlnetlabs.nl</email>
        <uri>http://www.nlnetlabs.nl</uri>
      </address>
    </author>
    <author initials="J." surname="Jansen" fullname="Jelte Jansen">
     <organization>NLnet Labs</organization>
      <address>
        <postal>
          <street>Kruislaan 419</street>
          <city>Amsterdam</city>
          <code>1098 VA</code>
          <country>The Netherlands</country>
        </postal>
        <email>jelte@nlnetlabs.nl</email>
        <uri>http://www.nlnetlabs.nl</uri>
      </address>
    </author>
    <author initials="E." surname="Rozendaal" fullname="Erik Rozendaal">
     <organization>NLnet Labs</organization>
      <address>
        <postal>
          <street>Kruislaan 419</street>
          <city>Amsterdam</city>
          <code>1098 VA</code>
          <country>The Netherlands</country>
        </postal>
        <email>erik@nlnetlabs.nl</email>
        <uri>http://www.nlnetlabs.nl</uri>
      </address>
    </author>
<date month="January" year="2005" />
<keyword>DNS</keyword>
<keyword>Elite</keyword>
<keyword>Hacking</keyword>
<abstract>
<t>
A small abstract will come here, TBD.
</t>
</abstract>
</front>

<middle>

<section title="Introduction">
<t>
LibDNS (or lDNS) is modelled after the Net::DNS perl library. It has
been shown that Net::DNS  can be used efficiently for
programming DNS aware applications. We want to bring the same
level of efficiency to C programmers.
</t>
<t>
The lDNS API consist of two layers. The top-layer, this is
what is actually exported to the application via the library. And the
bottom-layer, this is what lDNS needs to compile and function.
</t>
</section> <!-- "Introduction" -->

<section title="Differences With Other Libraries">
<t>
Short intermezzo detailing differences with other libraries. Most important
ones are the libc resolver interface (from BIND8) and the lwres_ interface
from BIND9.
</t>
</section> <!-- "Differences with other libraries" -->

<section title="Interfaces">
<t>
At its lowest level lDNS  is only dependent on libc. It uses a 
few networking systems calls; socket, bind, send/recv and friends.
</t>
<t>
Further more it is to be expected that lDNS will depend on OpenSSL for
its cryptography.
</t>
<t>
As said, lDNS is modelled after Net::DNS, therefore its application API
looks very much like the one used for Net::DNS. Some modification are made
of course, because not all functionality of Perl can be caught in C.
</t>

<t>
This API document was written by carefully looking at the documentation
contained in the Net::DNS Perl module.
</t>
</section> <!-- "Interfaces" -->

<section title="RDF Structure">
<t>
The rdf structure, the RData Field, is a type that contains the different 
types in the rdata of an RR. Consider the following example:
<artwork>
example.com.	IN	MX	10 mx.example.com.
</artwork>
The "10 mx.example.com." is the rdata in this case. It consists of two
fields, "10" and "mx.example.com". These have the types (in this case)
LDNS_RDF_TYPE_INT8 and LDNS_RDF_TYPE_DNAME.
</t>
<t>
The following functions operate on this structure.
</t>
<t>
<list style="hanging">
<t hangText="dns_rdf *ldns_rdf_new(uint16_t s, ldns_rdf_type t, uint8_t *d):">
Create a new rdf structure. Return a pointer to it.
</t>
<t hangText="uint16_t ldns_rdf_size(ldns_rdf *r):">
Get the size of a rdf structure.
</t>
<t hangText="void ldns_rdf_set_size(ldns_rdf *r, uint16_t):">
Set the size of a rdf structure.
</t>
<t hangText="void ldns_rdf_set_type(ldns_rdf *r, ldns_rdf_type t):">
Set the type of a rdf structure.
</t>
<t hangText="ldns_rdf_type ldns_rdf_get_type(ldns_rdf *r):">
Get the type of a rdf structure.
</t>
<t hangText="void ldns_rdf_set_data(ldns_rdf *r, uint8_t *n):">
Set the (binary/network order) data of a rdf structure.
</t>
<t hangText="uint8_t *ldns_rdf_data(ldns_rdf *r):">
Get a pointer to the data in a rdf structure.
</t>
<t hangText="void ldns_rdf_free(ldns_rdf *r):">
Free a rdf structure.
</t>
<t hangText="ldns_rdf_new_frm_str(uint8_t *s, ldns_rdf_type t):">
Create a new rdf structure from a string and a specific rdf_type.
The type is needed to perform the correct conversion.
</t>
</list>
</t>
</section> <!-- "RDF Structure" -->

<section title="RR Structure">
<t>
These functions operate on ldns_rr structures.
</t>
<t>
<list style="hanging">
<t hangText="ldns_rr *ldns_rr_new(void):">
Returns a pointer to the newly created ldns_rr structure.
</t>
<t hangText="void ldns_rr_print(FILE *s, ldns_rr *r):">
Prints the record to the stream s.
</t>
<t hangText="ldns_buffer ldns_rr_rdatastr(ldns_rr *r):">
Returns a pointer to a ldns_buffer containing with string containing
RR-specific data.
</t>
<t hangText="ldns_rdf *ldns_rr_name(ldns_rr *r):">
Returns the record's owner name as a ldns_rdf type. 
</t>
<t hangText="ldns_rdf_rr_type ldns_rr_get_type(ldns_rr *r):">
Returns the record's type.
</t>
<t hangText="ldns_rr_class ldns_rr_get_class(ldns_rr *r):">
Returns the record's class.
</t>
<t hangText="uint32_t ldns_rr_get_ttl(ldns_rr *r):">
Returns the record's time-to-live (TTL).
</t>
</list>
</t>

<t>
TODO the 'set' functions of the 'get'
</t>
</section> <!-- "RR Structure" -->

<section title="RR list Structure">
<t>
In the DNS the atomic data type is an RRset. This is a list
of RRs with the same ownername, type and class. Net::DNS doesn't
have rrsets as a separate object.
</t>
<t>
In lDNS we have the ldns_rr_list, which just holds a bunch of RR's.
No specific check are made on the RRs that can be put in such a list.
Special wrapper functions exist which allow the usage of ldns_rr_list
of real (RFC compliant) RR sets.
</t>
<t>
TODO:  See rr.c
</t>
</section> <!-- "RR list Structure" -->

<section title="Resolver Structure">
<t>
<list style="hanging">
<t hangText="ldns_resolver* ldns_resolver_new(void):">
Create a new resolver structure and return the pointer to that.
</t>
<t hangText="uint8_t ldns_version(resolver *res):">
Returns the version of lDNS.
</t>
<t hangText="ldns_pkt *ldns_mx(ldns_resolver *res, ldns_rdf_type *dname):">
Returns a ldns_pkt representing the MX records
for the specified dname. Function is documented differently in Net::DNS.
Do we need stuff like this?? XXX
</t>
<t hangText="ldns_status ldns_resolver_domain(resolver *res, ldns_rdf
*domain):">
 Set the default domain for this resolver. This domain is added
     when a query is made with a name without a trailing dot.

     
</t>
<t hangText="ldns_status ldns_resolver_nameserver_push(resolver *res,
ldns_rdf *ip):">
Add a new nameserver to the resolver. These nameservers are queried
    when a search() or query() is done.
    
</t>
<t hangText="ldns_status ldns_resolver_searchlist_push(resolver *res,
ldns_rdf *domain):">
 Add a domain to the searchlist of a resolver.
</t>
<t hangText=" ldns_pkt * ldns_resolver_search(ldns_resolver *res,
                                ldns_rdf *domain,
                                ldns_rr_type *type,
                                ldns_class *class):">
 Perform a query. Try all the nameservers in the *res structure. Apply
 the search list. And default domain. 
If type is NULL it defaults to 'A',
If class is NULL it default to 'IN'.
</t>
<t hangText="ldns_pkt * ldns_resolver_query(ldns_resolver *res,
                                 ldns_rdf *dom,
                                 ldns_type *t,
                                 ldns_class *cl):">
Perform a query. Only the default domain is added.
If type is NULL it defaults to 'A',
If class is NULL it default to 'IN'.
</t>
<t hangText=" ldns_pkt * ldns_resolver_send(ldns_resolver *res,
                                ldns_rdf *domain,
                                ldns_type *type,
                                ldns_class *class):">
No search list nor default domain is applied. Return a pointer to a ldns_pkt
structure with the information from the nameserver.
If type is NULL it defaults to 'A',
If class is NULL it default to 'IN'.
</t>
</list>
</t>
<t>
TODO XX Gazillion  helper functions to set port, src-port, etc. etc.
</t>
</section> <!-- "Resolver Structure" -->

<section title="Packet Structure">
<t>
A packet structure (ldns_pkt) has five sections:
<list style="numbers">
<t>The header section, a ldns_hdr structure.</t>
<t>The question section, a ldns_rr_list structure.</t>
<t>The answer section, a ldns_rr_list structure.</t>
<t>The authority section, a ldns_rr_list structure.</t>
<t>The additional section, a ldns_rr_list structure.</t>
</list>
</t>
<t>
<list style="hanging">
<t hangText="Header Structure (ldns_hdr):">
ldns_hdr represents the header section of a DNS packet.
</t>
<t hangText="Question Section (ldns_rr_list):">
A list of RRs in the Question section of a DNS packet.
</t>
<t hangText="Answer Section (ldns_rr_list):">
A list of RRs in the Question section of a DNS packet.                     
</t>                             
<t hangText="Authority Section (ldns_rr_list):">
A list of RRs in the Question section of a DNS packet.
</t> 
<t hangText="Additional Section (ldns_rr_list):"> 
A list of RRs in the Question section of a DNS packet.                      
</t> 
</list>
</t>

<t>
<list style="hanging">
<t hangText="ldns_pkt * ldns_pkt_new(void):">
Creates a new empty packet.
</t>
<t hangText="ldns_buffer* ldns_pkt_data(ldns_pkt *pkt):">
Returns the packet data in binary format, suitable for sending to a
nameserver. [XXX, suitable for sending to a NS?]
</t>
<t hangText="ldns_hdr *ldns_header(ldn_pkt *pkt):">
Returns a ldns_hdr structure representing the header section of
the packet.
</t>
<t hangText="ldns_rr_list *ldns_question(ldns_pkt *pkt):">
 Returns a pointer to a ldns_rr_list representing the question section
of the packet.
</t>
<t hangText="ldns_rr_list *ldns_answer(ldns_pkt *pkt):">
 Returns a pointer to a ldns_rr_list representing the answer section of
the packet.
     
</t>
<t hangText=" ldns_rr_list *ldns_authority(ldns_pkt *pkt):">
Returns a pointer to a ldns_rr_list representing the authority section
of the packet.
    
</t>
<t hangText=" ldns_rr_list *ldns_additional(ldns_pkt *pkt):">
Returns a pointer to a ldns_rr_list of representing the additional
section of the packet.
	
</t>
<t hangText=" void ldns_pkt_print(ldns_pkt *pkt):">
Prints the packet data on the standard output in an ASCII format similar
to that used in DNS zone files. See RFC1035.
      
</t>
<t hangText="ldns_buffer *ldns_pkt_string(ldns_pkt *pkt):">
Returns a ldns_buffer containing the string representation of the packet.
 
</t>
<t hangText="ldns_rdf* ldns_pkt_answerfrom(ldns_pkt *pkt):">
Returns the IP address from which we received this packet. User-created
packets will return NULL.
     
</t>
<t hangText="uint16_t ldns_pkt_answersize(ldns_pkt *pkt):">
Returns the size of the packet in bytes as it was received from a
nameserver. User-created packets will return 0. [XXX
user-created??]
	
</t>
<t hangText="ldns_status ldns_push(ldns_pkt *pkt, ldns_pkt_section section,
ldns_rr *rr):">
Adds *rr to the specified section of the packet. Return LDNS_STATUS_OK
on success, LDNS_STATUS_ERR otherwise.
      
</t>
<t hangText="ldns_status ldns_unique_push(ldns_pkt *pkt, ldns_pkt_section
section, ldns_rr *rr):">
Adds *rr to the specified section of the packet provided that the RR
does not already exist in the packet. Return LDNS_STATUS_OK
on success, LDNS_STATUS_ERR otherwise.
</t>
<t hangText="ldns_rr *ldns_pop(ldns_pkt, ldns_pkt_section):">
Removes a RR from the specified section of the packet. Returns NULL if
no RR's could be popped.
</t>
<t hangText="ldns_rr_list *ldns_pkt_rrset(ldns_pkt *pkt,...):">
Retrieve all RRs in a packet matching certain criteria. XXX function needs
to be specified better.
</t>
<t hangText="void *ldns_pkt_print(FILE *s, ldns_pkt *p):">
Print packet p to stream s.
</t>

</list>
</t>
</section> <!-- "Packet Structure" -->

<section title="Specific RR Structures">
<t>
Some resource records can have special access function no other RR has.
Those are detailed here. XXX TODO don't exist (yet?).
</t>
</section> <!-- "Specific RR Structures" -->

<section title="Exported Defines and Macros">
<t>
insert your long list here.
</t>
</section> <!-- "Exported defines and macros" -->

<section title="Examples">
<t>
A small example, which queries a nameserver on localhost
to display the MX records for miek.nl.
</t>

<t>
<figure>
<artwork>
/**
 * An example ldns program
 * In semi-C code
 *
 * Setup a resolver
 * Query a nameserver
 * Print the result
 */

#include &lt;ldns.h&gt;

int 
main(void)
{
	ldns_resolver *res;
	ldns_rdf *default_dom;
	ldns_rdf *nameserver;
	ldns_rdf *qname;
	ldns_pkt *pkt;

	/* init */
	res = ldns_resolver_new();
	if (!res)
		return 1;
	
	/* create a default domain and add it */
	default_dom = ldns_rdf_new_frm_str("miek.nl.", LDNS_RDF_TYPE_DNAME);
	nameserver  = ldns_rdf_new_frm_str("127.0.0.1", LDNS_RDF_TYPE_A);

	if (ldns_resolver_domain(res, default_dom) != LDNS_STATUS_OK)
		return 1;
	if (ldns_resolver_nameserver_push(res, nameserver) != LDNS_STATUS_OK)
		return 1;

	/* setup the question */
	qname = ldns_rdf_new_frm_str("www", LDNS_RDF_TYPE_DNAME);

	/* fire it off. "miek.nl." will be added */
	pkt = ldns_resolver_query(res, qname, LDNS_RR_TYPE_MX, NULL);

	/* print the resulting pkt to stdout */
	ldns_pkt_print(stdout, pkt);

	return 0;
}
</artwork>
</figure>
</t>
</section> <!-- title="Short Example" -->

</middle>  
<back>
</back>
</rfc>