1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef COMMUNICATION_NETMANAGER_BASE_DNS_CONFIG_CLIENT_H 17 #define COMMUNICATION_NETMANAGER_BASE_DNS_CONFIG_CLIENT_H 18 19 #include <arpa/inet.h> 20 #include <netdb.h> 21 #include <stdint.h> 22 23 #include "securec.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #if DNS_CONFIG_DEBUG 30 #ifndef DNS_CONFIG_PRINT 31 #define DNS_CONFIG_PRINT(fmt, ...) printf("DNS" fmt "\n", ##__VA_ARGS__) 32 #endif 33 #else 34 #define DNS_CONFIG_PRINT(fmt, ...) 35 #endif 36 37 #define MAX_SERVER_NUM 4 38 #define MAX_SERVER_LENGTH 50 39 #define DNS_SOCKET_PATH "/dev/unix/socket/dnsproxyd" 40 #define DNS_SOCKET_NAME "dnsproxyd" 41 #define MAX_RESULTS 32 42 #define MAX_CANON_NAME 256 43 #define MAX_HOST_NAME_LEN 256 44 #define MAX_KEY_LENGTH (MAX_HOST_NAME_LEN + 1 + MAX_SERVER_LENGTH + 1 + sizeof(uint32_t) * 4 + 3 + 1) 45 #define DEFAULT_TIMEOUT 5000 46 #define DEFAULT_RETRY 2 47 #define DEFAULT_SERVER_LENTH 16 48 #define DEFAULT_SERVER_NAME 114 49 50 enum CommandType { 51 GET_CONFIG = 1, 52 GET_CACHE = 2, 53 SET_CACHE = 3, 54 JUDGE_IPV6 = 4, 55 POST_DNS_RESULT = 5, 56 GET_DEFAULT_NETWORK = 6, 57 BIND_SOCKET = 7 58 }; 59 60 struct RequestInfo { 61 uint32_t uid; 62 uint32_t command; 63 uint32_t netId; 64 }; 65 66 struct ResolvConfig { 67 int32_t error; 68 int32_t timeoutMs; 69 uint32_t retryCount; 70 char nameservers[MAX_SERVER_NUM][MAX_SERVER_LENGTH + 1]; 71 }; 72 73 typedef union { 74 struct sockaddr sa; 75 struct sockaddr_in6 sin6; 76 struct sockaddr_in sin; 77 } AlignedSockAddr; 78 79 struct AddrInfo { 80 uint32_t aiFlags; 81 uint32_t aiFamily; 82 uint32_t aiSockType; 83 uint32_t aiProtocol; 84 uint32_t aiAddrLen; 85 AlignedSockAddr aiAddr; 86 char aiCanonName[MAX_CANON_NAME + 1]; 87 }; 88 89 struct ParamWrapper { 90 char *host; 91 char *serv; 92 struct addrinfo *hint; 93 }; 94 95 typedef int32_t (*FuncNetDnsqueryHook)(int32_t, int32_t, int32_t); 96 97 struct QueryParam { 98 int32_t type; 99 int32_t netId; 100 int32_t mark; 101 int32_t flags; 102 FuncNetDnsqueryHook qHook; 103 }; 104 105 #ifdef __cplusplus 106 } 107 #endif 108 #endif // COMMUNICATION_NETMANAGER_BASE_1_DNS_CONFIG_CLIENT_H 109