xref: /netbsd-src/lib/librumpclient/rumpclient.3 (revision 2b38e53a5804d11e64002e7d4c769aed3fa2436f)
1*2b38e53aSwiz.\"     $NetBSD: rumpclient.3,v 1.3 2013/03/08 08:30:44 wiz Exp $
22e866e76Spooka.\"
32e866e76Spooka.\" Copyright (c) 2011 Antti Kantee.  All rights reserved.
42e866e76Spooka.\"
52e866e76Spooka.\" Redistribution and use in source and binary forms, with or without
62e866e76Spooka.\" modification, are permitted provided that the following conditions
72e866e76Spooka.\" are met:
82e866e76Spooka.\" 1. Redistributions of source code must retain the above copyright
92e866e76Spooka.\"    notice, this list of conditions and the following disclaimer.
102e866e76Spooka.\" 2. Redistributions in binary form must reproduce the above copyright
112e866e76Spooka.\"    notice, this list of conditions and the following disclaimer in the
122e866e76Spooka.\"    documentation and/or other materials provided with the distribution.
132e866e76Spooka.\"
142e866e76Spooka.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
152e866e76Spooka.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
162e866e76Spooka.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
172e866e76Spooka.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
182e866e76Spooka.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
192e866e76Spooka.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
202e866e76Spooka.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
212e866e76Spooka.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
222e866e76Spooka.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
232e866e76Spooka.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
242e866e76Spooka.\" SUCH DAMAGE.
252e866e76Spooka.\"
262e866e76Spooka.Dd February 16, 2011
272e866e76Spooka.Dt RUMPCLIENT 3
282e866e76Spooka.Os
292e866e76Spooka.Sh NAME
302e866e76Spooka.Nm rumpclient
312e866e76Spooka.Nd rump client library
322e866e76Spooka.Sh LIBRARY
33*2b38e53aSwiz.Lb rumpclient
342e866e76Spooka.Sh SYNOPSIS
352e866e76Spooka.In rump/rumpclient.h
362e866e76Spooka.In rump/rump_syscalls.h
372e866e76Spooka.Ft int
382e866e76Spooka.Fn rumpclient_init
392e866e76Spooka.Ft pid_t
402e866e76Spooka.Fn rumpclient_fork
412e866e76Spooka.Ft pid_t
422e866e76Spooka.Fn rumpclient_vfork
432e866e76Spooka.Ft struct rumpclient_fork *
442e866e76Spooka.Fn rumpclient_prefork
452e866e76Spooka.Ft int
462e866e76Spooka.Fn rumpclient_fork_init "struct rumpclient_fork *rfp"
472e866e76Spooka.Ft void
482e866e76Spooka.Fn rumpclient_fork_cancel "struct rumpclient_fork *rfp"
492e866e76Spooka.Ft int
502e866e76Spooka.Fn rumpclient_exec "const char *path" "char *const argv[]" "char *const envp[]"
512e866e76Spooka.Ft int
522e866e76Spooka.Fn rumpclient_daemon "int nochdir" "int noclose"
532e866e76Spooka.Ft void
542e866e76Spooka.Fn rumpclient_setconnretry "time_t retrytime"
552e866e76Spooka.Ft int
562e866e76Spooka.Fo rumpclient_syscall
572e866e76Spooka.Fa "int num" "const void *sysarg" "size_t argsize" "register_t *retval"
582e866e76Spooka.Fc
592e866e76Spooka.Sh DESCRIPTION
602e866e76Spooka.Nm
612e866e76Spookais the clientside implementation of the
622e866e76Spooka.Xr rump_sp 7
632e866e76Spookafacility.
642e866e76SpookaIt can be used to connect to a rump kernel server and make system call
652e866e76Spookastyle requests.
662e866e76Spooka.Pp
672e866e76SpookaEvery connection to a rump kernel server creates a new process
682e866e76Spookacontext in the rump kernel.
692e866e76SpookaBy default a process is inherited from init, but through existing
702e866e76Spookaconnections and the forking facility offered by
712e866e76Spooka.Nm
722e866e76Spookait is possible to form process trees.
732e866e76Spooka.Bl -tag -width xxxx
742e866e76Spooka.It Fn rumpclient_init
752e866e76SpookaInitialize
762e866e76Spooka.Nm .
772e866e76SpookaThe server address is determined from the environment variable
78cd90032dSwiz.Ev RUMP_SERVER
792e866e76Spookaaccording to syntax described in
802e866e76Spooka.Xr rump_sp 7 .
812e866e76SpookaThe new process is registered to the rump kernel with the command
822e866e76Spookaname from
832e866e76Spooka.Xr getprogname 3 .
842e866e76Spooka.It Fn rumpclient_fork
852e866e76SpookaFork a rump client process.
862e866e76SpookaThis also causes a host process fork via
872e866e76Spooka.Xr fork 2 .
882e866e76SpookaThe child will have a copy of the parent's rump kernel file descriptors.
892e866e76Spooka.It Fn rumpclient_vfork
902e866e76SpookaLike above, but the host uses
912e866e76Spooka.Xr vfork 2 .
922e866e76Spooka.It Fn rumpclient_prefork
932e866e76SpookaLow-level routine which instructs the rump kernel that the current
942e866e76Spookaprocess is planning to fork.
95cd90032dSwizThe routine returns a
96cd90032dSwiz.Pf non- Dv NULL
97cd90032dSwizcookie if successful.
982e866e76Spooka.It Fn rumpclient_fork_init rfp
992e866e76SpookaLow-level routine which works like
1002e866e76Spooka.Fn rumpclient_init ,
1012e866e76Spookawith the exception that it uses the
1022e866e76Spooka.Ar rfp
1032e866e76Spookacontext created by a call to
104cd90032dSwiz.Fn rumpclient_prefork .
1052e866e76SpookaThis is typically called from the child of a
1062e866e76Spooka.Xr fork 2
1072e866e76Spookacall.
1082e866e76Spooka.It Fn rumpclient_fork_cancel rfp
1092e866e76SpookaCancel previously initiated prefork context.
1102e866e76SpookaThis is useful for error handling in case a full fork could not
1112e866e76Spookabe carried through.
1122e866e76Spooka.It Fn rumpclient_exec path argv envp
1132e866e76SpookaThis call is a
1142e866e76Spooka.Nm
1152e866e76Spookawrapper around
1162e866e76Spooka.Xr execve 2 .
1172e866e76SpookaThe wrapper makes sure that the rump kernel process context stays
1182e866e76Spookathe same in the newly executed program.
1192e866e76SpookaThis means that the rump kernel PID remains the same and the same
1202e866e76Spookarump file descriptors are available (apart from ones which
1212e866e76Spookawere marked with
1222e866e76Spooka.Dv FD_CLOEXEC ) .
1232e866e76Spooka.Pp
1242e866e76SpookaIt should be noted that the newly executed program must call
1252e866e76Spooka.Fn rumpclient_init
1262e866e76Spookabefore any other rump kernel communication can take place.
1272e866e76SpookaThe wrapper cannot do it because it no longer has program control.
1282e866e76SpookaHowever, since all rump clients call the init routine,
1292e866e76Spookathis should not be a problem.
1302e866e76Spooka.It Fn rumpclient_daemon noclose nochdir
1312e866e76SpookaThis function performs the equivalent of
1322e866e76Spooka.Xr daemon 3 ,
1332e866e76Spookabut also ensures that the internal call to
1342e866e76Spooka.Xr fork 2
1352e866e76Spookais handled properly.
1362e866e76SpookaThis routine is provided for convenience.
1372e866e76Spooka.It Fn rumpclient_setconnretry retrytime
1382e866e76SpookaSet the timeout for how long the client attempts to reconnect to
1392e866e76Spookathe server in case of a broken connection.
1402e866e76SpookaAfter the timeout expires the client will return a failure
1412e866e76Spookafor that particular request.
1422e866e76SpookaIt is critical to note that after a restablished connection the
1432e866e76Spookarump kernel context will be that of a newly connected client.
1442e866e76SpookaThis means all previous kernel state such as file descriptors
1452e866e76Spookawill be lost.
1462e866e76SpookaIt is largely up to a particular application if this has impact
1472e866e76Spookaor not.
1482e866e76SpookaFor example, web browsers tend to recover fairly smoothly from a
1492e866e76Spookakernel server reconnect, while
1502e866e76Spooka.Xr sshd 8
1512e866e76Spookagets confused if its sockets go missing.
1522e866e76Spooka.Pp
1532e866e76SpookaIf
1542e866e76Spooka.Ar retrytime
1552e866e76Spookais a positive integer, it means the number of seconds for which
1562e866e76Spookareconnection will be attempted.
1572e866e76SpookaThe value 0 means that reconnection will not be attempted, and all
1582e866e76Spookasubsequent operations will return the errno
159cd90032dSwiz.Er ENOTCONN .
1602e866e76Spooka.Pp
1612e866e76SpookaAdditionally, the following special values are accepted:
1622e866e76Spooka.Bl -tag -width xxxx
1632e866e76Spooka.It Dv RUMPCLIENT_RETRYCONN_INFTIME
1642e866e76SpookaAttempt reconnection indefinitely.
1652e866e76Spooka.It Dv RUMPCLIENT_RETRYCONN_ONCE
1662e866e76SpookaAttempt reconnect exactly once.
1672e866e76SpookaWhat this precisely means depends on the situation: e.g. getting
168cd90032dSwiz.Er EHOSTUNREACH
1692e866e76Spookaimmediately or the TCP connection request timeouting are considered
1702e866e76Spookato be one retry.
1712e866e76Spooka.It Dv RUMPCLIENT_RETRYCONN_DIE
1722e866e76SpookaIn case of a broken connection is detected at runtime, call
1732e866e76Spooka.Xr exit 3 .
1742e866e76SpookaThis is useful for example in testing.
1752e866e76SpookaIt ensures that clients are killed immediately when they attempt
1762e866e76Spookato communicate with a halted server.
1772e866e76Spooka.El
1782e866e76Spooka.It Fn rumpclient_syscall num sysarg argsize retval
1792e866e76SpookaExecute an "indirect" system call.
1802e866e76SpookaIn the normal case system calls are executed through the interfaces in
1812e866e76Spooka.In rump/rump_syscalls.h
1822e866e76Spooka(for example
1832e866e76Spooka.Fn rump_sys_read fd buf nbytes ) .
1842e866e76SpookaThis interface allows calling the server with pre-marshalled arguments.
1852e866e76Spooka.El
1862e866e76Spooka.Pp
1872e866e76SpookaAdditionally, all of the supported rump system calls are available
1882e866e76Spookathrough this library.
1892e866e76SpookaSee
1902e866e76Spooka.In rump/rump_syscalls.h
1912e866e76Spookafor a list.
1922e866e76Spooka.Sh RETURN VALUES
1932e866e76Spooka.Nm
1942e866e76Spookaroutines return \-1 in case of error and set errno.
1952e866e76SpookaIn case of success a non-negative integer is returned, where applicable.
1962e866e76Spooka.Sh SEE ALSO
1972e866e76Spooka.Xr rump_server 1 ,
1982e866e76Spooka.Xr rump 3 ,
1992e866e76Spooka.Xr rump_sp 7
2002e866e76Spooka.Sh CAVEATS
2012e866e76SpookaInterfaces for a cryptographically authenticated client-server
2022e866e76Spookahandshake do not currently exist.
2032e866e76SpookaThis can be worked around with e.g. host access control and an ssh
2042e866e76Spookatunnel.
205