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>
42 #define NETWORK_CONFIGURATION_VERSION 20191120
47 // base CFType information
54 SCPreferencesRef prefs
;
62 } SCNetworkSetPrivate
, *SCNetworkSetPrivateRef
;
67 // base CFType information
71 CFStringRef serviceID
;
74 SCNetworkInterfaceRef interface
;
77 SCPreferencesRef prefs
;
79 // store (for live SCNetworkService)
80 SCDynamicStoreRef store
;
85 // external identifiers
86 CFMutableDictionaryRef externalIDs
;
88 } SCNetworkServicePrivate
, *SCNetworkServicePrivateRef
;
93 // base CFType information
100 SCNetworkServiceRef service
;
102 } SCNetworkProtocolPrivate
, *SCNetworkProtocolPrivateRef
;
107 // base CFType information
108 CFRuntimeBase cfBase
;
110 // interface information
111 CFStringRef interface_type
; // interface type
115 // [non-localized] name
116 CFStringRef name
; // non-localized [display] name
119 CFStringRef localized_name
; // localized [display] name
120 CFStringRef localized_key
;
121 CFStringRef localized_arg1
;
122 CFStringRef localized_arg2
;
124 // [layered] interface
125 SCNetworkInterfaceRef interface
;
127 // prefs (for associated service, BOND interfaces, and VLAN interfaces)
128 SCPreferencesRef prefs
;
131 SCDynamicStoreRef store
;
133 // serviceID (NULL if not associated with a service)
134 CFStringRef serviceID
;
136 // unsaved configuration (when prefs not [yet] available)
137 CFMutableDictionaryRef unsaved
;
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
145 // configuration information
146 CFMutableArrayRef supported_interface_types
;
147 CFMutableArrayRef supported_protocol_types
;
149 // IORegistry (service plane) information
151 CFStringRef addressString
;
153 CFStringRef configurationAction
;
154 Boolean hiddenConfiguration
;
155 Boolean hiddenInterface
;
156 CFStringRef location
;
159 CFMutableDictionaryRef overrides
;
161 Boolean trustRequired
;
165 CFNumberRef subfamily
;
173 CFArrayRef matchingMACs
;
174 unsigned int sort_order
; // sort order for this interface
176 // for BOND interfaces
177 Boolean supportsBond
;
179 CFArrayRef interfaces
;
181 CFDictionaryRef options
;
184 // for Bridge interfaces
185 Boolean supportsBridge
;
187 CFArrayRef interfaces
;
188 CFDictionaryRef options
;
191 // for VLAN interfaces
192 Boolean supportsVLAN
;
194 SCNetworkInterfaceRef interface
;
195 CFNumberRef tag
; // e.g. 1 <= tag <= 4094
196 CFDictionaryRef options
;
199 // for interface rank assertions
200 IPMonitorControlRef IPMonitorControl
;
202 } SCNetworkInterfacePrivate
, *SCNetworkInterfacePrivateRef
;
208 #pragma mark SCNetworkConfiguration (internal)
213 __SCNetworkConfigurationBackup (SCPreferencesRef prefs
,
215 SCPreferencesRef relativeTo
);
220 #pragma mark SCNetworkInterface configuration (internal)
223 extern const SCNetworkServiceRef __kSCNetworkInterfaceSearchExternal
;
225 extern const SCNetworkServiceRef __kSCNetworkInterfaceSearchSystem
;
228 __SCNetworkInterfaceMatchesName (CFStringRef name
,
232 __SCNetworkInterfaceCopyAll_IONetworkInterface (Boolean keep_pre_configured
);
235 @function __SCNetworkInterfaceCopyStoredWithPreferences
236 @discussion Create an array of network interfaces, which is present in the preferences
237 in NetworkInteraces.plist
238 @param ni_prefs Preference for network interfaces
239 @result Array which contains SCNetworkInterfaceRef.
240 You must release the returned value.
243 CFArrayRef
// SCNetworkInterfaceRef
244 __SCNetworkInterfaceCopyStoredWithPreferences (SCPreferencesRef ni_prefs
);
246 SCNetworkInterfacePrivateRef
247 __SCNetworkInterfaceCreateCopy (CFAllocatorRef allocator
,
248 SCNetworkInterfaceRef interface
,
249 SCPreferencesRef prefs
,
250 CFStringRef serviceID
);
253 @function __SCNetworkInterfaceCreateMappingUsingBSDName
254 @discussion This function creates mapping of BSD name and network interface using
255 preferences which point to the NetworkInterfaces.plist file.
256 @param interfaces An array of network interfaces to use for the mapping.
257 @result BSD Mapping in a dictionary.
258 You must release the returned value.
261 __SCNetworkInterfaceCreateMappingUsingBSDName (CFArrayRef interfaces
);
263 SCNetworkInterfaceRef
264 __SCNetworkInterfaceCreateWithNIPreferencesUsingBSDName(CFAllocatorRef allocator
,
265 SCPreferencesRef ni_prefs
,
266 CFStringRef bsdName
);
268 SCNetworkInterfacePrivateRef
269 __SCNetworkInterfaceCreatePrivate (CFAllocatorRef allocator
,
270 SCNetworkInterfaceRef interface
,
271 SCPreferencesRef prefs
,
272 CFStringRef serviceID
);
274 SCNetworkInterfacePrivateRef
275 _SCBondInterfaceCreatePrivate (CFAllocatorRef allocator
,
276 CFStringRef bond_if
);
278 SCNetworkInterfacePrivateRef
279 _SCBridgeInterfaceCreatePrivate (CFAllocatorRef allocator
,
280 CFStringRef bridge_if
);
282 SCNetworkInterfacePrivateRef
283 _SCVLANInterfaceCreatePrivate (CFAllocatorRef allocator
,
284 CFStringRef vlan_if
);
287 __SCNetworkInterfaceCopyInterfaceEntity (SCNetworkInterfaceRef interface
);
290 __SCNetworkInterfaceCopyDeepConfiguration (SCNetworkSetRef set
,
291 SCNetworkInterfaceRef interface
);
293 #if !TARGET_OS_IPHONE
295 __SCNetworkInterfaceCopyXLocalizedDisplayName (SCNetworkInterfaceRef interface
);
298 __SCNetworkInterfaceCopyXNonLocalizedDisplayName(SCNetworkInterfaceRef interface
);
299 #endif // !TARGET_OS_IPHONE
302 __SCNetworkInterfaceGetDefaultConfigurationType (SCNetworkInterfaceRef interface
);
305 __SCNetworkInterfaceGetEntitySubType (SCNetworkInterfaceRef interface
);
308 __SCNetworkInterfaceGetEntityType (SCNetworkInterfaceRef interface
);
311 __SCNetworkInterfaceGetNonLocalizedDisplayName (SCNetworkInterfaceRef interface
);
314 __SCNetworkInterfaceSetUserDefinedName(SCNetworkInterfaceRef interface
, CFStringRef name
);
317 @function __SCNetworkInterfaceGetUserDefinedName
318 @discussion This function returns the user defined name of the interface if available
319 @param interface The network interface.
320 @result String containing the user defined name.
323 __SCNetworkInterfaceGetUserDefinedName(SCNetworkInterfaceRef interface
);
326 @function __SCNetworkInterfaceIsActive
327 @discussion Identifies if the configuration of network interface is active or not
328 @param interface The network interface
329 @result TRUE if the interface configuration is active.
332 __SCNetworkInterfaceIsActive (SCNetworkInterfaceRef interface
);
335 __SCNetworkInterfaceIsMember (SCPreferencesRef prefs
,
336 SCNetworkInterfaceRef interface
);
339 __SCNetworkInterfaceEntityIsPPTP (CFDictionaryRef entity
);
342 __SCNetworkInterfaceIsValidExtendedConfigurationType
343 (SCNetworkInterfaceRef interface
,
344 CFStringRef extendedType
,
345 Boolean requirePerInterface
);
348 __SCNetworkInterfaceGetTemplateOverrides (SCNetworkInterfaceRef interface
,
349 CFStringRef overrideType
);
352 __SCNetworkInterfaceOrder (SCNetworkInterfaceRef interface
);
355 @function __SCNetworkInterfaceSaveStoredWithPreferences
356 @discussion Saves the array of interfaces in the preferences passed in the function. The interfaces
357 which are already present in the prefs file are replaced.
358 @param prefs Preferences which contain the interfaces to be replaced. If NULL, then preferences on
360 @param interfacesToSave The new interfaces array which is to be stored in preferences.
361 @result TRUE if saving of the new interfaces was successful.
365 __SCNetworkInterfaceSaveStoredWithPreferences (SCPreferencesRef prefs
,
366 CFArrayRef interfacesToSave
);
369 __SCNetworkInterfaceSetConfiguration (SCNetworkInterfaceRef interface
,
370 CFStringRef extendedType
,
371 CFDictionaryRef config
,
375 __SCNetworkInterfaceSetDeepConfiguration (SCNetworkSetRef set
,
376 SCNetworkInterfaceRef interface
,
380 @function __SCNetworkInterfaceSetIOInterfaceUnity
381 @discussion Will allow the caller to set IO Interface Unit
382 @param interface The network interface
383 @param unit The new interface unit to set
386 __SCNetworkInterfaceSetIOInterfaceUnit (SCNetworkInterfaceRef interface
,
390 __SCNetworkInterfaceSupportsVLAN (CFStringRef bsd_if
);
393 __SCBondInterfaceListCollectMembers (CFArrayRef interfaces
,
394 CFMutableSetRef set
);
397 __SCBondInterfaceSetMemberInterfaces (SCBondInterfaceRef bond
,
401 __SCBridgeInterfaceListCollectMembers (CFArrayRef interfaces
,
402 CFMutableSetRef set
);
405 __SCBridgeInterfaceSetMemberInterfaces (SCBridgeInterfaceRef bridge
,
409 _SCNetworkInterfaceCacheOpen(void);
412 _SCNetworkInterfaceCacheClose(void);
416 #pragma mark SCNetworkInterface (NetworkInterfaces.plist) configuration (internal)
419 #define kSCNetworkInterfaceActive "Active"
420 #define kSCNetworkInterfaceInfo "SCNetworkInterfaceInfo"
421 #define kSCNetworkInterfaceType "SCNetworkInterfaceType"
422 #define kSCNetworkInterfaceBSDName kIOBSDNameKey
423 #define kSCNetworkInterfaceIOBuiltin kIOBuiltin
424 #define kSCNetworkInterfaceIOInterfaceNamePrefix kIOInterfaceNamePrefix
425 #define kSCNetworkInterfaceIOInterfaceType kIOInterfaceType
426 #define kSCNetworkInterfaceIOInterfaceUnit kIOInterfaceUnit
427 #define kSCNetworkInterfaceIOMACAddress kIOMACAddress
428 #define kSCNetworkInterfaceIOPathMatch kIOPathMatchKey
429 #define kSCNetworkInterfaceMatchingMACs "MatchingMACs"
433 @function __SCNetworkInterfaceCopyStorageEntity
434 @discussion Create interface entity of network interface as seen in
435 NetworkInterfaces.plist
436 @param interface The network interface from which interface entity is create
437 @result Dictionary which contains information about interface entity.
438 You must release the returned value.
441 __SCNetworkInterfaceCopyStorageEntity (SCNetworkInterfaceRef interface
);
445 #pragma mark SCNetworkProtocol configuration (internal)
448 SCNetworkProtocolPrivateRef
449 __SCNetworkProtocolCreatePrivate (CFAllocatorRef allocator
,
450 CFStringRef entityID
,
451 SCNetworkServiceRef service
);
454 __SCNetworkProtocolIsValidType (CFStringRef protocolType
);
458 #pragma mark SCNetworkService configuration (internal)
461 CFArrayRef
/* of SCNetworkServiceRef's */
462 __SCNetworkServiceCopyAllEnabled (SCPreferencesRef prefs
);
464 CFArrayRef
/* of SCNetworkInterfaceRef's */
465 __SCNetworkServiceCopyAllInterfaces (SCPreferencesRef prefs
);
467 SCNetworkServicePrivateRef
468 __SCNetworkServiceCreatePrivate (CFAllocatorRef allocator
,
469 SCPreferencesRef prefs
,
470 CFStringRef serviceID
,
471 SCNetworkInterfaceRef interface
);
474 __SCNetworkServiceExists (SCNetworkServiceRef service
);
477 __SCNetworkServiceExistsForInterface (CFArrayRef services
,
478 SCNetworkInterfaceRef interface
);
481 __SCNetworkServiceCreate (SCPreferencesRef prefs
,
482 SCNetworkInterfaceRef interface
,
483 CFStringRef userDefinedName
);
486 __SCNetworkServiceIsPPTP (SCNetworkServiceRef service
);
490 @function __SCNetworkServiceMigrateNew
491 @discussion Adds network service to SCPreferencesRef if it doesn't exists
492 @param prefs SCPreferencesRef
493 @param service The network service
494 @param bsdNameMapping Mapping of interface names between configurations
495 @result TRUE if add service to prefs is successful
498 __SCNetworkServiceMigrateNew (SCPreferencesRef prefs
,
499 SCNetworkServiceRef service
,
500 CFDictionaryRef bsdNameMapping
,
501 CFDictionaryRef setMapping
,
502 CFDictionaryRef serviceSetMapping
);
505 __SCNetworkServiceAddProtocolToService (SCNetworkServiceRef service
,
506 CFStringRef protocolType
,
507 CFDictionaryRef configuration
,
512 #pragma mark SCNetworkSet configuration (internal)
516 __SCNetworkSetExists (SCNetworkSetRef set
);
524 __log_SCNetworkConfiguration (void);
528 #pragma mark Miscellaneous (internal)
532 __copyInterfaceTemplate (CFStringRef interfaceType
,
533 CFStringRef childInterfaceType
);
536 __copyProtocolTemplate (CFStringRef interfaceType
,
537 CFStringRef childInterfaceType
,
538 CFStringRef protocolType
);
541 __SCNetworkConfigurationGetValue (SCPreferencesRef prefs
,
545 __SCNetworkConfigurationSetValue (SCPreferencesRef prefs
,
547 CFDictionaryRef config
,
548 Boolean keepInactive
);
551 __getPrefsEnabled (SCPreferencesRef prefs
,
555 __setPrefsEnabled (SCPreferencesRef prefs
,
560 __createInterface (int s
,
561 CFStringRef interface
);
564 __destroyInterface (int s
,
565 CFStringRef interface
);
568 __SCPreferencesPathCreateUniqueChild_WithMoreSCFCompatibility
569 (SCPreferencesRef prefs
,
573 __extract_password (SCPreferencesRef prefs
,
574 CFDictionaryRef config
,
575 CFStringRef passwordKey
,
576 CFStringRef encryptionKey
,
577 CFStringRef encryptionKeyChainValue
,
578 CFStringRef unique_id
,
579 CFDataRef
*password
);
582 __remove_password (SCPreferencesRef prefs
,
583 CFDictionaryRef config
,
584 CFStringRef passwordKey
,
585 CFStringRef encryptionKey
,
586 CFStringRef encryptionKeyChainValue
,
587 CFStringRef unique_id
,
588 CFDictionaryRef
*newConfig
);
591 __rank_to_str (SCNetworkServicePrimaryRank rank
,
592 CFStringRef
*rankStr
);
595 __str_to_rank (CFStringRef rankStr
,
596 SCNetworkServicePrimaryRank
*rank
);
600 #endif /* _SCNETWORKCONFIGURATIONINTERNAL_H */