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
c5abc9de
Unverified
Commit
c5abc9de
authored
Jul 26, 2019
by
Thomas Parrott
Committed by
Christian Brauner
Aug 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxccontainer: do_lxcapi_detach_interface to support detaching wlan devices
Signed-off-by:
Thomas Parrott
<
thomas.parrott@canonical.com
>
parent
a29e5dc5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
4 deletions
+31
-4
attach.c
src/lxc/attach.c
+1
-1
attach.h
src/lxc/attach.h
+2
-0
lxccontainer.c
src/lxc/lxccontainer.c
+22
-1
network.c
src/lxc/network.c
+2
-2
network.h
src/lxc/network.h
+4
-0
No files found.
src/lxc/attach.c
View file @
c5abc9de
...
@@ -213,7 +213,7 @@ static int lxc_attach_to_ns(pid_t pid, struct lxc_proc_context_info *ctx)
...
@@ -213,7 +213,7 @@ static int lxc_attach_to_ns(pid_t pid, struct lxc_proc_context_info *ctx)
return
0
;
return
0
;
}
}
static
int
lxc_attach_remount_sys_proc
(
void
)
int
lxc_attach_remount_sys_proc
(
void
)
{
{
int
ret
;
int
ret
;
...
...
src/lxc/attach.h
View file @
c5abc9de
...
@@ -45,4 +45,6 @@ extern int lxc_attach(struct lxc_container *container,
...
@@ -45,4 +45,6 @@ extern int lxc_attach(struct lxc_container *container,
lxc_attach_exec_t
exec_function
,
void
*
exec_payload
,
lxc_attach_exec_t
exec_function
,
void
*
exec_payload
,
lxc_attach_options_t
*
options
,
pid_t
*
attached_process
);
lxc_attach_options_t
*
options
,
pid_t
*
attached_process
);
extern
int
lxc_attach_remount_sys_proc
(
void
);
#endif
/* __LXC_ATTACH_H */
#endif
/* __LXC_ATTACH_H */
src/lxc/lxccontainer.c
View file @
c5abc9de
...
@@ -4752,6 +4752,7 @@ static bool do_lxcapi_detach_interface(struct lxc_container *c,
...
@@ -4752,6 +4752,7 @@ static bool do_lxcapi_detach_interface(struct lxc_container *c,
{
{
int
ret
;
int
ret
;
pid_t
pid
,
pid_outside
;
pid_t
pid
,
pid_outside
;
__do_free
char
*
physname
=
NULL
;
/*
/*
* TODO - if this is a physical device, then we need am_host_unpriv.
* TODO - if this is a physical device, then we need am_host_unpriv.
...
@@ -4787,6 +4788,19 @@ static bool do_lxcapi_detach_interface(struct lxc_container *c,
...
@@ -4787,6 +4788,19 @@ static bool do_lxcapi_detach_interface(struct lxc_container *c,
_exit
(
EXIT_FAILURE
);
_exit
(
EXIT_FAILURE
);
}
}
/* create new mount namespace for use with remounting /sys and is_wlan() below. */
ret
=
unshare
(
CLONE_NEWNS
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to unshare mount namespace"
);
_exit
(
EXIT_FAILURE
);
}
/* set / recursively as private so that mount propagation doesn't affect us. */
if
(
mount
(
NULL
,
"/"
,
NULL
,
MS_REC
|
MS_PRIVATE
,
0
)
<
0
)
{
ERROR
(
"Failed to recursively set / as private in mount namespace"
);
_exit
(
EXIT_FAILURE
);
}
ret
=
lxc_netdev_isup
(
ifname
);
ret
=
lxc_netdev_isup
(
ifname
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"Failed to determine whether network device
\"
%s
\"
is up"
,
ifname
);
ERROR
(
"Failed to determine whether network device
\"
%s
\"
is up"
,
ifname
);
...
@@ -4802,7 +4816,14 @@ static bool do_lxcapi_detach_interface(struct lxc_container *c,
...
@@ -4802,7 +4816,14 @@ static bool do_lxcapi_detach_interface(struct lxc_container *c,
}
}
}
}
ret
=
lxc_netdev_move_by_name
(
ifname
,
pid_outside
,
dst_ifname
);
/* remount /sys so is_wlan() can check if this device is a wlan device. */
lxc_attach_remount_sys_proc
();
physname
=
is_wlan
(
ifname
);
if
(
physname
)
ret
=
lxc_netdev_move_wlan
(
physname
,
ifname
,
pid_outside
,
dst_ifname
);
else
ret
=
lxc_netdev_move_by_name
(
ifname
,
pid_outside
,
dst_ifname
);
/* -EINVAL means there is no netdev named as ifname. */
/* -EINVAL means there is no netdev named as ifname. */
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
if
(
ret
==
-
EINVAL
)
if
(
ret
==
-
EINVAL
)
...
...
src/lxc/network.c
View file @
c5abc9de
...
@@ -666,7 +666,7 @@ out:
...
@@ -666,7 +666,7 @@ out:
* will be passed to lxc_netdev_move_wlan() which will free it when done.
* will be passed to lxc_netdev_move_wlan() which will free it when done.
*/
*/
#define PHYSNAME "/sys/class/net/%s/phy80211/name"
#define PHYSNAME "/sys/class/net/%s/phy80211/name"
static
char
*
is_wlan
(
const
char
*
ifname
)
char
*
is_wlan
(
const
char
*
ifname
)
{
{
__do_free
char
*
path
=
NULL
;
__do_free
char
*
path
=
NULL
;
int
i
,
ret
;
int
i
,
ret
;
...
@@ -739,7 +739,7 @@ static int lxc_netdev_rename_by_name_in_netns(pid_t pid, const char *old,
...
@@ -739,7 +739,7 @@ static int lxc_netdev_rename_by_name_in_netns(pid_t pid, const char *old,
_exit
(
lxc_netdev_rename_by_name
(
old
,
new
));
_exit
(
lxc_netdev_rename_by_name
(
old
,
new
));
}
}
static
int
lxc_netdev_move_wlan
(
char
*
physname
,
const
char
*
ifname
,
pid_t
pid
,
int
lxc_netdev_move_wlan
(
char
*
physname
,
const
char
*
ifname
,
pid_t
pid
,
const
char
*
newname
)
const
char
*
newname
)
{
{
char
*
cmd
;
char
*
cmd
;
...
...
src/lxc/network.h
View file @
c5abc9de
...
@@ -277,4 +277,8 @@ extern int lxc_network_recv_name_and_ifindex_from_child(struct lxc_handler *hand
...
@@ -277,4 +277,8 @@ extern int lxc_network_recv_name_and_ifindex_from_child(struct lxc_handler *hand
extern
int
lxc_netns_set_nsid
(
int
netns_fd
);
extern
int
lxc_netns_set_nsid
(
int
netns_fd
);
extern
int
lxc_netns_get_nsid
(
__s32
fd
);
extern
int
lxc_netns_get_nsid
(
__s32
fd
);
extern
char
*
is_wlan
(
const
char
*
ifname
);
extern
int
lxc_netdev_move_wlan
(
char
*
physname
,
const
char
*
ifname
,
pid_t
pid
,
const
char
*
newname
);
#endif
/* __LXC_NETWORK_H */
#endif
/* __LXC_NETWORK_H */
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