LD_PRELOAD: stateless LDP

- Refactor LDP to be stateless.
- Use upper bit of fd to identify
  tag as VCL session.
- Clean up debug output.
- Add VCOM config env vars for
  app name and sid bit.
- Add VCL get/set attributes
- Add VCL poll implementation.

Change-Id: I4603ae88254c460a024fdb79fe91c6d1ef9bc7b9
Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
diff --git a/src/vcl/vcom.h b/src/vcl/vcom.h
index e945c8a..0dd86c1 100644
--- a/src/vcl/vcom.h
+++ b/src/vcl/vcom.h
@@ -18,183 +18,23 @@
 
 #if (CLIB_DEBUG > 0)
 /* Set VCOM_DEBUG 2 for connection debug, 3 for read/write debug output */
-#define VCOM_DEBUG 1
+#define VCOM_DEBUG_INIT 1
 #else
-#define VCOM_DEBUG 0
+#define VCOM_DEBUG_INIT 0
 #endif
 
 #include <vppinfra/error.h>
 #include <vppinfra/types.h>
 #include <vcl/vcom_glibc_socket.h>
 
-#define MAX_VCOM_APP_NAME  256
+#define VCOM_ENV_DEBUG     "VCOM_DEBUG"
+#define VCOM_ENV_APP_NAME  "VCOM_APP_NAME"
+#define VCOM_ENV_SID_BIT   "VCOM_SID_BIT"
 
-/* Returns 0 on success or -1 on error. */
-extern int vcom_set_app_name (char *__app_name);
+#define VCOM_SID_BIT_MIN   9
+#define VCOM_SID_BIT_MAX   30
 
-/*
- *
- * File descriptor based APIs
- *
- */
-
-/*
- * vpp implementation of glibc APIs from <unistd.h>
- */
-extern int vcom_close (int __fd);
-
-extern ssize_t __wur vcom_read (int __fd, void *__buf, size_t __nbytes);
-
-extern ssize_t __wur vcom_write (int __fd, const void *__buf, size_t __n);
-
-extern ssize_t __wur vcom_readv (int __fd, const struct iovec *__iov,
-				 int __iovcnt);
-
-extern ssize_t __wur vcom_writev (int __fd, const struct iovec *__iov,
-				  int __iovcnt);
-
-/*
- * vpp implementation of glibc APIs from <fcntl.h>
- */
-extern int vcom_fcntl (int __fd, int __cmd, ...);
-
-/*
- * VPP implementation of glibc APIs ioctl
- */
-extern int vcom_ioctl (int __fd, unsigned long int __cmd, ...);
-
-/*
- * vpp implementation of glibc APIs from <sys/select.h>
- */
-extern int
-vcom_select (int __nfds, fd_set * __restrict __readfds,
-	     fd_set * __restrict __writefds,
-	     fd_set * __restrict __exceptfds,
-	     struct timeval *__restrict __timeout);
-
-#ifdef __USE_XOPEN2K
-extern int
-vcom_pselect (int __nfds, fd_set * __restrict __readfds,
-	      fd_set * __restrict __writefds,
-	      fd_set * __restrict __exceptfds,
-	      const struct timespec *__restrict __timeout,
-	      const __sigset_t * __restrict __sigmask);
-#endif
-
-/*
- * vpp implementation of glibc APIs from <sys/socket.h>
- */
-extern int __THROW vcom_socket (int __domain, int __type, int __protocol);
-
-/* On Linux, the only supported domain for this call is AF_UNIX
-* (or synonymously, AF_LOCAL). Most implementations have the
-* same restriction.
-* vpp does not implement AF_UNIX domain in this release.
-* */
-extern int __THROW
-vcom_socketpair (int __domain, int __type, int __protocol, int __fds[2]);
-
-extern int __THROW
-vcom_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
-
-extern int __THROW
-vcom_getsockname (int __fd, __SOCKADDR_ARG __addr,
-		  socklen_t * __restrict __len);
-
-extern int
-vcom_connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
-
-extern int __THROW
-vcom_getpeername (int __fd, __SOCKADDR_ARG __addr,
-		  socklen_t * __restrict __len);
-
-extern ssize_t
-vcom_sendfile (int __out_fd, int __in_fd, off_t * __offset, int __len);
-
-extern ssize_t vcom_recv (int __fd, void *__buf, size_t __n, int __flags);
-
-extern ssize_t
-vcom_sendto (int __fd, const void *__buf, size_t __n,
-	     int __flags, __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len);
-
-extern ssize_t
-vcom_recvfrom (int __fd, void *__restrict __buf,
-	       size_t __n, int __flags,
-	       __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len);
-
-extern ssize_t
-vcom_sendmsg (int __fd, const struct msghdr *__message, int __flags);
-
-#ifdef __USE_GNU
-extern int
-sendmmsg (int __fd, struct mmsghdr *__vmessages,
-	  unsigned int __vlen, int __flags);
-#endif
-
-extern ssize_t vcom_recvmsg (int __fd, struct msghdr *__message, int __flags);
-
-#ifdef __USE_GNU
-extern int
-vcom_recvmmsg (int __fd, struct mmsghdr *__vmessages,
-	       unsigned int __vlen, int __flags, struct timespec *__tmo);
-#endif
-
-extern int __THROW
-vcom_getsockopt (int __fd, int __level, int __optname,
-		 void *__restrict __optval, socklen_t * __restrict __optlen);
-
-extern int __THROW
-vcom_setsockopt (int __fd, int __level, int __optname,
-		 const void *__optval, socklen_t __optlen);
-
-extern int __THROW vcom_listen (int __fd, int __n);
-
-extern int
-vcom_accept (int __fd, __SOCKADDR_ARG __addr,
-	     socklen_t * __restrict __addr_len);
-
-#ifdef __USE_GNU
-/*
- * Similar to 'accept' but takes an additional parameter to specify
- * flags.
- * */
-/* TBD: implemented later */
-extern int
-vcom_accept4 (int __fd, __SOCKADDR_ARG __addr,
-	      socklen_t * __restrict __addr_len, int __flags);
-#endif
-
-extern int __THROW vcom_shutdown (int __fd, int __how);
-
-extern int __THROW vcom_epoll_create (int __size);
-
-extern int __THROW vcom_epoll_create1 (int __flags);
-
-extern int __THROW
-vcom_epoll_ctl (int __epfd, int __op, int __fd, struct epoll_event *__event);
-
-extern int
-vcom_epoll_wait (int __epfd, struct epoll_event *__events,
-		 int __maxevents, int __timeout);
-
-extern int
-vcom_epoll_pwait (int __epfd, struct epoll_event *__events,
-		  int __maxevents, int __timeout, const __sigset_t * __ss);
-
-/*
- * NOTE: observed __nfds is less than 128 from kubecon strace files
- * for the POC, it's fair to assume that nfds is less than 1024.
- * TBD: make it thread safe and design to scale.
- * */
-#define MAX_POLL_NFDS_DEFAULT   1024
-extern int vcom_poll (struct pollfd *__fds, nfds_t __nfds, int __timeout);
-
-#ifdef __USE_GNU
-extern int
-vcom_ppoll (struct pollfd *__fds, nfds_t __nfds,
-	    const struct timespec *__timeout, const __sigset_t * __ss);
-#endif
-
+#define VCOM_APP_NAME_MAX  256
 
 #endif /* included_vcom_h */