Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
clibcni
提交
7552595c
C
clibcni
项目概览
openeuler
/
clibcni
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
clibcni
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7552595c
编写于
4月 30, 2020
作者:
H
haozi007
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add prefix for utils function
add clibcni prefix Signed-off-by:
N
haozi007
<
liuhao27@huawei.com
>
上级
1185bcd2
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
315 addition
and
315 deletion
+315
-315
src/api.c
src/api.c
+55
-55
src/conf.c
src/conf.c
+44
-44
src/invoke/args.c
src/invoke/args.c
+9
-9
src/invoke/exec.c
src/invoke/exec.c
+21
-21
src/invoke/tools.c
src/invoke/tools.c
+2
-2
src/log.c
src/log.c
+6
-6
src/types/current.c
src/types/current.c
+58
-58
src/types/types.c
src/types/types.c
+36
-36
src/utils.c
src/utils.c
+40
-40
src/utils.h
src/utils.h
+24
-24
src/version/version.c
src/version/version.c
+20
-20
未找到文件。
src/api.c
浏览文件 @
7552595c
...
...
@@ -53,10 +53,10 @@ static int copy_cni_port_mapping(port_mapping *dst, const struct cni_port_mappin
return
-
1
;
}
if
(
src
->
protocol
!=
NULL
)
{
dst
->
protocol
=
util_strdup_s
(
src
->
protocol
);
dst
->
protocol
=
clibcni_
util_strdup_s
(
src
->
protocol
);
}
if
(
src
->
host_ip
!=
NULL
)
{
dst
->
host_ip
=
util_strdup_s
(
src
->
host_ip
);
dst
->
host_ip
=
clibcni_
util_strdup_s
(
src
->
host_ip
);
}
dst
->
container_port
=
src
->
container_port
;
dst
->
host_port
=
src
->
host_port
;
...
...
@@ -78,27 +78,27 @@ static int inject_port_mappings(const struct runtime_conf *rt, net_conf_runtime_
}
if
(
rt
->
p_mapping_len
>
(
SIZE_MAX
/
sizeof
(
port_mapping
*
)))
{
*
err
=
util_strdup_s
(
"Too many mapping"
);
*
err
=
clibcni_
util_strdup_s
(
"Too many mapping"
);
ERROR
(
"Too many mapping"
);
return
-
1
;
}
rt_config
->
port_mappings
=
util_common_calloc_s
(
sizeof
(
port_mapping
*
)
*
(
rt
->
p_mapping_len
));
rt_config
->
port_mappings
=
clibcni_
util_common_calloc_s
(
sizeof
(
port_mapping
*
)
*
(
rt
->
p_mapping_len
));
if
(
rt_config
->
port_mappings
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
-
1
;
}
for
(
j
=
0
;
j
<
rt
->
p_mapping_len
;
j
++
)
{
rt_config
->
port_mappings
[
j
]
=
util_common_calloc_s
(
sizeof
(
port_mapping
));
rt_config
->
port_mappings
[
j
]
=
clibcni_
util_common_calloc_s
(
sizeof
(
port_mapping
));
if
(
rt_config
->
port_mappings
[
j
]
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
-
1
;
}
(
rt_config
->
port_mappings_len
)
++
;
if
(
copy_cni_port_mapping
(
rt_config
->
port_mappings
[
j
],
rt
->
p_mapping
[
j
])
!=
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
-
1
;
}
...
...
@@ -114,9 +114,9 @@ static int inject_runtime_config_items(const struct network_config *orig, const
int
ret
=
-
1
;
size_t
i
=
0
;
*
rt_config
=
util_common_calloc_s
(
sizeof
(
net_conf_runtime_config
));
*
rt_config
=
clibcni_
util_common_calloc_s
(
sizeof
(
net_conf_runtime_config
));
if
(
*
rt_config
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
goto
free_out
;
}
...
...
@@ -150,7 +150,7 @@ static int do_generate_net_conf_json(const struct network_config *orig, char **r
*
result
=
net_conf_generate_json
(
orig
->
network
,
&
ctx
,
&
jerr
);
if
(
*
result
==
NULL
)
{
if
(
asprintf
(
err
,
"generate json failed: %s"
,
jerr
)
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
}
ERROR
(
"Generate json: %s"
,
jerr
);
...
...
@@ -246,9 +246,9 @@ static int build_one_config(const struct network_config_list *list, struct netwo
work
=
orig
->
network
;
free
(
work
->
name
);
work
->
name
=
util_strdup_s
(
list
->
list
->
name
);
work
->
name
=
clibcni_
util_strdup_s
(
list
->
list
->
name
);
free
(
work
->
cni_version
);
work
->
cni_version
=
util_strdup_s
(
list
->
list
->
cni_version
);
work
->
cni_version
=
clibcni_
util_strdup_s
(
list
->
list
->
cni_version
);
if
(
do_inject_prev_result
(
prev_result
,
work
,
err
)
!=
0
)
{
ERROR
(
"Inject pre result failed: %s"
,
*
err
!=
NULL
?
*
err
:
""
);
...
...
@@ -263,7 +263,7 @@ static int build_one_config(const struct network_config_list *list, struct netwo
ret
=
0
;
free_out:
if
(
ret
!=
0
&&
*
err
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
return
ret
;
}
...
...
@@ -281,7 +281,7 @@ static int do_check_generate_net_conf_json(char **full_conf_bytes, struct networ
pnet
->
bytes
=
net_conf_generate_json
(
pnet
->
network
,
&
ctx
,
&
serr
);
if
(
pnet
->
bytes
==
NULL
)
{
if
(
asprintf
(
err
,
"Generate json failed: %s"
,
serr
)
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"Generate json: %s"
,
serr
);
ret
=
-
1
;
...
...
@@ -308,7 +308,7 @@ static int run_cni_plugin(const struct network_config_list *list, size_t i, cons
net
.
network
=
list
->
list
->
plugins
[
i
];
if
(
net
.
network
==
NULL
)
{
*
err
=
util_strdup_s
(
"Empty network"
);
*
err
=
clibcni_
util_strdup_s
(
"Empty network"
);
ERROR
(
"Empty network"
);
goto
free_out
;
}
...
...
@@ -316,7 +316,7 @@ static int run_cni_plugin(const struct network_config_list *list, size_t i, cons
ret
=
find_in_path
(
net
.
network
->
type
,
paths
,
paths_len
,
&
plugin_path
,
&
save_errno
);
if
(
ret
!=
0
)
{
if
(
asprintf
(
err
,
"find plugin:
\"
%s
\"
failed: %s"
,
net
.
network
->
type
,
get_invoke_err_msg
(
save_errno
))
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"find plugin:
\"
%s
\"
failed: %s"
,
net
.
network
->
type
,
get_invoke_err_msg
(
save_errno
));
goto
free_out
;
...
...
@@ -441,7 +441,7 @@ static int add_network(const struct network_config *net, const struct runtime_co
ret
=
find_in_path
(
net
->
network
->
type
,
paths
,
paths_len
,
&
plugin_path
,
&
save_errno
);
if
(
ret
!=
0
)
{
if
(
asprintf
(
err
,
"find plugin:
\"
%s
\"
failed: %s"
,
net
->
network
->
type
,
get_invoke_err_msg
(
save_errno
))
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"find plugin:
\"
%s
\"
failed: %s"
,
net
->
network
->
type
,
get_invoke_err_msg
(
save_errno
));
goto
free_out
;
...
...
@@ -489,7 +489,7 @@ static int del_network(const struct network_config *net, const struct runtime_co
ret
=
find_in_path
(
net
->
network
->
type
,
paths
,
paths_len
,
&
plugin_path
,
&
save_errno
);
if
(
ret
!=
0
)
{
if
(
asprintf
(
err
,
"find plugin:
\"
%s
\"
failed: %s"
,
net
->
network
->
type
,
get_invoke_err_msg
(
save_errno
))
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"find plugin:
\"
%s
\"
failed: %s"
,
net
->
network
->
type
,
get_invoke_err_msg
(
save_errno
));
goto
free_out
;
...
...
@@ -527,14 +527,14 @@ static int do_copy_plugin_args(const struct runtime_conf *rc, struct cni_args **
ERROR
(
"Large arguments"
);
return
-
1
;
}
(
*
cargs
)
->
plugin_args
=
util_common_calloc_s
((
rc
->
args_len
)
*
sizeof
(
char
*
)
*
2
);
(
*
cargs
)
->
plugin_args
=
clibcni_
util_common_calloc_s
((
rc
->
args_len
)
*
sizeof
(
char
*
)
*
2
);
if
((
*
cargs
)
->
plugin_args
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
-
1
;
}
for
(
i
=
0
;
i
<
rc
->
args_len
;
i
++
)
{
(
*
cargs
)
->
plugin_args
[
i
][
0
]
=
util_strdup_s
(
rc
->
args
[
i
][
0
]);
(
*
cargs
)
->
plugin_args
[
i
][
1
]
=
util_strdup_s
(
rc
->
args
[
i
][
1
]);
(
*
cargs
)
->
plugin_args
[
i
][
0
]
=
clibcni_
util_strdup_s
(
rc
->
args
[
i
][
0
]);
(
*
cargs
)
->
plugin_args
[
i
][
1
]
=
clibcni_
util_strdup_s
(
rc
->
args
[
i
][
1
]);
(
*
cargs
)
->
plugin_args_len
=
(
i
+
1
);
}
...
...
@@ -544,13 +544,13 @@ static int do_copy_plugin_args(const struct runtime_conf *rc, struct cni_args **
static
int
copy_args
(
const
struct
runtime_conf
*
rc
,
struct
cni_args
**
cargs
)
{
if
(
rc
->
container_id
!=
NULL
)
{
(
*
cargs
)
->
container_id
=
util_strdup_s
(
rc
->
container_id
);
(
*
cargs
)
->
container_id
=
clibcni_
util_strdup_s
(
rc
->
container_id
);
}
if
(
rc
->
netns
!=
NULL
)
{
(
*
cargs
)
->
netns
=
util_strdup_s
(
rc
->
netns
);
(
*
cargs
)
->
netns
=
clibcni_
util_strdup_s
(
rc
->
netns
);
}
if
(
rc
->
ifname
!=
NULL
)
{
(
*
cargs
)
->
ifname
=
util_strdup_s
(
rc
->
ifname
);
(
*
cargs
)
->
ifname
=
clibcni_
util_strdup_s
(
rc
->
ifname
);
}
return
do_copy_plugin_args
(
rc
,
cargs
);
...
...
@@ -563,9 +563,9 @@ static int do_copy_args_paths(const char * const *paths, size_t paths_len, struc
}
if
(
paths_len
==
0
)
{
(
*
cargs
)
->
path
=
util_strdup_s
(
""
);
(
*
cargs
)
->
path
=
clibcni_
util_strdup_s
(
""
);
}
else
{
(
*
cargs
)
->
path
=
cni_util_string_join
(
":"
,
paths
,
paths_len
);
(
*
cargs
)
->
path
=
c
libc
ni_util_string_join
(
":"
,
paths
,
paths_len
);
if
((
*
cargs
)
->
path
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
-
1
;
...
...
@@ -588,14 +588,14 @@ static int args(const char *action, const struct runtime_conf *rc, const char *
ERROR
(
"Empty arguments"
);
return
ret
;
}
*
cargs
=
util_common_calloc_s
(
sizeof
(
struct
cni_args
));
*
cargs
=
clibcni_
util_common_calloc_s
(
sizeof
(
struct
cni_args
));
if
(
*
cargs
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
goto
free_out
;
}
if
(
action
!=
NULL
)
{
(
*
cargs
)
->
command
=
util_strdup_s
(
action
);
(
*
cargs
)
->
command
=
clibcni_
util_strdup_s
(
action
);
}
if
(
do_copy_args_paths
(
paths
,
paths_len
,
cargs
)
!=
0
)
{
goto
free_out
;
...
...
@@ -607,7 +607,7 @@ free_out:
free_cni_args
(
*
cargs
);
*
cargs
=
NULL
;
if
(
*
err
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
}
return
ret
;
...
...
@@ -685,7 +685,7 @@ int cni_add_network_list(const char *net_list_conf_str, const struct runtime_con
return
-
1
;
}
if
(
net_list_conf_str
==
NULL
)
{
*
err
=
util_strdup_s
(
"Empty net list conf argument"
);
*
err
=
clibcni_
util_strdup_s
(
"Empty net list conf argument"
);
ERROR
(
"Empty net list conf argument"
);
return
-
1
;
}
...
...
@@ -696,7 +696,7 @@ int cni_add_network_list(const char *net_list_conf_str, const struct runtime_con
return
ret
;
}
len
=
util_array_len
((
const
char
*
const
*
)
paths
);
len
=
clibcni_
util_array_len
((
const
char
*
const
*
)
paths
);
ret
=
add_network_list
(
list
,
rc
,
(
const
char
*
const
*
)
paths
,
len
,
pret
,
err
);
DEBUG
(
"Add network list return with: %d"
,
ret
);
...
...
@@ -716,7 +716,7 @@ int cni_add_network(const char *net_conf_str, const struct runtime_conf *rc, cha
return
-
1
;
}
if
(
net_conf_str
==
NULL
)
{
*
err
=
util_strdup_s
(
"Empty net conf argument"
);
*
err
=
clibcni_
util_strdup_s
(
"Empty net conf argument"
);
ERROR
(
"Empty net conf argument"
);
return
-
1
;
}
...
...
@@ -727,7 +727,7 @@ int cni_add_network(const char *net_conf_str, const struct runtime_conf *rc, cha
return
ret
;
}
len
=
util_array_len
((
const
char
*
const
*
)
paths
);
len
=
clibcni_
util_array_len
((
const
char
*
const
*
)
paths
);
ret
=
add_network
(
net
,
rc
,
(
const
char
*
const
*
)
paths
,
len
,
add_result
,
err
);
free_network_config
(
net
);
return
ret
;
...
...
@@ -744,7 +744,7 @@ int cni_del_network_list(const char *net_list_conf_str, const struct runtime_con
return
-
1
;
}
if
(
net_list_conf_str
==
NULL
)
{
*
err
=
util_strdup_s
(
"Empty net list conf argument"
);
*
err
=
clibcni_
util_strdup_s
(
"Empty net list conf argument"
);
ERROR
(
"Empty net list conf argument"
);
return
-
1
;
}
...
...
@@ -755,7 +755,7 @@ int cni_del_network_list(const char *net_list_conf_str, const struct runtime_con
return
ret
;
}
len
=
util_array_len
((
const
char
*
const
*
)
paths
);
len
=
clibcni_
util_array_len
((
const
char
*
const
*
)
paths
);
ret
=
del_network_list
(
list
,
rc
,
(
const
char
*
const
*
)
paths
,
len
,
err
);
DEBUG
(
"Delete network list return with: %d"
,
ret
);
...
...
@@ -774,7 +774,7 @@ int cni_del_network(const char *net_conf_str, const struct runtime_conf *rc, cha
return
-
1
;
}
if
(
net_conf_str
==
NULL
)
{
*
err
=
util_strdup_s
(
"Empty net conf argument"
);
*
err
=
clibcni_
util_strdup_s
(
"Empty net conf argument"
);
ERROR
(
"Empty net conf argument"
);
return
-
1
;
}
...
...
@@ -785,7 +785,7 @@ int cni_del_network(const char *net_conf_str, const struct runtime_conf *rc, cha
return
ret
;
}
len
=
util_array_len
((
const
char
*
const
*
)
paths
);
len
=
clibcni_
util_array_len
((
const
char
*
const
*
)
paths
);
ret
=
del_network
(
net
,
rc
,
(
const
char
*
const
*
)
paths
,
len
,
err
);
free_network_config
(
net
);
return
ret
;
...
...
@@ -802,11 +802,11 @@ int cni_get_version_info(const char *plugin_type, char **paths, struct plugin_in
ERROR
(
"Empty err"
);
return
-
1
;
}
len
=
util_array_len
((
const
char
*
const
*
)
paths
);
len
=
clibcni_
util_array_len
((
const
char
*
const
*
)
paths
);
ret
=
find_in_path
(
plugin_type
,
(
const
char
*
const
*
)
paths
,
len
,
&
plugin_path
,
&
save_errno
);
if
(
ret
!=
0
)
{
if
(
asprintf
(
err
,
"find plugin:
\"
%s
\"
failed: %s"
,
plugin_type
,
get_invoke_err_msg
(
save_errno
))
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"find plugin:
\"
%s
\"
failed: %s"
,
plugin_type
,
get_invoke_err_msg
(
save_errno
));
return
ret
;
...
...
@@ -841,17 +841,17 @@ int cni_conf_from_file(const char *filename, struct cni_network_conf **config, c
return
ret
;
}
*
config
=
util_common_calloc_s
(
sizeof
(
struct
cni_network_conf
));
*
config
=
clibcni_
util_common_calloc_s
(
sizeof
(
struct
cni_network_conf
));
if
(
*
config
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ret
=
-
1
;
ERROR
(
"Out of memory"
);
goto
free_out
;
}
if
(
netconf
!=
NULL
&&
netconf
->
network
!=
NULL
)
{
(
*
config
)
->
type
=
netconf
->
network
->
type
?
util_strdup_s
(
netconf
->
network
->
type
)
:
NULL
;
(
*
config
)
->
name
=
netconf
->
network
->
name
?
util_strdup_s
(
netconf
->
network
->
name
)
:
NULL
;
(
*
config
)
->
type
=
netconf
->
network
->
type
?
clibcni_
util_strdup_s
(
netconf
->
network
->
type
)
:
NULL
;
(
*
config
)
->
name
=
netconf
->
network
->
name
?
clibcni_
util_strdup_s
(
netconf
->
network
->
name
)
:
NULL
;
}
if
(
netconf
!=
NULL
)
{
(
*
config
)
->
bytes
=
netconf
->
bytes
;
...
...
@@ -874,13 +874,13 @@ static void json_obj_to_cni_list_conf(struct network_config_list *src, struct cn
list
->
bytes
=
src
->
bytes
;
src
->
bytes
=
NULL
;
if
(
src
->
list
!=
NULL
)
{
list
->
name
=
src
->
list
->
name
?
util_strdup_s
(
src
->
list
->
name
)
:
NULL
;
list
->
name
=
src
->
list
->
name
?
clibcni_
util_strdup_s
(
src
->
list
->
name
)
:
NULL
;
list
->
plugin_len
=
src
->
list
->
plugins_len
;
if
(
src
->
list
->
plugins_len
>
0
&&
src
->
list
->
plugins
!=
NULL
&&
src
->
list
->
plugins
[
0
]
!=
NULL
)
{
list
->
first_plugin_name
=
src
->
list
->
plugins
[
0
]
->
name
!=
NULL
?
util_strdup_s
(
src
->
list
->
plugins
[
0
]
->
name
)
:
NULL
;
clibcni_
util_strdup_s
(
src
->
list
->
plugins
[
0
]
->
name
)
:
NULL
;
list
->
first_plugin_type
=
src
->
list
->
plugins
[
0
]
->
type
!=
NULL
?
util_strdup_s
(
src
->
list
->
plugins
[
0
]
->
type
)
:
NULL
;
clibcni_
util_strdup_s
(
src
->
list
->
plugins
[
0
]
->
type
)
:
NULL
;
}
}
}
...
...
@@ -898,9 +898,9 @@ int cni_conflist_from_bytes(const char *bytes, struct cni_network_list_conf **li
if
(
ret
!=
0
)
{
return
ret
;
}
*
list
=
util_common_calloc_s
(
sizeof
(
struct
cni_network_list_conf
));
*
list
=
clibcni_
util_common_calloc_s
(
sizeof
(
struct
cni_network_list_conf
));
if
(
*
list
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ret
=
-
1
;
ERROR
(
"Out of memory"
);
goto
free_out
;
...
...
@@ -927,9 +927,9 @@ int cni_conflist_from_file(const char *filename, struct cni_network_list_conf **
if
(
ret
!=
0
)
{
return
ret
;
}
*
list
=
util_common_calloc_s
(
sizeof
(
struct
cni_network_list_conf
));
*
list
=
clibcni_
util_common_calloc_s
(
sizeof
(
struct
cni_network_list_conf
));
if
(
*
list
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ret
=
-
1
;
ERROR
(
"Out of memory"
);
goto
free_out
;
...
...
@@ -964,7 +964,7 @@ int cni_conflist_from_conf(const struct cni_network_conf *cni_conf, struct cni_n
invalid_arg
=
check_cni_conflist_from_conf_args
(
cni_conf
,
cni_conf_list
);
if
(
invalid_arg
)
{
*
err
=
util_strdup_s
(
"Empty cni conf or conflist argument"
);
*
err
=
clibcni_
util_strdup_s
(
"Empty cni conf or conflist argument"
);
ERROR
(
"Empty cni conf or conflist argument"
);
return
-
1
;
}
...
...
@@ -979,9 +979,9 @@ int cni_conflist_from_conf(const struct cni_network_conf *cni_conf, struct cni_n
goto
free_out
;
}
*
cni_conf_list
=
util_common_calloc_s
(
sizeof
(
struct
cni_network_list_conf
));
*
cni_conf_list
=
clibcni_
util_common_calloc_s
(
sizeof
(
struct
cni_network_list_conf
));
if
(
*
cni_conf_list
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
ret
=
-
1
;
goto
free_out
;
...
...
src/conf.c
浏览文件 @
7552595c
...
...
@@ -44,23 +44,23 @@ static int do_conf_from_bytes(const char *conf_str, struct network_config *confi
if
(
config
->
network
==
NULL
)
{
ret
=
asprintf
(
err
,
"Error parsing configuration: %s"
,
jerr
);
if
(
ret
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"Error parsing configuration: %s"
,
jerr
);
ret
=
-
1
;
goto
out
;
}
if
(
config
->
network
->
name
!=
NULL
&&
util_validate_name
(
config
->
network
->
name
)
!=
0
)
{
if
(
config
->
network
->
name
!=
NULL
&&
clibcni_
util_validate_name
(
config
->
network
->
name
)
!=
0
)
{
ret
=
asprintf
(
err
,
"Invalid network name: %s"
,
config
->
network
->
name
);
if
(
ret
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"Invalid network name: %s"
,
config
->
network
->
name
);
ret
=
-
1
;
goto
out
;
}
config
->
bytes
=
util_strdup_s
(
conf_str
);
config
->
bytes
=
clibcni_
util_strdup_s
(
conf_str
);
out:
free
(
jerr
);
return
ret
;
...
...
@@ -80,13 +80,13 @@ int conf_from_bytes(const char *conf_str, struct network_config **config, char *
return
ret
;
}
if
(
conf_str
==
NULL
)
{
*
err
=
util_strdup_s
(
"Empty json"
);
*
err
=
clibcni_
util_strdup_s
(
"Empty json"
);
ERROR
(
"Empty json"
);
return
ret
;
}
*
config
=
util_common_calloc_s
(
sizeof
(
struct
network_config
));
*
config
=
clibcni_
util_common_calloc_s
(
sizeof
(
struct
network_config
));
if
(
*
config
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
goto
free_out
;
}
...
...
@@ -108,7 +108,7 @@ static char *do_get_net_confs_json(const char *filename, char **err)
content
=
read_file
(
filename
,
&
filesize
);
if
(
content
==
NULL
)
{
if
(
asprintf
(
err
,
"Read file %s failed: %s"
,
filename
,
strerror
(
errno
))
<
0
)
{
*
err
=
util_strdup_s
(
"Read file failed"
);
*
err
=
clibcni_
util_strdup_s
(
"Read file failed"
);
}
ERROR
(
"Read file %s failed: %s"
,
filename
,
strerror
(
errno
));
}
...
...
@@ -149,19 +149,19 @@ static int do_check_net_conf_list_plugins(const net_conf_list *tmp_list, char **
size_t
i
=
0
;
if
(
tmp_list
->
plugins
==
NULL
)
{
*
err
=
util_strdup_s
(
"Error parsing configuration list: no 'plugins' key"
);
*
err
=
clibcni_
util_strdup_s
(
"Error parsing configuration list: no 'plugins' key"
);
ERROR
(
"Error parsing configuration list: no 'plugins' key"
);
return
-
1
;
}
if
(
tmp_list
->
plugins_len
==
0
)
{
*
err
=
util_strdup_s
(
"Error parsing configuration list: no plugins in list"
);
*
err
=
clibcni_
util_strdup_s
(
"Error parsing configuration list: no plugins in list"
);
ERROR
(
"Error parsing configuration list: no plugins in list"
);
return
-
1
;
}
for
(
i
=
0
;
i
<
tmp_list
->
plugins_len
;
i
++
)
{
if
(
tmp_list
->
plugins
[
i
]
->
name
!=
NULL
&&
util_validate_name
(
tmp_list
->
plugins
[
i
]
->
name
)
!=
0
)
{
if
(
tmp_list
->
plugins
[
i
]
->
name
!=
NULL
&&
clibcni_
util_validate_name
(
tmp_list
->
plugins
[
i
]
->
name
)
!=
0
)
{
if
(
asprintf
(
err
,
"Invalid network name: %s"
,
tmp_list
->
plugins
[
i
]
->
name
)
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"Invalid network name: %s"
,
tmp_list
->
plugins
[
i
]
->
name
);
return
-
1
;
...
...
@@ -173,14 +173,14 @@ static int do_check_net_conf_list_plugins(const net_conf_list *tmp_list, char **
static
int
check_net_conf_list
(
const
net_conf_list
*
tmp_list
,
char
**
err
)
{
if
(
tmp_list
->
name
==
NULL
)
{
*
err
=
util_strdup_s
(
"Error parsing configuration list: no name"
);
*
err
=
clibcni_
util_strdup_s
(
"Error parsing configuration list: no name"
);
ERROR
(
"Name is NULL"
);
return
-
1
;
}
if
(
util_validate_name
(
tmp_list
->
name
)
!=
0
)
{
if
(
clibcni_
util_validate_name
(
tmp_list
->
name
)
!=
0
)
{
if
(
asprintf
(
err
,
"Invalid network name: %s"
,
tmp_list
->
name
)
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"Invalid network name: %s"
,
tmp_list
->
name
);
return
-
1
;
...
...
@@ -205,13 +205,13 @@ int conflist_from_bytes(const char *json_str, struct network_config_list **list,
return
ret
;
}
if
(
json_str
==
NULL
)
{
*
err
=
util_strdup_s
(
"Empty json"
);
*
err
=
clibcni_
util_strdup_s
(
"Empty json"
);
ERROR
(
"Empty json"
);
return
-
1
;
}
*
list
=
util_common_calloc_s
(
sizeof
(
struct
network_config_list
));
*
list
=
clibcni_
util_common_calloc_s
(
sizeof
(
struct
network_config_list
));
if
(
*
list
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
goto
free_out
;
}
...
...
@@ -219,7 +219,7 @@ int conflist_from_bytes(const char *json_str, struct network_config_list **list,
if
(
tmp_list
==
NULL
)
{
ret
=
asprintf
(
err
,
"Error parsing configuration list: %s"
,
jerr
);
if
(
ret
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"Error parsing configuration list: %s"
,
jerr
);
ret
=
-
1
;
...
...
@@ -231,7 +231,7 @@ int conflist_from_bytes(const char *json_str, struct network_config_list **list,
goto
free_out
;
}
(
*
list
)
->
bytes
=
util_strdup_s
(
json_str
);
(
*
list
)
->
bytes
=
clibcni_
util_strdup_s
(
json_str
);
(
*
list
)
->
list
=
tmp_list
;
ret
=
0
;
...
...
@@ -303,7 +303,7 @@ static int check_conf_dir(const char *dir, DIR **directory, char **err)
return
0
;
}
if
(
asprintf
(
err
,
"Open dir failed: %s"
,
strerror
(
errno
))
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
SYSERROR
(
"Open dir failed"
);
return
-
1
;
...
...
@@ -320,7 +320,7 @@ static int do_check_file_is_valid(const char *fname, int *result, char **err)
if
(
nret
!=
0
)
{
nret
=
asprintf
(
err
,
"lstat %s failed: %s"
,
fname
,
strerror
(
errno
));
if
(
nret
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
SYSERROR
(
"lstat %s failed"
,
fname
);
*
result
=
-
1
;
...
...
@@ -337,7 +337,7 @@ static int do_check_file_is_valid(const char *fname, int *result, char **err)
if
(
tmp_fstat
.
st_size
>
MB
)
{
nret
=
asprintf
(
err
,
"Too large config file: %s"
,
fname
);
if
(
nret
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"Too large config file: %s"
,
fname
);
*
result
=
-
1
;
...
...
@@ -360,7 +360,7 @@ static int check_conf_file(const char *dir, const char * const *extensions, size
nret
=
snprintf
(
fname
,
PATH_MAX
,
"%s/%s"
,
dir
,
pdirent
->
d_name
);
if
(
nret
<
0
||
nret
>=
PATH_MAX
)
{
*
err
=
util_strdup_s
(
"Pathname too long"
);
*
err
=
clibcni_
util_strdup_s
(
"Pathname too long"
);
ERROR
(
"Pathname too long"
);
return
-
1
;
}
...
...
@@ -379,12 +379,12 @@ static int check_conf_file(const char *dir, const char * const *extensions, size
ext_name
=
(
pdirent
->
d_name
)
+
nret
;
for
(
i
=
0
;
i
<
ext_len
;
i
++
)
{
if
(
extensions
[
i
]
!=
NULL
&&
strcmp
(
ext_name
,
extensions
[
i
])
==
0
)
{
if
(
util_grow_array
(
result
,
&
cap
,
(
*
result_size
)
+
1
,
2
)
!=
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
if
(
clibcni_
util_grow_array
(
result
,
&
cap
,
(
*
result_size
)
+
1
,
2
)
!=
0
)
{
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
-
1
;
}
(
*
result
)[(
*
result_size
)
++
]
=
util_strdup_s
(
fname
);
(
*
result
)[(
*
result_size
)
++
]
=
clibcni_
util_strdup_s
(
fname
);
break
;
}
}
...
...
@@ -435,7 +435,7 @@ int conf_files(const char *dir, const char * const *extensions, size_t ext_len,
if
(
size
>
MAX_FILES
)
{
nret
=
asprintf
(
err
,
"Too more config files, current support max count of config file is %d."
,
MAX_FILES
);
if
(
nret
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"Too more config files, current support max count of config file is %d."
,
MAX_FILES
);
ret
=
-
1
;
...
...
@@ -447,13 +447,13 @@ free_out:
nret
=
closedir
(
directory
);
if
(
nret
!=
0
)
{
if
(
*
err
==
NULL
)
{
*
err
=
util_strdup_s
(
"Failed to close directory"
);
*
err
=
clibcni_
util_strdup_s
(
"Failed to close directory"
);
SYSERROR
(
"Failed to close directory"
);
}
ret
=
-
1
;
}
if
(
ret
!=
0
)
{
util_free_array
(
*
result
);
clibcni_
util_free_array
(
*
result
);
*
result
=
NULL
;
}
return
ret
;
...
...
@@ -488,10 +488,10 @@ int load_conf(const char *dir, const char *name, struct network_config **conf, c
if
(
ret
!=
0
)
{
return
-
1
;
}
len
=
util_array_len
((
const
char
*
const
*
)
files
);
len
=
clibcni_
util_array_len
((
const
char
*
const
*
)
files
);
if
(
len
==
0
)
{
if
(
asprintf
(
err
,
"no net configurations found in %s"
,
dir
)
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"no net configurations found in %s"
,
dir
);
goto
free_out
;
...
...
@@ -513,13 +513,13 @@ int load_conf(const char *dir, const char *name, struct network_config **conf, c
}
ret
=
asprintf
(
err
,
"No net configuration with name
\"
%s
\"
in %s"
,
name
,
dir
);
if
(
ret
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"No net configuration with name
\"
%s
\"
in %s"
,
name
,
dir
);
ret
=
-
1
;
free_out:
util_free_array
(
files
);
clibcni_
util_free_array
(
files
);
return
ret
;
}
...
...
@@ -534,7 +534,7 @@ static int generate_new_conflist(const net_conf_list *list, struct network_confi
if
(
net_conf_json_str
==
NULL
)
{
ret
=
asprintf
(
err
,
"Generate conf list json failed: %s"
,
jerr
);
if
(
ret
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"Generate conf list json failed: %s"
,
jerr
);
goto
free_out
;
...
...
@@ -547,7 +547,7 @@ static int generate_new_conflist(const net_conf_list *list, struct network_confi
if
((
*
conf_list
)
->
list
==
NULL
)
{
ret
=
asprintf
(
err
,
"Parse conf list from json failed: %s"
,
jerr
);
if
(
ret
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"Parse conf list from json failed: %s"
,
jerr
);
goto
free_out
;
...
...
@@ -573,22 +573,22 @@ int conflist_from_conf(const struct network_config *conf, struct network_config_
ERROR
(
"Invalid arguments"
);
return
-
1
;
}
*
conf_list
=
util_common_calloc_s
(
sizeof
(
struct
network_config_list
));
*
conf_list
=
clibcni_
util_common_calloc_s
(
sizeof
(
struct
network_config_list
));
if
(
*
conf_list
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
-
1
;
}
list
=
util_common_calloc_s
(
sizeof
(
net_conf_list
));
list
=
clibcni_
util_common_calloc_s
(
sizeof
(
net_conf_list
));
if
(
list
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
goto
free_out
;
}
list
->
plugins
=
util_common_calloc_s
(
sizeof
(
net_conf
*
)
*
(
1
+
1
));
list
->
plugins
=
clibcni_
util_common_calloc_s
(
sizeof
(
net_conf
*
)
*
(
1
+
1
));
if
(
list
->
plugins
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
goto
free_out
;
}
...
...
@@ -596,10 +596,10 @@ int conflist_from_conf(const struct network_config *conf, struct network_config_
list
->
plugins_len
=
1
;
if
(
conf
->
network
->
cni_version
!=
NULL
)
{
list
->
cni_version
=
util_strdup_s
(
conf
->
network
->
cni_version
);
list
->
cni_version
=
clibcni_
util_strdup_s
(
conf
->
network
->
cni_version
);
}
if
(
conf
->
network
->
name
!=
NULL
)
{
list
->
name
=
util_strdup_s
(
conf
->
network
->
name
);
list
->
name
=
clibcni_
util_strdup_s
(
conf
->
network
->
name
);
}
ret
=
generate_new_conflist
(
list
,
conf_list
,
err
);
...
...
src/invoke/args.c
浏览文件 @
7552595c
...
...
@@ -71,23 +71,23 @@ static char *env_stringify(char *(*pargs)[2], size_t len)
ERROR
(
"Too large arguments"
);
return
NULL
;
}
entries
=
util_common_calloc_s
(
sizeof
(
char
*
)
*
(
len
+
1
));
entries
=
clibcni_
util_common_calloc_s
(
sizeof
(
char
*
)
*
(
len
+
1
));
if
(
entries
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
NULL
;
}
for
(
i
=
0
;
i
<
len
;
i
++
)
{
work
=
(
const
char
**
)
pargs
[
i
];
entries
[
i
]
=
cni_util_string_join
(
"="
,
work
,
2
);
entries
[
i
]
=
c
libc
ni_util_string_join
(
"="
,
work
,
2
);
if
(
entries
[
i
]
==
NULL
)
{
ERROR
(
"Join args failed"
);
goto
free_out
;
}
}
result
=
cni_util_string_join
(
";"
,
(
const
char
**
)
entries
,
len
);
result
=
c
libc
ni_util_string_join
(
";"
,
(
const
char
**
)
entries
,
len
);
free_out:
util_free_array
(
entries
);
clibcni_
util_free_array
(
entries
);
return
result
;
}
...
...
@@ -99,8 +99,8 @@ static int add_cni_envs(const struct cni_args *cniargs, size_t *pos, char **resu
int
nret
=
0
;
int
ret
=
-
1
;
plugin_args_str
=
cniargs
->
plugin_args_str
?
util_strdup_s
(
cniargs
->
plugin_args_str
)
:
NULL
;
if
(
is_null_or_empty
(
plugin_args_str
))
{
plugin_args_str
=
cniargs
->
plugin_args_str
?
clibcni_
util_strdup_s
(
cniargs
->
plugin_args_str
)
:
NULL
;
if
(
clibcni_
is_null_or_empty
(
plugin_args_str
))
{
free
(
plugin_args_str
);
plugin_args_str
=
env_stringify
(
cniargs
->
plugin_args
,
cniargs
->
plugin_args_len
);
}
...
...
@@ -168,7 +168,7 @@ char **as_env(const struct cni_args *cniargs)
return
NULL
;
}
len
=
util_array_len
((
const
char
*
const
*
)
envir
);
len
=
clibcni_
util_array_len
((
const
char
*
const
*
)
envir
);
if
(
len
>
((
SIZE_MAX
/
sizeof
(
char
*
))
-
(
CNI_ENVS_LEN
+
1
)))
{
ERROR
(
"Too large arguments"
);
...
...
@@ -176,7 +176,7 @@ char **as_env(const struct cni_args *cniargs)
}
len
+=
(
CNI_ENVS_LEN
+
1
);
result
=
util_common_calloc_s
(
len
*
sizeof
(
char
*
));
result
=
clibcni_
util_common_calloc_s
(
len
*
sizeof
(
char
*
));
if
(
result
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
NULL
;
...
...
@@ -188,7 +188,7 @@ char **as_env(const struct cni_args *cniargs)
/* inherit environs of parent */
for
(
pos
=
envir
;
pos
!=
NULL
&&
*
pos
!=
NULL
&&
i
<
len
;
pos
++
)
{
result
[
i
]
=
util_strdup_s
(
*
pos
);
result
[
i
]
=
clibcni_
util_strdup_s
(
*
pos
);
i
++
;
}
...
...
src/invoke/exec.c
浏览文件 @
7552595c
...
...
@@ -62,7 +62,7 @@ static int do_parse_exec_stdout_str(int exec_ret, const char *net_conf_json, con
if
(
e_err
!=
NULL
)
{
*
err
=
str_exec_error
(
e_err
);
}
else
{
*
err
=
util_strdup_s
(
"raw exec fail"
);
*
err
=
clibcni_
util_strdup_s
(
"raw exec fail"
);
}
}
else
{
version
=
cniversion_decode
(
net_conf_json
,
err
);
...
...
@@ -71,7 +71,7 @@ static int do_parse_exec_stdout_str(int exec_ret, const char *net_conf_json, con
ERROR
(
"Decode cni version failed: %s"
,
*
err
!=
NULL
?
*
err
:
""
);
goto
out
;
}
if
(
is_null_or_empty
(
stdout_str
))
{
if
(
clibcni_
is_null_or_empty
(
stdout_str
))
{
ERROR
(
"Get empty stdout message"
);
goto
out
;
}
...
...
@@ -108,7 +108,7 @@ int exec_plugin_with_result(const char *plugin_path, const char *net_conf_json,
if
(
cniargs
!=
NULL
)
{
envs
=
as_env
(
cniargs
);
if
(
envs
==
NULL
)
{
*
err
=
util_strdup_s
(
"As env failed"
);
*
err
=
clibcni_
util_strdup_s
(
"As env failed"
);
ret
=
-
1
;
goto
out
;
}
...
...
@@ -119,7 +119,7 @@ int exec_plugin_with_result(const char *plugin_path, const char *net_conf_json,
ret
=
do_parse_exec_stdout_str
(
ret
,
net_conf_json
,
e_err
,
stdout_str
,
result
,
err
);
out:
free
(
stdout_str
);
util_free_array
(
envs
);
clibcni_
util_free_array
(
envs
);
free_exec_error
(
e_err
);
return
ret
;
}
...
...
@@ -139,7 +139,7 @@ int exec_plugin_without_result(const char *plugin_path, const char *net_conf_jso
if
(
cniargs
!=
NULL
)
{
envs
=
as_env
(
cniargs
);
if
(
envs
==
NULL
)
{
*
err
=
util_strdup_s
(
"As env failed"
);
*
err
=
clibcni_
util_strdup_s
(
"As env failed"
);
goto
out
;
}
}
...
...
@@ -149,12 +149,12 @@ int exec_plugin_without_result(const char *plugin_path, const char *net_conf_jso
if
(
e_err
!=
NULL
)
{
*
err
=
str_exec_error
(
e_err
);
}
else
{
*
err
=
util_strdup_s
(
"raw exec fail"
);
*
err
=
clibcni_
util_strdup_s
(
"raw exec fail"
);
}
}
DEBUG
(
"Raw exec
\"
%s
\"
result: %d"
,
plugin_path
,
ret
);
out:
util_free_array
(
envs
);
clibcni_
util_free_array
(
envs
);
free_exec_error
(
e_err
);
return
ret
;
}
...
...
@@ -212,11 +212,11 @@ int raw_get_version_info(const char *plugin_path, struct plugin_info **result, c
envs
=
as_env
(
&
args
);
if
(
envs
==
NULL
)
{
ret
=
-
1
;
*
err
=
util_strdup_s
(
"As env failed"
);
*
err
=
clibcni_
util_strdup_s
(
"As env failed"
);
goto
free_out
;
}
len
=
strlen
(
"{
\"
cniVersion
\"
:}"
)
+
strlen
(
version
)
+
1
;
stdin_data
=
util_common_calloc_s
(
len
);
stdin_data
=
clibcni_
util_common_calloc_s
(
len
);
if
(
stdin_data
==
NULL
)
{
ERROR
(
"Out of memory"
);
ret
=
-
1
;
...
...
@@ -225,7 +225,7 @@ int raw_get_version_info(const char *plugin_path, struct plugin_info **result, c
ret
=
snprintf
(
stdin_data
,
len
,
"{
\"
cniVersion
\"
:%s}"
,
version
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
{
ERROR
(
"Sprintf failed"
);
*
err
=
util_strdup_s
(
"Sprintf failed"
);
*
err
=
clibcni_
util_strdup_s
(
"Sprintf failed"
);
goto
free_out
;
}
ret
=
raw_exec
(
plugin_path
,
stdin_data
,
envs
,
&
stdout_str
,
&
e_err
);
...
...
@@ -241,7 +241,7 @@ int raw_get_version_info(const char *plugin_path, struct plugin_info **result, c
free_out:
free_exec_error
(
e_err
);
util_free_array
(
envs
);
clibcni_
util_free_array
(
envs
);
free
(
stdin_data
);
free
(
stdout_str
);
return
ret
;
...
...
@@ -303,7 +303,7 @@ static void child_fun(const char *plugin_path, int pipe_stdin, int pipe_stdout,
char
*
argv
[
2
]
=
{
NULL
};
int
ecode
=
0
;
argv
[
0
]
=
util_strdup_s
(
plugin_path
);
argv
[
0
]
=
clibcni_
util_strdup_s
(
plugin_path
);
ecode
=
prepare_child
(
pipe_stdin
,
pipe_stdout
);
if
(
ecode
!=
0
)
{
...
...
@@ -334,7 +334,7 @@ child_err_out:
static
inline
bool
check_prepare_raw_exec_args
(
const
char
*
plugin_path
)
{
return
(
plugin_path
==
NULL
||
util_validate_absolute_path
(
plugin_path
));
return
(
plugin_path
==
NULL
||
clibcni_
util_validate_absolute_path
(
plugin_path
));
}
static
int
prepare_raw_exec
(
const
char
*
plugin_path
,
int
pipe_stdin
[
2
],
int
pipe_stdout
[
2
],
char
*
errmsg
,
size_t
len
)
...
...
@@ -379,7 +379,7 @@ static int write_stdin_data_to_child(int pipe_stdin[2], const char *stdin_data,
}
len
=
strlen
(
stdin_data
);
if
(
util_write_nointr
(
pipe_stdin
[
1
],
stdin_data
,
len
)
!=
(
ssize_t
)
len
)
{
if
(
clibcni_
util_write_nointr
(
pipe_stdin
[
1
],
stdin_data
,
len
)
!=
(
ssize_t
)
len
)
{
ret
=
snprintf
(
errmsg
,
errmsg_len
,
"Write stdin data failed: %s"
,
strerror
(
errno
));
if
(
ret
<
0
||
(
size_t
)
ret
>=
errmsg_len
)
{
ERROR
(
"Sprintf failed"
);
...
...
@@ -400,8 +400,8 @@ static int read_child_stdout_msg(const int pipe_stdout[2], char *errmsg, size_t
return
0
;
}
if
(
stdout_str
!=
NULL
)
{
char
buffer
[
BUFFER_SIZE
]
=
{
0
};
ssize_t
tmp_len
=
util_read_nointr
(
pipe_stdout
[
0
],
buffer
,
BUFFER_SIZE
-
1
);
char
buffer
[
CLIBCNI_
BUFFER_SIZE
]
=
{
0
};
ssize_t
tmp_len
=
clibcni_util_read_nointr
(
pipe_stdout
[
0
],
buffer
,
CLIBCNI_
BUFFER_SIZE
-
1
);
if
(
tmp_len
<
0
)
{
ret
=
snprintf
(
errmsg
,
errmsg_len
,
"%s; read stdout failed: %s"
,
strlen
(
errmsg
)
>
0
?
errmsg
:
""
,
strerror
(
errno
));
...
...
@@ -410,7 +410,7 @@ static int read_child_stdout_msg(const int pipe_stdout[2], char *errmsg, size_t
}
ret
=
-
1
;
}
else
if
(
tmp_len
>
0
)
{
*
stdout_str
=
util_strdup_s
(
buffer
);
*
stdout_str
=
clibcni_
util_strdup_s
(
buffer
);
}
}
...
...
@@ -515,12 +515,12 @@ static void make_err_message(const char *plugin_path, char **stdout_str, int ret
get_err_msg
=
(
nret
!=
0
&&
*
err
==
NULL
&&
strlen
(
errmsg
)
>
0
);
if
(
get_err_msg
)
{
*
err
=
util_common_calloc_s
(
sizeof
(
exec_error
));
*
err
=
clibcni_
util_common_calloc_s
(
sizeof
(
exec_error
));
if
(
*
err
!=
NULL
)
{
char
*
tmp_err
=
NULL
;
nret
=
asprintf
(
&
tmp_err
,
"exec
\'
%s
\'
failed: %s"
,
plugin_path
,
errmsg
);
if
(
nret
<
0
)
{
tmp_err
=
util_strdup_s
(
errmsg
);
tmp_err
=
clibcni_
util_strdup_s
(
errmsg
);
}
(
*
err
)
->
msg
=
tmp_err
;
(
*
err
)
->
code
=
1
;
...
...
@@ -558,7 +558,7 @@ static int raw_exec(const char *plugin_path, const char *stdin_data, char * cons
int
pipe_stdout
[
2
]
=
{
-
1
,
-
1
};
int
pipe_stdin
[
2
]
=
{
-
1
,
-
1
};
pid_t
child_pid
=
0
;
char
errmsg
[
BUFFER_SIZE
]
=
{
0
};
char
errmsg
[
CLIBCNI_
BUFFER_SIZE
]
=
{
0
};
bool
parse_exec_err
=
false
;
if
(
prepare_raw_exec
(
plugin_path
,
pipe_stdin
,
pipe_stdout
,
errmsg
,
sizeof
(
errmsg
))
!=
0
)
{
...
...
@@ -583,7 +583,7 @@ static int raw_exec(const char *plugin_path, const char *stdin_data, char * cons
pipe_stdout
[
0
]
=
-
1
;
size_t
envs_len
=
0
;
envs_len
=
util_array_len
((
const
char
*
const
*
)
environs
);
envs_len
=
clibcni_
util_array_len
((
const
char
*
const
*
)
environs
);
child_fun
(
plugin_path
,
pipe_stdin
[
0
],
pipe_stdout
[
1
],
environs
,
envs_len
);
/* exit in child_fun */
}
...
...
src/invoke/tools.c
浏览文件 @
7552595c
...
...
@@ -69,7 +69,7 @@ static int do_check_file(const char *plugin, const char *path, char **find_path,
}
nret
=
stat
(
tmp_path
,
&
rt_stat
);
if
(
nret
==
0
&&
S_ISREG
(
rt_stat
.
st_mode
))
{
*
find_path
=
util_strdup_s
(
tmp_path
);
*
find_path
=
clibcni_
util_strdup_s
(
tmp_path
);
*
save_errno
=
0
;
return
0
;
}
else
{
...
...
@@ -81,7 +81,7 @@ static int do_check_file(const char *plugin, const char *path, char **find_path,
static
inline
bool
check_find_in_path_args
(
const
char
*
plugin
,
const
char
*
const
*
paths
,
size_t
len
,
char
*
const
*
find_path
)
{
return
(
is_null_or_empty
(
plugin
)
||
paths
==
NULL
||
len
==
0
||
find_path
==
NULL
);
return
(
clibcni_
is_null_or_empty
(
plugin
)
||
paths
==
NULL
||
len
==
0
||
find_path
==
NULL
);
}
int
find_in_path
(
const
char
*
plugin
,
const
char
*
const
*
paths
,
size_t
len
,
char
**
find_path
,
int
*
save_errno
)
...
...
src/log.c
浏览文件 @
7552595c
...
...
@@ -52,7 +52,7 @@ void clibcni_set_log_prefix(const char *prefix)
}
free
(
g_clibcni_log_prefix
);
g_clibcni_log_prefix
=
util_strdup_s
(
prefix
);
g_clibcni_log_prefix
=
clibcni_
util_strdup_s
(
prefix
);
}
/* engine free log prefix */
...
...
@@ -100,7 +100,7 @@ static int open_fifo(const char *fifo_path)
return
nret
;
}
fifo_fd
=
util_open
(
fifo_path
,
O_RDWR
|
O_NONBLOCK
,
0
);
fifo_fd
=
clibcni_
util_open
(
fifo_path
,
O_RDWR
|
O_NONBLOCK
,
0
);
if
(
fifo_fd
==
-
1
)
{
COMMAND_ERROR
(
"Open fifo %s failed: %s"
,
fifo_path
,
strerror
(
errno
));
return
-
1
;
...
...
@@ -185,11 +185,11 @@ int clibcni_log_enable(const struct clibcni_log_config *log)
}
free
(
g_clibcni_log_module
);
g_clibcni_log_module
=
util_strdup_s
(
log
->
name
);
g_clibcni_log_module
=
clibcni_
util_strdup_s
(
log
->
name
);
full_path
=
util_strdup_s
(
log
->
file
);
full_path
=
clibcni_
util_strdup_s
(
log
->
file
);
nret
=
util_build_dir
(
full_path
);
nret
=
clibcni_
util_build_dir
(
full_path
);
if
(
nret
!=
0
)
{
COMMAND_ERROR
(
"failed to create dir for log file"
);
goto
out
;
...
...
@@ -262,7 +262,7 @@ static char *parse_timespec_to_human()
return
NULL
;
}
return
util_strdup_s
(
date_time
);
return
clibcni_
util_strdup_s
(
date_time
);
}
/* use to add log to driver */
...
...
src/types/current.c
浏览文件 @
7552595c
...
...
@@ -36,7 +36,7 @@ static result_curr *new_curr_result_helper(const char *json_data, char **err)
result
=
result_curr_parse_data
(
json_data
,
NULL
,
&
errmsg
);
if
(
result
==
NULL
)
{
if
(
asprintf
(
err
,
"parse json failed: %s"
,
errmsg
)
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"Parse failed: %s"
,
errmsg
);
goto
free_out
;
...
...
@@ -61,7 +61,7 @@ static void do_append_result_errmsg(const struct result *ret, const char *save_e
*
err
=
NULL
;
nret
=
asprintf
(
err
,
"parse err: %s, convert err: %s"
,
save_err
?
save_err
:
""
,
tmp_err
?
tmp_err
:
""
);
if
(
nret
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
}
free
(
tmp_err
);
...
...
@@ -102,15 +102,15 @@ static struct interface *convert_curr_interface(const network_interface *curr_in
return
NULL
;
}
result
=
util_common_calloc_s
(
sizeof
(
struct
interface
));
result
=
clibcni_
util_common_calloc_s
(
sizeof
(
struct
interface
));
if
(
result
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
NULL
;
}
result
->
name
=
util_strdup_s
(
curr_interface
->
name
);
result
->
mac
=
util_strdup_s
(
curr_interface
->
mac
);
result
->
sandbox
=
util_strdup_s
(
curr_interface
->
sandbox
);
result
->
name
=
clibcni_
util_strdup_s
(
curr_interface
->
name
);
result
->
mac
=
clibcni_
util_strdup_s
(
curr_interface
->
mac
);
result
->
sandbox
=
clibcni_
util_strdup_s
(
curr_interface
->
sandbox
);
return
result
;
}
...
...
@@ -150,10 +150,10 @@ static struct ipconfig *convert_curr_ipconfig(const network_ipconfig *curr_ipcon
return
NULL
;
}
result
=
util_common_calloc_s
(
sizeof
(
struct
ipconfig
));
result
=
clibcni_
util_common_calloc_s
(
sizeof
(
struct
ipconfig
));
if
(
result
==
NULL
)
{
ERROR
(
"Out of memory"
);
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
return
NULL
;
}
/* parse address to ipnet */
...
...
@@ -164,13 +164,13 @@ static struct ipconfig *convert_curr_ipconfig(const network_ipconfig *curr_ipcon
result
->
address
=
ipnet_val
;
result
->
gateway
=
gateway
;
result
->
gateway_len
=
gateway_len
;
result
->
version
=
util_strdup_s
(
curr_ipconfig
->
version
);
result
->
version
=
clibcni_
util_strdup_s
(
curr_ipconfig
->
version
);
if
(
curr_ipconfig
->
interface
!=
NULL
)
{
result
->
interface
=
util_common_calloc_s
(
sizeof
(
int32_t
));
result
->
interface
=
clibcni_
util_common_calloc_s
(
sizeof
(
int32_t
));
if
(
result
->
interface
==
NULL
)
{
ERROR
(
"Out of memory"
);
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
goto
err_out
;
}
*
(
result
->
interface
)
=
*
(
curr_ipconfig
->
interface
);
...
...
@@ -200,12 +200,12 @@ static struct route *convert_curr_route(const network_route *curr_route, char **
return
NULL
;
}
result
=
util_common_calloc_s
(
sizeof
(
struct
route
));
result
=
clibcni_
util_common_calloc_s
(
sizeof
(
struct
route
));
if
(
result
==
NULL
)
{
ERROR
(
"Out of memory"
);
free
(
gw
);
free_ipnet_type
(
dst
);
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
return
NULL
;
}
...
...
@@ -221,15 +221,15 @@ static struct dns *convert_curr_dns(network_dns *curr_dns, char **err)
struct
dns
*
result
=
NULL
;
if
(
curr_dns
==
NULL
)
{
*
err
=
util_strdup_s
(
"Empty dns argument"
);
*
err
=
clibcni_
util_strdup_s
(
"Empty dns argument"
);
ERROR
(
"Empty dns argument"
);
return
NULL
;
}
result
=
util_common_calloc_s
(
sizeof
(
struct
dns
));
result
=
clibcni_
util_common_calloc_s
(
sizeof
(
struct
dns
));
if
(
result
==
NULL
)
{
ERROR
(
"Out of memory"
);
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
return
NULL
;
}
...
...
@@ -250,9 +250,9 @@ static int copy_result_interface(const result_curr *curr_result, struct result *
{
value
->
interfaces_len
=
curr_result
->
interfaces_len
;
if
(
value
->
interfaces_len
>
0
)
{
value
->
interfaces
=
util_smart_calloc_s
(
value
->
interfaces_len
,
sizeof
(
struct
interface
*
));
value
->
interfaces
=
clibcni_
util_smart_calloc_s
(
value
->
interfaces_len
,
sizeof
(
struct
interface
*
));
if
(
value
->
interfaces
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
value
->
interfaces_len
=
0
;
ERROR
(
"Out of memory"
);
return
-
1
;
...
...
@@ -261,7 +261,7 @@ static int copy_result_interface(const result_curr *curr_result, struct result *
for
(
i
=
0
;
i
<
curr_result
->
interfaces_len
;
i
++
)
{
value
->
interfaces
[
i
]
=
convert_curr_interface
(
curr_result
->
interfaces
[
i
]);
if
(
value
->
interfaces
[
i
]
==
NULL
)
{
*
err
=
util_strdup_s
(
"Convert interfaces failed"
);
*
err
=
clibcni_
util_strdup_s
(
"Convert interfaces failed"
);
value
->
interfaces_len
=
i
;
ERROR
(
"Convert interfaces failed"
);
return
-
1
;
...
...
@@ -280,9 +280,9 @@ static int copy_result_ips(const result_curr *curr_result, struct result *value,
return
0
;
}
value
->
ips
=
util_smart_calloc_s
(
value
->
ips_len
,
sizeof
(
struct
ipconfig
*
));
value
->
ips
=
clibcni_
util_smart_calloc_s
(
value
->
ips_len
,
sizeof
(
struct
ipconfig
*
));
if
(
value
->
ips
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
value
->
ips_len
=
0
;
return
-
1
;
...
...
@@ -308,9 +308,9 @@ static int copy_result_routes(const result_curr *curr_result, struct result *val
return
0
;
}
value
->
routes
=
util_smart_calloc_s
(
value
->
routes_len
,
sizeof
(
struct
route
*
));
value
->
routes
=
clibcni_
util_smart_calloc_s
(
value
->
routes_len
,
sizeof
(
struct
route
*
));
if
(
value
->
routes
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
value
->
routes_len
=
0
;
return
-
1
;
...
...
@@ -335,15 +335,15 @@ static struct result *get_result(const result_curr *curr_result, char **err)
if
(
invalid_arg
)
{
return
NULL
;
}
value
=
util_common_calloc_s
(
sizeof
(
struct
result
));
value
=
clibcni_
util_common_calloc_s
(
sizeof
(
struct
result
));
if
(
value
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
NULL
;
}
/* copy cni version */
value
->
cniversion
=
util_strdup_s
(
curr_result
->
cni_version
);
value
->
cniversion
=
clibcni_
util_strdup_s
(
curr_result
->
cni_version
);
/* copy interfaces */
if
(
copy_result_interface
(
curr_result
,
value
,
err
)
!=
0
)
{
...
...
@@ -381,15 +381,15 @@ static network_interface *interface_to_json_interface(const struct interface *sr
return
NULL
;
}
result
=
util_common_calloc_s
(
sizeof
(
network_interface
));
result
=
clibcni_
util_common_calloc_s
(
sizeof
(
network_interface
));
if
(
result
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
NULL
;
}
result
->
name
=
util_strdup_s
(
src
->
name
);
result
->
mac
=
util_strdup_s
(
src
->
mac
);
result
->
sandbox
=
util_strdup_s
(
src
->
sandbox
);
result
->
name
=
clibcni_
util_strdup_s
(
src
->
name
);
result
->
mac
=
clibcni_
util_strdup_s
(
src
->
mac
);
result
->
sandbox
=
clibcni_
util_strdup_s
(
src
->
sandbox
);
return
result
;
}
...
...
@@ -408,7 +408,7 @@ static int parse_ip_and_gateway(const struct ipconfig *src, network_ipconfig *re
result
->
gateway
=
ip_to_string
(
src
->
gateway
,
src
->
gateway_len
);
if
(
result
->
gateway
==
NULL
)
{
if
(
asprintf
(
err
,
"ip: %s to string failed"
,
src
->
gateway
)
<
0
)
{
*
err
=
util_strdup_s
(
"ip to string failed"
);
*
err
=
clibcni_
util_strdup_s
(
"ip to string failed"
);
}
ERROR
(
"IP: %s to string failed"
,
src
->
gateway
);
return
-
1
;
...
...
@@ -427,9 +427,9 @@ static network_ipconfig *ipconfig_to_json_ipconfig(const struct ipconfig *src, c
return
result
;
}
result
=
util_common_calloc_s
(
sizeof
(
network_ipconfig
));
result
=
clibcni_
util_common_calloc_s
(
sizeof
(
network_ipconfig
));
if
(
result
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
goto
out
;
}
...
...
@@ -440,13 +440,13 @@ static network_ipconfig *ipconfig_to_json_ipconfig(const struct ipconfig *src, c
}
if
(
src
->
version
!=
NULL
)
{
result
->
version
=
util_strdup_s
(
src
->
version
);
result
->
version
=
clibcni_
util_strdup_s
(
src
->
version
);
}
if
(
src
->
interface
!=
NULL
)
{
result
->
interface
=
util_common_calloc_s
(
sizeof
(
int32_t
));
result
->
interface
=
clibcni_
util_common_calloc_s
(
sizeof
(
int32_t
));
if
(
result
->
interface
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
goto
out
;
}
...
...
@@ -472,9 +472,9 @@ static network_route *route_to_json_route(const struct route *src, char **err)
return
NULL
;
}
result
=
(
network_route
*
)
util_common_calloc_s
(
sizeof
(
network_route
));
result
=
(
network_route
*
)
clibcni_
util_common_calloc_s
(
sizeof
(
network_route
));
if
(
result
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
goto
out
;
}
...
...
@@ -489,7 +489,7 @@ static network_route *route_to_json_route(const struct route *src, char **err)
if
(
src
->
gw
!=
NULL
&&
src
->
gw_len
>
0
)
{
result
->
gw
=
ip_to_string
(
src
->
gw
,
src
->
gw_len
);
if
(
result
->
gw
==
NULL
)
{
*
err
=
util_strdup_s
(
"ip to string failed"
);
*
err
=
clibcni_
util_strdup_s
(
"ip to string failed"
);
ERROR
(
"ip to string failed"
);
goto
out
;
}
...
...
@@ -509,9 +509,9 @@ static int dns_to_json_copy_servers(const struct dns *src, network_dns *result,
bool
need_copy
=
(
src
->
name_servers
!=
NULL
&&
src
->
name_servers_len
>
0
);
if
(
need_copy
)
{
result
->
nameservers
=
(
char
**
)
util_smart_calloc_s
(
src
->
name_servers_len
,
sizeof
(
char
*
));
result
->
nameservers
=
(
char
**
)
clibcni_
util_smart_calloc_s
(
src
->
name_servers_len
,
sizeof
(
char
*
));
if
(
result
->
nameservers
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
-
1
;
}
...
...
@@ -526,9 +526,9 @@ static int dns_to_json_copy_options(const struct dns *src, network_dns *result,
bool
need_copy
=
(
src
->
options
!=
NULL
&&
src
->
options_len
>
0
);
if
(
need_copy
)
{
result
->
options
=
(
char
**
)
util_smart_calloc_s
(
src
->
options_len
,
sizeof
(
char
*
));
result
->
options
=
(
char
**
)
clibcni_
util_smart_calloc_s
(
src
->
options_len
,
sizeof
(
char
*
));
if
(
result
->
options
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
-
1
;
}
...
...
@@ -543,9 +543,9 @@ static int dns_to_json_copy_searchs(const struct dns *src, network_dns *result,
bool
need_copy
=
(
src
->
search
!=
NULL
&&
src
->
search_len
>
0
);
if
(
need_copy
)
{
result
->
search
=
(
char
**
)
util_smart_calloc_s
(
src
->
search_len
,
sizeof
(
char
*
));
result
->
search
=
(
char
**
)
clibcni_
util_smart_calloc_s
(
src
->
search_len
,
sizeof
(
char
*
));
if
(
result
->
search
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
-
1
;
}
...
...
@@ -580,15 +580,15 @@ static network_dns *dns_to_json_dns(const struct dns *src, char **err)
return
NULL
;
}
result
=
(
network_dns
*
)
util_common_calloc_s
(
sizeof
(
network_dns
));
result
=
(
network_dns
*
)
clibcni_
util_common_calloc_s
(
sizeof
(
network_dns
));
if
(
result
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
goto
out
;
}
if
(
src
->
domain
!=
NULL
)
{
result
->
domain
=
util_strdup_s
(
src
->
domain
);
result
->
domain
=
clibcni_
util_strdup_s
(
src
->
domain
);
}
ret
=
do_copy_dns_configs_to_json
(
src
,
result
,
err
);
...
...
@@ -611,9 +611,9 @@ static bool copy_interfaces_from_result_to_json(const struct result *src, result
res
->
interfaces_len
=
0
;
res
->
interfaces
=
(
network_interface
**
)
util_smart_calloc_s
(
src
->
interfaces_len
,
sizeof
(
network_interface
*
));
res
->
interfaces
=
(
network_interface
**
)
clibcni_
util_smart_calloc_s
(
src
->
interfaces_len
,
sizeof
(
network_interface
*
));
if
(
res
->
interfaces
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
false
;
}
...
...
@@ -623,7 +623,7 @@ static bool copy_interfaces_from_result_to_json(const struct result *src, result
}
res
->
interfaces
[
i
]
=
interface_to_json_interface
(
src
->
interfaces
[
i
]);
if
(
res
->
interfaces
[
i
]
==
NULL
)
{
*
err
=
util_strdup_s
(
"interface to json struct failed"
);
*
err
=
clibcni_
util_strdup_s
(
"interface to json struct failed"
);
ERROR
(
"interface to json struct failed"
);
return
false
;
}
...
...
@@ -638,9 +638,9 @@ static bool copy_ips_from_result_to_json(const struct result *src, result_curr *
res
->
ips_len
=
0
;
if
(
need_copy
)
{
res
->
ips
=
(
network_ipconfig
**
)
util_smart_calloc_s
(
src
->
ips_len
,
sizeof
(
network_ipconfig
*
));
res
->
ips
=
(
network_ipconfig
**
)
clibcni_
util_smart_calloc_s
(
src
->
ips_len
,
sizeof
(
network_ipconfig
*
));
if
(
res
->
ips
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
false
;
}
...
...
@@ -663,9 +663,9 @@ static bool copy_routes_from_result_to_json(const struct result *src, result_cur
res
->
routes_len
=
0
;
if
(
need_copy
)
{
res
->
routes
=
(
network_route
**
)
util_smart_calloc_s
(
src
->
routes_len
,
sizeof
(
network_route
*
));
res
->
routes
=
(
network_route
**
)
clibcni_
util_smart_calloc_s
(
src
->
routes_len
,
sizeof
(
network_route
*
));
if
(
res
->
routes
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
false
;
}
...
...
@@ -721,16 +721,16 @@ result_curr *result_curr_to_json_result(const struct result *src, char **err)
return
res
;
}
res
=
(
result_curr
*
)
util_common_calloc_s
(
sizeof
(
result_curr
));
res
=
(
result_curr
*
)
clibcni_
util_common_calloc_s
(
sizeof
(
result_curr
));
if
(
res
==
NULL
)
{
ERROR
(
"Out of memory"
);
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
goto
out
;
}
/* copy cni version */
if
(
src
->
cniversion
!=
NULL
)
{
res
->
cni_version
=
util_strdup_s
(
src
->
cniversion
);
res
->
cni_version
=
clibcni_
util_strdup_s
(
src
->
cniversion
);
}
ret
=
do_result_copy_configs_to_json
(
src
,
res
,
err
);
...
...
src/types/types.c
浏览文件 @
7552595c
...
...
@@ -201,7 +201,7 @@ static size_t to_ipv4(const uint8_t *src, size_t src_len, uint8_t **ipv4)
return
0
;
}
if
(
src_len
==
IPV4LEN
)
{
ip
=
util_smart_calloc_s
(
IPV4LEN
,
sizeof
(
uint8_t
));
ip
=
clibcni_
util_smart_calloc_s
(
IPV4LEN
,
sizeof
(
uint8_t
));
if
(
ip
==
NULL
)
{
return
0
;
}
...
...
@@ -211,7 +211,7 @@ static size_t to_ipv4(const uint8_t *src, size_t src_len, uint8_t **ipv4)
}
if
(
src_len
==
IPV6LEN
&&
is_ipv4
(
src
,
src_len
)
&&
src
[
10
]
==
0xff
&&
src
[
11
]
==
0xff
)
{
ip
=
util_smart_calloc_s
(
IPV4LEN
,
sizeof
(
uint8_t
));
ip
=
clibcni_
util_smart_calloc_s
(
IPV4LEN
,
sizeof
(
uint8_t
));
if
(
ip
==
NULL
)
{
return
0
;
}
...
...
@@ -242,7 +242,7 @@ static int do_parse_ip_to_string(const uint8_t *ip, size_t len, char **result)
int
nret
=
0
;
size_t
res_len
=
0
;
tmp
=
util_uint8_join
(
""
,
"%x"
,
ip
,
len
);
tmp
=
clibcni_
util_uint8_join
(
""
,
"%x"
,
ip
,
len
);
if
(
tmp
==
NULL
)
{
return
-
1
;
}
...
...
@@ -253,7 +253,7 @@ static int do_parse_ip_to_string(const uint8_t *ip, size_t len, char **result)
}
res_len
=
1
+
strlen
(
tmp
)
+
1
;
*
result
=
util_common_calloc_s
(
res_len
);
*
result
=
clibcni_
util_common_calloc_s
(
res_len
);
if
(
*
result
==
NULL
)
{
ret
=
-
1
;
goto
free_out
;
...
...
@@ -280,7 +280,7 @@ static int get_ip_string(const uint8_t *ip, size_t len, char **result)
work_ip_len
=
to_ipv4
(
ip
,
len
,
&
work_ip
);
if
(
work_ip_len
==
IPV4LEN
)
{
*
result
=
util_uint8_join
(
"."
,
"%u"
,
work_ip
,
work_ip_len
);
*
result
=
clibcni_
util_uint8_join
(
"."
,
"%u"
,
work_ip
,
work_ip_len
);
ret
=
1
;
// get right result
goto
free_out
;
}
...
...
@@ -298,7 +298,7 @@ static void generate_ip_string(const uint8_t *ip, int e0, int e1, char **result)
int
i
=
0
;
int
j
=
0
;
*
result
=
util_common_calloc_s
(
IPV6_MAX_ADDR_LEN
);
*
result
=
clibcni_
util_common_calloc_s
(
IPV6_MAX_ADDR_LEN
);
if
(
*
result
==
NULL
)
{
return
;
}
...
...
@@ -330,7 +330,7 @@ char *ip_to_string(const uint8_t *ip, size_t len)
int
e1
=
0
;
if
(
len
==
0
)
{
return
util_strdup_s
(
"<nil>"
);
return
clibcni_
util_strdup_s
(
"<nil>"
);
}
if
(
get_ip_string
(
ip
,
len
,
&
result
)
!=
0
)
{
...
...
@@ -370,7 +370,7 @@ static char *mask_hex_string(const uint8_t *mask, size_t len)
size_t
j
=
0
;
if
(
len
==
0
)
{
return
util_strdup_s
(
"<nil>"
);
return
clibcni_
util_strdup_s
(
"<nil>"
);
}
if
(
len
>
((
SIZE_MAX
-
1
)
/
2
))
{
...
...
@@ -378,7 +378,7 @@ static char *mask_hex_string(const uint8_t *mask, size_t len)
}
res_len
=
(
len
*
2
)
+
1
;
result
=
util_common_calloc_s
(
res_len
);
result
=
clibcni_
util_common_calloc_s
(
res_len
);
if
(
result
==
NULL
)
{
return
NULL
;
}
...
...
@@ -398,10 +398,10 @@ static size_t try_to_ipv4(const struct ipnet *value, uint8_t **pip, char **err)
iplen
=
to_ipv4
(
value
->
ip
,
value
->
ip_len
,
pip
);
if
(
iplen
==
0
)
{
if
(
value
->
ip_len
==
IPV6LEN
)
{
*
pip
=
util_smart_calloc_s
(
IPV6LEN
,
sizeof
(
uint8_t
));
*
pip
=
clibcni_
util_smart_calloc_s
(
IPV6LEN
,
sizeof
(
uint8_t
));
if
(
*
pip
==
NULL
)
{
ERROR
(
"Out of memory"
);
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
return
0
;
}
(
void
)
memcpy
(
*
pip
,
value
->
ip
,
IPV6LEN
);
...
...
@@ -409,7 +409,7 @@ static size_t try_to_ipv4(const struct ipnet *value, uint8_t **pip, char **err)
}
else
{
if
(
asprintf
(
err
,
"Invalid ip, len=%lu"
,
iplen
)
<
0
)
{
ERROR
(
"Out of memory"
);
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
return
0
;
}
...
...
@@ -422,14 +422,14 @@ static int get_ipv4_mask(const struct ipnet *value, size_t iplen, uint8_t **mask
if
(
iplen
!=
IPV4LEN
)
{
int
nret
=
asprintf
(
err
,
"len of IP: %lu diffrent to len of mask: %lu"
,
iplen
,
value
->
ip_mask_len
);
if
(
nret
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
}
return
0
;
}
*
mask
=
util_smart_calloc_s
(
IPV4LEN
,
sizeof
(
uint8_t
));
*
mask
=
clibcni_
util_smart_calloc_s
(
IPV4LEN
,
sizeof
(
uint8_t
));
if
(
*
mask
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
-
1
;
}
...
...
@@ -440,9 +440,9 @@ static int get_ipv4_mask(const struct ipnet *value, size_t iplen, uint8_t **mask
static
int
get_ipv6_mask
(
const
struct
ipnet
*
value
,
size_t
iplen
,
uint8_t
**
mask
,
char
**
err
)
{
if
(
iplen
==
IPV4LEN
)
{
*
mask
=
util_smart_calloc_s
(
IPV4LEN
,
sizeof
(
uint8_t
));
*
mask
=
clibcni_
util_smart_calloc_s
(
IPV4LEN
,
sizeof
(
uint8_t
));
if
(
*
mask
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
0
;
}
...
...
@@ -481,7 +481,7 @@ static size_t try_get_mask(const struct ipnet *value, size_t iplen, uint8_t **ma
default:
nret
=
asprintf
(
err
,
"Invalid mask len: %lu"
,
value
->
ip_mask_len
);
if
(
nret
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
}
goto
free_out
;
...
...
@@ -505,27 +505,27 @@ static char *do_generate_ip_with_mask(const uint8_t *mask, size_t masklen, const
}
tmp_mask
=
mask_hex_string
(
mask
,
masklen
);
if
(
tmp_mask
==
NULL
)
{
*
err
=
util_strdup_s
(
"Mask toString failed"
);
*
err
=
clibcni_
util_strdup_s
(
"Mask toString failed"
);
ERROR
(
"Mask toString failed"
);
goto
free_out
;
}
if
(
strlen
(
ip
)
>
((
SIZE_MAX
-
2
)
-
strlen
(
tmp_mask
)))
{
*
err
=
util_strdup_s
(
"Too long ips"
);
*
err
=
clibcni_
util_strdup_s
(
"Too long ips"
);
ERROR
(
"Too long ips"
);
goto
free_out
;
}
res_len
=
strlen
(
ip
)
+
1
+
strlen
(
tmp_mask
)
+
1
;
result
=
util_common_calloc_s
(
res_len
);
result
=
clibcni_
util_common_calloc_s
(
res_len
);
if
(
result
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
goto
free_out
;
}
nret
=
snprintf
(
result
,
res_len
,
"%s/%s"
,
ip
,
tmp_mask
);
if
(
nret
<
0
||
(
size_t
)
nret
>=
res_len
)
{
*
err
=
util_strdup_s
(
"Sprintf first type failed"
);
*
err
=
clibcni_
util_strdup_s
(
"Sprintf first type failed"
);
ERROR
(
"Sprintf failed"
);
free
(
result
);
result
=
NULL
;
...
...
@@ -560,7 +560,7 @@ char *ipnet_to_string(const struct ipnet *value, char **err)
slen
=
simple_mask_len
(
mask
,
masklen
);
tmp_ip
=
ip_to_string
(
ip
,
iplen
);
if
(
tmp_ip
==
NULL
)
{
*
err
=
util_strdup_s
(
"IP toString failed"
);
*
err
=
clibcni_
util_strdup_s
(
"IP toString failed"
);
ERROR
(
"IP toString failed"
);
goto
free_out
;
}
...
...
@@ -570,21 +570,21 @@ char *ipnet_to_string(const struct ipnet *value, char **err)
}
if
(
strlen
(
tmp_ip
)
>
(
SIZE_MAX
-
5
))
{
*
err
=
util_strdup_s
(
"Too long ips"
);
*
err
=
clibcni_
util_strdup_s
(
"Too long ips"
);
goto
free_out
;
}
res_len
=
strlen
(
tmp_ip
)
+
1
+
3
+
1
;
result
=
util_common_calloc_s
(
res_len
);
result
=
clibcni_
util_common_calloc_s
(
res_len
);
if
(
result
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
goto
free_out
;
}
nret
=
snprintf
(
result
,
res_len
,
"%s/%d"
,
tmp_ip
,
slen
);
if
(
nret
<
0
||
(
size_t
)
nret
>=
res_len
)
{
ERROR
(
"Sprintf failed"
);
*
err
=
util_strdup_s
(
"Sprintf second type failed"
);
*
err
=
clibcni_
util_strdup_s
(
"Sprintf second type failed"
);
free
(
result
);
result
=
NULL
;
}
...
...
@@ -603,7 +603,7 @@ static int get_ip_from_in6_addr(const struct in6_addr *ipv6, uint8_t **ip, size_
if
(
ipv6
==
NULL
)
{
return
0
;
}
result
=
util_smart_calloc_s
(
IPV6LEN
,
sizeof
(
uint8_t
));
result
=
clibcni_
util_smart_calloc_s
(
IPV6LEN
,
sizeof
(
uint8_t
));
if
(
result
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
-
1
;
...
...
@@ -624,7 +624,7 @@ static int get_ip_from_in_addr(const struct in_addr *ipv4, uint8_t **ip, size_t
if
(
ipv4
==
NULL
)
{
return
0
;
}
result
=
util_smart_calloc_s
(
IPV4LEN
,
sizeof
(
uint8_t
));
result
=
clibcni_
util_smart_calloc_s
(
IPV4LEN
,
sizeof
(
uint8_t
));
if
(
result
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
-
1
;
...
...
@@ -716,9 +716,9 @@ static int do_parse_mask_in_cidr(unsigned int mask_num, struct ipnet *result, ch
j
=
result
->
ip_len
;
result
->
ip_mask
=
util_smart_calloc_s
(
j
,
sizeof
(
uint8_t
));
result
->
ip_mask
=
clibcni_
util_smart_calloc_s
(
j
,
sizeof
(
uint8_t
));
if
(
result
->
ip_mask
==
NULL
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
-
1
;
}
...
...
@@ -750,9 +750,9 @@ int parse_cidr(const char *cidr_str, struct ipnet **ipnet_val, char **err)
return
-
1
;
}
work_cidr
=
util_strdup_s
(
cidr_str
);
work_cidr
=
clibcni_
util_strdup_s
(
cidr_str
);
result
=
util_common_calloc_s
(
sizeof
(
struct
ipnet
));
result
=
clibcni_
util_common_calloc_s
(
sizeof
(
struct
ipnet
));
if
(
result
==
NULL
)
{
ERROR
(
"Out of memory"
);
goto
free_out
;
...
...
@@ -776,12 +776,12 @@ int parse_cidr(const char *cidr_str, struct ipnet **ipnet_val, char **err)
goto
free_out
;
}
nret
=
util_safe_uint
(
mask
,
&
mask_num
);
nret
=
clibcni_
util_safe_uint
(
mask
,
&
mask_num
);
if
(
nret
!=
0
||
(
size_t
)(
mask_num
>>
3
)
>
result
->
ip_len
)
{
nret
=
asprintf
(
err
,
"Invalid CIDR address %s"
,
cidr_str
);
if
(
nret
<
0
)
{
ERROR
(
"Sprintf failed"
);
*
err
=
util_strdup_s
(
"Asprintf cidr failed"
);
*
err
=
clibcni_
util_strdup_s
(
"Asprintf cidr failed"
);
ret
=
1
;
}
goto
free_out
;
...
...
src/utils.c
浏览文件 @
7552595c
...
...
@@ -28,7 +28,7 @@
#define ISSLASH(C) ((C) == '/')
#define IS_ABSOLUTE_FILE_NAME(F) (ISSLASH((F)[0]))
char
*
util_strdup_s
(
const
char
*
src
)
char
*
clibcni_
util_strdup_s
(
const
char
*
src
)
{
char
*
dst
=
NULL
;
...
...
@@ -166,25 +166,25 @@ error:
return
NULL
;
}
bool
is_null_or_empty
(
const
char
*
str
)
bool
clibcni_
is_null_or_empty
(
const
char
*
str
)
{
return
(
str
==
NULL
||
strlen
(
str
)
==
0
);
}
void
*
util_smart_calloc_s
(
size_t
count
,
size_t
unit_size
)
void
*
clibcni_
util_smart_calloc_s
(
size_t
count
,
size_t
unit_size
)
{
if
(
unit_size
==
0
)
{
return
NULL
;
}
if
(
count
>
(
MAX_MEMORY_SIZE
/
unit_size
))
{
if
(
count
>
(
CLIBCNI_
MAX_MEMORY_SIZE
/
unit_size
))
{
return
NULL
;
}
return
calloc
(
count
,
unit_size
);
}
void
*
util_common_calloc_s
(
size_t
size
)
void
*
clibcni_
util_common_calloc_s
(
size_t
size
)
{
if
(
size
==
0
)
{
return
NULL
;
...
...
@@ -193,7 +193,7 @@ void *util_common_calloc_s(size_t size)
return
calloc
(
1
,
size
);
}
size_t
util_array_len
(
const
char
*
const
*
array
)
size_t
clibcni_
util_array_len
(
const
char
*
const
*
array
)
{
const
char
*
const
*
pos
;
size_t
len
=
0
;
...
...
@@ -206,7 +206,7 @@ size_t util_array_len(const char * const *array)
}
/* util free array */
void
util_free_array
(
char
**
array
)
void
clibcni_
util_free_array
(
char
**
array
)
{
char
**
p
=
NULL
;
...
...
@@ -221,7 +221,7 @@ void util_free_array(char **array)
free
((
void
*
)
array
);
}
ssize_t
util_write_nointr
(
int
fd
,
const
void
*
buf
,
size_t
count
)
ssize_t
clibcni_
util_write_nointr
(
int
fd
,
const
void
*
buf
,
size_t
count
)
{
ssize_t
n
=
0
;
bool
empty_buf
=
(
buf
==
NULL
||
count
==
0
);
...
...
@@ -245,7 +245,7 @@ ssize_t util_write_nointr(int fd, const void *buf, size_t count)
return
n
;
}
ssize_t
util_read_nointr
(
int
fd
,
void
*
buf
,
size_t
count
)
ssize_t
clibcni_
util_read_nointr
(
int
fd
,
void
*
buf
,
size_t
count
)
{
ssize_t
rn
=
0
;
bool
empty_buf
=
(
buf
==
NULL
||
count
==
0
);
...
...
@@ -276,7 +276,7 @@ static char *do_string_join(const char *sep, const char * const *parts, size_t p
return
NULL
;
}
res_string
=
util_common_calloc_s
(
result_len
+
1
);
res_string
=
clibcni_
util_common_calloc_s
(
result_len
+
1
);
if
(
res_string
==
NULL
)
{
return
NULL
;
}
...
...
@@ -290,18 +290,18 @@ static char *do_string_join(const char *sep, const char * const *parts, size_t p
return
res_string
;
}
static
inline
bool
check_cni_util_string_join_args
(
const
char
*
sep
,
const
char
*
const
*
parts
,
size_t
len
)
static
inline
bool
check_c
libc
ni_util_string_join_args
(
const
char
*
sep
,
const
char
*
const
*
parts
,
size_t
len
)
{
return
(
sep
==
NULL
||
strlen
(
sep
)
==
0
||
len
==
0
||
parts
==
NULL
);
}
char
*
cni_util_string_join
(
const
char
*
sep
,
const
char
*
const
*
parts
,
size_t
len
)
char
*
c
libc
ni_util_string_join
(
const
char
*
sep
,
const
char
*
const
*
parts
,
size_t
len
)
{
size_t
sep_len
=
0
;
size_t
result_len
=
0
;
size_t
iter
=
0
;
if
(
check_cni_util_string_join_args
(
sep
,
parts
,
len
))
{
if
(
check_c
libc
ni_util_string_join_args
(
sep
,
parts
,
len
))
{
ERROR
(
"Invalid arguments"
);
return
NULL
;
}
...
...
@@ -334,7 +334,7 @@ static char *do_uint8_join(const char *sep, const char *type, const uint8_t *par
return
NULL
;
}
res_string
=
util_common_calloc_s
(
result_len
+
1
);
res_string
=
clibcni_
util_common_calloc_s
(
result_len
+
1
);
if
(
res_string
==
NULL
)
{
ERROR
(
"Out of memory"
);
return
NULL
;
...
...
@@ -361,17 +361,17 @@ static char *do_uint8_join(const char *sep, const char *type, const uint8_t *par
return
res_string
;
}
static
inline
bool
check_util_uint8_join_args
(
const
char
*
sep
,
const
uint8_t
*
parts
,
size_t
len
)
static
inline
bool
check_
clibcni_
util_uint8_join_args
(
const
char
*
sep
,
const
uint8_t
*
parts
,
size_t
len
)
{
return
(
sep
==
NULL
||
strlen
(
sep
)
==
0
||
len
==
0
||
parts
==
NULL
);
}
char
*
util_uint8_join
(
const
char
*
sep
,
const
char
*
type
,
const
uint8_t
*
parts
,
size_t
len
)
char
*
clibcni_
util_uint8_join
(
const
char
*
sep
,
const
char
*
type
,
const
uint8_t
*
parts
,
size_t
len
)
{
size_t
sep_len
=
0
;
size_t
result_len
=
0
;
if
(
check_util_uint8_join_args
(
sep
,
parts
,
len
))
{
if
(
check_
clibcni_
util_uint8_join_args
(
sep
,
parts
,
len
))
{
ERROR
(
"Invalid arguments"
);
return
NULL
;
}
...
...
@@ -392,14 +392,14 @@ char *util_uint8_join(const char *sep, const char *type, const uint8_t *parts, s
return
do_uint8_join
(
sep
,
type
,
parts
,
len
,
result_len
);
}
static
inline
bool
check_do_util_safe_uint_args
(
const
char
*
numstr
,
const
char
*
err_str
)
static
inline
bool
check_do_
clibcni_
util_safe_uint_args
(
const
char
*
numstr
,
const
char
*
err_str
)
{
return
(
err_str
==
NULL
||
err_str
==
numstr
||
*
err_str
!=
'\0'
);
}
static
int
do_util_safe_uint
(
const
char
*
numstr
,
const
char
*
err_str
,
unsigned
long
long
ull
,
unsigned
int
*
converted
)
static
int
do_
clibcni_
util_safe_uint
(
const
char
*
numstr
,
const
char
*
err_str
,
unsigned
long
long
ull
,
unsigned
int
*
converted
)
{
if
(
check_do_util_safe_uint_args
(
numstr
,
err_str
))
{
if
(
check_do_
clibcni_
util_safe_uint_args
(
numstr
,
err_str
))
{
return
-
EINVAL
;
}
...
...
@@ -411,7 +411,7 @@ static int do_util_safe_uint(const char *numstr, const char *err_str, unsigned l
return
0
;
}
int
util_safe_uint
(
const
char
*
numstr
,
unsigned
int
*
converted
)
int
clibcni_
util_safe_uint
(
const
char
*
numstr
,
unsigned
int
*
converted
)
{
char
*
err_str
=
NULL
;
unsigned
long
long
ull
=
0
;
...
...
@@ -425,10 +425,10 @@ int util_safe_uint(const char *numstr, unsigned int *converted)
return
-
errno
;
}
return
do_util_safe_uint
(
numstr
,
err_str
,
ull
,
converted
);
return
do_
clibcni_
util_safe_uint
(
numstr
,
err_str
,
ull
,
converted
);
}
bool
util_dir_exists
(
const
char
*
path
)
bool
clibcni_
util_dir_exists
(
const
char
*
path
)
{
struct
stat
s
=
{
0
};
int
nret
=
0
;
...
...
@@ -444,7 +444,7 @@ bool util_dir_exists(const char *path)
return
S_ISDIR
(
s
.
st_mode
);
}
static
int
do_util_grow_array
(
char
***
orig_array
,
size_t
*
orig_capacity
,
size_t
size
,
size_t
increment
)
static
int
do_
clibcni_
util_grow_array
(
char
***
orig_array
,
size_t
*
orig_capacity
,
size_t
size
,
size_t
increment
)
{
size_t
add_capacity
=
0
;
char
**
add_array
=
NULL
;
...
...
@@ -457,7 +457,7 @@ static int do_util_grow_array(char ***orig_array, size_t *orig_capacity, size_t
add_capacity
+=
increment
;
}
if
(
add_capacity
!=
*
orig_capacity
)
{
add_array
=
util_smart_calloc_s
(
add_capacity
,
sizeof
(
void
*
));
add_array
=
clibcni_
util_smart_calloc_s
(
add_capacity
,
sizeof
(
void
*
));
if
(
add_array
==
NULL
)
{
return
-
1
;
}
...
...
@@ -473,7 +473,7 @@ static int do_util_grow_array(char ***orig_array, size_t *orig_capacity, size_t
return
0
;
}
int
util_grow_array
(
char
***
orig_array
,
size_t
*
orig_capacity
,
size_t
size
,
size_t
increment
)
int
clibcni_
util_grow_array
(
char
***
orig_array
,
size_t
*
orig_capacity
,
size_t
size
,
size_t
increment
)
{
if
(
orig_array
==
NULL
||
orig_capacity
==
NULL
)
{
return
-
1
;
...
...
@@ -484,10 +484,10 @@ int util_grow_array(char ***orig_array, size_t *orig_capacity, size_t size, size
*
orig_capacity
=
0
;
}
return
do_util_grow_array
(
orig_array
,
orig_capacity
,
size
,
increment
);
return
do_
clibcni_
util_grow_array
(
orig_array
,
orig_capacity
,
size
,
increment
);
}
static
int
do_util_validate_absolute_path
(
const
char
*
path
,
regmatch_t
*
pregmatch
)
static
int
do_
clibcni_
util_validate_absolute_path
(
const
char
*
path
,
regmatch_t
*
pregmatch
)
{
regex_t
preg
;
int
nret
=
0
;
...
...
@@ -508,7 +508,7 @@ err_out:
return
nret
;
}
int
util_validate_absolute_path
(
const
char
*
path
)
int
clibcni_
util_validate_absolute_path
(
const
char
*
path
)
{
regmatch_t
regmatch
;
...
...
@@ -518,10 +518,10 @@ int util_validate_absolute_path(const char *path)
(
void
)
memset
(
&
regmatch
,
0
,
sizeof
(
regmatch_t
));
return
do_util_validate_absolute_path
(
path
,
&
regmatch
);
return
do_
clibcni_
util_validate_absolute_path
(
path
,
&
regmatch
);
}
static
int
do_util_validate_name
(
const
char
*
name
,
regmatch_t
*
pregmatch
)
static
int
do_
clibcni_
util_validate_name
(
const
char
*
name
,
regmatch_t
*
pregmatch
)
{
int
nret
=
0
;
int
status
=
0
;
...
...
@@ -542,23 +542,23 @@ err_out:
return
nret
;
}
static
inline
bool
check_util_validate_name_args
(
const
char
*
name
)
static
inline
bool
check_
clibcni_
util_validate_name_args
(
const
char
*
name
)
{
#define MAX_LEN_NAME 200
return
(
name
==
NULL
||
strlen
(
name
)
>
MAX_LEN_NAME
);
}
int
util_validate_name
(
const
char
*
name
)
int
clibcni_
util_validate_name
(
const
char
*
name
)
{
regmatch_t
regmatch
;
if
(
check_util_validate_name_args
(
name
))
{
if
(
check_
clibcni_
util_validate_name_args
(
name
))
{
return
-
1
;
}
(
void
)
memset
(
&
regmatch
,
0
,
sizeof
(
regmatch_t
));
return
do_util_validate_name
(
name
,
&
regmatch
);
return
do_
clibcni_
util_validate_name
(
name
,
&
regmatch
);
}
static
void
set_char_to_terminator
(
char
*
p
)
...
...
@@ -570,7 +570,7 @@ static void set_char_to_terminator(char *p)
* @name is absolute path of this file.
* make all directory in this absolute path.
* */
int
util_build_dir
(
const
char
*
name
)
int
clibcni_
util_build_dir
(
const
char
*
name
)
{
char
*
n
=
NULL
;
// because we'll be modifying it
char
*
p
=
NULL
;
...
...
@@ -581,7 +581,7 @@ int util_build_dir(const char *name)
ERROR
(
"name is NULL"
);
return
-
1
;
}
n
=
util_strdup_s
(
name
);
n
=
clibcni_
util_strdup_s
(
name
);
e
=
&
(
n
[
strlen
(
n
)]);
for
(
p
=
n
+
1
;
p
<
e
;
p
++
)
{
...
...
@@ -589,8 +589,8 @@ int util_build_dir(const char *name)
continue
;
}
set_char_to_terminator
(
p
);
nret
=
mkdir
(
n
,
DEFAULT_SECURE_DIRECTORY_MODE
);
if
(
nret
!=
0
&&
(
errno
!=
EEXIST
||
!
util_dir_exists
(
n
)))
{
nret
=
mkdir
(
n
,
CLIBCNI_
DEFAULT_SECURE_DIRECTORY_MODE
);
if
(
nret
!=
0
&&
(
errno
!=
EEXIST
||
!
clibcni_
util_dir_exists
(
n
)))
{
SYSERROR
(
"failed to create directory '%s'."
,
n
);
free
(
n
);
return
-
1
;
...
...
@@ -602,7 +602,7 @@ int util_build_dir(const char *name)
}
/* util open */
int
util_open
(
const
char
*
filename
,
unsigned
int
flags
,
mode_t
mode
)
int
clibcni_
util_open
(
const
char
*
filename
,
unsigned
int
flags
,
mode_t
mode
)
{
char
rpath
[
PATH_MAX
]
=
{
0x00
};
...
...
src/utils.h
浏览文件 @
7552595c
...
...
@@ -12,61 +12,61 @@
* Create: 2019-04-25
* Description: provide util function definition
*********************************************************************************/
#ifndef CLIBCNI_
INVOKE_
UTILS_H
#define CLIBCNI_
INVOKE_
UTILS_H
#ifndef CLIBCNI_UTILS_H
#define CLIBCNI_UTILS_H
#include <unistd.h>
#include <string.h>
#include <inttypes.h>
#include <stdbool.h>
#define BUFFER_SIZE 4096
#define
CLIBCNI_
BUFFER_SIZE 4096
#define MB (1 * 1024 * 1024)
#define NUMSTRLEN64_MAXLEN 21
#define
CLIBCNI_
NUMSTRLEN64_MAXLEN 21
#define DEFAULT_SECURE_DIRECTORY_MODE 0750
#define
CLIBCNI_
DEFAULT_SECURE_DIRECTORY_MODE 0750
#if __WORDSIZE == 64
/* current max user memory for 64-machine is 2^47 B */
#define MAX_MEMORY_SIZE ((size_t)1 << 47)
#define
CLIBCNI_
MAX_MEMORY_SIZE ((size_t)1 << 47)
#else
/* current max user memory for 32-machine is 2^31 B */
#define MAX_MEMORY_SIZE ((size_t)1 << 31)
#define
CLIBCNI_
MAX_MEMORY_SIZE ((size_t)1 << 31)
#endif
bool
is_null_or_empty
(
const
char
*
str
);
bool
clibcni_
is_null_or_empty
(
const
char
*
str
);
size_t
util_array_len
(
const
char
*
const
*
array
);
size_t
clibcni_
util_array_len
(
const
char
*
const
*
array
);
void
util_free_array
(
char
**
array
);
void
clibcni_
util_free_array
(
char
**
array
);
void
*
util_smart_calloc_s
(
size_t
count
,
size_t
unit_size
);
void
*
clibcni_
util_smart_calloc_s
(
size_t
count
,
size_t
unit_size
);
void
*
util_common_calloc_s
(
size_t
size
);
void
*
clibcni_
util_common_calloc_s
(
size_t
size
);
ssize_t
util_write_nointr
(
int
fd
,
const
void
*
buf
,
size_t
count
);
ssize_t
clibcni_
util_write_nointr
(
int
fd
,
const
void
*
buf
,
size_t
count
);
ssize_t
util_read_nointr
(
int
fd
,
void
*
buf
,
size_t
count
);
ssize_t
clibcni_
util_read_nointr
(
int
fd
,
void
*
buf
,
size_t
count
);
char
*
cni_util_string_join
(
const
char
*
sep
,
const
char
*
const
*
parts
,
size_t
len
);
char
*
c
libc
ni_util_string_join
(
const
char
*
sep
,
const
char
*
const
*
parts
,
size_t
len
);
char
*
util_uint8_join
(
const
char
*
sep
,
const
char
*
type
,
const
uint8_t
*
parts
,
size_t
len
);
char
*
clibcni_
util_uint8_join
(
const
char
*
sep
,
const
char
*
type
,
const
uint8_t
*
parts
,
size_t
len
);
int
util_safe_uint
(
const
char
*
numstr
,
unsigned
int
*
converted
);
int
clibcni_
util_safe_uint
(
const
char
*
numstr
,
unsigned
int
*
converted
);
bool
util_dir_exists
(
const
char
*
path
);
bool
clibcni_
util_dir_exists
(
const
char
*
path
);
int
util_grow_array
(
char
***
orig_array
,
size_t
*
orig_capacity
,
size_t
size
,
size_t
increment
);
int
clibcni_
util_grow_array
(
char
***
orig_array
,
size_t
*
orig_capacity
,
size_t
size
,
size_t
increment
);
char
*
util_strdup_s
(
const
char
*
src
);
char
*
clibcni_
util_strdup_s
(
const
char
*
src
);
int
util_validate_absolute_path
(
const
char
*
path
);
int
clibcni_
util_validate_absolute_path
(
const
char
*
path
);
int
util_validate_name
(
const
char
*
name
);
int
clibcni_
util_validate_name
(
const
char
*
name
);
int
util_open
(
const
char
*
filename
,
unsigned
int
flags
,
mode_t
mode
);
int
clibcni_
util_open
(
const
char
*
filename
,
unsigned
int
flags
,
mode_t
mode
);
int
util_build_dir
(
const
char
*
name
);
int
clibcni_
util_build_dir
(
const
char
*
name
);
#endif
src/version/version.c
浏览文件 @
7552595c
...
...
@@ -49,14 +49,14 @@ static void convert_from_inner_plugin_info(inner_plugin_info *inner, struct plug
bool
invalid_arg
=
(
inner
==
NULL
||
result
==
NULL
);
if
(
invalid_arg
)
{
*
errmsg
=
util_strdup_s
(
"Invalid argument"
);
*
errmsg
=
clibcni_
util_strdup_s
(
"Invalid argument"
);
ERROR
(
"Invalid argument"
);
return
;
}
*
result
=
util_common_calloc_s
(
sizeof
(
struct
plugin_info
));
*
result
=
clibcni_
util_common_calloc_s
(
sizeof
(
struct
plugin_info
));
if
(
*
result
==
NULL
)
{
*
errmsg
=
util_strdup_s
(
"Out of memory"
);
*
errmsg
=
clibcni_
util_strdup_s
(
"Out of memory"
);
ERROR
(
"Out of memory"
);
return
;
}
...
...
@@ -76,34 +76,34 @@ struct plugin_info *plugin_supports(const char * const *supported_versions, size
bool
invalid_arg
=
(
supported_versions
==
NULL
||
len
<
1
);
if
(
invalid_arg
)
{
*
errmsg
=
util_strdup_s
(
"Invalid version argument"
);
*
errmsg
=
clibcni_
util_strdup_s
(
"Invalid version argument"
);
return
NULL
;
}
result
=
util_common_calloc_s
(
sizeof
(
struct
plugin_info
));
result
=
clibcni_
util_common_calloc_s
(
sizeof
(
struct
plugin_info
));
if
(
result
==
NULL
)
{
ERROR
(
"Out of memory"
);
*
errmsg
=
util_strdup_s
(
"Out of memory"
);
*
errmsg
=
clibcni_
util_strdup_s
(
"Out of memory"
);
return
NULL
;
}
result
->
cniversion
=
util_strdup_s
(
current
());
result
->
cniversion
=
clibcni_
util_strdup_s
(
current
());
if
(
len
>
(
SIZE_MAX
/
sizeof
(
char
*
)
-
1
))
{
*
errmsg
=
util_strdup_s
(
"Too many plugins"
);
*
errmsg
=
clibcni_
util_strdup_s
(
"Too many plugins"
);
ERROR
(
"Too many plugins"
);
goto
err_out
;
}
size
=
sizeof
(
char
*
)
*
(
len
+
1
);
result
->
supported_versions
=
util_common_calloc_s
(
size
);
result
->
supported_versions
=
clibcni_
util_common_calloc_s
(
size
);
if
(
result
->
supported_versions
==
NULL
)
{
ERROR
(
"Out of memory"
);
*
errmsg
=
util_strdup_s
(
"Out of memory"
);
*
errmsg
=
clibcni_
util_strdup_s
(
"Out of memory"
);
goto
err_out
;
}
for
(
i
=
0
;
i
<
len
;
i
++
)
{
result
->
supported_versions
[
i
]
=
util_strdup_s
(
supported_versions
[
i
]);
result
->
supported_versions
[
i
]
=
clibcni_
util_strdup_s
(
supported_versions
[
i
]);
result
->
supported_versions_len
=
i
+
1
;
}
...
...
@@ -125,7 +125,7 @@ struct plugin_info *plugin_info_decode(const char *jsonstr, char **errmsg)
return
NULL
;
}
if
(
jsonstr
==
NULL
)
{
*
errmsg
=
util_strdup_s
(
"empty argument"
);
*
errmsg
=
clibcni_
util_strdup_s
(
"empty argument"
);
ERROR
(
"Invalid arguments"
);
goto
out
;
}
...
...
@@ -133,13 +133,13 @@ struct plugin_info *plugin_info_decode(const char *jsonstr, char **errmsg)
if
(
pinfo
==
NULL
)
{
nret
=
asprintf
(
errmsg
,
"decoding version info: %s"
,
err
);
if
(
nret
<
0
)
{
*
errmsg
=
util_strdup_s
(
"Out of memory"
);
*
errmsg
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"decoding version info: %s"
,
err
);
goto
out
;
}
if
(
is_null_or_empty
(
pinfo
->
cni_version
))
{
*
errmsg
=
util_strdup_s
(
"decoding version info: missing field cniVersion"
);
if
(
clibcni_
is_null_or_empty
(
pinfo
->
cni_version
))
{
*
errmsg
=
clibcni_
util_strdup_s
(
"decoding version info: missing field cniVersion"
);
goto
out
;
}
if
(
pinfo
->
supported_versions_len
==
0
)
{
...
...
@@ -147,7 +147,7 @@ struct plugin_info *plugin_info_decode(const char *jsonstr, char **errmsg)
result
=
plugin_supports
(
type020
,
sizeof
(
type020
)
/
sizeof
(
char
*
),
errmsg
);
goto
out
;
}
*
errmsg
=
util_strdup_s
(
"decoding version info: missing field supportedVersions"
);
*
errmsg
=
clibcni_
util_strdup_s
(
"decoding version info: missing field supportedVersions"
);
goto
out
;
}
...
...
@@ -172,17 +172,17 @@ char *cniversion_decode(const char *jsonstr, char **errmsg)
if
(
conf
==
NULL
)
{
nret
=
asprintf
(
errmsg
,
"decoding config
\"
%s
\"
, failed: %s"
,
jsonstr
,
err
);
if
(
nret
<
0
)
{
*
errmsg
=
util_strdup_s
(
"Out of memory"
);
*
errmsg
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"decoding config
\"
%s
\"
, failed: %s"
,
jsonstr
,
err
);
goto
out
;
}
if
(
conf
->
cni_version
==
NULL
||
strlen
(
conf
->
cni_version
)
==
0
)
{
result
=
util_strdup_s
(
"0.1.0"
);
result
=
clibcni_
util_strdup_s
(
"0.1.0"
);
goto
out
;
}
result
=
util_strdup_s
(
conf
->
cni_version
);
result
=
clibcni_
util_strdup_s
(
conf
->
cni_version
);
out:
free
(
err
);
free_cni_version
(
conf
);
...
...
@@ -228,7 +228,7 @@ struct result *new_result(const char *version, const char *jsonstr, char **err)
}
ret
=
asprintf
(
err
,
"unsupported CNI result version
\"
%s
\"
"
,
version
);
if
(
ret
<
0
)
{
*
err
=
util_strdup_s
(
"Out of memory"
);
*
err
=
clibcni_
util_strdup_s
(
"Out of memory"
);
}
ERROR
(
"unsupported CNI result version
\"
%s
\"
"
,
version
);
return
NULL
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录