1 | /* -*- Mode: C; tab-width: 4 -*- |
---|
2 | * |
---|
3 | * Copyright (c) 2012-2015 Apple Inc. All rights reserved. |
---|
4 | * |
---|
5 | * |
---|
6 | * @header Interface to DNSX SPI |
---|
7 | * |
---|
8 | * @discussion Describes the functions and data structures |
---|
9 | * that make up the DNSX SPI |
---|
10 | */ |
---|
11 | |
---|
12 | #ifndef _DNS_SERVICES_H |
---|
13 | #define _DNS_SERVICES_H |
---|
14 | |
---|
15 | #include <dispatch/dispatch.h> |
---|
16 | |
---|
17 | // DNSXConnRef: Opaque internal data type |
---|
18 | typedef struct _DNSXConnRef_t *DNSXConnRef; |
---|
19 | |
---|
20 | typedef enum |
---|
21 | { |
---|
22 | kDNSX_NoError = 0, |
---|
23 | kDNSX_UnknownErr = -65537, /* 0xFFFE FFFF */ |
---|
24 | kDNSX_NoMem = -65539, /* No Memory */ |
---|
25 | kDNSX_BadParam = -65540, /* Client passes invalid arg/Bad use of SPI */ |
---|
26 | kDNSX_DaemonNotRunning = -65563 /* Daemon not running */ |
---|
27 | } DNSXErrorType; |
---|
28 | |
---|
29 | // A max of 5 input interfaces can be processed |
---|
30 | #define MaxInputIf 5 |
---|
31 | #define IfIndex uint64_t |
---|
32 | #define kDNSIfindexAny 0 |
---|
33 | |
---|
34 | // Enable DNS Proxy with an appropriate parameter defined below |
---|
35 | typedef enum |
---|
36 | { |
---|
37 | kDNSProxyEnable = 1 |
---|
38 | // Other values reserved for future use |
---|
39 | } DNSProxyParameters; |
---|
40 | |
---|
41 | /********************************************************************************************* |
---|
42 | * |
---|
43 | * Enable DNS Proxy Functionality |
---|
44 | * |
---|
45 | *********************************************************************************************/ |
---|
46 | |
---|
47 | /* DNSXEnableProxy : Turns ON the DNS Proxy (Details below) |
---|
48 | * |
---|
49 | * DNSXEnableProxyReply() parameters: |
---|
50 | * |
---|
51 | * connRef: The DNSXConnRef initialized by DNSXEnableProxy(). |
---|
52 | * |
---|
53 | * errCode: Will be kDNSX_NoError on success, otherwise will indicate the |
---|
54 | * failure that occurred. |
---|
55 | * |
---|
56 | */ |
---|
57 | |
---|
58 | typedef void (*DNSXEnableProxyReply) |
---|
59 | ( |
---|
60 | DNSXConnRef connRef, |
---|
61 | DNSXErrorType errCode |
---|
62 | ); |
---|
63 | |
---|
64 | /* DNSXEnableProxy |
---|
65 | * |
---|
66 | * Enables the DNS Proxy functionality which will remain ON until the client explicitly turns it OFF |
---|
67 | * by passing the returned DNSXConnRef to DNSXRefDeAlloc(), or the client exits or crashes. |
---|
68 | * |
---|
69 | * DNSXEnableProxy() Parameters: |
---|
70 | * |
---|
71 | * connRef: A pointer to DNSXConnRef that is initialized to NULL. |
---|
72 | * If the call succeeds it will be initialized to a non-NULL value. |
---|
73 | * Client terminates the DNS Proxy by passing this DNSXConnRef to DNSXRefDeAlloc(). |
---|
74 | * |
---|
75 | * proxyparam: Enable DNS Proxy functionality with parameters that are described in |
---|
76 | * DNSProxyParameters above. |
---|
77 | * |
---|
78 | * inIfindexArr[MaxInputIf]: List of input interfaces from which the DNS queries will be accepted and |
---|
79 | * forwarded to the output interface specified below. The daemon processes |
---|
80 | * MaxInputIf entries in the list. For eg. if one has less than MaxInputIfs |
---|
81 | * values, just initialize the other values to be 0. Note: This field needs to |
---|
82 | * be initialized by the client. |
---|
83 | * |
---|
84 | * outIfindex: Output interface on which the query will be forwarded. |
---|
85 | * Passing kDNSIfindexAny causes DNS Queries to be sent on the primary interface. |
---|
86 | * |
---|
87 | * Note: It is the responsibility of the client to ensure the input/output interface |
---|
88 | * indexes are valid. |
---|
89 | * |
---|
90 | * clientq: Queue the client wants to schedule the callBack on (Note: Must not be NULL) |
---|
91 | * |
---|
92 | * callBack: CallBack function for the client that indicates success or failure. |
---|
93 | * Note: callback may be invoked more than once, For e.g. if enabling DNS Proxy |
---|
94 | * first succeeds and the daemon possibly crashes sometime later. |
---|
95 | * |
---|
96 | * return value: Returns kDNSX_NoError when no error otherwise returns an error code indicating |
---|
97 | * the error that occurred. Note: A return value of kDNSX_NoError does not mean |
---|
98 | * that DNS Proxy was successfully enabled. The callBack may asynchronously |
---|
99 | * return an error (such as kDNSX_DaemonNotRunning) |
---|
100 | * |
---|
101 | */ |
---|
102 | |
---|
103 | DNSXErrorType DNSXEnableProxy |
---|
104 | ( |
---|
105 | DNSXConnRef *connRef, |
---|
106 | DNSProxyParameters proxyparam, |
---|
107 | IfIndex inIfindexArr[MaxInputIf], |
---|
108 | IfIndex outIfindex, |
---|
109 | dispatch_queue_t clientq, |
---|
110 | DNSXEnableProxyReply callBack |
---|
111 | ); |
---|
112 | |
---|
113 | /* DNSXRefDeAlloc() |
---|
114 | * |
---|
115 | * Terminate a connection with the daemon and free memory associated with the DNSXConnRef. |
---|
116 | * Used to Disable DNS Proxy on that connection. |
---|
117 | * |
---|
118 | * connRef: A DNSXConnRef initialized by any of the DNSX*() calls. |
---|
119 | * |
---|
120 | */ |
---|
121 | void DNSXRefDeAlloc(DNSXConnRef connRef); |
---|
122 | |
---|
123 | #endif |
---|