]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/mDNSMacOSX.h
mDNSResponder-320.5.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 mDNSs32 AppearanceTime; // Time this interface appeared most recently in getifaddrs list
82 // i.e. the first time an interface is seen, AppearanceTime is set.
83 // If an interface goes away temporarily and then comes back then
84 // AppearanceTime is updated to the time of the most recent appearance.
85 mDNSs32 LastSeen; // If Exists==0, last time this interface appeared in getifaddrs list
86 unsigned int ifa_flags;
87 struct in_addr ifa_v4addr;
88 mDNSu32 scope_id; // interface index / IPv6 scope ID
89 mDNSEthAddr BSSID; // BSSID of 802.11 base station, if applicable
90 u_short sa_family;
91 int BPF_fd; // -1 uninitialized; -2 requested BPF; -3 failed
92 int BPF_mcfd; // Socket for our IPv6 ND group membership
93 u_int BPF_len;
94 #ifdef MDNSRESPONDER_USES_LIB_DISPATCH_AS_PRIMARY_EVENT_LOOP_MECHANISM
95 dispatch_source_t BPF_source;
96 #else
97 CFSocketRef BPF_cfs;
98 CFRunLoopSourceRef BPF_rls;
99 #endif
100 NetworkInterfaceInfoOSX *Registered; // non-NULL means registered with mDNS Core
101 };
102
103 struct mDNS_PlatformSupport_struct
104 {
105 NetworkInterfaceInfoOSX *InterfaceList;
106 KQSocketSet permanentsockets;
107 domainlabel userhostlabel; // The hostlabel as it was set in System Preferences the last time we looked
108 domainlabel usernicelabel; // The nicelabel as it was set in System Preferences the last time we looked
109 // Following four variables are used for optimization where the helper is not
110 // invoked when not needed. It records the state of what we told helper the
111 // last time we invoked mDNSPreferencesSetName
112 domainlabel prevoldhostlabel; // Previous m->p->userhostlabel
113 domainlabel prevnewhostlabel; // Previous m->hostlabel
114 domainlabel prevoldnicelabel; // Previous m->p->usernicelabel
115 domainlabel prevnewnicelabel; // Previous m->nicelabel
116 mDNSs32 NotifyUser;
117 mDNSs32 HostNameConflict; // Time we experienced conflict on our link-local host name
118 mDNSs32 NetworkChanged;
119 mDNSs32 KeyChainTimer;
120
121 CFRunLoopRef CFRunLoop;
122 SCDynamicStoreRef Store;
123 CFRunLoopSourceRef StoreRLS;
124 CFRunLoopSourceRef PMRLS;
125 int SysEventNotifier;
126 KQueueEntry SysEventKQueue;
127 IONotificationPortRef PowerPortRef;
128 io_connect_t PowerConnection;
129 io_object_t PowerNotifier;
130 #ifdef kIOPMAcknowledgmentOptionSystemCapabilityRequirements
131 IOPMConnection IOPMConnection;
132 #endif
133 IOPMAssertionID IOPMAssertion;
134 SCPreferencesRef SCPrefs;
135 long SleepCookie; // Cookie we need to pass to IOAllowPowerChange()
136 long WakeAtUTC;
137 mDNSs32 RequestReSleep;
138 #ifdef MDNSRESPONDER_USES_LIB_DISPATCH_AS_PRIMARY_EVENT_LOOP_MECHANISM
139 dispatch_source_t timer;
140 dispatch_source_t custom;
141 #else
142 pthread_mutex_t BigMutex;
143 #endif
144 mDNSs32 BigMutexStartTime;
145 int WakeKQueueLoopFD;
146 #if APPLE_OSX_mDNSResponder
147 CFDictionaryRef ConndBTMMDict; // Dictionary of tunnel name/value pairs
148 #endif
149 };
150
151 extern int OfferSleepProxyService;
152 extern int DisableSleepProxyClient;
153 extern int UseInternalSleepProxy;
154 extern int OSXVers, iOSVers;
155 extern mDNSBool DisableInboundRelayConnection;
156 #define OSXVers_Base 4
157 #define OSXVers_10_0_Cheetah 4
158 #define OSXVers_10_1_Puma 5
159 #define OSXVers_10_2_Jaguar 6
160 #define OSXVers_10_3_Panther 7
161 #define OSXVers_10_4_Tiger 8
162 #define OSXVers_10_5_Leopard 9
163 #define OSXVers_10_6_SnowLeopard 10
164
165 extern int KQueueFD;
166
167 extern void NotifyOfElusiveBug(const char *title, const char *msg); // Both strings are UTF-8 text
168 extern void SetDomainSecrets(mDNS *m);
169 extern void mDNSMacOSXNetworkChanged(mDNS *const m);
170 extern void mDNSMacOSXSystemBuildNumber(char *HINFO_SWstring);
171 extern NetworkInterfaceInfoOSX *IfindexToInterfaceInfoOSX(const mDNS *const m, mDNSInterfaceID ifindex);
172
173 #ifdef MDNSRESPONDER_USES_LIB_DISPATCH_AS_PRIMARY_EVENT_LOOP_MECHANISM
174 extern int KQueueSet(int fd, u_short flags, short filter, KQueueEntry *const entryRef);
175 mDNSexport void TriggerEventCompletion(void);
176 #else
177 extern int KQueueSet(int fd, u_short flags, short filter, const KQueueEntry *const entryRef);
178 #endif
179
180 // When events are processed on the non-kqueue thread (i.e. CFRunLoop notifications like Sleep/Wake,
181 // Interface changes, Keychain changes, etc.) they must use KQueueLock/KQueueUnlock to lock out the kqueue thread
182 extern void KQueueLock(mDNS *const m);
183 extern void KQueueUnlock(mDNS *const m, const char const *task);
184 extern void mDNSPlatformCloseFD(KQueueEntry *kq, int fd);
185
186 extern mDNSBool DictionaryIsEnabled(CFDictionaryRef dict);
187
188 // If any event takes more than WatchDogReportingThreshold milliseconds to be processed, we log a warning message
189 // General event categories are:
190 // o Mach client request initiated / terminated
191 // o UDS client request
192 // o Handling UDP packets received from the network
193 // o Environmental change events:
194 // - network interface changes
195 // - sleep/wake
196 // - keychain changes
197 // o Name conflict dialog dismissal
198 // o Reception of Unix signal (e.g. SIGINFO)
199 // o Idle task processing
200 // If we find that we're getting warnings for any of these categories, and it's not evident
201 // what's causing the problem, we may need to subdivide some categories into finer-grained
202 // sub-categories (e.g. "Idle task processing" covers a pretty broad range of sub-tasks).
203
204 extern int WatchDogReportingThreshold;
205
206 struct CompileTimeAssertionChecks_mDNSMacOSX
207 {
208 // Check our structures are reasonable sizes. Including overly-large buffers, or embedding
209 // other overly-large structures instead of having a pointer to them, can inadvertently
210 // cause structure sizes (and therefore memory usage) to balloon unreasonably.
211 char sizecheck_NetworkInterfaceInfoOSX[(sizeof(NetworkInterfaceInfoOSX) <= 7000) ? 1 : -1];
212 char sizecheck_mDNS_PlatformSupport [(sizeof(mDNS_PlatformSupport) <= 768) ? 1 : -1];
213 };
214
215 #ifdef __cplusplus
216 }
217 #endif
218
219 #endif