2 * Copyright (c) 2014 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@
25 // SCNetworkMigration.c
27 // Created by Ashish Kulkarni on 11/19/13.
32 #include <CoreFoundation/CoreFoundation.h>
33 #include <SystemConfiguration/SystemConfiguration.h>
34 #include <SystemConfiguration/SCNetworkConfigurationPrivate.h>
35 #include <SystemConfiguration/SCNetworkConfigurationInternal.h>
36 #include "SCPreferencesInternal.h"
37 #include <IOKit/network/IONetworkInterface.h>
38 #include <IOKit/network/IONetworkController.h>
39 #include <SystemConfiguration/SCPrivate.h>
42 #include <sys/param.h>
45 #define BACK_TO_MY_MAC CFSTR("BackToMyMac")
46 #define BACK_TO_MY_MAC_DSIDS CFSTR("BackToMyMacDSIDs")
47 #define PREFS_DEFAULT_DIR_PLIST "/Library/Preferences/SystemConfiguration"
48 #define PREFS_DEFAULT_DIR_RELATIVE CFSTR("Library/Preferences/SystemConfiguration/")
49 #define PREFS_DEFAULT_CONFIG_PLIST "preferences.plist"
50 #define NETWORK_INTERFACES_PREFS_PLIST "NetworkInterfaces.plist"
51 #define NUM_MIGRATION_PATHS 2
52 #define PLUGIN_ID CFSTR("System Migration")
53 #define PREFERENCES_PLIST_INDEX 0
54 #define NETWORK_INTERFACES_PLIST_INDEX 1
57 const CFStringRef kSCNetworkConfigurationMigrationActionKey
= CFSTR("MigrationActionKey");
58 const CFStringRef kSCNetworkConfigurationRepair
= CFSTR("ConfigurationRepair");
60 static CFDictionaryRef
61 _SCNetworkMigrationCopyMappingBSDNameToBridgeServices(SCPreferencesRef prefs
);
63 static CFDictionaryRef
64 _SCNetworkMigrationCopyMappingBSDNameToBondServices(SCPreferencesRef prefs
);
66 static CFDictionaryRef
67 _SCNetworkMigrationCopyMappingBSDNameToVLANServices(SCPreferencesRef prefs
);
70 _SCNetworkConfigurationIsInterfaceNamerMappable(SCNetworkInterfaceRef interface1
, SCNetworkInterfaceRef interface2
, Boolean bypassActive
);
73 _SCNetworkConfigurationMigrateConfiguration(CFURLRef sourceDir
, CFURLRef targetDir
);
76 _SCNetworkConfigurationCopyMigrationPathsWithBaseURL(CFURLRef baseURL
, CFURLRef
*prefs
, CFURLRef
*interfaces
)
78 if (baseURL
!= NULL
) {
82 baseURL
= CFURLCreateFromFileSystemRepresentation(NULL
,
83 (UInt8
*)PREFS_DEFAULT_DIR_PLIST
,
84 sizeof(PREFS_DEFAULT_DIR_PLIST
),
88 *prefs
= CFURLCreateFromFileSystemRepresentationRelativeToBase(NULL
,
89 (UInt8
*)PREFS_DEFAULT_CONFIG_PLIST
,
90 sizeof(PREFS_DEFAULT_CONFIG_PLIST
) - 1,
93 *interfaces
= CFURLCreateFromFileSystemRepresentationRelativeToBase(NULL
,
94 (UInt8
*)NETWORK_INTERFACES_PREFS_PLIST
,
95 sizeof(NETWORK_INTERFACES_PREFS_PLIST
) - 1,
102 _SCNetworkConfigurationCopyMigrationPaths(CFDictionaryRef options
)
105 CFMutableArrayRef migrationPaths
= NULL
;
108 if (getenv(INSTALL_ENVIRONMENT
) != NULL
) {
111 _SCNetworkConfigurationCopyMigrationPathsWithBaseURL(NULL
, &prefs
, &interfaces
);
113 migrationPaths
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
114 CFArrayInsertValueAtIndex(migrationPaths
, PREFERENCES_PLIST_INDEX
, prefs
);
115 CFArrayInsertValueAtIndex(migrationPaths
, NETWORK_INTERFACES_PLIST_INDEX
, interfaces
);
118 CFRelease(interfaces
);
119 return migrationPaths
;
123 _SCNetworkConfigurationRemoveConfigurationFiles(CFURLRef configDir
)
126 char configPathString
[PATH_MAX
];
127 CFURLRef configPathURL
= NULL
;
128 char configNetworkInterfacesPathString
[PATH_MAX
];
129 CFURLRef configNetworkInterfacesPathURL
= NULL
;
131 _SCNetworkConfigurationCopyMigrationPathsWithBaseURL(configDir
, &configPathURL
, &configNetworkInterfacesPathURL
);
133 if(CFURLGetFileSystemRepresentation(configPathURL
, TRUE
, (UInt8
*)configPathString
, sizeof(configPathString
)) == FALSE
) {
134 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationRemoveConfigurationFiles: configPathString is NULL"));
137 if (remove(configPathString
) != 0) {
138 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationRemoveConfigurationFiles: Removing file failed from: %s. Error is %d"), configPathString
, errno
);
142 if(CFURLGetFileSystemRepresentation(configNetworkInterfacesPathURL
, TRUE
, (UInt8
*)configNetworkInterfacesPathString
, sizeof(configNetworkInterfacesPathString
)) == FALSE
) {
143 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationRemoveConfigurationFiles: configNetwork"));
146 if (remove(configNetworkInterfacesPathString
) != 0) {
147 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationRemoveConfigurationFiles: Removing file failed from: %s. Error is %d"), configNetworkInterfacesPathString
, errno
);
151 if (configPathURL
!= NULL
) {
152 CFRelease(configPathURL
);
154 if (configNetworkInterfacesPathURL
!= NULL
) {
155 CFRelease(configNetworkInterfacesPathURL
);
162 SCNetworkConfigurationCopyConfigurationFiles(CFURLRef configDir
,
163 CFURLRef targetDir
) // TargetDir needs to exist
166 mode_t mode
= S_IRWXU
| S_IRGRP
| S_IXGRP
| S_IROTH
| S_IXOTH
;
167 char networkInterfacesPathString
[PATH_MAX
];
168 CFURLRef networkInterfacesPathURL
= NULL
;
169 copyfile_state_t networkInterfacesState
;
170 char preferencesPathString
[PATH_MAX
];
171 CFURLRef preferencesPathURL
= NULL
;
172 Boolean removeTargetFiles
= FALSE
;
173 copyfile_state_t state
;
174 Boolean success
= FALSE
;
175 char targetNetworkInterfacesPathString
[PATH_MAX
];
176 CFURLRef targetNetworkInterfacesPathURL
= NULL
;
177 char targetPathString
[PATH_MAX
];
178 CFURLRef targetPathURL
= NULL
;
180 _SCNetworkConfigurationCopyMigrationPathsWithBaseURL(targetDir
, &targetPathURL
, &targetNetworkInterfacesPathURL
);
182 if (CFURLGetFileSystemRepresentation(targetPathURL
, TRUE
, (UInt8
*)targetPathString
, sizeof(targetPathString
)) == FALSE
) {
183 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("SCNetworkConfigurationCopyConfigurationFiles: targetPathString is NULL"));
187 if (CFURLGetFileSystemRepresentation(targetNetworkInterfacesPathURL
, TRUE
, (UInt8
*)targetNetworkInterfacesPathString
, sizeof(targetNetworkInterfacesPathString
)) == FALSE
) {
188 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("SCNetworkConfigurationCopyConfigurationFiles: targetNetworkInterfacesPathString is NULL"));
192 if (configDir
== NULL
) {
193 removeTargetFiles
= TRUE
;
197 _SCNetworkConfigurationCopyMigrationPathsWithBaseURL(configDir
, &preferencesPathURL
, &networkInterfacesPathURL
);
199 if (CFURLGetFileSystemRepresentation(preferencesPathURL
, TRUE
, (UInt8
*)preferencesPathString
, sizeof(preferencesPathString
)) == FALSE
) {
200 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("SCNetworkConfigurationCopyConfigurationFiles: preferencesPathString is NULL"));
205 if (CFURLGetFileSystemRepresentation(networkInterfacesPathURL
, TRUE
, (UInt8
*)networkInterfacesPathString
, sizeof(networkInterfacesPathString
)) == FALSE
) {
206 SCLog(_sc_debug
, LOG_DEBUG
, CFSTR("SCNetworkConfigurationCopyConfigurationFiles: networkInterfacePathString is NULL"));
210 state
= copyfile_state_alloc();
211 if ((error
= copyfile(preferencesPathString
, targetPathString
, state
, COPYFILE_ALL
)) != 0) {
212 SCLog(TRUE
, LOG_ERR
, CFSTR("SCNetworkConfigurationCopyConfigurationFiles: Copying failed from:%s to %s. Error is %d"), preferencesPathString
, targetPathString
, errno
);
213 copyfile_state_free(state
);
214 removeTargetFiles
= TRUE
;
217 copyfile_state_free(state
);
218 chmod(targetPathString
, mode
);
220 networkInterfacesState
= copyfile_state_alloc();
221 if ((error
= copyfile(networkInterfacesPathString
, targetNetworkInterfacesPathString
, networkInterfacesState
, COPYFILE_ALL
)) != 0) {
222 SCLog(TRUE
, LOG_ERR
, CFSTR("SCNetworkConfigurationCopyConfigurationFiles: Copying failed from:%s to %s. Error is %d"), networkInterfacesPathString
, targetNetworkInterfacesPathString
, errno
);
223 copyfile_state_free(networkInterfacesState
);
224 removeTargetFiles
= TRUE
;
227 copyfile_state_free(networkInterfacesState
);
228 chmod(targetNetworkInterfacesPathString
, mode
);
232 if (removeTargetFiles
== TRUE
) {
233 _SCNetworkConfigurationRemoveConfigurationFiles(targetDir
);
235 if (preferencesPathURL
!= NULL
) {
236 CFRelease(preferencesPathURL
);
238 if (networkInterfacesPathURL
!= NULL
) {
239 CFRelease(networkInterfacesPathURL
);
241 if (targetPathURL
!= NULL
) {
242 CFRelease(targetPathURL
);
244 if (targetNetworkInterfacesPathURL
!= NULL
) {
245 CFRelease(targetNetworkInterfacesPathURL
);
251 /* -----------------------------------------------------------------------------
252 Create directories and intermediate directories as required.
253 ----------------------------------------------------------------------------- */
255 _SCNetworkConfigurationMakePathIfNeeded(CFURLRef pathURL
)
260 char thepath
[PATH_MAX
];
263 Boolean success
= FALSE
;
265 if (CFURLGetFileSystemRepresentation(pathURL
, TRUE
, (UInt8
*)path
, sizeof(path
)) == FALSE
) {
266 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMakePathIfNeeded: Could not get character array from target string"));
269 SCLog(TRUE
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMakePathIfNeeded: Creating path: %s"), path
);
271 newmask
= S_IRWXU
| S_IRGRP
| S_IROTH
| S_IXGRP
| S_IXOTH
;
275 strlcpy( thepath
, path
, slen
+1);
279 for( ; !success
; c
++){
280 if ( (*c
== '/') || ( *c
== '\0' )){
285 if ( mkdir( thepath
, newmask
) ){
286 if ( errno
== EEXIST
|| errno
== EISDIR
){
287 if ( stat(thepath
, &sb
) < 0){
288 printf("stat returned value < 0\n");
292 printf("received error: %s\n", strerror(errno
));
302 static SCPreferencesRef
303 __SCNetworkCreateDefaultPref(CFStringRef prefsID
)
305 SCPreferencesRef prefs
;
306 SCNetworkSetRef currentSet
;
309 prefs
= SCPreferencesCreate(NULL
, PLUGIN_ID
, prefsID
);
314 currentSet
= SCNetworkSetCopyCurrent(prefs
);
315 if (currentSet
== NULL
) {
317 CFStringRef setName
= NULL
;
319 currentSet
= SCNetworkSetCreate(prefs
);
320 bundle
= _SC_CFBundleGet();
321 if (bundle
!= NULL
) {
322 setName
= CFBundleCopyLocalizedString(bundle
,
323 CFSTR("DEFAULT_SET_NAME"),
327 SCNetworkSetSetName(currentSet
, (setName
!= NULL
) ? setName
: CFSTR("Automatic"));
328 SCNetworkSetSetCurrent(currentSet
);
329 if (setName
!= NULL
) {
333 SCNetworkSetEstablishDefaultConfiguration(currentSet
);
334 CFRelease(currentSet
);
336 model
= SCPreferencesGetValue(prefs
, MODEL
);
338 model
= _SC_hw_model(FALSE
);
339 SCPreferencesSetValue(prefs
, MODEL
, model
);
347 __SCNetworkCreateDefaultNIPrefs(CFStringRef prefsID
)
349 CFMutableArrayRef interfaces
= NULL
;
351 CFArrayRef networkInterfaces
;
352 SCPreferencesRef ni_prefs
;
353 CFComparisonResult res
;
356 networkInterfaces
= __SCNetworkInterfaceCopyAll_IONetworkInterface();
358 if (networkInterfaces
== NULL
) {
361 if (prefsID
== NULL
) {
362 prefsID
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%@/%@"), PREFS_DEFAULT_DIR
, NETWORK_INTERFACES_PREFS
);
368 ni_prefs
= SCPreferencesCreate(NULL
, PLUGIN_ID
, prefsID
);
371 if (ni_prefs
== NULL
) {
375 interfaces
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
377 for (CFIndex idx
= 0; idx
< CFArrayGetCount(networkInterfaces
); idx
++) {
381 SCNetworkInterfaceRef interface
= CFArrayGetValueAtIndex(networkInterfaces
, idx
);
382 CFDictionaryRef interfaceEntity
= __SCNetworkInterfaceCopyStorageEntity(interface
);
384 if (interfaceEntity
== NULL
) {
388 if_type
= _SCNetworkInterfaceGetIOInterfaceType(interface
);
389 if_unit
= _SCNetworkInterfaceGetIOInterfaceUnit(interface
);
391 if ((if_type
== NULL
) || (if_unit
== NULL
)) {
392 CFRelease(interfaceEntity
);
396 for (idx2
= 0; idx2
< CFArrayGetCount(interfaces
); idx2
++) {
399 CFDictionaryRef dict
= CFArrayGetValueAtIndex(interfaces
, idx2
);
401 db_type
= CFDictionaryGetValue(dict
, CFSTR(kIOInterfaceType
));
402 db_unit
= CFDictionaryGetValue(dict
, CFSTR(kIOInterfaceUnit
));
403 res
= CFNumberCompare(if_type
, db_type
, NULL
);
404 if (res
== kCFCompareLessThan
405 || (res
== kCFCompareEqualTo
406 && (CFNumberCompare(if_unit
, db_unit
, NULL
) == kCFCompareLessThan
))) {
411 CFArrayInsertValueAtIndex(interfaces
, idx2
, interfaceEntity
);
412 CFRelease(interfaceEntity
);
415 SCPreferencesSetValue(ni_prefs
, INTERFACES
, interfaces
);
417 model
= SCPreferencesGetValue(ni_prefs
, MODEL
);
419 model
= _SC_hw_model(FALSE
);
420 SCPreferencesSetValue(ni_prefs
, MODEL
, model
);
423 if (interfaces
!= NULL
) {
424 CFRelease(interfaces
);
426 if (networkInterfaces
!= NULL
) {
427 CFRelease(networkInterfaces
);
435 * _SCNetworkConfigurationPerformMigration will migrate configuration between source and destination systems
439 _SCNetworkConfigurationPerformMigration(CFURLRef sourceDir
, CFURLRef currentDir
, CFURLRef targetDir
, CFDictionaryRef options
)
441 CFURLRef currentDirConfig
= NULL
;
442 CFURLRef currentSystemPath
= NULL
;
443 Boolean migrationComplete
= FALSE
;
444 CFArrayRef paths
= NULL
;
445 Boolean removeTargetOnFailure
= FALSE
;
446 CFURLRef sourceDirConfig
= NULL
;
447 CFURLRef targetDirConfig
= NULL
;
449 if (getenv(INSTALL_ENVIRONMENT
) != NULL
) {
453 // Both sourceDir and currentDir cannot be NULL because NULL value indicates using current system
454 if (sourceDir
== NULL
&& currentDir
== NULL
) {
455 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationPerformMigration: Both sourceDir and currentDir are NULL"));
459 currentSystemPath
= CFURLCreateWithString(NULL
,
463 // if either of the sourceDir or currentDir are NULL, then populate it with current system path
464 if (sourceDir
== NULL
) {
465 sourceDirConfig
= CFRetain(currentSystemPath
);
468 sourceDirConfig
= CFURLCreateWithFileSystemPathRelativeToBase(NULL
, PREFS_DEFAULT_DIR_RELATIVE
, kCFURLPOSIXPathStyle
, TRUE
, sourceDir
);
471 if (currentDir
!= NULL
) {
472 currentDirConfig
= CFURLCreateWithFileSystemPathRelativeToBase(NULL
, PREFS_DEFAULT_DIR_RELATIVE
, kCFURLPOSIXPathStyle
, TRUE
, currentDir
);
474 // If the targetDir is not provided then migration will take place in currentDir
475 if (targetDir
== NULL
) {
476 targetDirConfig
= CFRetain(currentSystemPath
);
479 targetDirConfig
= CFURLCreateWithFileSystemPathRelativeToBase(NULL
, PREFS_DEFAULT_DIR_RELATIVE
, kCFURLPOSIXPathStyle
, TRUE
, targetDir
);
481 // Source directory cannot be the same as Target Directory
482 if (CFEqual(sourceDirConfig
, targetDirConfig
)) {
483 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationPerformMigration: Source directory cannot be the same as target directory"));
487 if ((currentDirConfig
== NULL
) || (CFEqual(currentDirConfig
, targetDirConfig
) == FALSE
)) {
488 if (_SCNetworkConfigurationMakePathIfNeeded(targetDirConfig
) == FALSE
) {
489 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationPerformMigration: Could not create target directory as expected"));
493 if (SCNetworkConfigurationCopyConfigurationFiles(currentDirConfig
, targetDirConfig
) == FALSE
) {
494 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationPerformMigration: Could not copy configuration files from %@ to %@"),
495 currentDirConfig
, targetDirConfig
);
497 else if (currentDirConfig
!= NULL
) {
498 removeTargetOnFailure
= TRUE
; // Configuration files were copied over to target directory
499 // If migration failed, then we should remove those configuration
500 // files since current directory and target directory are not
505 // If both source and current configurations point to current system, then no migration needs to be done.
506 if ((currentDirConfig
!= NULL
) && (CFEqual(sourceDirConfig
, currentDirConfig
) == TRUE
)) {
507 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationPerformMigration: both source and current configurations point to same path ... No migration needs to be done"));
508 migrationComplete
= TRUE
;
511 migrationComplete
= _SCNetworkConfigurationMigrateConfiguration(sourceDirConfig
, targetDirConfig
);
513 SCLog(TRUE
, LOG_NOTICE
, CFSTR("Migration %s"), migrationComplete
? "complete" : "failed");
514 if (migrationComplete
== TRUE
) {
515 paths
= _SCNetworkConfigurationCopyMigrationPaths(NULL
);
518 // If migration fails, then remove configuration files from target config if they are
519 // copied from the current directory
520 if (removeTargetOnFailure
== TRUE
) {
521 _SCNetworkConfigurationRemoveConfigurationFiles(targetDirConfig
);
525 if (currentDirConfig
!= NULL
) {
526 CFRelease(currentDirConfig
);
528 if (currentSystemPath
!= NULL
) {
529 CFRelease(currentSystemPath
);
531 if (sourceDirConfig
!= NULL
) {
532 CFRelease(sourceDirConfig
);
534 if (targetDirConfig
!= NULL
) {
535 CFRelease(targetDirConfig
);
541 _SCNetworkConfigurationMigrateIsFilePresent(CFURLRef filePath
)
543 Boolean fileExists
= false;
544 char filePathStr
[PATH_MAX
];
546 struct stat statStruct
= {0, };
548 if (filePath
== NULL
) {
549 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateIsFilePresent: filePath is NULL"));
553 if (CFURLGetFileSystemRepresentation(filePath
, TRUE
, (UInt8
*) filePathStr
, sizeof(filePathStr
)) == FALSE
) {
554 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateIsFilePresent: Couldn't get file system representation\n"));
558 statResult
= stat(filePathStr
, &statStruct
);
560 if (statResult
== 0) {
568 __SCNetworkConfigurationMigrateConfigurationFilesPresent(CFURLRef baseURL
, CFArrayRef
* migrationPaths
)
570 Boolean configFilesPresent
= FALSE
;
572 CFURLRef filePath
= NULL
;
574 CFMutableArrayRef migrationPathsMutable
= NULL
;
577 if (baseURL
== NULL
) {
578 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("__SCNetworkConfigurationMigrateConfigurationFilesPresent: baseURL is NULL"));
582 _SCNetworkConfigurationCopyMigrationPathsWithBaseURL(baseURL
, &prefs
, &interfaces
);
584 migrationPathsMutable
= CFArrayCreateMutable(kCFAllocatorDefault
, 0, &kCFTypeArrayCallBacks
);
585 CFArrayInsertValueAtIndex(migrationPathsMutable
, PREFERENCES_PLIST_INDEX
, prefs
);
586 CFArrayInsertValueAtIndex(migrationPathsMutable
, NETWORK_INTERFACES_PLIST_INDEX
, interfaces
);
589 CFRelease(interfaces
);
591 *migrationPaths
= migrationPathsMutable
;
593 if ((*migrationPaths
== NULL
) ||
594 ((count
= CFArrayGetCount(*migrationPaths
)) == 0)) {
595 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("__SCNetworkConfigurationMigrateConfigurationFilesPresent: migrationPath is NULL or number of elements in migrationPath array is 0"));
599 for (CFIndex idx
= 0; idx
< count
; idx
++) {
600 filePath
= CFArrayGetValueAtIndex(*migrationPaths
, idx
);
601 if (_SCNetworkConfigurationMigrateIsFilePresent(filePath
) == FALSE
) {
602 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("__SCNetworkConfigurationMigrateConfigurationFilesPresent: File not present: %@"), filePath
);
607 configFilesPresent
= TRUE
; // all necessary configuration files present
609 return configFilesPresent
;
613 static CFMutableArrayRef
614 _SCNetworkInterfaceCopyInterfacesFilteredByBuiltinWithPreferences (SCPreferencesRef ni_prefs
, Boolean isBuiltin
)
617 SCNetworkInterfaceRef interface
;
618 CFArrayRef interfaceList
= NULL
;
619 CFMutableArrayRef resultInterfaceList
= NULL
;
621 interfaceList
= __SCNetworkInterfaceCopyStoredWithPreferences(ni_prefs
);
622 if (interfaceList
== NULL
) {
623 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkInterfaceCopyInterfacesFilteredByBuiltinWithPreferences: interfaceList is NULL"));
627 count
= CFArrayGetCount(interfaceList
);
629 resultInterfaceList
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
632 for (CFIndex i
= 0; i
< count
; i
++) {
633 interface
= CFArrayGetValueAtIndex(interfaceList
, i
);
635 if (_SCNetworkInterfaceIsBuiltin(interface
) == isBuiltin
) {
636 CFArrayAppendValue(resultInterfaceList
, interface
);
641 if (interfaceList
!= NULL
) {
642 CFRelease(interfaceList
);
644 return resultInterfaceList
;
647 static CFMutableDictionaryRef
648 _SCNetworkInterfaceStorageCopyMaxUnitPerInterfaceType(SCPreferencesRef ni_prefs
)
650 CFNumberRef cfMaxUnit
;
652 CFArrayRef ifList
= NULL
;
653 SCNetworkInterfaceRef interface
;
654 CFMutableDictionaryRef InterfaceTypeToMaxUnitMapping
= NULL
;
658 ifList
= __SCNetworkInterfaceCopyStoredWithPreferences(ni_prefs
);
660 if (ifList
== NULL
) {
661 SCLog(TRUE
, LOG_ERR
, CFSTR("_SCNetworkInterfaceStorageCopyMaxUnitPerInterfaceType: ifList is NULL"));
665 InterfaceTypeToMaxUnitMapping
= CFDictionaryCreateMutable(NULL
, 0,
666 &kCFTypeDictionaryKeyCallBacks
,
667 &kCFTypeDictionaryValueCallBacks
);
668 count
= CFArrayGetCount(ifList
);
670 for (CFIndex idx
= 0; idx
< count
; idx
++) {
672 interface
= CFArrayGetValueAtIndex(ifList
, idx
);
674 if (isA_SCNetworkInterface(interface
) == NULL
) {
678 type
= _SCNetworkInterfaceGetIOInterfaceType(interface
);
680 if (isA_CFNumber(type
) == NULL
) {
681 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkInterfaceStorageCopyMaxUnitPerInterfaceType: type is NULL"));
685 if (CFDictionaryContainsKey(InterfaceTypeToMaxUnitMapping
, type
) == FALSE
) {
687 cfMaxUnit
= CFNumberCreate(NULL
, kCFNumberIntType
, &temp
);
688 CFDictionaryAddValue(InterfaceTypeToMaxUnitMapping
, type
, cfMaxUnit
);
689 CFRelease(cfMaxUnit
);
692 if (cfMaxUnit
== NULL
) {
693 cfMaxUnit
= CFDictionaryGetValue(InterfaceTypeToMaxUnitMapping
, type
);
696 unit
= _SCNetworkInterfaceGetIOInterfaceUnit(interface
);
698 if (isA_CFNumber(unit
) == NULL
) {
702 if (CFNumberCompare(unit
, cfMaxUnit
, NULL
) == kCFCompareGreaterThan
) {
703 CFDictionarySetValue(InterfaceTypeToMaxUnitMapping
, type
, unit
);
706 if (ifList
!= NULL
) {
709 return InterfaceTypeToMaxUnitMapping
;
712 static CFMutableDictionaryRef
713 _SCNetworkConfigurationCopyBuiltinMapping (SCPreferencesRef sourcePrefs
, SCPreferencesRef targetPrefs
)
715 CFMutableDictionaryRef builtinMapping
= NULL
;
716 CFIndex sourceBuiltinInterfaceCount
= 0;
717 CFMutableArrayRef sourceBuiltinInterfaces
= NULL
;
718 SCNetworkInterfaceRef sourceInterface
;
719 CFIndex targetBuiltinInterfaceCount
= 0;
720 CFMutableArrayRef targetBuiltinInterfaces
= NULL
;
721 SCNetworkInterfaceRef targetInterface
;
723 sourceBuiltinInterfaces
= _SCNetworkInterfaceCopyInterfacesFilteredByBuiltinWithPreferences(sourcePrefs
, TRUE
);
724 if (isA_CFArray(sourceBuiltinInterfaces
) == NULL
) {
725 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCopyBuiltinMapping: sourceBuiltinInterfaces is NULL"));
728 sourceBuiltinInterfaceCount
= CFArrayGetCount(sourceBuiltinInterfaces
);
730 targetBuiltinInterfaces
= _SCNetworkInterfaceCopyInterfacesFilteredByBuiltinWithPreferences(targetPrefs
, TRUE
);
731 if (isA_CFArray(targetBuiltinInterfaces
) == NULL
) {
732 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCopyBuiltinMapping: targetBuiltinInterfaces is NULL"));
735 targetBuiltinInterfaceCount
= CFArrayGetCount(targetBuiltinInterfaces
);
737 // Builtin Mapping will try to map all source interfaces into target interfaces
738 for (CFIndex idx
= 0; idx
< sourceBuiltinInterfaceCount
; idx
++) {
739 sourceInterface
= CFArrayGetValueAtIndex(sourceBuiltinInterfaces
, idx
);
740 for (CFIndex idx2
= 0; idx2
< targetBuiltinInterfaceCount
; idx2
++) {
741 targetInterface
= CFArrayGetValueAtIndex(targetBuiltinInterfaces
, idx2
);
743 if (_SCNetworkConfigurationIsInterfaceNamerMappable(sourceInterface
, targetInterface
, FALSE
) == TRUE
) {
744 if (builtinMapping
== NULL
) {
745 builtinMapping
= CFDictionaryCreateMutable(NULL
, 0,
746 &kCFTypeDictionaryKeyCallBacks
,
747 &kCFTypeDictionaryValueCallBacks
);
749 CFDictionaryAddValue(builtinMapping
, sourceInterface
, targetInterface
);
750 CFArrayRemoveValueAtIndex(targetBuiltinInterfaces
, idx2
);
754 targetBuiltinInterfaceCount
= CFArrayGetCount(targetBuiltinInterfaces
);
758 if (sourceBuiltinInterfaces
!= NULL
) {
759 CFRelease(sourceBuiltinInterfaces
);
761 if (targetBuiltinInterfaces
!= NULL
) {
762 CFRelease(targetBuiltinInterfaces
);
764 return builtinMapping
;
767 static CFMutableDictionaryRef
768 _SCNetworkConfigurationCopyExternalInterfaceMapping (SCPreferencesRef sourcePref
, SCPreferencesRef targetPrefs
)
770 CFNumberRef cfMaxTargetUnit
= NULL
;
771 CFNumberRef currentInterfaceUnit
= NULL
;
772 CFMutableDictionaryRef externalMapping
= NULL
;
773 CFMutableDictionaryRef InterfaceTypeToMaxUnitMapping
= NULL
;
776 CFIndex sourceExternalInterfaceCount
= 0;
777 CFMutableArrayRef sourceExternalInterfaces
= NULL
;
778 SCNetworkInterfaceRef sourceInterface
= NULL
;
779 CFIndex targetExternalInterfaceCount
= 0;
780 CFMutableArrayRef targetExternalInterfaces
= NULL
;
781 SCNetworkInterfaceRef targetInterface
= NULL
;
784 sourceExternalInterfaces
= _SCNetworkInterfaceCopyInterfacesFilteredByBuiltinWithPreferences(sourcePref
, FALSE
);
785 if (isA_CFArray(sourceExternalInterfaces
) == NULL
) {
786 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCopyExternalInterfaceMapping: sourceExternalInterfaces is NULL"));
789 sourceExternalInterfaceCount
= CFArrayGetCount(sourceExternalInterfaces
);
791 if (sourceExternalInterfaceCount
== 0) {
792 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCopyExternalInterfaceMapping: sourceExternalInterfaceCount is 0"));
796 targetExternalInterfaces
= _SCNetworkInterfaceCopyInterfacesFilteredByBuiltinWithPreferences(targetPrefs
, FALSE
);
797 if (isA_CFArray(targetExternalInterfaces
) == NULL
) {
798 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCopyExternalInterfaceMapping: targetExternalInterfaces is NULL"));
802 InterfaceTypeToMaxUnitMapping
= _SCNetworkInterfaceStorageCopyMaxUnitPerInterfaceType(targetPrefs
);
803 externalMapping
= CFDictionaryCreateMutable(NULL
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
805 // Map all external interfaces which exist in both source and target
806 for (CFIndex idx
= 0; idx
< sourceExternalInterfaceCount
; idx
++) {
807 sourceInterface
= CFArrayGetValueAtIndex(sourceExternalInterfaces
, idx
);
808 targetExternalInterfaceCount
= CFArrayGetCount(targetExternalInterfaces
);
809 currentInterfaceUnit
= NULL
;
811 for (CFIndex idx2
= 0; idx2
< targetExternalInterfaceCount
; idx2
++) {
812 targetInterface
= CFArrayGetValueAtIndex(targetExternalInterfaces
, idx2
);
814 if (_SCNetworkConfigurationIsInterfaceNamerMappable(sourceInterface
, targetInterface
, TRUE
) == TRUE
) {
815 CFDictionaryAddValue(externalMapping
, sourceInterface
, targetInterface
);
816 CFArrayRemoveValueAtIndex(targetExternalInterfaces
, idx2
);
821 if (CFDictionaryContainsKey(externalMapping
, sourceInterface
) == FALSE
) {
822 // Create new mappings for external source interfaces which don't exist in the target
823 type
= _SCNetworkInterfaceGetIOInterfaceType(sourceInterface
);
825 cfMaxTargetUnit
= CFDictionaryGetValue(InterfaceTypeToMaxUnitMapping
, type
);
826 if (cfMaxTargetUnit
!= NULL
) {
827 CFNumberGetValue(cfMaxTargetUnit
, kCFNumberIntType
, &maxTargetUnit
);
828 newTargetUnit
= maxTargetUnit
+ 1;
834 cfMaxTargetUnit
= CFNumberCreate(NULL
, kCFNumberIntType
, &newTargetUnit
);
835 CFDictionarySetValue(InterfaceTypeToMaxUnitMapping
, type
, cfMaxTargetUnit
);
837 targetInterface
= (SCNetworkInterfaceRef
)__SCNetworkInterfaceCreateCopy(NULL
, sourceInterface
, NULL
, NULL
);
839 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCopyExternalInterfaceMapping: sourceInterface: %p, target Interface: %p"), sourceInterface
, targetInterface
);
841 currentInterfaceUnit
= _SCNetworkInterfaceGetIOInterfaceUnit(targetInterface
);
843 if ((isA_CFNumber(currentInterfaceUnit
) == NULL
) ||
844 (CFEqual(currentInterfaceUnit
, cfMaxTargetUnit
) == FALSE
)) {
845 // Update the interface unit
846 __SCNetworkInterfaceSetIOInterfaceUnit(targetInterface
, cfMaxTargetUnit
);
849 CFDictionaryAddValue(externalMapping
, sourceInterface
, targetInterface
);
851 CFRelease(targetInterface
);
852 targetInterface
= NULL
;
853 CFRelease(cfMaxTargetUnit
);
854 cfMaxTargetUnit
= NULL
;
858 if (sourceExternalInterfaces
!= NULL
) {
859 CFRelease(sourceExternalInterfaces
);
861 if (targetExternalInterfaces
!= NULL
) {
862 CFRelease(targetExternalInterfaces
);
864 if (InterfaceTypeToMaxUnitMapping
!= NULL
) {
865 CFRelease(InterfaceTypeToMaxUnitMapping
);
867 return externalMapping
;
870 __SCNetworkConfigurationInterfaceNameIsEquiv(CFStringRef interfaceName1
, CFStringRef interfaceName2
);
873 _SCNetworkConfigurationIsInterfaceNamerMappable(SCNetworkInterfaceRef interface1
, SCNetworkInterfaceRef interface2
, Boolean bypassActive
)
875 Boolean interface1IsBuiltin
;
876 CFStringRef interface1Prefix
;
877 CFStringRef interface1Type
;
878 CFStringRef interface1UserDefinedName
;
879 Boolean interface2IsBuiltin
;
880 CFStringRef interface2Prefix
;
881 CFStringRef interface2Type
;
882 CFStringRef interface2UserDefinedName
;
884 if (interface1
== interface2
) {
885 // No work needs to be done
888 interface1IsBuiltin
= _SCNetworkInterfaceIsBuiltin(interface1
);
889 interface2IsBuiltin
= _SCNetworkInterfaceIsBuiltin(interface2
);
891 interface1UserDefinedName
= SCNetworkInterfaceGetLocalizedDisplayName(interface1
);
892 interface2UserDefinedName
= SCNetworkInterfaceGetLocalizedDisplayName(interface2
);
894 interface1Type
= SCNetworkInterfaceGetInterfaceType(interface1
);
895 interface2Type
= SCNetworkInterfaceGetInterfaceType(interface2
);
897 interface1Prefix
= _SCNetworkInterfaceGetIOInterfaceNamePrefix(interface1
);
898 interface2Prefix
= _SCNetworkInterfaceGetIOInterfaceNamePrefix(interface2
);
900 // Check if have same builtin values.
901 // Check if User Defined name matches
902 // Check if SCNetwork Interface Type matches
904 if (interface1IsBuiltin
!= interface2IsBuiltin
) {
908 if (_SC_CFEqual(interface1Type
, interface2Type
) == FALSE
) {
912 if (_SC_CFEqual(interface1Prefix
, interface2Prefix
) == FALSE
) {
916 if (_SC_CFEqual(interface1UserDefinedName
, interface2UserDefinedName
) == FALSE
) {
917 // Checking if we have a mismatch because of the name Ethernet and Ethernet 1
918 // Checking if we have a mismatch because of the name Airport and WiFi
919 if ((interface1IsBuiltin
== TRUE
) &&
920 (interface2IsBuiltin
== TRUE
) &&
921 (__SCNetworkConfigurationInterfaceNameIsEquiv(interface1UserDefinedName
, interface2UserDefinedName
) == TRUE
)) {
930 __SCNetworkConfigurationInterfaceNameIsEquiv(CFStringRef interfaceName1
, CFStringRef interfaceName2
)
932 CFStringRef interfaceArray
[] = { CFSTR("iPhone"), CFSTR("iPad"), CFSTR("iPod"), CFSTR("AppleTV") };
933 const int interfaceCount
= sizeof(interfaceArray
) / sizeof(CFStringRef
);
934 CFStringRef portSuffix
= CFSTR(", Port 1");
936 if ((isA_CFString(interfaceName1
) != NULL
) &&
937 (isA_CFString(interfaceName2
) != NULL
)) {
938 if (CFEqual(interfaceName1
, interfaceName2
) == FALSE
) {
939 // Check if we are looking at the WiFi interface
940 if ((CFEqual(interfaceName1
, CFSTR("AirPort")) ||
941 (CFEqual(interfaceName1
, CFSTR("Wi-Fi")))) &&
942 (CFEqual(interfaceName2
, CFSTR("AirPort")) ||
943 (CFEqual(interfaceName2
, CFSTR("Wi-Fi"))))) {
947 if (((CFEqual(interfaceName1
, CFSTR("Ethernet"))) ||
948 (CFEqual(interfaceName1
, CFSTR("Ethernet 1")))) &&
949 ((CFEqual(interfaceName2
, CFSTR("Ethernet"))) ||
950 (CFEqual(interfaceName2
, CFSTR("Ethernet 1"))))) {
954 if (((CFStringHasSuffix(interfaceName1
, portSuffix
) == TRUE
) &&
955 (CFStringCompareWithOptions(interfaceName1
, interfaceName2
, CFRangeMake(0, (CFStringGetLength(interfaceName1
) - CFStringGetLength(portSuffix
))), 0) == kCFCompareEqualTo
)) ||
956 ((CFStringHasSuffix(interfaceName2
, portSuffix
) == TRUE
) &&
957 (CFStringCompareWithOptions(interfaceName2
, interfaceName1
, CFRangeMake(0, (CFStringGetLength(interfaceName2
) - CFStringGetLength(portSuffix
))), 0) == kCFCompareEqualTo
))) {
961 for (CFIndex idx
= 0; idx
< interfaceCount
; idx
++) {
962 CFStringRef tempInterfaceName
= interfaceArray
[idx
];
963 if ((CFEqual(interfaceName1
, tempInterfaceName
) == TRUE
||
964 __SCNetworkInterfaceMatchesName(interfaceName1
, tempInterfaceName
) == TRUE
) &&
965 (CFEqual(interfaceName2
, tempInterfaceName
) == TRUE
||
966 __SCNetworkInterfaceMatchesName(interfaceName2
, tempInterfaceName
) == TRUE
)) {
980 CFDictionaryRef interfaceMapping
;
981 CFMutableArrayRef interfacesMissingServices
;
982 } SCNetworkConfigurationMissingServiceContext
;
985 CFDictionaryRef bsdNameToBridgeServices
; // Mapping of BSD Name to SCBridgeInterfaceRef
986 CFDictionaryRef bsdNameToBondServices
; // Mapping of BSD Name to SCBondInterfaceRef
987 CFDictionaryRef bsdNameToVLANServices
; // Mapping of BSD Name to SCVLANInterfaceRef
988 CFDictionaryRef interfaceMapping
;
990 CFMutableArrayRef interfaceToBeRemoved
; // SCNetworkInterfaceRef. Services containing the interface will be removed
991 CFMutableArrayRef interfaceToBeReplaced
;// SCNetworkInterfaceRef. Services containing the interface will be replaced with default service
993 } SCNetworkConfigurationValidityContext
;
996 _SCNetworkConfigurationValidateInterface (const void *key
, const void *value
, void *context
)
998 CFStringRef bsdName
= (CFStringRef
)key
;
999 SCNetworkConfigurationValidityContext
*ctx
= (SCNetworkConfigurationValidityContext
*)context
;
1000 CFDictionaryRef bsdNameToBridgeServices
= ctx
->bsdNameToBridgeServices
;
1001 CFDictionaryRef bsdNameToBondServices
= ctx
->bsdNameToBondServices
;
1002 CFDictionaryRef bsdNameToVLANServices
= ctx
->bsdNameToVLANServices
;
1003 SCNetworkInterfaceRef interface
= NULL
;
1004 CFDictionaryRef interfaceMapping
= ctx
->interfaceMapping
;
1005 CFStringRef interfaceUserDefinedName
= NULL
;
1006 Boolean repair
= ctx
->repair
;
1007 SCNetworkInterfaceRef serviceInterface
= (SCNetworkInterfaceRef
)value
;
1008 CFStringRef serviceInterfaceUserDefinedName
= NULL
;
1009 CFMutableArrayRef interfaceToBeRemoved
= ctx
->interfaceToBeRemoved
;
1010 CFMutableArrayRef interfaceToBeReplaced
= ctx
->interfaceToBeReplaced
;
1012 // No work needs to be done if we have already made determination that configuration somewhere is not valid,
1013 // or we don't intend to repair invalid configuration.
1014 if ((*ctx
->isValid
== FALSE
) && (repair
== FALSE
)) {
1018 // There is no interface present for the service
1019 interface
= CFDictionaryGetValue(interfaceMapping
, bsdName
);
1020 if (interface
== NULL
) {
1021 if ((((bsdNameToBridgeServices
!= NULL
) && (CFDictionaryContainsKey(bsdNameToBridgeServices
, bsdName
) == FALSE
))) &&
1022 (((bsdNameToBondServices
!= NULL
) && (CFDictionaryContainsKey(bsdNameToBondServices
, bsdName
) == FALSE
))) &&
1023 (((bsdNameToVLANServices
!= NULL
) && (CFDictionaryContainsKey(bsdNameToVLANServices
, bsdName
) == FALSE
)))) {
1024 // Not a virtual interface
1025 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationValidateInterface: There is no real interface with bsd name: %@ for service"), bsdName
);
1027 if (repair
== TRUE
) {
1028 CFArrayAppendValue(interfaceToBeRemoved
, serviceInterface
);
1030 *ctx
->isValid
= FALSE
;
1035 // TODO: Need to compare between both SCNetworkInterfaceRefs
1036 interfaceUserDefinedName
= __SCNetworkInterfaceGetUserDefinedName(interface
);
1037 serviceInterfaceUserDefinedName
= __SCNetworkInterfaceGetUserDefinedName(serviceInterface
);
1039 if (__SCNetworkConfigurationInterfaceNameIsEquiv(interfaceUserDefinedName
, serviceInterfaceUserDefinedName
) == FALSE
) {
1040 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationValidateInterface: Interface user defined name: %@ doesn't match service interface user defined name: %@"), interfaceUserDefinedName
, serviceInterfaceUserDefinedName
);
1041 *ctx
->isValid
= FALSE
;
1042 // Add service interface to the interfaceToBeReplaced list
1043 if (isA_CFArray(interfaceToBeReplaced
) != NULL
) {
1044 CFArrayAppendValue(interfaceToBeReplaced
, interface
);
1046 if (isA_CFArray(interfaceToBeRemoved
) != NULL
) {
1047 CFArrayAppendValue(interfaceToBeRemoved
, serviceInterface
);
1054 _SCNetworkConfigurationCollectMissingService(const void *key
, const void *value
, void *context
)
1056 CFStringRef bsdName
= (CFStringRef
)key
;
1057 SCNetworkConfigurationMissingServiceContext
*ctx
= (SCNetworkConfigurationMissingServiceContext
*)context
;
1058 SCNetworkInterfaceRef interface
= (SCNetworkInterfaceRef
)value
;
1059 CFMutableArrayRef interfacesMissingServices
= ctx
->interfacesMissingServices
;
1060 CFDictionaryRef serviceInterfaceMapping
= ctx
->interfaceMapping
;
1062 if ((isA_SCNetworkInterface(interface
) == NULL
) ||
1063 (_SCNetworkInterfaceIsBuiltin(interface
) == FALSE
)) {
1067 // Check if services have mapping for the BSD name of the interface
1068 if (CFDictionaryContainsKey(serviceInterfaceMapping
, bsdName
) == FALSE
) {
1069 CFArrayAppendValue(interfacesMissingServices
, interface
); // Adding interface since the corresponding service seems to be missing
1074 _SCNetworkConfigurationCreateBuiltinInterfaceServices(SCPreferencesRef pref
,
1075 SCPreferencesRef ni_pref
)
1077 SCNetworkConfigurationMissingServiceContext context
;
1078 SCNetworkInterfaceRef interface
= NULL
;
1079 CFArrayRef interfaces
= NULL
;
1080 CFMutableArrayRef interfacesWithoutService
= NULL
;
1081 CFDictionaryRef mappingBSDNameToInterface
= NULL
;
1082 CFDictionaryRef mappingServiceBSDNameToInterface
= NULL
;
1083 CFIndex missingServiceCount
= 0;
1084 Boolean success
= FALSE
;
1086 interfaces
= __SCNetworkInterfaceCopyStoredWithPreferences(ni_pref
);
1087 if (interfaces
== NULL
) {
1088 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCreateBuiltinInterfaceServices: interfaces is NULL or not of the correct type"));
1092 mappingBSDNameToInterface
= __SCNetworkInterfaceCreateMappingUsingBSDName(interfaces
);
1093 CFRelease(interfaces
);
1094 if (isA_CFDictionary(mappingBSDNameToInterface
) == NULL
) {
1098 interfaces
= __SCNetworkServiceCopyAllInterfaces(pref
);
1099 if (interfaces
== NULL
) {
1100 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCreateBuiltinInterfaceServices: interfaces is NULL for configPref or not of the correct type"));
1103 mappingServiceBSDNameToInterface
= __SCNetworkInterfaceCreateMappingUsingBSDName(interfaces
);
1104 CFRelease(interfaces
);
1105 if (isA_CFDictionary(mappingServiceBSDNameToInterface
) == NULL
) {
1109 interfacesWithoutService
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
1111 context
.interfaceMapping
= mappingServiceBSDNameToInterface
;
1112 context
.interfacesMissingServices
= interfacesWithoutService
;
1114 CFDictionaryApplyFunction(mappingBSDNameToInterface
, _SCNetworkConfigurationCollectMissingService
, &context
);
1115 missingServiceCount
= CFArrayGetCount(interfacesWithoutService
);
1119 for (CFIndex idx
= 0; idx
< missingServiceCount
; idx
++) {
1120 interface
= CFArrayGetValueAtIndex(interfacesWithoutService
, idx
);
1122 if (__SCNetworkServiceCreate(pref
, interface
, NULL
) == FALSE
) {
1123 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCreateBuiltinInterfaceServices: Could not add service for interface: %@"), interface
);
1128 if (mappingBSDNameToInterface
!= NULL
) {
1129 CFRelease(mappingBSDNameToInterface
);
1131 if (mappingServiceBSDNameToInterface
!= NULL
) {
1132 CFRelease(mappingServiceBSDNameToInterface
);
1134 if (interfacesWithoutService
!= NULL
) {
1135 CFRelease(interfacesWithoutService
);
1142 add_default_service(const void *value
, void *context
)
1144 SCNetworkSetRef currentSet
= NULL
;
1145 SCNetworkInterfaceRef interface
= (SCNetworkInterfaceRef
)value
;
1146 SCPreferencesRef prefs
= (SCPreferencesRef
)context
;
1147 SCNetworkServiceRef service
;
1149 service
= SCNetworkServiceCreate(prefs
, interface
);
1151 if (service
== NULL
) {
1152 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("add_default_service: Could not create new service"));
1156 if (SCNetworkServiceEstablishDefaultConfiguration(service
) == FALSE
) {
1157 SCNetworkServiceRemove(service
);
1158 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("add_default_service: SCNetworkServiceEstablishDefaultConfiguration failed"));
1162 // Add Service to current set
1163 currentSet
= SCNetworkSetCopyCurrent(prefs
);
1164 if (currentSet
== NULL
) {
1165 SCNetworkServiceRemove(service
);
1166 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("add_default_service: Could not find current set"));
1170 if (SCNetworkSetAddService(currentSet
, service
) == FALSE
) {
1171 SCNetworkServiceRemove(service
);
1172 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("add_default_service: Could not add service to current set"));
1176 if (service
!= NULL
) {
1179 if (currentSet
!= NULL
) {
1180 CFRelease(currentSet
);
1185 remove_service(const void *value
, void *context
)
1187 SCNetworkInterfaceRef interface
;
1188 SCNetworkServiceRef service
= (SCNetworkServiceRef
)value
;
1189 CFArrayRef toBeRemoved
= (CFArrayRef
)context
;
1191 interface
= SCNetworkServiceGetInterface(service
);
1193 if (CFArrayContainsValue(toBeRemoved
, CFRangeMake(0, CFArrayGetCount(toBeRemoved
)), interface
)) {
1194 SCNetworkServiceRemove(service
);
1199 _SCNetworkConfigurationSaveOldConfiguration(SCPreferencesRef prefs
)
1201 CFAbsoluteTime absoluteTime
;
1202 CFCalendarRef currentCalendar
;
1205 CFStringRef keyList
[] = {
1208 kSCPrefNetworkServices
,
1211 kSCPrefVirtualNetworkInterfaces
1213 CFIndex keyListCount
;
1219 currentCalendar
= CFCalendarCopyCurrent();
1220 absoluteTime
= CFAbsoluteTimeGetCurrent();
1222 if (CFCalendarDecomposeAbsoluteTime(currentCalendar
, absoluteTime
, "yMdHms",
1223 &year
, &month
, &day
, &hour
, &minute
, &second
) == FALSE
) {
1224 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationSaveOldConfiguration: Cannot decompose absolute time"));
1226 keyListCount
= (CFIndex
)sizeof(keyList
)/sizeof(CFStringRef
);
1228 for (CFIndex idx
= 0; idx
< keyListCount
; idx
++) {
1230 CFTypeRef value
= SCPreferencesGetValue(prefs
, keyList
[idx
]);
1232 if (value
!= NULL
) {
1233 newKey
= CFStringCreateWithFormat(NULL
, NULL
,
1234 CFSTR("%d-%d-%d %d:%d:%d : %@"),
1235 year
, month
, day
, hour
,
1236 minute
, second
, keyList
[idx
]);
1237 SCPreferencesSetValue(prefs
, newKey
, value
);
1241 CFRelease(currentCalendar
);
1245 _SCNetworkConfigurationRepairUsingPreferences(SCPreferencesRef prefs
,
1246 CFArrayRef interfaceToBeRemoved
,
1247 CFArrayRef interfaceToBeReplaced
)
1249 CFIndex removeCount
;
1250 CFIndex replaceCount
;
1251 CFArrayRef serviceList
;
1253 removeCount
= CFArrayGetCount(interfaceToBeRemoved
);
1254 replaceCount
= CFArrayGetCount(interfaceToBeReplaced
);
1255 if (removeCount
== 0 &&
1256 replaceCount
== 0) {
1257 // We don't have any information to repair
1260 // Backup current preferences before making changes
1261 _SCNetworkConfigurationSaveOldConfiguration(prefs
);
1263 serviceList
= SCNetworkServiceCopyAll(prefs
);
1264 CFArrayApplyFunction(serviceList
, CFRangeMake(0, CFArrayGetCount(serviceList
)), remove_service
, (void*)interfaceToBeRemoved
);
1266 CFArrayApplyFunction(interfaceToBeReplaced
, CFRangeMake(0, replaceCount
), add_default_service
, (void*)prefs
);
1267 CFRelease(serviceList
);
1272 validate_bridge(const void *value
, void *context
)
1274 SCBridgeInterfaceRef bridge
= (SCBridgeInterfaceRef
) value
;
1275 CFArrayRef memberInterfaces
= SCBridgeInterfaceGetMemberInterfaces(bridge
);
1276 CFMutableArrayRef memberInterfacesMutable
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
1277 SCPreferencesRef ni_prefs
= (SCPreferencesRef
)context
;
1279 for (CFIndex idx
= 0; idx
< CFArrayGetCount(memberInterfaces
); idx
++) {
1280 CFStringRef bsdName
;
1281 SCNetworkInterfaceRef interface
= (SCNetworkInterfaceRef
)CFArrayGetValueAtIndex(memberInterfaces
, idx
);
1282 SCNetworkInterfaceRef memberInterface
;
1284 bsdName
= SCNetworkInterfaceGetBSDName(interface
);
1285 if (bsdName
== NULL
) {
1289 // Check if member interface is present
1290 memberInterface
= __SCNetworkInterfaceCreateWithNIPreferencesUsingBSDName(NULL
, ni_prefs
, bsdName
);
1291 if (memberInterface
!= NULL
) {
1292 CFArrayAppendValue(memberInterfacesMutable
, memberInterface
);
1293 CFRelease(memberInterface
);
1297 if (CFArrayGetCount(memberInterfacesMutable
) == 0) {
1298 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("validate_bridge: Removing invalid bridge configuration: %@"), bridge
);
1299 SCBridgeInterfaceRemove(bridge
);
1302 SCBridgeInterfaceSetMemberInterfaces(bridge
, memberInterfacesMutable
);
1304 CFRelease(memberInterfacesMutable
);
1306 #if !TARGET_OS_IPHONE
1308 validate_bond(const void *value
, void *context
)
1310 SCBondInterfaceRef bond
= (SCBondInterfaceRef
)value
;
1311 CFArrayRef memberInterfaces
= SCBondInterfaceGetMemberInterfaces(bond
);
1312 CFMutableArrayRef memberInterfacesMutable
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
1313 SCPreferencesRef ni_prefs
= (SCPreferencesRef
)context
;
1315 for (CFIndex idx
= 0; idx
< CFArrayGetCount(memberInterfaces
); idx
++) {
1316 CFStringRef bsdName
;
1317 SCNetworkInterfaceRef interface
= (SCNetworkInterfaceRef
)CFArrayGetValueAtIndex(memberInterfaces
, idx
);
1318 SCNetworkInterfaceRef memberInterface
;
1320 bsdName
= SCNetworkInterfaceGetBSDName(interface
);
1321 if (bsdName
== NULL
) {
1325 // Check if member interface is present
1326 memberInterface
= __SCNetworkInterfaceCreateWithNIPreferencesUsingBSDName(NULL
, ni_prefs
, bsdName
);
1327 if (memberInterface
!= NULL
) {
1328 CFArrayAppendValue(memberInterfacesMutable
, memberInterface
);
1329 CFRelease(memberInterface
);
1333 if (CFArrayGetCount(memberInterfacesMutable
) == 0) {
1334 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("validate_bond: Removing invalid bond configuration: %@"), bond
);
1335 SCBondInterfaceRemove(bond
);
1338 SCBondInterfaceSetMemberInterfaces(bond
, memberInterfacesMutable
);
1340 CFRelease(memberInterfacesMutable
);
1345 validate_vlan(const void *value
, void *context
)
1347 CFStringRef bsdName
;
1348 SCNetworkInterfaceRef interface
;
1349 Boolean isValid
= TRUE
;
1350 SCPreferencesRef ni_prefs
= (SCPreferencesRef
)context
;
1351 SCNetworkInterfaceRef physicalInterface
;
1352 SCVLANInterfaceRef vlan
= (SCVLANInterfaceRef
)value
;
1354 physicalInterface
= SCVLANInterfaceGetPhysicalInterface(vlan
);
1355 bsdName
= SCNetworkInterfaceGetBSDName(physicalInterface
);
1357 if (bsdName
== NULL
) {
1362 // Check if the physical interface is present
1363 interface
= __SCNetworkInterfaceCreateWithNIPreferencesUsingBSDName(NULL
, ni_prefs
, bsdName
);
1364 if (interface
== NULL
) {
1368 CFRelease(interface
);
1371 if (isValid
== FALSE
) {
1372 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("validate_vlan: Removing invalid VLAN configuration: %@"), vlan
);
1373 SCVLANInterfaceRemove(vlan
);
1378 _SCNetworkConfigurationCheckValidityUsingPreferences(SCPreferencesRef prefs
,
1379 SCPreferencesRef ni_prefs
,
1380 CFDictionaryRef options
)
1382 CFArrayRef allServices
= NULL
;
1383 CFArrayRef allSets
= NULL
;
1384 CFDictionaryRef bsdNameToBridgeServices
= NULL
;
1385 CFDictionaryRef bsdNameToBondServices
= NULL
;
1386 CFDictionaryRef bsdNameToVLANServices
= NULL
;
1387 SCNetworkConfigurationValidityContext context
;
1388 CFArrayRef interfaces
= NULL
;
1389 Boolean isValid
= TRUE
;
1390 CFDictionaryRef mappingBSDNameToInterface
= NULL
;
1391 CFDictionaryRef mappingServiceBSDNameToInterface
= NULL
;
1392 Boolean repairConfiguration
= FALSE
;
1393 CFArrayRef setServiceOrder
= NULL
;
1394 CFArrayRef setServices
= NULL
;
1395 CFMutableArrayRef interfaceToBeRemoved
= NULL
;
1396 CFMutableArrayRef interfaceToBeReplaced
= NULL
;
1399 if ((isA_CFDictionary(options
) != NULL
)) {
1400 CFBooleanRef repair
= CFDictionaryGetValue(options
, kSCNetworkConfigurationRepair
);
1401 if (isA_CFBoolean(repair
) != NULL
) {
1402 repairConfiguration
= CFBooleanGetValue(repair
);
1407 Check the validity by:
1408 1) Comparing if the interfaces names mentioned in NetworkInterfaces.plist and preferences.plist match
1411 __SCNetworkInterfaceCreateMappingUsingBSDName(SCPreferencesRef prefs);
1413 interfaces
= __SCNetworkInterfaceCopyStoredWithPreferences(ni_prefs
);
1414 if (isA_CFArray(interfaces
) == NULL
) {
1416 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCheckValidityUsingPreferences: interfaces is NULL or not of the correct type"));
1419 mappingBSDNameToInterface
= __SCNetworkInterfaceCreateMappingUsingBSDName(interfaces
);
1420 CFRelease(interfaces
);
1421 if (isA_CFDictionary(mappingBSDNameToInterface
) == NULL
) {
1423 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCheckValidityUsingPreferences: mappingBSDNameToInterface is NULL"));
1427 interfaces
= __SCNetworkServiceCopyAllInterfaces(prefs
);
1428 if (isA_CFArray(interfaces
) == NULL
) {
1430 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCheckValidityUsingPreferences: interfaces is NULL for configPref or not of the correct type"));
1433 mappingServiceBSDNameToInterface
= __SCNetworkInterfaceCreateMappingUsingBSDName(interfaces
);
1434 CFRelease(interfaces
);
1435 if (isA_CFDictionary(mappingServiceBSDNameToInterface
) == NULL
) {
1437 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCheckValidityUsingPreferences: mappingServiceBSDNameToInterface is NULL"));
1441 if (repairConfiguration
) {
1442 interfaceToBeRemoved
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
1443 interfaceToBeReplaced
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
1444 #if !TARGET_OS_IPHONE
1445 bsdNameToBridgeServices
= _SCNetworkMigrationCopyMappingBSDNameToBridgeServices(prefs
);
1446 bsdNameToBondServices
= _SCNetworkMigrationCopyMappingBSDNameToBondServices(prefs
);
1447 bsdNameToVLANServices
= _SCNetworkMigrationCopyMappingBSDNameToVLANServices(prefs
);
1450 context
.interfaceMapping
= mappingBSDNameToInterface
;
1451 context
.isValid
= &isValid
;
1452 context
.interfaceToBeRemoved
= interfaceToBeRemoved
;
1453 context
.interfaceToBeReplaced
= interfaceToBeReplaced
;
1454 context
.bsdNameToBridgeServices
= bsdNameToBridgeServices
;
1455 context
.bsdNameToBondServices
= bsdNameToBondServices
;
1456 context
.bsdNameToVLANServices
= bsdNameToVLANServices
;
1457 context
.repair
= repairConfiguration
;
1459 CFDictionaryApplyFunction(mappingServiceBSDNameToInterface
, _SCNetworkConfigurationValidateInterface
, &context
);
1461 if (isValid
== FALSE
) {
1462 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCheckValidityUsingPreferences: Found mismatch between interface names in NetworkInterfaces.plist and preferences.plist"));
1463 if (repairConfiguration
) {
1464 isValid
= _SCNetworkConfigurationRepairUsingPreferences(prefs
, interfaceToBeRemoved
, interfaceToBeReplaced
);
1465 if (isValid
== FALSE
) {
1468 // Save the changes if repair fixed an invalid configuration
1469 if (SCPreferencesCommitChanges(prefs
) == FALSE
) {
1470 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("Failed to commit changes from the repaired configuration"));
1479 2) Check if all the network services mentioned in the SCNetworkSet are actually present in the SCNetworkService array
1482 allServices
= SCNetworkServiceCopyAll(prefs
);
1483 if (isA_CFArray(allServices
) == NULL
) {
1485 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCheckValidityUsingPreferences: allServices is NULL"));
1489 allSets
= SCNetworkSetCopyAll(prefs
);
1490 if (isA_CFArray(allSets
) == NULL
) {
1492 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCheckValidityUsingPreferences: allSets is NULL"));
1496 for (CFIndex idx
= 0; ((idx
< CFArrayGetCount(allSets
)) && isValid
); idx
++) {
1497 SCNetworkSetRef set
= CFArrayGetValueAtIndex(allSets
, idx
);
1499 if (isA_SCNetworkSet(set
) == NULL
) {
1500 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCheckValidityUsingPreferences: set is NULL"));
1503 setServices
= SCNetworkSetCopyServices(set
);
1504 if (setServices
== NULL
) {
1505 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCheckValidityUsingPreferences: setServices is NULL"));
1508 for (CFIndex idx2
= 0; idx2
< CFArrayGetCount(setServices
); idx2
++) {
1509 SCNetworkServiceRef service
= CFArrayGetValueAtIndex(setServices
, idx2
);
1511 if (CFArrayContainsValue(allServices
, CFRangeMake(0, CFArrayGetCount(allServices
)), service
) == FALSE
) {
1513 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCheckValidityUsingPreferences: All network services in the network set are not present in SCNetworkService array"));
1517 if (isValid
== FALSE
) {
1522 3) Check if service IDs in service order do exist in the SET
1524 setServiceOrder
= SCNetworkSetGetServiceOrder(set
);
1525 if (setServiceOrder
!= NULL
) {
1526 for (CFIndex idx2
= 0; idx2
< CFArrayGetCount(setServiceOrder
); idx2
++) {
1527 SCNetworkServiceRef service
= CFArrayGetValueAtIndex(setServiceOrder
, idx2
);
1528 if ((CFArrayContainsValue(setServiceOrder
, CFRangeMake(0, CFArrayGetCount(setServiceOrder
)), service
) == FALSE
) &&
1529 (CFArrayContainsValue(allServices
, CFRangeMake(0, CFArrayGetCount(allServices
)), service
) == FALSE
)) {
1530 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("Service: %@ is not present in the service order for set %@"), service
, set
);
1535 if (setServices
!= NULL
) {
1536 CFRelease(setServices
);
1542 4) Check if the virtual network interfaces have valid member interfaces
1544 CFArrayRef bridges
= SCBridgeInterfaceCopyAll(prefs
);
1545 if (bridges
!= NULL
) {
1546 CFArrayApplyFunction(bridges
, CFRangeMake(0, CFArrayGetCount(bridges
)), validate_bridge
, (void*)ni_prefs
);
1549 #if !TARGET_OS_IPHONE
1550 CFArrayRef bonds
= SCBondInterfaceCopyAll(prefs
);
1551 if (bonds
!= NULL
) {
1552 CFArrayApplyFunction(bonds
, CFRangeMake(0, CFArrayGetCount(bonds
)), validate_bond
, (void*)ni_prefs
);
1556 CFArrayRef vlans
= SCVLANInterfaceCopyAll(prefs
);
1557 if (vlans
!= NULL
) {
1558 CFArrayApplyFunction(vlans
, CFRangeMake(0, CFArrayGetCount(vlans
)), validate_vlan
, (void*)ni_prefs
);
1564 if (mappingBSDNameToInterface
!= NULL
) {
1565 CFRelease(mappingBSDNameToInterface
);
1567 if (mappingServiceBSDNameToInterface
!= NULL
) {
1568 CFRelease(mappingServiceBSDNameToInterface
);
1570 if (allServices
!= NULL
) {
1571 CFRelease(allServices
);
1573 if (allSets
!= NULL
) {
1576 if (bsdNameToBridgeServices
!= NULL
) {
1577 CFRelease(bsdNameToBridgeServices
);
1579 if (bsdNameToBondServices
!= NULL
) {
1580 CFRelease(bsdNameToBondServices
);
1582 if (bsdNameToVLANServices
!= NULL
) {
1583 CFRelease(bsdNameToVLANServices
);
1585 if (setServices
!= NULL
) {
1586 CFRelease(setServices
);
1588 if (interfaceToBeRemoved
!= NULL
) {
1589 CFRelease(interfaceToBeRemoved
);
1591 if (interfaceToBeReplaced
!= NULL
) {
1592 CFRelease(interfaceToBeReplaced
);
1598 _SCNetworkConfigurationCheckValidity(CFURLRef configDir
, CFDictionaryRef options
)
1600 CFURLRef baseURL
= NULL
;
1601 CFURLRef configNetworkInterfaceFile
= NULL
;
1602 CFStringRef configNetworkInterfaceFileString
= NULL
;
1603 SCPreferencesRef configNetworkInterfacePref
= NULL
;
1604 SCPreferencesRef configPref
= NULL
;
1605 CFURLRef configPreferenceFile
= NULL
;
1606 CFStringRef configPreferencesFileString
= NULL
;
1607 CFArrayRef configurationFiles
= NULL
;
1608 Boolean isValid
= FALSE
;
1609 char networkInterfaceStr
[PATH_MAX
];
1610 char prefsStr
[PATH_MAX
];
1612 if (configDir
== NULL
) {
1613 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCheckValidity: Migration files not found in directory: %@"), ((configDir
== NULL
) ? CFSTR("NULL") : CFURLGetString(configDir
)));
1616 baseURL
= CFURLCreateWithFileSystemPathRelativeToBase(NULL
, PREFS_DEFAULT_DIR_RELATIVE
,
1617 kCFURLPOSIXPathStyle
, TRUE
, configDir
);
1619 configPreferenceFile
= CFURLCreateFromFileSystemRepresentationRelativeToBase(NULL
, (const UInt8
*)PREFS_DEFAULT_CONFIG_PLIST
, sizeof(PREFS_DEFAULT_CONFIG_PLIST
), FALSE
, baseURL
);
1620 configNetworkInterfaceFile
= CFURLCreateFromFileSystemRepresentationRelativeToBase(NULL
, (const UInt8
*)NETWORK_INTERFACES_PREFS_PLIST
, sizeof(NETWORK_INTERFACES_PREFS_PLIST
), FALSE
, baseURL
);
1622 if (CFURLGetFileSystemRepresentation(configPreferenceFile
, TRUE
, (UInt8
*)prefsStr
, sizeof(prefsStr
)) == FALSE
) {
1623 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCheckValidity: Could not extract preferences information"));
1626 if (CFURLGetFileSystemRepresentation(configNetworkInterfaceFile
, TRUE
, (UInt8
*)networkInterfaceStr
, sizeof(networkInterfaceStr
)) == FALSE
) {
1627 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCheckValidity: Could not extract network interface information"));
1631 configPreferencesFileString
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%s"), prefsStr
);
1632 configNetworkInterfaceFileString
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%s"), networkInterfaceStr
);
1634 configPref
= SCPreferencesCreate(NULL
,
1636 configPreferencesFileString
);
1638 configNetworkInterfacePref
= SCPreferencesCreate(NULL
,
1640 configNetworkInterfaceFileString
);
1641 if ((configPref
== NULL
) || (configNetworkInterfacePref
== NULL
)) {
1645 // This function compares preferences.plist and NetworkInterfaces.plist and verifies if the values are correct
1646 // Checking interface mismatch for validity
1647 isValid
= _SCNetworkConfigurationCheckValidityUsingPreferences(configPref
, configNetworkInterfacePref
, options
);
1650 if (baseURL
!= NULL
) {
1653 if (configurationFiles
!= NULL
) {
1654 CFRelease(configurationFiles
);
1656 if (configPreferencesFileString
!= NULL
) {
1657 CFRelease(configPreferencesFileString
);
1659 if (configNetworkInterfaceFileString
!= NULL
) {
1660 CFRelease(configNetworkInterfaceFileString
);
1662 if (configPref
!= NULL
) {
1663 CFRelease(configPref
);
1665 if (configNetworkInterfacePref
!= NULL
) {
1666 CFRelease(configNetworkInterfacePref
);
1668 if (configPreferenceFile
!= NULL
) {
1669 CFRelease(configPreferenceFile
);
1671 if (configNetworkInterfaceFile
!= NULL
) {
1672 CFRelease(configNetworkInterfaceFile
);
1679 CFMutableArrayRef externalInterfaceList
;
1680 CFMutableArrayRef networkInterfaceList
;
1681 } SCExternalMappingContext
;
1684 _SCNetworkConfigurationCollectInterfaceStorageEntity(const void *key
, const void *value
, void *context
)
1686 SCExternalMappingContext
* ctx
= context
;
1687 CFDictionaryRef interface_entity
= NULL
;
1688 SCNetworkInterfaceRef targetInterface
= (SCNetworkInterfaceRef
)value
;
1690 if (CFArrayContainsValue(ctx
->externalInterfaceList
, CFRangeMake(0, CFArrayGetCount(ctx
->externalInterfaceList
)), targetInterface
) == TRUE
) {
1691 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationCollectInterfaceStorageEntity: Target Interface %@ already exists, thus do no add it to NetworkInterfaces.plist"), targetInterface
);
1692 return; // If the target interface already exists then do not add it to NetworkInterfaces.plist
1694 interface_entity
= __SCNetworkInterfaceCopyStorageEntity(targetInterface
);
1696 if (interface_entity
!= NULL
) {
1697 CFArrayAppendValue(ctx
->networkInterfaceList
, interface_entity
);
1698 CFRelease(interface_entity
);
1702 static CFArrayRef
// CFDictionaryRef
1703 _SCNetworkMigrationCreateNetworkInterfaceArray(SCPreferencesRef ni_prefs
, CFDictionaryRef externalMapping
)
1705 SCExternalMappingContext context
;
1707 CFMutableArrayRef externalInterfaceList
= NULL
;
1708 CFArrayRef if_list
= NULL
;
1709 CFDictionaryRef interface_entity
= NULL
;
1710 CFMutableArrayRef networkInterfaceList
= NULL
;
1712 if (ni_prefs
== NULL
) {
1713 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateNetworkInterfaceArray: ni_prefs are NULL"));
1717 if_list
= SCPreferencesGetValue(ni_prefs
, INTERFACES
);
1719 if ((isA_CFArray(if_list
) == NULL
) ||
1720 ((count
= CFArrayGetCount(if_list
)) == 0)) {
1721 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateNetworkInterfaceArray: if_list is NULL or interface count is 0"));
1725 networkInterfaceList
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
1727 // Keep the same builtin and external interfaces
1728 for (CFIndex idx
= 0; idx
< count
; idx
++) {
1729 interface_entity
= CFArrayGetValueAtIndex(if_list
, idx
);
1730 if (isA_CFDictionary(interface_entity
) == NULL
) {
1733 CFArrayAppendValue(networkInterfaceList
, interface_entity
);
1736 if (isA_CFDictionary(externalMapping
) == NULL
) {
1737 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateNetworkInterfaceArray: externalMapping is NULL or not of the correct type"));
1740 // Add any new external interfaces found
1741 externalInterfaceList
= _SCNetworkInterfaceCopyInterfacesFilteredByBuiltinWithPreferences(ni_prefs
, FALSE
);
1742 context
.externalInterfaceList
= externalInterfaceList
;
1743 context
.networkInterfaceList
= networkInterfaceList
;
1745 CFDictionaryApplyFunction(externalMapping
, _SCNetworkConfigurationCollectInterfaceStorageEntity
, &context
);
1748 if (externalInterfaceList
!= NULL
) {
1749 CFRelease(externalInterfaceList
);
1751 return networkInterfaceList
;
1755 SCNetworkMigrationMapSourceToTargetName(const void *key
, const void *value
, void *context
)
1757 SCNetworkInterfaceRef interfaceKey
= (SCNetworkInterfaceRef
)key
;
1758 SCNetworkInterfaceRef interfaceValue
= (SCNetworkInterfaceRef
)value
;
1759 CFMutableDictionaryRef mapping
= (CFMutableDictionaryRef
)context
;
1760 CFStringRef sourceBSDName
= NULL
;
1761 CFStringRef targetBSDName
= NULL
;
1763 sourceBSDName
= SCNetworkInterfaceGetBSDName(interfaceKey
);
1764 if (isA_CFString(sourceBSDName
) == NULL
) {
1768 targetBSDName
= SCNetworkInterfaceGetBSDName(interfaceValue
);
1769 if (isA_CFString(targetBSDName
) == NULL
) {
1773 if (CFDictionaryContainsKey(mapping
, sourceBSDName
) == FALSE
) {
1774 CFDictionaryAddValue(mapping
, sourceBSDName
, targetBSDName
);
1779 static CFDictionaryRef
1780 _SCNetworkMigrationCreateBSDNameMapping(CFDictionaryRef internalMapping
, CFDictionaryRef externalMapping
)
1782 CFMutableDictionaryRef bsdNameMapping
= CFDictionaryCreateMutable(NULL
, 0,
1783 &kCFTypeDictionaryKeyCallBacks
,
1784 &kCFTypeDictionaryValueCallBacks
);
1786 if ((internalMapping
== NULL
) && externalMapping
== NULL
) {
1790 if (internalMapping
!= NULL
) {
1791 CFDictionaryApplyFunction(internalMapping
, SCNetworkMigrationMapSourceToTargetName
, bsdNameMapping
);
1794 if (externalMapping
!= NULL
) {
1795 CFDictionaryApplyFunction(externalMapping
, SCNetworkMigrationMapSourceToTargetName
, bsdNameMapping
);
1799 return bsdNameMapping
;
1803 CFMutableArrayRef mutableServiceArray
;
1804 SCPreferencesRef prefs
;
1805 } SCNetworkServiceArrayCopyContext
;
1807 static CFDictionaryRef
1808 _SCNetworkMigrationCreateServiceSetMapping(SCPreferencesRef prefs
)
1810 CFMutableDictionaryRef serviceSetMapping
= CFDictionaryCreateMutable(NULL
, 0,
1811 &kCFTypeDictionaryKeyCallBacks
,
1812 &kCFTypeDictionaryValueCallBacks
);
1813 SCNetworkServiceRef service
= NULL
;
1814 CFArrayRef services
= NULL
;
1815 CFMutableArrayRef setList
= NULL
;
1816 CFArrayRef sets
= NULL
;
1818 services
= SCNetworkServiceCopyAll(prefs
);
1819 if (services
== NULL
) {
1822 for (CFIndex idx
= 0; idx
< CFArrayGetCount(services
); idx
++) {
1823 service
= CFArrayGetValueAtIndex(services
, idx
);
1825 if (CFDictionaryContainsKey(serviceSetMapping
, service
) == FALSE
) {
1826 setList
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
1827 CFDictionaryAddValue(serviceSetMapping
, service
, setList
);
1831 CFRelease(services
);
1833 sets
= SCNetworkSetCopyAll(prefs
);
1838 for (CFIndex idx
= 0; idx
< CFArrayGetCount(sets
); idx
++) {
1839 SCNetworkSetRef set
= CFArrayGetValueAtIndex(sets
, idx
);
1840 services
= SCNetworkSetCopyServices(set
);
1842 for (CFIndex idx2
= 0; idx2
< CFArrayGetCount(services
); idx2
++) {
1843 service
= CFArrayGetValueAtIndex(services
, idx2
);
1844 setList
= (CFMutableArrayRef
)CFDictionaryGetValue(serviceSetMapping
, service
);
1845 if (setList
!= NULL
) {
1846 CFArrayAppendValue(setList
, set
);
1849 CFRelease(services
);
1856 return serviceSetMapping
;
1859 static CFDictionaryRef
1860 _SCNetworkMigrationCreateSetMapping(SCPreferencesRef sourcePrefs
,
1861 SCPreferencesRef targetPrefs
)
1863 SCNetworkSetRef currentSourceSet
= NULL
;
1864 CFMutableDictionaryRef setMapping
= NULL
;
1865 CFStringRef setName
;
1866 CFArrayRef sourceSets
= NULL
;
1867 CFArrayRef targetSets
= NULL
;
1868 CFMutableArrayRef targetSetsMutable
= NULL
;
1870 sourceSets
= SCNetworkSetCopyAll(sourcePrefs
);
1871 targetSets
= SCNetworkSetCopyAll(targetPrefs
);
1873 if (sourceSets
== NULL
||
1874 targetSets
== NULL
) {
1877 targetSetsMutable
= CFArrayCreateMutableCopy(NULL
, 0, targetSets
);
1879 setMapping
= CFDictionaryCreateMutable(NULL
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
1881 currentSourceSet
= SCNetworkSetCopyCurrent(sourcePrefs
);
1883 for (CFIndex idx
= 0; idx
< CFArrayGetCount(sourceSets
); idx
++) {
1884 SCNetworkSetRef sourceSet
= CFArrayGetValueAtIndex(sourceSets
, idx
);
1885 CFIndex targetCount
= CFArrayGetCount(targetSetsMutable
);
1886 SCNetworkSetRef targetSet
;
1888 setName
= SCNetworkSetGetName(sourceSet
);
1889 if (targetCount
> 0) {
1890 targetSet
= CFArrayGetValueAtIndex(targetSetsMutable
, 0);
1891 CFRetain(targetSet
);
1892 CFArrayRemoveValueAtIndex(targetSetsMutable
, 0);
1895 targetSet
= SCNetworkSetCreate(targetPrefs
);
1898 SCNetworkSetSetName(targetSet
, setName
);
1899 CFDictionaryAddValue(setMapping
, sourceSet
, targetSet
);
1901 if (CFEqual(sourceSet
, currentSourceSet
) == TRUE
) {
1902 SCNetworkSetSetCurrent(targetSet
);
1904 CFRelease(targetSet
);
1908 if (sourceSets
!= NULL
) {
1909 CFRelease(sourceSets
);
1911 if (targetSets
!= NULL
) {
1912 CFRelease(targetSets
);
1914 if (targetSetsMutable
!= NULL
) {
1915 CFRelease(targetSetsMutable
);
1917 if (currentSourceSet
!= NULL
) {
1918 CFRelease(currentSourceSet
);
1923 // This function finds the mapping between source and target preferences (SCNetworkServicesRef -> SCNetworkServicesRef)
1924 // If there is no mapping found between source and target preferences, then the CFBooleanRef value indicating no value is found is stored (SCNetworkServicesRef -> kCFBooleanFalse)
1925 static CFDictionaryRef
1926 _SCNetworkMigrationCreateServiceMappingUsingBSDMapping(SCPreferencesRef sourcePrefs
,
1927 SCPreferencesRef targetPrefs
,
1928 CFDictionaryRef bsdNameMapping
)
1930 CFStringRef bsdNameMapTarget
= NULL
;
1931 CFMutableDictionaryRef serviceMapping
= NULL
; // Mapping of services between source and target configurations
1932 CFStringRef sourceBSDName
= NULL
;
1933 CFIndex sourceCount
= 0;
1934 SCNetworkInterfaceRef sourceInterface
= NULL
;
1935 CFStringRef sourceInterfaceSubType
= NULL
; // Check interface type and subtype to be able to transfer VPN
1936 CFStringRef sourceInterfaceType
= NULL
;
1937 CFArrayRef sourceSCNetworkServices
= NULL
;
1938 CFMutableArrayRef sourceSCNetworkServicesMutable
= NULL
; // Source SCNetworkServiceRef mutable array
1939 SCNetworkServiceRef sourceService
= NULL
;
1940 CFStringRef targetBSDName
= NULL
;
1941 CFIndex targetCount
= 0; // Count of Source and Target Services
1942 SCNetworkInterfaceRef targetInterface
= NULL
;
1943 CFStringRef targetInterfaceSubType
= NULL
; // services during migration
1944 CFStringRef targetInterfaceType
= NULL
;
1945 CFArrayRef targetSCNetworkServices
= NULL
;
1946 CFMutableArrayRef targetSCNetworkServicesMutable
= NULL
; // Target SCNetworkServiceRef mutable array
1947 SCNetworkServiceRef targetService
= NULL
;
1949 // We need BSD Mapping to successfully create service mapping
1950 if (bsdNameMapping
== NULL
) {
1951 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateServiceMappingUsingBSDMapping: BSD Name Mapping is NULL"));
1954 sourceSCNetworkServices
= SCNetworkServiceCopyAll(sourcePrefs
);
1955 if (isA_CFArray(sourceSCNetworkServices
) == NULL
) {
1956 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateServiceMappingUsingBSDMapping: sourceSCNetworkServices is NULL or not of the correct CFType"));
1959 targetSCNetworkServices
= SCNetworkServiceCopyAll(targetPrefs
);
1960 if (isA_CFArray(targetSCNetworkServices
) == NULL
) {
1961 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateServiceMappingUsingBSDMapping: targetSCNetworkServices is NULL or not of the correct CFType"));
1965 sourceCount
= CFArrayGetCount(sourceSCNetworkServices
);
1967 sourceSCNetworkServicesMutable
= CFArrayCreateMutableCopy(NULL
, 0, sourceSCNetworkServices
);
1968 targetSCNetworkServicesMutable
= CFArrayCreateMutableCopy(NULL
, 0, targetSCNetworkServices
);
1970 serviceMapping
= CFDictionaryCreateMutable(NULL
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
1972 for (CFIndex idx
= 0; idx
< sourceCount
; idx
++) {
1973 sourceBSDName
= NULL
;
1974 sourceService
= NULL
;
1975 sourceInterface
= NULL
;
1976 sourceInterfaceType
= NULL
;
1977 sourceInterfaceSubType
= NULL
;
1978 bsdNameMapTarget
= NULL
;
1980 targetCount
= CFArrayGetCount(targetSCNetworkServicesMutable
);
1981 sourceService
= (SCNetworkServiceRef
) CFArrayGetValueAtIndex(sourceSCNetworkServicesMutable
, idx
);
1983 sourceInterface
= SCNetworkServiceGetInterface(sourceService
);
1985 if (sourceInterface
== NULL
) {
1986 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateServiceMappingUsingBSDMapping: sourceInterface is NULL or not of the correct type"));
1990 sourceInterfaceType
= __SCNetworkInterfaceGetEntityType(sourceInterface
);
1991 if ((isA_CFString(sourceInterfaceType
) != NULL
) &&
1992 ((CFEqual(sourceInterfaceType
, kSCValNetInterfaceTypeVPN
) == TRUE
) ||
1993 (CFEqual(sourceInterfaceType
, kSCValNetInterfaceTypePPP
) == TRUE
))) {
1994 sourceInterfaceSubType
= __SCNetworkInterfaceGetEntitySubType(sourceInterface
);
1995 if (isA_CFString(sourceInterfaceSubType
) == NULL
) {
1996 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateServiceMappingUsingBSDMapping: sourceInterfaceSubType is NULL or not of the correct type"));
2000 else if (((isA_CFString(sourceInterfaceType
) != NULL
) &&
2001 (CFEqual(sourceInterfaceType
, kSCValNetInterfaceTypeIPSec
) == FALSE
) &&
2002 (CFEqual(sourceInterfaceType
, kSCValNetInterfaceType6to4
) == FALSE
) &&
2003 (CFEqual(sourceInterfaceType
, kSCValNetInterfaceTypeLoopback
) == FALSE
)) ||
2004 (isA_CFString(sourceInterfaceType
) == NULL
)) {
2005 sourceBSDName
= SCNetworkInterfaceGetBSDName(sourceInterface
);
2006 if ((isA_CFString(sourceBSDName
) == NULL
) ||
2007 (CFDictionaryContainsKey(bsdNameMapping
, sourceBSDName
)) == FALSE
) {
2008 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateServiceMappingUsingBSDMapping: bsdNameMapping doesn't contain sourceBSDName: %@"), (sourceBSDName
== NULL
) ? CFSTR("NULL") : sourceBSDName
);
2012 bsdNameMapTarget
= CFDictionaryGetValue(bsdNameMapping
, sourceBSDName
);
2013 if (isA_CFString(bsdNameMapTarget
) == NULL
) {
2014 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateServiceMappingUsingBSDMapping: bsdNameMapTarget is NULL or not of the correct CFType"));
2018 // Find the bsd name in target service
2019 for (CFIndex idx2
= 0; idx2
< targetCount
; idx2
++) {
2020 targetService
= NULL
;
2021 targetInterface
= NULL
;
2022 targetBSDName
= NULL
;
2023 targetInterfaceType
= NULL
;
2024 targetInterfaceSubType
= NULL
;
2026 targetService
= (SCNetworkServiceRef
) CFArrayGetValueAtIndex(targetSCNetworkServicesMutable
, idx2
);
2028 targetInterface
= SCNetworkServiceGetInterface(targetService
);
2029 if (targetInterface
== NULL
) {
2030 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateServiceMappingUsingBSDMapping: targetInterface is NULL or not of the correct type"));
2033 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("targetInterface: %@"), targetInterface
);
2034 if (sourceBSDName
!= NULL
) {
2035 targetBSDName
= SCNetworkInterfaceGetBSDName(targetInterface
);
2036 if (isA_CFString(targetBSDName
) == NULL
) {
2037 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateServiceMappingUsingBSDMapping: targetBSDName is NULL or not of the correct type"));
2041 if (CFEqual(targetBSDName
, bsdNameMapTarget
) == TRUE
) {
2042 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateServiceMappingUsingBSDMapping: Removing target BSD Name: %@"), targetBSDName
);
2043 CFDictionaryAddValue(serviceMapping
, sourceService
, targetService
);
2044 CFArrayRemoveValueAtIndex(targetSCNetworkServicesMutable
, idx2
);
2049 // Source Interface Type should be VPN
2050 targetInterfaceType
= __SCNetworkInterfaceGetEntityType(targetInterface
);
2051 if ((isA_CFString(targetInterfaceType
) == NULL
) ||
2052 ((CFEqual(targetInterfaceType
, kSCValNetInterfaceTypeVPN
) == FALSE
) &&
2053 (CFEqual(targetInterfaceType
, kSCValNetInterfaceTypePPP
) == FALSE
))) {
2054 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateServiceMappingUsingBSDMapping: targetInterfaceType is NULL or not of the correct type : %@"), (targetInterfaceType
!= NULL
) ? targetInterfaceType
: CFSTR("NULL"));
2057 targetInterfaceSubType
= __SCNetworkInterfaceGetEntitySubType(targetInterface
);
2058 if (isA_CFString(targetInterfaceSubType
) == NULL
) {
2059 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateServiceMappingUsingBSDMapping: targetInterfaceSubType is NULL or not of the correct type: %@"), (targetInterfaceSubType
!= NULL
) ? targetInterfaceSubType
: CFSTR("NULL"));
2063 // Check if the target interface type and the target interface sub type match
2064 if ((CFEqual(targetInterfaceType
, sourceInterfaceType
) == TRUE
) &&
2065 (CFEqual(targetInterfaceSubType
, sourceInterfaceSubType
) == TRUE
)) {
2066 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateServiceMappingUsingBSDMapping: Removing target BSD Name: %@ for VPN"), targetBSDName
);
2067 CFDictionaryAddValue(serviceMapping
, sourceService
, targetService
);
2068 CFArrayRemoveValueAtIndex(targetSCNetworkServicesMutable
, idx2
);
2073 // Check if sourceService has found a mapping or not, if not the create a NULL mapping to indicate
2074 // the this service needs to be added and not replaced
2075 if (CFDictionaryContainsKey(serviceMapping
, sourceService
) == FALSE
) {
2076 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationCreateServiceMappingUsingBSDMapping: Service needs to be added: %@"), sourceService
);
2077 CFDictionaryAddValue(serviceMapping
, sourceService
, kCFBooleanFalse
);
2081 if (sourceSCNetworkServices
!= NULL
) {
2082 CFRelease(sourceSCNetworkServices
);
2084 if (targetSCNetworkServices
!= NULL
) {
2085 CFRelease(targetSCNetworkServices
);
2087 if (sourceSCNetworkServicesMutable
!= NULL
) {
2088 CFRelease(sourceSCNetworkServicesMutable
);
2090 if (targetSCNetworkServicesMutable
!= NULL
) {
2091 CFRelease(targetSCNetworkServicesMutable
);
2093 return serviceMapping
;
2097 SCPreferencesRef targetPrefs
;
2098 CFDictionaryRef bsdMapping
;
2099 CFDictionaryRef setMapping
;
2100 CFDictionaryRef serviceSetMapping
;
2101 } ServiceMigrationContext
;
2104 // SCNetworkServiceRef: if target service needs replacement
2105 // CFBooleanRef: if target service is not present
2107 ServiceMigrationAddOrReplace(const void *key
, const void *value
, void *context
)
2109 CFDictionaryRef bsdMapping
= NULL
;
2110 ServiceMigrationContext
*ctx
= (ServiceMigrationContext
*)context
;
2111 CFDictionaryRef setMapping
;
2112 CFDictionaryRef sourceServiceSetMapping
;
2113 SCNetworkServiceRef sourceService
= (SCNetworkServiceRef
)key
;
2114 SCPreferencesRef targetPrefs
= NULL
;
2115 SCNetworkServiceRef targetService
= (SCNetworkServiceRef
)value
;
2117 targetPrefs
= ctx
->targetPrefs
;
2118 bsdMapping
= ctx
->bsdMapping
;
2119 setMapping
= ctx
->setMapping
;
2120 sourceServiceSetMapping
= ctx
->serviceSetMapping
;
2122 if (isA_SCNetworkService(targetService
) != NULL
) {
2123 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("ServiceMigrationAddOrReplace: Removing target service: %@"), targetService
);
2124 SCNetworkServiceRemove(targetService
);
2126 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("ServiceMigrationAddOrReplace: Adding service with %@"), sourceService
);
2127 if (__SCNetworkServiceMigrateNew(targetPrefs
, sourceService
, bsdMapping
, setMapping
, sourceServiceSetMapping
) == FALSE
) {
2128 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("Could not Add Service: %@"), sourceService
);
2133 _SCNetworkMigrationDoServiceMigration(SCPreferencesRef sourcePrefs
, SCPreferencesRef targetPrefs
,
2134 CFDictionaryRef serviceMapping
, CFDictionaryRef bsdMapping
,
2135 CFDictionaryRef setMapping
, CFDictionaryRef serviceSetMapping
)
2137 ServiceMigrationContext context
;
2138 Boolean success
= FALSE
;
2140 if ((sourcePrefs
== NULL
) ||
2141 (targetPrefs
== NULL
) ||
2142 (isA_CFDictionary(serviceMapping
) == NULL
) ||
2143 (isA_CFDictionary(bsdMapping
) == NULL
)) {
2144 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationDoServiceMigration: targetPrefs or serviceMapping or bsdMapping is NULL"));
2147 context
.targetPrefs
= targetPrefs
;
2148 context
.bsdMapping
= bsdMapping
;
2149 context
.setMapping
= setMapping
;
2150 context
.serviceSetMapping
= serviceSetMapping
;
2152 CFDictionaryApplyFunction(serviceMapping
, ServiceMigrationAddOrReplace
, &context
);
2160 _SCNetworkMigrationDoSystemMigration(SCPreferencesRef sourcePrefs
, SCPreferencesRef targetPrefs
)
2162 CFStringEncoding nameEncoding
;
2163 CFStringRef computerName
;
2164 CFStringRef hostname
;
2165 CFStringRef localHostname
;
2166 CFDictionaryRef btmm
= NULL
;
2167 CFDictionaryRef btmmDSID
= NULL
;
2168 CFStringRef btmmDSIDPath
;
2169 CFStringRef btmmPath
;
2172 if ((sourcePrefs
== NULL
) ||
2173 (targetPrefs
== NULL
)) {
2177 hostname
= SCPreferencesGetHostName(sourcePrefs
);
2178 if (hostname
!= NULL
) {
2179 SCPreferencesSetHostName(targetPrefs
, hostname
);
2182 localHostname
= _SCPreferencesCopyLocalHostName(sourcePrefs
);
2183 if (localHostname
!= NULL
) {
2184 SCPreferencesSetLocalHostName(targetPrefs
, localHostname
);
2185 CFRelease(localHostname
);
2188 computerName
= _SCPreferencesCopyComputerName(sourcePrefs
, &nameEncoding
);
2190 if (computerName
!= NULL
) {
2191 SCPreferencesSetComputerName(targetPrefs
, computerName
, nameEncoding
);
2192 CFRelease(computerName
);
2195 btmmPath
= CFStringCreateWithFormat(NULL
, NULL
,
2200 btmm
= SCPreferencesPathGetValue(sourcePrefs
, btmmPath
);
2203 SCPreferencesPathSetValue(targetPrefs
, btmmPath
, btmm
);
2205 CFRelease(btmmPath
);
2207 btmmDSIDPath
= CFStringCreateWithFormat(NULL
, NULL
,
2211 BACK_TO_MY_MAC_DSIDS
);
2213 btmmDSID
= SCPreferencesPathGetValue(sourcePrefs
, btmmDSIDPath
);
2214 if (btmmDSID
!= NULL
) {
2215 SCPreferencesPathSetValue(targetPrefs
, btmmDSIDPath
, btmmDSID
);
2217 CFRelease(btmmDSIDPath
);
2221 #if !TARGET_OS_IPHONE
2224 CFMutableArrayRef interfaceList
;
2225 SCPreferencesRef ni_prefs
;
2226 CFDictionaryRef bsdMapping
;
2227 } SCVirtualInterfaceMemberListContext
;
2230 SCPreferencesRef prefs
;
2231 SCPreferencesRef ni_prefs
;
2232 CFDictionaryRef bsdMapping
;
2233 CFDictionaryRef virtualBSDMapping
;
2234 CFDictionaryRef mappingBSDNameToService
;
2235 CFDictionaryRef setMapping
;
2236 CFDictionaryRef serviceSetMapping
;
2237 } SCVirtualInterfaceContext
;
2240 add_virtual_interface(const void *value
, void *context
)
2242 SCVirtualInterfaceMemberListContext
*ctx
= (SCVirtualInterfaceMemberListContext
*)context
;
2243 CFMutableArrayRef interfaceList
= ctx
->interfaceList
;
2244 CFDictionaryRef bsdMapping
= ctx
->bsdMapping
;
2245 CFStringRef oldInterfaceBSDName
= (CFStringRef
)value
;
2246 SCNetworkInterfaceRef newInterface
;
2247 CFStringRef newInterfaceBSDName
;
2249 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("old interface BSD name is %@"), oldInterfaceBSDName
);
2250 newInterfaceBSDName
= CFDictionaryGetValue(bsdMapping
, oldInterfaceBSDName
);
2251 if (newInterfaceBSDName
== NULL
) {
2255 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("new interface BSD name is %@"), newInterfaceBSDName
);
2256 newInterface
= __SCNetworkInterfaceCreateWithNIPreferencesUsingBSDName(NULL
, ctx
->ni_prefs
, newInterfaceBSDName
);
2258 if (newInterface
!= NULL
) {
2259 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("Adding interface to interfaceList: %@"), newInterface
);
2260 CFArrayAppendValue(interfaceList
, newInterface
);
2261 CFRelease(newInterface
);
2267 add_target_bridge(const void *key
, const void *value
, void *context
)
2269 CFStringRef bridgeName
;
2270 CFDictionaryRef bridgeOptions
;
2271 SCVirtualInterfaceContext
*ctx
= (SCVirtualInterfaceContext
*)context
;
2272 CFDictionaryRef bridgeBSDNameMapping
= ctx
->virtualBSDMapping
;
2273 CFDictionaryRef bsdNameToServiceMapping
= ctx
->mappingBSDNameToService
;
2274 SCVirtualInterfaceMemberListContext memberListContext
;
2275 CFMutableArrayRef newInterfaceList
;
2276 SCBridgeInterfaceRef newBridge
;
2277 SCBridgeInterfaceRef oldBridge
= (SCBridgeInterfaceRef
)key
;
2278 CFStringRef oldBSDName
;
2279 CFArrayRef oldInterfaceList
= (CFArrayRef
)value
;
2280 CFArrayRef oldServiceList
;
2281 SCPreferencesRef prefs
= ctx
->prefs
;
2282 CFDictionaryRef serviceSetMapping
= ctx
->serviceSetMapping
;
2283 CFDictionaryRef setMapping
= ctx
->setMapping
;
2285 newInterfaceList
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
2287 memberListContext
.bsdMapping
= ctx
->bsdMapping
;
2288 memberListContext
.interfaceList
= newInterfaceList
;
2289 memberListContext
.ni_prefs
= ctx
->ni_prefs
;
2291 CFArrayApplyFunction(oldInterfaceList
, CFRangeMake(0, CFArrayGetCount(oldInterfaceList
)), add_virtual_interface
, &memberListContext
);
2293 newBridge
= SCBridgeInterfaceCreate(prefs
);
2295 if (__SCBridgeInterfaceSetMemberInterfaces(newBridge
, newInterfaceList
) == FALSE
) {
2296 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("add_target_bridge: Adding Member Interfaces failed"));
2298 CFRelease(newInterfaceList
);
2300 bridgeOptions
= SCBridgeInterfaceGetOptions(oldBridge
);
2301 if (bridgeOptions
!= NULL
) {
2302 SCBridgeInterfaceSetOptions(newBridge
, bridgeOptions
);
2305 bridgeName
= SCNetworkInterfaceGetLocalizedDisplayName(oldBridge
);
2307 if (bridgeName
!= NULL
) {
2308 SCBridgeInterfaceSetLocalizedDisplayName(newBridge
, bridgeName
);
2311 oldBSDName
= SCNetworkInterfaceGetBSDName(oldBridge
);
2312 if (oldBSDName
== NULL
) {
2316 oldServiceList
= CFDictionaryGetValue(bsdNameToServiceMapping
, oldBSDName
);
2317 if (oldServiceList
== NULL
) {
2321 for (CFIndex idx
= 0; idx
< CFArrayGetCount(oldServiceList
); idx
++) {
2322 SCNetworkServiceRef oldService
= CFArrayGetValueAtIndex(oldServiceList
, idx
);
2323 if (__SCNetworkServiceMigrateNew(prefs
, oldService
, bridgeBSDNameMapping
, setMapping
, serviceSetMapping
) == FALSE
) {
2324 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("add_target_bridge: Could not migrate service: %@"), oldService
);
2328 CFRelease(newBridge
);
2332 _SCNetworkMigrationRemoveBridgeServices(SCPreferencesRef prefs
)
2334 CFArrayRef services
= SCNetworkServiceCopyAll(prefs
);
2336 for (CFIndex idx
= 0; idx
< CFArrayGetCount(services
); idx
++) {
2337 SCNetworkServiceRef service
= CFArrayGetValueAtIndex(services
, idx
);
2338 SCNetworkInterfaceRef interface
= SCNetworkServiceGetInterface(service
);
2339 CFStringRef bsdName
= SCNetworkInterfaceGetBSDName(interface
);
2341 if ((bsdName
!= NULL
) &&
2342 SCNetworkInterfaceGetInterfaceType(interface
) == kSCNetworkInterfaceTypeBridge
) {
2343 SCLog(TRUE
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationRemoveBridgeServices: Removing services: %@"), service
);
2344 SCNetworkServiceRemove(service
);
2347 CFRelease(services
);
2351 static CFDictionaryRef
2352 _SCNetworkMigrationCopyMappingBSDNameToBridgeServices(SCPreferencesRef prefs
)
2354 CFArrayRef services
= SCNetworkServiceCopyAll(prefs
);
2355 CFMutableDictionaryRef bridgeServices
= CFDictionaryCreateMutable(NULL
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
2357 for (CFIndex idx
= 0; idx
< CFArrayGetCount(services
); idx
++) {
2358 SCNetworkServiceRef service
= CFArrayGetValueAtIndex(services
, idx
);
2359 SCNetworkInterfaceRef interface
= SCNetworkServiceGetInterface(service
);
2360 CFStringRef bsdName
= SCNetworkInterfaceGetBSDName(interface
);
2362 if ((bsdName
!= NULL
) &&
2363 SCNetworkInterfaceGetInterfaceType(interface
) == kSCNetworkInterfaceTypeBridge
) {
2364 CFMutableArrayRef serviceList
;
2365 if (CFDictionaryContainsKey(bridgeServices
, bsdName
) == FALSE
) {
2366 serviceList
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
2367 CFDictionaryAddValue(bridgeServices
, bsdName
, serviceList
);
2368 CFRelease(serviceList
);
2370 serviceList
= (CFMutableArrayRef
)CFDictionaryGetValue(bridgeServices
, bsdName
);
2371 CFArrayAppendValue(serviceList
, service
);
2374 CFRelease(services
);
2375 return bridgeServices
;
2380 _SCNetworkMigrationDoBridgeMigration (SCPreferencesRef sourcePrefs
,
2381 SCPreferencesRef sourceNIPrefs
,
2382 SCPreferencesRef targetPrefs
,
2383 SCPreferencesRef targetNIPrefs
,
2384 CFDictionaryRef bsdMapping
,
2385 CFDictionaryRef setMapping
,
2386 CFDictionaryRef serviceSetMapping
)
2388 CFArrayRef allSourceBridges
;
2389 CFArrayRef allTargetBridges
;
2390 SCBridgeInterfaceRef bridge
;
2391 CFMutableDictionaryRef bridgeInterfaceMapping
= NULL
;
2392 CFMutableDictionaryRef bridgeMapping
;
2393 CFDictionaryRef bsdNameToBridgeServices
;
2394 SCVirtualInterfaceContext context
;
2396 Boolean success
= FALSE
;
2398 allSourceBridges
= SCBridgeInterfaceCopyAll(sourcePrefs
);
2399 allTargetBridges
= SCBridgeInterfaceCopyAll(targetPrefs
);
2401 bsdNameToBridgeServices
= _SCNetworkMigrationCopyMappingBSDNameToBridgeServices(sourcePrefs
);
2403 bridgeInterfaceMapping
= CFDictionaryCreateMutable(NULL
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
2404 bridgeMapping
= CFDictionaryCreateMutable(NULL
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
2406 // Create Bridge Interface Mapping
2407 for (CFIndex idx
= 0; idx
< CFArrayGetCount(allSourceBridges
); idx
++) {
2408 bridge
= CFArrayGetValueAtIndex(allSourceBridges
, idx
);
2409 CFArrayRef bridgeMembers
= SCBridgeInterfaceGetMemberInterfaces(bridge
);
2410 CFMutableArrayRef interfaceList
;
2412 interfaceList
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
2413 for (CFIndex idx2
= 0; idx2
< CFArrayGetCount(bridgeMembers
); idx2
++) {
2414 CFStringRef interfaceName
= NULL
;
2415 SCNetworkInterfaceRef interface
= NULL
;
2417 interface
= CFArrayGetValueAtIndex(bridgeMembers
, idx2
);
2418 interfaceName
= SCNetworkInterfaceGetBSDName(interface
);
2420 if (CFDictionaryContainsKey(bsdMapping
, interfaceName
) == TRUE
) {
2421 CFStringRef bridgeNewName
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("bridge%ld"), count
);
2422 CFDictionaryAddValue(bridgeMapping
, interfaceName
, bridgeNewName
);
2423 CFArrayAppendValue(interfaceList
, interfaceName
);
2424 CFRelease(bridgeNewName
);
2428 if (CFArrayGetCount(interfaceList
) > 0) {
2429 CFDictionaryAddValue(bridgeInterfaceMapping
, bridge
, interfaceList
);
2431 CFRelease(interfaceList
);
2433 // Remove bridge services from target
2434 _SCNetworkMigrationRemoveBridgeServices(targetPrefs
);
2436 // Remove Target Bridges
2437 for (CFIndex idx
= 0; idx
< CFArrayGetCount(allTargetBridges
); idx
++) {
2438 bridge
= CFArrayGetValueAtIndex(allTargetBridges
, idx
);
2439 if (SCBridgeInterfaceRemove(bridge
) == FALSE
) {
2440 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationDoBridgeMigration: Could not remove bridge: %@"), bridge
);
2445 context
.prefs
= targetPrefs
;
2446 context
.ni_prefs
= targetNIPrefs
;
2447 context
.bsdMapping
= bsdMapping
;
2448 context
.virtualBSDMapping
= bridgeMapping
;
2449 context
.mappingBSDNameToService
= bsdNameToBridgeServices
;
2450 context
.setMapping
= setMapping
;
2451 context
.serviceSetMapping
= serviceSetMapping
;
2453 // Add Bridge configurations at the target using mapping
2454 CFDictionaryApplyFunction(bridgeInterfaceMapping
, add_target_bridge
, &context
);
2458 CFRelease(allSourceBridges
);
2459 CFRelease(allTargetBridges
);
2460 CFRelease(bridgeInterfaceMapping
);
2461 CFRelease(bridgeMapping
);
2462 CFRelease(bsdNameToBridgeServices
);
2468 add_target_bond(const void *key
, const void *value
, void *context
)
2470 CFNumberRef bondMode
;
2471 CFStringRef bondName
;
2472 CFDictionaryRef bondOptions
;
2473 SCVirtualInterfaceContext
*ctx
= (SCVirtualInterfaceContext
*)context
;
2474 CFDictionaryRef bondBSDNameMapping
= ctx
->virtualBSDMapping
;
2475 CFDictionaryRef bsdNameToServiceMapping
= ctx
->mappingBSDNameToService
;
2476 SCVirtualInterfaceMemberListContext memberListContext
;
2477 CFMutableArrayRef newInterfaceList
;
2478 SCBondInterfaceRef newBond
;
2479 SCBondInterfaceRef oldBond
= (SCBondInterfaceRef
)key
;
2480 CFStringRef oldBSDName
;
2481 CFArrayRef oldInterfaceList
= (CFArrayRef
)value
;
2482 CFArrayRef oldServiceList
;
2483 SCPreferencesRef prefs
= ctx
->prefs
;
2484 CFDictionaryRef serviceSetMapping
= ctx
->serviceSetMapping
;
2485 CFDictionaryRef setMapping
= ctx
->setMapping
;
2487 newInterfaceList
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
2489 memberListContext
.bsdMapping
= ctx
->bsdMapping
;
2490 memberListContext
.interfaceList
= newInterfaceList
;
2491 memberListContext
.ni_prefs
= ctx
->ni_prefs
;
2493 CFArrayApplyFunction(oldInterfaceList
, CFRangeMake(0, CFArrayGetCount(oldInterfaceList
)), add_virtual_interface
, &memberListContext
);
2495 newBond
= SCBondInterfaceCreate(prefs
);
2496 if (__SCBondInterfaceSetMemberInterfaces(newBond
, newInterfaceList
) == FALSE
) {
2497 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("add_target_bond: Adding member interface failed."));
2499 CFRelease(newInterfaceList
);
2501 bondOptions
= SCBondInterfaceGetOptions(oldBond
);
2502 if (bondOptions
!= NULL
) {
2503 SCBondInterfaceSetOptions(newBond
, bondOptions
);
2506 bondName
= SCNetworkInterfaceGetLocalizedDisplayName(oldBond
);
2507 if (bondName
!= NULL
) {
2508 SCBondInterfaceSetLocalizedDisplayName(newBond
, bondName
);
2511 bondMode
= SCBondInterfaceGetMode(oldBond
);
2512 if (bondMode
!= NULL
) {
2513 SCBondInterfaceSetMode(newBond
, bondMode
);
2515 oldBSDName
= SCNetworkInterfaceGetBSDName(oldBond
);
2516 if (oldBSDName
== NULL
) {
2520 oldServiceList
= CFDictionaryGetValue(bsdNameToServiceMapping
, oldBSDName
);
2521 if (oldServiceList
== NULL
) {
2525 for (CFIndex idx
= 0; idx
< CFArrayGetCount(oldServiceList
); idx
++) {
2526 SCNetworkServiceRef oldService
= CFArrayGetValueAtIndex(oldServiceList
, idx
);
2527 if (__SCNetworkServiceMigrateNew(prefs
, oldService
, bondBSDNameMapping
, setMapping
, serviceSetMapping
) == FALSE
) {
2528 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("add_target_bond: Could not migrate service: %@"), oldService
);
2536 _SCNetworkMigrationRemoveBondServices(SCPreferencesRef prefs
)
2538 CFArrayRef services
= SCNetworkServiceCopyAll(prefs
);
2540 for (CFIndex idx
= 0; idx
< CFArrayGetCount(services
); idx
++) {
2541 SCNetworkServiceRef service
= CFArrayGetValueAtIndex(services
, idx
);
2542 SCNetworkInterfaceRef interface
= SCNetworkServiceGetInterface(service
);
2543 CFStringRef bsdName
= SCNetworkInterfaceGetBSDName(interface
);
2545 if ((bsdName
!= NULL
) &&
2546 SCNetworkInterfaceGetInterfaceType(interface
) == kSCNetworkInterfaceTypeBond
) {
2547 SCNetworkServiceRemove(service
);
2550 CFRelease(services
);
2554 static CFDictionaryRef
2555 _SCNetworkMigrationCopyMappingBSDNameToBondServices(SCPreferencesRef prefs
)
2557 CFArrayRef services
= SCNetworkServiceCopyAll(prefs
);
2558 CFMutableDictionaryRef bondServices
= CFDictionaryCreateMutable(NULL
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
2560 for (CFIndex idx
= 0; idx
< CFArrayGetCount(services
); idx
++) {
2561 SCNetworkServiceRef service
= CFArrayGetValueAtIndex(services
, idx
);
2562 SCNetworkInterfaceRef interface
= SCNetworkServiceGetInterface(service
);
2563 CFStringRef bsdName
= SCNetworkInterfaceGetBSDName(interface
);
2565 if ((bsdName
!= NULL
) &&
2566 SCNetworkInterfaceGetInterfaceType(interface
) == kSCNetworkInterfaceTypeBond
) {
2567 CFMutableArrayRef serviceList
;
2568 if (CFDictionaryContainsKey(bondServices
, bsdName
) == FALSE
) {
2569 serviceList
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
2570 CFDictionaryAddValue(bondServices
, bsdName
, serviceList
);
2571 CFRelease(serviceList
);
2573 serviceList
= (CFMutableArrayRef
)CFDictionaryGetValue(bondServices
, bsdName
);
2574 CFArrayAppendValue(serviceList
, service
);
2577 CFRelease(services
);
2578 return bondServices
;
2583 _SCNetworkMigrationDoBondMigration (SCPreferencesRef sourcePrefs
,
2584 SCPreferencesRef sourceNIPrefs
,
2585 SCPreferencesRef targetPrefs
,
2586 SCPreferencesRef targetNIPrefs
,
2587 CFDictionaryRef bsdMapping
,
2588 CFDictionaryRef setMapping
,
2589 CFDictionaryRef serviceSetMapping
)
2591 CFArrayRef allSourceBonds
;
2592 CFArrayRef allTargetBonds
;
2593 SCBondInterfaceRef bond
;
2594 CFMutableDictionaryRef bondInterfaceMapping
= NULL
;
2595 CFMutableDictionaryRef bondMapping
;
2596 CFDictionaryRef bsdNameToBondServices
;
2597 SCVirtualInterfaceContext context
;
2599 Boolean success
= FALSE
;
2601 allSourceBonds
= SCBondInterfaceCopyAll(sourcePrefs
);
2602 allTargetBonds
= SCBondInterfaceCopyAll(targetPrefs
);
2604 bsdNameToBondServices
= _SCNetworkMigrationCopyMappingBSDNameToBondServices(sourcePrefs
);
2606 bondInterfaceMapping
= CFDictionaryCreateMutable(NULL
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
2607 bondMapping
= CFDictionaryCreateMutable(NULL
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
2608 // Create Bond Interface mapping
2609 for (CFIndex idx
= 0; idx
< CFArrayGetCount(allSourceBonds
); idx
++) {
2610 bond
= CFArrayGetValueAtIndex(allSourceBonds
, idx
);
2611 CFArrayRef bondMembers
= SCBondInterfaceGetMemberInterfaces(bond
);
2612 CFMutableArrayRef interfaceList
;
2614 interfaceList
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
2615 for (CFIndex idx2
= 0; idx2
< CFArrayGetCount(bondMembers
); idx2
++) {
2616 CFStringRef interfaceName
;
2617 SCNetworkInterfaceRef interface
;
2619 interface
= CFArrayGetValueAtIndex(bondMembers
, idx2
);
2620 interfaceName
= SCNetworkInterfaceGetBSDName(interface
);
2622 if (CFDictionaryContainsKey(bsdMapping
, interfaceName
) == TRUE
) {
2623 CFStringRef bondNewName
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("bond%ld"), count
);
2624 CFDictionaryAddValue(bondMapping
, interfaceName
, bondNewName
);
2625 CFArrayAppendValue(interfaceList
, interfaceName
);
2626 CFRelease(bondNewName
);
2630 if (CFArrayGetCount(interfaceList
) > 0) {
2631 CFDictionaryAddValue(bondInterfaceMapping
, bond
, interfaceList
);
2633 CFRelease(interfaceList
);
2635 // Remove bond services from target
2636 _SCNetworkMigrationRemoveBondServices(targetPrefs
);
2638 // Remove Target Bonds
2639 for (CFIndex idx
= 0; idx
< CFArrayGetCount(allTargetBonds
); idx
++) {
2640 bond
= CFArrayGetValueAtIndex(allTargetBonds
, idx
);
2641 if (SCBondInterfaceRemove(bond
) == FALSE
) {
2642 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationDoBondMigration: Could not remove bond: %@"), bond
);
2647 context
.prefs
= targetPrefs
;
2648 context
.ni_prefs
= targetNIPrefs
;
2649 context
.bsdMapping
= bsdMapping
;
2650 context
.virtualBSDMapping
= bondMapping
;
2651 context
.mappingBSDNameToService
= bsdNameToBondServices
;
2652 context
.setMapping
= setMapping
;
2653 context
.serviceSetMapping
= serviceSetMapping
;
2655 // Add Bond configurations at the target using mapping
2656 CFDictionaryApplyFunction(bondInterfaceMapping
, add_target_bond
, &context
);
2660 CFRelease(allSourceBonds
);
2661 CFRelease(allTargetBonds
);
2662 CFRelease(bondInterfaceMapping
);
2663 CFRelease(bondMapping
);
2664 CFRelease(bsdNameToBondServices
);
2669 add_target_vlan(const void *value
, void *context
)
2671 CFDictionaryRef bsdMapping
;
2672 SCVirtualInterfaceContext
*ctx
= (SCVirtualInterfaceContext
*)context
;
2673 CFDictionaryRef bsdNameToServiceMapping
= ctx
->mappingBSDNameToService
;
2674 SCPreferencesRef prefs
= ctx
->prefs
;
2675 SCVLANInterfaceRef newVLAN
= NULL
;
2676 SCNetworkInterfaceRef newPhysicalInterface
= NULL
;
2677 CFStringRef newPhysicalInterfaceName
;
2678 SCVLANInterfaceRef oldVLAN
= (SCVLANInterfaceRef
)value
;
2679 CFStringRef oldBSDName
;
2680 SCNetworkInterfaceRef oldPhysicalInterface
;
2681 CFStringRef oldPhysicalInterfaceName
;
2682 SCNetworkServiceRef oldService
;
2683 CFArrayRef oldServiceList
;
2684 CFDictionaryRef serviceSetMapping
= ctx
->serviceSetMapping
;
2685 CFDictionaryRef setMapping
= ctx
->setMapping
;
2686 CFDictionaryRef vlanBSDMapping
= ctx
->virtualBSDMapping
;
2687 CFNumberRef vlanTag
;
2688 CFStringRef vlanName
;
2689 CFDictionaryRef vlanOptions
;
2691 bsdMapping
= ctx
->bsdMapping
;
2692 oldPhysicalInterface
= SCVLANInterfaceGetPhysicalInterface(oldVLAN
);
2694 if (oldPhysicalInterface
== NULL
) {
2695 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("add_target_vlan: oldPhysicalInterface is NULL"));
2698 oldPhysicalInterfaceName
= SCNetworkInterfaceGetBSDName(oldPhysicalInterface
);
2700 if (oldPhysicalInterfaceName
== NULL
) {
2701 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("add_target_vlan: oldPhysicalInterfaceName is NULL"));
2705 newPhysicalInterfaceName
= CFDictionaryGetValue(bsdMapping
, oldPhysicalInterfaceName
);
2706 if (newPhysicalInterfaceName
== NULL
) {
2707 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("add_target_vlan: newPhysicalInterfaceName is NULL"));
2710 newPhysicalInterface
= __SCNetworkInterfaceCreateWithNIPreferencesUsingBSDName(NULL
, ctx
->ni_prefs
, newPhysicalInterfaceName
);
2711 if (newPhysicalInterface
== NULL
) {
2712 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("add_target_vlan: newPhysicalInterface is NULL"));
2716 vlanTag
= SCVLANInterfaceGetTag(oldVLAN
);
2717 if (vlanTag
== NULL
) {
2718 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("add_target_vlan: vlanTag is NULL"));
2722 newVLAN
= SCVLANInterfaceCreate(prefs
, newPhysicalInterface
, vlanTag
);
2723 if (newVLAN
== NULL
) {
2724 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("add_target_vlan: Could not create newVLAN"));
2727 vlanName
= SCNetworkInterfaceGetLocalizedDisplayName(oldVLAN
);
2728 if (vlanName
!= NULL
) {
2729 SCVLANInterfaceSetLocalizedDisplayName(newVLAN
, vlanName
);
2732 vlanOptions
= SCVLANInterfaceGetOptions(oldVLAN
);
2733 if (vlanOptions
!= NULL
) {
2734 SCVLANInterfaceSetOptions(newVLAN
, vlanOptions
);
2736 oldBSDName
= SCNetworkInterfaceGetBSDName(oldVLAN
);
2738 if (oldBSDName
== NULL
) {
2742 oldServiceList
= CFDictionaryGetValue(bsdNameToServiceMapping
, oldBSDName
);
2743 if (oldServiceList
== NULL
) {
2747 for (CFIndex idx
= 0; idx
< CFArrayGetCount(oldServiceList
); idx
++) {
2748 oldService
= CFArrayGetValueAtIndex(oldServiceList
, idx
);
2749 if (__SCNetworkServiceMigrateNew(prefs
, oldService
, vlanBSDMapping
, setMapping
, serviceSetMapping
) == FALSE
) {
2750 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("add_target_vlan: Could not migrate service: %@"), oldService
);
2755 if (newPhysicalInterface
!= NULL
) {
2756 CFRelease(newPhysicalInterface
);
2758 if (newVLAN
!= NULL
) {
2764 _SCNetworkMigrationRemoveVLANServices(SCPreferencesRef prefs
)
2766 CFArrayRef services
= SCNetworkServiceCopyAll(prefs
);
2768 for (CFIndex idx
= 0; idx
< CFArrayGetCount(services
); idx
++) {
2769 SCNetworkServiceRef service
= CFArrayGetValueAtIndex(services
, idx
);
2770 SCNetworkInterfaceRef interface
= SCNetworkServiceGetInterface(service
);
2771 CFStringRef bsdName
= SCNetworkInterfaceGetBSDName(interface
);
2773 if ((bsdName
!= NULL
) &&
2774 SCNetworkInterfaceGetInterfaceType(interface
) == kSCNetworkInterfaceTypeVLAN
) {
2775 SCNetworkServiceRemove(service
);
2779 CFRelease(services
);
2783 static CFDictionaryRef
2784 _SCNetworkMigrationCopyMappingBSDNameToVLANServices(SCPreferencesRef prefs
)
2786 CFArrayRef services
= SCNetworkServiceCopyAll(prefs
);
2787 CFMutableDictionaryRef vlanServices
= CFDictionaryCreateMutable(NULL
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
2789 for (CFIndex idx
= 0; idx
< CFArrayGetCount(services
); idx
++) {
2790 SCNetworkServiceRef service
= CFArrayGetValueAtIndex(services
, idx
);
2791 SCNetworkInterfaceRef interface
= SCNetworkServiceGetInterface(service
);
2792 CFStringRef bsdName
= SCNetworkInterfaceGetBSDName(interface
);
2794 if ((bsdName
!= NULL
) &&
2795 SCNetworkInterfaceGetInterfaceType(interface
) == kSCNetworkInterfaceTypeVLAN
) {
2796 CFMutableArrayRef serviceList
;
2797 if (CFDictionaryContainsKey(vlanServices
, bsdName
) == FALSE
) {
2798 serviceList
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
2799 CFDictionaryAddValue(vlanServices
, bsdName
, serviceList
);
2800 CFRelease(serviceList
);
2802 serviceList
= (CFMutableArrayRef
)CFDictionaryGetValue(vlanServices
, bsdName
);
2803 CFArrayAppendValue(serviceList
, service
);
2806 CFRelease(services
);
2807 return vlanServices
;
2811 _SCNetworkMigrationDoVLANMigration (SCPreferencesRef sourcePrefs
,
2812 SCPreferencesRef sourceNIPrefs
,
2813 SCPreferencesRef targetPrefs
,
2814 SCPreferencesRef targetNIPrefs
,
2815 CFDictionaryRef bsdMapping
,
2816 CFDictionaryRef setMapping
,
2817 CFDictionaryRef serviceSetMapping
)
2819 CFArrayRef allSourceVLAN
;
2820 CFArrayRef allTargetVLAN
;
2821 SCVirtualInterfaceContext context
;
2823 Boolean success
= FALSE
;
2824 SCVLANInterfaceRef vlan
;
2825 CFMutableArrayRef vlanList
;
2826 CFMutableDictionaryRef vlanMapping
;
2827 CFDictionaryRef bsdNameToVLANServices
;
2829 allSourceVLAN
= SCVLANInterfaceCopyAll(sourcePrefs
);
2830 allTargetVLAN
= SCVLANInterfaceCopyAll(targetPrefs
);
2832 bsdNameToVLANServices
= _SCNetworkMigrationCopyMappingBSDNameToVLANServices(sourcePrefs
);
2834 vlanList
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
2835 vlanMapping
= CFDictionaryCreateMutable(NULL
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
2837 for (CFIndex idx
= 0; idx
< CFArrayGetCount(allSourceVLAN
); idx
++) {
2838 vlan
= CFArrayGetValueAtIndex(allSourceVLAN
, idx
);
2839 CFStringRef vlanBSDName
= SCNetworkInterfaceGetBSDName(vlan
);
2840 SCNetworkInterfaceRef physicalInterface
= SCVLANInterfaceGetPhysicalInterface(vlan
);
2841 CFStringRef physicalInterfaceName
;
2843 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationDoVLANMigration: physical interface is %@"), physicalInterface
);
2845 physicalInterfaceName
= SCNetworkInterfaceGetBSDName(physicalInterface
);
2846 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationDoVLANMigration: Physical Interface name is %@"), physicalInterfaceName
);
2848 // Add VLAN to be migrated if the mapping between interfaces exists
2849 if (CFDictionaryContainsKey(bsdMapping
, physicalInterfaceName
) == TRUE
) {
2850 CFStringRef vlanNewName
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("vlan%ld"), count
);
2851 CFDictionaryAddValue(vlanMapping
, vlanBSDName
, vlanNewName
);
2852 CFArrayAppendValue(vlanList
, vlan
);
2853 CFRelease(vlanNewName
);
2857 // Remove vlan services from target
2858 _SCNetworkMigrationRemoveVLANServices(targetPrefs
);
2860 // Remove Target VLANs
2861 for (CFIndex idx
= 0; idx
< CFArrayGetCount(allTargetVLAN
); idx
++) {
2862 vlan
= CFArrayGetValueAtIndex(allTargetVLAN
, idx
);
2863 if (SCVLANInterfaceRemove(vlan
) == FALSE
) {
2864 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationDoVLANMigration: Could not remove VLAN: %@"), vlan
);
2869 context
.prefs
= targetPrefs
;
2870 context
.ni_prefs
= targetNIPrefs
;
2871 context
.bsdMapping
= bsdMapping
;
2872 context
.virtualBSDMapping
= vlanMapping
;
2873 context
.mappingBSDNameToService
= bsdNameToVLANServices
;
2874 context
.setMapping
= setMapping
;
2875 context
.serviceSetMapping
= serviceSetMapping
;
2877 // Add VLAN configurations at the target using vlanList
2878 CFArrayApplyFunction(vlanList
, CFRangeMake(0, CFArrayGetCount(vlanList
)), add_target_vlan
, &context
);
2882 CFRelease(allSourceVLAN
);
2883 CFRelease(allTargetVLAN
);
2884 CFRelease(vlanList
);
2885 CFRelease(vlanMapping
);
2886 CFRelease(bsdNameToVLANServices
);
2891 _SCNetworkMigrationDoVirtualNetworkInterfaceMigration(SCPreferencesRef sourcePrefs
,
2892 SCPreferencesRef sourceNIPrefs
,
2893 SCPreferencesRef targetPrefs
,
2894 SCPreferencesRef targetNIPrefs
,
2895 CFDictionaryRef bsdMapping
,
2896 CFDictionaryRef setMapping
,
2897 CFDictionaryRef serviceSetMapping
)
2900 if (_SCNetworkMigrationDoBridgeMigration(sourcePrefs
, sourceNIPrefs
,
2901 targetPrefs
, targetNIPrefs
,
2902 bsdMapping
, setMapping
, serviceSetMapping
) == FALSE
) {
2903 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationDoVirtualNetworkInterfaceMigration: Bridge migration failed"));
2907 if (_SCNetworkMigrationDoBondMigration(sourcePrefs
, sourceNIPrefs
,
2908 targetPrefs
, targetNIPrefs
,
2909 bsdMapping
, setMapping
, serviceSetMapping
) == FALSE
) {
2910 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationDoVirtualNetworkInterfaceMigration: Bond migration failed"));
2914 if (_SCNetworkMigrationDoVLANMigration(sourcePrefs
, sourceNIPrefs
,
2915 targetPrefs
, targetNIPrefs
,
2916 bsdMapping
, setMapping
, serviceSetMapping
) == FALSE
) {
2917 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationDoVirtualNetworkInterfaceMigration: VLAN migration failed"));
2924 SCPreferencesRef prefs
;
2925 CFArrayRef serviceOrder
;
2926 CFMutableArrayRef serviceListMutable
;
2928 } migrated_service_context
;
2931 create_migrated_order(const void *value
, void *context
)
2933 migrated_service_context
*ctx
= (migrated_service_context
*)context
;
2934 CFMutableArrayRef migratedServiceOrder
= ctx
->serviceListMutable
;
2935 CFArrayRef targetServiceOrder
= ctx
->serviceOrder
;
2936 CFStringRef migratedServiceID
= (CFStringRef
)value
;
2937 Boolean
*success
= ctx
->success
;
2939 if (*success
== FALSE
) {
2942 // Preserving the service order in the source configuration for the services
2943 // which were migrated into the target configuration
2944 for (CFIndex idx
= 0; idx
< CFArrayGetCount(targetServiceOrder
); idx
++) {
2945 CFStringRef targetServiceID
= CFArrayGetValueAtIndex(targetServiceOrder
, idx
);
2946 if (CFEqual(migratedServiceID
, targetServiceID
) == TRUE
) {
2947 CFArrayAppendValue(migratedServiceOrder
, migratedServiceID
);
2954 create_non_migrated_service_list(const void *value
, void *context
)
2956 migrated_service_context
*ctx
= (migrated_service_context
*)context
;
2957 CFArrayRef migratedServiceOrder
= ctx
->serviceOrder
;
2958 CFMutableArrayRef nonMigratedService
= ctx
->serviceListMutable
;
2959 SCPreferencesRef prefs
= ctx
->prefs
;
2960 SCNetworkServiceRef service
;
2961 Boolean
*success
= ctx
->success
;
2962 CFStringRef targetServiceID
= (CFStringRef
)value
;
2964 if (*success
== FALSE
) {
2967 // Adding all services not present in migratedServiceOrder into nonMigrated service
2968 for (CFIndex idx
= 0; idx
< CFArrayGetCount(migratedServiceOrder
); idx
++) {
2969 CFStringRef migratedServiceID
= CFArrayGetValueAtIndex(migratedServiceOrder
, idx
);
2971 if (CFEqual(targetServiceID
, migratedServiceID
) == TRUE
) {
2975 service
= SCNetworkServiceCopy(prefs
, targetServiceID
);
2976 if (service
== NULL
) {
2981 CFArrayAppendValue(nonMigratedService
, service
);
2986 preserve_service_order(const void *key
, const void *value
, void *context
)
2988 migrated_service_context migrated_context
;
2989 CFMutableArrayRef migratedServiceOrder
;
2990 migrated_service_context non_migrated_context
;
2991 CFMutableArrayRef nonMigratedServices
;
2992 SCNetworkSetRef sourceSet
= (SCNetworkSetRef
)key
;
2993 CFArrayRef sourceServiceOrder
= NULL
;
2994 Boolean
*success
= (Boolean
*)context
;
2995 SCNetworkSetRef targetSet
= (SCNetworkSetRef
)value
;
2996 SCNetworkSetPrivateRef targetPrivate
= (SCNetworkSetPrivateRef
)targetSet
;
2997 CFArrayRef targetServiceOrder
= NULL
;
2999 if (*success
== FALSE
) {
3002 migratedServiceOrder
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
3003 nonMigratedServices
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
3005 sourceServiceOrder
= SCNetworkSetGetServiceOrder(sourceSet
);
3006 if (sourceServiceOrder
== NULL
) {
3009 targetServiceOrder
= SCNetworkSetGetServiceOrder(targetSet
);
3010 if (targetServiceOrder
== NULL
) {
3014 migrated_context
.prefs
= NULL
;
3015 migrated_context
.serviceOrder
= targetServiceOrder
;
3016 migrated_context
.serviceListMutable
= migratedServiceOrder
;
3017 migrated_context
.success
= success
;
3019 // Creating a list of service IDs which were migrated in the target set
3020 // while maintaining the service order or the source set
3021 CFArrayApplyFunction(sourceServiceOrder
, CFRangeMake(0, CFArrayGetCount(sourceServiceOrder
)), create_migrated_order
, &migrated_context
);
3023 if (success
== FALSE
) {
3027 non_migrated_context
.prefs
= targetPrivate
->prefs
;
3028 non_migrated_context
.serviceOrder
= migratedServiceOrder
;
3029 non_migrated_context
.serviceListMutable
= nonMigratedServices
;
3030 non_migrated_context
.success
= success
;
3032 // Creating a list of all the services which were not migrated from the source set to the
3034 CFArrayApplyFunction(targetServiceOrder
, CFRangeMake(0, CFArrayGetCount(targetServiceOrder
)), create_non_migrated_service_list
, &non_migrated_context
);
3036 // Remove non migrated service
3037 for (CFIndex idx
= 0; idx
< CFArrayGetCount(nonMigratedServices
); idx
++) {
3038 SCNetworkServiceRef service
= CFArrayGetValueAtIndex(nonMigratedServices
, idx
);
3039 SCNetworkSetRemoveService(targetSet
, service
);
3041 // Set migrated service order
3042 SCNetworkSetSetServiceOrder(targetSet
, migratedServiceOrder
);
3044 // Add non migrated services
3045 for (CFIndex idx
= 0; idx
< CFArrayGetCount(nonMigratedServices
); idx
++) {
3046 SCNetworkServiceRef service
= CFArrayGetValueAtIndex(nonMigratedServices
, idx
);
3047 SCNetworkSetAddService(targetSet
, service
);
3051 CFRelease(migratedServiceOrder
);
3052 CFRelease(nonMigratedServices
);
3058 _SCNetworkMigrationDoServiceOrderMigration(SCPreferencesRef sourcePrefs
,
3059 SCPreferencesRef targetPrefs
,
3060 CFDictionaryRef setMapping
)
3062 Boolean success
= TRUE
;
3064 if (isA_CFDictionary(setMapping
) == NULL
) {
3069 CFDictionaryApplyFunction(setMapping
, preserve_service_order
, &success
);
3075 // This is a function that looks at source and target network configuration
3076 // and determines what network configurations can be transferred from source to
3079 _SCNetworkConfigurationMigrateConfiguration(CFURLRef sourceDir
, CFURLRef targetDir
)
3081 CFDictionaryRef bsdNameMapping
= NULL
; // Mapping between BSD name and SCNetworkInterfaceRef to help with mapping services
3082 CFMutableDictionaryRef builtinMapping
= NULL
; // Mapping between builtin interfaces between source and target configurations: (SCNetworkInterfaceRef -> SCNetworkInterfaceRef)
3083 CFMutableDictionaryRef externalMapping
= NULL
; // Mapping between external interfaces between source and target configurations: (SCNetworkInterfaceRef -> SCNetworkInterfaceRef)
3084 Boolean migrationSuccess
= FALSE
;
3085 CFArrayRef newTargetNetworkInterfaceEntity
= NULL
; // Array of Interface Entity which used to create new target interfaces created during migration
3086 CFDictionaryRef serviceMapping
= NULL
; // Mapping between services of source to target. (SCNetworkServicesRef -> SCNetworkServicesRef)
3087 CFDictionaryRef setMapping
= NULL
;
3088 CFDictionaryRef sourceServiceSetMapping
= NULL
;
3089 CFArrayRef sourceConfigurationFiles
= NULL
; // Path to the source configuration files which need to be migrated
3090 CFURLRef sourceNetworkInterfaceFile
= NULL
; // Source CFURLRef for preferences.plist and NetworkInterfaces.plist
3091 char sourceNetworkInterfaceFileStr
[PATH_MAX
];
3092 CFStringRef sourceNetworkInterfaceFileString
= NULL
; // Source CFStringRef for preferences.plist and NetworkInterfaces.plist
3093 SCPreferencesRef sourceNetworkInterfacePrefs
= NULL
; // Source SCPreferencesRef for preferences.plist and NetworkInterfaces.plist
3094 CFURLRef sourcePreferencesFile
= NULL
;
3095 char sourcePreferencesFileStr
[PATH_MAX
];
3096 CFStringRef sourcePreferencesFileString
= NULL
;
3097 SCPreferencesRef sourcePrefs
= NULL
;
3098 CFArrayRef targetConfigurationFiles
= NULL
; // Path to the target configuration files where migration will take place to
3099 Boolean targetConfigurationFilesPresent
;
3100 CFURLRef targetNetworkInterfaceFile
= NULL
; // Target CFURLRef for preferences.plist and NetworkInterfaces.plist
3101 char targetNetworkInterfaceFileStr
[PATH_MAX
];
3102 CFStringRef targetNetworkInterfaceFileString
= NULL
; // Target CFStringRef for preferences.plist and NetworkInterfaces.plist
3103 SCPreferencesRef targetNetworkInterfacePrefs
= NULL
; // Target SCPreferencesRef for preferences.plist and NetworkInterfaces.plist
3104 CFURLRef targetPreferencesFile
= NULL
;
3105 char targetPreferencesFileStr
[PATH_MAX
];
3106 CFStringRef targetPreferencesFileString
= NULL
;
3107 SCPreferencesRef targetPrefs
= NULL
;
3108 CFMutableDictionaryRef validityOptions
= NULL
;
3110 // Check if configuration files exist in sourceDir
3111 if (__SCNetworkConfigurationMigrateConfigurationFilesPresent(sourceDir
, &sourceConfigurationFiles
) == FALSE
) {
3112 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: sourceDir: (%@) doesn't contain configuration files"), sourceDir
);
3116 sourcePreferencesFile
= CFArrayGetValueAtIndex(sourceConfigurationFiles
, PREFERENCES_PLIST_INDEX
);
3117 if (CFURLGetFileSystemRepresentation(sourcePreferencesFile
, TRUE
, (UInt8
*)sourcePreferencesFileStr
, sizeof(sourcePreferencesFileStr
)) == FALSE
) {
3118 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: Cannot get file system representation for url: %@"), sourcePreferencesFile
);
3122 sourceNetworkInterfaceFile
= CFArrayGetValueAtIndex(sourceConfigurationFiles
, NETWORK_INTERFACES_PLIST_INDEX
);
3123 if (CFURLGetFileSystemRepresentation(sourceNetworkInterfaceFile
, TRUE
, (UInt8
*)sourceNetworkInterfaceFileStr
, sizeof(sourceNetworkInterfaceFileStr
)) == FALSE
) {
3124 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: Cannot get file system representation for url: %@"), sourceNetworkInterfaceFile
);
3128 sourcePreferencesFileString
= CFStringCreateWithCString(NULL
, sourcePreferencesFileStr
, kCFStringEncodingUTF8
);
3129 sourceNetworkInterfaceFileString
= CFStringCreateWithCString(NULL
, sourceNetworkInterfaceFileStr
, kCFStringEncodingUTF8
);
3131 sourcePrefs
= SCPreferencesCreate(NULL
, PLUGIN_ID
, sourcePreferencesFileString
);
3132 sourceNetworkInterfacePrefs
= SCPreferencesCreate(NULL
, PLUGIN_ID
, sourceNetworkInterfaceFileString
);
3133 if ((sourcePrefs
== NULL
) || (sourceNetworkInterfacePrefs
== NULL
)) {
3137 if ((targetConfigurationFilesPresent
= __SCNetworkConfigurationMigrateConfigurationFilesPresent(targetDir
, &targetConfigurationFiles
)) == FALSE
) {
3138 if (targetConfigurationFiles
== NULL
) {
3139 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: targetConfigurationFiles is NULL"));
3142 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: targetDir: (%@) doesn't contain configuration files ... Need to create default configuration"), targetDir
);
3145 targetPreferencesFile
= CFArrayGetValueAtIndex(targetConfigurationFiles
, PREFERENCES_PLIST_INDEX
);
3146 if (CFURLGetFileSystemRepresentation(targetPreferencesFile
, TRUE
, (UInt8
*)targetPreferencesFileStr
, sizeof(targetPreferencesFileStr
)) == FALSE
) {
3147 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: Cannot get file system representation for url: %@"), targetPreferencesFile
);
3150 targetNetworkInterfaceFile
= CFArrayGetValueAtIndex(targetConfigurationFiles
, NETWORK_INTERFACES_PLIST_INDEX
);
3151 if (CFURLGetFileSystemRepresentation(targetNetworkInterfaceFile
, TRUE
, (UInt8
*)targetNetworkInterfaceFileStr
, sizeof(targetNetworkInterfaceFileStr
)) == FALSE
) {
3152 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: Cannot get file system representation for url: %@"), targetNetworkInterfaceFile
);
3156 targetPreferencesFileString
= CFStringCreateWithCString(NULL
, targetPreferencesFileStr
, kCFStringEncodingUTF8
);
3157 targetNetworkInterfaceFileString
= CFStringCreateWithCString(NULL
, targetNetworkInterfaceFileStr
, kCFStringEncodingUTF8
);
3159 if (targetConfigurationFilesPresent
== TRUE
) {
3160 targetPrefs
= SCPreferencesCreate(NULL
, PLUGIN_ID
, targetPreferencesFileString
);
3161 targetNetworkInterfacePrefs
= SCPreferencesCreate(NULL
, PLUGIN_ID
, targetNetworkInterfaceFileString
);
3162 if ((targetPrefs
== NULL
) || (targetNetworkInterfacePrefs
== NULL
)) {
3167 targetPrefs
= __SCNetworkCreateDefaultPref(targetPreferencesFileString
);
3168 targetNetworkInterfacePrefs
= __SCNetworkCreateDefaultNIPrefs(targetNetworkInterfaceFileString
);
3170 if (targetPrefs
== NULL
||
3171 targetNetworkInterfacePrefs
== NULL
) {
3172 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: Could not create default configuration."));
3176 validityOptions
= CFDictionaryCreateMutable(NULL
, 0,
3177 &kCFTypeDictionaryKeyCallBacks
,
3178 &kCFTypeDictionaryValueCallBacks
);
3179 CFDictionaryAddValue(validityOptions
, kSCNetworkConfigurationRepair
, kCFBooleanTrue
);
3181 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("sourcePreferenceFileString: %@\n sourceNetworkInterfaceFileString:%@\n targetPreferencesFileString:%@\ntargetNetworkInterfaceFileString:%@"), sourcePreferencesFileString
, sourceNetworkInterfaceFileString
,
3182 targetPreferencesFileString
, targetNetworkInterfaceFileString
);
3184 // Setting Bypass Interface to avoid looking at system interfaces
3185 __SCPreferencesSetLimitSCNetworkConfiguration(sourcePrefs
, TRUE
);
3186 __SCPreferencesSetLimitSCNetworkConfiguration(targetPrefs
, TRUE
);
3188 // Create services for builtin interfaces at source if they don't exist
3189 (void)_SCNetworkConfigurationCreateBuiltinInterfaceServices(sourcePrefs
, sourceNetworkInterfacePrefs
);
3190 // Checking validity of the source and destination preferences before continuing
3191 if (_SCNetworkConfigurationCheckValidityUsingPreferences(sourcePrefs
,
3192 sourceNetworkInterfacePrefs
,
3193 validityOptions
) == FALSE
) {
3194 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: Source configuration is not valid"));
3195 goto skipServiceMigration
;
3197 // Only call this function if configuration files were not created by default
3198 if (targetConfigurationFilesPresent
== TRUE
) {
3199 // Create services for builtin interfaces at target if they don't exist
3200 (void)_SCNetworkConfigurationCreateBuiltinInterfaceServices(targetPrefs
, targetNetworkInterfacePrefs
);
3201 if (_SCNetworkConfigurationCheckValidityUsingPreferences(targetPrefs
,
3202 targetNetworkInterfacePrefs
,
3203 validityOptions
) == FALSE
) {
3204 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: Target configuration is not valid"));
3205 goto skipServiceMigration
;
3209 builtinMapping
= _SCNetworkConfigurationCopyBuiltinMapping(sourceNetworkInterfacePrefs
, targetNetworkInterfacePrefs
);
3210 externalMapping
= _SCNetworkConfigurationCopyExternalInterfaceMapping(sourceNetworkInterfacePrefs
, targetNetworkInterfacePrefs
);
3214 Now builtin and external interface mapping is complete, work needs to be done on updating the preferences.plist and NetworkInterface.plist.
3216 Also, work needs to be done to check the validity of the data in preferences in source and target destinations, and after migration
3219 newTargetNetworkInterfaceEntity
= _SCNetworkMigrationCreateNetworkInterfaceArray(targetNetworkInterfacePrefs
, externalMapping
);
3220 if (isA_CFArray(newTargetNetworkInterfaceEntity
) == NULL
) {
3221 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: newTargetNetworkInterfaceEntity is NULL or not of correct type"));
3224 // Write new interface mapping to NetworkInterfaces.plist
3225 if (__SCNetworkInterfaceSaveStoredWithPreferences(targetNetworkInterfacePrefs
, newTargetNetworkInterfaceEntity
) == FALSE
)
3227 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: SCNetworkInterfaceSaveStoreWithPreferences failed to update NetworkInterface.plist"));
3230 // Create BSD Name Mapping to facilitate mapping of services
3231 bsdNameMapping
= _SCNetworkMigrationCreateBSDNameMapping(builtinMapping
, externalMapping
);
3233 if (isA_CFDictionary(bsdNameMapping
) == NULL
) {
3234 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: BSD Name Mapping is NULL"));
3237 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("BSD Name Mapping: %@"), bsdNameMapping
);
3238 serviceMapping
= _SCNetworkMigrationCreateServiceMappingUsingBSDMapping(sourcePrefs
, targetPrefs
, bsdNameMapping
);
3240 if (isA_CFDictionary(serviceMapping
) == NULL
) {
3241 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: Service Mapping is NULL"));
3244 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("Service Mapping: %@"), serviceMapping
);
3246 setMapping
= _SCNetworkMigrationCreateSetMapping(sourcePrefs
, targetPrefs
);
3247 sourceServiceSetMapping
= _SCNetworkMigrationCreateServiceSetMapping(sourcePrefs
);
3249 // Perform the migration of services
3250 if (_SCNetworkMigrationDoServiceMigration(sourcePrefs
, targetPrefs
,
3251 serviceMapping
, bsdNameMapping
,
3252 setMapping
, sourceServiceSetMapping
) == FALSE
) {
3253 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: SCNetworkMigrationDoServiceMigration failed to complete successfully"));
3257 #if !TARGET_OS_IPHONE
3258 // Migrating Virtual Network Interface
3259 if (_SCNetworkMigrationDoVirtualNetworkInterfaceMigration(sourcePrefs
, sourceNetworkInterfacePrefs
,
3260 targetPrefs
, targetNetworkInterfacePrefs
,
3261 bsdNameMapping
, setMapping
, sourceServiceSetMapping
) == FALSE
) {
3262 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: _SCNetworkMigrationDoVirtualNetworkInterfaceMigration failed to complete successfully"));
3265 // Migrate Service Order
3266 if (_SCNetworkMigrationDoServiceOrderMigration(sourcePrefs
, targetPrefs
, setMapping
) == FALSE
) {
3267 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: _SCNetworkMigrationDoServiceOrderMigration failed to complete successfully"));
3270 skipServiceMigration
:
3271 // Migrating System Information
3272 if (_SCNetworkMigrationDoSystemMigration(sourcePrefs
, targetPrefs
) == FALSE
) {
3273 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: _SCNetworkMigrationDoSystemMigration failed to complete successfully"));
3276 if (_SCNetworkConfigurationCheckValidityUsingPreferences(targetPrefs
, targetNetworkInterfacePrefs
, NULL
) == FALSE
) {
3277 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: Migrated configuration is not valid"));
3280 if (SCPreferencesCommitChanges(targetPrefs
) == FALSE
) {
3281 SCLog(TRUE
, LOG_ERR
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: Error commiting targetPrefs, %s"), SCErrorString(SCError()));
3285 if (SCPreferencesCommitChanges(targetNetworkInterfacePrefs
) == FALSE
) {
3286 SCLog(TRUE
, LOG_ERR
, CFSTR("_SCNetworkConfigurationMigrateConfiguration: Error commiting targetNetworkInterfacePrefs, %s"), SCErrorString(SCError()));
3289 migrationSuccess
= TRUE
;
3292 if (setMapping
!= NULL
) {
3293 CFRelease(setMapping
);
3295 if (sourceServiceSetMapping
!= NULL
) {
3296 CFRelease(sourceServiceSetMapping
);
3298 if (sourceConfigurationFiles
!= NULL
) {
3299 CFRelease(sourceConfigurationFiles
);
3301 if (targetConfigurationFiles
!= NULL
) {
3302 CFRelease(targetConfigurationFiles
);
3304 if (sourcePreferencesFileString
!= NULL
) {
3305 CFRelease(sourcePreferencesFileString
);
3307 if (sourceNetworkInterfaceFileString
!= NULL
) {
3308 CFRelease(sourceNetworkInterfaceFileString
);
3310 if (targetPreferencesFileString
!= NULL
) {
3311 CFRelease(targetPreferencesFileString
);
3313 if (targetNetworkInterfaceFileString
!= NULL
) {
3314 CFRelease(targetNetworkInterfaceFileString
);
3316 if (newTargetNetworkInterfaceEntity
!= NULL
) {
3317 CFRelease(newTargetNetworkInterfaceEntity
);
3319 if (builtinMapping
!= NULL
) {
3320 CFRelease(builtinMapping
);
3322 if (externalMapping
!= NULL
) {
3323 CFRelease(externalMapping
);
3325 if (bsdNameMapping
!= NULL
) {
3326 CFRelease(bsdNameMapping
);
3328 if (serviceMapping
!= NULL
) {
3329 CFRelease(serviceMapping
);
3331 if (targetPrefs
!= NULL
) {
3332 CFRelease(targetPrefs
);
3334 if (sourcePrefs
!= NULL
) {
3335 CFRelease(sourcePrefs
);
3337 if (sourceNetworkInterfacePrefs
!= NULL
) {
3338 CFRelease(sourceNetworkInterfacePrefs
);
3340 if (targetNetworkInterfacePrefs
!= NULL
) {
3341 CFRelease(targetNetworkInterfacePrefs
);
3343 if (validityOptions
!= NULL
) {
3344 CFRelease(validityOptions
);
3346 return migrationSuccess
;
3352 _SCNetworkMigrationAreServicesIdentical( SCPreferencesRef configPref
, SCPreferencesRef expectedConfigPref
)
3354 const void * expected_vals_q
[N_QUICK
];
3355 const void ** expected_vals
= expected_vals_q
;
3356 CFMutableArrayRef expectedServiceArray
= NULL
;
3357 CFIndex expectedServiceArrayCount
= 0;
3358 CFDictionaryRef expectedServiceDict
= NULL
;
3359 CFIndex expectedServiceDictCount
= 0;
3360 CFDictionaryRef expectedServiceEntity
= 0;
3361 Boolean foundMatch
= FALSE
;
3362 CFMutableArrayRef serviceArray
= NULL
;
3363 CFIndex serviceArrayCount
= 0;
3364 CFDictionaryRef serviceDict
= NULL
;
3365 CFIndex serviceDictCount
= 0;
3366 CFDictionaryRef serviceEntity
= NULL
;
3367 Boolean success
= FALSE
;
3368 const void * vals_q
[N_QUICK
];
3369 const void ** vals
= vals_q
;
3371 serviceDict
= SCPreferencesGetValue(configPref
, kSCPrefNetworkServices
);
3372 if (isA_CFDictionary(serviceDict
) == NULL
) {
3375 serviceDictCount
= CFDictionaryGetCount(serviceDict
);
3377 expectedServiceDict
= SCPreferencesGetValue(expectedConfigPref
, kSCPrefNetworkServices
);
3378 if (isA_CFDictionary(expectedServiceDict
) == NULL
) {
3381 expectedServiceDictCount
= CFDictionaryGetCount(expectedServiceDict
);
3383 if (serviceDictCount
!= expectedServiceDictCount
) {
3387 if (serviceDictCount
> (sizeof(vals_q
) / sizeof(CFTypeRef
))) {
3388 vals
= CFAllocatorAllocate(NULL
, serviceDictCount
* sizeof(CFPropertyListRef
), 0);
3391 CFDictionaryGetKeysAndValues(serviceDict
, NULL
, vals
);
3392 serviceArray
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
3394 for (CFIndex idx
=0; idx
< serviceDictCount
; idx
++) {
3395 serviceEntity
= vals
[idx
];
3396 if (isA_CFDictionary(serviceEntity
) == FALSE
) {
3399 CFArrayAppendValue(serviceArray
, serviceEntity
);
3402 serviceArrayCount
= CFArrayGetCount(serviceArray
);
3404 if (expectedServiceDictCount
> (sizeof(expected_vals_q
) / sizeof(CFTypeRef
))) {
3405 expected_vals
= CFAllocatorAllocate(NULL
, expectedServiceDictCount
, 0);
3408 CFDictionaryGetKeysAndValues(expectedServiceDict
, NULL
, expected_vals
);
3409 expectedServiceArray
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
3411 for (CFIndex idx
= 0; idx
< expectedServiceDictCount
; idx
++) {
3412 serviceEntity
= expected_vals
[idx
];
3414 if (isA_CFDictionary(serviceEntity
) == FALSE
) {
3417 CFArrayAppendValue(expectedServiceArray
, serviceEntity
);
3419 expectedServiceArrayCount
= CFArrayGetCount(expectedServiceArray
);
3421 if (serviceArrayCount
!= expectedServiceArrayCount
) {
3425 for (CFIndex idx
= 0; idx
< expectedServiceArrayCount
; idx
++) {
3427 expectedServiceEntity
= CFArrayGetValueAtIndex(expectedServiceArray
, idx
);
3428 serviceArrayCount
= CFArrayGetCount(serviceArray
);
3430 for (CFIndex idx2
= 0; idx2
< serviceArrayCount
; idx2
++) {
3431 serviceEntity
= CFArrayGetValueAtIndex(serviceArray
, idx2
);
3433 if (CFEqual(expectedServiceEntity
, serviceEntity
) == TRUE
) {
3439 if (foundMatch
== FALSE
) {
3444 success
= foundMatch
;
3446 if (vals
!= vals_q
) {
3447 CFAllocatorDeallocate(NULL
, vals
);
3449 if (expected_vals
!= expected_vals_q
) {
3450 CFAllocatorDeallocate(NULL
, expected_vals
);
3456 _SCNetworkMigrationAreNetworkInterfaceConfigurationsIdentical (SCPreferencesRef configNetworkInterfacePref
, SCPreferencesRef expectedNetworkInterfacePref
)
3458 CFDictionaryRef expectedInterfaceEntity
= NULL
;
3459 CFArrayRef expectedInterfaceList
= NULL
;
3460 CFIndex expectedInterfaceListCount
;
3461 Boolean foundMatch
= FALSE
;
3462 CFDictionaryRef interfaceEntity
= NULL
;
3463 CFArrayRef interfaceList
= NULL
;
3464 CFIndex interfaceListCount
;
3465 CFMutableArrayRef interfaceListMutable
= NULL
;
3466 Boolean success
= FALSE
;
3468 interfaceList
= SCPreferencesGetValue(configNetworkInterfacePref
, INTERFACES
);
3469 if (isA_CFArray(interfaceList
) == NULL
) {
3472 interfaceListMutable
= CFArrayCreateMutableCopy(NULL
, 0, interfaceList
);
3473 interfaceListCount
= CFArrayGetCount(interfaceListMutable
);
3475 expectedInterfaceList
= SCPreferencesGetValue(expectedNetworkInterfacePref
, INTERFACES
);
3476 if (isA_CFArray(expectedInterfaceList
) == NULL
) {
3479 expectedInterfaceListCount
= CFArrayGetCount(expectedInterfaceList
);
3481 if (interfaceListCount
!= expectedInterfaceListCount
) {
3485 for (CFIndex idx
= 0; idx
< expectedInterfaceListCount
; idx
++) {
3487 expectedInterfaceEntity
= CFArrayGetValueAtIndex(expectedInterfaceList
, idx
);
3488 interfaceListCount
= CFArrayGetCount(interfaceListMutable
);
3490 for (CFIndex idx2
= 0; idx2
< interfaceListCount
; idx2
++) {
3491 interfaceEntity
= CFArrayGetValueAtIndex(interfaceList
, idx2
);
3492 if (CFEqual(expectedInterfaceEntity
, interfaceEntity
) == TRUE
) {
3497 if (foundMatch
== FALSE
) {
3501 success
= foundMatch
;
3504 if (interfaceListMutable
!= NULL
) {
3505 CFRelease(interfaceListMutable
);
3512 _SCNetworkMigrationAreConfigurationsIdentical (CFURLRef configurationURL
,
3513 CFURLRef expectedConfigurationURL
)
3515 CFURLRef baseConfigURL
= NULL
;
3516 CFURLRef baseExpectedConfigURL
= NULL
;
3517 CFURLRef configPreferencesURL
= NULL
;
3518 CFURLRef configNetworkInterfacesURL
= NULL
;
3519 SCPreferencesRef configPref
= NULL
;
3520 SCPreferencesRef configNetworkInterfacePref
= NULL
;
3521 SCPreferencesRef expectedConfigPref
= NULL
;
3522 SCPreferencesRef expectedNetworkInterfacePref
= NULL
;
3523 CFURLRef expectedNetworkInterfaceURL
= NULL
;
3524 CFURLRef expectedPreferencesURL
= NULL
;
3525 Boolean isIdentical
= FALSE
;
3526 CFStringRef networkInterfaceConfigString
= NULL
;
3527 CFStringRef networkInterfaceExpectedString
= NULL
;
3528 CFStringRef prefsConfigString
= NULL
;
3529 CFStringRef prefsExpectedString
= NULL
;
3530 char networkInterfaceConfigStr
[PATH_MAX
];
3531 char networkInterfaceExpectedStr
[PATH_MAX
];
3532 char prefsConfigStr
[PATH_MAX
];
3533 char prefsExpectedStr
[PATH_MAX
];
3535 if (configurationURL
== NULL
||
3536 expectedConfigurationURL
== NULL
) {
3539 baseConfigURL
= CFURLCreateWithFileSystemPathRelativeToBase(NULL
, PREFS_DEFAULT_DIR_RELATIVE
, kCFURLPOSIXPathStyle
, TRUE
, configurationURL
);
3540 configPreferencesURL
= CFURLCreateFromFileSystemRepresentationRelativeToBase(NULL
, (const UInt8
*) PREFS_DEFAULT_CONFIG_PLIST
, sizeof(PREFS_DEFAULT_CONFIG_PLIST
), FALSE
, baseConfigURL
);
3542 if (CFURLResourceIsReachable(configPreferencesURL
, NULL
) == FALSE
) {
3543 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationAreConfigurationsIdentical: preferences.plist file is not present."));
3547 configNetworkInterfacesURL
= CFURLCreateFromFileSystemRepresentationRelativeToBase(NULL
, (const UInt8
*)NETWORK_INTERFACES_PREFS_PLIST
, sizeof(NETWORK_INTERFACES_PREFS_PLIST
), FALSE
, baseConfigURL
);
3549 if (CFURLResourceIsReachable(configNetworkInterfacesURL
, NULL
) == FALSE
) {
3550 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationAreConfigurationsIdentical: NetworkInterfaces.plist file is not present."));
3554 if (CFURLGetFileSystemRepresentation(configPreferencesURL
, TRUE
, (UInt8
*)prefsConfigStr
, sizeof(prefsConfigStr
)) == FALSE
) {
3555 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationAreConfigurationsIdentical: Could not extract preferences information"));
3558 if (CFURLGetFileSystemRepresentation(configNetworkInterfacesURL
, TRUE
, (UInt8
*)networkInterfaceConfigStr
, sizeof(networkInterfaceConfigStr
)) == FALSE
) {
3559 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationAreConfigurationsIdentical: Could not extract network interfaces information"));
3563 baseExpectedConfigURL
= CFURLCreateWithFileSystemPathRelativeToBase(NULL
, PREFS_DEFAULT_DIR_RELATIVE
, kCFURLPOSIXPathStyle
, TRUE
, expectedConfigurationURL
);
3564 expectedPreferencesURL
= CFURLCreateFromFileSystemRepresentationRelativeToBase(NULL
, (const UInt8
*)PREFS_DEFAULT_CONFIG_PLIST
, sizeof(PREFS_DEFAULT_CONFIG_PLIST
), FALSE
, baseExpectedConfigURL
);
3566 if (CFURLResourceIsReachable(expectedPreferencesURL
, NULL
) == FALSE
) {
3567 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationAreConfigurationsIdentical: preferences.plist file is not present in the expected configuration."));
3571 expectedNetworkInterfaceURL
= CFURLCreateFromFileSystemRepresentationRelativeToBase(NULL
, (const UInt8
*)NETWORK_INTERFACES_PREFS_PLIST
, sizeof(NETWORK_INTERFACES_PREFS_PLIST
), FALSE
, baseExpectedConfigURL
);
3573 if (CFURLResourceIsReachable(expectedNetworkInterfaceURL
, NULL
) == FALSE
) {
3574 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationAreConfigurationsIdentical: NetworkInterfaces.plist file is not present in the expected configuration."));
3578 if (CFURLGetFileSystemRepresentation(expectedPreferencesURL
, TRUE
, (UInt8
*)prefsExpectedStr
, sizeof(prefsExpectedStr
)) == FALSE
) {
3579 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationAreConfigurationsIdentical: Could not extract preferences information"));
3582 if (CFURLGetFileSystemRepresentation(expectedNetworkInterfaceURL
, TRUE
, (UInt8
*)networkInterfaceExpectedStr
, sizeof(networkInterfaceExpectedStr
)) == FALSE
) {
3583 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationAreConfigurationsIdentical: Could not extract network interfaces information"));
3587 prefsConfigString
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%s"), prefsConfigStr
);
3588 networkInterfaceConfigString
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%s"), networkInterfaceConfigStr
);
3589 prefsExpectedString
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%s"), prefsExpectedStr
);
3590 networkInterfaceExpectedString
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%s"), networkInterfaceExpectedStr
);
3592 configPref
= SCPreferencesCreate(NULL
, PLUGIN_ID
, prefsConfigString
);
3593 expectedConfigPref
= SCPreferencesCreate(NULL
, PLUGIN_ID
, prefsExpectedString
);
3594 configNetworkInterfacePref
= SCPreferencesCreate(NULL
, PLUGIN_ID
, networkInterfaceConfigString
);
3595 expectedNetworkInterfacePref
= SCPreferencesCreate(NULL
, PLUGIN_ID
, networkInterfaceExpectedString
);
3597 if (configPref
== NULL
||
3598 expectedConfigPref
== NULL
||
3599 configNetworkInterfacePref
== NULL
||
3600 expectedNetworkInterfacePref
== NULL
) {
3601 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("_SCNetworkMigrationAreConfigurationsIdentical: One of the preferences is NULL"));
3602 isIdentical
= FALSE
;
3605 isIdentical
= (_SCNetworkMigrationAreServicesIdentical(configPref
, expectedConfigPref
) &&
3606 _SCNetworkMigrationAreNetworkInterfaceConfigurationsIdentical(configNetworkInterfacePref
, expectedNetworkInterfacePref
));
3608 if (baseConfigURL
!= NULL
) {
3609 CFRelease(baseConfigURL
);
3611 if (configPreferencesURL
!= NULL
) {
3612 CFRelease(configPreferencesURL
);
3614 if (configNetworkInterfacesURL
!= NULL
) {
3615 CFRelease(configNetworkInterfacesURL
);
3617 if (baseExpectedConfigURL
!= NULL
) {
3618 CFRelease(baseExpectedConfigURL
);
3620 if (expectedPreferencesURL
!= NULL
) {
3621 CFRelease(expectedPreferencesURL
);
3623 if (expectedNetworkInterfaceURL
!= NULL
) {
3624 CFRelease(expectedNetworkInterfaceURL
);
3626 if (prefsConfigString
!= NULL
) {
3627 CFRelease(prefsConfigString
);
3629 if (networkInterfaceConfigString
!= NULL
) {
3630 CFRelease(networkInterfaceConfigString
);
3632 if (prefsExpectedString
!= NULL
) {
3633 CFRelease(prefsExpectedString
);
3635 if (networkInterfaceExpectedString
!= NULL
) {
3636 CFRelease(networkInterfaceExpectedString
);
3638 if (configPref
!= NULL
) {
3639 CFRelease(configPref
);
3641 if (expectedConfigPref
!= NULL
) {
3642 CFRelease(expectedConfigPref
);
3644 if (configNetworkInterfacePref
!= NULL
) {
3645 CFRelease(configNetworkInterfacePref
);
3647 if (expectedNetworkInterfacePref
!= NULL
) {
3648 CFRelease(expectedNetworkInterfacePref
);
3654 _SCNetworkConfigurationCopyMigrationRemovePaths (CFArrayRef targetPaths
,
3657 CFURLRef affectedURL
;
3658 char filePath
[PATH_MAX
];
3659 CFURLRef targetFile
;
3660 CFMutableArrayRef toBeRemoved
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
3662 for (CFIndex idx
= 0; idx
< CFArrayGetCount(targetPaths
); idx
++) {
3663 affectedURL
= CFArrayGetValueAtIndex(targetPaths
, idx
);
3665 if (CFURLGetFileSystemRepresentation(affectedURL
, TRUE
, (UInt8
*)filePath
, sizeof(filePath
)) == FALSE
) {
3666 SCLog(_sc_debug
, LOG_NOTICE
, CFSTR("filesToBeRemoved: Could not get file system representation"));
3669 targetFile
= CFURLCreateFromFileSystemRepresentationRelativeToBase(NULL
, (const UInt8
*)filePath
,
3670 strnlen(filePath
, sizeof(filePath
)), FALSE
, targetDir
);
3672 if (CFURLResourceIsReachable(targetFile
, NULL
) == FALSE
) {
3673 CFArrayAppendValue(toBeRemoved
, affectedURL
);
3675 CFRelease(targetFile
);
3677 // If number of files to be removed is 0, return NULL
3678 if (CFArrayGetCount(toBeRemoved
) == 0) {
3679 CFRelease(toBeRemoved
);