Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nemu3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
nemu3
Commits
564e6000
Commit
564e6000
authored
Jul 29, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for migrating pre-existing interfaces into netns's. Fix destroy() issues.
parent
98faabfc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
21 deletions
+53
-21
src/netns/interface.py
src/netns/interface.py
+53
-21
No files found.
src/netns/interface.py
View file @
564e6000
...
...
@@ -4,7 +4,7 @@ import os
import
netns.iproute
__all__
=
[
'NodeInterface'
,
'P2PInterface'
,
'ForeignInterface'
,
'ForeignNodeInterface'
,
'Link'
]
'ForeignNodeInterface'
,
'
ImportedNodeInterface'
,
'
Link'
]
class
Interface
(
object
):
"""Just a base class for the *Interface classes: assign names and handle
...
...
@@ -119,12 +119,10 @@ class NodeInterface(NSInterface):
return
self
.
_control
def
destroy
(
self
):
try
:
if
self
.
_slave
:
if
self
.
index
in
self
.
_slave
.
get_if_data
():
self
.
_slave
.
del_if
(
self
.
index
)
except
:
# Maybe it already went away, or the slave died. Anyway, better
# ignore the error
pass
self
.
_slave
=
None
class
P2PInterface
(
NSInterface
):
"""Class to create and handle point-to-point interfaces between name
...
...
@@ -160,10 +158,10 @@ class P2PInterface(NSInterface):
raise
RuntimeError
(
P2PInterface
.
__init__
.
__doc__
)
def
destroy
(
self
):
try
:
if
self
.
_slave
:
if
self
.
index
in
self
.
_slave
.
get_if_data
():
self
.
_slave
.
del_if
(
self
.
index
)
except
:
pass
self
.
_slave
=
None
class
ForeignNodeInterface
(
NSInterface
):
"""Class to handle already existing interfaces inside a name space, usually
...
...
@@ -172,15 +170,39 @@ class ForeignNodeInterface(NSInterface):
in before being imported into netns."""
def
__init__
(
self
,
node
,
iface
):
iface
=
node
.
_slave
.
get_if_data
(
iface
)
self
.
_original_state
=
iface
self
.
_original_state
=
iface
.
copy
()
super
(
ForeignNodeInterface
,
self
).
__init__
(
node
,
iface
.
index
)
# FIXME: register somewhere for destruction!
def
destroy
(
self
):
# override: restore as much as possible
try
:
if
self
.
_slave
:
if
self
.
index
in
self
.
_slave
.
get_if_data
():
self
.
_slave
.
set_if
(
self
.
_original_state
)
except
:
pass
self
.
_slave
=
None
class
ImportedNodeInterface
(
NSInterface
):
"""Class to handle already existing interfaces that are migrated inside a
name space: real devices, tun devices, etc. On destruction, the interface
will be restored to the original name space and will try to restore the
original state."""
def
__init__
(
self
,
node
,
iface
):
iface
=
netns
.
iproute
.
get_if
(
iface
)
self
.
_original_state
=
iface
.
copy
()
# Change the name to avoid clashes
iface
.
name
=
self
.
_gen_if_name
()
netns
.
iproute
.
set_if
(
iface
)
netns
.
iproute
.
change_netns
(
iface
,
node
.
pid
)
super
(
ImportedNodeInterface
,
self
).
__init__
(
node
,
iface
.
index
)
def
destroy
(
self
):
# override: restore as much as possible
if
self
.
_slave
:
if
self
.
index
in
self
.
_slave
.
get_if_data
():
self
.
_slave
.
change_netns
(
self
.
index
,
os
.
getpid
())
# else, assume it is in the main name space
netns
.
iproute
.
set_if
(
self
.
_original_state
)
self
.
_slave
=
None
class
ExternalInterface
(
Interface
):
"""Add user-facing methods for interfaces that run in the main namespace."""
...
...
@@ -248,15 +270,15 @@ class ForeignInterface(ExternalInterface):
was in before being imported into netns."""
def
__init__
(
self
,
iface
):
iface
=
netns
.
iproute
.
get_if
(
iface
)
self
.
_original_state
=
iface
self
.
_original_state
=
iface
.
copy
()
super
(
ForeignInterface
,
self
).
__init__
(
iface
.
index
)
# FIXME: register somewhere for destruction!
def
destroy
(
self
):
# override: restore as much as possible
try
:
if
self
.
_slave
:
if
self
.
index
in
self
.
_slave
.
get_if_data
():
netns
.
iproute
.
set_if
(
self
.
_original_state
)
except
:
pass
self
.
_slave
=
None
# Link is just another interface type
...
...
@@ -267,6 +289,16 @@ class Link(ExternalInterface):
# Max 15 chars
return
"NETNSbr-%.4x%.3x"
%
(
os
.
getpid
(),
n
)
bandwidth
=
property
(
lambda
s
:
getattr
(
s
,
'_bandwidth'
))
delay
=
property
(
lambda
s
:
getattr
(
s
,
'_delay'
))
delay_jitter
=
property
(
lambda
s
:
getattr
(
s
,
'_delay_jitter'
))
delay_correlation
=
property
(
lambda
s
:
getattr
(
s
,
'_delay_correlation'
))
delay_distribution
=
property
(
lambda
s
:
getattr
(
s
,
'_delay_distribution'
))
loss
=
property
(
lambda
s
:
getattr
(
s
,
'_loss'
))
loss_correlation
=
property
(
lambda
s
:
getattr
(
s
,
'_loss_correlation'
))
dup
=
property
(
lambda
s
:
getattr
(
s
,
'_dup'
))
dup_correlation
=
property
(
lambda
s
:
getattr
(
s
,
'_dup_correlation'
))
def
__init__
(
self
,
bandwidth
=
None
,
delay
=
None
,
delay_jitter
=
None
,
delay_correlation
=
None
,
delay_distribution
=
None
,
loss
=
None
,
loss_correlation
=
None
,
dup
=
None
,
dup_correlation
=
None
,
...
...
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