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
beb7ae64
Commit
beb7ae64
authored
Jun 11, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplification of the protocol; more functions implemented
parent
93dab2a9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
65 deletions
+87
-65
protocol.txt
protocol.txt
+17
-11
src/netns/protocol.py
src/netns/protocol.py
+70
-54
No files found.
protocol.txt
View file @
beb7ae64
...
...
@@ -19,12 +19,14 @@ ADDR DEL if# addr_spec 200/500 ip addr del
ROUT LIST 200 serialised data ip route list
ROUT ADD route_spec 200/500 ip route add
ROUT DEL route_spec 200/500 ip route del
PROC CRTE [args_len] 354+200/500 (2)
PROC SIN 354+200/500 (3)
PROC SOUT 354+200/500 (3)
PROC SERR 354+200/500 (3)
PROC RUN 200 <pid>/500 (4)
PROC ABRT 200 (4)
PROC CRTE proc_params 200/500 (2)
PROC CWD cwd 200/500 (3)
PROC ENV k v k v... 200/500 (3)
PROC SIN 354+200/500 (4)
PROC SOUT 354+200/500 (4)
PROC SERR 354+200/500 (4)
PROC RUN 200 <pid>/500 (5)
PROC ABRT 200 (5)
PROC POLL <pid> 200 <code>/500 check if process alive
PROC WAIT <pid> 200 <code>/500 waitpid(pid)
PROC KILL <pid> <signal> 200/500 kill(pid, signal)
...
...
@@ -32,15 +34,19 @@ PROC KILL <pid> <signal> 200/500 kill(pid, signal)
(1) valid arguments: mtu <n>, state <up|down>, name <name>, lladdr <addr>
(2) After PROC CRTE, only secondary PROC cmds are accepted until finished.
Server waits for serialized data (lenght pre-specified, or empty line to
finish) specifying complex arguments: cwd, env, argv.
After receiving the arguments, answers with 200 or 500
.
Arguments are: uid gid argv[0] argv[1] ...
The argv parameters are parsed as base64-encoded strings if they start with a
'=' character
.
(3) Secondary PROC commands, only valid after PROC CRTE. Server reply 354 and
(3) Secondary PROC commands, only valid after PROC CRTE. All parameters parsed
as base64-encoded strings. Arguments for PROC ENV are pairs of key-value to
set up the process environment.
(4) Secondary PROC commands, only valid after PROC CRTE. Server reply 354 and
waits for a file descriptor to be passed along with a duplicate of the same
command. Answers 200/500 after processing the file descriptor.
(
4
) Secondary PROC commands, unconditionally end the PROC transaction. If RUN
(
5
) Secondary PROC commands, unconditionally end the PROC transaction. If RUN
was successful, the process is started and the process ID is returned.
...
...
src/netns/protocol.py
View file @
beb7ae64
...
...
@@ -7,7 +7,7 @@ try:
except
ImportError
:
from
yaml
import
Loader
,
Dumper
import
sys
,
yaml
import
passfd
,
sys
,
yaml
# Protocol definition
#
...
...
@@ -35,7 +35,7 @@ _proto_commands = {
"DEL"
:
(
"sisi"
,
""
)
},
"PROC"
:
{
"CRTE"
:
(
"
"
,
"i
"
),
"CRTE"
:
(
"
iib"
,
"b*
"
),
"POLL"
:
(
"i"
,
""
),
"WAIT"
:
(
"i"
,
""
)
},
...
...
@@ -45,6 +45,8 @@ _proc_commands = {
"HELP"
:
{
None
:
(
""
,
""
)
},
"QUIT"
:
{
None
:
(
""
,
""
)
},
"PROC"
:
{
"CWD"
:
(
"b"
,
""
),
"ENV"
:
(
"bb"
,
"b*"
),
"SIN"
:
(
""
,
""
),
"SOUT"
:
(
""
,
""
),
"SERR"
:
(
""
,
""
),
...
...
@@ -58,6 +60,7 @@ class Server(object):
self
.
commands
=
_proto_commands
self
.
closed
=
False
self
.
debug
=
True
self
.
_proc
=
None
if
hasattr
(
fd
,
"readline"
):
self
.
f
=
fd
else
:
...
...
@@ -150,22 +153,35 @@ class Server(object):
if
len
(
args
)
<
len
(
mandatory
):
self
.
reply
(
500
,
"Missing mandatory arguments for %s."
%
cmdname
)
return
None
if
len
(
args
)
>
len
(
argstemplate
):
if
(
not
argstemplate
or
argstemplate
[
-
1
]
!=
"*"
)
and
\
len
(
args
)
>
len
(
argstemplate
):
self
.
reply
(
500
,
"Too many arguments for %s."
%
cmdname
)
return
None
j
=
0
for
i
in
range
(
len
(
args
)):
if
argstemplate
[
i
]
==
'i'
:
if
argstemplate
[
j
]
==
'*'
:
j
=
j
-
1
if
argstemplate
[
j
]
==
'i'
:
try
:
args
[
i
]
=
int
(
args
[
i
])
except
:
self
.
reply
(
500
,
"Invalid parameter %s: must be an integer."
%
args
[
i
])
return
None
elif
argstemplate
[
i
]
==
's'
:
elif
argstemplate
[
j
]
==
's'
:
pass
elif
argstemplate
[
j
]
==
'b'
:
try
:
if
args
[
i
][
0
]
==
'='
:
args
[
i
]
=
base64
.
b64decode
(
args
[
i
])
except
:
self
.
reply
(
500
,
"Invalid parameter: not base-64 encoded."
)
return
None
else
:
raise
RuntimeError
(
"Invalid argument template: %s"
%
_argstmpl
)
j
+=
1
func
=
getattr
(
self
,
funcname
)
return
(
func
,
cmdname
,
args
)
...
...
@@ -185,6 +201,16 @@ class Server(object):
pass
# FIXME: cleanup
def
do_HELP
(
self
,
cmdname
):
reply
=
[
"Available commands:"
]
for
c
in
sorted
(
self
.
commands
):
for
sc
in
sorted
(
self
.
commands
[
c
]):
if
sc
:
reply
.
append
(
"%s %s"
%
(
c
,
sc
))
else
:
reply
.
append
(
c
)
self
.
reply
(
200
,
reply
)
def
do_QUIT
(
self
,
cmdname
):
self
.
reply
(
221
,
"Sayounara."
);
self
.
closed
=
True
...
...
@@ -207,63 +233,53 @@ class Server(object):
pass
def
do_ROUT_DEL
(
self
,
cmdname
,
prefix
,
prefixlen
,
nexthop
,
ifnr
):
pass
def
do_PROC_CRTE
(
self
,
cmdname
,
argslen
=
None
):
if
argslen
:
self
.
reply
(
354
,
"Go ahead, reading %d bytes."
%
argslen
)
else
:
self
.
reply
(
354
,
"Go ahead, enter an empty line to finish."
)
argsstr
=
self
.
readchunk
(
argslen
)
if
argsstr
==
None
:
# connection closed
return
if
not
argsstr
:
self
.
reply
(
500
,
"Missing parameters."
)
return
try
:
args
=
yaml
.
load
(
argsstr
,
Loader
=
Loader
)
except
BaseException
,
e
:
self
.
reply
(
500
,
"Cannot decode parameters: %s"
%
e
)
return
def
do_PROC_CRTE
(
self
,
cmdname
,
uid
,
gid
,
file
,
*
argv
):
self
.
_proc
=
{
'uid'
:
uid
,
'gid'
:
gid
,
'file'
:
file
,
'argv'
:
argv
}
self
.
commands
=
_proc_commands
self
.
reply
(
200
,
"Entering PROC mode."
)
if
not
hasattr
(
args
,
"items"
):
self
.
reply
(
500
,
"Invalid parameters."
)
return
def
do_PROC_CWD
(
self
,
cmdname
,
dir
):
self
.
_proc
[
'cwd'
]
=
dir
self
.
reply
(
200
,
"CWD set to %s."
%
dir
)
valid_params
=
{
'cwd'
:
str
,
'exec'
:
str
,
'args'
:
list
,
'uid'
:
int
,
'gid'
:
int
}
for
(
k
,
v
)
in
args
.
items
():
try
:
args
[
k
]
=
valid_params
[
k
](
args
[
k
])
except
:
self
.
reply
(
500
,
"Invalid parameter: %s"
%
k
)
return
def
do_PROC_ENV
(
self
,
cmdname
,
*
env
):
if
len
(
env
)
%
2
:
self
.
reply
(
500
,
"Invalid number of arguments for PROC ENV: must be even."
)
return
self
.
_proc
[
'env'
]
=
{}
for
i
in
range
(
len
(
env
)
/
2
):
self
.
_proc
[
'env'
][
env
[
i
*
2
]]
=
env
[
i
*
2
+
1
]
required_params
=
[
'exec'
,
'args'
,
'uid'
,
'gid'
]
for
i
in
required_params
:
if
i
not
in
args
:
self
.
reply
(
500
,
"Missing required parameter: %s"
%
i
)
return
self
.
reply
(
200
,
"%d environment definition(s) read."
%
(
len
(
env
)
/
2
))
if
self
.
debug
:
sys
.
stderr
.
write
(
"Arguments for PROC CRTE: %s
\
n
"
%
str
(
args
))
self
.
reply
(
200
,
"Entering PROC mode."
)
def
do_PROC_SIN
(
self
,
cmdname
):
self
.
reply
(
354
,
"Pass the file descriptor now, with '%s
\
\
n' as payload."
%
cmdname
)
try
:
fd
,
payload
=
passfd
.
recvfd
(
len
(
cmdname
)
+
1
)
assert
payload
[
0
:
len
(
cmdname
)]
==
cmdname
except
:
self
.
reply
(
500
,
"Invalid FD or payload."
)
raise
return
m
=
{
'PROC SIN'
:
'stdin'
,
'PROC SOUT'
:
'stdout'
,
'PROC SERR'
:
'stderr'
}
self
.
_proc
[
m
[
cmdname
]]
=
fd
self
.
reply
(
200
,
'FD saved as %d.'
%
m
[
cmdname
])
self
.
_proc_args
=
args
self
.
commands
=
_proc_commands
do_PROC_SOUT
=
do_PROC_SERR
=
do_PROC_SIN
def
do_PROC_POLL
(
self
,
cmdname
,
pid
):
pass
def
do_PROC_WAIT
(
self
,
cmdname
,
pid
):
pass
def
do_PROC_SIN
(
self
,
cmdname
):
pass
def
do_PROC_SOUT
(
self
,
cmdname
):
pass
def
do_PROC_SERR
(
self
,
cmdname
):
pass
def
do_PROC_RUN
(
self
,
cmdname
):
self
.
reply
(
200
,
"Aborted."
)
self
.
_proc
=
None
self
.
commands
=
_proto_commands
def
do_PROC_ABRT
(
self
,
cmdname
):
self
.
reply
(
200
,
"Aborted."
)
def
do_PROC_ABRT
(
self
,
cmdname
):
self
.
_proc
=
None
self
.
commands
=
_proto_commands
self
.
reply
(
200
,
"Aborted."
)
def
do_PROC_POLL
(
self
,
cmdname
,
pid
):
pass
def
do_PROC_WAIT
(
self
,
cmdname
,
pid
):
pass
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