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