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
f9fcfffd
Unverified
Commit
f9fcfffd
authored
May 29, 2018
by
Stéphane Graber
Committed by
GitHub
May 29, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2359 from brauner/2018-05-28/fix_stable-2.0_network_parsing
confile: backport parts of network parsing
parents
834b74a0
04cc2bf1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
112 additions
and
27 deletions
+112
-27
confile.c
src/lxc/confile.c
+112
-27
No files found.
src/lxc/confile.c
View file @
f9fcfffd
...
@@ -528,45 +528,130 @@ static int set_config_path_item(char **conf_item, const char *value)
...
@@ -528,45 +528,130 @@ static int set_config_path_item(char **conf_item, const char *value)
return
set_config_string_item_max
(
conf_item
,
value
,
PATH_MAX
);
return
set_config_string_item_max
(
conf_item
,
value
,
PATH_MAX
);
}
}
/*
static
struct
lxc_config_t
*
get_network_config_ops
(
const
char
*
key
,
* Config entry is something like "lxc.network.0.ipv4" the key 'lxc.network.'
struct
lxc_conf
*
lxc_conf
,
* was found. So we make sure next comes an integer, find the right callback
ssize_t
*
idx
,
* (by rewriting the key), and call it.
char
**
deindexed_key
)
*/
static
int
set_config_network_nic
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
{
char
*
copy
=
strdup
(
key
),
*
p
;
int
ret
;
int
ret
=
-
1
;
unsigned
int
tmpidx
;
struct
lxc_config_t
*
config
;
size_t
numstrlen
;
char
*
copy
,
*
idx_start
,
*
idx_end
;
struct
lxc_config_t
*
config
=
NULL
;
/* check that this is a sensible network key */
if
(
strncmp
(
"lxc.network."
,
key
,
12
))
{
ERROR
(
"Invalid network configuration key
\"
%s
\"
"
,
key
);
return
NULL
;
}
copy
=
strdup
(
key
);
if
(
!
copy
)
{
if
(
!
copy
)
{
SYSERROR
(
"failed to allocate memory"
);
ERROR
(
"Failed to duplicate string
\"
%s
\"
"
,
key
);
return
-
1
;
return
NULL
;
}
/* lxc.network.<n> */
if
(
!
isdigit
(
*
(
key
+
12
)))
{
ERROR
(
"Failed to detect digit in string
\"
%s
\"
"
,
key
+
12
);
goto
on_error
;
}
/* beginning of index string */
idx_start
=
(
copy
+
11
);
*
idx_start
=
'\0'
;
/* end of index string */
idx_end
=
strchr
((
copy
+
12
),
'.'
);
if
(
idx_end
)
*
idx_end
=
'\0'
;
/* parse current index */
ret
=
lxc_safe_uint
((
idx_start
+
1
),
&
tmpidx
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to parse usigned integer from string
\"
%s
\"
: %s"
,
idx_start
+
1
,
strerror
(
-
ret
));
*
idx
=
ret
;
goto
on_error
;
}
}
/*
* Ok we know that to get here we've got "lxc.network."
/* This, of course is utterly nonsensical on so many levels, but
* and it isn't any of the other network entries. So
* better safe than sorry.
* after the second . Should come an integer (# of defined
* (Checking for INT_MAX here is intentional.)
* nic) followed by a valid entry.
*/
*/
if
(
*
(
key
+
12
)
<
'0'
||
*
(
key
+
12
)
>
'9'
)
if
(
tmpidx
==
INT_MAX
)
{
goto
out
;
SYSERROR
(
"Number of configured networks would overflow the "
"counter"
);
goto
on_error
;
}
*
idx
=
tmpidx
;
p
=
strchr
(
key
+
12
,
'.'
);
numstrlen
=
strlen
((
idx_start
+
1
));
if
(
!
p
)
goto
out
;
/* repair configuration key */
*
idx_start
=
'.'
;
/* lxc.network.<idx>.<subkey> */
if
(
idx_end
)
{
*
idx_end
=
'.'
;
if
(
strlen
(
idx_end
+
1
)
==
0
)
{
ERROR
(
"No subkey in network configuration key
\"
%s
\"
"
,
key
);
goto
on_error
;
}
memmove
(
copy
+
12
,
idx_end
+
1
,
strlen
(
idx_end
+
1
));
copy
[
strlen
(
key
)
-
numstrlen
+
1
]
=
'\0'
;
strcpy
(
copy
+
12
,
p
+
1
);
config
=
lxc_getconfig
(
copy
);
config
=
lxc_getconfig
(
copy
);
if
(
!
config
)
{
if
(
!
config
)
{
ERROR
(
"unknown key %s"
,
key
);
ERROR
(
"Unknown network configuration key
\"
%s
\"
"
,
key
);
goto
out
;
goto
on_error
;
}
}
}
ret
=
config
->
set
(
key
,
value
,
lxc_conf
,
data
);
out:
if
(
deindexed_key
)
*
deindexed_key
=
copy
;
return
config
;
on_error:
free
(
copy
);
free
(
copy
);
return
NULL
;
}
/* Config entry is something like "lxc.network.0.ipv4" the key 'lxc.network.'
* was found. So we make sure next comes an integer, find the right callback
* (by rewriting the key), and call it.
*/
static
int
set_config_network_nic
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
int
ret
;
const
char
*
idxstring
;
struct
lxc_config_t
*
config
;
struct
lxc_netdev
*
netdev
;
ssize_t
idx
=
-
1
;
char
*
deindexed_key
=
NULL
;
idxstring
=
key
+
12
;
if
(
!
isdigit
(
*
idxstring
))
return
-
1
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_network_item
(
key
,
lxc_conf
,
data
);
config
=
get_network_config_ops
(
key
,
lxc_conf
,
&
idx
,
&
deindexed_key
);
if
(
!
config
||
idx
<
0
)
return
-
1
;
netdev
=
lxc_get_netdev_by_idx
(
lxc_conf
,
(
unsigned
int
)
idx
);
if
(
!
netdev
)
{
free
(
deindexed_key
);
return
-
1
;
}
ret
=
config
->
set
(
deindexed_key
,
value
,
lxc_conf
,
netdev
);
free
(
deindexed_key
);
return
ret
;
return
ret
;
}
}
...
...
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