]> git.saurik.com Git - apple/configd.git/commitdiff
configd-1061.120.2.tar.gz macos-10155 v1061.120.2
authorApple <opensource@apple.com>
Wed, 3 Jun 2020 04:29:32 +0000 (04:29 +0000)
committerApple <opensource@apple.com>
Wed, 3 Jun 2020 04:29:32 +0000 (04:29 +0000)
Plugins/IPMonitor/ip_plugin.c
Plugins/InterfaceNamer/ifnamer.c
Plugins/common/plugin_shared.h
SystemConfiguration.fproj/SCNetworkConfigurationPrivate.c
SystemConfiguration.fproj/SCNetworkInterface.c
SystemConfiguration.fproj/SCNetworkMigration.c
SystemConfiguration.fproj/SCNetworkSet.c

index 027d7e3bc3bd6f3170b758d75632fc55efa7593b..b31b6e686f4dc93618bc2c0d3199b6728ede30e0 100644 (file)
@@ -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@
  *
  *
  * @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)) {
        }
        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;
                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;
        }
        else if (CFStringHasPrefix(change, S_state_service_prefix)) {
            CFStringRef protocol = NULL;
index 9d3f0dd175afbf4a44ef9ceb705a42d30e48a213..13db1ec833c5dfa6aff73b03243ab511de5cf92f 100644 (file)
@@ -391,6 +391,15 @@ writeInterfaceList(CFArrayRef if_list)
 
     SCPreferencesSetValue(ni_prefs, INTERFACES, 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()));
     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()
 {
 static CF_RETURNS_RETAINED CFMutableArrayRef
 readInterfaceList()
 {
+    CFMutableArrayRef          db_list = NULL;
     CFArrayRef                 if_list;
     SCPreferencesRef           ni_prefs;
     CFStringRef                        old_model;
     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) {
 
     ni_prefs = SCPreferencesCreate(NULL, CFSTR(MY_PLUGIN_NAME ":readInterfaceList"), INTERFACES_DEFAULT_CONFIG);
     if (ni_prefs == NULL) {
@@ -419,11 +427,6 @@ readInterfaceList()
        return (NULL);
     }
 
        return (NULL);
     }
 
-    if (!once) {
-       __SCNetworkConfigurationUpgrade(NULL, &ni_prefs, TRUE);
-       once = TRUE;
-    }
-
     if_list = SCPreferencesGetValue(ni_prefs, INTERFACES);
     if_list = isA_CFArray(if_list);
 
     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);
 
     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;
 
        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))) {
                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) {
 
        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);
        }
     }
 
     CFRelease(ni_prefs);
-    return (plist);
+    return (db_list);
 }
 
 static CF_RETURNS_RETAINED CFMutableArrayRef
 }
 
 static CF_RETURNS_RETAINED CFMutableArrayRef
@@ -3024,6 +3027,52 @@ updateNetworkConfiguration(CFArrayRef if_list)
 }
 #endif // !TARGET_OS_IPHONE
 
 }
 #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)
 {
 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.
             */
             * 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);
            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();
     if (messageType == kIOMessageServiceBusyStateChange) {
        addTimestamp(S_state, CFSTR("*QUIET&NAMED*"));
        updateStore();
+       upgradeNetworkConfiguration();
     }
 
     return;
     }
 
     return;
@@ -3495,6 +3545,7 @@ timerCallback(CFRunLoopTimerRef   timer, void *info)
 
     addTimestamp(S_state, CFSTR("*TIMEOUT&NAMED*"));
     updateStore();
 
     addTimestamp(S_state, CFSTR("*TIMEOUT&NAMED*"));
     updateStore();
+    upgradeNetworkConfiguration();
 
     return;
 }
 
     return;
 }
@@ -3511,14 +3562,6 @@ setup_IOKit(CFBundleRef bundle)
 
     // read DB of previously named network interfaces
     S_dblist = readInterfaceList();
 
     // 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();
 
     // get interfaces that were named during the last boot
     S_prev_active_list = previouslyActiveInterfaces();
