]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCNetworkConfigurationInternal.h
8cf01f7cb7428ed2293483ede11cd9ff409754ae
[apple/configd.git] / SystemConfiguration.fproj / SCNetworkConfigurationInternal.h
1 /*
2 * Copyright (c) 2004-2020 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef _SCNETWORKCONFIGURATIONINTERNAL_H
25 #define _SCNETWORKCONFIGURATIONINTERNAL_H
26
27 #include <TargetConditionals.h>
28 #include <CoreFoundation/CoreFoundation.h>
29 #include <CoreFoundation/CFRuntime.h>
30
31 #ifndef SC_LOG_HANDLE
32 #define SC_LOG_HANDLE __log_SCNetworkConfiguration
33 #endif // SC_LOG_HANDLE
34 #include <SystemConfiguration/SystemConfiguration.h>
35 #include <SystemConfiguration/SCPrivate.h>
36 #include <SystemConfiguration/SCValidation.h>
37 #include "SCPreferencesPathKey.h"
38 #include "IPMonitorControl.h"
39 #include <IOKit/IOKitLib.h>
40
41
42 #define NETWORK_CONFIGURATION_VERSION 20191120
43
44
45 typedef struct {
46
47 // base CFType information
48 CFRuntimeBase cfBase;
49
50 // set id
51 CFStringRef setID;
52
53 // prefs
54 SCPreferencesRef prefs;
55
56 // name
57 CFStringRef name;
58
59 // misc
60 Boolean established;
61
62 } SCNetworkSetPrivate, *SCNetworkSetPrivateRef;
63
64
65 typedef struct {
66
67 // base CFType information
68 CFRuntimeBase cfBase;
69
70 // service id
71 CFStringRef serviceID;
72
73 // interface
74 SCNetworkInterfaceRef interface;
75
76 // prefs
77 SCPreferencesRef prefs;
78
79 // store (for live SCNetworkService)
80 SCDynamicStoreRef store;
81
82 // name
83 CFStringRef name;
84
85 // external identifiers
86 CFMutableDictionaryRef externalIDs;
87
88 } SCNetworkServicePrivate, *SCNetworkServicePrivateRef;
89
90
91 typedef struct {
92
93 // base CFType information
94 CFRuntimeBase cfBase;
95
96 // entity id
97 CFStringRef entityID;
98
99 // service
100 SCNetworkServiceRef service;
101
102 } SCNetworkProtocolPrivate, *SCNetworkProtocolPrivateRef;
103
104
105 typedef struct {
106
107 // base CFType information
108 CFRuntimeBase cfBase;
109
110 // interface information
111 CFStringRef interface_type; // interface type
112
113 Boolean active;
114
115 // [non-localized] name
116 CFStringRef name; // non-localized [display] name
117
118 // localized name
119 CFStringRef localized_name; // localized [display] name
120 CFStringRef localized_key;
121 CFStringRef localized_arg1;
122 CFStringRef localized_arg2;
123
124 // [layered] interface
125 SCNetworkInterfaceRef interface;
126
127 // prefs (for associated service, BOND interfaces, and VLAN interfaces)
128 SCPreferencesRef prefs;
129
130 // SCDynamicStore
131 SCDynamicStoreRef store;
132
133 // serviceID (NULL if not associated with a service)
134 CFStringRef serviceID;
135
136 // unsaved configuration (when prefs not [yet] available)
137 CFMutableDictionaryRef unsaved;
138
139 // [SCPreferences] interface entity information
140 CFStringRef entity_device; // interface device
141 CFStringRef entity_device_unique; // ... UniqueIdentifier
142 CFStringRef entity_type; // interface type
143 CFStringRef entity_subtype; // interface subtype
144
145 // configuration information
146 CFMutableArrayRef supported_interface_types;
147 CFMutableArrayRef supported_protocol_types;
148
149 // IORegistry (service plane) information
150 CFDataRef address;
151 CFStringRef addressString;
152 Boolean builtin;
153 CFStringRef configurationAction;
154 Boolean hidden;
155 CFStringRef location;
156 CFStringRef path;
157 uint64_t entryID;
158 CFMutableDictionaryRef overrides;
159 CFStringRef prefix;
160 Boolean trustRequired;
161 CFNumberRef type;
162 CFNumberRef unit;
163 CFNumberRef family;
164 CFNumberRef subfamily;
165 struct {
166 CFStringRef name;
167 CFNumberRef vid;
168 CFNumberRef pid;
169 } usb;
170
171 // misc
172 CFArrayRef matchingMACs;
173 unsigned int sort_order; // sort order for this interface
174
175 // for BOND interfaces
176 Boolean supportsBond;
177 struct {
178 CFArrayRef interfaces;
179 CFNumberRef mode;
180 CFDictionaryRef options;
181 } bond;
182
183 // for Bridge interfaces
184 Boolean supportsBridge;
185 struct {
186 CFArrayRef interfaces;
187 CFDictionaryRef options;
188 } bridge;
189
190 // for VLAN interfaces
191 Boolean supportsVLAN;
192 struct {
193 SCNetworkInterfaceRef interface;
194 CFNumberRef tag; // e.g. 1 <= tag <= 4094
195 CFDictionaryRef options;
196 } vlan;
197
198 // for interface rank assertions
199 IPMonitorControlRef IPMonitorControl;
200
201 } SCNetworkInterfacePrivate, *SCNetworkInterfacePrivateRef;
202
203
204 __BEGIN_DECLS
205
206 #pragma mark -
207 #pragma mark SCNetworkConfiguration (internal)
208
209
210
211 Boolean
212 __SCNetworkConfigurationBackup (SCPreferencesRef prefs,
213 CFStringRef suffix,
214 SCPreferencesRef relativeTo);
215
216
217
218 #pragma mark -
219 #pragma mark SCNetworkInterface configuration (internal)
220
221
222 Boolean
223 __SCNetworkInterfaceMatchesName (CFStringRef name,
224 CFStringRef key);
225
226 CFArrayRef
227 __SCNetworkInterfaceCopyAll_IONetworkInterface (Boolean keep_pre_configured);
228
229 /*!
230 @function __SCNetworkInterfaceCopyStoredWithPreferences
231 @discussion Create an array of network interfaces, which is present in the preferences
232 in NetworkInteraces.plist
233 @param ni_prefs Preference for network interfaces
234 @result Array which contains SCNetworkInterfaceRef.
235 You must release the returned value.
236 */
237
238 CFArrayRef // SCNetworkInterfaceRef
239 __SCNetworkInterfaceCopyStoredWithPreferences (SCPreferencesRef ni_prefs);
240
241 SCNetworkInterfacePrivateRef
242 __SCNetworkInterfaceCreateCopy (CFAllocatorRef allocator,
243 SCNetworkInterfaceRef interface,
244 SCPreferencesRef prefs,
245 CFStringRef serviceID);
246
247 /*!
248 @function __SCNetworkInterfaceCreateMappingUsingBSDName
249 @discussion This function creates mapping of BSD name and network interface using
250 preferences which point to the NetworkInterfaces.plist file.
251 @param interfaces An array of network interfaces to use for the mapping.
252 @result BSD Mapping in a dictionary.
253 You must release the returned value.
254 */
255 CFDictionaryRef
256 __SCNetworkInterfaceCreateMappingUsingBSDName (CFArrayRef interfaces);
257
258 SCNetworkInterfaceRef
259 __SCNetworkInterfaceCreateWithNIPreferencesUsingBSDName(CFAllocatorRef allocator,
260 SCPreferencesRef ni_prefs,
261 CFStringRef bsdName);
262
263 SCNetworkInterfacePrivateRef
264 __SCNetworkInterfaceCreatePrivate (CFAllocatorRef allocator,
265 SCNetworkInterfaceRef interface,
266 SCPreferencesRef prefs,
267 CFStringRef serviceID);
268
269 SCNetworkInterfacePrivateRef
270 _SCBondInterfaceCreatePrivate (CFAllocatorRef allocator,
271 CFStringRef bond_if);
272
273 SCNetworkInterfacePrivateRef
274 _SCBridgeInterfaceCreatePrivate (CFAllocatorRef allocator,
275 CFStringRef bridge_if);
276
277 SCNetworkInterfacePrivateRef
278 _SCVLANInterfaceCreatePrivate (CFAllocatorRef allocator,
279 CFStringRef vlan_if);
280
281 CFDictionaryRef
282 __SCNetworkInterfaceCopyInterfaceEntity (SCNetworkInterfaceRef interface);
283
284 CFArrayRef
285 __SCNetworkInterfaceCopyDeepConfiguration (SCNetworkSetRef set,
286 SCNetworkInterfaceRef interface);
287
288 #if !TARGET_OS_IPHONE
289 CFStringRef
290 __SCNetworkInterfaceCopyXLocalizedDisplayName (SCNetworkInterfaceRef interface);
291
292 CFStringRef
293 __SCNetworkInterfaceCopyXNonLocalizedDisplayName(SCNetworkInterfaceRef interface);
294 #endif // !TARGET_OS_IPHONE
295
296 CFStringRef
297 __SCNetworkInterfaceGetDefaultConfigurationType (SCNetworkInterfaceRef interface);
298
299 CFStringRef
300 __SCNetworkInterfaceGetEntitySubType (SCNetworkInterfaceRef interface);
301
302 CFStringRef
303 __SCNetworkInterfaceGetEntityType (SCNetworkInterfaceRef interface);
304
305 CFStringRef
306 __SCNetworkInterfaceGetNonLocalizedDisplayName (SCNetworkInterfaceRef interface);
307
308 void
309 __SCNetworkInterfaceSetUserDefinedName(SCNetworkInterfaceRef interface, CFStringRef name);
310
311 /*!
312 @function __SCNetworkInterfaceGetUserDefinedName
313 @discussion This function returns the user defined name of the interface if available
314 @param interface The network interface.
315 @result String containing the user defined name.
316 */
317 CFStringRef
318 __SCNetworkInterfaceGetUserDefinedName(SCNetworkInterfaceRef interface);
319
320 /*!
321 @function __SCNetworkInterfaceIsActive
322 @discussion Identifies if the configuration of network interface is active or not
323 @param interface The network interface
324 @result TRUE if the interface configuration is active.
325 */
326 Boolean
327 __SCNetworkInterfaceIsActive (SCNetworkInterfaceRef interface);
328
329 Boolean
330 __SCNetworkInterfaceIsMember (SCPreferencesRef prefs,
331 SCNetworkInterfaceRef interface);
332
333 Boolean
334 __SCNetworkInterfaceEntityIsPPTP (CFDictionaryRef entity);
335
336 Boolean
337 __SCNetworkInterfaceIsValidExtendedConfigurationType
338 (SCNetworkInterfaceRef interface,
339 CFStringRef extendedType,
340 Boolean requirePerInterface);
341
342 CFPropertyListRef
343 __SCNetworkInterfaceGetTemplateOverrides (SCNetworkInterfaceRef interface,
344 CFStringRef overrideType);
345
346 int
347 __SCNetworkInterfaceOrder (SCNetworkInterfaceRef interface);
348
349 /*!
350 @function __SCNetworkInterfaceSaveStoredWithPreferences
351 @discussion Saves the array of interfaces in the preferences passed in the function. The interfaces
352 which are already present in the prefs file are replaced.
353 @param prefs Preferences which contain the interfaces to be replaced. If NULL, then preferences on
354 the system are used.
355 @param interfacesToSave The new interfaces array which is to be stored in preferences.
356 @result TRUE if saving of the new interfaces was successful.
357 */
358
359 Boolean
360 __SCNetworkInterfaceSaveStoredWithPreferences (SCPreferencesRef prefs,
361 CFArrayRef interfacesToSave);
362
363 Boolean
364 __SCNetworkInterfaceSetConfiguration (SCNetworkInterfaceRef interface,
365 CFStringRef extendedType,
366 CFDictionaryRef config,
367 Boolean okToHold);
368
369 void
370 __SCNetworkInterfaceSetDeepConfiguration (SCNetworkSetRef set,
371 SCNetworkInterfaceRef interface,
372 CFArrayRef configs);
373
374 /*!
375 @function __SCNetworkInterfaceSetIOInterfaceUnity
376 @discussion Will allow the caller to set IO Interface Unit
377 @param interface The network interface
378 @param unit The new interface unit to set
379 */
380 void
381 __SCNetworkInterfaceSetIOInterfaceUnit (SCNetworkInterfaceRef interface,
382 CFNumberRef unit);
383
384 Boolean
385 __SCNetworkInterfaceSupportsVLAN (CFStringRef bsd_if);
386
387 void
388 __SCBondInterfaceListCollectMembers (CFArrayRef interfaces,
389 CFMutableSetRef set);
390
391 Boolean
392 __SCBondInterfaceSetMemberInterfaces (SCBondInterfaceRef bond,
393 CFArrayRef members);
394
395 void
396 __SCBridgeInterfaceListCollectMembers (CFArrayRef interfaces,
397 CFMutableSetRef set);
398
399 Boolean
400 __SCBridgeInterfaceSetMemberInterfaces (SCBridgeInterfaceRef bridge,
401 CFArrayRef members);
402
403 void
404 _SCNetworkInterfaceCacheOpen(void);
405
406 void
407 _SCNetworkInterfaceCacheClose(void);
408
409
410 #pragma mark -
411 #pragma mark SCNetworkInterface (NetworkInterfaces.plist) configuration (internal)
412
413
414 #define kSCNetworkInterfaceActive "Active"
415 #define kSCNetworkInterfaceInfo "SCNetworkInterfaceInfo"
416 #define kSCNetworkInterfaceType "SCNetworkInterfaceType"
417 #define kSCNetworkInterfaceBSDName kIOBSDNameKey
418 #define kSCNetworkInterfaceIOBuiltin kIOBuiltin
419 #define kSCNetworkInterfaceIOInterfaceNamePrefix kIOInterfaceNamePrefix
420 #define kSCNetworkInterfaceIOInterfaceType kIOInterfaceType
421 #define kSCNetworkInterfaceIOInterfaceUnit kIOInterfaceUnit
422 #define kSCNetworkInterfaceIOMACAddress kIOMACAddress
423 #define kSCNetworkInterfaceIOPathMatch kIOPathMatchKey
424 #define kSCNetworkInterfaceMatchingMACs "MatchingMACs"
425
426
427 /*!
428 @function __SCNetworkInterfaceCopyStorageEntity
429 @discussion Create interface entity of network interface as seen in
430 NetworkInterfaces.plist
431 @param interface The network interface from which interface entity is create
432 @result Dictionary which contains information about interface entity.
433 You must release the returned value.
434 */
435 CFDictionaryRef
436 __SCNetworkInterfaceCopyStorageEntity (SCNetworkInterfaceRef interface);
437
438
439 #pragma mark -
440 #pragma mark SCNetworkProtocol configuration (internal)
441
442
443 SCNetworkProtocolPrivateRef
444 __SCNetworkProtocolCreatePrivate (CFAllocatorRef allocator,
445 CFStringRef entityID,
446 SCNetworkServiceRef service);
447
448 Boolean
449 __SCNetworkProtocolIsValidType (CFStringRef protocolType);
450
451
452 #pragma mark -
453 #pragma mark SCNetworkService configuration (internal)
454
455
456 CFArrayRef /* of SCNetworkServiceRef's */
457 __SCNetworkServiceCopyAllEnabled (SCPreferencesRef prefs);
458
459 CFArrayRef /* of SCNetworkInterfaceRef's */
460 __SCNetworkServiceCopyAllInterfaces (SCPreferencesRef prefs);
461
462 SCNetworkServicePrivateRef
463 __SCNetworkServiceCreatePrivate (CFAllocatorRef allocator,
464 SCPreferencesRef prefs,
465 CFStringRef serviceID,
466 SCNetworkInterfaceRef interface);
467
468 Boolean
469 __SCNetworkServiceExists (SCNetworkServiceRef service);
470
471 Boolean
472 __SCNetworkServiceExistsForInterface (CFArrayRef services,
473 SCNetworkInterfaceRef interface);
474
475 Boolean
476 __SCNetworkServiceCreate (SCPreferencesRef prefs,
477 SCNetworkInterfaceRef interface,
478 CFStringRef userDefinedName);
479
480 Boolean
481 __SCNetworkServiceIsPPTP (SCNetworkServiceRef service);
482
483
484 void
485 __SCNetworkPopulateDefaultNIPrefs (SCPreferencesRef ni_prefs);
486
487 /*!
488 @function __SCNetworkServiceMigrateNew
489 @discussion Adds network service to SCPreferencesRef if it doesn't exists
490 @param prefs SCPreferencesRef
491 @param service The network service
492 @param bsdMapping Mapping of interface names between configurations
493 @result TRUE if add service to prefs is successful
494 */
495 Boolean
496 __SCNetworkServiceMigrateNew (SCPreferencesRef prefs,
497 SCNetworkServiceRef service,
498 CFDictionaryRef bsdMapping,
499 CFDictionaryRef setMapping,
500 CFDictionaryRef serviceSetMapping);
501
502 void
503 __SCNetworkServiceAddProtocolToService (SCNetworkServiceRef service,
504 CFStringRef protocolType,
505 CFDictionaryRef configuration,
506 Boolean enabled);
507
508
509 #pragma mark -
510 #pragma mark SCNetworkSet configuration (internal)
511
512
513 Boolean
514 __SCNetworkSetExists (SCNetworkSetRef set);
515
516
517 #pragma mark -
518 #pragma mark Logging
519
520
521 os_log_t
522 __log_SCNetworkConfiguration (void);
523
524
525 #pragma mark -
526 #pragma mark Miscellaneous (internal)
527
528
529 CFDictionaryRef
530 __copyInterfaceTemplate (CFStringRef interfaceType,
531 CFStringRef childInterfaceType);
532
533 CFDictionaryRef
534 __copyProtocolTemplate (CFStringRef interfaceType,
535 CFStringRef childInterfaceType,
536 CFStringRef protocolType);
537
538 CFDictionaryRef
539 __SCNetworkConfigurationGetValue (SCPreferencesRef prefs,
540 CFStringRef path);
541
542 Boolean
543 __SCNetworkConfigurationSetValue (SCPreferencesRef prefs,
544 CFStringRef path,
545 CFDictionaryRef config,
546 Boolean keepInactive);
547
548 Boolean
549 __getPrefsEnabled (SCPreferencesRef prefs,
550 CFStringRef path);
551
552 Boolean
553 __setPrefsEnabled (SCPreferencesRef prefs,
554 CFStringRef path,
555 Boolean enabled);
556
557 Boolean
558 __createInterface (int s,
559 CFStringRef interface);
560
561 Boolean
562 __destroyInterface (int s,
563 CFStringRef interface);
564
565 CFStringRef
566 __SCPreferencesPathCreateUniqueChild_WithMoreSCFCompatibility
567 (SCPreferencesRef prefs,
568 CFStringRef prefix);
569
570 Boolean
571 __extract_password (SCPreferencesRef prefs,
572 CFDictionaryRef config,
573 CFStringRef passwordKey,
574 CFStringRef encryptionKey,
575 CFStringRef encryptionKeyChainValue,
576 CFStringRef unique_id,
577 CFDataRef *password);
578
579 Boolean
580 __remove_password (SCPreferencesRef prefs,
581 CFDictionaryRef config,
582 CFStringRef passwordKey,
583 CFStringRef encryptionKey,
584 CFStringRef encryptionKeyChainValue,
585 CFStringRef unique_id,
586 CFDictionaryRef *newConfig);
587
588 Boolean
589 __rank_to_str (SCNetworkServicePrimaryRank rank,
590 CFStringRef *rankStr);
591
592 Boolean
593 __str_to_rank (CFStringRef rankStr,
594 SCNetworkServicePrimaryRank *rank);
595
596 __END_DECLS
597
598 #endif /* _SCNETWORKCONFIGURATIONINTERNAL_H */