logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

ioth_newstack, ioth_newstackl, ioth_newstackv, ioth_delstack, ioth_msocket, ioth_set_defstack,

Author

       VirtualSquare.  Project leader: Renzo Davoli

VirtualSquare                                     January 2024                                           IOTH(3)

Description

libioth  is  the  API  for  the  Internet  of Threads.  TCP-IP networking stacks can be loaded as dynamic
       libraries at run time.

       • the API is minimal: Berkeley Sockets + msocket + newstack/delstack.

       • the stack implementation can be chosen as a plugin at run time.

       • netlink based stack/interface/ip configuration via nlinline.

       • ioth sockets are real file descriptors, poll/select/ppoll/pselect/epoll friendly

       • plug-ins can be loaded in private address namespaces: libioth supports several stacks of the same  type
         (same plugin) even if the stack implementation library was designed to provide just one stack.

       libioth provides the following functions:

       ioth_newstackioth_newstack  creates  a  new stack without any interface if vnl is NULL, otherwise the new stack
              has a virtual interface connected to the vde  network  identified  by  the  VNL  (Virtual  Network
              Locator, see vde_open(3) ).

       ioth_newstackl, ioth_newstackv
              ioth_newstacklandioth_newstackv`  (l  = list, v = vector) support the creation of a new stack with
              several interfaces.  It is possible to provide  the  VNLs  as  a  sequence  of  arguments  (as  in
              execl(3)) or as a NULL terminated array of VNLs (as the arguments in execv(3)).

       ioth_delstack
              This function terminates/deletes a stack.

       ioth_msocket
              This  is  the  multi-stack supporting extension of socket(2).  It behaves exactly as socket except
              for the added heading argument that allows the choice of the stack among those currently available
              (previously created by a ioth_newstack*).

       ioth_set_defstack, ioth_get_defstack
              These functions define and retrieve  the  default  stack,  respectively.   The  default  stack  is
              implicitly  used  by ioth_msocket when its first argument iothstack is NULL.  The default stack is
              initially defined as the native stack provided by the kernel.  Use  ioth_set_defstack(mystack)  to
              define  mystack as the current default stack.  ioth_set_defstack(NULL) to revert the default stack
              to the native stack.

       ioth_socketioth_socket opens a socket using  the  default  stack:  ioth_socket(d,t,p)  is  an  alias  for
              ioth_msocket(NULL,d,t,p)ioth_close, ioth_bind, ioth_connect, ioth_listen, ioth_accept, ioth_getsockname, ioth_getpeername,
       ioth_setsockopt, ioth_getsockopt, ioth_shutdown, ioth_ioctl, ioth_fcntl, ioth_read, ioth_readv,
       ioth_recv, ioth_recvfrom, ioth_recvmsg, ioth_write, ioth_writev, ioth_send, ioth_sendto, ioth_sendmsg
              these  functions  have  the same signature and functionalities of their counterpart in (2) and (3)
              without the ioth_ prefix.

       ioth_if_nametoindex, ioth_linksetupdown, ioth_ipaddr_add, ioth_ipaddr_del, ioth_iproute_add,
       ioth_iproute_del, ioth_iplink_add, ioth_iplink_del, ioth_linksetaddr, ioth_linkgetaddr
              these functions have the same signature and functionnalities described in nlinline(3).

Name

       ioth_newstack,    ioth_newstackl,   ioth_newstackv,   ioth_delstack,   ioth_msocket,   ioth_set_defstack,
       ioth_get_defstack,  ioth_socket,   ioth_close,   ioth_bind,   ioth_connect,   ioth_listen,   ioth_accept,
       ioth_getsockname,   ioth_getpeername,   ioth_setsockopt,   ioth_getsockopt,   ioth_shutdown,  ioth_ioctl,
       ioth_fcntl, ioth_read,  ioth_readv,  ioth_recv,  ioth_recvfrom,  ioth_recvmsg,  ioth_write,  ioth_writev,
       ioth_send,    ioth_sendto   ioth_sendmsg,   ioth_if_nametoindex,   ioth_linksetupdown,   ioth_ipaddr_add,
       ioth_ipaddr_del, ioth_iproute_add, ioth_iproute_del, ioth_iplink_add, ioth_iplink_del,  ioth_linksetaddr,
       ioth_linkgetaddr - Internet of Threads (IoTh) library

Return Value

ioth_newstack, ioth_newstackl, ioth_newstackv return a structstack pointer, NULL in case of error.  This
       address is used as a descriptor of  the  newly  created  stack  and  is  later  passed  as  parameter  to
       ioth_msocket, ioth_set_defstack or ioth_delstack.

       ioth_msocket and ioth_socket return the file descriptor of the new socket, -1 in case of errore.

       ioth_delstack  returns  -1  in case of error, 0 otherwise.  If there are file descriptors already in use,
       this function fails and errno is EBUSY.

       ioth_get_defstack returns the stack descriptor of the default stack.

       The return values of all the other functions are defined in the man pages of the corresponding  functions
       provided by the GNU C library or nlinline(3)

See Also

vde_plug(1), vdeplug_open(3), nlinline(3)

Synopsis

#include<ioth.h>structioth*ioth_newstack(constchar*stack,constchar*vnl);structioth*ioth_newstackl(constchar*stack,constchar*vnl,...);structioth*ioth_newstackv(constchar*stack,constchar*vnlv[]);intioth_delstack(structioth*iothstack);intioth_msocket(structioth*iothstack,intdomain,inttype,intprotocol);voidioth_set_defstack(structioth*iothstack);structioth*ioth_get_defstack(void);intioth_socket(intdomain,inttype,intprotocol);

       • Berkeley Sockets API

       intioth_close(intfd);intioth_bind(intsockfd,conststructsockaddr*addr,socklen_taddrlen);intioth_connect(intsockfd,conststructsockaddr*addr,socklen_taddrlen);intioth_listen(intsockfd,intbacklog);intioth_accept(intsockfd,structsockaddr*restrictaddr,socklen_t*restrictaddrlen);intioth_getsockname(intsockfd,structsockaddr*restrictaddr,socklen_t*restrictaddrlen);intioth_getpeername(intsockfd,structsockaddr*restrictaddr,socklen_t*restrictaddrlen);intioth_getsockopt(intsockfd,intlevel,intoptname,void*restrictoptval,socklen_t*restrictoptlen);intioth_setsockopt(intsockfd,intlevel,intoptname,constvoid*optval,socklen_toptlen);intioth_shutdown(intsockfd,inthow);intioth_ioctl(intfd,unsignedlongrequest,...);intioth_fcntl(intfd,intcmd,.../*arg*/);ssize_tioth_read(intfd,void*buf,size_tcount);ssize_tioth_readv(intfd,conststructiovec*iov,intiovcnt);ssize_tioth_recv(intsockfd,void*buf,size_tlen,intflags);ssize_tioth_recvfrom(intsockfd,void*restrictbuf,size_tlen,intflags,structsockaddr*restrictsrc_addr,socklen_t*restrictaddrlen);ssize_tioth_recvmsg(intsockfd,structmsghdr*msg,intflags);ssize_tioth_write(intfd,constvoid*buf,size_tcount);ssize_tioth_writev(intfd,conststructiovec*iov,intiovcnt);ssize_tioth_send(intsockfd,constvoid*buf,size_tlen,intflags);ssize_tioth_sendto(intsockfd,constvoid*buf,size_tlen,intflags,conststructsockaddr*dest_addr,socklen_taddrlen);ssize_tioth_sendmsg(intsockfd,conststructmsghdr*msg,intflags);

       • nlinline+ API

       intioth_if_nametoindex(constchar*ifname);intioth_linksetupdown(unsignedintifindex,intupdown);intioth_ipaddr_add(intfamily,void*addr,intprefixlen,unsignedintifindex);intioth_ipaddr_del(intfamily,void*addr,intprefixlen,unsignedintifindex);intioth_iproute_add(intfamily,void*dst_addr,intdst_prefixlen,void*gw_addr,unsignedintifindex);intioth_iproute_del(intfamily,void*dst_addr,intdst_prefixlen,void*gw_addr,unsignedintifindex);intioth_iplink_add(constchar*ifname,unsignedintifindex,constchar*type,constchar*data);intioth_iplink_del(constchar*ifname,unsignedintifindex`);

       intioth_linksetaddr(unsignedintifindex,void*macaddr`);

       intioth_linkgetaddr(unsignedintifindex,void*macaddr`);

See Also