.\" Copyright (C) 2019 VirtualSquare. Project Leader: Renzo Davoli .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License, .\" as published by the Free Software Foundation, either version 2 .\" of the License, or (at your option) any later version. .\" .\" The GNU General Public License's references to "object code" .\" and "executables" are to be interpreted as the output of any .\" document formatting or typesetting system, including .\" intermediate and printed output. .\" .\" This manual is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, .\" MA 02110-1301 USA. .\" .\" generated with Ronn-NG/v0.9.1 .\" http://github.com/apjanke/ronn-ng/tree/0.9.1 .TH "LIBVDESTACK" "3" "June 2021" "VirtualSquare" .SH "NAME" vde_addstack, vde_delstack, vde_stackcmd, vde_msocket \- vde network namespace as a user library .SH "SYNOPSIS" \fB#include \fR .P \fBstruct vdestack *vde_addstack(char *\fR\fIvdenet\fR\fB, char *\fR\fIifname\fR\fB);\fR .P \fBvoid vde_delstack(struct vdestack *\fR\fIstack\fR\fB);\fR .P \fBint vde_stackcmd(struct vdestack *\fR\fIstack\fR\fB, char *\fR\fIstackcmd\fR\fB);\fR .P \fBint vde_msocket(struct vdestack *\fR\fIstack\fR\fB,int\fR \fIdomain\fR\fB, int\fR \fItype\fR\fB, int\fR \fIprotocol\fR\fB);\fR .P \fBvoid vde_default_stack(struct vdestack *\fR\fIstack\fR\fB);\fR .SH "DESCRIPTION" Libvdestack implements the idea of Internet of Threads through network namespaces\. By libvdestack a program can use one (or even several) private networking protocol stack(s), thus a program can be assigned its own IP address(es), routing etc\. .P \fBvde_addstack\fR creates a private network namespace: \fIvdenet\fR is the URL\-like specification of a vde network as described in \fBvde_plug\fR(1)\. \fIifname\fR is the name of the interface in the network namespace\. When \fIifname\fR is NULL, the default interface name is vde0\. .P \fBvde_delstack\fR destroys a vdestack when it is no longer needed\. .P \fBvde_stackcmd\fR run a command or a comma separated sequence of commands in the private network namespace\. The purpose of this function is to configure the networking parameters and options (e\.g\. IP address, routing)\. For security reasons, commands must be specified using full pathnames\. Do not use this function to start long lasting or non terminating programs, the caller waits for the termination of the command sequence\. .P \fBvde_msocket\fR has the same semantics of \fBsocket\fR(2) except that the socket is defined in the scope of the network namespace whose descriptor is the first argument\. The remaining arguments are those defined in socket(2)\. .P \fBvde_default_stack\fR defines the default stack: any successive socket(2) call will use the stack passed as parameter to vde_default_stack\. Use NULL to undefine the default stack\. .SH "RETURN VALUE" \fBvde_addstack\fR returns a struct vdestack pointer which is used as a descriptor and thus passed as an argument to the other functions of this library\. NULL is returned in case of error\. .P \fBvde_stackcmd\fR returns the exit status of the command\. If the stackcmd argument is a comma separated sequence of commands, the execution terminates upon the first command whose exit status is not zero, and the exit status of that command is returned\. Therefore when vde_stackcmd returns zero the entire sequence was successfully executed\. .P On success, \fBvde_msocket\fR returns a valid file descriptor\. \-1 is returned elseways and errno is set appropriately as .br described in socket(2)\. .SH "NOTES" Libvdestack fails if user namespaces have not been configured in the running kernel and enabled for users\. In Debian the sysctl knob \fBkernel\.unprivileged_userns_clone\fR must be set to 1\. .SH "EXAMPLE" The following excerpt of C code shows the use of libvdestack: .IP "" 4 .nf \|\.\|\.\|\. int fd; int exit_status; struct vdestack *stack = vde_addstack("vde://", NULL); if (stack == NULL) \|\.\|\.\|\. error management exit_status = vde_stackcmd(stack, "/bin/ip link set vde0 up;" "/bin/ip addr add 10\.0\.0\.1/24 dev vde0;" "/bin/ip route add default via 10\.0\.0\.254"); if (exit_status != 0) \|\.\|\.\|\. error management fd = vde_msocket(stack, AF_INET, SOCK_STREAM, 0); \|\.\|\.\|\. fd can be used in any context in which a file descriptor returned by socket(2) can\. e\.g\. bind, accept, connect, read/write, send/recv \|\.\|\.\|\. vde_delstack(stack); .fi .IP "" 0 .SH "SEE ALSO" \fBsocket\fR(2), \fBvde_plug\fR(1) .SH "BUGS" Bug reports should be addressed to \fIinfo@virtualsquare\.org\fR .SH "AUTHOR" VirtualSquare\. Project leader: Renzo Davoli\.