From ff4fe4c30788b558815d52739e3b35d9bc21e831 Mon Sep 17 00:00:00 2001 From: Apple Date: Wed, 5 Jun 2019 22:47:12 +0000 Subject: [PATCH] Libinfo-538.tar.gz --- Libinfo/pseudo_public.h | 1 + gen.subproj/configuration_profile.c | 4 ++-- gen.subproj/vars.c | 1 + lookup.subproj/file_module.c | 19 ++++++++++++++--- lookup.subproj/mdns_module.c | 8 +++---- lookup.subproj/muser_module.c | 2 +- lookup.subproj/si_compare.c | 33 +++++++++++++++++++++++++++-- lookup.subproj/si_getaddrinfo.c | 8 +++++++ membership.subproj/membership.c | 6 +++++- xcodescripts/Libinfo.xcconfig | 3 +-- 10 files changed, 70 insertions(+), 15 deletions(-) diff --git a/Libinfo/pseudo_public.h b/Libinfo/pseudo_public.h index 6007b51..063b6a3 100644 --- a/Libinfo/pseudo_public.h +++ b/Libinfo/pseudo_public.h @@ -60,6 +60,7 @@ unsigned int if_nametoindex(const char *ifname); extern const struct in6_addr in6addr_any; extern const struct in6_addr in6addr_linklocal_allnodes; extern const struct in6_addr in6addr_linklocal_allrouters; +extern const struct in6_addr in6addr_linklocal_allv2routers; extern const struct in6_addr in6addr_loopback; extern const struct in6_addr in6addr_nodelocal_allnodes; diff --git a/gen.subproj/configuration_profile.c b/gen.subproj/configuration_profile.c index 7ee5363..abdbd3e 100644 --- a/gen.subproj/configuration_profile.c +++ b/gen.subproj/configuration_profile.c @@ -44,7 +44,7 @@ configuration_profile_create_notification_key(const char *ident) return out; } -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) if (strchr(ident + 1, '/') != NULL) return NULL; asprintf(&out, "%s%s/%s.plist", NOTIFY_PATH_SERVICE, CPROF_PATH, ident); #endif @@ -68,7 +68,7 @@ configuration_profile_copy_property_list(const char *ident) { snprintf(path, sizeof(path), "%s", ident); } -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) else { if (strchr(ident + 1, '/') != NULL) return NULL; diff --git a/gen.subproj/vars.c b/gen.subproj/vars.c index 13fb5d0..78102eb 100644 --- a/gen.subproj/vars.c +++ b/gen.subproj/vars.c @@ -45,4 +45,5 @@ LIBINFO_EXPORT const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT; LIBINFO_EXPORT const struct in6_addr in6addr_nodelocal_allnodes = IN6ADDR_NODELOCAL_ALLNODES_INIT; LIBINFO_EXPORT const struct in6_addr in6addr_linklocal_allnodes = IN6ADDR_LINKLOCAL_ALLNODES_INIT; LIBINFO_EXPORT const struct in6_addr in6addr_linklocal_allrouters = IN6ADDR_LINKLOCAL_ALLROUTERS_INIT; +LIBINFO_EXPORT const struct in6_addr in6addr_linklocal_allv2routers = IN6ADDR_LINKLOCAL_ALLV2ROUTERS_INIT; diff --git a/lookup.subproj/file_module.c b/lookup.subproj/file_module.c index 57b1d90..4f56dbc 100644 --- a/lookup.subproj/file_module.c +++ b/lookup.subproj/file_module.c @@ -341,7 +341,7 @@ _fsi_get_validation(si_mod_t *si, int vtype, const char *path, FILE *f, uint64_t static int _fsi_validate(si_mod_t *si, int cat, uint64_t va, uint64_t vb) { -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) struct stat sb; const char *path; uint32_t item_val, curr_val, vtype; @@ -351,7 +351,7 @@ _fsi_validate(si_mod_t *si, int cat, uint64_t va, uint64_t vb) if (si == NULL) return 0; -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) /* /etc is on a read-only filesystem, so no validation is required */ pp = (file_si_private_t *)si->private; @@ -1862,7 +1862,20 @@ _fsi_fs_root(si_mod_t *si) } root_spec = _fsi_get_device_path(rootstat.st_dev); - + + // In case root is mounted from snapshot, _fsi_get_device_path will return NULL as the device name does not comply to + // /dev/diskAAsBB, but in the format of snap@/dev/diskAAsBB, in that case f_mntfromname has the correct device name, so return it + if (root_spec == NULL) { + const char *mntfromname = rootfsinfo.f_mntfromname; + size_t len = sizeof(rootfsinfo.f_mntfromname); + const char *p; + while ((p = strnstr(mntfromname, "@", len))) { + len -= p + 1 - mntfromname; + mntfromname = p + 1; + } + root_spec = strndup(mntfromname, len); + } + rootfs = (si_item_t *)LI_ils_create("L4488sssss44", (unsigned long)si, CATEGORY_FS, 1, 0LL, 0LL, root_spec, root_path, rootfsinfo.f_fstypename, FSTAB_RW, FSTAB_RW, 0, 1); free(root_spec); }); diff --git a/lookup.subproj/mdns_module.c b/lookup.subproj/mdns_module.c index 34468a8..f5b4d30 100644 --- a/lookup.subproj/mdns_module.c +++ b/lookup.subproj/mdns_module.c @@ -1790,10 +1790,10 @@ _mdns_search_ex(const char *name, int class, int type, uint32_t ifindex, DNSServ if (name == NULL) return -1; -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) /* log a warning for queries from the main thread */ if (pthread_is_threaded_np() && pthread_main_np()) os_log(OS_LOG_DEFAULT, "Warning: Libinfo call to mDNSResponder on main thread"); -#endif /* TARGET_OS_EMBEDDED */ +#endif /* (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) */ /* * Timeout Logic @@ -1881,7 +1881,7 @@ _mdns_search_ex(const char *name, int class, int type, uint32_t ifindex, DNSServ if (err != 0) _mdns_debug_message(";; initialization error %d\n", err); /* try to reinitialize */ - if ((err == kDNSServiceErr_Unknown) || (err == kDNSServiceErr_ServiceNotRunning) || (err == kDNSServiceErr_BadReference)) + if ((err == kDNSServiceErr_Unknown) || (err == kDNSServiceErr_ServiceNotRunning) || (err == kDNSServiceErr_BadReference) || (err == kDNSServiceErr_DefunctConnection)) { if (_mdns_sdref != NULL) { @@ -1938,7 +1938,7 @@ _mdns_search_ex(const char *name, int class, int type, uint32_t ifindex, DNSServ _mdns_debug_message(";; _mdns_search calling DNSServiceProcessResult\n", err); err = DNSServiceProcessResult(_mdns_sdref); _mdns_debug_message(";; DNSServiceProcessResult -> %s\n", err); - if ((err == kDNSServiceErr_ServiceNotRunning) || (err == kDNSServiceErr_BadReference)) + if ((err == kDNSServiceErr_ServiceNotRunning) || (err == kDNSServiceErr_BadReference) || (err == kDNSServiceErr_DefunctConnection)) { _mdns_debug_message(";; DNSServiceProcessResult status %d [ctx %p %p]\n", err, (n_ctx > 0) ? &(ctx[0]) : NULL, (n_ctx > 1) ? &(ctx[1]) : NULL); err = 0; diff --git a/lookup.subproj/muser_module.c b/lookup.subproj/muser_module.c index 8d4d5cb..9de0993 100644 --- a/lookup.subproj/muser_module.c +++ b/lookup.subproj/muser_module.c @@ -138,7 +138,7 @@ _muser_xpc_pipe(bool reset) } if (__muser_pipe == NULL) { - __muser_pipe = xpc_pipe_create(kLibinfoMultiuserPortName, 0); + __muser_pipe = xpc_pipe_create(kLibinfoMultiuserPortName, XPC_PIPE_USE_SYNC_IPC_OVERRIDE | XPC_PIPE_PROPAGATE_QOS); if (!_si_muser_disabled) { _si_muser_disabled = _muser_xpc_pipe_disabled(__muser_pipe); } } diff --git a/lookup.subproj/si_compare.c b/lookup.subproj/si_compare.c index e7e1994..e879c2e 100644 --- a/lookup.subproj/si_compare.c +++ b/lookup.subproj/si_compare.c @@ -24,6 +24,7 @@ #include #include #include +#include enum { @@ -83,8 +84,6 @@ static uint64_t cache_timeout = 0ULL; static os_log_t si_destination_log = OS_LOG_DEFAULT; static DestCompareSettings si_compare_settings = {}; -static const uint32_t kLoopbackIndex = 1; - #ifndef TCP_RTT_SCALE #define TCP_RTT_SCALE 32 // see netinet/tcp_var.h #endif // defined(TCP_RTT_SCALE) @@ -107,6 +106,8 @@ static void si_destination_compare_child_has_forked(void) { cache_lock = OS_UNFAIR_LOCK_INIT; + // Cannot use os_log_t object from parent process in child process. + si_destination_log = OS_LOG_DEFAULT; } static void @@ -297,12 +298,40 @@ si_destination_fill_netsrc(Destination *d) #pragma mark -- Statistics -- +static uint32_t kLoopbackIndex = 1; + +// Only update kLoopbackIndex from the default value of 1 if an entry with the IFF_LOOPBACK flag set is found. +void +set_loopback_ifindex() +{ + struct ifaddrs *ifaddrs, *ifa; + + if (getifaddrs(&ifaddrs) < 0) + return; + + for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { + if (ifa->ifa_addr && + ifa->ifa_addr->sa_family == AF_LINK && + (ifa->ifa_flags & IFF_LOOPBACK) != 0) { + kLoopbackIndex = (unsigned int)((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index; + break; + } + } + + freeifaddrs(ifaddrs); + return; +} + static int si_destination_compare_statistics( Destination *dst1, Destination *dst2) { int slightPreference = kPrefer_Equal; + // Initialize kLoopbackIndex value + static pthread_once_t once = PTHREAD_ONCE_INIT; + pthread_once(&once, set_loopback_ifindex); + // If we have min round trip times for both, use that if (dst1->d_min_rtt && dst2->d_min_rtt) { diff --git a/lookup.subproj/si_getaddrinfo.c b/lookup.subproj/si_getaddrinfo.c index 6f6930c..dc7677a 100644 --- a/lookup.subproj/si_getaddrinfo.c +++ b/lookup.subproj/si_getaddrinfo.c @@ -76,10 +76,18 @@ typedef struct { uint64_t ttl; } build_hostent_t; +static void +gai_child_has_forked(void) +{ + // Cannot use os_log_t object from parent process in child process. + _gai_log = OS_LOG_DEFAULT; +} + static void gai_log_init(void) { _gai_log = os_log_create("com.apple.network.libinfo", "getaddrinfo"); + (void)pthread_atfork(NULL, NULL, gai_child_has_forked); } static os_log_t diff --git a/membership.subproj/membership.c b/membership.subproj/membership.c index 55c6a3e..2186a8b 100644 --- a/membership.subproj/membership.c +++ b/membership.subproj/membership.c @@ -283,6 +283,7 @@ mbr_identifier_translate(int id_type, const void *identifier, size_t identifier_ (*result) = tempRes; return 0; } + free(tempRes); } break; @@ -648,7 +649,10 @@ mbr_reset_cache() { #ifdef DS_AVAILABLE MBR_OS_ACTIVITY("Membership API: Flush the membership cache"); - _od_rpc_call("mbr_cache_flush", NULL, _mbr_xpc_pipe); + xpc_object_t result = _od_rpc_call("mbr_cache_flush", NULL, _mbr_xpc_pipe); + if (result) { + xpc_release(result); + } return 0; #else return EIO; diff --git a/xcodescripts/Libinfo.xcconfig b/xcodescripts/Libinfo.xcconfig index 3e5caf0..da29a65 100644 --- a/xcodescripts/Libinfo.xcconfig +++ b/xcodescripts/Libinfo.xcconfig @@ -37,7 +37,6 @@ LIBM_LDFLAGS = -lsystem_m LIBDYLD_LDFLAGS = -ldyld LIBC_LDFLAGS = -lsystem_c LIBDISPATCH_LDFLAGS = -ldispatch -LIBLAUNCH_LDFLAGS = -llaunch LIBASL_LDFLAGS = -lsystem_asl LIBBLOCKS_LDFLAGS = -lsystem_blocks LIBDNSD_LDFLAGS = -lsystem_dnssd @@ -76,7 +75,7 @@ OTHER_CFLAGS = -DDEBUG=1 DYLIB_COMPATIBILITY_VERSION = 1 -OTHER_LDFLAGS = -all_load -umbrella System -L/usr/lib/system $(LIBCOMPILER_RT_LDFLAGS) $(LIBDYLD_LDFLAGS) $(LIBSYSCALL_LDFLAGS) $(LIBMALLOC_LDFLAGS) $(LIBPLATFORM_LDFLAGS) $(LIBPTHREAD_LDFLAGS) $(LIBC_LDFLAGS) $(LIBDISPATCH_LDFLAGS) $(LIBLAUNCH_LDFLAGS) $(LIBASL_LDFLAGS) $(LIBBLOCKS_LDFLAGS) $(LIBDNSD_LDFLAGS) $(LIBNOTIFY_LDFLAGS) $(LIBXPC_LDFLAGS) $(LIBTRACE_LDFLAGS) +OTHER_LDFLAGS = -all_load -umbrella System -L/usr/lib/system $(LIBCOMPILER_RT_LDFLAGS) $(LIBDYLD_LDFLAGS) $(LIBSYSCALL_LDFLAGS) $(LIBMALLOC_LDFLAGS) $(LIBPLATFORM_LDFLAGS) $(LIBPTHREAD_LDFLAGS) $(LIBC_LDFLAGS) $(LIBDISPATCH_LDFLAGS) $(LIBASL_LDFLAGS) $(LIBBLOCKS_LDFLAGS) $(LIBDNSD_LDFLAGS) $(LIBNOTIFY_LDFLAGS) $(LIBXPC_LDFLAGS) $(LIBTRACE_LDFLAGS) // Text-Based API settings -- 2.45.2