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;
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
{
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;
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;
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;
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;
}
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);
});
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
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)
{
_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;
}
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); }
}
#include <os/log.h>
#include <mach/mach_time.h>
#include <net/ntstat.h>
+#include <ifaddrs.h>
enum
{
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)
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
#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)
{
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
(*result) = tempRes;
return 0;
}
+ free(tempRes);
}
break;
{
#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;
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
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