blob: 9176996e72499f941cc06b61670d38c62424e9cb [file] [log] [blame]
Bernie Innocenti55864192018-08-30 04:05:20 +09001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
Bernie Innocenti189eb502018-10-01 23:10:18 +090028#ifndef NETD_RESOLV_RESOLV_H
29#define NETD_RESOLV_RESOLV_H
Bernie Innocenti55864192018-08-30 04:05:20 +090030
Bernie Innocenti189eb502018-10-01 23:10:18 +090031/*
32 * This header contains declarations related to per-network DNS server selection.
33 * They are used by system/netd/ and should not be exposed by the public NDK headers.
Bernie Innocenti55864192018-08-30 04:05:20 +090034 */
Bernie Innocenti55864192018-08-30 04:05:20 +090035#include <netinet/in.h>
Bernie Innocentia8cfe092018-09-13 16:00:42 +090036
Bernie Innocenti189eb502018-10-01 23:10:18 +090037#include "params.h"
Bernie Innocenti55864192018-08-30 04:05:20 +090038
nuccachene172a4e2018-10-23 17:10:58 +080039typedef union sockaddr_union {
40 struct sockaddr sa;
41 struct sockaddr_in sin;
42 struct sockaddr_in6 sin6;
43} sockaddr_union;
44
Bernie Innocenti55864192018-08-30 04:05:20 +090045/*
46 * Passing NETID_UNSET as the netId causes system/netd/server/DnsProxyListener.cpp to
47 * fill in the appropriate default netId for the query.
48 */
49#define NETID_UNSET 0u
50
51/*
52 * MARK_UNSET represents the default (i.e. unset) value for a socket mark.
53 */
54#define MARK_UNSET 0u
55
Bernie Innocenti55864192018-08-30 04:05:20 +090056struct __res_params;
57struct addrinfo;
Bernie Innocentiee1b85b2018-09-25 14:23:19 +090058struct hostent;
Bernie Innocenti55864192018-08-30 04:05:20 +090059
60/*
61 * A struct to capture context relevant to network operations.
62 *
63 * Application and DNS netids/marks can differ from one another under certain
64 * circumstances, notably when a VPN applies to the given uid's traffic but the
65 * VPN network does not have its own DNS servers explicitly provisioned.
66 *
67 * The introduction of per-UID routing means the uid is also an essential part
68 * of the evaluation context. Its proper uninitialized value is
69 * NET_CONTEXT_INVALID_UID.
70 */
71struct android_net_context {
72 unsigned app_netid;
73 unsigned app_mark;
74 unsigned dns_netid;
75 unsigned dns_mark;
76 uid_t uid;
77 unsigned flags;
Bernie Innocenti55864192018-08-30 04:05:20 +090078};
79
Bernie Innocentif12d5bb2018-08-31 14:09:46 +090080#define NET_CONTEXT_INVALID_UID ((uid_t) -1)
Bernie Innocenti55864192018-08-30 04:05:20 +090081
Bernie Innocentif12d5bb2018-08-31 14:09:46 +090082#define NET_CONTEXT_FLAG_USE_LOCAL_NAMESERVERS 0x00000001
83#define NET_CONTEXT_FLAG_USE_EDNS 0x00000002
Bernie Innocenti55864192018-08-30 04:05:20 +090084
Mike Yua46fae72018-11-01 20:07:00 +080085struct ExternalPrivateDnsStatus {
86 PrivateDnsMode mode;
87 unsigned numServers;
88 struct PrivateDnsInfo {
89 sockaddr_storage ss;
90 const char* hostname;
91 Validation validation;
92 } serverStatus[MAXNS];
93};
94
95typedef void (*private_dns_validated_callback)(unsigned netid, const char* server,
96 const char* hostname, bool success);
97
Bernie Innocentiee1b85b2018-09-25 14:23:19 +090098LIBNETD_RESOLV_PUBLIC hostent* android_gethostbyaddrfornetcontext(const void*, socklen_t, int,
99 const android_net_context*);
Mike Yucac05e42018-11-06 19:20:07 +0800100LIBNETD_RESOLV_PUBLIC int android_gethostbynamefornetcontext(const char*, int,
101 const android_net_context*, hostent**);
Bernie Innocentiee1b85b2018-09-25 14:23:19 +0900102LIBNETD_RESOLV_PUBLIC int android_getaddrinfofornetcontext(const char*, const char*,
103 const addrinfo*,
104 const android_net_context*, addrinfo**);
Bernie Innocenti55864192018-08-30 04:05:20 +0900105
Bernie Innocentiee1b85b2018-09-25 14:23:19 +0900106// Set name servers for a network
Bernie Innocenti189eb502018-10-01 23:10:18 +0900107LIBNETD_RESOLV_PUBLIC int resolv_set_nameservers_for_net(unsigned netid, const char** servers,
108 unsigned numservers, const char* domains,
109 const __res_params* params);
Bernie Innocenti55864192018-08-30 04:05:20 +0900110
Mike Yua46fae72018-11-01 20:07:00 +0800111LIBNETD_RESOLV_PUBLIC int resolv_set_private_dns_for_net(unsigned netid, uint32_t mark,
112 const char** servers,
113 const unsigned numServers,
114 const char* tlsName,
115 const uint8_t** fingerprints,
116 const unsigned numFingerprints);
117
118LIBNETD_RESOLV_PUBLIC void resolv_delete_private_dns_for_net(unsigned netid);
119
120LIBNETD_RESOLV_PUBLIC void resolv_get_private_dns_status_for_net(unsigned netid,
121 ExternalPrivateDnsStatus* status);
122
123// Register callback to listen whether private DNS validated
124LIBNETD_RESOLV_PUBLIC void resolv_register_private_dns_callback(
125 private_dns_validated_callback callback);
126
Bernie Innocentiee1b85b2018-09-25 14:23:19 +0900127// Flush the cache associated with a certain network
Bernie Innocenti189eb502018-10-01 23:10:18 +0900128LIBNETD_RESOLV_PUBLIC void resolv_flush_cache_for_net(unsigned netid);
Bernie Innocenti55864192018-08-30 04:05:20 +0900129
Bernie Innocentiee1b85b2018-09-25 14:23:19 +0900130// Delete the cache associated with a certain network
Bernie Innocenti189eb502018-10-01 23:10:18 +0900131LIBNETD_RESOLV_PUBLIC void resolv_delete_cache_for_net(unsigned netid);
Bernie Innocenti55864192018-08-30 04:05:20 +0900132
Bernie Innocenti189eb502018-10-01 23:10:18 +0900133#endif // NETD_RESOLV_RESOLV_H