/*
- * Copyright (c) 2013-2014 Apple Inc. All rights reserved.
+ * Copyright (c) 2013-2017 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,
* 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@
*/
#include "IPMonitorControlPrivate.h"
#include <SystemConfiguration/SCPrivate.h>
-STATIC Boolean * S_verbose;
-
#ifdef TEST_IPMONITOR_CONTROL
-#define my_log(__level, fmt, ...) SCPrint(TRUE, stdout, CFSTR(fmt "\n"), ## __VA_ARGS__)
+#define my_log(__level, __format, ...) SCPrint(TRUE, stdout, CFSTR(__format "\n"), ## __VA_ARGS__)
#else /* TEST_IPMONITOR_CONTROL */
#include "ip_plugin.h"
CFArrayAppendValue(S_if_changes, ifname);
S_if_changes_range.length = 1;
}
- else if (CFArrayContainsValue(S_if_changes, S_if_changes_range,
- ifname) == FALSE) {
+ else if (!CFArrayContainsValue(S_if_changes, S_if_changes_range, ifname)) {
CFArrayAppendValue(S_if_changes, ifname);
S_if_changes_range.length++;
}
= CFDictionaryCreateMutable(NULL, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
- CFDictionarySetValue(*assertions_p, key, value);
+ CFDictionarySetValue(*assertions_p, key, rank);
return;
}
existing_rank = CFDictionaryGetValue(*assertions_p, key);
if (existing_rank == NULL
|| (CFNumberCompare(rank, existing_rank, NULL)
== kCFCompareGreaterThan)) {
- CFDictionarySetValue(*assertions_p, key, value);
+ CFDictionarySetValue(*assertions_p, key, rank);
}
return;
}
STATIC void
AddChangedInterface(const void * key, const void * value, void * context)
{
+#pragma unused(value)
+#pragma unused(context)
InterfaceChangedListAddInterface((CFStringRef)key);
return;
}
STATIC void
ControlSessionInvalidate(ControlSessionRef session)
{
- if (*S_verbose) {
- my_log(LOG_NOTICE, "Invalidating %p", session);
- }
+ my_log(LOG_DEBUG, "Invalidating %p", session);
LIST_REMOVE(session, link);
if (session->assertions != NULL) {
my_log(LOG_DEBUG,
"IPMonitorControlServer: %p pid %d removing assertions %@",
- session->connection,
+ session->connection,
xpc_connection_get_pid(session->connection),
session->assertions);
CFDictionaryApplyFunction(session->assertions, AddChangedInterface,
STATIC void
ControlSessionRelease(void * p)
{
- if (*S_verbose) {
- my_log(LOG_NOTICE, "Releasing %p", p);
- }
+ my_log(LOG_DEBUG, "Releasing %p", p);
free(p);
return;
}
xpc_connection_set_finalizer_f(connection, ControlSessionRelease);
xpc_connection_set_context(connection, session);
LIST_INSERT_HEAD(&S_ControlSessions, session, link);
- if (*S_verbose) {
- my_log(LOG_NOTICE, "Created %p (connection %p)", session, connection);
- }
+ my_log(LOG_DEBUG, "Created %p (connection %p)", session, connection);
return (session);
}
}
ifname_cf = CFStringCreateWithCString(NULL, ifname,
kCFStringEncodingUTF8);
-
+
if (rank == kSCNetworkServicePrimaryRankDefault) {
CFDictionaryRemoveValue(session->assertions, ifname_cf);
if (CFDictionaryGetCount(session->assertions) == 0) {
xpc_object_t request,
xpc_object_t reply)
{
+#pragma unused(reply)
const char * ifname;
SCNetworkServicePrimaryRank rank;
ControlSessionRef session;
- if (IPMonitorControlServerValidateConnection(connection) == FALSE) {
- my_log(LOG_DEBUG,
- "IPMonitorControlServer: %p pid %d permission denied",
+ if (!IPMonitorControlServerValidateConnection(connection)) {
+ my_log(LOG_INFO, "connection %p pid %d permission denied",
connection, xpc_connection_get_pid(connection));
return (EPERM);
}
- ifname
+ ifname
= xpc_dictionary_get_string(request,
kIPMonitorControlRequestKeyInterfaceName);
if (ifname == NULL) {
}
session = ControlSessionGet(connection);
ControlSessionSetInterfaceRank(session, ifname, rank);
- my_log(LOG_DEBUG,
- "IPMonitorControlServer: %p pid %d set %s %u",
+ my_log(LOG_INFO, "connection %p pid %d set %s %u",
connection, xpc_connection_get_pid(connection), ifname, rank);
return (0);
}
/* no session, no rank assertion */
return (ENOENT);
}
- ifname
+ ifname
= xpc_dictionary_get_string(request,
kIPMonitorControlRequestKeyInterfaceName);
if (ifname == NULL) {
{
ControlSessionRef session;
- if (*S_verbose) {
- my_log(LOG_NOTICE, "IPMonitorControlServer: client %p went away",
- connection);
- }
+ my_log(LOG_DEBUG, "IPMonitorControlServer: client %p went away", connection);
session = ControlSessionLookup(connection);
if (session == NULL) {
/* never asserted anything */
xpc_object_t request)
{
xpc_type_t type;
-
+
type = xpc_get_type(request);
if (type == XPC_TYPE_DICTIONARY) {
int error = 0;
uint64_t request_type;
xpc_connection_t remote;
xpc_object_t reply;
-
- request_type
+
+ request_type
= xpc_dictionary_get_uint64(request,
kIPMonitorControlRequestKeyType);
reply = xpc_dictionary_create_reply(request);
IPMonitorControlServerHandleDisconnect(connection);
}
else if (request == XPC_ERROR_CONNECTION_INTERRUPTED) {
- my_log(LOG_NOTICE,
- "IPMonitorControlServer: connection interrupted");
+ my_log(LOG_INFO, "connection interrupted");
}
}
else {
- my_log(LOG_NOTICE, "IPMonitorControlServer: unexpected event");
+ my_log(LOG_NOTICE, "unexpected event");
}
return;
}
IPMonitorControlServerHandleRequest(connection, event);
};
xpc_connection_set_event_handler(connection, handler);
+ xpc_connection_set_target_queue(connection, S_IPMonitorControlServerQueue);
xpc_connection_resume(connection);
return;
}
}
handler = ^(xpc_object_t event) {
xpc_type_t type;
-
+
type = xpc_get_type(event);
if (type == XPC_TYPE_CONNECTION) {
IPMonitorControlServerHandleNewConnection(event);
}
else if (type == XPC_TYPE_ERROR) {
const char * desc;
-
+
desc = xpc_dictionary_get_string(event, XPC_ERROR_KEY_DESCRIPTION);
if (event == XPC_ERROR_CONNECTION_INVALID) {
- my_log(LOG_NOTICE, "IPMonitorControlServer: %s", desc);
+ my_log(LOG_NOTICE, "%s", desc);
xpc_release(connection);
}
else {
- my_log(LOG_NOTICE, "IPMonitorControlServer: %s", desc);
- }
+ my_log(LOG_NOTICE, "%s", desc);
+ }
}
else {
- my_log(LOG_NOTICE, "IPMonitorControlServer: unknown event %p",
- type);
+ my_log(LOG_NOTICE, "unknown event %p", type);
}
};
S_IPMonitorControlServerQueue = queue;
IPMonitorControlServerStart(CFRunLoopRef runloop, CFRunLoopSourceRef rls,
Boolean * verbose)
{
+#pragma unused(verbose)
dispatch_queue_t q;
xpc_connection_t connection;
- S_verbose = verbose;
SetNotificationInfo(runloop, rls);
q = dispatch_queue_create("IPMonitorControlServer", NULL);
connection = IPMonitorControlServerCreate(q, kIPMonitorControlServerName);