]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/CUPolicy.c
187748e1ca11ea3ffe921c1eba087489f75c06cb
[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 xpc_object_t uuidx = xpc_uuid_create(q->uuid);
56 if (uuidx)
57 {
58 allowed = (mDNSBool) cellular_usage_policy_is_data_allowed_for_uuid(m->p->handle, uuidx);
59 if (!allowed)
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 }
64 xpc_release(uuidx);
65 }
66 else
67 {
68 allowed = false;
69 }
70 }
71 return allowed;
72 }
73 else
74 {
75 return mDNStrue;
76 }
77 }
78
79 #else // TARGET_OS_IPHONE
80
81 mDNSexport void CUPInit(mDNS *const m)
82 {
83 (void)m; //unused
84 }
85
86 mDNSexport mDNSBool mDNSPlatformAllowPID(mDNS *const m, DNSQuestion *q)
87 {
88 (void)m; //unused
89 (void)q; //unused
90 //LogMsg("mDNSPlatformAllowPID: %##s (%s)", q->qname.c, DNSTypeName(q->qtype));
91 return mDNStrue;
92 }
93
94 #endif // TARGET_OS_IPHONE
95