]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSShared/dnsextd.h
mDNSResponder-212.1.tar.gz
[apple/mdnsresponder.git] / mDNSShared / dnsextd.h
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16
17 Change History (most recent first):
18
19 $Log: dnsextd.h,v $
20 Revision 1.5 2007/03/20 17:07:16 cheshire
21 Rename "struct uDNS_TCPSocket_struct" to "TCPSocket", "struct uDNS_UDPSocket_struct" to "UDPSocket"
22
23 Revision 1.4 2006/12/22 20:59:51 cheshire
24 <rdar://problem/4742742> Read *all* DNS keys from keychain,
25 not just key for the system-wide default registration domain
26
27 Revision 1.3 2006/11/18 05:01:33 cheshire
28 Preliminary support for unifying the uDNS and mDNS code,
29 including caching of uDNS answers
30
31 Revision 1.2 2006/08/14 23:24:56 cheshire
32 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
33
34 Revision 1.1 2006/07/06 00:09:05 cheshire
35 <rdar://problem/4472013> Add Private DNS server functionality to dnsextd
36
37
38 */
39
40
41 #ifndef _dnsextd_h
42 #define _dnsextd_h
43
44
45 #include <mDNSEmbeddedAPI.h>
46 #include <DNSCommon.h>
47 #include <GenLinkedList.h>
48 #include <sys/types.h>
49 #include <sys/socket.h>
50 #include <netinet/in.h>
51
52
53 #define LLQ_TABLESIZE 1024 // !!!KRS make this dynamically growable
54
55
56 typedef enum DNSZoneSpecType
57 {
58 kDNSZonePublic,
59 kDNSZonePrivate
60 } DNSZoneSpecType;
61
62
63 typedef struct DNSZone
64 {
65 domainname name;
66 DNSZoneSpecType type;
67 DomainAuthInfo * updateKeys; // linked list of keys for signing deletion updates
68 DomainAuthInfo * queryKeys; // linked list of keys for queries
69 struct DNSZone * next;
70 } DNSZone;
71
72
73 typedef struct
74 {
75 struct sockaddr_in src;
76 size_t len;
77 DNSZone * zone;
78 mDNSBool isZonePublic;
79 DNSMessage msg;
80 // Note: extra storage for oversized (TCP) messages goes here
81 } PktMsg;
82
83 // lease table entry
84 typedef struct RRTableElem
85 {
86 struct RRTableElem *next;
87 struct sockaddr_in cli; // client's source address
88 long expire; // expiration time, in seconds since epoch
89 domainname zone; // from zone field of update message
90 domainname name; // name of the record
91 CacheRecord rr; // last field in struct allows for allocation of oversized RRs
92 } RRTableElem;
93
94 typedef enum
95 {
96 RequestReceived = 0,
97 ChallengeSent = 1,
98 Established = 2
99 } LLQState;
100
101 typedef struct AnswerListElem
102 {
103 struct AnswerListElem *next;
104 domainname name;
105 mDNSu16 type;
106 CacheRecord *KnownAnswers; // All valid answers delivered to client
107 CacheRecord *EventList; // New answers (adds/removes) to be sent to client
108 int refcount;
109 mDNSBool UseTCP; // Use TCP if UDP would cause truncation
110 pthread_t tid; // Allow parallel list updates
111 } AnswerListElem;
112
113 // llq table entry
114 typedef struct LLQEntry
115 {
116 struct LLQEntry *next;
117 struct sockaddr_in cli; // clien'ts source address
118 domainname qname;
119 mDNSu16 qtype;
120 mDNSOpaque64 id;
121 LLQState state;
122 mDNSu32 lease; // original lease, in seconds
123 mDNSs32 expire; // expiration, absolute, in seconds since epoch
124 AnswerListElem *AnswerList;
125 } LLQEntry;
126
127
128 typedef void (*EventCallback)( void * context );
129
130 typedef struct EventSource
131 {
132 EventCallback callback;
133 void * context;
134 TCPSocket * sock;
135 int fd;
136 mDNSBool markedForDeletion;
137 struct EventSource * next;
138 } EventSource;
139
140
141 // daemon-wide information
142 typedef struct
143 {
144 // server variables - read only after initialization (no locking)
145 struct sockaddr_in addr; // the address we will bind to
146 struct sockaddr_in llq_addr; // the address we will receive llq requests on.
147 struct sockaddr_in ns_addr; // the real ns server address
148 int tcpsd; // listening TCP socket for dns requests
149 int udpsd; // listening UDP socket for dns requests
150 int tlssd; // listening TCP socket for private browsing
151 int llq_tcpsd; // listening TCP socket for llq service
152 int llq_udpsd; // listening UDP socket for llq service
153 DNameListElem * public_names; // list of public SRV names
154 DNSZone * zones;
155
156 // daemon variables - read only after initialization (no locking)
157 mDNSIPPort private_port; // listening port for private messages
158 mDNSIPPort llq_port; // listening port for llq
159
160 // lease table variables (locked via mutex after initialization)
161 RRTableElem **table; // hashtable for records with leases
162 pthread_mutex_t tablelock; // mutex for lease table
163 mDNSs32 nbuckets; // buckets allocated
164 mDNSs32 nelems; // elements in table
165
166 // LLQ table variables
167 LLQEntry *LLQTable[LLQ_TABLESIZE]; // !!!KRS change this and RRTable to use a common data structure
168 AnswerListElem *AnswerTable[LLQ_TABLESIZE];
169 int AnswerTableCount;
170 int LLQEventNotifySock; // Unix domain socket pair - update handling thread writes to EventNotifySock, which wakes
171 int LLQEventListenSock; // the main thread listening on EventListenSock, indicating that the zone has changed
172
173 GenLinkedList eventSources; // linked list of EventSource's
174 } DaemonInfo;
175
176
177 int
178 ParseConfig
179 (
180 DaemonInfo * d,
181 const char * file
182 );
183
184
185 #endif