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
;
155 CFStringRef location
;
158 CFMutableDictionaryRef overrides
;
160 Boolean trustRequired
;
164 CFNumberRef subfamily
;
172 CFArrayRef matchingMACs
;
173 unsigned int sort_order
; // sort order for this interface
175 // for BOND interfaces
176 Boolean supportsBond
;
178 CFArrayRef interfaces
;
180 CFDictionaryRef options
;
183 // for Bridge interfaces
184 Boolean supportsBridge
;
186 CFArrayRef interfaces
;
187 CFDictionaryRef options
;
190 // for VLAN interfaces
191 Boolean supportsVLAN
;
193 SCNetworkInterfaceRef interface
;
194 CFNumberRef tag
; // e.g. 1 <= tag <= 4094
195 CFDictionaryRef options
;
198 // for interface rank assertions
199 IPMonitorControlRef IPMonitorControl
;
201 } SCNetworkInterfacePrivate
, *SCNetworkInterfacePrivateRef
;
207 #pragma mark SCNetworkConfiguration (internal)
212 __SCNetworkConfigurationBackup (SCPreferencesRef prefs
,
214 SCPreferencesRef relativeTo
);
219 #pragma mark SCNetworkInterface configuration (internal)
223 __SCNetworkInterfaceMatchesName (CFStringRef name
,
227 __SCNetworkInterfaceCopyAll_IONetworkInterface (Boolean keep_pre_configured
);
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.
238 CFArrayRef
// SCNetworkInterfaceRef
239 __SCNetworkInterfaceCopyStoredWithPreferences (SCPreferencesRef ni_prefs
);
241 SCNetworkInterfacePrivateRef
242 __SCNetworkInterfaceCreateCopy (CFAllocatorRef allocator
,
243 SCNetworkInterfaceRef interface
,
244 SCPreferencesRef prefs
,
245 CFStringRef serviceID
);
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.
256 __SCNetworkInterfaceCreateMappingUsingBSDName (CFArrayRef interfaces
);
258 SCNetworkInterfaceRef
259 __SCNetworkInterfaceCreateWithNIPreferencesUsingBSDName(CFAllocatorRef allocator
,
260 SCPreferencesRef ni_prefs
,
261 CFStringRef bsdName
);
263 SCNetworkInterfacePrivateRef
264 __SCNetworkInterfaceCreatePrivate (CFAllocatorRef allocator
,
265 SCNetworkInterfaceRef interface
,
266 SCPreferencesRef prefs
,
267 CFStringRef serviceID
);
269 SCNetworkInterfacePrivateRef
270 _SCBondInterfaceCreatePrivate (CFAllocatorRef allocator
,
271 CFStringRef bond_if
);
273 SCNetworkInterfacePrivateRef
274 _SCBridgeInterfaceCreatePrivate (CFAllocatorRef allocator
,
275 CFStringRef bridge_if
);
277 SCNetworkInterfacePrivateRef
278 _SCVLANInterfaceCreatePrivate (CFAllocatorRef allocator
,
279 CFStringRef vlan_if
);
282 __SCNetworkInterfaceCopyInterfaceEntity (SCNetworkInterfaceRef interface
);
285 __SCNetworkInterfaceCopyDeepConfiguration (SCNetworkSetRef set
,
286 SCNetworkInterfaceRef interface
);
288 #if !TARGET_OS_IPHONE
290 __SCNetworkInterfaceCopyXLocalizedDisplayName (SCNetworkInterfaceRef interface
);
293 __SCNetworkInterfaceCopyXNonLocalizedDisplayName(SCNetworkInterfaceRef interface
);
294 #endif // !TARGET_OS_IPHONE
297 __SCNetworkInterfaceGetDefaultConfigurationType (SCNetworkInterfaceRef interface
);
300 __SCNetworkInterfaceGetEntitySubType (SCNetworkInterfaceRef interface
);
303 __SCNetworkInterfaceGetEntityType (SCNetworkInterfaceRef interface
);
306 __SCNetworkInterfaceGetNonLocalizedDisplayName (SCNetworkInterfaceRef interface
);
309 __SCNetworkInterfaceSetUserDefinedName(SCNetworkInterfaceRef interface
, CFStringRef name
);
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.
318 __SCNetworkInterfaceGetUserDefinedName(SCNetworkInterfaceRef interface
);
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.
327 __SCNetworkInterfaceIsActive (SCNetworkInterfaceRef interface
);
330 __SCNetworkInterfaceIsMember (SCPreferencesRef prefs
,
331 SCNetworkInterfaceRef interface
);
334 __SCNetworkInterfaceEntityIsPPTP (CFDictionaryRef entity
);
337 __SCNetworkInterfaceIsValidExtendedConfigurationType
338 (SCNetworkInterfaceRef interface
,
339 CFStringRef extendedType
,
340 Boolean requirePerInterface
);
343 __SCNetworkInterfaceGetTemplateOverrides (SCNetworkInterfaceRef interface
,
344 CFStringRef overrideType
);
347 __SCNetworkInterfaceOrder (SCNetworkInterfaceRef interface
);
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
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.
360 __SCNetworkInterfaceSaveStoredWithPreferences (SCPreferencesRef prefs
,
361 CFArrayRef interfacesToSave
);
364 __SCNetworkInterfaceSetConfiguration (SCNetworkInterfaceRef interface
,
365 CFStringRef extendedType
,
366 CFDictionaryRef config
,
370 __SCNetworkInterfaceSetDeepConfiguration (SCNetworkSetRef set
,
371 SCNetworkInterfaceRef interface
,
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
381 __SCNetworkInterfaceSetIOInterfaceUnit (SCNetworkInterfaceRef interface
,
385 __SCNetworkInterfaceSupportsVLAN (CFStringRef bsd_if
);
388 __SCBondInterfaceListCollectMembers (CFArrayRef interfaces
,
389 CFMutableSetRef set
);
392 __SCBondInterfaceSetMemberInterfaces (SCBondInterfaceRef bond
,
396 __SCBridgeInterfaceListCollectMembers (CFArrayRef interfaces
,
397 CFMutableSetRef set
);
400 __SCBridgeInterfaceSetMemberInterfaces (SCBridgeInterfaceRef bridge
,
404 _SCNetworkInterfaceCacheOpen(void);
407 _SCNetworkInterfaceCacheClose(void);
411 #pragma mark SCNetworkInterface (NetworkInterfaces.plist) configuration (internal)
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"
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.
436 __SCNetworkInterfaceCopyStorageEntity (SCNetworkInterfaceRef interface
);
440 #pragma mark SCNetworkProtocol configuration (internal)
443 SCNetworkProtocolPrivateRef
444 __SCNetworkProtocolCreatePrivate (CFAllocatorRef allocator
,
445 CFStringRef entityID
,
446 SCNetworkServiceRef service
);
449 __SCNetworkProtocolIsValidType (CFStringRef protocolType
);
453 #pragma mark SCNetworkService configuration (internal)
456 CFArrayRef
/* of SCNetworkServiceRef's */
457 __SCNetworkServiceCopyAllEnabled (SCPreferencesRef prefs
);
459 CFArrayRef
/* of SCNetworkInterfaceRef's */
460 __SCNetworkServiceCopyAllInterfaces (SCPreferencesRef prefs
);
462 SCNetworkServicePrivateRef
463 __SCNetworkServiceCreatePrivate (CFAllocatorRef allocator
,
464 SCPreferencesRef prefs
,
465 CFStringRef serviceID
,
466 SCNetworkInterfaceRef interface
);
469 __SCNetworkServiceExists (SCNetworkServiceRef service
);
472 __SCNetworkServiceExistsForInterface (CFArrayRef services
,
473 SCNetworkInterfaceRef interface
);
476 __SCNetworkServiceCreate (SCPreferencesRef prefs
,
477 SCNetworkInterfaceRef interface
,
478 CFStringRef userDefinedName
);
481 __SCNetworkServiceIsPPTP (SCNetworkServiceRef service
);
485 __SCNetworkPopulateDefaultNIPrefs (SCPreferencesRef ni_prefs
);
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
496 __SCNetworkServiceMigrateNew (SCPreferencesRef prefs
,
497 SCNetworkServiceRef service
,
498 CFDictionaryRef bsdMapping
,
499 CFDictionaryRef setMapping
,
500 CFDictionaryRef serviceSetMapping
);
503 __SCNetworkServiceAddProtocolToService (SCNetworkServiceRef service
,
504 CFStringRef protocolType
,
505 CFDictionaryRef configuration
,
510 #pragma mark SCNetworkSet configuration (internal)
514 __SCNetworkSetExists (SCNetworkSetRef set
);
522 __log_SCNetworkConfiguration (void);
526 #pragma mark Miscellaneous (internal)
530 __copyInterfaceTemplate (CFStringRef interfaceType
,
531 CFStringRef childInterfaceType
);
534 __copyProtocolTemplate (CFStringRef interfaceType
,
535 CFStringRef childInterfaceType
,
536 CFStringRef protocolType
);
539 __SCNetworkConfigurationGetValue (SCPreferencesRef prefs
,
543 __SCNetworkConfigurationSetValue (SCPreferencesRef prefs
,
545 CFDictionaryRef config
,
546 Boolean keepInactive
);
549 __getPrefsEnabled (SCPreferencesRef prefs
,
553 __setPrefsEnabled (SCPreferencesRef prefs
,
558 __createInterface (int s
,
559 CFStringRef interface
);
562 __destroyInterface (int s
,
563 CFStringRef interface
);
566 __SCPreferencesPathCreateUniqueChild_WithMoreSCFCompatibility
567 (SCPreferencesRef prefs
,
571 __extract_password (SCPreferencesRef prefs
,
572 CFDictionaryRef config
,
573 CFStringRef passwordKey
,
574 CFStringRef encryptionKey
,
575 CFStringRef encryptionKeyChainValue
,
576 CFStringRef unique_id
,
577 CFDataRef
*password
);
580 __remove_password (SCPreferencesRef prefs
,
581 CFDictionaryRef config
,
582 CFStringRef passwordKey
,
583 CFStringRef encryptionKey
,
584 CFStringRef encryptionKeyChainValue
,
585 CFStringRef unique_id
,
586 CFDictionaryRef
*newConfig
);
589 __rank_to_str (SCNetworkServicePrimaryRank rank
,
590 CFStringRef
*rankStr
);
593 __str_to_rank (CFStringRef rankStr
,
594 SCNetworkServicePrimaryRank
*rank
);
598 #endif /* _SCNETWORKCONFIGURATIONINTERNAL_H */