Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
2b9319af
Unverified
Commit
2b9319af
authored
Dec 08, 2020
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
confile: clean up network configuration parsing
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
20f0e57d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
120 additions
and
157 deletions
+120
-157
confile.c
src/lxc/confile.c
+118
-155
utils.c
src/lxc/utils.c
+2
-2
No files found.
src/lxc/confile.c
View file @
2b9319af
...
@@ -306,7 +306,7 @@ static int set_config_net_type(const char *key, const char *value,
...
@@ -306,7 +306,7 @@ static int set_config_net_type(const char *key, const char *value,
return
clr_config_net_type
(
key
,
lxc_conf
,
data
);
return
clr_config_net_type
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
ret_errno
(
EINVAL
)
;
if
(
strcmp
(
value
,
"veth"
)
==
0
)
{
if
(
strcmp
(
value
,
"veth"
)
==
0
)
{
netdev
->
type
=
LXC_NET_VETH
;
netdev
->
type
=
LXC_NET_VETH
;
...
@@ -333,8 +333,7 @@ static int set_config_net_type(const char *key, const char *value,
...
@@ -333,8 +333,7 @@ static int set_config_net_type(const char *key, const char *value,
}
else
if
(
strcmp
(
value
,
"none"
)
==
0
)
{
}
else
if
(
strcmp
(
value
,
"none"
)
==
0
)
{
netdev
->
type
=
LXC_NET_NONE
;
netdev
->
type
=
LXC_NET_NONE
;
}
else
{
}
else
{
ERROR
(
"Invalid network type %s"
,
value
);
return
log_error
(
-
1
,
"Invalid network type %s"
,
value
);
return
-
1
;
}
}
return
0
;
return
0
;
...
@@ -349,7 +348,7 @@ static int set_config_net_flags(const char *key, const char *value,
...
@@ -349,7 +348,7 @@ static int set_config_net_flags(const char *key, const char *value,
return
clr_config_net_flags
(
key
,
lxc_conf
,
data
);
return
clr_config_net_flags
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
ret_errno
(
EINVAL
)
;
netdev
->
flags
|=
IFF_UP
;
netdev
->
flags
|=
IFF_UP
;
...
@@ -407,7 +406,7 @@ static int set_config_net_link(const char *key, const char *value,
...
@@ -407,7 +406,7 @@ static int set_config_net_link(const char *key, const char *value,
return
clr_config_net_link
(
key
,
lxc_conf
,
data
);
return
clr_config_net_link
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
ret_errno
(
EINVAL
)
;
if
(
value
[
strlen
(
value
)
-
1
]
==
'+'
&&
netdev
->
type
==
LXC_NET_PHYS
)
if
(
value
[
strlen
(
value
)
-
1
]
==
'+'
&&
netdev
->
type
==
LXC_NET_PHYS
)
ret
=
create_matched_ifnames
(
value
,
lxc_conf
,
netdev
);
ret
=
create_matched_ifnames
(
value
,
lxc_conf
,
netdev
);
...
@@ -428,11 +427,11 @@ static int set_config_net_l2proxy(const char *key, const char *value,
...
@@ -428,11 +427,11 @@ static int set_config_net_l2proxy(const char *key, const char *value,
return
clr_config_net_l2proxy
(
key
,
lxc_conf
,
data
);
return
clr_config_net_l2proxy
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
ret_
set_errno
(
-
1
,
EINVAL
);
return
ret_
errno
(
EINVAL
);
ret
=
lxc_safe_uint
(
value
,
&
val
);
ret
=
lxc_safe_uint
(
value
,
&
val
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
ret_
set_errno
(
-
1
,
-
ret
);
return
ret_
errno
(
-
ret
);
switch
(
val
)
{
switch
(
val
)
{
case
0
:
case
0
:
...
@@ -455,7 +454,7 @@ static int set_config_net_name(const char *key, const char *value,
...
@@ -455,7 +454,7 @@ static int set_config_net_name(const char *key, const char *value,
return
clr_config_net_name
(
key
,
lxc_conf
,
data
);
return
clr_config_net_name
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
ret_errno
(
EINVAL
)
;
return
network_ifname
(
netdev
->
name
,
value
,
sizeof
(
netdev
->
name
));
return
network_ifname
(
netdev
->
name
,
value
,
sizeof
(
netdev
->
name
));
}
}
...
@@ -470,7 +469,7 @@ static int set_config_net_veth_mode(const char *key, const char *value,
...
@@ -470,7 +469,7 @@ static int set_config_net_veth_mode(const char *key, const char *value,
return
clr_config_net_veth_mode
(
key
,
lxc_conf
,
data
);
return
clr_config_net_veth_mode
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
ret_errno
(
EINVAL
)
;
return
lxc_veth_mode_to_flag
(
&
netdev
->
priv
.
veth_attr
.
mode
,
value
);
return
lxc_veth_mode_to_flag
(
&
netdev
->
priv
.
veth_attr
.
mode
,
value
);
}
}
...
@@ -484,9 +483,10 @@ static int set_config_net_veth_pair(const char *key, const char *value,
...
@@ -484,9 +483,10 @@ static int set_config_net_veth_pair(const char *key, const char *value,
return
clr_config_net_veth_pair
(
key
,
lxc_conf
,
data
);
return
clr_config_net_veth_pair
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
ret_errno
(
EINVAL
)
;
return
network_ifname
(
netdev
->
priv
.
veth_attr
.
pair
,
value
,
sizeof
(
netdev
->
priv
.
veth_attr
.
pair
));
return
network_ifname
(
netdev
->
priv
.
veth_attr
.
pair
,
value
,
sizeof
(
netdev
->
priv
.
veth_attr
.
pair
));
}
}
static
int
set_config_net_macvlan_mode
(
const
char
*
key
,
const
char
*
value
,
static
int
set_config_net_macvlan_mode
(
const
char
*
key
,
const
char
*
value
,
...
@@ -498,7 +498,7 @@ static int set_config_net_macvlan_mode(const char *key, const char *value,
...
@@ -498,7 +498,7 @@ static int set_config_net_macvlan_mode(const char *key, const char *value,
return
clr_config_net_macvlan_mode
(
key
,
lxc_conf
,
data
);
return
clr_config_net_macvlan_mode
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
ret_errno
(
EINVAL
)
;
return
lxc_macvlan_mode_to_flag
(
&
netdev
->
priv
.
macvlan_attr
.
mode
,
value
);
return
lxc_macvlan_mode_to_flag
(
&
netdev
->
priv
.
macvlan_attr
.
mode
,
value
);
}
}
...
@@ -512,12 +512,12 @@ static int set_config_net_ipvlan_mode(const char *key, const char *value,
...
@@ -512,12 +512,12 @@ static int set_config_net_ipvlan_mode(const char *key, const char *value,
return
clr_config_net_ipvlan_mode
(
key
,
lxc_conf
,
data
);
return
clr_config_net_ipvlan_mode
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
ret_
set_errno
(
-
1
,
EINVAL
);
return
ret_
errno
(
EINVAL
);
if
(
netdev
->
type
!=
LXC_NET_IPVLAN
)
{
if
(
netdev
->
type
!=
LXC_NET_IPVLAN
)
SYSERROR
(
"Invalid ipvlan mode
\"
%s
\"
, can only be used with ipvlan network"
,
value
);
return
log_error_errno
(
-
EINVAL
,
return
ret_set_errno
(
-
1
,
EINVAL
);
EINVAL
,
"Invalid ipvlan mode
\"
%s
\"
, can only be used with ipvlan network"
,
}
value
);
return
lxc_ipvlan_mode_to_flag
(
&
netdev
->
priv
.
ipvlan_attr
.
mode
,
value
);
return
lxc_ipvlan_mode_to_flag
(
&
netdev
->
priv
.
ipvlan_attr
.
mode
,
value
);
}
}
...
@@ -531,12 +531,12 @@ static int set_config_net_ipvlan_isolation(const char *key, const char *value,
...
@@ -531,12 +531,12 @@ static int set_config_net_ipvlan_isolation(const char *key, const char *value,
return
clr_config_net_ipvlan_isolation
(
key
,
lxc_conf
,
data
);
return
clr_config_net_ipvlan_isolation
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
ret_
set_errno
(
-
1
,
EINVAL
);
return
ret_
errno
(
EINVAL
);
if
(
netdev
->
type
!=
LXC_NET_IPVLAN
)
{
if
(
netdev
->
type
!=
LXC_NET_IPVLAN
)
SYSERROR
(
"Invalid ipvlan isolation
\"
%s
\"
, can only be used with ipvlan network"
,
value
);
return
log_error_errno
(
-
EINVAL
,
return
ret_set_errno
(
-
1
,
EINVAL
);
EINVAL
,
"Invalid ipvlan isolation
\"
%s
\"
, can only be used with ipvlan network"
,
}
value
);
return
lxc_ipvlan_isolation_to_flag
(
&
netdev
->
priv
.
ipvlan_attr
.
isolation
,
value
);
return
lxc_ipvlan_isolation_to_flag
(
&
netdev
->
priv
.
ipvlan_attr
.
isolation
,
value
);
}
}
...
@@ -551,11 +551,11 @@ static int set_config_net_hwaddr(const char *key, const char *value,
...
@@ -551,11 +551,11 @@ static int set_config_net_hwaddr(const char *key, const char *value,
return
clr_config_net_hwaddr
(
key
,
lxc_conf
,
data
);
return
clr_config_net_hwaddr
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
ret_errno
(
EINVAL
)
;
new_value
=
strdup
(
value
);
new_value
=
strdup
(
value
);
if
(
!
new_value
)
if
(
!
new_value
)
return
-
1
;
return
ret_errno
(
ENOMEM
)
;
rand_complete_hwaddr
(
new_value
);
rand_complete_hwaddr
(
new_value
);
...
@@ -580,11 +580,11 @@ static int set_config_net_vlan_id(const char *key, const char *value,
...
@@ -580,11 +580,11 @@ static int set_config_net_vlan_id(const char *key, const char *value,
return
clr_config_net_vlan_id
(
key
,
lxc_conf
,
data
);
return
clr_config_net_vlan_id
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
ret_errno
(
EINVAL
)
;
ret
=
get_u16
(
&
netdev
->
priv
.
vlan_attr
.
vid
,
value
,
0
);
ret
=
get_u16
(
&
netdev
->
priv
.
vlan_attr
.
vid
,
value
,
0
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
-
1
;
return
ret
;
return
0
;
return
0
;
}
}
...
@@ -598,7 +598,7 @@ static int set_config_net_mtu(const char *key, const char *value,
...
@@ -598,7 +598,7 @@ static int set_config_net_mtu(const char *key, const char *value,
return
clr_config_net_mtu
(
key
,
lxc_conf
,
data
);
return
clr_config_net_mtu
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
ret_errno
(
EINVAL
)
;
return
set_config_string_item
(
&
netdev
->
mtu
,
value
);
return
set_config_string_item
(
&
netdev
->
mtu
,
value
);
}
}
...
@@ -606,39 +606,34 @@ static int set_config_net_mtu(const char *key, const char *value,
...
@@ -606,39 +606,34 @@ static int set_config_net_mtu(const char *key, const char *value,
static
int
set_config_net_ipv4_address
(
const
char
*
key
,
const
char
*
value
,
static
int
set_config_net_ipv4_address
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
{
__do_free
char
*
addr
=
NULL
;
__do_free
struct
lxc_inetdev
*
inetdev
=
NULL
;
__do_free
struct
lxc_list
*
list
=
NULL
;
int
ret
;
int
ret
;
struct
lxc_netdev
*
netdev
=
data
;
struct
lxc_netdev
*
netdev
=
data
;
struct
lxc_inetdev
*
inetdev
;
struct
lxc_list
*
list
;
char
*
cursor
,
*
slash
;
char
*
cursor
,
*
slash
;
char
*
addr
=
NULL
,
*
bcast
=
NULL
,
*
prefix
=
NULL
;
char
*
bcast
=
NULL
,
*
prefix
=
NULL
;
if
(
lxc_config_value_empty
(
value
))
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_ipv4_address
(
key
,
lxc_conf
,
data
);
return
clr_config_net_ipv4_address
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
ret_errno
(
EINVAL
)
;
inetdev
=
malloc
(
sizeof
(
*
inetdev
));
inetdev
=
malloc
(
sizeof
(
*
inetdev
));
if
(
!
inetdev
)
if
(
!
inetdev
)
return
-
1
;
return
ret_errno
(
ENOMEM
)
;
memset
(
inetdev
,
0
,
sizeof
(
*
inetdev
));
memset
(
inetdev
,
0
,
sizeof
(
*
inetdev
));
list
=
malloc
(
sizeof
(
*
list
));
list
=
malloc
(
sizeof
(
*
list
));
if
(
!
list
)
{
if
(
!
list
)
free
(
inetdev
);
return
ret_errno
(
ENOMEM
);
return
-
1
;
}
lxc_list_init
(
list
);
lxc_list_init
(
list
);
list
->
elem
=
inetdev
;
addr
=
strdup
(
value
);
addr
=
strdup
(
value
);
if
(
!
addr
)
{
if
(
!
addr
)
free
(
inetdev
);
return
ret_errno
(
ENOMEM
);
free
(
list
);
return
-
1
;
}
cursor
=
strstr
(
addr
,
" "
);
cursor
=
strstr
(
addr
,
" "
);
if
(
cursor
)
{
if
(
cursor
)
{
...
@@ -653,35 +648,21 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
...
@@ -653,35 +648,21 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
}
}
ret
=
inet_pton
(
AF_INET
,
addr
,
&
inetdev
->
addr
);
ret
=
inet_pton
(
AF_INET
,
addr
,
&
inetdev
->
addr
);
if
(
!
ret
||
ret
<
0
)
{
if
(
!
ret
||
ret
<
0
)
SYSERROR
(
"Invalid ipv4 address
\"
%s
\"
"
,
value
);
return
log_error_errno
(
-
1
,
errno
,
"Invalid ipv4 address
\"
%s
\"
"
,
value
);
free
(
inetdev
);
free
(
addr
);
free
(
list
);
return
-
1
;
}
if
(
bcast
)
{
if
(
bcast
)
{
ret
=
inet_pton
(
AF_INET
,
bcast
,
&
inetdev
->
bcast
);
ret
=
inet_pton
(
AF_INET
,
bcast
,
&
inetdev
->
bcast
);
if
(
!
ret
||
ret
<
0
)
{
if
(
!
ret
||
ret
<
0
)
SYSERROR
(
"Invalid ipv4 broadcast address
\"
%s
\"
"
,
value
);
return
log_error_errno
(
-
1
,
errno
,
"Invalid ipv4 broadcast address
\"
%s
\"
"
,
value
);
free
(
inetdev
);
free
(
list
);
free
(
addr
);
return
-
1
;
}
}
}
/* No prefix specified, determine it from the network class. */
/* No prefix specified, determine it from the network class. */
if
(
prefix
)
{
if
(
prefix
)
{
ret
=
lxc_safe_uint
(
prefix
,
&
inetdev
->
prefix
);
ret
=
lxc_safe_uint
(
prefix
,
&
inetdev
->
prefix
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
free
(
inetdev
);
return
ret
;
free
(
list
);
free
(
addr
);
return
-
1
;
}
}
else
{
}
else
{
inetdev
->
prefix
=
config_ip_prefix
(
&
inetdev
->
addr
);
inetdev
->
prefix
=
config_ip_prefix
(
&
inetdev
->
addr
);
}
}
...
@@ -694,8 +675,10 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
...
@@ -694,8 +675,10 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
inetdev
->
bcast
.
s_addr
|=
htonl
(
INADDR_BROADCAST
>>
inetdev
->
prefix
);
inetdev
->
bcast
.
s_addr
|=
htonl
(
INADDR_BROADCAST
>>
inetdev
->
prefix
);
}
}
list
->
elem
=
inetdev
;
lxc_list_add_tail
(
&
netdev
->
ipv4
,
list
);
lxc_list_add_tail
(
&
netdev
->
ipv4
,
list
);
free
(
addr
);
move_ptr
(
inetdev
);
move_ptr
(
list
);
return
0
;
return
0
;
}
}
...
@@ -721,21 +704,18 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value,
...
@@ -721,21 +704,18 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value,
netdev
->
ipv4_gateway_auto
=
false
;
netdev
->
ipv4_gateway_auto
=
false
;
netdev
->
ipv4_gateway_dev
=
true
;
netdev
->
ipv4_gateway_dev
=
true
;
}
else
{
}
else
{
__do_free
struct
in_addr
*
gw
=
NULL
;
int
ret
;
int
ret
;
struct
in_addr
*
gw
;
gw
=
malloc
(
sizeof
(
*
gw
));
gw
=
malloc
(
sizeof
(
*
gw
));
if
(
!
gw
)
if
(
!
gw
)
return
-
1
;
return
ret_errno
(
ENOMEM
)
;
ret
=
inet_pton
(
AF_INET
,
value
,
gw
);
ret
=
inet_pton
(
AF_INET
,
value
,
gw
);
if
(
!
ret
||
ret
<
0
)
{
if
(
!
ret
||
ret
<
0
)
SYSERROR
(
"Invalid ipv4 gateway address
\"
%s
\"
"
,
value
);
return
log_error_errno
(
-
1
,
errno
,
"Invalid ipv4 gateway address
\"
%s
\"
"
,
value
);
free
(
gw
);
return
-
1
;
}
netdev
->
ipv4_gateway
=
gw
;
netdev
->
ipv4_gateway
=
move_ptr
(
gw
)
;
netdev
->
ipv4_gateway_auto
=
false
;
netdev
->
ipv4_gateway_auto
=
false
;
}
}
...
@@ -756,47 +736,47 @@ static int set_config_net_veth_ipv4_route(const char *key, const char *value,
...
@@ -756,47 +736,47 @@ static int set_config_net_veth_ipv4_route(const char *key, const char *value,
return
clr_config_net_veth_ipv4_route
(
key
,
lxc_conf
,
data
);
return
clr_config_net_veth_ipv4_route
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
ret_
set_errno
(
-
1
,
EINVAL
);
return
ret_
errno
(
EINVAL
);
if
(
netdev
->
type
!=
LXC_NET_VETH
)
{
if
(
netdev
->
type
!=
LXC_NET_VETH
)
SYSERROR
(
"Invalid ipv4 route
\"
%s
\"
, can only be used with veth network"
,
value
);
return
log_error_errno
(
-
EINVAL
,
return
ret_set_errno
(
-
1
,
EINVAL
);
EINVAL
,
"Invalid ipv4 route
\"
%s
\"
, can only be used with veth network"
,
}
value
);
inetdev
=
malloc
(
sizeof
(
*
inetdev
));
inetdev
=
malloc
(
sizeof
(
*
inetdev
));
if
(
!
inetdev
)
if
(
!
inetdev
)
return
-
1
;
return
ret_errno
(
ENOMEM
)
;
memset
(
inetdev
,
0
,
sizeof
(
*
inetdev
));
memset
(
inetdev
,
0
,
sizeof
(
*
inetdev
));
list
=
malloc
(
sizeof
(
*
list
));
list
=
malloc
(
sizeof
(
*
list
));
if
(
!
list
)
if
(
!
list
)
return
-
1
;
return
ret_errno
(
ENOMEM
)
;
lxc_list_init
(
list
);
lxc_list_init
(
list
);
list
->
elem
=
inetdev
;
list
->
elem
=
inetdev
;
valdup
=
strdup
(
value
);
valdup
=
strdup
(
value
);
if
(
!
valdup
)
if
(
!
valdup
)
return
-
1
;
return
ret_errno
(
ENOMEM
)
;
slash
=
strchr
(
valdup
,
'/'
);
slash
=
strchr
(
valdup
,
'/'
);
if
(
!
slash
)
if
(
!
slash
)
return
ret_
set_errno
(
-
1
,
EINVAL
);
return
ret_
errno
(
EINVAL
);
*
slash
=
'\0'
;
*
slash
=
'\0'
;
slash
++
;
slash
++
;
if
(
*
slash
==
'\0'
)
if
(
*
slash
==
'\0'
)
return
ret_
set_errno
(
-
1
,
EINVAL
);
return
ret_
errno
(
EINVAL
);
netmask
=
slash
;
netmask
=
slash
;
ret
=
lxc_safe_uint
(
netmask
,
&
inetdev
->
prefix
);
ret
=
lxc_safe_uint
(
netmask
,
&
inetdev
->
prefix
);
if
(
ret
<
0
||
inetdev
->
prefix
>
32
)
if
(
ret
<
0
||
inetdev
->
prefix
>
32
)
return
ret_
set_errno
(
-
1
,
EINVAL
);
return
ret_
errno
(
EINVAL
);
ret
=
inet_pton
(
AF_INET
,
valdup
,
&
inetdev
->
addr
);
ret
=
inet_pton
(
AF_INET
,
valdup
,
&
inetdev
->
addr
);
if
(
!
ret
||
ret
<
0
)
if
(
!
ret
||
ret
<
0
)
return
ret_
set_errno
(
-
1
,
EINVAL
);
return
ret_
errno
(
EINVAL
);
lxc_list_add_tail
(
&
netdev
->
priv
.
veth_attr
.
ipv4_routes
,
list
);
lxc_list_add_tail
(
&
netdev
->
priv
.
veth_attr
.
ipv4_routes
,
list
);
move_ptr
(
inetdev
);
move_ptr
(
inetdev
);
...
@@ -808,38 +788,33 @@ static int set_config_net_veth_ipv4_route(const char *key, const char *value,
...
@@ -808,38 +788,33 @@ static int set_config_net_veth_ipv4_route(const char *key, const char *value,
static
int
set_config_net_ipv6_address
(
const
char
*
key
,
const
char
*
value
,
static
int
set_config_net_ipv6_address
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
{
__do_free
char
*
valdup
=
NULL
;
__do_free
struct
lxc_inet6dev
*
inet6dev
=
NULL
;
__do_free
struct
lxc_list
*
list
=
NULL
;
int
ret
;
int
ret
;
struct
lxc_netdev
*
netdev
=
data
;
struct
lxc_netdev
*
netdev
=
data
;
struct
lxc_inet6dev
*
inet6dev
;
char
*
slash
,
*
netmask
;
struct
lxc_list
*
list
;
char
*
slash
,
*
valdup
,
*
netmask
;
if
(
lxc_config_value_empty
(
value
))
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_ipv6_address
(
key
,
lxc_conf
,
data
);
return
clr_config_net_ipv6_address
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
ret_errno
(
EINVAL
)
;
inet6dev
=
malloc
(
sizeof
(
*
inet6dev
));
inet6dev
=
malloc
(
sizeof
(
*
inet6dev
));
if
(
!
inet6dev
)
if
(
!
inet6dev
)
return
-
1
;
return
ret_errno
(
ENOMEM
)
;
memset
(
inet6dev
,
0
,
sizeof
(
*
inet6dev
));
memset
(
inet6dev
,
0
,
sizeof
(
*
inet6dev
));
list
=
malloc
(
sizeof
(
*
list
));
list
=
malloc
(
sizeof
(
*
list
));
if
(
!
list
)
{
if
(
!
list
)
free
(
inet6dev
);
return
ret_errno
(
ENOMEM
);
return
-
1
;
}
lxc_list_init
(
list
);
lxc_list_init
(
list
);
list
->
elem
=
inet6dev
;
valdup
=
strdup
(
value
);
valdup
=
strdup
(
value
);
if
(
!
valdup
)
{
if
(
!
valdup
)
free
(
list
);
return
ret_errno
(
ENOMEM
);
free
(
inet6dev
);
return
-
1
;
}
inet6dev
->
prefix
=
64
;
inet6dev
->
prefix
=
64
;
slash
=
strstr
(
valdup
,
"/"
);
slash
=
strstr
(
valdup
,
"/"
);
...
@@ -848,25 +823,18 @@ static int set_config_net_ipv6_address(const char *key, const char *value,
...
@@ -848,25 +823,18 @@ static int set_config_net_ipv6_address(const char *key, const char *value,
netmask
=
slash
+
1
;
netmask
=
slash
+
1
;
ret
=
lxc_safe_uint
(
netmask
,
&
inet6dev
->
prefix
);
ret
=
lxc_safe_uint
(
netmask
,
&
inet6dev
->
prefix
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
free
(
list
);
return
ret
;
free
(
inet6dev
);
free
(
valdup
);
return
-
1
;
}
}
}
ret
=
inet_pton
(
AF_INET6
,
valdup
,
&
inet6dev
->
addr
);
ret
=
inet_pton
(
AF_INET6
,
valdup
,
&
inet6dev
->
addr
);
if
(
!
ret
||
ret
<
0
)
{
if
(
!
ret
||
ret
<
0
)
SYSERROR
(
"Invalid ipv6 address
\"
%s
\"
"
,
valdup
);
return
log_error_errno
(
-
EINVAL
,
EINVAL
,
"Invalid ipv6 address
\"
%s
\"
"
,
valdup
);
free
(
list
);
free
(
inet6dev
);
free
(
valdup
);
return
-
1
;
}
list
->
elem
=
inet6dev
;
lxc_list_add_tail
(
&
netdev
->
ipv6
,
list
);
lxc_list_add_tail
(
&
netdev
->
ipv6
,
list
);
free
(
valdup
);
move_ptr
(
inet6dev
);
move_ptr
(
list
);
return
0
;
return
0
;
}
}
...
@@ -880,7 +848,7 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value,
...
@@ -880,7 +848,7 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value,
return
clr_config_net_ipv6_gateway
(
key
,
lxc_conf
,
data
);
return
clr_config_net_ipv6_gateway
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
ret_errno
(
EINVAL
)
;
free
(
netdev
->
ipv6_gateway
);
free
(
netdev
->
ipv6_gateway
);
...
@@ -893,20 +861,18 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value,
...
@@ -893,20 +861,18 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value,
netdev
->
ipv6_gateway_dev
=
true
;
netdev
->
ipv6_gateway_dev
=
true
;
}
else
{
}
else
{
int
ret
;
int
ret
;
struct
in6_addr
*
gw
;
__do_free
struct
in6_addr
*
gw
=
NULL
;
gw
=
malloc
(
sizeof
(
*
gw
));
gw
=
malloc
(
sizeof
(
*
gw
));
if
(
!
gw
)
if
(
!
gw
)
return
-
1
;
return
ret_errno
(
ENOMEM
)
;
ret
=
inet_pton
(
AF_INET6
,
value
,
gw
);
ret
=
inet_pton
(
AF_INET6
,
value
,
gw
);
if
(
!
ret
||
ret
<
0
)
{
if
(
!
ret
||
ret
<
0
)
SYSERROR
(
"Invalid ipv6 gateway address
\"
%s
\"
"
,
value
);
return
log_error_errno
(
-
EINVAL
,
EINVAL
,
free
(
gw
);
"Invalid ipv6 gateway address
\"
%s
\"
"
,
value
);
return
-
1
;
}
netdev
->
ipv6_gateway
=
gw
;
netdev
->
ipv6_gateway
=
move_ptr
(
gw
)
;
netdev
->
ipv6_gateway_auto
=
false
;
netdev
->
ipv6_gateway_auto
=
false
;
}
}
...
@@ -927,24 +893,23 @@ static int set_config_net_veth_ipv6_route(const char *key, const char *value,
...
@@ -927,24 +893,23 @@ static int set_config_net_veth_ipv6_route(const char *key, const char *value,
return
clr_config_net_veth_ipv6_route
(
key
,
lxc_conf
,
data
);
return
clr_config_net_veth_ipv6_route
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
ret_
set_errno
(
-
1
,
EINVAL
);
return
ret_
errno
(
EINVAL
);
if
(
netdev
->
type
!=
LXC_NET_VETH
)
{
if
(
netdev
->
type
!=
LXC_NET_VETH
)
SYSERROR
(
"Invalid ipv6 route
\"
%s
\"
, can only be used with veth network"
,
value
);
return
log_error_errno
(
-
EINVAL
,
return
ret_set_errno
(
-
1
,
EINVAL
);
EINVAL
,
"Invalid ipv6 route
\"
%s
\"
, can only be used with veth network"
,
}
value
);
inet6dev
=
malloc
(
sizeof
(
*
inet6dev
));
inet6dev
=
malloc
(
sizeof
(
*
inet6dev
));
if
(
!
inet6dev
)
if
(
!
inet6dev
)
return
-
1
;
return
ret_errno
(
ENOMEM
)
;
memset
(
inet6dev
,
0
,
sizeof
(
*
inet6dev
));
memset
(
inet6dev
,
0
,
sizeof
(
*
inet6dev
));
list
=
malloc
(
sizeof
(
*
list
));
list
=
malloc
(
sizeof
(
*
list
));
if
(
!
list
)
if
(
!
list
)
return
-
1
;
return
ret_errno
(
ENOMEM
)
;
lxc_list_init
(
list
);
lxc_list_init
(
list
);
list
->
elem
=
inet6dev
;
valdup
=
strdup
(
value
);
valdup
=
strdup
(
value
);
if
(
!
valdup
)
if
(
!
valdup
)
...
@@ -952,23 +917,24 @@ static int set_config_net_veth_ipv6_route(const char *key, const char *value,
...
@@ -952,23 +917,24 @@ static int set_config_net_veth_ipv6_route(const char *key, const char *value,
slash
=
strchr
(
valdup
,
'/'
);
slash
=
strchr
(
valdup
,
'/'
);
if
(
!
slash
)
if
(
!
slash
)
return
ret_
set_errno
(
-
1
,
EINVAL
);
return
ret_
errno
(
EINVAL
);
*
slash
=
'\0'
;
*
slash
=
'\0'
;
slash
++
;
slash
++
;
if
(
*
slash
==
'\0'
)
if
(
*
slash
==
'\0'
)
return
ret_
set_errno
(
-
1
,
EINVAL
);
return
ret_
errno
(
EINVAL
);
netmask
=
slash
;
netmask
=
slash
;
ret
=
lxc_safe_uint
(
netmask
,
&
inet6dev
->
prefix
);
ret
=
lxc_safe_uint
(
netmask
,
&
inet6dev
->
prefix
);
if
(
ret
<
0
||
inet6dev
->
prefix
>
128
)
if
(
ret
<
0
||
inet6dev
->
prefix
>
128
)
return
ret_
set_errno
(
-
1
,
EINVAL
);
return
ret_
errno
(
EINVAL
);
ret
=
inet_pton
(
AF_INET6
,
valdup
,
&
inet6dev
->
addr
);
ret
=
inet_pton
(
AF_INET6
,
valdup
,
&
inet6dev
->
addr
);
if
(
!
ret
||
ret
<
0
)
if
(
!
ret
||
ret
<
0
)
return
ret_
set_errno
(
-
1
,
EINVAL
);
return
ret_
errno
(
EINVAL
);
list
->
elem
=
inet6dev
;
lxc_list_add_tail
(
&
netdev
->
priv
.
veth_attr
.
ipv6_routes
,
list
);
lxc_list_add_tail
(
&
netdev
->
priv
.
veth_attr
.
ipv6_routes
,
list
);
move_ptr
(
inet6dev
);
move_ptr
(
inet6dev
);
move_ptr
(
list
);
move_ptr
(
list
);
...
@@ -985,7 +951,7 @@ static int set_config_net_script_up(const char *key, const char *value,
...
@@ -985,7 +951,7 @@ static int set_config_net_script_up(const char *key, const char *value,
return
clr_config_net_script_up
(
key
,
lxc_conf
,
data
);
return
clr_config_net_script_up
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
ret_errno
(
EINVAL
)
;
return
set_config_string_item
(
&
netdev
->
upscript
,
value
);
return
set_config_string_item
(
&
netdev
->
upscript
,
value
);
}
}
...
@@ -999,22 +965,21 @@ static int set_config_net_script_down(const char *key, const char *value,
...
@@ -999,22 +965,21 @@ static int set_config_net_script_down(const char *key, const char *value,
return
clr_config_net_script_down
(
key
,
lxc_conf
,
data
);
return
clr_config_net_script_down
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
ret_errno
(
EINVAL
)
;
return
set_config_string_item
(
&
netdev
->
downscript
,
value
);
return
set_config_string_item
(
&
netdev
->
downscript
,
value
);
}
}
static
int
add_hook
(
struct
lxc_conf
*
lxc_conf
,
int
which
,
char
*
hook
)
static
int
add_hook
(
struct
lxc_conf
*
lxc_conf
,
int
which
,
__owns
char
*
hook
)
{
{
__do_free
char
*
val
=
hook
;
struct
lxc_list
*
hooklist
;
struct
lxc_list
*
hooklist
;
hooklist
=
malloc
(
sizeof
(
*
hooklist
));
hooklist
=
malloc
(
sizeof
(
*
hooklist
));
if
(
!
hooklist
)
{
if
(
!
hooklist
)
free
(
hook
);
return
ret_errno
(
ENOMEM
);
return
-
1
;
}
hooklist
->
elem
=
hook
;
hooklist
->
elem
=
move_ptr
(
val
)
;
lxc_list_add_tail
(
&
lxc_conf
->
hooks
[
which
],
hooklist
);
lxc_list_add_tail
(
&
lxc_conf
->
hooks
[
which
],
hooklist
);
return
0
;
return
0
;
...
@@ -1135,7 +1100,7 @@ static int set_config_init_gid(const char *key, const char *value,
...
@@ -1135,7 +1100,7 @@ static int set_config_init_gid(const char *key, const char *value,
static
int
set_config_hooks
(
const
char
*
key
,
const
char
*
value
,
static
int
set_config_hooks
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
{
char
*
copy
;
__do_free
char
*
copy
=
NULL
;
if
(
lxc_config_value_empty
(
value
))
if
(
lxc_config_value_empty
(
value
))
return
lxc_clear_hooks
(
lxc_conf
,
key
);
return
lxc_clear_hooks
(
lxc_conf
,
key
);
...
@@ -1147,30 +1112,28 @@ static int set_config_hooks(const char *key, const char *value,
...
@@ -1147,30 +1112,28 @@ static int set_config_hooks(const char *key, const char *value,
copy
=
strdup
(
value
);
copy
=
strdup
(
value
);
if
(
!
copy
)
if
(
!
copy
)
return
-
1
;
return
ret_errno
(
ENOMEM
)
;
if
(
strcmp
(
key
+
9
,
"pre-start"
)
==
0
)
if
(
strcmp
(
key
+
9
,
"pre-start"
)
==
0
)
return
add_hook
(
lxc_conf
,
LXCHOOK_PRESTART
,
copy
);
return
add_hook
(
lxc_conf
,
LXCHOOK_PRESTART
,
move_ptr
(
copy
)
);
else
if
(
strcmp
(
key
+
9
,
"start-host"
)
==
0
)
else
if
(
strcmp
(
key
+
9
,
"start-host"
)
==
0
)
return
add_hook
(
lxc_conf
,
LXCHOOK_START_HOST
,
copy
);
return
add_hook
(
lxc_conf
,
LXCHOOK_START_HOST
,
move_ptr
(
copy
)
);
else
if
(
strcmp
(
key
+
9
,
"pre-mount"
)
==
0
)
else
if
(
strcmp
(
key
+
9
,
"pre-mount"
)
==
0
)
return
add_hook
(
lxc_conf
,
LXCHOOK_PREMOUNT
,
copy
);
return
add_hook
(
lxc_conf
,
LXCHOOK_PREMOUNT
,
move_ptr
(
copy
)
);
else
if
(
strcmp
(
key
+
9
,
"autodev"
)
==
0
)
else
if
(
strcmp
(
key
+
9
,
"autodev"
)
==
0
)
return
add_hook
(
lxc_conf
,
LXCHOOK_AUTODEV
,
copy
);
return
add_hook
(
lxc_conf
,
LXCHOOK_AUTODEV
,
move_ptr
(
copy
)
);
else
if
(
strcmp
(
key
+
9
,
"mount"
)
==
0
)
else
if
(
strcmp
(
key
+
9
,
"mount"
)
==
0
)
return
add_hook
(
lxc_conf
,
LXCHOOK_MOUNT
,
copy
);
return
add_hook
(
lxc_conf
,
LXCHOOK_MOUNT
,
move_ptr
(
copy
)
);
else
if
(
strcmp
(
key
+
9
,
"start"
)
==
0
)
else
if
(
strcmp
(
key
+
9
,
"start"
)
==
0
)
return
add_hook
(
lxc_conf
,
LXCHOOK_START
,
copy
);
return
add_hook
(
lxc_conf
,
LXCHOOK_START
,
move_ptr
(
copy
)
);
else
if
(
strcmp
(
key
+
9
,
"stop"
)
==
0
)
else
if
(
strcmp
(
key
+
9
,
"stop"
)
==
0
)
return
add_hook
(
lxc_conf
,
LXCHOOK_STOP
,
copy
);
return
add_hook
(
lxc_conf
,
LXCHOOK_STOP
,
move_ptr
(
copy
)
);
else
if
(
strcmp
(
key
+
9
,
"post-stop"
)
==
0
)
else
if
(
strcmp
(
key
+
9
,
"post-stop"
)
==
0
)
return
add_hook
(
lxc_conf
,
LXCHOOK_POSTSTOP
,
copy
);
return
add_hook
(
lxc_conf
,
LXCHOOK_POSTSTOP
,
move_ptr
(
copy
)
);
else
if
(
strcmp
(
key
+
9
,
"clone"
)
==
0
)
else
if
(
strcmp
(
key
+
9
,
"clone"
)
==
0
)
return
add_hook
(
lxc_conf
,
LXCHOOK_CLONE
,
copy
);
return
add_hook
(
lxc_conf
,
LXCHOOK_CLONE
,
move_ptr
(
copy
)
);
else
if
(
strcmp
(
key
+
9
,
"destroy"
)
==
0
)
else
if
(
strcmp
(
key
+
9
,
"destroy"
)
==
0
)
return
add_hook
(
lxc_conf
,
LXCHOOK_DESTROY
,
copy
);
return
add_hook
(
lxc_conf
,
LXCHOOK_DESTROY
,
move_ptr
(
copy
));
free
(
copy
);
return
-
1
;
return
-
1
;
}
}
...
...
src/lxc/utils.c
View file @
2b9319af
...
@@ -201,12 +201,12 @@ extern int get_u16(unsigned short *val, const char *arg, int base)
...
@@ -201,12 +201,12 @@ extern int get_u16(unsigned short *val, const char *arg, int base)
char
*
ptr
;
char
*
ptr
;
if
(
!
arg
||
!*
arg
)
if
(
!
arg
||
!*
arg
)
return
-
1
;
return
ret_errno
(
EINVAL
)
;
errno
=
0
;
errno
=
0
;
res
=
strtoul
(
arg
,
&
ptr
,
base
);
res
=
strtoul
(
arg
,
&
ptr
,
base
);
if
(
!
ptr
||
ptr
==
arg
||
*
ptr
||
res
>
0xFFFF
||
errno
!=
0
)
if
(
!
ptr
||
ptr
==
arg
||
*
ptr
||
res
>
0xFFFF
||
errno
!=
0
)
return
-
1
;
return
ret_errno
(
ERANGE
)
;
*
val
=
res
;
*
val
=
res
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment