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
d5c2cd94
Unverified
Commit
d5c2cd94
authored
Dec 08, 2020
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
confile: cleanup get_network_config_ops()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
218c46ec
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
49 deletions
+24
-49
confile.c
src/lxc/confile.c
+24
-49
No files found.
src/lxc/confile.c
View file @
d5c2cd94
...
@@ -5050,29 +5050,24 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
...
@@ -5050,29 +5050,24 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
ssize_t
*
idx
,
ssize_t
*
idx
,
char
**
deindexed_key
)
char
**
deindexed_key
)
{
{
__do_free
char
*
copy
=
NULL
;
struct
lxc_config_t
*
config
=
NULL
;
int
ret
;
int
ret
;
unsigned
int
tmpidx
;
unsigned
int
tmpidx
;
size_t
numstrlen
;
size_t
numstrlen
;
char
*
copy
,
*
idx_start
,
*
idx_end
;
char
*
idx_start
,
*
idx_end
;
struct
lxc_config_t
*
config
=
NULL
;
/* check that this is a sensible network key */
/* check that this is a sensible network key */
if
(
strncmp
(
"lxc.net."
,
key
,
8
))
{
if
(
strncmp
(
"lxc.net."
,
key
,
8
))
ERROR
(
"Invalid network configuration key
\"
%s
\"
"
,
key
);
return
log_error_errno
(
NULL
,
EINVAL
,
"Invalid network configuration key
\"
%s
\"
"
,
key
);
return
NULL
;
}
copy
=
strdup
(
key
);
copy
=
strdup
(
key
);
if
(
!
copy
)
{
if
(
!
copy
)
ERROR
(
"Failed to duplicate string
\"
%s
\"
"
,
key
);
return
log_error_errno
(
NULL
,
ENOMEM
,
"Failed to duplicate string
\"
%s
\"
"
,
key
);
return
NULL
;
}
/* lxc.net.<n> */
/* lxc.net.<n> */
if
(
!
isdigit
(
*
(
key
+
8
)))
{
if
(
!
isdigit
(
*
(
key
+
8
)))
ERROR
(
"Failed to detect digit in string
\"
%s
\"
"
,
key
+
8
);
return
log_error_errno
(
NULL
,
EINVAL
,
"Failed to detect digit in string
\"
%s
\"
"
,
key
+
8
);
goto
on_error
;
}
/* beginning of index string */
/* beginning of index string */
idx_start
=
(
copy
+
7
);
idx_start
=
(
copy
+
7
);
...
@@ -5086,22 +5081,16 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
...
@@ -5086,22 +5081,16 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
/* parse current index */
/* parse current index */
ret
=
lxc_safe_uint
((
idx_start
+
1
),
&
tmpidx
);
ret
=
lxc_safe_uint
((
idx_start
+
1
),
&
tmpidx
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
errno
=
-
ret
;
SYSERROR
(
"Failed to parse unsigned integer from string
\"
%s
\"
"
,
idx_start
+
1
);
*
idx
=
ret
;
*
idx
=
ret
;
goto
on_error
;
return
log_error_errno
(
NULL
,
-
ret
,
"Failed to parse unsigned integer from string
\"
%s
\"
"
,
idx_start
+
1
)
;
}
}
/* This, of course is utterly nonsensical on so many levels, but
/* This, of course is utterly nonsensical on so many levels, but
* better safe than sorry.
* better safe than sorry.
* (Checking for INT_MAX here is intentional.)
* (Checking for INT_MAX here is intentional.)
*/
*/
if
(
tmpidx
==
INT_MAX
)
{
if
(
tmpidx
==
INT_MAX
)
SYSERROR
(
"Number of configured networks would overflow the "
return
log_error_errno
(
NULL
,
ERANGE
,
"Number of configured networks would overflow the counter"
);
"counter"
);
goto
on_error
;
}
*
idx
=
tmpidx
;
*
idx
=
tmpidx
;
numstrlen
=
strlen
((
idx_start
+
1
));
numstrlen
=
strlen
((
idx_start
+
1
));
...
@@ -5112,29 +5101,21 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
...
@@ -5112,29 +5101,21 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
/* lxc.net.<idx>.<subkey> */
/* lxc.net.<idx>.<subkey> */
if
(
idx_end
)
{
if
(
idx_end
)
{
*
idx_end
=
'.'
;
*
idx_end
=
'.'
;
if
(
strlen
(
idx_end
+
1
)
==
0
)
{
if
(
strlen
(
idx_end
+
1
)
==
0
)
ERROR
(
"No subkey in network configuration key
\"
%s
\"
"
,
key
);
return
log_error_errno
(
NULL
,
EINVAL
,
"No subkey in network configuration key
\"
%s
\"
"
,
key
);
goto
on_error
;
}
memmove
(
copy
+
8
,
idx_end
+
1
,
strlen
(
idx_end
+
1
));
memmove
(
copy
+
8
,
idx_end
+
1
,
strlen
(
idx_end
+
1
));
copy
[
strlen
(
key
)
-
(
numstrlen
+
1
)]
=
'\0'
;
copy
[
strlen
(
key
)
-
(
numstrlen
+
1
)]
=
'\0'
;
config
=
lxc_get_config
(
copy
);
config
=
lxc_get_config
(
copy
);
if
(
!
config
)
{
if
(
!
config
)
ERROR
(
"Unknown network configuration key
\"
%s
\"
"
,
key
);
return
log_error_errno
(
NULL
,
ENOENT
,
"Unknown network configuration key
\"
%s
\"
"
,
key
);
goto
on_error
;
}
}
}
if
(
deindexed_key
)
if
(
deindexed_key
)
*
deindexed_key
=
copy
;
*
deindexed_key
=
move_ptr
(
copy
)
;
return
config
;
return
config
;
on_error:
free
(
copy
);
return
NULL
;
}
}
/* Config entry is something like "lxc.net.0.ipv4" the key 'lxc.net.' was
/* Config entry is something like "lxc.net.0.ipv4" the key 'lxc.net.' was
...
@@ -5144,34 +5125,28 @@ on_error:
...
@@ -5144,34 +5125,28 @@ on_error:
static
int
set_config_net_nic
(
const
char
*
key
,
const
char
*
value
,
static
int
set_config_net_nic
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
{
int
ret
;
__do_free
char
*
deindexed_key
=
NULL
;
ssize_t
idx
=
-
1
;
const
char
*
idxstring
;
const
char
*
idxstring
;
struct
lxc_config_t
*
config
;
struct
lxc_config_t
*
config
;
struct
lxc_netdev
*
netdev
;
struct
lxc_netdev
*
netdev
;
ssize_t
idx
=
-
1
;
char
*
deindexed_key
=
NULL
;
idxstring
=
key
+
8
;
idxstring
=
key
+
8
;
if
(
!
isdigit
(
*
idxstring
))
if
(
!
isdigit
(
*
idxstring
))
return
-
1
;
return
ret_errno
(
EINVAL
)
;
if
(
lxc_config_value_empty
(
value
))
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_nic
(
key
,
lxc_conf
,
data
);
return
clr_config_net_nic
(
key
,
lxc_conf
,
data
);
config
=
get_network_config_ops
(
key
,
lxc_conf
,
&
idx
,
&
deindexed_key
);
config
=
get_network_config_ops
(
key
,
lxc_conf
,
&
idx
,
&
deindexed_key
);
if
(
!
config
||
idx
<
0
)
if
(
!
config
||
idx
<
0
)
return
-
1
;
return
-
errno
;
netdev
=
lxc_get_netdev_by_idx
(
lxc_conf
,
(
unsigned
int
)
idx
,
true
);
netdev
=
lxc_get_netdev_by_idx
(
lxc_conf
,
(
unsigned
int
)
idx
,
true
);
if
(
!
netdev
)
{
if
(
!
netdev
)
free
(
deindexed_key
);
return
ret_errno
(
EINVAL
);
return
-
1
;
}
ret
=
config
->
set
(
deindexed_key
,
value
,
lxc_conf
,
netdev
);
free
(
deindexed_key
);
return
ret
;
return
config
->
set
(
deindexed_key
,
value
,
lxc_conf
,
netdev
)
;
}
}
static
int
clr_config_net_nic
(
const
char
*
key
,
struct
lxc_conf
*
lxc_conf
,
static
int
clr_config_net_nic
(
const
char
*
key
,
struct
lxc_conf
*
lxc_conf
,
...
...
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