]> git.saurik.com Git - apple/configd.git/blob - dnsinfo/dnsinfo_private.h
configd-1109.101.1.tar.gz
[apple/configd.git] / dnsinfo / dnsinfo_private.h
1 /*
2 * Copyright (c) 2004-2006, 2008, 2009, 2012, 2013, 2015, 2017, 2018 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef __DNSINFO_PRIVATE_H__
25 #define __DNSINFO_PRIVATE_H__
26
27
28 #include <os/availability.h>
29 #include <sys/cdefs.h>
30 #include <stdint.h>
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <mach/mach.h>
35
36 #include "dnsinfo.h"
37
38 /*
39 * What's all of this stuff about???
40 *
41 * In order to minimize the amount of data conversions associated with
42 * storing, retrieving, and accessing the systems DNS configuration I
43 * have opted to create a memory image filled with the actual data
44 * types / structures that would be used by those applications which
45 * make use of these APIS. The implication here is that we use
46 * sockaddr's for addresses, char *'s for strings, etc.
47 *
48 * To achieve this goal the APIs which are used to store and access the
49 * configuration data build and use a single buffer of the relevant
50 * bits. When multiple instances of a given type / structure are needed
51 * we maintain a count, the actual data, and when the configuration has
52 * been unpacked, arrays of pointers to the data.
53 *
54 * In memory, the data looks as follows:
55 *
56 * +-------------------------------------------------------------------+
57 * | struct _dns_config_buf_t |
58 * +-+-------------+---------------------------------------------------+
59 * | | config | struct dns_config_t |
60 * | | +-+-----------------------------+-------------------+
61 * | | | | n_resolver | int32_t | <- # of name resolvers
62 * | | | +-----------------------------+-------------------+
63 * | | | | resolver | dns_resolver_t ** | <- not used during creation, filled
64 * | | | | | | in with pointer to a list of
65 * | | | | | | resolver configurations that will
66 * | | | | | | be established in the "padding"
67 * | | | +-----------------------------+--------------------+
68 * | | | | n_scoped_resolver | int32_t | <- # of name scoped resolvers
69 * | | | +-----------------------------+--------------------+
70 * | | | | scoped_resolver | dns_resolver_t ** | <- not used during creation, filled
71 * | | | | | | in with pointer to a list of scoped
72 * | | | | | | resolver configurations that will
73 * | | | | | | be established in the "padding"
74 * | | | +-----------------------------+--------------------+
75 * | | | | generation | uint64_t | <- generation # of configuration
76 * | | | +-----------------------------+-------------------+
77 * | | | | n_service_specific_resolver | int32_t | <- # of name service-specific resolvers
78 * | | | +-------------------+---------+-------------------+
79 * | | | | service_specific_resolver | dns_resolver_t ** | <- not used during creation, filled
80 * | | | | | | in with pointer to a list of service-specific
81 * | | | | | | resolver configurations that will be
82 * | | | | | | established in the "padding"
83 * | | | +-----------------------------+-------------------+
84 * | | | | version | uint32_t | <- configuration structure(s) version
85 * | +-------------+-+-----------------------------+-------------------+
86 * | | n_attribute | uint32_t | <- how many bytes of "attribute"
87 * | | | | data is associated with the
88 * | | | | configuration
89 * |-+-------------+---------------------------------------------------+
90 * | | n_padding | uint32_t | <- how many additional bytes
91 * | | | | for arrays (of pointers), ...
92 * +-+-------------+---------------------------------------------------+
93 * | struct dns_attribute_t |
94 * |-+-------------+---------------------------------------------------+
95 * | | type | uint32_t | <- type of attribute (e.g. CONFIG_ATTRIBUTE_RESOLVER)
96 * | +-------------+---------------------------------------------------+
97 * | | length | uint32_t | <- length of the attribute
98 * | +-------------+---------------------------------------------------+
99 * | | attribute | struct _dns_resolver_buf_t | <- the attribute data (resolver configuration #1)
100 * | | +-+-------------+-----------------------------------+
101 * | | | | resolver | struct dns_resolver_t |
102 * | | | | +--------------+--------------------+
103 * | | | | | domain | char * | <- not used during creation,
104 * | | | | | | | filled in with pointer to
105 * | | | | | | | domain name in the "padding"
106 * | | | | +--------------+--------------------+
107 * | | | | | n_nameserver | int32_t | <- # of name server addresses
108 * | | | | +--------------+--------------------+
109 * | | | | | nameserver | struct sockaddr ** | <- not used during creation,
110 * | | | | | | | filled in with pointer to
111 * | | | | | | | a list of addresses which
112 * | | | | | | | will be established in the
113 * | | | | | | | "padding"
114 * | | | | +--------------+--------------------+
115 * | | | | | ... |
116 * | | +-+-------------+--------------+--------------------+
117 * | | | | n_attribute | uint32_t |
118 * | | +-+-------------+-----------------------------------+
119 * | | | | attribute | struct dns_attribute_t |
120 * | | | | +-+-----------+---------------------+
121 * | | | | | | type | uint32_t | <- type of attribute (e.g. RESOLVER_ATTRIBUTE_DOMAIN)
122 * | | | | | +-----------+---------------------+
123 * | | | | | | length | uint32_t | <- length of the attribute
124 * | | | | | +-----------+---------------------+
125 * | | | | | | attribute | | <- the attribute data ("apple.com")
126 * | | +-+-------------+-------------+---------------------+
127 * | | | | attribute | struct dns_attribute_t |
128 * | | | | +-+-----------+---------------------+
129 * | | | | | | type | uint32_t | <- type of attribute (e.g. RESOLVER_ATTRIBUTE_ADDRESS)
130 * | | | | | +-----------+---------------------+
131 * | | | | | | length | uint32_t | <- length of the attribute
132 * | | | | | +-----------+---------------------+
133 * | | | | | | attribute | | <- the attribute data ("struct sockaddr_in" #1)
134 * | | +---------------+-----------------------------------+
135 * | | | | attribute | struct dns_attribute_t |
136 * | | | | +-+-----------+---------------------+
137 * | | | | | | type | uint32_t | <- type of attribute (e.g. RESOLVER_ATTRIBUTE_ADDRESS)
138 * | | | | | +-----------+---------------------+
139 * | | | | | | length | uint32_t | <- length of the attribute
140 * | | | | | +-----------+---------------------+
141 * | | | | | | attribute | | <- the attribute data ("struct sockaddr_in" #2)
142 * | | +---------------+-----------------------------------+
143 * | | | ... |
144 * +-+-------------+---------------------------------------------------+
145 * | | attribute | struct _dns_resolver_buf_t | <- the attribute data (resolver configuration #2)
146 * | | +---------------+-----------------------------------+
147 * | | | ... |
148 * +---------------+---------------------------------------------------+
149 * | | ... |
150 * +---------------+---------------------------------------------------+
151 *
152 * When the data is unpacked the "n_padding" additional bytes
153 * specified in configuration buffer will be allocated at the
154 * end of this buffer. Arrays of pointers will be allocated
155 * within the extra space array element (an "attribute") is
156 * encountered the pointer reference will be filled in.
157 */
158
159
160 // configuration buffer attributes
161 enum {
162 CONFIG_ATTRIBUTE_RESOLVER = 1,
163 CONFIG_ATTRIBUTE_SCOPED_RESOLVER,
164 CONFIG_ATTRIBUTE_SERVICE_SPECIFIC_RESOLVER,
165 };
166
167
168 // resolver buffer attributes
169 enum {
170 RESOLVER_ATTRIBUTE_DOMAIN = 10,
171 RESOLVER_ATTRIBUTE_ADDRESS,
172 RESOLVER_ATTRIBUTE_SEARCH,
173 RESOLVER_ATTRIBUTE_SORTADDR,
174 RESOLVER_ATTRIBUTE_OPTIONS,
175 RESOLVER_ATTRIBUTE_CONFIGURATION_ID,
176 RESOLVER_ATTRIBUTE_INTERFACE_NAME,
177 };
178
179
180 #pragma pack(4)
181 typedef struct {
182 uint32_t type;
183 uint32_t length;
184 uint8_t attribute[0];
185 } dns_attribute_t;
186 #pragma pack()
187
188
189 #pragma pack(4)
190 typedef struct {
191 dns_config_t config;
192 uint32_t n_attribute;
193 uint32_t n_padding;
194 uint8_t attribute[0];
195 } _dns_config_buf_t;
196 #pragma pack()
197
198
199 #pragma pack(4)
200 typedef struct {
201 dns_resolver_t resolver;
202 uint32_t n_attribute;
203 uint8_t attribute[0];
204 } _dns_resolver_buf_t;
205 #pragma pack()
206
207
208 __BEGIN_DECLS
209
210 __END_DECLS
211
212 #endif /* __DNSINFO_PRIVATE_H__ */