protocol.txt 2.47 KB
Protocol format:
----------------

RFC 2821-like.

At start-up, server sends 220 code and greeting text

To close the connection and the node, client sends QUIT command, and server
replies with 221 code.

Command	Subcmd	Arguments	Response		Effect
QUIT				221			Close the netns
IF	LIST	[if#]		200 serialised data	ip link list
IF	SET	if# key val	200/500			ip link set (1)
IF	RTRN	if#		200/500			ip link set netns 1
ADDR	LIST	[if#]		200 serialised data	ip addr list
ADDR	ADD	if# addr_spec	200/500			ip addr add
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	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)

(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) specifying complex
arguments: cwd, env, argv.
After receiving the arguments, answers with 200 or 500.

(3) 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
was successful, the process is started and the process ID is returned.


Sample session
--------------

Parent calls socketpair(), fork() and unshare(); thus creating a new netns;
protocol exchanges occur through the socket.

<S> 220 Hello
<C> IF LIST
<S> 200-[{id: 1, mtu: 16436, name: lo, up: true}, {id: 10,
<S> 200     lladdr: '12:34:56:78:9a:bc', mtu: 1500, name: eth0, up: true}]
<C> IF SET 10 MTU 1492
<S> 200 Ok.
<C> ADDR ADD 10 10.0.0.1 24 10.0.0.255
<S> 200 Ok.
<C> ADDR DEL 10 192.168.1.1 24
<S> 500 Address does not exist.
<C> PROC CRTE 71
<S> 354 Go ahead.
<C> {args: [sh, -c, sleep, 10], cmd: /, exec: /bin/sh, gid: 100, uid: 100}
<S> 200 Entering PROC mode.
<C> PROC SIN
<S> 354 Waiting for FD.
 Server calls recvmsg()
 Client calls sendmsg()
<S> 200 FD received OK.
<C> PROC RUN
<S> 200 1649 pid process started.
<C> PROC WAIT 1649
 Time passes...
<S> 200 0 exit code
<C> QUIT
<S> 221 Exiting...