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
f5c0d3f2
Unverified
Commit
f5c0d3f2
authored
Aug 24, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
conf: refactor network deletion
I'm ashamed at how aweful my previous code was. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
581c75e7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
53 deletions
+57
-53
conf.c
src/lxc/conf.c
+57
-53
No files found.
src/lxc/conf.c
View file @
f5c0d3f2
...
@@ -3187,92 +3187,96 @@ int lxc_setup_networks_in_parent_namespaces(struct lxc_handler *handler)
...
@@ -3187,92 +3187,96 @@ int lxc_setup_networks_in_parent_namespaces(struct lxc_handler *handler)
bool
lxc_delete_network
(
struct
lxc_handler
*
handler
)
bool
lxc_delete_network
(
struct
lxc_handler
*
handler
)
{
{
int
ret
;
int
ret
;
struct
lxc_list
*
network
=
&
handler
->
conf
->
network
;
struct
lxc_list
*
iterator
;
struct
lxc_list
*
iterator
;
struct
lxc_
netdev
*
netdev
;
struct
lxc_
list
*
network
=
&
handler
->
conf
->
network
;
bool
deleted_all
=
true
;
bool
deleted_all
=
true
;
lxc_list_for_each
(
iterator
,
network
)
{
lxc_list_for_each
(
iterator
,
network
)
{
netdev
=
iterator
->
elem
;
char
*
hostveth
=
NULL
;
struct
lxc_netdev
*
netdev
=
iterator
->
elem
;
if
(
netdev
->
ifindex
!=
0
&&
netdev
->
type
==
LXC_NET_PHYS
)
{
/* We can only delete devices whose ifindex we have. If we don't
if
(
lxc_netdev_rename_by_index
(
netdev
->
ifindex
,
netdev
->
link
))
* have the index it means that we didn't create it.
*/
if
(
!
netdev
->
ifindex
)
continue
;
if
(
netdev
->
type
==
LXC_NET_PHYS
)
{
ret
=
lxc_netdev_rename_by_index
(
netdev
->
ifindex
,
netdev
->
link
);
if
(
ret
<
0
)
WARN
(
"Failed to rename interface with index %d "
WARN
(
"Failed to rename interface with index %d "
"to its initial name
\"
%s
\"
."
,
"to its initial name
\"
%s
\"
"
,
netdev
->
ifindex
,
netdev
->
link
);
else
TRACE
(
"Renamed interface with index %d to its "
"initial name
\"
%s
\"
"
,
netdev
->
ifindex
,
netdev
->
link
);
netdev
->
ifindex
,
netdev
->
link
);
continue
;
continue
;
}
}
if
(
netdev_deconf
[
netdev
->
type
](
handler
,
netdev
))
{
ret
=
netdev_deconf
[
netdev
->
type
](
handler
,
netdev
);
WARN
(
"Failed to destroy netdev"
);
if
(
ret
<
0
)
}
WARN
(
"Failed to deconfigure network device"
);
/* Recent kernel remove the virtual interfaces when the network
/* Recent kernel remove the virtual interfaces when the network
* namespace is destroyed but in case we did not move the
* namespace is destroyed but in case we did not move the
* interface to the network namespace, we have to destroy it
* interface to the network namespace, we have to destroy it
*/
*/
if
(
netdev
->
ifindex
!=
0
)
{
ret
=
lxc_netdev_delete_by_index
(
netdev
->
ifindex
);
ret
=
lxc_netdev_delete_by_index
(
netdev
->
ifindex
);
if
(
-
ret
==
ENODEV
)
{
if
(
-
ret
==
ENODEV
)
{
INFO
(
"Interface
\"
%s
\"
with index %d already "
INFO
(
"Interface
\"
%s
\"
with index %d already deleted "
"deleted or existing in different network "
"or existing in different network namespace"
,
"namespace."
,
netdev
->
name
?
netdev
->
name
:
"(null)"
,
netdev
->
ifindex
);
netdev
->
name
?
netdev
->
name
:
"(null)"
,
netdev
->
ifindex
);
}
else
if
(
ret
<
0
)
{
}
else
if
(
ret
<
0
)
{
deleted_all
=
false
;
deleted_all
=
false
;
WARN
(
"Failed to remove interface
\"
%s
\"
with "
WARN
(
"Failed to remove interface
\"
%s
\"
with index %d: "
"index %d: %s."
,
"%s"
,
netdev
->
name
?
netdev
->
name
:
"(null)"
,
netdev
->
name
?
netdev
->
name
:
"(null)"
,
netdev
->
ifindex
,
strerror
(
-
ret
));
netdev
->
ifindex
,
strerror
(
-
ret
));
}
else
{
continue
;
INFO
(
"Removed interface
\"
%s
\"
with index %d."
,
netdev
->
name
?
netdev
->
name
:
"(null)"
,
netdev
->
ifindex
);
}
}
}
INFO
(
"Removed interface
\"
%s
\"
with index %d"
,
netdev
->
name
?
netdev
->
name
:
"(null)"
,
netdev
->
ifindex
);
if
(
netdev
->
type
!=
LXC_NET_VETH
)
continue
;
if
(
am_unpriv
())
continue
;
/* Explicitly delete host veth device to prevent lingering
/* Explicitly delete host veth device to prevent lingering
* devices. We had issues in LXD around this.
* devices. We had issues in LXD around this.
*/
*/
if
(
netdev
->
ifindex
!=
0
&&
netdev
->
type
==
LXC_NET_VETH
&&
!
am_unpriv
())
{
if
(
netdev
->
priv
.
veth_attr
.
pair
)
char
*
hostveth
;
if
(
netdev
->
priv
.
veth_attr
.
pair
)
{
hostveth
=
netdev
->
priv
.
veth_attr
.
pair
;
hostveth
=
netdev
->
priv
.
veth_attr
.
pair
;
else
hostveth
=
netdev
->
priv
.
veth_attr
.
veth1
;
if
(
*
hostveth
==
'\0'
)
continue
;
ret
=
lxc_netdev_delete_by_name
(
hostveth
);
ret
=
lxc_netdev_delete_by_name
(
hostveth
);
if
(
ret
<
0
)
if
(
ret
<
0
)
{
WARN
(
"Failed to remove interface
\"
%s
\"
from host: %s."
,
hostveth
,
strerror
(
-
ret
));
deleted_all
=
false
;
else
WARN
(
"Failed to remove interface
\"
%s
\"
from
\"
%s
\"
: %s"
,
INFO
(
"Removed interface
\"
%s
\"
from host."
,
hostveth
);
hostveth
,
netdev
->
link
,
strerror
(
-
ret
));
continue
;
}
INFO
(
"Removed interface
\"
%s
\"
from
\"
%s
\"
"
,
hostveth
,
netdev
->
link
);
if
(
!
is_ovs_bridge
(
netdev
->
link
))
{
netdev
->
priv
.
veth_attr
.
veth1
[
0
]
=
'\0'
;
continue
;
}
if
(
is_ovs_bridge
(
netdev
->
link
))
{
/* Delete the openvswitch port. */
ret
=
lxc_ovs_delete_port
(
netdev
->
link
,
hostveth
);
ret
=
lxc_ovs_delete_port
(
netdev
->
link
,
hostveth
);
if
(
ret
<
0
)
if
(
ret
<
0
)
WARN
(
"Failed to remove port
\"
%s
\"
from openvswitch bridge
\"
%s
\"
"
,
hostveth
,
netdev
->
link
);
WARN
(
"Failed to remove port
\"
%s
\"
from openvswitch "
"bridge
\"
%s
\"
"
,
hostveth
,
netdev
->
link
);
else
else
INFO
(
"Removed port
\"
%s
\"
from openvswitch bridge
\"
%s
\"
"
,
hostveth
,
netdev
->
link
);
INFO
(
"Removed port
\"
%s
\"
from openvswitch bridge
\"
%s
\"
"
,
}
hostveth
,
netdev
->
link
);
}
else
if
(
strlen
(
netdev
->
priv
.
veth_attr
.
veth1
)
>
0
)
{
hostveth
=
netdev
->
priv
.
veth_attr
.
veth1
;
ret
=
lxc_netdev_delete_by_name
(
hostveth
);
if
(
ret
<
0
)
{
WARN
(
"Failed to remove
\"
%s
\"
from host: %s."
,
hostveth
,
strerror
(
-
ret
));
}
else
{
INFO
(
"Removed interface
\"
%s
\"
from host."
,
hostveth
);
if
(
is_ovs_bridge
(
netdev
->
link
))
{
netdev
->
priv
.
veth_attr
.
veth1
[
0
]
=
'\0'
;
ret
=
lxc_ovs_delete_port
(
netdev
->
link
,
hostveth
);
if
(
ret
<
0
)
{
WARN
(
"Failed to remove port
\"
%s
\"
from openvswitch bridge
\"
%s
\"
"
,
hostveth
,
netdev
->
link
);
}
else
{
INFO
(
"Removed port
\"
%s
\"
from openvswitch bridge
\"
%s
\"
"
,
hostveth
,
netdev
->
link
);
memset
((
void
*
)
&
netdev
->
priv
.
veth_attr
.
veth1
,
0
,
sizeof
(
netdev
->
priv
.
veth_attr
.
veth1
));
}
}
}
}
}
}
}
return
deleted_all
;
return
deleted_all
;
...
...
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