• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 command;
62     uint32_t netId;
63 };
64 
65 struct ResolvConfig {
66     int32_t error;
67     int32_t timeoutMs;
68     uint32_t retryCount;
69     char nameservers[MAX_SERVER_NUM][MAX_SERVER_LENGTH + 1];
70 };
71 
72 typedef union {
73     struct sockaddr sa;
74     struct sockaddr_in6 sin6;
75     struct sockaddr_in sin;
76 } AlignedSockAddr;
77 
78 struct AddrInfo {
79     uint32_t aiFlags;
80     uint32_t aiFamily;
81     uint32_t aiSockType;
82     uint32_t aiProtocol;
83     uint32_t aiAddrLen;
84     AlignedSockAddr aiAddr;
85     char aiCanonName[MAX_CANON_NAME + 1];
86 };
87 
88 struct ParamWrapper {
89     char *host;
90     char *serv;
91     struct addrinfo *hint;
92 };
93 
94 typedef int32_t (*FuncNetDnsqueryHook)(int32_t, int32_t, int32_t);
95 
96 struct QueryParam {
97     int32_t type;
98     int32_t netId;
99     int32_t mark;
100     int32_t flags;
101     FuncNetDnsqueryHook qHook;
102 };
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 #endif // COMMUNICATION_NETMANAGER_BASE_1_DNS_CONFIG_CLIENT_H
108