1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2002-2013 Apple Inc. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include "mDNSEmbeddedAPI.h"
22 #include "dnssd_ipc.h"
26 // ***************************************************************************
27 #if COMPILER_LIKES_PRAGMA_MARK
29 #pragma mark - Types and Data Structures
41 typedef struct request_state request_state;
43 typedef void (*req_termination_fn)(request_state *request);
45 typedef struct registered_record_entry
47 struct registered_record_entry *next;
49 client_context_t regrec_client_context;
50 request_state *request;
51 mDNSBool external_advertise;
52 mDNSInterfaceID origInterfaceID;
53 AuthRecord *rr; // Pointer to variable-sized AuthRecord (Why a pointer? Why not just embed it here?)
54 } registered_record_entry;
56 // A single registered service: ServiceRecordSet + bookkeeping
57 // Note that we duplicate some fields from parent service_info object
58 // to facilitate cleanup, when instances and parent may be deallocated at different times.
59 typedef struct service_instance
61 struct service_instance *next;
62 request_state *request;
64 mDNSBool renameonmemfree; // Set on config change when we deregister original name
65 mDNSBool clientnotified; // Has client been notified of successful registration yet?
66 mDNSBool default_local; // is this the "local." from an empty-string registration?
67 mDNSBool external_advertise; // is this is being advertised externally?
69 ServiceRecordSet srs; // note -- variable-sized object -- must be last field in struct
72 // for multi-domain default browsing
73 typedef struct browser_t
75 struct browser_t *next;
81 typedef unsigned int pid_t;
82 typedef unsigned int socklen_t;
85 #if (!defined(MAXCOMLEN))
92 request_state *primary; // If this operation is on a shared socket, pointer to primary
93 // request_state for the original DNSServiceCreateConnection() operation
95 pid_t process_id; // Client's PID value
96 char pid_name[MAXCOMLEN]; // Client's process name
97 mDNSu8 uuid[UUID_SIZE];
101 void * platform_data;
103 // Note: On a shared connection these fields in the primary structure, including hdr, are re-used
104 // for each new request. This is because, until we've read the ipc_msg_hdr to find out what the
105 // operation is, we don't know if we're going to need to allocate a new request_state or not.
107 mDNSu32 hdr_bytes; // bytes of header already read
109 mDNSu32 data_bytes; // bytes of message data already read
110 char *msgbuf; // pointer to data storage to pass to free()
111 const char *msgptr; // pointer to data to be read from (may be modified)
112 char *msgend; // pointer to byte after last byte of message
114 // reply, termination, error, and client context info
115 int no_reply; // don't send asynchronous replies to client
116 mDNSs32 time_blocked; // record time of a blocked client
117 int unresponsiveness_reports;
118 struct reply_state *replies; // corresponding (active) reply list
119 req_termination_fn terminate;
120 DNSServiceFlags flags;
121 mDNSu32 interfaceIndex;
125 registered_record_entry *reg_recs; // list of registrations for a connection-oriented request
128 mDNSInterfaceID interface_id;
129 mDNSBool default_domain;
133 const mDNSu8 *AnonData;
137 mDNSInterfaceID InterfaceID;
142 char type_as_string[MAX_ESCAPED_DOMAIN_NAME];
144 mDNSBool default_domain;
146 mDNSBool autoname; // Set if this name is tied to the Computer Name
147 mDNSBool autorename; // Set if this client wants us to automatically rename on conflict
148 mDNSBool allowremotequery; // Respond to unicast queries from outside the local link?
151 service_instance *instances;
155 mDNSInterfaceID interface_id;
167 mDNSIPPort ReqExt; // External port we originally requested, for logging purposes
168 NATTraversalInfo NATinfo;
172 DNSServiceFlags flags;
174 DNSQuestion q_default;
175 DNSQuestion q_autoall;
187 const ResourceRecord *txt;
188 const ResourceRecord *srv;
190 mDNSBool external_advertise;
195 // struct physically sits between ipc message header and call-specific fields in the message buffer
198 DNSServiceFlags flags; // Note: This field is in NETWORK byte order
199 mDNSu32 ifi; // Note: This field is in NETWORK byte order
200 DNSServiceErrorType error; // Note: This field is in NETWORK byte order
203 typedef struct reply_state
205 struct reply_state *next; // If there are multiple unsent replies
212 /* Client interface: */
214 #define SRS_PORT(S) mDNSVal16((S)->RR_SRV.resrec.rdata->u.srv.port)
216 #define LogTimer(MSG,T) LogMsgNoIdent( MSG " %08X %11d %08X %11d", (T), (T), (T)-now, (T)-now)
218 extern int udsserver_init(dnssd_sock_t skts[], mDNSu32 count);
219 extern mDNSs32 udsserver_idle(mDNSs32 nextevent);
220 extern void udsserver_info(void); // print out info about current state
221 extern void udsserver_handle_configchange(mDNS *const m);
222 extern int udsserver_exit(void); // should be called prior to app exit
223 extern void LogMcastStateInfo(mDNSBool mflag, mDNSBool start, mDNSBool mstatelog);
224 #define LogMcastQ (mDNS_McastLoggingEnabled == 0) ? ((void)0) : LogMcastQuestion
225 #define LogMcastS (mDNS_McastLoggingEnabled == 0) ? ((void)0) : LogMcastService
226 #define LogMcast (mDNS_McastLoggingEnabled == 0) ? ((void)0) : LogMsg
227 #define LogMcastNoIdent (mDNS_McastLoggingEnabled == 0) ? ((void)0) : LogMsgNoIdent
229 /* Routines that uds_daemon expects to link against: */
231 typedef void (*udsEventCallback)(int fd, short filter, void *context);
232 extern mStatus udsSupportAddFDToEventLoop(dnssd_sock_t fd, udsEventCallback callback, void *context, void **platform_data);
233 extern int udsSupportReadFD(dnssd_sock_t fd, char* buf, int len, int flags, void *platform_data);
234 extern mStatus udsSupportRemoveFDFromEventLoop(dnssd_sock_t fd, void *platform_data); // Note: This also CLOSES the file descriptor as well
236 extern void RecordUpdatedNiceLabel(mDNSs32 delay);
238 // Globals and functions defined in uds_daemon.c and also shared with the old "daemon.c" on OS X
240 extern mDNS mDNSStorage;
241 extern DNameListElem *AutoRegistrationDomains;
242 extern DNameListElem *AutoBrowseDomains;
244 extern mDNSs32 ChopSubTypes(char *regtype, char **AnonData);
245 extern AuthRecord *AllocateSubTypes(mDNSs32 NumSubTypes, char *p, char **AnonData);
246 extern int CountExistingRegistrations(domainname *srv, mDNSIPPort port);
247 extern mDNSBool callExternalHelpers(mDNSInterfaceID InterfaceID, const domainname *const domain, DNSServiceFlags flags);
248 extern void FreeExtraRR(mDNS *const m, AuthRecord *const rr, mStatus result);
249 extern int CountPeerRegistrations(ServiceRecordSet *const srs);
251 #if APPLE_OSX_mDNSResponder
253 // D2D interface support
254 extern void external_start_browsing_for_service(mDNSInterfaceID InterfaceID, const domainname *const type, DNS_TypeValues qtype, DNSServiceFlags flags);
255 extern void external_stop_browsing_for_service(mDNSInterfaceID InterfaceID, const domainname *const type, DNS_TypeValues qtype, DNSServiceFlags flags);
256 extern void external_start_advertising_service(const ResourceRecord *const resourceRecord, DNSServiceFlags flags);
257 extern void external_stop_advertising_service(const ResourceRecord *const resourceRecord, DNSServiceFlags flags);
258 extern void external_start_resolving_service(mDNSInterfaceID InterfaceID, const domainname *const fqdn, DNSServiceFlags flags);
259 extern void external_stop_resolving_service(mDNSInterfaceID InterfaceID, const domainname *const fqdn, DNSServiceFlags flags);
260 extern void external_connection_release(const domainname *instance);
262 #else // APPLE_OSX_mDNSResponder
264 #define external_start_browsing_for_service(A,B,C,D) (void)(A)
265 #define external_stop_browsing_for_service(A,B,C,D) (void)(A)
266 #define external_start_advertising_service(A,B) (void)(A)
267 #define external_stop_advertising_service(A,B) do { (void)(A); (void)(B); } while (0)
268 #define external_start_resolving_service(A,B,C) (void)(A)
269 #define external_stop_resolving_service(A,B,C) (void)(A)
270 #define external_connection_release(A) (void)(A)
272 #endif // APPLE_OSX_mDNSResponder
274 extern const char mDNSResponderVersionString_SCCS[];
275 #define mDNSResponderVersionString (mDNSResponderVersionString_SCCS+5)
278 extern void SetDebugBoundPath(void);
279 extern int IsDebugSocketInUse(void);
282 #endif /* UDS_DAEMON_H */