]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2004-2006, 2008, 2009 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 <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 | * | | | | ... | ... | | |
76 | * | +-------------+-+-------------------+-----------------------------+ | |
77 | * | | n_attribute | uint32_t | <- how many bytes of "attribute" | |
78 | * | | | | data is associated with the | |
79 | * | | | | configuration | |
80 | * |-+-------------+---------------------------------------------------+ | |
81 | * | | n_padding | uint32_t | <- how many additional bytes | |
82 | * | | | | for arrays (of pointers), ... | |
83 | * +-+-------------+---------------------------------------------------+ | |
84 | * | struct dns_attribute_t | | |
85 | * |-+-------------+---------------------------------------------------+ | |
86 | * | | type | uint32_t | <- type of attribute (e.g. CONFIG_ATTRIBUTE_RESOLVER) | |
87 | * | +-------------+---------------------------------------------------+ | |
88 | * | | length | uint32_t | <- length of the attribute | |
89 | * | +-------------+---------------------------------------------------+ | |
90 | * | | attribute | struct _dns_resolver_buf_t | <- the attribute data (resolver configuration #1) | |
91 | * | | +-+-------------+-----------------------------------+ | |
92 | * | | | | resolver | struct dns_resolver_t | | |
93 | * | | | | +--------------+--------------------+ | |
94 | * | | | | | domain | char * | <- not used during creation, | |
95 | * | | | | | | | filled in with pointer to | |
96 | * | | | | | | | domain name in the "padding" | |
97 | * | | | | +--------------+--------------------+ | |
98 | * | | | | | n_nameserver | int32_t | <- # of name server addresses | |
99 | * | | | | +--------------+--------------------+ | |
100 | * | | | | | nameserver | struct sockaddr ** | <- not used during creation, | |
101 | * | | | | | | | filled in with pointer to | |
102 | * | | | | | | | a list of addresses which | |
103 | * | | | | | | | will be established in the | |
104 | * | | | | | | | "padding" | |
105 | * | | | | +--------------+--------------------+ | |
106 | * | | | | | ... | | |
107 | * | | +-+-------------+--------------+--------------------+ | |
108 | * | | | | n_attribute | uint32_t | | |
109 | * | | +-+-------------+-----------------------------------+ | |
110 | * | | | | attribute | struct dns_attribute_t | | |
111 | * | | | | +-+-----------+---------------------+ | |
112 | * | | | | | | type | uint32_t | <- type of attribute (e.g. RESOLVER_ATTRIBUTE_DOMAIN) | |
113 | * | | | | | +-----------+---------------------+ | |
114 | * | | | | | | length | uint32_t | <- length of the attribute | |
115 | * | | | | | +-----------+---------------------+ | |
116 | * | | | | | | attribute | | <- the attribute data ("apple.com") | |
117 | * | | +-+-------------+-------------+---------------------+ | |
118 | * | | | | attribute | struct dns_attribute_t | | |
119 | * | | | | +-+-----------+---------------------+ | |
120 | * | | | | | | type | uint32_t | <- type of attribute (e.g. RESOLVER_ATTRIBUTE_ADDRESS) | |
121 | * | | | | | +-----------+---------------------+ | |
122 | * | | | | | | length | uint32_t | <- length of the attribute | |
123 | * | | | | | +-----------+---------------------+ | |
124 | * | | | | | | attribute | | <- the attribute data ("struct sockaddr_in" #1) | |
125 | * | | +---------------+-----------------------------------+ | |
126 | * | | | | attribute | struct dns_attribute_t | | |
127 | * | | | | +-+-----------+---------------------+ | |
128 | * | | | | | | type | uint32_t | <- type of attribute (e.g. RESOLVER_ATTRIBUTE_ADDRESS) | |
129 | * | | | | | +-----------+---------------------+ | |
130 | * | | | | | | length | uint32_t | <- length of the attribute | |
131 | * | | | | | +-----------+---------------------+ | |
132 | * | | | | | | attribute | | <- the attribute data ("struct sockaddr_in" #2) | |
133 | * | | +---------------+-----------------------------------+ | |
134 | * | | | ... | | |
135 | * +-+-------------+---------------------------------------------------+ | |
136 | * | | attribute | struct _dns_resolver_buf_t | <- the attribute data (resolver configuration #2) | |
137 | * | | +---------------+-----------------------------------+ | |
138 | * | | | ... | | |
139 | * +---------------+---------------------------------------------------+ | |
140 | * | | ... | | |
141 | * +---------------+---------------------------------------------------+ | |
142 | * | |
143 | * When the data is unpacked the "n_padding" additional bytes | |
144 | * specified in configuration buffer will be allocated at the | |
145 | * end of this buffer. Arrays of pointers will be allocated | |
146 | * within the extra space array element (an "attribute") is | |
147 | * encountered the pointer reference will be filled in. | |
148 | */ | |
149 | ||
150 | ||
151 | // configuration buffer attributes | |
152 | enum { | |
153 | CONFIG_ATTRIBUTE_RESOLVER = 1, | |
154 | CONFIG_ATTRIBUTE_SCOPED_RESOLVER, | |
155 | }; | |
156 | ||
157 | ||
158 | // resolver buffer attributes | |
159 | enum { | |
160 | RESOLVER_ATTRIBUTE_DOMAIN = 10, | |
161 | RESOLVER_ATTRIBUTE_ADDRESS, | |
162 | RESOLVER_ATTRIBUTE_SEARCH, | |
163 | RESOLVER_ATTRIBUTE_SORTADDR, | |
164 | RESOLVER_ATTRIBUTE_IF_INDEX, | |
165 | RESOLVER_ATTRIBUTE_FLAGS, | |
166 | RESOLVER_ATTRIBUTE_OPTIONS, | |
167 | }; | |
168 | ||
169 | ||
170 | #pragma pack(4) | |
171 | typedef struct { | |
172 | uint32_t type; | |
173 | uint32_t length; | |
174 | uint8_t attribute[0]; | |
175 | } dns_attribute_t; | |
176 | #pragma pack() | |
177 | ||
178 | ||
179 | #pragma pack(4) | |
180 | typedef struct { | |
181 | dns_config_t config; | |
182 | uint32_t n_attribute; | |
183 | uint32_t n_padding; | |
184 | uint8_t attribute[0]; | |
185 | } _dns_config_buf_t; | |
186 | #pragma pack() | |
187 | ||
188 | ||
189 | #pragma pack(4) | |
190 | typedef struct { | |
191 | dns_resolver_t resolver; | |
192 | uint32_t n_attribute; | |
193 | uint8_t attribute[0]; | |
194 | } _dns_resolver_buf_t; | |
195 | #pragma pack() | |
196 | ||
197 | ||
198 | __BEGIN_DECLS | |
199 | ||
200 | /* | |
201 | * NOTE: __private_extern__ and __OSX_AVAILABLE_STARTING() cannot be mixed | |
202 | * due to a "visibility" conflict | |
203 | */ | |
204 | ||
205 | __private_extern__ | |
206 | const char * | |
207 | _dns_configuration_notify_key () /*__OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_2_0)*/; | |
208 | ||
209 | __private_extern__ | |
210 | mach_port_t | |
211 | _dns_configuration_server_port () /*__OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_2_0)*/; | |
212 | ||
213 | __END_DECLS | |
214 | ||
215 | #endif /* __DNSINFO_PRIVATE_H__ */ |