]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/CUPolicy.c
mDNSResponder-544.tar.gz
[apple/mdnsresponder.git] / mDNSMacOSX / CUPolicy.c
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2013 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #include "mDNSMacOSX.h"
19 #include <network/config.h>
20
21 #if TARGET_OS_IPHONE
22
23 mDNSexport void CUPInit(mDNS *const m)
24 {
25
26 m->p->handle = cellular_usage_policy_create_client();
27 if (!m->p->handle)
28 {
29 LogMsg("CUPInit: cellular_usage_policy_create_client failed");
30 }
31 }
32
33 mDNSexport mDNSBool mDNSPlatformAllowPID(mDNS *const m, DNSQuestion *q)
34 {
35 // Currently the policy applies only for DNS requests sent over cellular interface
36 if (m->p->handle && q->qDNSServer && q->qDNSServer->cellIntf)
37 {
38 mDNSBool allowed;
39 if (q->pid)
40 {
41 allowed = (mDNSBool) cellular_usage_policy_is_data_allowed_for_pid(m->p->handle, q->pid);
42 if (!allowed)
43 {
44 xpc_object_t pidx = xpc_uint64_create(q->pid);
45 if (pidx)
46 {
47 network_config_cellular_blocked_notify(pidx, NULL, NULL);
48 LogInfo("mDNSPlaformAllowPID: Notified PID(%d) for %##s (%s)", q->pid, q->qname.c, DNSTypeName(q->qtype));
49 xpc_release(pidx);
50 }
51 }
52 }
53 else
54 {
55 allowed = (mDNSBool) cellular_usage_policy_is_data_allowed_for_uuid(m->p->handle, q->uuid);
56 if (!allowed)
57 {
58 xpc_object_t uuidx = xpc_uuid_create(q->uuid);
59 if (uuidx)
60 {
61 network_config_cellular_blocked_notify(NULL, uuidx, NULL);
62 LogInfo("mDNSPlaformAllowPID: Notified UUID for %##s (%s)", q->qname.c, DNSTypeName(q->qtype));
63 xpc_release(uuidx);
64 }
65 }
66 }
67 return allowed;
68 }
69 else
70 {
71 return mDNStrue;
72 }
73 }
74
75 #else // TARGET_OS_IPHONE
76
77 mDNSexport void CUPInit(mDNS *const m)
78 {
79 (void)m; //unused
80 }
81
82 mDNSexport mDNSBool mDNSPlatformAllowPID(mDNS *const m, DNSQuestion *q)
83 {
84 (void)m; //unused
85 (void)q; //unused
86 //LogMsg("mDNSPlatformAllowPID: %##s (%s)", q->qname.c, DNSTypeName(q->qtype));
87 return mDNStrue;
88 }
89
90 #endif // TARGET_OS_IPHONE
91