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)
211 __SCNetworkConfigurationBackup (SCPreferencesRef prefs
) SPI_AVAILABLE(macos(10.15.4), ios(13.4), tvos(13.4), watchos(6.2), bridgeos(4.0));
215 #pragma mark SCNetworkInterface configuration (internal)
219 __SCNetworkInterfaceMatchesName (CFStringRef name
,
223 __SCNetworkInterfaceCopyAll_IONetworkInterface (Boolean keep_pre_configured
);
226 @function __SCNetworkInterfaceCopyStoredWithPreferences
227 @discussion Create an array of network interfaces, which is present in the preferences
228 in NetworkInteraces.plist
229 @param ni_prefs Preference for network interfaces
230 @result Array which contains SCNetworkInterfaceRef.
231 You must release the returned value.
234 CFArrayRef
// SCNetworkInterfaceRef
235 __SCNetworkInterfaceCopyStoredWithPreferences (SCPreferencesRef ni_prefs
);
237 SCNetworkInterfacePrivateRef
238 __SCNetworkInterfaceCreateCopy (CFAllocatorRef allocator
,
239 SCNetworkInterfaceRef interface
,
240 SCPreferencesRef prefs
,
241 CFStringRef serviceID
);
244 @function __SCNetworkInterfaceCreateMappingUsingBSDName
245 @discussion This function creates mapping of BSD name and network interface using
246 preferences which point to the NetworkInterfaces.plist file.
247 @param interfaces An array of network interfaces to use for the mapping.
248 @result BSD Mapping in a dictionary.
249 You must release the returned value.
252 __SCNetworkInterfaceCreateMappingUsingBSDName (CFArrayRef interfaces
);
254 SCNetworkInterfaceRef
255 __SCNetworkInterfaceCreateWithNIPreferencesUsingBSDName(CFAllocatorRef allocator
,
256 SCPreferencesRef ni_prefs
,
257 CFStringRef bsdName
);
259 SCNetworkInterfacePrivateRef
260 __SCNetworkInterfaceCreatePrivate (CFAllocatorRef allocator
,
261 SCNetworkInterfaceRef interface
,
262 SCPreferencesRef prefs
,
263 CFStringRef serviceID
);
265 SCNetworkInterfacePrivateRef
266 _SCBondInterfaceCreatePrivate (CFAllocatorRef allocator
,
267 CFStringRef bond_if
);
269 SCNetworkInterfacePrivateRef
270 _SCBridgeInterfaceCreatePrivate (CFAllocatorRef allocator
,
271 CFStringRef bridge_if
);
273 SCNetworkInterfacePrivateRef
274 _SCVLANInterfaceCreatePrivate (CFAllocatorRef allocator
,
275 CFStringRef vlan_if
);
278 __SCNetworkInterfaceCopyInterfaceEntity (SCNetworkInterfaceRef interface
);
281 __SCNetworkInterfaceCopyDeepConfiguration (SCNetworkSetRef set
,
282 SCNetworkInterfaceRef interface
);
284 #if !TARGET_OS_IPHONE
286 __SCNetworkInterfaceCopyXLocalizedDisplayName (SCNetworkInterfaceRef interface
);
289 __SCNetworkInterfaceCopyXNonLocalizedDisplayName(SCNetworkInterfaceRef interface
);
290 #endif // !TARGET_OS_IPHONE
293 __SCNetworkInterfaceGetDefaultConfigurationType (SCNetworkInterfaceRef interface
);
296 __SCNetworkInterfaceGetEntitySubType (SCNetworkInterfaceRef interface
);
299 __SCNetworkInterfaceGetEntityType (SCNetworkInterfaceRef interface
);
302 __SCNetworkInterfaceGetNonLocalizedDisplayName (SCNetworkInterfaceRef interface
);
305 __SCNetworkInterfaceSetUserDefinedName(SCNetworkInterfaceRef interface
, CFStringRef name
);
308 @function __SCNetworkInterfaceGetUserDefinedName
309 @discussion This function returns the user defined name of the interface if available
310 @param interface The network interface.
311 @result String containing the user defined name.
314 __SCNetworkInterfaceGetUserDefinedName(SCNetworkInterfaceRef interface
);
317 @function __SCNetworkInterfaceIsActive
318 @discussion Identifies if the configuration of network interface is active or not
319 @param interface The network interface
320 @result TRUE if the interface configuration is active.
323 __SCNetworkInterfaceIsActive (SCNetworkInterfaceRef interface
);
326 __SCNetworkInterfaceIsMember (SCPreferencesRef prefs
,
327 SCNetworkInterfaceRef interface
);
330 __SCNetworkInterfaceEntityIsPPTP (CFDictionaryRef entity
);
333 __SCNetworkInterfaceIsValidExtendedConfigurationType
334 (SCNetworkInterfaceRef interface
,
335 CFStringRef extendedType
,
336 Boolean requirePerInterface
);
339 __SCNetworkInterfaceGetTemplateOverrides (SCNetworkInterfaceRef interface
,
340 CFStringRef overrideType
);
343 __SCNetworkInterfaceOrder (SCNetworkInterfaceRef interface
);
346 @function __SCNetworkInterfaceSaveStoredWithPreferences
347 @discussion Saves the array of interfaces in the preferences passed in the function. The interfaces
348 which are already present in the prefs file are replaced.
349 @param prefs Preferences which contain the interfaces to be replaced. If NULL, then preferences on
351 @param interfacesToSave The new interfaces array which is to be stored in preferences.
352 @result TRUE if saving of the new interfaces was successful.
356 __SCNetworkInterfaceSaveStoredWithPreferences (SCPreferencesRef prefs
,
357 CFArrayRef interfacesToSave
);
360 __SCNetworkInterfaceSetConfiguration (SCNetworkInterfaceRef interface
,
361 CFStringRef extendedType
,
362 CFDictionaryRef config
,
366 __SCNetworkInterfaceSetDeepConfiguration (SCNetworkSetRef set
,
367 SCNetworkInterfaceRef interface
,
371 @function __SCNetworkInterfaceSetIOInterfaceUnity
372 @discussion Will allow the caller to set IO Interface Unit
373 @param interface The network interface
374 @param unit The new interface unit to set
377 __SCNetworkInterfaceSetIOInterfaceUnit (SCNetworkInterfaceRef interface
,
381 __SCNetworkInterfaceSupportsVLAN (CFStringRef bsd_if
);
384 __SCBondInterfaceListCollectMembers (CFArrayRef interfaces
,
385 CFMutableSetRef set
);
388 __SCBondInterfaceSetMemberInterfaces (SCBondInterfaceRef bond
,
392 __SCBridgeInterfaceListCollectMembers (CFArrayRef interfaces
,
393 CFMutableSetRef set
);
396 __SCBridgeInterfaceSetMemberInterfaces (SCBridgeInterfaceRef bridge
,
400 _SCNetworkInterfaceCacheOpen(void);
403 _SCNetworkInterfaceCacheClose(void);
407 #pragma mark SCNetworkInterface (NetworkInterfaces.plist) configuration (internal)
410 #define kSCNetworkInterfaceActive "Active"
411 #define kSCNetworkInterfaceInfo "SCNetworkInterfaceInfo"
412 #define kSCNetworkInterfaceType "SCNetworkInterfaceType"
413 #define kSCNetworkInterfaceBSDName kIOBSDNameKey
414 #define kSCNetworkInterfaceIOBuiltin kIOBuiltin
415 #define kSCNetworkInterfaceIOInterfaceNamePrefix kIOInterfaceNamePrefix
416 #define kSCNetworkInterfaceIOInterfaceType kIOInterfaceType
417 #define kSCNetworkInterfaceIOInterfaceUnit kIOInterfaceUnit
418 #define kSCNetworkInterfaceIOMACAddress kIOMACAddress
419 #define kSCNetworkInterfaceIOPathMatch kIOPathMatchKey
420 #define kSCNetworkInterfaceMatchingMACs "MatchingMACs"
424 @function __SCNetworkInterfaceCopyStorageEntity
425 @discussion Create interface entity of network interface as seen in
426 NetworkInterfaces.plist
427 @param interface The network interface from which interface entity is create
428 @result Dictionary which contains information about interface entity.
429 You must release the returned value.
432 __SCNetworkInterfaceCopyStorageEntity (SCNetworkInterfaceRef interface
);
436 #pragma mark SCNetworkProtocol configuration (internal)
439 SCNetworkProtocolPrivateRef
440 __SCNetworkProtocolCreatePrivate (CFAllocatorRef allocator
,
441 CFStringRef entityID
,
442 SCNetworkServiceRef service
);
445 __SCNetworkProtocolIsValidType (CFStringRef protocolType
);
449 #pragma mark SCNetworkService configuration (internal)
452 CFArrayRef
/* of SCNetworkServiceRef's */
453 __SCNetworkServiceCopyAllEnabled (SCPreferencesRef prefs
);
455 CFArrayRef
/* of SCNetworkInterfaceRef's */
456 __SCNetworkServiceCopyAllInterfaces (SCPreferencesRef prefs
);
458 SCNetworkServicePrivateRef
459 __SCNetworkServiceCreatePrivate (CFAllocatorRef allocator
,
460 SCPreferencesRef prefs
,
461 CFStringRef serviceID
,
462 SCNetworkInterfaceRef interface
);
465 __SCNetworkServiceExists (SCNetworkServiceRef service
);
468 __SCNetworkServiceExistsForInterface (CFArrayRef services
,
469 SCNetworkInterfaceRef interface
);
472 __SCNetworkServiceCreate (SCPreferencesRef prefs
,
473 SCNetworkInterfaceRef interface
,
474 CFStringRef userDefinedName
);
477 __SCNetworkServiceIsPPTP (SCNetworkServiceRef service
);
481 __SCNetworkPopulateDefaultNIPrefs (SCPreferencesRef ni_prefs
);
484 @function __SCNetworkServiceMigrateNew
485 @discussion Adds network service to SCPreferencesRef if it doesn't exists
486 @param prefs SCPreferencesRef
487 @param service The network service
488 @param bsdMapping Mapping of interface names between configurations
489 @result TRUE if add service to prefs is successful
492 __SCNetworkServiceMigrateNew (SCPreferencesRef prefs
,
493 SCNetworkServiceRef service
,
494 CFDictionaryRef bsdMapping
,
495 CFDictionaryRef setMapping
,
496 CFDictionaryRef serviceSetMapping
);
499 __SCNetworkServiceAddProtocolToService (SCNetworkServiceRef service
,
500 CFStringRef protocolType
,
501 CFDictionaryRef configuration
,
506 #pragma mark SCNetworkSet configuration (internal)
510 __SCNetworkSetExists (SCNetworkSetRef set
);
518 __log_SCNetworkConfiguration (void);
522 #pragma mark Miscellaneous (internal)
526 __copyInterfaceTemplate (CFStringRef interfaceType
,
527 CFStringRef childInterfaceType
);
530 __copyProtocolTemplate (CFStringRef interfaceType
,
531 CFStringRef childInterfaceType
,
532 CFStringRef protocolType
);
535 __SCNetworkConfigurationGetValue (SCPreferencesRef prefs
,
539 __SCNetworkConfigurationSetValue (SCPreferencesRef prefs
,
541 CFDictionaryRef config
,
542 Boolean keepInactive
);
545 __getPrefsEnabled (SCPreferencesRef prefs
,
549 __setPrefsEnabled (SCPreferencesRef prefs
,
554 __createInterface (int s
,
555 CFStringRef interface
);
558 __destroyInterface (int s
,
559 CFStringRef interface
);
562 __SCPreferencesPathCreateUniqueChild_WithMoreSCFCompatibility
563 (SCPreferencesRef prefs
,
567 __extract_password (SCPreferencesRef prefs
,
568 CFDictionaryRef config
,
569 CFStringRef passwordKey
,
570 CFStringRef encryptionKey
,
571 CFStringRef encryptionKeyChainValue
,
572 CFStringRef unique_id
,
573 CFDataRef
*password
);
576 __remove_password (SCPreferencesRef prefs
,
577 CFDictionaryRef config
,
578 CFStringRef passwordKey
,
579 CFStringRef encryptionKey
,
580 CFStringRef encryptionKeyChainValue
,
581 CFStringRef unique_id
,
582 CFDictionaryRef
*newConfig
);
585 __rank_to_str (SCNetworkServicePrimaryRank rank
,
586 CFStringRef
*rankStr
);
589 __str_to_rank (CFStringRef rankStr
,
590 SCNetworkServicePrimaryRank
*rank
);
594 #endif /* _SCNETWORKCONFIGURATIONINTERNAL_H */