resolv_netid.h revision 589afca92c2fa026f908ec2c54c0450c438c602c
1ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak/* 2ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * Copyright (C) 2014 The Android Open Source Project 3ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * All rights reserved. 4ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * 5ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * Redistribution and use in source and binary forms, with or without 6ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * modification, are permitted provided that the following conditions 7ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * are met: 8ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * * Redistributions of source code must retain the above copyright 9ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * notice, this list of conditions and the following disclaimer. 10ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * * Redistributions in binary form must reproduce the above copyright 11ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * notice, this list of conditions and the following disclaimer in 12ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * the documentation and/or other materials provided with the 13ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * distribution. 14ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * 15ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * SUCH DAMAGE. 27ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak */ 28ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak#ifndef _RESOLV_NETID_H 29ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak#define _RESOLV_NETID_H 30ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak 31ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak/* This header contains declarations related to per-network DNS 32ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * server selection. They are used by system/netd/ and should not be 33ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * exposed by the C library's public NDK headers. 34ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak */ 35ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak#include <sys/cdefs.h> 36ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak#include <netinet/in.h> 379773fa3ffd7c2d1de2431b8ea1eb8043e8959fcbElliott Hughes#include <stdio.h> 38ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak 39ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak/* 402582f02a01cd56c56a4e6c9de4444a6ec937cc37Sreeram Ramachandran * Passing NETID_UNSET as the netId causes system/netd/server/DnsProxyListener.cpp to 41ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * fill in the appropriate default netId for the query. 42ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak */ 43ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak#define NETID_UNSET 0u 44ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak 45ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak/* 46ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak * MARK_UNSET represents the default (i.e. unset) value for a socket mark. 47ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak */ 48ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak#define MARK_UNSET 0u 49ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak 50ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak__BEGIN_DECLS 51ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak 524d8e740b0868b2670599b949ff07d74e5f317114Pierre Imaistruct __res_params; 53ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczakstruct addrinfo; 54ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak 558563802b04347951d8878747a830987e5ca145f5Elliott Hughes#define __used_in_netd __attribute__((visibility ("default"))) 568563802b04347951d8878747a830987e5ca145f5Elliott Hughes 5701e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline/* 5801e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline * A struct to capture context relevant to network operations. 5901e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline * 6001e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline * Application and DNS netids/marks can differ from one another under certain 6101e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline * circumstances, notably when a VPN applies to the given uid's traffic but the 6201e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline * VPN network does not have its own DNS servers explicitly provisioned. 6301e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline * 6401e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline * The introduction of per-UID routing means the uid is also an essential part 6501e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline * of the evaluation context. Its proper uninitialized value is 6601e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline * NET_CONTEXT_INVALID_UID. 6701e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline */ 6801e37c9665018534c798daaa59d5b0adb408e0a4Erik Klinestruct android_net_context { 6901e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline unsigned app_netid; 7001e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline unsigned app_mark; 7101e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline unsigned dns_netid; 7201e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline unsigned dns_mark; 7301e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline uid_t uid; 7401e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline} __attribute__((packed)); 7501e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline 7601e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline#define NET_CONTEXT_INVALID_UID ((uid_t)-1) 7701e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline 788563802b04347951d8878747a830987e5ca145f5Elliott Hughesstruct hostent *android_gethostbyaddrfornet(const void *, socklen_t, int, unsigned, unsigned) __used_in_netd; 798563802b04347951d8878747a830987e5ca145f5Elliott Hughesstruct hostent *android_gethostbynamefornet(const char *, int, unsigned, unsigned) __used_in_netd; 80ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczakint android_getaddrinfofornet(const char *, const char *, const struct addrinfo *, unsigned, 8101e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline unsigned, struct addrinfo **) __used_in_netd; 8201e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline/* 8301e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline * TODO: consider refactoring android_getaddrinfo_proxy() to serve as an 8401e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline * explore_fqdn() dispatch table method, with the below function only making DNS calls. 8501e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline */ 8601e37c9665018534c798daaa59d5b0adb408e0a4Erik Klineint android_getaddrinfofornetcontext(const char *, const char *, const struct addrinfo *, 8701e37c9665018534c798daaa59d5b0adb408e0a4Erik Kline const struct android_net_context *, struct addrinfo **) __used_in_netd; 88ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak 89ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak/* set name servers for a network */ 90589afca92c2fa026f908ec2c54c0450c438c602cPierre Imaiextern int _resolv_set_nameservers_for_net(unsigned netid, const char** servers, 91589afca92c2fa026f908ec2c54c0450c438c602cPierre Imai unsigned numservers, const char *domains, const struct __res_params* params) __used_in_netd; 92ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak 931544eae56e2713a199e085438809078ebad8e7d1Paul Jensen/* flush the cache associated with a certain network */ 941544eae56e2713a199e085438809078ebad8e7d1Paul Jensenextern void _resolv_flush_cache_for_net(unsigned netid) __used_in_netd; 951544eae56e2713a199e085438809078ebad8e7d1Paul Jensen 967f2d4c21cc7b7f27a5163f5a6d5bc724116a8cdeElliott Hughes/* delete the cache associated with a certain network */ 977f2d4c21cc7b7f27a5163f5a6d5bc724116a8cdeElliott Hughesextern void _resolv_delete_cache_for_net(unsigned netid) __used_in_netd; 987f2d4c21cc7b7f27a5163f5a6d5bc724116a8cdeElliott Hughes 998563802b04347951d8878747a830987e5ca145f5Elliott Hughes/* Internal use only. */ 1009773fa3ffd7c2d1de2431b8ea1eb8043e8959fcbElliott Hughesstruct hostent *android_gethostbyaddrfornet_proxy(const void *, socklen_t, int , unsigned, unsigned) __LIBC_HIDDEN__; 1019773fa3ffd7c2d1de2431b8ea1eb8043e8959fcbElliott Hughesint android_getnameinfofornet(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int, unsigned, unsigned) __LIBC_HIDDEN__; 1029773fa3ffd7c2d1de2431b8ea1eb8043e8959fcbElliott HughesFILE* android_open_proxy(void) __LIBC_HIDDEN__; 103ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak 10441d9a503716ed6f3291f4cae097dca08d459429cPaul Jensen/* delete the cache associated with a certain network */ 10541d9a503716ed6f3291f4cae097dca08d459429cPaul Jensenextern void _resolv_delete_cache_for_net(unsigned netid); 10641d9a503716ed6f3291f4cae097dca08d459429cPaul Jensen 107ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak__END_DECLS 108ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak 109ea9bf6788144b83cc51c454b2bfe6b980d6e947cSzymon Jakubczak#endif /* _RESOLV_NETID_H */ 110