xref: /openbsd/usr.bin/dig/lib/dns/include/dns/fixedname.h (revision 5185a700)
1 /*
2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14  * PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 /* $Id: fixedname.h,v 1.1 2020/02/07 09:58:52 florian Exp $ */
18 
19 #ifndef DNS_FIXEDNAME_H
20 #define DNS_FIXEDNAME_H 1
21 
22 /*****
23  ***** Module Info
24  *****/
25 
26 /*! \file dns/fixedname.h
27  * \brief
28  * Fixed-size Names
29  *
30  * dns_fixedname_t is a convenience type containing a name, an offsets table,
31  * and a dedicated buffer big enough for the longest possible name.
32  *
33  * MP:
34  *\li	The caller must ensure any required synchronization.
35  *
36  * Reliability:
37  *\li	No anticipated impact.
38  *
39  * Resources:
40  *\li	Per dns_fixedname_t:
41  *\code
42  *		sizeof(dns_name_t) + sizeof(dns_offsets_t) +
43  *		sizeof(isc_buffer_t) + 255 bytes + structure padding
44  *\endcode
45  *
46  * Security:
47  *\li	No anticipated impact.
48  *
49  * Standards:
50  *\li	None.
51  */
52 
53 /*****
54  ***** Imports
55  *****/
56 
57 #include <isc/buffer.h>
58 
59 #include <dns/name.h>
60 
61 /*****
62  ***** Types
63  *****/
64 
65 struct dns_fixedname {
66 	dns_name_t			name;
67 	dns_offsets_t			offsets;
68 	isc_buffer_t			buffer;
69 	unsigned char			data[DNS_NAME_MAXWIRE];
70 };
71 
72 #define dns_fixedname_init(fn) \
73 	do { \
74 		dns_name_init(&((fn)->name), (fn)->offsets); \
75 		isc_buffer_init(&((fn)->buffer), (fn)->data, \
76 				  DNS_NAME_MAXWIRE); \
77 		dns_name_setbuffer(&((fn)->name), &((fn)->buffer)); \
78 	} while (0)
79 
80 #define dns_fixedname_invalidate(fn) \
81 	dns_name_invalidate(&((fn)->name))
82 
83 #define dns_fixedname_name(fn)		(&((fn)->name))
84 
85 #endif /* DNS_FIXEDNAME_H */
86