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
01f55c40
Unverified
Commit
01f55c40
authored
Aug 11, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
confile: rework lxc_list_net()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
70c1e708
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
94 deletions
+69
-94
confile.c
src/lxc/confile.c
+60
-92
confile.h
src/lxc/confile.h
+8
-1
lxccontainer.c
src/lxc/lxccontainer.c
+1
-1
No files found.
src/lxc/confile.c
View file @
01f55c40
...
...
@@ -435,98 +435,6 @@ static int set_config_net_type(const char *key, const char *value,
return
0
;
}
/*
* If you have p="lxc.net.0.link", pass it p+8
* to get back '0' (the index of the nic).
*/
static
int
get_network_netdev_idx
(
const
char
*
key
)
{
int
ret
,
idx
;
if
(
*
key
<
'0'
||
*
key
>
'9'
)
return
-
1
;
ret
=
sscanf
(
key
,
"%d"
,
&
idx
);
if
(
ret
!=
1
)
return
-
1
;
return
idx
;
}
/*
* If you have p="lxc.net.0", pass this p+8 and it will return
* the netdev of the first configured nic.
*/
static
struct
lxc_netdev
*
get_netdev_from_key
(
const
char
*
key
,
struct
lxc_list
*
network
)
{
int
idx
;
struct
lxc_list
*
it
;
int
i
=
0
;
struct
lxc_netdev
*
netdev
=
NULL
;
idx
=
get_network_netdev_idx
(
key
);
if
(
idx
==
-
1
)
return
NULL
;
lxc_list_for_each
(
it
,
network
)
{
if
(
idx
==
i
++
)
{
netdev
=
it
->
elem
;
break
;
}
}
return
netdev
;
}
extern
int
lxc_list_nicconfigs
(
struct
lxc_conf
*
c
,
const
char
*
key
,
char
*
retv
,
int
inlen
)
{
struct
lxc_netdev
*
netdev
;
int
len
;
int
fulllen
=
0
;
netdev
=
get_netdev_from_key
(
key
+
8
,
&
c
->
network
);
if
(
!
netdev
)
return
-
1
;
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
strprint
(
retv
,
inlen
,
"type
\n
"
);
strprint
(
retv
,
inlen
,
"script.up
\n
"
);
strprint
(
retv
,
inlen
,
"script.down
\n
"
);
if
(
netdev
->
type
!=
LXC_NET_EMPTY
)
{
strprint
(
retv
,
inlen
,
"flags
\n
"
);
strprint
(
retv
,
inlen
,
"link
\n
"
);
strprint
(
retv
,
inlen
,
"name
\n
"
);
strprint
(
retv
,
inlen
,
"hwaddr
\n
"
);
strprint
(
retv
,
inlen
,
"mtu
\n
"
);
strprint
(
retv
,
inlen
,
"ipv6.address
\n
"
);
strprint
(
retv
,
inlen
,
"ipv6.gateway
\n
"
);
strprint
(
retv
,
inlen
,
"ipv4.address
\n
"
);
strprint
(
retv
,
inlen
,
"ipv4.gateway
\n
"
);
}
switch
(
netdev
->
type
)
{
case
LXC_NET_VETH
:
strprint
(
retv
,
inlen
,
"veth.pair
\n
"
);
break
;
case
LXC_NET_MACVLAN
:
strprint
(
retv
,
inlen
,
"macvlan.mode
\n
"
);
break
;
case
LXC_NET_VLAN
:
strprint
(
retv
,
inlen
,
"vlan.id
\n
"
);
break
;
case
LXC_NET_PHYS
:
break
;
}
return
fulllen
;
}
static
int
set_config_net_flags
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
...
...
@@ -3734,6 +3642,66 @@ on_error:
return
NULL
;
}
int
lxc_list_net
(
struct
lxc_conf
*
c
,
const
char
*
key
,
char
*
retv
,
int
inlen
)
{
int
len
;
const
char
*
idxstring
;
struct
lxc_config_t
*
config
;
struct
lxc_netdev
*
netdev
;
int
fulllen
=
0
;
ssize_t
idx
=
-
1
;
char
*
deindexed_key
=
NULL
;
idxstring
=
key
+
8
;
if
(
!
isdigit
(
*
idxstring
))
return
-
1
;
config
=
get_network_config_ops
(
key
,
c
,
&
idx
,
&
deindexed_key
);
if
(
!
config
||
idx
<
0
)
return
-
1
;
netdev
=
lxc_get_netdev_by_idx
(
c
,
(
unsigned
int
)
idx
,
false
);
free
(
deindexed_key
);
if
(
!
netdev
)
return
-
1
;
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
strprint
(
retv
,
inlen
,
"type
\n
"
);
strprint
(
retv
,
inlen
,
"script.up
\n
"
);
strprint
(
retv
,
inlen
,
"script.down
\n
"
);
if
(
netdev
->
type
!=
LXC_NET_EMPTY
)
{
strprint
(
retv
,
inlen
,
"flags
\n
"
);
strprint
(
retv
,
inlen
,
"link
\n
"
);
strprint
(
retv
,
inlen
,
"name
\n
"
);
strprint
(
retv
,
inlen
,
"hwaddr
\n
"
);
strprint
(
retv
,
inlen
,
"mtu
\n
"
);
strprint
(
retv
,
inlen
,
"ipv6.address
\n
"
);
strprint
(
retv
,
inlen
,
"ipv6.gateway
\n
"
);
strprint
(
retv
,
inlen
,
"ipv4.address
\n
"
);
strprint
(
retv
,
inlen
,
"ipv4.gateway
\n
"
);
}
switch
(
netdev
->
type
)
{
case
LXC_NET_VETH
:
strprint
(
retv
,
inlen
,
"veth.pair
\n
"
);
break
;
case
LXC_NET_MACVLAN
:
strprint
(
retv
,
inlen
,
"macvlan.mode
\n
"
);
break
;
case
LXC_NET_VLAN
:
strprint
(
retv
,
inlen
,
"vlan.id
\n
"
);
break
;
case
LXC_NET_PHYS
:
break
;
}
return
fulllen
;
}
/*
* Config entry is something like "lxc.net.0.ipv4" the key 'lxc.net.'
* was found. So we make sure next comes an integer, find the right callback
...
...
src/lxc/confile.h
View file @
01f55c40
...
...
@@ -38,6 +38,7 @@ typedef int (*config_set_cb)(const char *, const char *, struct lxc_conf *,
typedef
int
(
*
config_get_cb
)(
const
char
*
,
char
*
,
int
,
struct
lxc_conf
*
,
void
*
);
typedef
int
(
*
config_clr_cb
)(
const
char
*
,
struct
lxc_conf
*
c
,
void
*
data
);
struct
lxc_config_t
{
char
*
name
;
config_set_cb
set
;
...
...
@@ -46,7 +47,13 @@ struct lxc_config_t {
};
extern
struct
lxc_config_t
*
lxc_getconfig
(
const
char
*
key
);
extern
int
lxc_list_nicconfigs
(
struct
lxc_conf
*
c
,
const
char
*
key
,
char
*
retv
,
int
inlen
);
/* List all configuration items associated with a given network. For example
* pass "lxc.net.[i]" to retrieve all configuration items associated with
* the network associated with index [i].
*/
extern
int
lxc_list_net
(
struct
lxc_conf
*
c
,
const
char
*
key
,
char
*
retv
,
int
inlen
);
extern
int
lxc_listconfigs
(
char
*
retv
,
int
inlen
);
extern
int
lxc_config_read
(
const
char
*
file
,
struct
lxc_conf
*
conf
,
bool
from_include
);
extern
int
append_unexp_config_line
(
const
char
*
line
,
struct
lxc_conf
*
conf
);
...
...
src/lxc/lxccontainer.c
View file @
01f55c40
...
...
@@ -2261,7 +2261,7 @@ static int do_lxcapi_get_keys(struct lxc_container *c, const char *key, char *re
return
-
1
;
int
ret
=
-
1
;
if
(
strncmp
(
key
,
"lxc.net."
,
8
)
==
0
)
ret
=
lxc_list_n
icconfigs
(
c
->
lxc_conf
,
key
,
retv
,
inlen
);
ret
=
lxc_list_n
et
(
c
->
lxc_conf
,
key
,
retv
,
inlen
);
else
if
(
strncmp
(
key
,
"lxc.network."
,
12
)
==
0
)
ret
=
lxc_list_nicconfigs_legacy
(
c
->
lxc_conf
,
key
,
retv
,
inlen
);
container_mem_unlock
(
c
);
...
...
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