X-Git-Url: https://git.saurik.com/apple/configd.git/blobdiff_plain/17d3ee29fb04fcc79d3be0b9d5c7bcb377cfc610..78deefe8e371573ba1c4e975adf72db0dddc81f9:/Plugins/KernelEventMonitor/ev_ipv4.c diff --git a/Plugins/KernelEventMonitor/ev_ipv4.c b/Plugins/KernelEventMonitor/ev_ipv4.c index 14e2979..55c4cf2 100644 --- a/Plugins/KernelEventMonitor/ev_ipv4.c +++ b/Plugins/KernelEventMonitor/ev_ipv4.c @@ -1,15 +1,15 @@ /* - * Copyright (c) 2002-2005, 2007, 2008, 2011 Apple Inc. All rights reserved. + * Copyright (c) 2002-2018 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ - * + * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. - * + * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, @@ -17,7 +17,7 @@ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. - * + * * @APPLE_LICENSE_HEADER_END@ */ @@ -29,19 +29,8 @@ */ #include "eventmon.h" -#include "cache.h" #include "ev_ipv4.h" -#ifndef kSCEntNetIPv4ARPCollision -#define kSCEntNetIPv4ARPCollision CFSTR("IPv4ARPCollision") -#endif /* kSCEntNetIPv4ARPCollision */ - -#if !TARGET_OS_IPHONE -#ifndef kSCEntNetIPv4PortInUse -#define kSCEntNetIPv4PortInUse CFSTR("PortInUse") -#endif /* kSCEntNetIPv4PortInUse */ -#endif /* !TARGET_OS_IPHONE */ - #define IP_FORMAT "%d.%d.%d.%d" #define IP_CH(ip, i) (((u_char *)(ip))[i]) #define IP_LIST(ip) IP_CH(ip,0),IP_CH(ip,1),IP_CH(ip,2),IP_CH(ip,3) @@ -80,7 +69,7 @@ copyIF(CFStringRef key, CFMutableDictionaryRef oldIFs, CFMutableDictionaryRef ne if (CFDictionaryGetValueIfPresent(newIFs, key, (const void **)&dict)) { newDict = CFDictionaryCreateMutableCopy(NULL, 0, dict); } else { - dict = cache_SCDynamicStoreCopyValue(store, key); + dict = SCDynamicStoreCopyValue(store, key); if (dict) { CFDictionarySetValue(oldIFs, key, dict); if (isA_CFDictionary(dict)) { @@ -116,9 +105,17 @@ updateStore(const void *key, const void *value, void *context) if (!dict || !CFEqual(dict, newDict)) { if (CFDictionaryGetCount(newDict) > 0) { - cache_SCDynamicStoreSetValue(store, key, newDict); + SC_log(LOG_DEBUG, "Update interface configuration: %@: %@", key, newDict); + SCDynamicStoreSetValue(store, key, newDict); } else if (dict) { - cache_SCDynamicStoreRemoveValue(store, key); + CFDictionaryRef oldDict; + + oldDict = SCDynamicStoreCopyValue(store, key); + if (oldDict != NULL) { + SC_log(LOG_DEBUG, "Update interface configuration: %@: ", key); + CFRelease(oldDict); + } + SCDynamicStoreRemoveValue(store, key); } network_changed = TRUE; } @@ -129,7 +126,7 @@ updateStore(const void *key, const void *value, void *context) __private_extern__ void -interface_update_ipv4(struct ifaddrs *ifap, const char *if_name) +ipv4_interface_update(struct ifaddrs *ifap, const char *if_name) { struct ifaddrs *ifa; struct ifaddrs *ifap_temp = NULL; @@ -151,7 +148,7 @@ interface_update_ipv4(struct ifaddrs *ifap, const char *if_name) if (!ifap) { if (getifaddrs(&ifap_temp) == -1) { - SCLog(TRUE, LOG_ERR, CFSTR("getifaddrs() failed: %s"), strerror(errno)); + SC_log(LOG_NOTICE, "getifaddrs() failed: %s", strerror(errno)); goto error; } ifap = ifap_temp; @@ -239,7 +236,7 @@ interface_update_ipv4(struct ifaddrs *ifap, const char *if_name) __private_extern__ void -interface_collision_ipv4(const char *if_name, struct in_addr ip_addr, int hw_len, const void * hw_addr) +ipv4_arp_collision(const char *if_name, struct in_addr ip_addr, int hw_len, const void * hw_addr) { uint8_t * hw_addr_bytes = (uint8_t *)hw_addr; int i; @@ -260,7 +257,8 @@ interface_collision_ipv4(const char *if_name, struct in_addr ip_addr, int hw_len CFStringAppendFormat(key, NULL, CFSTR("%s%02x"), (i == 0) ? "/" : ":", hw_addr_bytes[i]); } - cache_SCDynamicStoreNotifyValue(store, key); + SC_log(LOG_DEBUG, "Post ARP collision: %@", key); + SCDynamicStoreNotifyValue(store, key); CFRelease(key); CFRelease(prefix); CFRelease(if_name_cf); @@ -270,7 +268,7 @@ interface_collision_ipv4(const char *if_name, struct in_addr ip_addr, int hw_len #if !TARGET_OS_IPHONE __private_extern__ void -port_in_use_ipv4(uint16_t port, pid_t req_pid) +ipv4_port_in_use(uint16_t port, pid_t req_pid) { CFStringRef key; @@ -281,8 +279,42 @@ port_in_use_ipv4(uint16_t port, pid_t req_pid) kSCEntNetIPv4, kSCEntNetIPv4PortInUse, port, req_pid); - cache_SCDynamicStoreNotifyValue(store, key); + SC_log(LOG_DEBUG, "Post port-in-use: %@", key); + SCDynamicStoreNotifyValue(store, key); CFRelease(key); return; } #endif /* !TARGET_OS_IPHONE */ + +static void +interface_notify_entity(const char * if_name, const char * type, CFStringRef entity) +{ + CFStringRef if_name_cf; + CFStringRef key; + + if_name_cf = CFStringCreateWithCString(NULL, if_name, + kCFStringEncodingASCII); + key = SCDynamicStoreKeyCreateNetworkInterfaceEntity(NULL, + kSCDynamicStoreDomainState, + if_name_cf, + entity); + CFRelease(if_name_cf); + SC_log(LOG_DEBUG, "Post %s: %@", type, key); + SCDynamicStoreNotifyValue(store, key); + CFRelease(key); + return; +} + +__private_extern__ void +ipv4_router_arp_failure(const char * if_name) +{ + interface_notify_entity(if_name, "Router ARP failure", kSCEntNetIPv4RouterARPFailure); + return; +} + +__private_extern__ void +ipv4_router_arp_alive(const char * if_name) +{ + interface_notify_entity(if_name, "Router ARP alive", kSCEntNetIPv4RouterARPAlive); + return; +}