1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2012-2020 Apple Inc. All rights reserved.
6 * @header Interface to DNSX SPI
8 * @discussion Describes the functions and data structures
9 * that make up the DNSX SPI
12 #ifndef _DNS_SERVICES_H
13 #define _DNS_SERVICES_H
15 #include <dispatch/dispatch.h>
17 #if (defined(__GNUC__) && (__GNUC__ >= 4))
18 #define DNS_SERVICES_EXPORT __attribute__((visibility("default")))
20 #define DNS_SERVICES_EXPORT
23 // DNSXConnRef: Opaque internal data type
24 typedef struct _DNSXConnRef_t
*DNSXConnRef
;
29 kDNSX_UnknownErr
= -65537, /* 0xFFFE FFFF */
30 kDNSX_NoMem
= -65539, /* No Memory */
31 kDNSX_BadParam
= -65540, /* Client passed invalid arg */
32 kDNSX_Busy
= -65551, /* DNS Proxy already in use: incorrect use of SPI by client */
33 kDNSX_DaemonNotRunning
= -65563 /* Daemon not running */
36 // A max of 5 input interfaces can be processed
38 #define IfIndex uint64_t
39 #define kDNSIfindexAny 0
41 // Enable DNS Proxy with an appropriate parameter defined below
45 // Other values reserved for future use
48 /*********************************************************************************************
50 * Enable DNS Proxy Functionality
52 *********************************************************************************************/
54 /* DNSXEnableProxy : Turns ON the DNS Proxy (Details below)
56 * DNSXEnableProxyReply() parameters:
58 * connRef: The DNSXConnRef initialized by DNSXEnableProxy().
60 * errCode: Will be kDNSX_NoError on success, otherwise will indicate the
61 * failure that occurred.
65 typedef void (*DNSXEnableProxyReply
)
73 * Enables the DNS Proxy functionality which will remain ON until the client explicitly turns it OFF
74 * by passing the returned DNSXConnRef to DNSXRefDeAlloc(), or the client exits or crashes.
76 * DNSXEnableProxy() Parameters:
78 * connRef: A pointer to DNSXConnRef that is initialized to NULL.
79 * If the call succeeds it will be initialized to a non-NULL value.
80 * Client terminates the DNS Proxy by passing this DNSXConnRef to DNSXRefDeAlloc().
82 * proxyparam: Enable DNS Proxy functionality with parameters that are described in
83 * DNSProxyParameters above.
85 * inIfindexArr[MaxInputIf]: List of input interfaces from which the DNS queries will be accepted and
86 * forwarded to the output interface specified below. The daemon processes
87 * MaxInputIf entries in the list. For eg. if one has less than MaxInputIfs
88 * values, just initialize the other values to be 0. Note: This field needs to
89 * be initialized by the client.
91 * outIfindex: Output interface on which the query will be forwarded.
92 * Passing kDNSIfindexAny causes DNS Queries to be sent on the primary interface.
94 * Note: It is the responsibility of the client to ensure the input/output interface
97 * clientq: Queue the client wants to schedule the callBack on (Note: Must not be NULL)
99 * callBack: CallBack function for the client that indicates success or failure.
100 * Note: callback may be invoked more than once, For e.g. if enabling DNS Proxy
101 * first succeeds and the daemon possibly crashes sometime later.
103 * return value: Returns kDNSX_NoError when no error otherwise returns an error code indicating
104 * the error that occurred. Note: A return value of kDNSX_NoError does not mean
105 * that DNS Proxy was successfully enabled. The callBack may asynchronously
106 * return an error (such as kDNSX_DaemonNotRunning)
111 DNSXErrorType DNSXEnableProxy
113 DNSXConnRef
*connRef
,
114 DNSProxyParameters proxyparam
,
115 IfIndex inIfindexArr
[MaxInputIf
],
117 dispatch_queue_t clientq
,
118 DNSXEnableProxyReply callBack
121 typedef uint32_t DNSXProxyFlags
;
123 #define kDNSXProxyFlagNull 0 // No flags.
124 #define kDNSXProxyFlagForceAAAASynthesis (1U << 1) // Force AAAA synthesis during DNS64.
128 * Enables the DNS Proxy functionality which will remain ON until the client explicitly turns it OFF
129 * by passing the returned DNSXConnRef to DNSXRefDeAlloc(), or the client exits or crashes.
131 * DNSXEnableProxy64() Parameters:
133 * connRef: A pointer to DNSXConnRef that is initialized to NULL.
134 * If the call succeeds it will be initialized to a non-NULL value.
135 * Client terminates the DNS Proxy by passing this DNSXConnRef to DNSXRefDeAlloc().
137 * proxyparam: Enable DNS Proxy functionality with parameters that are described in
138 * DNSProxyParameters above.
140 * inIfindexArr[MaxInputIf]: List of input interfaces from which the DNS queries will be accepted and
141 * forwarded to the output interface specified below. The daemon processes
142 * MaxInputIf entries in the list. For eg. if one has less than MaxInputIfs
143 * values, just initialize the other values to be 0. Note: This field needs to
144 * be initialized by the client.
146 * outIfindex: Output interface on which the query will be forwarded.
147 * Passing kDNSIfindexAny causes DNS Queries to be sent on the primary interface.
149 * Note: It is the responsibility of the client to ensure the input/output interface
152 * ipv6Prefix: IPv6 prefix to use for DNS64.
154 * ipv6PrefixBitLength: Bit length of IPv6 prefix to use for DNS64.
156 * flags: Flags to specify additional behavioral aspects of the proxy.
158 * clientq: Queue the client wants to schedule the callBack on (Note: Must not be NULL)
160 * callBack: CallBack function for the client that indicates success or failure.
161 * Note: callback may be invoked more than once, For e.g. if enabling DNS Proxy
162 * first succeeds and the daemon possibly crashes sometime later.
164 * return value: Returns kDNSX_NoError when no error otherwise returns an error code indicating
165 * the error that occurred. Note: A return value of kDNSX_NoError does not mean
166 * that DNS Proxy was successfully enabled. The callBack may asynchronously
167 * return an error (such as kDNSX_DaemonNotRunning)
171 SPI_AVAILABLE(macos(10.16), ios(14.0), watchos(7.0), tvos(14.0))
172 DNSXErrorType DNSXEnableProxy64
174 DNSXConnRef
*connRef
,
175 DNSProxyParameters proxyparam
,
176 IfIndex inIfindexArr
[MaxInputIf
],
178 uint8_t ipv6Prefix
[16],
179 int ipv6PrefixBitLength
,
180 DNSXProxyFlags flags
,
181 dispatch_queue_t clientq
,
182 DNSXEnableProxyReply callBack
187 * Terminate a connection with the daemon and free memory associated with the DNSXConnRef.
188 * Used to Disable DNS Proxy on that connection.
190 * connRef: A DNSXConnRef initialized by any of the DNSX*() calls.
194 void DNSXRefDeAlloc(DNSXConnRef connRef
);