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
5f4535a3
Commit
5f4535a3
authored
Oct 09, 2009
by
Daniel Lezcano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix netdev structure vs network structure
The netdev vs network structure is not well defined. Fix that. Signed-off-by:
Daniel Lezcano
<
dlezcano@fr.ibm.com
>
parent
4bf1968d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
118 deletions
+55
-118
conf.c
src/lxc/conf.c
+16
-24
conf.h
src/lxc/conf.h
+2
-15
confile.c
src/lxc/confile.c
+34
-76
start.c
src/lxc/start.c
+3
-3
No files found.
src/lxc/conf.c
View file @
5f4535a3
...
...
@@ -897,17 +897,14 @@ static int setup_netdev(struct lxc_netdev *netdev)
return
0
;
}
static
int
setup_network
(
struct
lxc_list
*
network
s
)
static
int
setup_network
(
struct
lxc_list
*
network
)
{
struct
lxc_list
*
iterator
;
struct
lxc_network
*
network
;
struct
lxc_netdev
*
netdev
;
lxc_list_for_each
(
iterator
,
network
s
)
{
lxc_list_for_each
(
iterator
,
network
)
{
network
=
iterator
->
elem
;
netdev
=
lxc_list_first_elem
(
&
network
->
netdev
);
netdev
=
iterator
->
elem
;
if
(
setup_netdev
(
netdev
))
{
ERROR
(
"failed to setup netdev"
);
...
...
@@ -915,7 +912,8 @@ static int setup_network(struct lxc_list *networks)
}
}
INFO
(
"network has been setup"
);
if
(
!
lxc_list_empty
(
network
))
INFO
(
"network has been setup"
);
return
0
;
}
...
...
@@ -953,7 +951,7 @@ int lxc_conf_init(struct lxc_conf *conf)
conf
->
pts
=
0
;
conf
->
console
[
0
]
=
'\0'
;
lxc_list_init
(
&
conf
->
cgroup
);
lxc_list_init
(
&
conf
->
network
s
);
lxc_list_init
(
&
conf
->
network
);
return
0
;
}
...
...
@@ -1109,25 +1107,22 @@ static int instanciate_empty(struct lxc_netdev *netdev)
return
0
;
}
int
lxc_create_network
(
struct
lxc_list
*
network
s
)
int
lxc_create_network
(
struct
lxc_list
*
network
)
{
struct
lxc_list
*
iterator
;
struct
lxc_network
*
network
;
struct
lxc_netdev
*
netdev
;
lxc_list_for_each
(
iterator
,
network
s
)
{
lxc_list_for_each
(
iterator
,
network
)
{
net
work
=
iterator
->
elem
;
net
dev
=
iterator
->
elem
;
if
(
net
work
->
type
<
0
||
network
->
type
>
MAXCONFTYPE
)
{
if
(
net
dev
->
type
<
0
||
netdev
->
type
>
MAXCONFTYPE
)
{
ERROR
(
"invalid network configuration type '%d'"
,
net
work
->
type
);
net
dev
->
type
);
return
-
1
;
}
netdev
=
lxc_list_first_elem
(
&
network
->
netdev
);
if
(
netdev_conf
[
network
->
type
](
netdev
))
{
if
(
netdev_conf
[
netdev
->
type
](
netdev
))
{
ERROR
(
"failed to create netdev"
);
return
-
1
;
}
...
...
@@ -1136,17 +1131,14 @@ int lxc_create_network(struct lxc_list *networks)
return
0
;
}
int
lxc_assign_network
(
struct
lxc_list
*
network
s
,
pid_t
pid
)
int
lxc_assign_network
(
struct
lxc_list
*
network
,
pid_t
pid
)
{
struct
lxc_list
*
iterator
;
struct
lxc_network
*
network
;
struct
lxc_netdev
*
netdev
;
lxc_list_for_each
(
iterator
,
networks
)
{
network
=
iterator
->
elem
;
lxc_list_for_each
(
iterator
,
network
)
{
netdev
=
lxc_list_first_elem
(
&
network
->
netdev
)
;
netdev
=
iterator
->
elem
;
if
(
lxc_device_move
(
netdev
->
ifindex
,
pid
))
{
ERROR
(
"failed to move '%s' to the container"
,
...
...
@@ -1238,7 +1230,7 @@ int lxc_setup(const char *name, struct lxc_conf *lxc_conf)
return
-
1
;
}
if
(
setup_network
(
&
lxc_conf
->
network
s
))
{
if
(
setup_network
(
&
lxc_conf
->
network
))
{
ERROR
(
"failed to setup the network for '%s'"
,
name
);
return
-
1
;
}
...
...
src/lxc/conf.h
View file @
5f4535a3
...
...
@@ -75,6 +75,7 @@ struct lxc_route6 {
* @ipv6 : a list of ipv6 addresses to be set on the network device
*/
struct
lxc_netdev
{
int
type
;
int
flags
;
int
ifindex
;
char
*
ifname
;
...
...
@@ -83,20 +84,6 @@ struct lxc_netdev {
char
*
mtu
;
struct
lxc_list
ipv4
;
struct
lxc_list
ipv6
;
struct
lxc_list
route4
;
struct
lxc_list
route6
;
};
/*
* Defines the kind of the network to use
* @type : the type of the network virtualization
* @phys : phys configuration type
* @veth : veth configuration type
* @macvlan : macvlan configuration type
*/
struct
lxc_network
{
int
type
;
struct
lxc_list
netdev
;
};
/*
...
...
@@ -149,7 +136,7 @@ struct lxc_conf {
int
pts
;
struct
utsname
*
utsname
;
struct
lxc_list
cgroup
;
struct
lxc_list
network
s
;
struct
lxc_list
network
;
struct
lxc_tty_info
tty_info
;
char
console
[
MAXPATHLEN
];
};
...
...
src/lxc/confile.c
View file @
5f4535a3
...
...
@@ -94,19 +94,9 @@ static struct config *getconfig(const char *key)
static
int
config_network_type
(
const
char
*
key
,
char
*
value
,
struct
lxc_conf
*
lxc_conf
)
{
struct
lxc_list
*
networks
=
&
lxc_conf
->
networks
;
struct
lxc_network
*
network
;
struct
lxc_list
*
network
=
&
lxc_conf
->
network
;
struct
lxc_netdev
*
netdev
;
struct
lxc_list
*
list
;
struct
lxc_list
*
ndlist
;
network
=
malloc
(
sizeof
(
*
network
));
if
(
!
network
)
{
SYSERROR
(
"failed to allocate memory"
);
return
-
1
;
}
lxc_list_init
(
&
network
->
netdev
);
netdev
=
malloc
(
sizeof
(
*
netdev
));
if
(
!
netdev
)
{
...
...
@@ -117,18 +107,6 @@ static int config_network_type(const char *key, char *value, struct lxc_conf *lx
memset
(
netdev
,
0
,
sizeof
(
*
netdev
));
lxc_list_init
(
&
netdev
->
ipv4
);
lxc_list_init
(
&
netdev
->
ipv6
);
lxc_list_init
(
&
netdev
->
route4
);
lxc_list_init
(
&
netdev
->
route6
);
ndlist
=
malloc
(
sizeof
(
*
ndlist
));
if
(
!
ndlist
)
{
SYSERROR
(
"failed to allocate memory"
);
return
-
1
;
}
ndlist
->
elem
=
netdev
;
lxc_list_add
(
&
network
->
netdev
,
ndlist
);
list
=
malloc
(
sizeof
(
*
list
));
if
(
!
list
)
{
...
...
@@ -137,18 +115,18 @@ static int config_network_type(const char *key, char *value, struct lxc_conf *lx
}
lxc_list_init
(
list
);
list
->
elem
=
net
work
;
list
->
elem
=
net
dev
;
lxc_list_add
(
network
s
,
list
);
lxc_list_add
(
network
,
list
);
if
(
!
strcmp
(
value
,
"veth"
))
net
work
->
type
=
VETH
;
net
dev
->
type
=
VETH
;
else
if
(
!
strcmp
(
value
,
"macvlan"
))
net
work
->
type
=
MACVLAN
;
net
dev
->
type
=
MACVLAN
;
else
if
(
!
strcmp
(
value
,
"phys"
))
net
work
->
type
=
PHYS
;
net
dev
->
type
=
PHYS
;
else
if
(
!
strcmp
(
value
,
"empty"
))
net
work
->
type
=
EMPTY
;
net
dev
->
type
=
EMPTY
;
else
{
ERROR
(
"invalid network type %s"
,
value
);
return
-
1
;
...
...
@@ -158,39 +136,36 @@ static int config_network_type(const char *key, char *value, struct lxc_conf *lx
static
int
config_network_flags
(
const
char
*
key
,
char
*
value
,
struct
lxc_conf
*
lxc_conf
)
{
struct
lxc_list
*
networks
=
&
lxc_conf
->
networks
;
struct
lxc_network
*
network
;
struct
lxc_list
*
network
=
&
lxc_conf
->
network
;
struct
lxc_netdev
*
netdev
;
if
(
lxc_list_empty
(
network
s
))
{
if
(
lxc_list_empty
(
network
))
{
ERROR
(
"network is not created for '%s' option"
,
value
);
return
-
1
;
}
net
work
=
lxc_list_first_elem
(
networks
);
if
(
!
net
work
)
{
net
dev
=
lxc_list_first_elem
(
network
);
if
(
!
net
dev
)
{
ERROR
(
"no network defined for '%s' option"
,
value
);
return
-
1
;
}
netdev
=
lxc_list_first_elem
(
&
network
->
netdev
);
netdev
->
flags
|=
IFF_UP
;
return
0
;
}
static
int
config_network_link
(
const
char
*
key
,
char
*
value
,
struct
lxc_conf
*
lxc_conf
)
{
struct
lxc_list
*
networks
=
&
lxc_conf
->
networks
;
struct
lxc_network
*
network
;
struct
lxc_list
*
network
=
&
lxc_conf
->
network
;
struct
lxc_netdev
*
netdev
;
if
(
lxc_list_empty
(
network
s
))
{
if
(
lxc_list_empty
(
network
))
{
ERROR
(
"network is not created for %s"
,
value
);
return
-
1
;
}
net
work
=
lxc_list_first_elem
(
networks
);
if
(
!
net
work
)
{
net
dev
=
lxc_list_first_elem
(
network
);
if
(
!
net
dev
)
{
ERROR
(
"no network defined for %s"
,
value
);
return
-
1
;
}
...
...
@@ -200,24 +175,22 @@ static int config_network_link(const char *key, char *value, struct lxc_conf *lx
return
-
1
;
}
netdev
=
lxc_list_first_elem
(
&
network
->
netdev
);
netdev
->
ifname
=
strdup
(
value
);
return
0
;
}
static
int
config_network_name
(
const
char
*
key
,
char
*
value
,
struct
lxc_conf
*
lxc_conf
)
{
struct
lxc_list
*
networks
=
&
lxc_conf
->
networks
;
struct
lxc_network
*
network
;
struct
lxc_list
*
network
=
&
lxc_conf
->
network
;
struct
lxc_netdev
*
netdev
;
if
(
lxc_list_empty
(
network
s
))
{
if
(
lxc_list_empty
(
network
))
{
ERROR
(
"network is not created for %s"
,
value
);
return
-
1
;
}
net
work
=
lxc_list_first_elem
(
networks
);
if
(
!
net
work
)
{
net
dev
=
lxc_list_first_elem
(
network
);
if
(
!
net
dev
)
{
ERROR
(
"no network defined for %s"
,
value
);
return
-
1
;
}
...
...
@@ -227,76 +200,64 @@ static int config_network_name(const char *key, char *value, struct lxc_conf *lx
return
-
1
;
}
netdev
=
lxc_list_first_elem
(
&
network
->
netdev
);
netdev
->
newname
=
strdup
(
value
);
return
0
;
}
static
int
config_network_hwaddr
(
const
char
*
key
,
char
*
value
,
struct
lxc_conf
*
lxc_conf
)
{
struct
lxc_list
*
networks
=
&
lxc_conf
->
networks
;
struct
lxc_network
*
network
;
struct
lxc_list
*
network
=
&
lxc_conf
->
network
;
struct
lxc_netdev
*
netdev
;
if
(
lxc_list_empty
(
network
s
))
{
if
(
lxc_list_empty
(
network
))
{
ERROR
(
"network is not created for %s"
,
value
);
return
-
1
;
}
net
work
=
lxc_list_first_elem
(
networks
);
if
(
!
net
work
)
{
net
dev
=
lxc_list_first_elem
(
network
);
if
(
!
net
dev
)
{
ERROR
(
"no network defined for %s"
,
value
);
return
-
1
;
}
netdev
=
lxc_list_first_elem
(
&
network
->
netdev
);
netdev
->
hwaddr
=
strdup
(
value
);
return
0
;
}
static
int
config_network_mtu
(
const
char
*
key
,
char
*
value
,
struct
lxc_conf
*
lxc_conf
)
{
struct
lxc_list
*
networks
=
&
lxc_conf
->
networks
;
struct
lxc_network
*
network
;
struct
lxc_list
*
network
=
&
lxc_conf
->
network
;
struct
lxc_netdev
*
netdev
;
if
(
lxc_list_empty
(
network
s
))
{
if
(
lxc_list_empty
(
network
))
{
ERROR
(
"network is not created for %s"
,
value
);
return
-
1
;
}
net
work
=
lxc_list_first_elem
(
networks
);
if
(
!
net
work
)
{
net
dev
=
lxc_list_first_elem
(
network
);
if
(
!
net
dev
)
{
ERROR
(
"no network defined for %s"
,
value
);
return
-
1
;
}
netdev
=
lxc_list_first_elem
(
&
network
->
netdev
);
netdev
->
mtu
=
strdup
(
value
);
return
0
;
}
static
int
config_network_ipv4
(
const
char
*
key
,
char
*
value
,
struct
lxc_conf
*
lxc_conf
)
{
struct
lxc_list
*
networks
=
&
lxc_conf
->
networks
;
struct
lxc_network
*
network
;
struct
lxc_list
*
network
=
&
lxc_conf
->
network
;
struct
lxc_inetdev
*
inetdev
;
struct
lxc_netdev
*
netdev
;
struct
lxc_list
*
list
;
char
*
cursor
,
*
slash
,
*
addr
=
NULL
,
*
bcast
=
NULL
,
*
prefix
=
NULL
;
if
(
lxc_list_empty
(
network
s
))
{
if
(
lxc_list_empty
(
network
))
{
ERROR
(
"network is not created for '%s'"
,
value
);
return
-
1
;
}
network
=
lxc_list_first_elem
(
networks
);
if
(
!
network
)
{
ERROR
(
"no network defined for '%s'"
,
value
);
return
-
1
;
}
netdev
=
lxc_list_first_elem
(
&
network
->
netdev
);
netdev
=
lxc_list_first_elem
(
network
);
if
(
!
netdev
)
{
ERROR
(
"no netdev defined for '%s'"
,
value
);
}
...
...
@@ -357,21 +318,20 @@ static int config_network_ipv4(const char *key, char *value, struct lxc_conf *lx
static
int
config_network_ipv6
(
const
char
*
key
,
char
*
value
,
struct
lxc_conf
*
lxc_conf
)
{
struct
lxc_list
*
networks
=
&
lxc_conf
->
networks
;
struct
lxc_network
*
network
;
struct
lxc_list
*
network
=
&
lxc_conf
->
network
;
struct
lxc_netdev
*
netdev
;
struct
lxc_inet6dev
*
inet6dev
;
struct
lxc_list
*
list
;
char
*
slash
;
char
*
netmask
;
if
(
lxc_list_empty
(
network
s
))
{
if
(
lxc_list_empty
(
network
))
{
ERROR
(
"network is not created for %s"
,
value
);
return
-
1
;
}
net
work
=
lxc_list_first_elem
(
networks
);
if
(
!
net
work
)
{
net
dev
=
lxc_list_first_elem
(
network
);
if
(
!
net
dev
)
{
ERROR
(
"no network defined for %s"
,
value
);
return
-
1
;
}
...
...
@@ -404,8 +364,6 @@ static int config_network_ipv6(const char *key, char *value, struct lxc_conf *lx
return
-
1
;
}
netdev
=
lxc_list_first_elem
(
&
network
->
netdev
);
lxc_list_add
(
&
netdev
->
ipv6
,
list
);
return
0
;
...
...
src/lxc/start.c
View file @
5f4535a3
...
...
@@ -425,14 +425,14 @@ int lxc_spawn(const char *name, struct lxc_handler *handler, char *const argv[])
}
clone_flags
=
CLONE_NEWUTS
|
CLONE_NEWPID
|
CLONE_NEWIPC
|
CLONE_NEWNS
;
if
(
!
lxc_list_empty
(
&
handler
->
conf
.
network
s
))
{
if
(
!
lxc_list_empty
(
&
handler
->
conf
.
network
))
{
clone_flags
|=
CLONE_NEWNET
;
/* that should be done before the clone because we will
* fill the netdev index and use them in the child
*/
if
(
lxc_create_network
(
&
handler
->
conf
.
network
s
))
{
if
(
lxc_create_network
(
&
handler
->
conf
.
network
))
{
ERROR
(
"failed to create the network"
);
goto
out_close
;
}
...
...
@@ -458,7 +458,7 @@ int lxc_spawn(const char *name, struct lxc_handler *handler, char *const argv[])
/* Create the network configuration */
if
(
clone_flags
&
CLONE_NEWNET
)
{
if
(
lxc_assign_network
(
&
handler
->
conf
.
network
s
,
handler
->
pid
))
{
if
(
lxc_assign_network
(
&
handler
->
conf
.
network
,
handler
->
pid
))
{
ERROR
(
"failed to create the configured network"
);
goto
out_abort
;
}
...
...
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