blob: e92195876d97dc09d04880d8aae96a3f24cc1e06 [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
39/*
40 * Passing NETID_UNSET as the netId causes system/netd/server/DnsProxyListener.cpp to
41 * fill in the appropriate default netId for the query.
42 */
43#define NETID_UNSET 0u
44
45/*
46 * MARK_UNSET represents the default (i.e. unset) value for a socket mark.
47 */
48#define MARK_UNSET 0u
49
Bernie Innocenti55864192018-08-30 04:05:20 +090050struct __res_params;
51struct addrinfo;
Bernie Innocentiee1b85b2018-09-25 14:23:19 +090052struct hostent;
Bernie Innocenti55864192018-08-30 04:05:20 +090053
54/*
55 * A struct to capture context relevant to network operations.
56 *
57 * Application and DNS netids/marks can differ from one another under certain
58 * circumstances, notably when a VPN applies to the given uid's traffic but the
59 * VPN network does not have its own DNS servers explicitly provisioned.
60 *
61 * The introduction of per-UID routing means the uid is also an essential part
62 * of the evaluation context. Its proper uninitialized value is
63 * NET_CONTEXT_INVALID_UID.
64 */
65struct android_net_context {
66 unsigned app_netid;
67 unsigned app_mark;
68 unsigned dns_netid;
69 unsigned dns_mark;
70 uid_t uid;
71 unsigned flags;
72 res_send_qhook qhook;
73};
74
Bernie Innocentif12d5bb2018-08-31 14:09:46 +090075#define NET_CONTEXT_INVALID_UID ((uid_t) -1)
Bernie Innocenti55864192018-08-30 04:05:20 +090076
Bernie Innocentif12d5bb2018-08-31 14:09:46 +090077#define NET_CONTEXT_FLAG_USE_LOCAL_NAMESERVERS 0x00000001
78#define NET_CONTEXT_FLAG_USE_EDNS 0x00000002
Bernie Innocenti55864192018-08-30 04:05:20 +090079
Bernie Innocentiee1b85b2018-09-25 14:23:19 +090080LIBNETD_RESOLV_PUBLIC hostent* android_gethostbyaddrfornet(const void*, socklen_t, int, unsigned,
81 unsigned);
82LIBNETD_RESOLV_PUBLIC hostent* android_gethostbynamefornet(const char*, int, unsigned, unsigned);
Bernie Innocenti189eb502018-10-01 23:10:18 +090083LIBNETD_RESOLV_PUBLIC int android_getaddrinfofornet(const char*, const char*, const addrinfo*,
84 unsigned, unsigned, addrinfo**);
Bernie Innocenti55864192018-08-30 04:05:20 +090085/*
86 * TODO: consider refactoring android_getaddrinfo_proxy() to serve as an
87 * explore_fqdn() dispatch table method, with the below function only making DNS calls.
88 */
Bernie Innocentiee1b85b2018-09-25 14:23:19 +090089LIBNETD_RESOLV_PUBLIC hostent* android_gethostbyaddrfornetcontext(const void*, socklen_t, int,
90 const android_net_context*);
91LIBNETD_RESOLV_PUBLIC hostent* android_gethostbynamefornetcontext(const char*, int,
92 const android_net_context*);
93LIBNETD_RESOLV_PUBLIC int android_getaddrinfofornetcontext(const char*, const char*,
94 const addrinfo*,
95 const android_net_context*, addrinfo**);
Bernie Innocenti55864192018-08-30 04:05:20 +090096
Bernie Innocentiee1b85b2018-09-25 14:23:19 +090097// Set name servers for a network
Bernie Innocenti189eb502018-10-01 23:10:18 +090098LIBNETD_RESOLV_PUBLIC int resolv_set_nameservers_for_net(unsigned netid, const char** servers,
99 unsigned numservers, const char* domains,
100 const __res_params* params);
Bernie Innocenti55864192018-08-30 04:05:20 +0900101
Bernie Innocentiee1b85b2018-09-25 14:23:19 +0900102// Flush the cache associated with a certain network
Bernie Innocenti189eb502018-10-01 23:10:18 +0900103LIBNETD_RESOLV_PUBLIC void resolv_flush_cache_for_net(unsigned netid);
Bernie Innocenti55864192018-08-30 04:05:20 +0900104
Bernie Innocentiee1b85b2018-09-25 14:23:19 +0900105// Delete the cache associated with a certain network
Bernie Innocenti189eb502018-10-01 23:10:18 +0900106LIBNETD_RESOLV_PUBLIC void resolv_delete_cache_for_net(unsigned netid);
Bernie Innocenti55864192018-08-30 04:05:20 +0900107
Bernie Innocenti189eb502018-10-01 23:10:18 +0900108#endif // NETD_RESOLV_RESOLV_H