xref: /aosp_15_r20/bionic/libc/dns/include/resolv_netid.h (revision 8d67ca893c1523eb926b9080dbe4e2ffd2a27ba1)
1*8d67ca89SAndroid Build Coastguard Worker /*
2*8d67ca89SAndroid Build Coastguard Worker  * Copyright (C) 2014 The Android Open Source Project
3*8d67ca89SAndroid Build Coastguard Worker  * All rights reserved.
4*8d67ca89SAndroid Build Coastguard Worker  *
5*8d67ca89SAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
6*8d67ca89SAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions
7*8d67ca89SAndroid Build Coastguard Worker  * are met:
8*8d67ca89SAndroid Build Coastguard Worker  *  * Redistributions of source code must retain the above copyright
9*8d67ca89SAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer.
10*8d67ca89SAndroid Build Coastguard Worker  *  * Redistributions in binary form must reproduce the above copyright
11*8d67ca89SAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer in
12*8d67ca89SAndroid Build Coastguard Worker  *    the documentation and/or other materials provided with the
13*8d67ca89SAndroid Build Coastguard Worker  *    distribution.
14*8d67ca89SAndroid Build Coastguard Worker  *
15*8d67ca89SAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16*8d67ca89SAndroid Build Coastguard Worker  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17*8d67ca89SAndroid Build Coastguard Worker  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18*8d67ca89SAndroid Build Coastguard Worker  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19*8d67ca89SAndroid Build Coastguard Worker  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20*8d67ca89SAndroid Build Coastguard Worker  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21*8d67ca89SAndroid Build Coastguard Worker  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22*8d67ca89SAndroid Build Coastguard Worker  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23*8d67ca89SAndroid Build Coastguard Worker  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24*8d67ca89SAndroid Build Coastguard Worker  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25*8d67ca89SAndroid Build Coastguard Worker  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*8d67ca89SAndroid Build Coastguard Worker  * SUCH DAMAGE.
27*8d67ca89SAndroid Build Coastguard Worker  */
28*8d67ca89SAndroid Build Coastguard Worker #ifndef _RESOLV_NETID_H
29*8d67ca89SAndroid Build Coastguard Worker #define _RESOLV_NETID_H
30*8d67ca89SAndroid Build Coastguard Worker 
31*8d67ca89SAndroid Build Coastguard Worker /* This header contains declarations related to per-network DNS
32*8d67ca89SAndroid Build Coastguard Worker  * server selection. They are used by system/netd/ and should not be
33*8d67ca89SAndroid Build Coastguard Worker  * exposed by the C library's public NDK headers.
34*8d67ca89SAndroid Build Coastguard Worker  */
35*8d67ca89SAndroid Build Coastguard Worker #include <sys/cdefs.h>
36*8d67ca89SAndroid Build Coastguard Worker #include <netinet/in.h>
37*8d67ca89SAndroid Build Coastguard Worker #include "resolv_params.h"
38*8d67ca89SAndroid Build Coastguard Worker #include <stdio.h>
39*8d67ca89SAndroid Build Coastguard Worker 
40*8d67ca89SAndroid Build Coastguard Worker /*
41*8d67ca89SAndroid Build Coastguard Worker  * Passing NETID_UNSET as the netId causes system/netd/server/DnsProxyListener.cpp to
42*8d67ca89SAndroid Build Coastguard Worker  * fill in the appropriate default netId for the query.
43*8d67ca89SAndroid Build Coastguard Worker  */
44*8d67ca89SAndroid Build Coastguard Worker #define NETID_UNSET 0u
45*8d67ca89SAndroid Build Coastguard Worker 
46*8d67ca89SAndroid Build Coastguard Worker /*
47*8d67ca89SAndroid Build Coastguard Worker  * MARK_UNSET represents the default (i.e. unset) value for a socket mark.
48*8d67ca89SAndroid Build Coastguard Worker  */
49*8d67ca89SAndroid Build Coastguard Worker #define MARK_UNSET 0u
50*8d67ca89SAndroid Build Coastguard Worker 
51*8d67ca89SAndroid Build Coastguard Worker __BEGIN_DECLS
52*8d67ca89SAndroid Build Coastguard Worker 
53*8d67ca89SAndroid Build Coastguard Worker struct __res_params;
54*8d67ca89SAndroid Build Coastguard Worker struct addrinfo;
55*8d67ca89SAndroid Build Coastguard Worker 
56*8d67ca89SAndroid Build Coastguard Worker #define __used_in_netd __attribute__((visibility ("default")))
57*8d67ca89SAndroid Build Coastguard Worker 
58*8d67ca89SAndroid Build Coastguard Worker /*
59*8d67ca89SAndroid Build Coastguard Worker  * A struct to capture context relevant to network operations.
60*8d67ca89SAndroid Build Coastguard Worker  *
61*8d67ca89SAndroid Build Coastguard Worker  * Application and DNS netids/marks can differ from one another under certain
62*8d67ca89SAndroid Build Coastguard Worker  * circumstances, notably when a VPN applies to the given uid's traffic but the
63*8d67ca89SAndroid Build Coastguard Worker  * VPN network does not have its own DNS servers explicitly provisioned.
64*8d67ca89SAndroid Build Coastguard Worker  *
65*8d67ca89SAndroid Build Coastguard Worker  * The introduction of per-UID routing means the uid is also an essential part
66*8d67ca89SAndroid Build Coastguard Worker  * of the evaluation context. Its proper uninitialized value is
67*8d67ca89SAndroid Build Coastguard Worker  * NET_CONTEXT_INVALID_UID.
68*8d67ca89SAndroid Build Coastguard Worker  */
69*8d67ca89SAndroid Build Coastguard Worker struct android_net_context {
70*8d67ca89SAndroid Build Coastguard Worker     unsigned app_netid;
71*8d67ca89SAndroid Build Coastguard Worker     unsigned app_mark;
72*8d67ca89SAndroid Build Coastguard Worker     unsigned dns_netid;
73*8d67ca89SAndroid Build Coastguard Worker     unsigned dns_mark;
74*8d67ca89SAndroid Build Coastguard Worker     uid_t uid;
75*8d67ca89SAndroid Build Coastguard Worker     unsigned flags;
76*8d67ca89SAndroid Build Coastguard Worker     res_send_qhook qhook;
77*8d67ca89SAndroid Build Coastguard Worker };
78*8d67ca89SAndroid Build Coastguard Worker 
79*8d67ca89SAndroid Build Coastguard Worker #define NET_CONTEXT_INVALID_UID ((uid_t)-1)
80*8d67ca89SAndroid Build Coastguard Worker 
81*8d67ca89SAndroid Build Coastguard Worker #define NET_CONTEXT_FLAG_USE_LOCAL_NAMESERVERS  0x00000001
82*8d67ca89SAndroid Build Coastguard Worker #define NET_CONTEXT_FLAG_USE_EDNS               0x00000002
83*8d67ca89SAndroid Build Coastguard Worker 
84*8d67ca89SAndroid Build Coastguard Worker struct hostent *android_gethostbyaddrfornet(const void *, socklen_t, int, unsigned, unsigned) __used_in_netd;
85*8d67ca89SAndroid Build Coastguard Worker struct hostent *android_gethostbynamefornet(const char *, int, unsigned, unsigned) __used_in_netd;
86*8d67ca89SAndroid Build Coastguard Worker int android_getaddrinfofornet(const char *, const char *, const struct addrinfo *, unsigned,
87*8d67ca89SAndroid Build Coastguard Worker     unsigned, struct addrinfo **) __used_in_netd;
88*8d67ca89SAndroid Build Coastguard Worker /*
89*8d67ca89SAndroid Build Coastguard Worker  * TODO: consider refactoring android_getaddrinfo_proxy() to serve as an
90*8d67ca89SAndroid Build Coastguard Worker  * explore_fqdn() dispatch table method, with the below function only making DNS calls.
91*8d67ca89SAndroid Build Coastguard Worker  */
92*8d67ca89SAndroid Build Coastguard Worker struct hostent *android_gethostbyaddrfornetcontext(const void *, socklen_t, int, const struct android_net_context *) __used_in_netd;
93*8d67ca89SAndroid Build Coastguard Worker struct hostent *android_gethostbynamefornetcontext(const char *, int, const struct android_net_context *) __used_in_netd;
94*8d67ca89SAndroid Build Coastguard Worker int android_getaddrinfofornetcontext(const char *, const char *, const struct addrinfo *,
95*8d67ca89SAndroid Build Coastguard Worker     const struct android_net_context *, struct addrinfo **) __used_in_netd;
96*8d67ca89SAndroid Build Coastguard Worker 
97*8d67ca89SAndroid Build Coastguard Worker /* set name servers for a network */
98*8d67ca89SAndroid Build Coastguard Worker extern int _resolv_set_nameservers_for_net(unsigned netid, const char** servers,
99*8d67ca89SAndroid Build Coastguard Worker         unsigned numservers, const char *domains, const struct __res_params* params) __used_in_netd;
100*8d67ca89SAndroid Build Coastguard Worker 
101*8d67ca89SAndroid Build Coastguard Worker /* flush the cache associated with a certain network */
102*8d67ca89SAndroid Build Coastguard Worker extern void _resolv_flush_cache_for_net(unsigned netid) __used_in_netd;
103*8d67ca89SAndroid Build Coastguard Worker 
104*8d67ca89SAndroid Build Coastguard Worker /* delete the cache associated with a certain network */
105*8d67ca89SAndroid Build Coastguard Worker extern void _resolv_delete_cache_for_net(unsigned netid) __used_in_netd;
106*8d67ca89SAndroid Build Coastguard Worker 
107*8d67ca89SAndroid Build Coastguard Worker /* Internal use only. */
108*8d67ca89SAndroid Build Coastguard Worker struct hostent *android_gethostbyaddrfornetcontext_proxy(const void *, socklen_t, int , const struct android_net_context *) __LIBC_HIDDEN__;
109*8d67ca89SAndroid Build Coastguard Worker int android_getnameinfofornet(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int, unsigned, unsigned) __LIBC_HIDDEN__;
110*8d67ca89SAndroid Build Coastguard Worker 
111*8d67ca89SAndroid Build Coastguard Worker __END_DECLS
112*8d67ca89SAndroid Build Coastguard Worker 
113*8d67ca89SAndroid Build Coastguard Worker #endif /* _RESOLV_NETID_H */
114