]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSShared/uds_daemon.h
mDNSResponder-1096.0.2.tar.gz
[apple/mdnsresponder.git] / mDNSShared / uds_daemon.h
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2002-2018 Apple 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
18 #ifndef UDS_DAEMON_H
19 #define UDS_DAEMON_H
20
21 #include "mDNSEmbeddedAPI.h"
22 #include "dnssd_ipc.h"
23 #include "ClientRequests.h"
24
25 /* Client request: */
26
27 // ***************************************************************************
28 #if COMPILER_LIKES_PRAGMA_MARK
29 #pragma mark -
30 #pragma mark - Types and Data Structures
31 #endif
32
33 typedef enum
34 {
35 t_uninitialized,
36 t_morecoming,
37 t_complete,
38 t_error,
39 t_terminated
40 } transfer_state;
41
42 typedef struct request_state request_state;
43
44 typedef void (*req_termination_fn)(request_state *request);
45
46 typedef struct registered_record_entry
47 {
48 struct registered_record_entry *next;
49 mDNSu32 key;
50 client_context_t regrec_client_context;
51 request_state *request;
52 mDNSBool external_advertise;
53 mDNSInterfaceID origInterfaceID;
54 AuthRecord *rr; // Pointer to variable-sized AuthRecord (Why a pointer? Why not just embed it here?)
55 } registered_record_entry;
56
57 // A single registered service: ServiceRecordSet + bookkeeping
58 // Note that we duplicate some fields from parent service_info object
59 // to facilitate cleanup, when instances and parent may be deallocated at different times.
60 typedef struct service_instance
61 {
62 struct service_instance *next;
63 request_state *request;
64 AuthRecord *subtypes;
65 mDNSBool renameonmemfree; // Set on config change when we deregister original name
66 mDNSBool clientnotified; // Has client been notified of successful registration yet?
67 mDNSBool default_local; // is this the "local." from an empty-string registration?
68 mDNSBool external_advertise; // is this is being advertised externally?
69 domainname domain;
70 ServiceRecordSet srs; // note -- variable-sized object -- must be last field in struct
71 } service_instance;
72
73 // for multi-domain default browsing
74 typedef struct browser_t
75 {
76 struct browser_t *next;
77 domainname domain;
78 DNSQuestion q;
79 } browser_t;
80
81 #ifdef _WIN32
82 typedef unsigned int pid_t;
83 typedef unsigned int socklen_t;
84 #endif
85
86 #if (!defined(MAXCOMLEN))
87 #define MAXCOMLEN 16
88 #endif
89
90 struct request_state
91 {
92 request_state *next;
93 request_state *primary; // If this operation is on a shared socket, pointer to primary
94 // request_state for the original DNSServiceCreateConnection() operation
95 dnssd_sock_t sd;
96 pid_t process_id; // Client's PID value
97 char pid_name[MAXCOMLEN]; // Client's process name
98 mDNSu8 uuid[UUID_SIZE];
99 mDNSBool validUUID;
100 dnssd_sock_t errsd;
101 mDNSu32 uid;
102 mDNSu32 request_id;
103 void * platform_data;
104
105 // Note: On a shared connection these fields in the primary structure, including hdr, are re-used
106 // for each new request. This is because, until we've read the ipc_msg_hdr to find out what the
107 // operation is, we don't know if we're going to need to allocate a new request_state or not.
108 transfer_state ts;
109 mDNSu32 hdr_bytes; // bytes of header already read
110 ipc_msg_hdr hdr;
111 mDNSu32 data_bytes; // bytes of message data already read
112 char *msgbuf; // pointer to data storage to pass to free()
113 const char *msgptr; // pointer to data to be read from (may be modified)
114 char *msgend; // pointer to byte after last byte of message
115
116 // reply, termination, error, and client context info
117 int no_reply; // don't send asynchronous replies to client
118 mDNSs32 time_blocked; // record time of a blocked client
119 int unresponsiveness_reports;
120 struct reply_state *replies; // corresponding (active) reply list
121 req_termination_fn terminate;
122 DNSServiceFlags flags;
123 mDNSu32 interfaceIndex;
124
125 union
126 {
127 registered_record_entry *reg_recs; // list of registrations for a connection-oriented request
128 struct
129 {
130 mDNSInterfaceID interface_id;
131 mDNSBool default_domain;
132 mDNSBool ForceMCast;
133 domainname regtype;
134 browser_t *browsers;
135 } browser;
136 struct
137 {
138 mDNSInterfaceID InterfaceID;
139 mDNSu16 txtlen;
140 void *txtdata;
141 mDNSIPPort port;
142 domainlabel name;
143 char type_as_string[MAX_ESCAPED_DOMAIN_NAME];
144 domainname type;
145 mDNSBool default_domain;
146 domainname host;
147 mDNSBool autoname; // Set if this name is tied to the Computer Name
148 mDNSBool autorename; // Set if this client wants us to automatically rename on conflict
149 mDNSBool allowremotequery; // Respond to unicast queries from outside the local link?
150 int num_subtypes;
151 service_instance *instances;
152 } servicereg;
153 struct
154 {
155 mDNSIPPort ReqExt; // External port we originally requested, for logging purposes
156 NATTraversalInfo NATinfo;
157 } pm;
158 struct
159 {
160 DNSServiceFlags flags;
161 DNSQuestion q_all;
162 DNSQuestion q_default;
163 DNSQuestion q_autoall;
164 } enumeration;
165 struct
166 {
167 DNSQuestion qtxt;
168 DNSQuestion qsrv;
169 const ResourceRecord *txt;
170 const ResourceRecord *srv;
171 mDNSs32 ReportTime;
172 mDNSBool external_advertise;
173 } resolve;
174 GetAddrInfoClientRequest addrinfo;
175 QueryRecordClientRequest queryrecord;
176 } u;
177 };
178
179 // struct physically sits between ipc message header and call-specific fields in the message buffer
180 typedef struct
181 {
182 DNSServiceFlags flags; // Note: This field is in NETWORK byte order
183 mDNSu32 ifi; // Note: This field is in NETWORK byte order
184 DNSServiceErrorType error; // Note: This field is in NETWORK byte order
185 } reply_hdr;
186
187 typedef struct reply_state
188 {
189 struct reply_state *next; // If there are multiple unsent replies
190 mDNSu32 totallen;
191 mDNSu32 nwriten;
192 ipc_msg_hdr mhdr[1];
193 reply_hdr rhdr[1];
194 } reply_state;
195
196 /* Client interface: */
197
198 #define SRS_PORT(S) mDNSVal16((S)->RR_SRV.resrec.rdata->u.srv.port)
199
200 #define LogTimerToFD(FILE_DESCRIPTOR, MSG, T) LogToFD((FILE_DESCRIPTOR), MSG " %08X %11d %08X %11d", (T), (T), (T)-now, (T)-now)
201
202 extern int udsserver_init(dnssd_sock_t skts[], mDNSu32 count);
203 extern mDNSs32 udsserver_idle(mDNSs32 nextevent);
204 extern void udsserver_info_dump_to_fd(int fd);
205 extern void udsserver_handle_configchange(mDNS *const m);
206 extern int udsserver_exit(void); // should be called prior to app exit
207 extern void LogMcastStateInfo(mDNSBool mflag, mDNSBool start, mDNSBool mstatelog);
208 #define LogMcastQ (mDNS_McastLoggingEnabled == 0) ? ((void)0) : LogMcastQuestion
209 #define LogMcastS (mDNS_McastLoggingEnabled == 0) ? ((void)0) : LogMcastService
210 #define LogMcast (mDNS_McastLoggingEnabled == 0) ? ((void)0) : LogMsg
211 #define LogMcastNoIdent (mDNS_McastLoggingEnabled == 0) ? ((void)0) : LogMsgNoIdent
212
213 /* Routines that uds_daemon expects to link against: */
214
215 typedef void (*udsEventCallback)(int fd, void *context);
216 extern mStatus udsSupportAddFDToEventLoop(dnssd_sock_t fd, udsEventCallback callback, void *context, void **platform_data);
217 extern int udsSupportReadFD(dnssd_sock_t fd, char* buf, int len, int flags, void *platform_data);
218 extern mStatus udsSupportRemoveFDFromEventLoop(dnssd_sock_t fd, void *platform_data); // Note: This also CLOSES the file descriptor as well
219
220 extern void RecordUpdatedNiceLabel(mDNSs32 delay);
221
222 // Globals and functions defined in uds_daemon.c and also shared with the old "daemon.c" on OS X
223
224 extern mDNS mDNSStorage;
225 extern DNameListElem *AutoRegistrationDomains;
226 extern DNameListElem *AutoBrowseDomains;
227
228 extern int CountExistingRegistrations(domainname *srv, mDNSIPPort port);
229 extern void FreeExtraRR(mDNS *const m, AuthRecord *const rr, mStatus result);
230 extern int CountPeerRegistrations(ServiceRecordSet *const srs);
231
232 extern const char mDNSResponderVersionString_SCCS[];
233 #define mDNSResponderVersionString (mDNSResponderVersionString_SCCS+5)
234
235 #if DEBUG
236 extern void SetDebugBoundPath(void);
237 extern int IsDebugSocketInUse(void);
238 #endif
239
240 #endif /* UDS_DAEMON_H */