Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
cdfecad8
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
1 年多 前同步成功
通知
37
Star
125
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Musl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cdfecad8
编写于
6月 24, 2022
作者:
M
maosiping
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dns proxt from netsys
Signed-off-by:
N
maosiping
<
maosiping@huawei.com
>
上级
f15f4e9d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
264 addition
and
3 deletion
+264
-3
musl_src.gni
musl_src.gni
+1
-0
musl_template.gni
musl_template.gni
+5
-1
src/network/freeaddrinfo.c
src/network/freeaddrinfo.c
+4
-2
src/network/getaddrinfo.c
src/network/getaddrinfo.c
+10
-0
src/network/lookup.h
src/network/lookup.h
+71
-0
src/network/res_cache.c
src/network/res_cache.c
+119
-0
src/network/resolvconf.c
src/network/resolvconf.c
+54
-0
未找到文件。
musl_src.gni
浏览文件 @
cdfecad8
...
...
@@ -823,6 +823,7 @@ musl_src_file = [
"src/network/recvfrom.c",
"src/network/recvmmsg.c",
"src/network/recvmsg.c",
"src/network/res_cache.c",
"src/network/res_init.c",
"src/network/res_mkquery.c",
"src/network/res_msend.c",
...
...
musl_template.gni
浏览文件 @
cdfecad8
...
...
@@ -177,8 +177,12 @@ template("musl_libs") {
cflags = cflags_all
defines = []
if ("${target_abi}" != "a7_hard_neon-vfpv4") {
defines = [ "BROKEN_VFP_ASM" ]
defines += [ "BROKEN_VFP_ASM" ]
}
if (is_standard_system) {
defines += [ "OHOS_DNS_PROXY_BY_NETSYS=1" ]
}
dynamic_list =
...
...
src/network/freeaddrinfo.c
浏览文件 @
cdfecad8
...
...
@@ -6,10 +6,12 @@
void
freeaddrinfo
(
struct
addrinfo
*
p
)
{
if
(
!
p
)
{
return
;
}
size_t
cnt
;
for
(
cnt
=
1
;
p
->
ai_next
;
cnt
++
,
p
=
p
->
ai_next
);
struct
aibuf
*
b
=
(
void
*
)((
char
*
)
p
-
offsetof
(
struct
aibuf
,
ai
));
b
-=
b
->
slot
;
for
(
cnt
=
1
;
p
->
ai_next
;
cnt
++
,
p
=
p
->
ai_next
)
;
LOCK
(
b
->
lock
);
if
(
!
(
b
->
ref
-=
cnt
))
free
(
b
);
else
UNLOCK
(
b
->
lock
);
...
...
src/network/getaddrinfo.c
浏览文件 @
cdfecad8
...
...
@@ -11,6 +11,13 @@
int
getaddrinfo
(
const
char
*
restrict
host
,
const
char
*
restrict
serv
,
const
struct
addrinfo
*
restrict
hint
,
struct
addrinfo
**
restrict
res
)
{
#if OHOS_DNS_PROXY_BY_NETSYS
if
(
dns_get_addr_info_from_netsys_cache
(
host
,
serv
,
hint
,
res
)
==
0
)
{
DNS_CONFIG_PRINT
(
"get from netsys cache OK
\n
"
);
return
0
;
}
#endif
struct
service
ports
[
MAXSERVS
];
struct
address
addrs
[
MAXADDRS
];
char
canon
[
256
],
*
outcanon
;
...
...
@@ -131,5 +138,8 @@ int getaddrinfo(const char *restrict host, const char *restrict serv, const stru
}
out
[
0
].
ref
=
nais
;
*
res
=
&
out
->
ai
;
#if OHOS_DNS_PROXY_BY_NETSYS
dns_set_addr_info_to_netsys_cache
(
host
,
serv
,
hint
,
*
res
);
#endif
return
0
;
}
src/network/lookup.h
浏览文件 @
cdfecad8
...
...
@@ -7,6 +7,19 @@
#include <netinet/in.h>
#include <netdb.h>
#if OHOS_DNS_PROXY_BY_NETSYS
#include <stdio.h>
#if DNS_CONFIG_DEBUG
#ifndef DNS_CONFIG_PRINT
#define DNS_CONFIG_PRINT(fmt, ...) printf("DNS " fmt "\n", ##__VA_ARGS__)
#endif
#else
#define DNS_CONFIG_PRINT(fmt, ...)
#endif
#endif
struct
aibuf
{
struct
addrinfo
ai
;
union
sa
{
...
...
@@ -52,4 +65,62 @@ hidden int __res_msend_rc(int, const unsigned char *const *, const int *, unsign
hidden
int
__dns_parse
(
const
unsigned
char
*
,
int
,
int
(
*
)(
void
*
,
int
,
const
void
*
,
int
,
const
void
*
),
void
*
);
#if OHOS_DNS_PROXY_BY_NETSYS
#define DNS_SO_PATH "libnetsys_client.z.so"
#define MAX_SERVER_NUM 4
#define MAX_SERVER_LENGTH 50
#define OHOS_GET_CONFIG_FUNC_NAME "NetSysGetResolvConf"
#define OHOS_GET_CACHE_FUNC_NAME "NetSysGetResolvCache"
#define OHOS_SET_CACHE_FUNC_NAME "NetSysSetResolvCache"
#define MAX_RESULTS 32
#define MAX_CANON_NAME 256
#define MACRO_MIN(a, b) ((a) < (b) ? (a) : (b))
struct
resolv_config
{
int32_t
error
;
int32_t
timeout_ms
;
uint32_t
retry_count
;
char
nameservers
[
MAX_SERVER_NUM
][
MAX_SERVER_LENGTH
+
1
];
};
typedef
union
{
struct
sockaddr
sa
;
struct
sockaddr_in6
sin6
;
struct
sockaddr_in
sin
;
}
aligned_sockAddr
;
struct
addr_info_wrapper
{
uint32_t
ai_flags
;
uint32_t
ai_family
;
uint32_t
ai_sockType
;
uint32_t
ai_protocol
;
uint32_t
ai_addrLen
;
aligned_sockAddr
ai_addr
;
char
ai_canonName
[
MAX_CANON_NAME
+
1
];
};
struct
param_wrapper
{
char
*
host
;
char
*
serv
;
struct
addrinfo
*
hint
;
};
typedef
int32_t
(
*
GetConfig
)(
uint16_t
netId
,
struct
resolv_config
*
config
);
typedef
int32_t
(
*
GetCache
)(
uint16_t
netId
,
struct
param_wrapper
param
,
struct
addr_info_wrapper
addr_info
[
static
MAX_RESULTS
],
uint32_t
*
num
);
typedef
int32_t
(
*
SetCache
)(
uint16_t
netId
,
struct
param_wrapper
param
,
struct
addrinfo
*
res
);
void
dns_set_addr_info_to_netsys_cache
(
const
char
*
__restrict
host
,
const
char
*
__restrict
serv
,
const
struct
addrinfo
*
__restrict
hint
,
struct
addrinfo
*
res
);
int
dns_get_addr_info_from_netsys_cache
(
const
char
*
__restrict
host
,
const
char
*
__restrict
serv
,
const
struct
addrinfo
*
__restrict
hint
,
struct
addrinfo
**
__restrict
res
);
#endif
#endif
src/network/res_cache.c
0 → 100644
浏览文件 @
cdfecad8
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
#include "lookup.h"
#include <dlfcn.h>
#if OHOS_DNS_PROXY_BY_NETSYS
void
dns_set_addr_info_to_netsys_cache
(
const
char
*
restrict
host
,
const
char
*
restrict
serv
,
const
struct
addrinfo
*
restrict
hint
,
struct
addrinfo
*
res
)
{
void
*
handle
=
dlopen
(
DNS_SO_PATH
,
RTLD_LAZY
);
if
(
handle
==
NULL
)
{
DNS_CONFIG_PRINT
(
"dns_set_addr_info_to_netsys_cache dlopen err %s
\n
"
,
dlerror
());
return
;
}
SetCache
func
=
dlsym
(
handle
,
OHOS_SET_CACHE_FUNC_NAME
);
if
(
func
==
NULL
)
{
DNS_CONFIG_PRINT
(
"dns_set_addr_info_to_netsys_cache dlsym err %s
\n
"
,
dlerror
());
dlclose
(
handle
);
return
;
}
struct
param_wrapper
param
=
{(
char
*
)
host
,
(
char
*
)
serv
,
(
struct
addrinfo
*
)
hint
};
int
ret
=
func
(
0
,
param
,
res
);
dlclose
(
handle
);
if
(
ret
<
0
)
{
DNS_CONFIG_PRINT
(
"dns_set_addr_info_to_netsys_cache OHOS_SET_CACHE_FUNC_NAME err %d
\n
"
,
ret
);
return
;
}
DNS_CONFIG_PRINT
(
"set to netsys cache OK
\n
"
);
}
int
dns_get_addr_info_from_netsys_cache
(
const
char
*
restrict
host
,
const
char
*
restrict
serv
,
const
struct
addrinfo
*
restrict
hint
,
struct
addrinfo
**
restrict
res
)
{
void
*
handle
=
dlopen
(
DNS_SO_PATH
,
RTLD_LAZY
);
if
(
handle
==
NULL
)
{
DNS_CONFIG_PRINT
(
"dns_get_addr_info_from_netsys_cache dlopen err %s
\n
"
,
dlerror
());
return
-
1
;
}
GetCache
func
=
dlsym
(
handle
,
OHOS_GET_CACHE_FUNC_NAME
);
if
(
func
==
NULL
)
{
DNS_CONFIG_PRINT
(
"dns_get_addr_info_from_netsys_cache dlsym err %s
\n
"
,
dlerror
());
dlclose
(
handle
);
return
-
1
;
}
struct
addr_info_wrapper
addr_info
[
MAX_RESULTS
]
=
{
0
};
uint32_t
num
=
0
;
struct
param_wrapper
param
=
{(
char
*
)
host
,
(
char
*
)
serv
,
(
struct
addrinfo
*
)
hint
};
int
ret
=
func
(
0
,
param
,
addr_info
,
&
num
);
dlclose
(
handle
);
if
(
ret
<
0
)
{
DNS_CONFIG_PRINT
(
"dns_get_addr_info_from_netsys_cache OHOS_GET_CACHE_FUNC_NAME err %d
\n
"
,
ret
);
return
-
1
;
}
num
=
MACRO_MIN
(
num
,
MACRO_MIN
(
MAX_RESULTS
,
MAXADDRS
));
if
(
num
==
0
)
{
DNS_CONFIG_PRINT
(
"dns_get_addr_info_from_netsys_cache num is invalid err %u"
,
num
);
return
-
1
;
}
int
canon_len
=
(
int
)
strlen
(
addr_info
[
0
].
ai_canonName
);
struct
aibuf
*
out
=
calloc
(
1
,
num
*
sizeof
(
*
out
)
+
canon_len
+
1
);
if
(
!
out
)
{
return
-
1
;
}
char
*
outcanon
=
NULL
;
if
(
canon_len
)
{
outcanon
=
(
char
*
)
&
out
[
num
];
memcpy
(
outcanon
,
addr_info
[
0
].
ai_canonName
,
canon_len
+
1
);
}
for
(
int
i
=
0
;
i
<
num
;
i
++
)
{
out
[
i
].
slot
=
(
short
)
i
;
out
[
i
].
ai
=
(
struct
addrinfo
)
{
.
ai_flags
=
(
int
)
addr_info
[
i
].
ai_flags
,
.
ai_family
=
(
int
)
addr_info
[
i
].
ai_family
,
.
ai_socktype
=
(
int
)
addr_info
[
i
].
ai_sockType
,
.
ai_protocol
=
(
int
)
addr_info
[
i
].
ai_protocol
,
.
ai_addrlen
=
(
socklen_t
)
addr_info
[
i
].
ai_addrLen
,
.
ai_addr
=
(
void
*
)
&
out
[
i
].
sa
,
.
ai_canonname
=
outcanon
,
};
memcpy
(
&
out
[
i
].
sa
,
&
addr_info
[
i
].
ai_addr
,
addr_info
[
i
].
ai_addrLen
);
if
(
i
>
0
)
{
out
[
i
-
1
].
ai
.
ai_next
=
&
out
[
i
].
ai
;
}
}
out
[
0
].
ref
=
(
short
)
num
;
*
res
=
&
out
->
ai
;
DNS_CONFIG_PRINT
(
"dns_get_addr_info_from_netsys_cache end
\n
"
);
return
0
;
}
#endif
src/network/resolvconf.c
浏览文件 @
cdfecad8
...
...
@@ -5,6 +5,9 @@
#include <string.h>
#include <stdlib.h>
#include <netinet/in.h>
#if OHOS_DNS_PROXY_BY_NETSYS
#include <dlfcn.h>
#endif
int
__get_resolv_conf
(
struct
resolvconf
*
conf
,
char
*
search
,
size_t
search_sz
)
{
...
...
@@ -18,6 +21,57 @@ int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
conf
->
attempts
=
2
;
if
(
search
)
*
search
=
0
;
#if OHOS_DNS_PROXY_BY_NETSYS
void
*
handle
=
dlopen
(
DNS_SO_PATH
,
RTLD_LAZY
);
if
(
handle
==
NULL
)
{
DNS_CONFIG_PRINT
(
"__get_resolv_conf dlopen err %s
\n
"
,
dlerror
());
goto
etc_resolv_conf
;
}
GetConfig
func
=
dlsym
(
handle
,
OHOS_GET_CONFIG_FUNC_NAME
);
if
(
func
==
NULL
)
{
DNS_CONFIG_PRINT
(
"__get_resolv_conf dlsym err %s
\n
"
,
dlerror
());
dlclose
(
handle
);
goto
etc_resolv_conf
;
}
struct
resolv_config
config
=
{
0
};
int
ret
=
func
(
0
,
&
config
);
dlclose
(
handle
);
if
(
ret
<
0
)
{
DNS_CONFIG_PRINT
(
"__get_resolv_conf OHOS_GET_CONFIG_FUNC_NAME err %d
\n
"
,
ret
);
goto
etc_resolv_conf
;
}
int32_t
timeout_second
=
config
.
timeout_ms
/
1000
;
#endif
#if OHOS_DNS_PROXY_BY_NETSYS
netsys_conf:
if
(
timeout_second
>
0
)
{
if
(
timeout_second
>=
60
)
{
conf
->
timeout
=
60
;
}
else
{
conf
->
timeout
=
timeout_second
;
}
}
if
(
config
.
retry_count
>
0
)
{
if
(
config
.
retry_count
>=
10
)
{
conf
->
attempts
=
10
;
}
else
{
conf
->
attempts
=
config
.
retry_count
;
}
}
for
(
int
i
=
0
;
i
<
MAX_SERVER_NUM
;
++
i
)
{
if
(
config
.
nameservers
[
i
]
==
NULL
||
config
.
nameservers
[
i
][
0
]
==
0
||
nns
>=
MAXNS
)
{
continue
;
}
if
(
__lookup_ipliteral
(
conf
->
ns
+
nns
,
config
.
nameservers
[
i
],
AF_UNSPEC
)
>
0
)
{
nns
++
;
}
}
etc_resolv_conf:
#endif
f
=
__fopen_rb_ca
(
"/etc/resolv.conf"
,
&
_f
,
_buf
,
sizeof
_buf
);
if
(
!
f
)
switch
(
errno
)
{
case
ENOENT
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录