1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2002-2018 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"
23 #include "ClientRequests.h"
27 // ***************************************************************************
28 #if COMPILER_LIKES_PRAGMA_MARK
30 #pragma mark - Types and Data Structures
42 typedef struct request_state request_state
;
44 typedef void (*req_termination_fn
)(request_state
*request
);
46 typedef struct registered_record_entry
48 struct registered_record_entry
*next
;
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
;
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
62 struct service_instance
*next
;
63 request_state
*request
;
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?
70 ServiceRecordSet srs
; // note -- variable-sized object -- must be last field in struct
73 // for multi-domain default browsing
74 typedef struct browser_t
76 struct browser_t
*next
;
82 typedef unsigned int pid_t
;
83 typedef unsigned int socklen_t
;
86 #if (!defined(MAXCOMLEN))
93 request_state
*primary
; // If this operation is on a shared socket, pointer to primary
94 // request_state for the original DNSServiceCreateConnection() operation
96 pid_t process_id
; // Client's PID value
97 char pid_name
[MAXCOMLEN
]; // Client's process name
98 mDNSu8 uuid
[UUID_SIZE
];
103 void * platform_data
;
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.
109 mDNSu32 hdr_bytes
; // bytes of header already read
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
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
;
127 registered_record_entry
*reg_recs
; // list of registrations for a connection-oriented request
130 mDNSInterfaceID interface_id
;
131 mDNSBool default_domain
;
138 mDNSInterfaceID InterfaceID
;
143 char type_as_string
[MAX_ESCAPED_DOMAIN_NAME
];
145 mDNSBool default_domain
;
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?
151 service_instance
*instances
;
155 mDNSIPPort ReqExt
; // External port we originally requested, for logging purposes
156 NATTraversalInfo NATinfo
;
160 DNSServiceFlags flags
;
162 DNSQuestion q_default
;
163 DNSQuestion q_autoall
;
169 const ResourceRecord
*txt
;
170 const ResourceRecord
*srv
;
172 mDNSBool external_advertise
;
174 GetAddrInfoClientRequest addrinfo
;
175 QueryRecordClientRequest queryrecord
;
179 // struct physically sits between ipc message header and call-specific fields in the message buffer
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
187 typedef struct reply_state
189 struct reply_state
*next
; // If there are multiple unsent replies
196 /* Client interface: */
198 #define SRS_PORT(S) mDNSVal16((S)->RR_SRV.resrec.rdata->u.srv.port)
200 #define LogTimerToFD(FILE_DESCRIPTOR, MSG, T) LogToFD((FILE_DESCRIPTOR), MSG " %08X %11d %08X %11d", (T), (T), (T)-now, (T)-now)
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
213 /* Routines that uds_daemon expects to link against: */
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
220 extern void RecordUpdatedNiceLabel(mDNSs32 delay
);
222 // Globals and functions defined in uds_daemon.c and also shared with the old "daemon.c" on OS X
224 extern mDNS mDNSStorage
;
225 extern DNameListElem
*AutoRegistrationDomains
;
226 extern DNameListElem
*AutoBrowseDomains
;
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
);
232 extern const char mDNSResponderVersionString_SCCS
[];
233 #define mDNSResponderVersionString (mDNSResponderVersionString_SCCS+5)
236 extern void SetDebugBoundPath(void);
237 extern int IsDebugSocketInUse(void);
240 #endif /* UDS_DAEMON_H */