]>
Commit | Line | Data |
---|---|---|
dbf6a266 | 1 | /* |
5e9ce69e | 2 | * Copyright (c) 2004-2006, 2008, 2009, 2012, 2013 Apple Inc. All rights reserved. |
dbf6a266 A |
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 | ||
a40a14f8 | 28 | #include <Availability.h> |
d6c893b2 | 29 | #include <sys/cdefs.h> |
dbf6a266 A |
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 | ||
dbf6a266 A |
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 | * +-+-------------+---------------------------------------------------+ | |
6bb65964 A |
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 | * | | | +-------------------+-----------------------------+ | |
5e9ce69e A |
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 | * | | | +-------------------+---------+-------------------+ | |
6bb65964 A |
84 | * | | | | ... | ... | |
85 | * | +-------------+-+-------------------+-----------------------------+ | |
dbf6a266 | 86 | * | | n_attribute | uint32_t | <- how many bytes of "attribute" |
6bb65964 A |
87 | * | | | | data is associated with the |
88 | * | | | | configuration | |
dbf6a266 A |
89 | * |-+-------------+---------------------------------------------------+ |
90 | * | | n_padding | uint32_t | <- how many additional bytes | |
6bb65964 | 91 | * | | | | for arrays (of pointers), ... |
dbf6a266 A |
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 | | |
6bb65964 A |
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 | * | | | | | ... | | |
dbf6a266 A |
116 | * | | +-+-------------+--------------+--------------------+ |
117 | * | | | | n_attribute | uint32_t | | |
118 | * | | +-+-------------+-----------------------------------+ | |
119 | * | | | | attribute | struct dns_attribute_t | | |
6bb65964 A |
120 | * | | | | +-+-----------+---------------------+ |
121 | * | | | | | | type | uint32_t | <- type of attribute (e.g. RESOLVER_ATTRIBUTE_DOMAIN) | |
122 | * | | | | | +-----------+---------------------+ | |
dbf6a266 | 123 | * | | | | | | length | uint32_t | <- length of the attribute |
6bb65964 A |
124 | * | | | | | +-----------+---------------------+ |
125 | * | | | | | | attribute | | <- the attribute data ("apple.com") | |
dbf6a266 A |
126 | * | | +-+-------------+-------------+---------------------+ |
127 | * | | | | attribute | struct dns_attribute_t | | |
6bb65964 A |
128 | * | | | | +-+-----------+---------------------+ |
129 | * | | | | | | type | uint32_t | <- type of attribute (e.g. RESOLVER_ATTRIBUTE_ADDRESS) | |
130 | * | | | | | +-----------+---------------------+ | |
dbf6a266 | 131 | * | | | | | | length | uint32_t | <- length of the attribute |
6bb65964 A |
132 | * | | | | | +-----------+---------------------+ |
133 | * | | | | | | attribute | | <- the attribute data ("struct sockaddr_in" #1) | |
dbf6a266 A |
134 | * | | +---------------+-----------------------------------+ |
135 | * | | | | attribute | struct dns_attribute_t | | |
6bb65964 A |
136 | * | | | | +-+-----------+---------------------+ |
137 | * | | | | | | type | uint32_t | <- type of attribute (e.g. RESOLVER_ATTRIBUTE_ADDRESS) | |
138 | * | | | | | +-----------+---------------------+ | |
dbf6a266 | 139 | * | | | | | | length | uint32_t | <- length of the attribute |
6bb65964 A |
140 | * | | | | | +-----------+---------------------+ |
141 | * | | | | | | attribute | | <- the attribute data ("struct sockaddr_in" #2) | |
dbf6a266 | 142 | * | | +---------------+-----------------------------------+ |
6bb65964 | 143 | * | | | ... | |
dbf6a266 | 144 | * +-+-------------+---------------------------------------------------+ |
6bb65964 | 145 | * | | attribute | struct _dns_resolver_buf_t | <- the attribute data (resolver configuration #2) |
dbf6a266 | 146 | * | | +---------------+-----------------------------------+ |
6bb65964 | 147 | * | | | ... | |
dbf6a266 | 148 | * +---------------+---------------------------------------------------+ |
6bb65964 | 149 | * | | ... | |
dbf6a266 A |
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 { | |
6bb65964 A |
162 | CONFIG_ATTRIBUTE_RESOLVER = 1, |
163 | CONFIG_ATTRIBUTE_SCOPED_RESOLVER, | |
5e9ce69e | 164 | CONFIG_ATTRIBUTE_SERVICE_SPECIFIC_RESOLVER, |
dbf6a266 A |
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, | |
6bb65964 | 174 | RESOLVER_ATTRIBUTE_OPTIONS, |
dbf6a266 A |
175 | }; |
176 | ||
177 | ||
edebe297 | 178 | #pragma pack(4) |
dbf6a266 A |
179 | typedef struct { |
180 | uint32_t type; | |
181 | uint32_t length; | |
182 | uint8_t attribute[0]; | |
183 | } dns_attribute_t; | |
edebe297 | 184 | #pragma pack() |
dbf6a266 A |
185 | |
186 | ||
edebe297 | 187 | #pragma pack(4) |
dbf6a266 A |
188 | typedef struct { |
189 | dns_config_t config; | |
190 | uint32_t n_attribute; | |
191 | uint32_t n_padding; | |
192 | uint8_t attribute[0]; | |
193 | } _dns_config_buf_t; | |
edebe297 | 194 | #pragma pack() |
dbf6a266 A |
195 | |
196 | ||
edebe297 | 197 | #pragma pack(4) |
dbf6a266 A |
198 | typedef struct { |
199 | dns_resolver_t resolver; | |
200 | uint32_t n_attribute; | |
201 | uint8_t attribute[0]; | |
202 | } _dns_resolver_buf_t; | |
edebe297 | 203 | #pragma pack() |
dbf6a266 A |
204 | |
205 | ||
d6c893b2 | 206 | __BEGIN_DECLS |
dbf6a266 | 207 | |
a40a14f8 | 208 | __END_DECLS |
d6c893b2 A |
209 | |
210 | #endif /* __DNSINFO_PRIVATE_H__ */ |