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
e2f2d86a
Unverified
Commit
e2f2d86a
authored
May 15, 2019
by
Christian Brauner
Committed by
GitHub
May 15, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3005 from tomponline/tp-phys-ns-restore
network: move phys netdevs back to monitor's net ns rather than pid 1's
parents
8f06ff54
0037ab49
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
2 deletions
+46
-2
macro.h
src/lxc/macro.h
+4
-0
network.c
src/lxc/network.c
+42
-2
No files found.
src/lxc/macro.h
View file @
e2f2d86a
...
...
@@ -261,6 +261,10 @@ extern int __build_bug_on_failed;
#define IFLA_NET_NS_PID 19
#endif
#ifndef IFLA_NET_NS_FD
#define IFLA_NET_NS_FD 28
#endif
#ifndef IFLA_INFO_KIND
#define IFLA_INFO_KIND 1
#endif
...
...
src/lxc/network.c
View file @
e2f2d86a
...
...
@@ -883,6 +883,46 @@ static instantiate_cb netdev_deconf[LXC_NET_MAXCONFTYPE + 1] = {
[
LXC_NET_NONE
]
=
shutdown_none
,
};
static
int
lxc_netdev_move_by_index_fd
(
int
ifindex
,
int
fd
,
const
char
*
ifname
)
{
int
err
;
struct
nl_handler
nlh
;
struct
ifinfomsg
*
ifi
;
struct
nlmsg
*
nlmsg
=
NULL
;
err
=
netlink_open
(
&
nlh
,
NETLINK_ROUTE
);
if
(
err
)
return
err
;
err
=
-
ENOMEM
;
nlmsg
=
nlmsg_alloc
(
NLMSG_GOOD_SIZE
);
if
(
!
nlmsg
)
goto
out
;
nlmsg
->
nlmsghdr
->
nlmsg_flags
=
NLM_F_REQUEST
|
NLM_F_ACK
;
nlmsg
->
nlmsghdr
->
nlmsg_type
=
RTM_NEWLINK
;
ifi
=
nlmsg_reserve
(
nlmsg
,
sizeof
(
struct
ifinfomsg
));
if
(
!
ifi
)
goto
out
;
ifi
->
ifi_family
=
AF_UNSPEC
;
ifi
->
ifi_index
=
ifindex
;
if
(
nla_put_u32
(
nlmsg
,
IFLA_NET_NS_FD
,
fd
))
goto
out
;
if
(
ifname
!=
NULL
)
{
if
(
nla_put_string
(
nlmsg
,
IFLA_IFNAME
,
ifname
))
goto
out
;
}
err
=
netlink_transaction
(
&
nlh
,
nlmsg
,
nlmsg
);
out:
netlink_close
(
&
nlh
);
nlmsg_free
(
nlmsg
);
return
err
;
}
int
lxc_netdev_move_by_index
(
int
ifindex
,
pid_t
pid
,
const
char
*
ifname
)
{
int
err
;
...
...
@@ -3306,7 +3346,7 @@ int lxc_restore_phys_nics_to_netns(struct lxc_handler *handler)
TRACE
(
"Moving physical network devices back to parent network namespace"
);
oldfd
=
lxc_preserve_ns
(
lxc_raw_getpid
()
,
"net"
);
oldfd
=
lxc_preserve_ns
(
handler
->
monitor_pid
,
"net"
);
if
(
oldfd
<
0
)
{
SYSERROR
(
"Failed to preserve network namespace"
);
return
-
1
;
...
...
@@ -3334,7 +3374,7 @@ int lxc_restore_phys_nics_to_netns(struct lxc_handler *handler)
continue
;
}
ret
=
lxc_netdev_move_by_
name
(
ifname
,
1
,
netdev
->
link
);
ret
=
lxc_netdev_move_by_
index_fd
(
netdev
->
ifindex
,
oldfd
,
netdev
->
link
);
if
(
ret
<
0
)
WARN
(
"Error moving network device
\"
%s
\"
back to "
"network namespace"
,
ifname
);
...
...
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