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