From 6de80e47cd0fa121e11fcedf2e472e13c2f8ea0e Mon Sep 17 00:00:00 2001 From: Apple Date: Wed, 3 Jun 2020 04:29:32 +0000 Subject: [PATCH] configd-1061.120.2.tar.gz --- Plugins/IPMonitor/ip_plugin.c | 7 +- Plugins/InterfaceNamer/ifnamer.c | 87 ++++++++++++++----- Plugins/common/plugin_shared.h | 5 +- .../SCNetworkConfigurationPrivate.c | 18 ++-- .../SCNetworkInterface.c | 3 + .../SCNetworkMigration.c | 34 ++++++-- SystemConfiguration.fproj/SCNetworkSet.c | 12 ++- 7 files changed, 127 insertions(+), 39 deletions(-) diff --git a/Plugins/IPMonitor/ip_plugin.c b/Plugins/IPMonitor/ip_plugin.c index 027d7e3..b31b6e6 100644 --- a/Plugins/IPMonitor/ip_plugin.c +++ b/Plugins/IPMonitor/ip_plugin.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2019 Apple Inc. All Rights Reserved. + * Copyright (c) 2000-2020 Apple Inc. All Rights Reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -8257,7 +8257,12 @@ IPMonitorProcessChanges(SCDynamicStoreRef session, CFArrayRef changed_keys, } else if (CFStringHasPrefix(change, S_interface_delegation_prefix) && CFStringHasSuffix(change, kSCEntNetInterfaceDelegation)) { + // ensure that we update the reachability flags in the NWI + // state (including the non-interface-specific flags) reachability_changed = TRUE; + // ensure that we update the reachability flags in the DNS + // configuration + dnsinfo_changed = TRUE; } else if (CFStringHasPrefix(change, S_state_service_prefix)) { CFStringRef protocol = NULL; diff --git a/Plugins/InterfaceNamer/ifnamer.c b/Plugins/InterfaceNamer/ifnamer.c index 9d3f0dd..13db1ec 100644 --- a/Plugins/InterfaceNamer/ifnamer.c +++ b/Plugins/InterfaceNamer/ifnamer.c @@ -391,6 +391,15 @@ writeInterfaceList(CFArrayRef if_list) SCPreferencesSetValue(ni_prefs, INTERFACES, if_list); + if (cur_list == NULL) { + const int new_version = NETWORK_CONFIGURATION_VERSION; + CFNumberRef version; + + version = CFNumberCreate(NULL, kCFNumberIntType, &new_version); + SCPreferencesSetValue(ni_prefs, kSCPrefVersion, version); + CFRelease(version); + } + if (!SCPreferencesCommitChanges(ni_prefs)) { if (SCError() != EROFS) { SC_log(LOG_NOTICE, "SCPreferencesCommitChanges() failed: %s", SCErrorString(SCError())); @@ -407,11 +416,10 @@ done: static CF_RETURNS_RETAINED CFMutableArrayRef readInterfaceList() { + CFMutableArrayRef db_list = NULL; CFArrayRef if_list; SCPreferencesRef ni_prefs; CFStringRef old_model; - static Boolean once = FALSE; - CFMutableArrayRef plist = NULL; ni_prefs = SCPreferencesCreate(NULL, CFSTR(MY_PLUGIN_NAME ":readInterfaceList"), INTERFACES_DEFAULT_CONFIG); if (ni_prefs == NULL) { @@ -419,11 +427,6 @@ readInterfaceList() return (NULL); } - if (!once) { - __SCNetworkConfigurationUpgrade(NULL, &ni_prefs, TRUE); - once = TRUE; - } - if_list = SCPreferencesGetValue(ni_prefs, INTERFACES); if_list = isA_CFArray(if_list); @@ -444,7 +447,7 @@ readInterfaceList() if (if_list != NULL) { CFIndex n = CFArrayGetCount(if_list); - plist = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); + db_list = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); for (CFIndex i = 0; i < n; i++) { CFDictionaryRef dict; @@ -453,21 +456,21 @@ readInterfaceList() CFDictionaryContainsKey(dict, CFSTR(kIOInterfaceType)) && CFDictionaryContainsKey(dict, CFSTR(kIOInterfaceUnit)) && CFDictionaryContainsKey(dict, CFSTR(kIOMACAddress))) { - CFArrayAppendValue(plist, dict); + CFArrayAppendValue(db_list, dict); } } } - if (plist != NULL) { - CFIndex n = CFArrayGetCount(plist); + if (db_list != NULL) { + CFIndex n = CFArrayGetCount(db_list); if (n > 1) { - CFArraySortValues(plist, CFRangeMake(0, n), if_unit_compare, NULL); + CFArraySortValues(db_list, CFRangeMake(0, n), if_unit_compare, NULL); } } CFRelease(ni_prefs); - return (plist); + return (db_list); } static CF_RETURNS_RETAINED CFMutableArrayRef @@ -3024,6 +3027,52 @@ updateNetworkConfiguration(CFArrayRef if_list) } #endif // !TARGET_OS_IPHONE +static void +upgradeNetworkConfiguration() +{ + static dispatch_once_t once; + + /* + * Once, per start of InterfaceNamer, we check/ensure that the + * configuration has been upgraded. + * + * Note: this check should not be performed until we know that + * the __wait_for_IOKit_to_quiesce() conditions have been + * satisfied. + */ + + dispatch_once(&once, ^{ + SCPreferencesRef ni_prefs; + Boolean updated; + + // save the [current] DB with the interfaces that have been named + writeInterfaceList(S_dblist); + + // upgrade the configuration + ni_prefs = SCPreferencesCreate(NULL, CFSTR(MY_PLUGIN_NAME ":upgradeNetworkConfiguration"), INTERFACES_DEFAULT_CONFIG); + if (ni_prefs == NULL) { + SC_log(LOG_NOTICE, "SCPreferencesCreate() failed: %s", SCErrorString(SCError())); + return; + } + updated = __SCNetworkConfigurationUpgrade(NULL, &ni_prefs, TRUE); + CFRelease(ni_prefs); + + if (updated) { + // re-read list of previously named network interfaces + if (S_dblist != NULL) { + CFRelease(S_dblist); + } + S_dblist = readInterfaceList(); + + addTimestamp(S_state, CFSTR("*UPGRADED*")); + SC_log(LOG_INFO, "network configuration upgraded"); + updateStore(); + } + }); + + return; +} + static void removeInactiveInterfaces(void) { @@ -3219,7 +3268,7 @@ updateInterfaces(void) * if we've named all of the interfaces that * were used during the previous boot. */ - addTimestamp(S_state, CFSTR("*RELEASE*")); + addTimestamp(S_state, kInterfaceNamerKey_Complete); SC_log(LOG_INFO, "last boot interfaces have been named"); updateStore(); CFRelease(S_prev_active_list); @@ -3349,6 +3398,7 @@ quietCallback(void *refcon, if (messageType == kIOMessageServiceBusyStateChange) { addTimestamp(S_state, CFSTR("*QUIET&NAMED*")); updateStore(); + upgradeNetworkConfiguration(); } return; @@ -3495,6 +3545,7 @@ timerCallback(CFRunLoopTimerRef timer, void *info) addTimestamp(S_state, CFSTR("*TIMEOUT&NAMED*")); updateStore(); + upgradeNetworkConfiguration(); return; } @@ -3511,14 +3562,6 @@ setup_IOKit(CFBundleRef bundle) // read DB of previously named network interfaces S_dblist = readInterfaceList(); - if (S_dblist != NULL) { - CFIndex n; - - n = CFArrayGetCount(S_dblist); - if (n > 1) { - CFArraySortValues(S_dblist, CFRangeMake(0, n), if_unit_compare, NULL); - } - } // get interfaces that were named during the last boot S_prev_active_list = previouslyActiveInterfaces(); diff --git a/Plugins/common/plugin_shared.h b/Plugins/common/plugin_shared.h index 5fdad83..0b18f22 100644 --- a/Plugins/common/plugin_shared.h +++ b/Plugins/common/plugin_shared.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2016, 2018, 2020 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -43,7 +43,8 @@ * Plugin:InterfaceNamer [SCDynamicStore] dictionary content */ -// IORegistry "quiet" (and timeout) +// IORegistry "quiet", "complete" (last boot interfaces found), and "timeout" +#define kInterfaceNamerKey_Complete CFSTR("*COMPLETE*") #define kInterfaceNamerKey_Quiet CFSTR("*QUIET*") #define kInterfaceNamerKey_Timeout CFSTR("*TIMEOUT*") diff --git a/SystemConfiguration.fproj/SCNetworkConfigurationPrivate.c b/SystemConfiguration.fproj/SCNetworkConfigurationPrivate.c index 9bab431..01576ea 100644 --- a/SystemConfiguration.fproj/SCNetworkConfigurationPrivate.c +++ b/SystemConfiguration.fproj/SCNetworkConfigurationPrivate.c @@ -822,12 +822,18 @@ __SCNetworkConfigurationCleanHiddenInterfaces(SCPreferencesRef prefs, SCPreferen if_dict = CFArrayGetValueAtIndex(interfaces, i); bsdName = CFDictionaryGetValue(if_dict, CFSTR(kIOBSDNameKey)); if (isThin(interfaces_thin, bsdName)) { - // remove this "thinned" interface - if ((_sc_log == 1) || _sc_verbose) { - SC_log(LOG_INFO, "thinned network interface : %@", bsdName); - } - updated++; - continue; + if (CFDictionaryContainsKey(if_dict, CFSTR(kSCNetworkInterfaceActive))) { + if ((_sc_log == 1) || _sc_debug) { + SC_log(LOG_INFO, "skipping interface : %@ (active)", bsdName); + } + } else { + // remove this "thinned" interface + if ((_sc_log == 1) || _sc_debug || _sc_verbose) { + SC_log(LOG_INFO, "thinned network interface : %@", bsdName); + } + updated++; + continue; + } } CFArrayAppendValue(interfaces_new, if_dict); diff --git a/SystemConfiguration.fproj/SCNetworkInterface.c b/SystemConfiguration.fproj/SCNetworkInterface.c index 9179550..b9c0ba4 100644 --- a/SystemConfiguration.fproj/SCNetworkInterface.c +++ b/SystemConfiguration.fproj/SCNetworkInterface.c @@ -4714,6 +4714,9 @@ __waitForInterfaces() if (dict != NULL) { if (isA_CFDictionary(dict) && (CFDictionaryContainsKey(dict, kInterfaceNamerKey_Quiet) || +#if TARGET_OS_IPHONE + CFDictionaryContainsKey(dict, kInterfaceNamerKey_Complete) || + #endif // TARGET_OS_IPHONE CFDictionaryContainsKey(dict, kInterfaceNamerKey_Timeout))) { quiet = TRUE; } diff --git a/SystemConfiguration.fproj/SCNetworkMigration.c b/SystemConfiguration.fproj/SCNetworkMigration.c index f38e15c..091645c 100644 --- a/SystemConfiguration.fproj/SCNetworkMigration.c +++ b/SystemConfiguration.fproj/SCNetworkMigration.c @@ -320,9 +320,10 @@ _SCNetworkConfigurationMakePathIfNeeded(CFURLRef pathURL) static SCPreferencesRef __SCNetworkCreateDefaultPref(CFStringRef prefsID) { - SCPreferencesRef prefs; - SCNetworkSetRef currentSet; - CFStringRef model; + SCNetworkSetRef currentSet; + CFStringRef model; + SCPreferencesRef prefs; + CFNumberRef version; prefs = SCPreferencesCreate(NULL, PLUGIN_ID, prefsID); if (prefs == NULL) { @@ -342,6 +343,15 @@ __SCNetworkCreateDefaultPref(CFStringRef prefsID) SCPreferencesSetValue(prefs, MODEL, model); } + version = SCPreferencesGetValue(prefs, MODEL); + if (version == NULL) { + const int new_version = NETWORK_CONFIGURATION_VERSION; + + version = CFNumberCreate(NULL, kCFNumberIntType, &new_version); + SCPreferencesSetValue(prefs, kSCPrefVersion, version); + CFRelease(version); + } + return prefs; } @@ -349,10 +359,11 @@ __private_extern__ void __SCNetworkPopulateDefaultNIPrefs(SCPreferencesRef ni_prefs) { - CFMutableArrayRef interfaces = NULL; - CFStringRef model; - CFArrayRef networkInterfaces; - CFComparisonResult res; + CFMutableArrayRef interfaces = NULL; + CFStringRef model; + CFArrayRef networkInterfaces; + CFComparisonResult res; + CFNumberRef version; interfaces = (CFMutableArrayRef)SCPreferencesGetValue(ni_prefs, INTERFACES); if (isA_CFArray(interfaces)) { @@ -416,6 +427,15 @@ __SCNetworkPopulateDefaultNIPrefs(SCPreferencesRef ni_prefs) SCPreferencesSetValue(ni_prefs, MODEL, model); } + version = SCPreferencesGetValue(ni_prefs, MODEL); + if (version == NULL) { + const int new_version = NETWORK_CONFIGURATION_VERSION; + + version = CFNumberCreate(NULL, kCFNumberIntType, &new_version); + SCPreferencesSetValue(ni_prefs, kSCPrefVersion, version); + CFRelease(version); + } + CFRelease(networkInterfaces); return; diff --git a/SystemConfiguration.fproj/SCNetworkSet.c b/SystemConfiguration.fproj/SCNetworkSet.c index bfcf499..9679534 100644 --- a/SystemConfiguration.fproj/SCNetworkSet.c +++ b/SystemConfiguration.fproj/SCNetworkSet.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2019 Apple Inc. All rights reserved. + * Copyright (c) 2004-2020 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -968,6 +968,7 @@ _SCNetworkSetCreateDefault(SCPreferencesRef prefs) Boolean ok = TRUE; SCNetworkSetRef set; CFStringRef setName = NULL; + CFNumberRef version; set = SCNetworkSetCopyCurrent(prefs); if (set != NULL) { @@ -1009,6 +1010,15 @@ _SCNetworkSetCreateDefault(SCPreferencesRef prefs) SCPreferencesSetValue(prefs, MODEL, model); } + version = SCPreferencesGetValue(prefs, kSCPrefVersion); + if (version == NULL) { + const int new_version = NETWORK_CONFIGURATION_VERSION; + + version = CFNumberCreate(NULL, kCFNumberIntType, &new_version); + SCPreferencesSetValue(prefs, kSCPrefVersion, version); + CFRelease(version); + } + done : if (!ok && (set != NULL)) { -- 2.45.2