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
5ea9a3ef
Commit
5ea9a3ef
authored
Jul 02, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Node class: Keep track of processes, make unshare optional.
parent
8b0eca1e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
11 deletions
+13
-11
src/netns/node.py
src/netns/node.py
+13
-11
No files found.
src/netns/node.py
View file @
5ea9a3ef
...
...
@@ -12,16 +12,17 @@ class Node(object):
s
=
sorted
(
Node
.
_nodes
.
items
(),
key
=
lambda
x
:
x
[
0
])
return
[
x
[
1
]
for
x
in
s
]
def
__init__
(
self
,
debug
=
False
):
def
__init__
(
self
,
debug
=
False
,
nonetns
=
False
):
"""Create a new node in the emulation. Implemented as a separate
process in a new network name space. Requires root privileges to run.
If keepns is true, the network name space is not created and can be run
as a normal user, for testing. If debug is true, details of the
communication protocol are printed on stderr."""
fd
,
pid
=
_start_child
(
debug
)
fd
,
pid
=
_start_child
(
debug
,
nonetns
)
self
.
_pid
=
pid
self
.
_slave
=
netns
.
protocol
.
Client
(
fd
,
debug
)
self
.
_processes
=
weakref
.
WeakValueDictionary
()
Node
.
_nodes
[
Node
.
_nextnode
]
=
self
Node
.
_nextnode
+=
1
...
...
@@ -29,10 +30,15 @@ class Node(object):
self
.
shutdown
()
def
shutdown
(
self
):
self
.
_slave
.
shutdown
()
for
p
in
self
.
_processes
:
p
.
destroy
()
del
self
.
_processes
del
self
.
_pid
self
.
_slave
.
shutdown
()
del
self
.
_slave
def
_add_subprocess
(
self
,
subprocess
):
self
.
_processes
[
subprocess
.
pid
]
=
subprocess
@
property
def
pid
(
self
):
return
self
.
_pid
...
...
@@ -43,7 +49,7 @@ class Node(object):
def
add_default_route
(
self
,
nexthop
,
interface
=
None
):
return
self
.
add_route
(
'0.0.0.0'
,
0
,
nexthop
,
interface
)
def
start_process
(
self
,
args
):
return
Process
(
)
return
netns
.
subprocess
.
start_process
(
node
,
args
)
def
run_process
(
self
,
args
):
return
(
""
,
""
)
def
get_routes
(
self
):
...
...
@@ -60,15 +66,10 @@ class Interface(object):
def
add_v6_address
(
self
,
address
,
prefix_len
):
pass
class
Process
(
object
):
def
__init__
(
self
):
self
.
pid
=
os
.
getpid
()
self
.
valid
=
True
# Handle the creation of the child; parent gets (fd, pid), child creates and
# runs a Server(); never returns.
# Requires CAP_SYS_ADMIN privileges to run.
def
_start_child
(
debug
=
False
):
def
_start_child
(
debug
,
nonetns
):
# Create socket pair to communicate
(
s0
,
s1
)
=
socket
.
socketpair
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
,
0
)
# Spawn a child that will run in a loop
...
...
@@ -81,7 +82,8 @@ def _start_child(debug = False):
try
:
s0
.
close
()
srv
=
netns
.
protocol
.
Server
(
s1
,
debug
)
unshare
.
unshare
(
unshare
.
CLONE_NEWNET
)
if
not
nonetns
:
unshare
.
unshare
(
unshare
.
CLONE_NEWNET
)
srv
.
run
()
except
BaseException
,
e
:
s
=
"Slave node aborting: %s
\
n
"
%
str
(
e
)
...
...
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