2 * Copyright (c) 2004-2020 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 #ifndef _SCNETWORKCONFIGURATIONINTERNAL_H
25 #define _SCNETWORKCONFIGURATIONINTERNAL_H
27 #include <TargetConditionals.h>
28 #include <CoreFoundation/CoreFoundation.h>
29 #include <CoreFoundation/CFRuntime.h>
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 #include <IOKit/IOBSD.h>
43 #define NETWORK_CONFIGURATION_VERSION 20191120
48 // base CFType information
55 SCPreferencesRef prefs
;
63 } SCNetworkSetPrivate
, *SCNetworkSetPrivateRef
;
68 // base CFType information
72 CFStringRef serviceID
;
75 SCNetworkInterfaceRef interface
;
78 SCPreferencesRef prefs
;
80 // store (for live SCNetworkService)
81 SCDynamicStoreRef store
;
86 // external identifiers
87 CFMutableDictionaryRef externalIDs
;
89 } SCNetworkServicePrivate
, *SCNetworkServicePrivateRef
;
94 // base CFType information
101 SCNetworkServiceRef service
;
103 } SCNetworkProtocolPrivate
, *SCNetworkProtocolPrivateRef
;
108 // base CFType information
109 CFRuntimeBase cfBase
;
111 // interface information
112 CFStringRef interface_type
; // interface type
116 // [non-localized] name
117 CFStringRef name
; // non-localized [display] name
120 CFStringRef localized_name
; // localized [display] name
121 CFStringRef localized_key
;
122 CFStringRef localized_arg1
;
123 CFStringRef localized_arg2
;
125 // [layered] interface
126 SCNetworkInterfaceRef interface
;
128 // prefs (for associated service, BOND interfaces, and VLAN interfaces)
129 SCPreferencesRef prefs
;
132 SCDynamicStoreRef store
;
134 // serviceID (NULL if not associated with a service)
135 CFStringRef serviceID
;
137 // unsaved configuration (when prefs not [yet] available)
138 CFMutableDictionaryRef unsaved
;
140 // [SCPreferences] interface entity information
141 CFStringRef entity_device
; // interface device
142 CFStringRef entity_device_unique
; // ... UniqueIdentifier
143 CFStringRef entity_type
; // interface type
144 CFStringRef entity_subtype
; // interface subtype
146 // configuration information
147 CFMutableArrayRef supported_interface_types
;
148 CFMutableArrayRef supported_protocol_types
;
150 // IORegistry (service plane) information
152 CFStringRef addressString
;
154 CFStringRef configurationAction
;
155 Boolean hiddenConfiguration
;
156 Boolean hiddenInterface
;
157 CFStringRef location
;
160 CFMutableDictionaryRef overrides
;
162 Boolean trustRequired
;
166 CFNumberRef subfamily
;
174 CFArrayRef matchingMACs
;
175 unsigned int sort_order
; // sort order for this interface
177 // for BOND interfaces
178 Boolean supportsBond
;
180 CFArrayRef interfaces
;
182 CFDictionaryRef options
;
185 // for Bridge interfaces
186 Boolean supportsBridge
;
188 CFArrayRef interfaces
;
189 CFDictionaryRef options
;
192 // for VLAN interfaces
193 Boolean supportsVLAN
;
195 SCNetworkInterfaceRef interface
;
196 CFNumberRef tag
; // e.g. 1 <= tag <= 4094
197 CFDictionaryRef options
;
200 // for interface rank assertions
201 IPMonitorControlRef IPMonitorControl
;
203 } SCNetworkInterfacePrivate
, *SCNetworkInterfacePrivateRef
;
209 #pragma mark SCNetworkConfiguration (internal)
214 __SCNetworkConfigurationBackup (SCPreferencesRef prefs
,
216 SCPreferencesRef relativeTo
);
221 #pragma mark SCNetworkInterface configuration (internal)
224 extern const SCNetworkServiceRef __kSCNetworkInterfaceSearchExternal
;
226 extern const SCNetworkServiceRef __kSCNetworkInterfaceSearchSystem
;
229 __SCNetworkInterfaceMatchesName (CFStringRef name
,
233 __SCNetworkInterfaceCopyAll_IONetworkInterface (Boolean keep_pre_configured
);
236 @function __SCNetworkInterfaceCopyStoredWithPreferences
237 @discussion Create an array of network interfaces, which is present in the preferences
238 in NetworkInteraces.plist
239 @param ni_prefs Preference for network interfaces
240 @result Array which contains SCNetworkInterfaceRef.
241 You must release the returned value.
244 CFArrayRef
// SCNetworkInterfaceRef
245 __SCNetworkInterfaceCopyStoredWithPreferences (SCPreferencesRef ni_prefs
);
247 SCNetworkInterfacePrivateRef
248 __SCNetworkInterfaceCreateCopy (CFAllocatorRef allocator
,
249 SCNetworkInterfaceRef interface
,
250 SCPreferencesRef prefs
,
251 CFStringRef serviceID
);
254 @function __SCNetworkInterfaceCreateMappingUsingBSDName
255 @discussion This function creates mapping of BSD name and network interface using
256 preferences which point to the NetworkInterfaces.plist file.
257 @param interfaces An array of network interfaces to use for the mapping.
258 @result BSD Mapping in a dictionary.
259 You must release the returned value.
262 __SCNetworkInterfaceCreateMappingUsingBSDName (CFArrayRef interfaces
);
264 SCNetworkInterfaceRef
265 __SCNetworkInterfaceCreateWithNIPreferencesUsingBSDName(CFAllocatorRef allocator
,
266 SCPreferencesRef ni_prefs
,
267 CFStringRef bsdName
);
269 SCNetworkInterfacePrivateRef
270 __SCNetworkInterfaceCreatePrivate (CFAllocatorRef allocator
,
271 SCNetworkInterfaceRef interface
,
272 SCPreferencesRef prefs
,
273 CFStringRef serviceID
);
275 SCNetworkInterfacePrivateRef
276 _SCBondInterfaceCreatePrivate (CFAllocatorRef allocator
,
277 CFStringRef bond_if
);
279 SCNetworkInterfacePrivateRef
280 _SCBridgeInterfaceCreatePrivate (CFAllocatorRef allocator
,
281 CFStringRef bridge_if
);
283 SCNetworkInterfacePrivateRef
284 _SCVLANInterfaceCreatePrivate (CFAllocatorRef allocator
,
285 CFStringRef vlan_if
);
288 __SCNetworkInterfaceCopyInterfaceEntity (SCNetworkInterfaceRef interface
);
291 __SCNetworkInterfaceCopyDeepConfiguration (SCNetworkSetRef set
,
292 SCNetworkInterfaceRef interface
);
294 #if !TARGET_OS_IPHONE
296 __SCNetworkInterfaceCopyXLocalizedDisplayName (SCNetworkInterfaceRef interface
);
299 __SCNetworkInterfaceCopyXNonLocalizedDisplayName(SCNetworkInterfaceRef interface
);
300 #endif // !TARGET_OS_IPHONE
303 __SCNetworkInterfaceGetDefaultConfigurationType (SCNetworkInterfaceRef interface
);
306 __SCNetworkInterfaceGetEntitySubType (SCNetworkInterfaceRef interface
);
309 __SCNetworkInterfaceGetEntityType (SCNetworkInterfaceRef interface
);
312 __SCNetworkInterfaceGetNonLocalizedDisplayName (SCNetworkInterfaceRef interface
);
315 __SCNetworkInterfaceSetUserDefinedName(SCNetworkInterfaceRef interface
, CFStringRef name
);
318 @function __SCNetworkInterfaceGetUserDefinedName
319 @discussion This function returns the user defined name of the interface if available
320 @param interface The network interface.
321 @result String containing the user defined name.
324 __SCNetworkInterfaceGetUserDefinedName(SCNetworkInterfaceRef interface
);
327 @function __SCNetworkInterfaceIsActive
328 @discussion Identifies if the configuration of network interface is active or not
329 @param interface The network interface
330 @result TRUE if the interface configuration is active.
333 __SCNetworkInterfaceIsActive (SCNetworkInterfaceRef interface
);
336 __SCNetworkInterfaceIsMember (SCPreferencesRef prefs
,
337 SCNetworkInterfaceRef interface
);
340 __SCNetworkInterfaceEntityIsPPTP (CFDictionaryRef entity
);
343 __SCNetworkInterfaceIsValidExtendedConfigurationType
344 (SCNetworkInterfaceRef interface
,
345 CFStringRef extendedType
,
346 Boolean requirePerInterface
);
349 __SCNetworkInterfaceGetTemplateOverrides (SCNetworkInterfaceRef interface
,
350 CFStringRef overrideType
);
353 __SCNetworkInterfaceOrder (SCNetworkInterfaceRef interface
);
356 @function __SCNetworkInterfaceSaveStoredWithPreferences
357 @discussion Saves the array of interfaces in the preferences passed in the function. The interfaces
358 which are already present in the prefs file are replaced.
359 @param prefs Preferences which contain the interfaces to be replaced. If NULL, then preferences on
361 @param interfacesToSave The new interfaces array which is to be stored in preferences.
362 @result TRUE if saving of the new interfaces was successful.
366 __SCNetworkInterfaceSaveStoredWithPreferences (SCPreferencesRef prefs
,
367 CFArrayRef interfacesToSave
);
370 __SCNetworkInterfaceSetConfiguration (SCNetworkInterfaceRef interface
,
371 CFStringRef extendedType
,
372 CFDictionaryRef config
,
376 __SCNetworkInterfaceSetDeepConfiguration (SCNetworkSetRef set
,
377 SCNetworkInterfaceRef interface
,
381 @function __SCNetworkInterfaceSetIOInterfaceUnity
382 @discussion Will allow the caller to set IO Interface Unit
383 @param interface The network interface
384 @param unit The new interface unit to set
387 __SCNetworkInterfaceSetIOInterfaceUnit (SCNetworkInterfaceRef interface
,
391 __SCNetworkInterfaceSupportsVLAN (CFStringRef bsd_if
);
394 __SCBondInterfaceListCollectMembers (CFArrayRef interfaces
,
395 CFMutableSetRef set
);
398 __SCBondInterfaceSetMemberInterfaces (SCBondInterfaceRef bond
,
402 __SCBridgeInterfaceListCollectMembers (CFArrayRef interfaces
,
403 CFMutableSetRef set
);
406 __SCBridgeInterfaceSetMemberInterfaces (SCBridgeInterfaceRef bridge
,
410 _SCNetworkInterfaceCacheOpen(void);
413 _SCNetworkInterfaceCacheClose(void);
417 #pragma mark SCNetworkInterface (NetworkInterfaces.plist) configuration (internal)
420 #define kSCNetworkInterfaceActive "Active"
421 #define kSCNetworkInterfaceInfo "SCNetworkInterfaceInfo"
422 #define kSCNetworkInterfaceType "SCNetworkInterfaceType"
423 #define kSCNetworkInterfaceBSDName kIOBSDNameKey
424 #define kSCNetworkInterfaceIOBuiltin kIOBuiltin
425 #define kSCNetworkInterfaceIOInterfaceNamePrefix kIOInterfaceNamePrefix
426 #define kSCNetworkInterfaceIOInterfaceType kIOInterfaceType
427 #define kSCNetworkInterfaceIOInterfaceUnit kIOInterfaceUnit
428 #define kSCNetworkInterfaceIOMACAddress kIOMACAddress
429 #define kSCNetworkInterfaceIOPathMatch kIOPathMatchKey
430 #define kSCNetworkInterfaceMatchingMACs "MatchingMACs"
434 @function __SCNetworkInterfaceCopyStorageEntity
435 @discussion Create interface entity of network interface as seen in
436 NetworkInterfaces.plist
437 @param interface The network interface from which interface entity is create
438 @result Dictionary which contains information about interface entity.
439 You must release the returned value.
442 __SCNetworkInterfaceCopyStorageEntity (SCNetworkInterfaceRef interface
);
446 #pragma mark SCNetworkProtocol configuration (internal)
449 SCNetworkProtocolPrivateRef
450 __SCNetworkProtocolCreatePrivate (CFAllocatorRef allocator
,
451 CFStringRef entityID
,
452 SCNetworkServiceRef service
);
455 __SCNetworkProtocolIsValidType (CFStringRef protocolType
);
459 #pragma mark SCNetworkService configuration (internal)
462 CFArrayRef
/* of SCNetworkServiceRef's */
463 __SCNetworkServiceCopyAllEnabled (SCPreferencesRef prefs
);
465 CFArrayRef
/* of SCNetworkInterfaceRef's */
466 __SCNetworkServiceCopyAllInterfaces (SCPreferencesRef prefs
);
468 SCNetworkServicePrivateRef
469 __SCNetworkServiceCreatePrivate (CFAllocatorRef allocator
,
470 SCPreferencesRef prefs
,
471 CFStringRef serviceID
,
472 SCNetworkInterfaceRef interface
);
475 __SCNetworkServiceExists (SCNetworkServiceRef service
);
478 __SCNetworkServiceExistsForInterface (CFArrayRef services
,
479 SCNetworkInterfaceRef interface
);
482 __SCNetworkServiceCreate (SCPreferencesRef prefs
,
483 SCNetworkInterfaceRef interface
,
484 CFStringRef userDefinedName
);
487 __SCNetworkServiceIsPPTP (SCNetworkServiceRef service
);
491 @function __SCNetworkServiceMigrateNew
492 @discussion Adds network service to SCPreferencesRef if it doesn't exists
493 @param prefs SCPreferencesRef
494 @param service The network service
495 @param bsdNameMapping Mapping of interface names between configurations
496 @result TRUE if add service to prefs is successful
499 __SCNetworkServiceMigrateNew (SCPreferencesRef prefs
,
500 SCNetworkServiceRef service
,
501 CFDictionaryRef bsdNameMapping
,
502 CFDictionaryRef setMapping
,
503 CFDictionaryRef serviceSetMapping
);
506 __SCNetworkServiceAddProtocolToService (SCNetworkServiceRef service
,
507 CFStringRef protocolType
,
508 CFDictionaryRef configuration
,
513 #pragma mark SCNetworkSet configuration (internal)
517 __SCNetworkSetExists (SCNetworkSetRef set
);
525 __log_SCNetworkConfiguration (void);
529 #pragma mark Miscellaneous (internal)
533 __copyInterfaceTemplate (CFStringRef interfaceType
,
534 CFStringRef childInterfaceType
);
537 __copyProtocolTemplate (CFStringRef interfaceType
,
538 CFStringRef childInterfaceType
,
539 CFStringRef protocolType
);
542 __SCNetworkConfigurationGetValue (SCPreferencesRef prefs
,
546 __SCNetworkConfigurationSetValue (SCPreferencesRef prefs
,
548 CFDictionaryRef config
,
549 Boolean keepInactive
);
552 __getPrefsEnabled (SCPreferencesRef prefs
,
556 __setPrefsEnabled (SCPreferencesRef prefs
,
561 __createInterface (int s
,
562 CFStringRef interface
);
565 __destroyInterface (int s
,
566 CFStringRef interface
);
569 __SCPreferencesPathCreateUniqueChild_WithMoreSCFCompatibility
570 (SCPreferencesRef prefs
,
574 __extract_password (SCPreferencesRef prefs
,
575 CFDictionaryRef config
,
576 CFStringRef passwordKey
,
577 CFStringRef encryptionKey
,
578 CFStringRef encryptionKeyChainValue
,
579 CFStringRef unique_id
,
580 CFDataRef
*password
);
583 __remove_password (SCPreferencesRef prefs
,
584 CFDictionaryRef config
,
585 CFStringRef passwordKey
,
586 CFStringRef encryptionKey
,
587 CFStringRef encryptionKeyChainValue
,
588 CFStringRef unique_id
,
589 CFDictionaryRef
*newConfig
);
592 __rank_to_str (SCNetworkServicePrimaryRank rank
,
593 CFStringRef
*rankStr
);
596 __str_to_rank (CFStringRef rankStr
,
597 SCNetworkServicePrimaryRank
*rank
);
601 #endif /* _SCNETWORKCONFIGURATIONINTERNAL_H */