index 5fdad83cf7639fbe2924e1ed582ef4ac789e328f..0b18f22944eaf278c275c40a8d71d0ab6ca77a6e 100644 (file)
@@ -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@
  *
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -43,7 +43,8 @@
  * Plugin:InterfaceNamer [SCDynamicStore] dictionary content
  */
 
  * 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*")
 
 #define        kInterfaceNamerKey_Quiet                        CFSTR("*QUIET*")
 #define        kInterfaceNamerKey_Timeout                      CFSTR("*TIMEOUT*")
 
index 9bab43170aa8f52e814bfa355fe39e146f43a068..01576ea693c71ea8b3645e8f4c04860347f61424 100644 (file)
@@ -822,12 +822,18 @@ __SCNetworkConfigurationCleanHiddenInterfaces(SCPreferencesRef prefs, SCPreferen
                        if_dict = CFArrayGetValueAtIndex(interfaces, i);
                        bsdName = CFDictionaryGetValue(if_dict, CFSTR(kIOBSDNameKey));
                        if (isThin(interfaces_thin, bsdName)) {
                        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);
                        }
 
                        CFArrayAppendValue(interfaces_new, if_dict);
index 91795507d5e36841ddae5a3390f1e3da6d048504..b9c0ba441ecb0abef33261cf28dbfcc730897f88 100644 (file)
@@ -4714,6 +4714,9 @@ __waitForInterfaces()
                if (dict != NULL) {
                        if (isA_CFDictionary(dict) &&
                            (CFDictionaryContainsKey(dict, kInterfaceNamerKey_Quiet) ||
                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;
                        }
                             CFDictionaryContainsKey(dict, kInterfaceNamerKey_Timeout))) {
                                quiet = TRUE;
                        }
index f38e15cca4a793c8b3e372e85c755f2dfb51a2b9..091645cb409a213d9ca02c63195ccb78058232fc 100644 (file)
@@ -320,9 +320,10 @@ _SCNetworkConfigurationMakePathIfNeeded(CFURLRef pathURL)
 static SCPreferencesRef
 __SCNetworkCreateDefaultPref(CFStringRef prefsID)
 {
 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) {
 
        prefs = SCPreferencesCreate(NULL, PLUGIN_ID, prefsID);
        if (prefs == NULL) {
@@ -342,6 +343,15 @@ __SCNetworkCreateDefaultPref(CFStringRef prefsID)
                SCPreferencesSetValue(prefs, MODEL, model);
        }
 
                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;
 }
 
        return prefs;
 }
 
@@ -349,10 +359,11 @@ __private_extern__
 void
 __SCNetworkPopulateDefaultNIPrefs(SCPreferencesRef ni_prefs)
 {
 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)) {
 
        interfaces = (CFMutableArrayRef)SCPreferencesGetValue(ni_prefs, INTERFACES);
        if (isA_CFArray(interfaces)) {
@@ -416,6 +427,15 @@ __SCNetworkPopulateDefaultNIPrefs(SCPreferencesRef ni_prefs)
                SCPreferencesSetValue(ni_prefs, MODEL, model);
        }
 
                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;
        CFRelease(networkInterfaces);
 
        return;
index bfcf499e614a4e9e2c0592070ac49ff67927aa66..96795348fbaece6a8123f88255908732a379fe49 100644 (file)
@@ -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@
  *
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -968,6 +968,7 @@ _SCNetworkSetCreateDefault(SCPreferencesRef prefs)
        Boolean         ok              = TRUE;
        SCNetworkSetRef set;
        CFStringRef     setName         = NULL;
        Boolean         ok              = TRUE;
        SCNetworkSetRef set;
        CFStringRef     setName         = NULL;
+       CFNumberRef     version;
 
        set = SCNetworkSetCopyCurrent(prefs);
        if (set != NULL) {
 
        set = SCNetworkSetCopyCurrent(prefs);
        if (set != NULL) {
@@ -1009,6 +1010,15 @@ _SCNetworkSetCreateDefault(SCPreferencesRef prefs)
                SCPreferencesSetValue(prefs, MODEL, model);
        }
 
                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)) {
     done :
 
        if (!ok && (set != NULL)) {