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
e337179a
Unverified
Commit
e337179a
authored
Jun 18, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
network: non-functional changes
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
9b0df30f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
24 deletions
+31
-24
conf.c
src/lxc/conf.c
+29
-22
conf.h
src/lxc/conf.h
+1
-1
start.c
src/lxc/start.c
+1
-1
No files found.
src/lxc/conf.c
View file @
e337179a
...
@@ -2326,7 +2326,7 @@ static int setup_ipv6_addr(struct lxc_list *ip, int ifindex)
...
@@ -2326,7 +2326,7 @@ static int setup_ipv6_addr(struct lxc_list *ip, int ifindex)
return
0
;
return
0
;
}
}
static
int
setup_netdev
(
struct
lxc_netdev
*
netdev
)
static
int
lxc_setup_netdev_in_child_namespaces
(
struct
lxc_netdev
*
netdev
)
{
{
char
ifname
[
IFNAMSIZ
];
char
ifname
[
IFNAMSIZ
];
char
*
current_ifname
=
ifname
;
char
*
current_ifname
=
ifname
;
...
@@ -2508,7 +2508,8 @@ static int setup_netdev(struct lxc_netdev *netdev)
...
@@ -2508,7 +2508,8 @@ static int setup_netdev(struct lxc_netdev *netdev)
return
0
;
return
0
;
}
}
static
int
setup_network
(
const
struct
lxc_conf
*
conf
,
struct
lxc_list
*
network
)
static
int
lxc_setup_networks_in_child_namespaces
(
const
struct
lxc_conf
*
conf
,
struct
lxc_list
*
network
)
{
{
struct
lxc_list
*
iterator
;
struct
lxc_list
*
iterator
;
struct
lxc_netdev
*
netdev
;
struct
lxc_netdev
*
netdev
;
...
@@ -2516,10 +2517,9 @@ static int setup_network(const struct lxc_conf *conf, struct lxc_list *network)
...
@@ -2516,10 +2517,9 @@ static int setup_network(const struct lxc_conf *conf, struct lxc_list *network)
lxc_log_configured_netdevs
(
conf
);
lxc_log_configured_netdevs
(
conf
);
lxc_list_for_each
(
iterator
,
network
)
{
lxc_list_for_each
(
iterator
,
network
)
{
netdev
=
iterator
->
elem
;
netdev
=
iterator
->
elem
;
if
(
setup_netdev
(
netdev
))
{
if
(
lxc_setup_netdev_in_child_namespaces
(
netdev
))
{
ERROR
(
"failed to setup netdev"
);
ERROR
(
"failed to setup netdev"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -3036,38 +3036,42 @@ int lxc_requests_empty_network(struct lxc_handler *handler)
...
@@ -3036,38 +3036,42 @@ int lxc_requests_empty_network(struct lxc_handler *handler)
return
0
;
return
0
;
}
}
int
lxc_
create_network
(
struct
lxc_handler
*
handler
)
int
lxc_
setup_networks_in_parent_namespaces
(
struct
lxc_handler
*
handler
)
{
{
struct
lxc_list
*
network
=
&
handler
->
conf
->
network
;
bool
am_root
;
struct
lxc_list
*
iterator
;
struct
lxc_netdev
*
netdev
;
struct
lxc_netdev
*
netdev
;
int
am_root
=
(
getuid
()
==
0
);
struct
lxc_list
*
iterator
;
struct
lxc_list
*
network
=
&
handler
->
conf
->
network
;
/* We need to be root. */
am_root
=
(
getuid
()
==
0
);
if
(
!
am_root
)
if
(
!
am_root
)
return
0
;
return
0
;
lxc_list_for_each
(
iterator
,
network
)
{
lxc_list_for_each
(
iterator
,
network
)
{
netdev
=
iterator
->
elem
;
netdev
=
iterator
->
elem
;
if
(
netdev
->
type
!=
LXC_NET_MACVLAN
&&
netdev
->
priv
.
macvlan_attr
.
mode
)
{
if
(
netdev
->
type
<
0
||
netdev
->
type
>
LXC_NET_MAXCONFTYPE
)
{
ERROR
(
"Invalid macvlan.mode for a non-macvlan netdev"
);
ERROR
(
"invalid network configuration type '%d'"
,
netdev
->
type
);
return
-
1
;
return
-
1
;
}
}
if
(
netdev
->
type
!=
LXC_NET_VETH
&&
netdev
->
priv
.
veth_attr
.
pair
)
{
if
(
netdev
->
type
!=
LXC_NET_MACVLAN
&&
ERROR
(
"Invalid veth pair for a non-veth netdev"
);
netdev
->
priv
.
macvlan_attr
.
mode
)
{
ERROR
(
"Invalid macvlan.mode for a non-macvlan netdev"
);
return
-
1
;
return
-
1
;
}
}
if
(
netdev
->
type
!=
LXC_NET_VLAN
&&
netdev
->
priv
.
vlan_attr
.
vid
>
0
)
{
if
(
netdev
->
type
!=
LXC_NET_VETH
&&
ERROR
(
"Invalid vlan.id for a non-macvlan netdev"
);
netdev
->
priv
.
veth_attr
.
pair
)
{
ERROR
(
"Invalid veth pair for a non-veth netdev"
);
return
-
1
;
return
-
1
;
}
}
if
(
netdev
->
type
<
0
||
netdev
->
type
>
LXC_NET_MAXCONFTYPE
)
{
if
(
netdev
->
type
!=
LXC_NET_VLAN
&&
ERROR
(
"invalid network configuration type '%d'"
,
netdev
->
priv
.
vlan_attr
.
vid
>
0
)
{
netdev
->
type
);
ERROR
(
"Invalid vlan.id for a non-macvlan netdev"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -3285,9 +3289,11 @@ int lxc_assign_network(const char *lxcpath, char *lxcname,
...
@@ -3285,9 +3289,11 @@ int lxc_assign_network(const char *lxcpath, char *lxcname,
INFO
(
"mtu ignored due to insufficient privilege"
);
INFO
(
"mtu ignored due to insufficient privilege"
);
if
(
unpriv_assign_nic
(
lxcpath
,
lxcname
,
netdev
,
pid
))
if
(
unpriv_assign_nic
(
lxcpath
,
lxcname
,
netdev
,
pid
))
return
-
1
;
return
-
1
;
// lxc-user-nic has moved the nic to the new ns.
/* lxc-user-nic has moved the nic to the new ns.
// unpriv_assign_nic() fills in netdev->name.
* unpriv_assign_nic() fills in netdev->name.
// netdev->ifindex will be filed in at setup_netdev.
* netdev->ifindex will be filed in at
* lxc_setup_netdev_in_child_namespaces.
*/
continue
;
continue
;
}
}
...
@@ -4110,7 +4116,8 @@ int lxc_setup(struct lxc_handler *handler)
...
@@ -4110,7 +4116,8 @@ int lxc_setup(struct lxc_handler *handler)
}
}
}
}
if
(
setup_network
(
lxc_conf
,
&
lxc_conf
->
network
))
{
if
(
lxc_setup_networks_in_child_namespaces
(
lxc_conf
,
&
lxc_conf
->
network
))
{
ERROR
(
"failed to setup the network for '%s'"
,
name
);
ERROR
(
"failed to setup the network for '%s'"
,
name
);
return
-
1
;
return
-
1
;
}
}
...
...
src/lxc/conf.h
View file @
e337179a
...
@@ -432,7 +432,7 @@ extern void lxc_conf_free(struct lxc_conf *conf);
...
@@ -432,7 +432,7 @@ extern void lxc_conf_free(struct lxc_conf *conf);
extern
int
pin_rootfs
(
const
char
*
rootfs
);
extern
int
pin_rootfs
(
const
char
*
rootfs
);
extern
int
lxc_requests_empty_network
(
struct
lxc_handler
*
handler
);
extern
int
lxc_requests_empty_network
(
struct
lxc_handler
*
handler
);
extern
int
lxc_
create_network
(
struct
lxc_handler
*
handler
);
extern
int
lxc_
setup_networks_in_parent_namespaces
(
struct
lxc_handler
*
handler
);
extern
bool
lxc_delete_network
(
struct
lxc_handler
*
handler
);
extern
bool
lxc_delete_network
(
struct
lxc_handler
*
handler
);
extern
int
lxc_assign_network
(
const
char
*
lxcpath
,
char
*
lxcname
,
extern
int
lxc_assign_network
(
const
char
*
lxcpath
,
char
*
lxcname
,
struct
lxc_list
*
networks
,
pid_t
pid
);
struct
lxc_list
*
networks
,
pid_t
pid
);
...
...
src/lxc/start.c
View file @
e337179a
...
@@ -1239,7 +1239,7 @@ static int lxc_spawn(struct lxc_handler *handler)
...
@@ -1239,7 +1239,7 @@ static int lxc_spawn(struct lxc_handler *handler)
/* That should be done before the clone because we will
/* That should be done before the clone because we will
* fill the netdev index and use them in the child.
* fill the netdev index and use them in the child.
*/
*/
if
(
lxc_
create_network
(
handler
))
{
if
(
lxc_
setup_networks_in_parent_namespaces
(
handler
))
{
ERROR
(
"Failed to create the network."
);
ERROR
(
"Failed to create the network."
);
lxc_sync_fini
(
handler
);
lxc_sync_fini
(
handler
);
return
-
1
;
return
-
1
;
...
...
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