]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/mDNSMacOSX.h
mDNSResponder-379.32.1.tar.gz
[apple/mdnsresponder.git] / mDNSMacOSX / mDNSMacOSX.h
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2002-2003 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
18 #ifndef __mDNSOSX_h
19 #define __mDNSOSX_h
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #include <SystemConfiguration/SystemConfiguration.h>
26 #include <IOKit/pwr_mgt/IOPM.h>
27 #include <IOKit/pwr_mgt/IOPMLib.h>
28 #include <IOKit/pwr_mgt/IOPMLibPrivate.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31 #include "mDNSEmbeddedAPI.h" // for domain name structure
32
33 //#define MDNSRESPONDER_USES_LIB_DISPATCH_AS_PRIMARY_EVENT_LOOP_MECHANISM
34 #ifdef MDNSRESPONDER_USES_LIB_DISPATCH_AS_PRIMARY_EVENT_LOOP_MECHANISM
35 #include <dispatch/dispatch.h>
36 #endif
37
38 typedef struct NetworkInterfaceInfoOSX_struct NetworkInterfaceInfoOSX;
39
40 typedef void (*KQueueEventCallback)(int fd, short filter, void *context);
41 typedef struct
42 {
43 KQueueEventCallback KQcallback;
44 void *KQcontext;
45 const char const *KQtask; // For debugging messages
46 #ifdef MDNSRESPONDER_USES_LIB_DISPATCH_AS_PRIMARY_EVENT_LOOP_MECHANISM
47 dispatch_source_t readSource;
48 dispatch_source_t writeSource;
49 mDNSBool fdClosed;
50 #endif
51 } KQueueEntry;
52
53 typedef struct
54 {
55 mDNSIPPort port; // MUST BE FIRST FIELD -- UDPSocket_struct begins with a KQSocketSet,
56 // and mDNSCore requires every UDPSocket_struct to begin with a mDNSIPPort port
57 mDNS *m;
58 int sktv4;
59 KQueueEntry kqsv4;
60 #ifndef NO_IPV6
61 int sktv6;
62 KQueueEntry kqsv6;
63 #endif
64 int *closeFlag;
65 } KQSocketSet;
66
67 struct UDPSocket_struct
68 {
69 KQSocketSet ss; // First field of KQSocketSet has to be mDNSIPPort -- mDNSCore requires every UDPSocket_struct to begin with mDNSIPPort port
70 };
71
72 struct NetworkInterfaceInfoOSX_struct
73 {
74 NetworkInterfaceInfo ifinfo; // MUST be the first element in this structure
75 NetworkInterfaceInfoOSX *next;
76 mDNS *m;
77 mDNSu8 Exists; // 1 = currently exists in getifaddrs list; 0 = doesn't
78 // 2 = exists, but McastTxRx state changed
79 mDNSu8 Flashing; // Set if interface appeared for less than 60 seconds and then vanished
80 mDNSu8 Occulting; // Set if interface vanished for less than 60 seconds and then came back
81 mDNSu8 D2DInterface; // IFEF_LOCALNET_PRIVATE flag indicates we should call
82 // D2D plugin for operations over this interface
83
84 mDNSs32 AppearanceTime; // Time this interface appeared most recently in getifaddrs list
85 // i.e. the first time an interface is seen, AppearanceTime is set.
86 // If an interface goes away temporarily and then comes back then
87 // AppearanceTime is updated to the time of the most recent appearance.
88 mDNSs32 LastSeen; // If Exists==0, last time this interface appeared in getifaddrs list
89 unsigned int ifa_flags;
90 struct in_addr ifa_v4addr;
91 mDNSu32 scope_id; // interface index / IPv6 scope ID
92 mDNSEthAddr BSSID; // BSSID of 802.11 base station, if applicable
93 u_short sa_family;
94 int BPF_fd; // -1 uninitialized; -2 requested BPF; -3 failed
95 int BPF_mcfd; // Socket for our IPv6 ND group membership
96 u_int BPF_len;
97 #ifdef MDNSRESPONDER_USES_LIB_DISPATCH_AS_PRIMARY_EVENT_LOOP_MECHANISM
98 dispatch_source_t BPF_source;
99 #else
100 CFSocketRef BPF_cfs;
101 CFRunLoopSourceRef BPF_rls;
102 #endif
103 NetworkInterfaceInfoOSX *Registered; // non-NULL means registered with mDNS Core
104 };
105
106 struct mDNS_PlatformSupport_struct
107 {
108 NetworkInterfaceInfoOSX *InterfaceList;
109 KQSocketSet permanentsockets;
110 domainlabel userhostlabel; // The hostlabel as it was set in System Preferences the last time we looked
111 domainlabel usernicelabel; // The nicelabel as it was set in System Preferences the last time we looked
112 // Following four variables are used for optimization where the helper is not
113 // invoked when not needed. It records the state of what we told helper the
114 // last time we invoked mDNSPreferencesSetName
115 domainlabel prevoldhostlabel; // Previous m->p->userhostlabel
116 domainlabel prevnewhostlabel; // Previous m->hostlabel
117 domainlabel prevoldnicelabel; // Previous m->p->usernicelabel
118 domainlabel prevnewnicelabel; // Previous m->nicelabel
119 mDNSs32 NotifyUser;
120 mDNSs32 HostNameConflict; // Time we experienced conflict on our link-local host name
121 mDNSs32 NetworkChanged;
122 mDNSs32 KeyChainTimer;
123
124 CFRunLoopRef CFRunLoop;
125 SCDynamicStoreRef Store;
126 CFRunLoopSourceRef StoreRLS;
127 CFRunLoopSourceRef PMRLS;
128 int SysEventNotifier;
129 KQueueEntry SysEventKQueue;
130 IONotificationPortRef PowerPortRef;
131 io_connect_t PowerConnection;
132 io_object_t PowerNotifier;
133 #ifdef kIOPMAcknowledgmentOptionSystemCapabilityRequirements
134 IOPMConnection IOPMConnection;
135 #endif
136 IOPMAssertionID IOPMAssertion;
137 long SleepCookie; // Cookie we need to pass to IOAllowPowerChange()
138 long WakeAtUTC;
139 mDNSs32 RequestReSleep;
140 #ifdef MDNSRESPONDER_USES_LIB_DISPATCH_AS_PRIMARY_EVENT_LOOP_MECHANISM
141 dispatch_source_t timer;
142 dispatch_source_t custom;
143 #else
144 pthread_mutex_t BigMutex;
145 #endif
146 mDNSs32 BigMutexStartTime;
147 int WakeKQueueLoopFD;
148 };
149
150 extern int OfferSleepProxyService;
151 extern int DisableSleepProxyClient;
152 extern int UseInternalSleepProxy;
153 extern int OSXVers, iOSVers;
154 #define OSXVers_Base 4
155 #define OSXVers_10_0_Cheetah 4
156 #define OSXVers_10_1_Puma 5
157 #define OSXVers_10_2_Jaguar 6
158 #define OSXVers_10_3_Panther 7
159 #define OSXVers_10_4_Tiger 8
160 #define OSXVers_10_5_Leopard 9
161 #define OSXVers_10_6_SnowLeopard 10
162
163 extern int KQueueFD;
164
165 extern void NotifyOfElusiveBug(const char *title, const char *msg); // Both strings are UTF-8 text
166 extern void SetDomainSecrets(mDNS *m);
167 extern void mDNSMacOSXNetworkChanged(mDNS *const m);
168 extern void mDNSMacOSXSystemBuildNumber(char *HINFO_SWstring);
169 extern NetworkInterfaceInfoOSX *IfindexToInterfaceInfoOSX(const mDNS *const m, mDNSInterfaceID ifindex);
170 extern void mDNSUpdatePacketFilter(const ResourceRecord *const excludeRecord);
171
172 #ifdef MDNSRESPONDER_USES_LIB_DISPATCH_AS_PRIMARY_EVENT_LOOP_MECHANISM
173 extern int KQueueSet(int fd, u_short flags, short filter, KQueueEntry *const entryRef);
174 mDNSexport void TriggerEventCompletion(void);
175 #else
176 extern int KQueueSet(int fd, u_short flags, short filter, const KQueueEntry *const entryRef);
177 #endif
178
179 // When events are processed on the non-kqueue thread (i.e. CFRunLoop notifications like Sleep/Wake,
180 // Interface changes, Keychain changes, etc.) they must use KQueueLock/KQueueUnlock to lock out the kqueue thread
181 extern void KQueueLock(mDNS *const m);
182 extern void KQueueUnlock(mDNS *const m, const char const *task);
183 extern void mDNSPlatformCloseFD(KQueueEntry *kq, int fd);
184
185 extern mDNSBool DictionaryIsEnabled(CFDictionaryRef dict);
186
187 extern void mDNSPlatformToggleInterfaceAdvt(mDNS *const m, mDNSBool stopAdvt);
188
189 // If any event takes more than WatchDogReportingThreshold milliseconds to be processed, we log a warning message
190 // General event categories are:
191 // o Mach client request initiated / terminated
192 // o UDS client request
193 // o Handling UDP packets received from the network
194 // o Environmental change events:
195 // - network interface changes
196 // - sleep/wake
197 // - keychain changes
198 // o Name conflict dialog dismissal
199 // o Reception of Unix signal (e.g. SIGINFO)
200 // o Idle task processing
201 // If we find that we're getting warnings for any of these categories, and it's not evident
202 // what's causing the problem, we may need to subdivide some categories into finer-grained
203 // sub-categories (e.g. "Idle task processing" covers a pretty broad range of sub-tasks).
204
205 extern int WatchDogReportingThreshold;
206
207 struct CompileTimeAssertionChecks_mDNSMacOSX
208 {
209 // Check our structures are reasonable sizes. Including overly-large buffers, or embedding
210 // other overly-large structures instead of having a pointer to them, can inadvertently
211 // cause structure sizes (and therefore memory usage) to balloon unreasonably.
212 char sizecheck_NetworkInterfaceInfoOSX[(sizeof(NetworkInterfaceInfoOSX) <= 7000) ? 1 : -1];
213 char sizecheck_mDNS_PlatformSupport [(sizeof(mDNS_PlatformSupport) <= 768) ? 1 : -1];
214 };
215
216 #ifdef __cplusplus
217 }
218 #endif
219
220 #endif