Keith Burns (alagalah) | b327c2b | 2017-10-09 08:52:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #ifndef included_vcom_h |
| 17 | #define included_vcom_h |
| 18 | |
| 19 | /* VCOM DEBUG flag. Setting this to 1 or 0 turns off |
| 20 | ASSERT & other debugging code. */ |
| 21 | #ifndef VCOM_DEBUG |
| 22 | #define VCOM_DEBUG 0 |
| 23 | #endif |
| 24 | |
Dave Wallace | 5c7cf1c | 2017-10-24 04:12:18 -0400 | [diff] [blame] | 25 | #include <vcl/vcom_glibc_socket.h> |
Keith Burns (alagalah) | b327c2b | 2017-10-09 08:52:59 -0700 | [diff] [blame] | 26 | |
| 27 | #define MAX_VCOM_APP_NAME 256 |
| 28 | |
| 29 | /* Returns 0 on success or -1 on error. */ |
| 30 | extern int vcom_set_app_name (char *__app_name); |
| 31 | |
| 32 | /* |
| 33 | * |
| 34 | * File descriptor based APIs |
| 35 | * |
| 36 | */ |
| 37 | |
| 38 | /* |
| 39 | * vpp implementation of glibc APIs from <unistd.h> |
| 40 | */ |
| 41 | extern int vcom_close (int __fd); |
| 42 | |
| 43 | extern ssize_t __wur vcom_read (int __fd, void *__buf, size_t __nbytes); |
| 44 | |
| 45 | extern ssize_t __wur vcom_write (int __fd, const void *__buf, size_t __n); |
| 46 | |
| 47 | extern ssize_t __wur vcom_readv (int __fd, const struct iovec *__iov, |
| 48 | int __iovcnt); |
| 49 | |
| 50 | extern ssize_t __wur vcom_writev (int __fd, const struct iovec *__iov, |
| 51 | int __iovcnt); |
| 52 | |
| 53 | /* |
| 54 | * vpp implementation of glibc APIs from <fcntl.h> |
| 55 | */ |
| 56 | extern int vcom_fcntl (int __fd, int __cmd, ...); |
| 57 | |
| 58 | /* |
Steven | b59f227 | 2017-10-12 17:10:33 -0700 | [diff] [blame] | 59 | * VPP implementation of glibc APIs ioctl |
| 60 | */ |
| 61 | extern int vcom_ioctl (int __fd, unsigned long int __cmd, ...); |
| 62 | |
| 63 | /* |
Keith Burns (alagalah) | b327c2b | 2017-10-09 08:52:59 -0700 | [diff] [blame] | 64 | * vpp implementation of glibc APIs from <sys/select.h> |
| 65 | */ |
| 66 | extern int |
| 67 | vcom_select (int __nfds, fd_set * __restrict __readfds, |
| 68 | fd_set * __restrict __writefds, |
| 69 | fd_set * __restrict __exceptfds, |
| 70 | struct timeval *__restrict __timeout); |
| 71 | |
| 72 | #ifdef __USE_XOPEN2K |
| 73 | extern int |
| 74 | vcom_pselect (int __nfds, fd_set * __restrict __readfds, |
| 75 | fd_set * __restrict __writefds, |
| 76 | fd_set * __restrict __exceptfds, |
| 77 | const struct timespec *__restrict __timeout, |
| 78 | const __sigset_t * __restrict __sigmask); |
| 79 | #endif |
| 80 | |
| 81 | /* |
| 82 | * vpp implementation of glibc APIs from <sys/socket.h> |
| 83 | */ |
| 84 | extern int __THROW vcom_socket (int __domain, int __type, int __protocol); |
| 85 | |
| 86 | /* On Linux, the only supported domain for this call is AF_UNIX |
| 87 | * (or synonymously, AF_LOCAL). Most implementations have the |
| 88 | * same restriction. |
| 89 | * vpp does not implement AF_UNIX domain in this release. |
| 90 | * */ |
| 91 | extern int __THROW |
| 92 | vcom_socketpair (int __domain, int __type, int __protocol, int __fds[2]); |
| 93 | |
| 94 | extern int __THROW |
| 95 | vcom_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len); |
| 96 | |
| 97 | extern int __THROW |
| 98 | vcom_getsockname (int __fd, __SOCKADDR_ARG __addr, |
| 99 | socklen_t * __restrict __len); |
| 100 | |
| 101 | extern int |
| 102 | vcom_connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len); |
| 103 | |
| 104 | extern int __THROW |
| 105 | vcom_getpeername (int __fd, __SOCKADDR_ARG __addr, |
| 106 | socklen_t * __restrict __len); |
| 107 | |
| 108 | extern ssize_t |
| 109 | vcom_send (int __fd, const void *__buf, size_t __n, int __flags); |
| 110 | |
| 111 | extern ssize_t vcom_recv (int __fd, void *__buf, size_t __n, int __flags); |
| 112 | |
| 113 | extern ssize_t |
| 114 | vcom_sendto (int __fd, const void *__buf, size_t __n, |
| 115 | int __flags, __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len); |
| 116 | |
| 117 | extern ssize_t |
| 118 | vcom_recvfrom (int __fd, void *__restrict __buf, |
| 119 | size_t __n, int __flags, |
| 120 | __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len); |
| 121 | |
| 122 | extern ssize_t |
| 123 | vcom_sendmsg (int __fd, const struct msghdr *__message, int __flags); |
| 124 | |
| 125 | #ifdef __USE_GNU |
| 126 | extern int |
| 127 | sendmmsg (int __fd, struct mmsghdr *__vmessages, |
| 128 | unsigned int __vlen, int __flags); |
| 129 | #endif |
| 130 | |
| 131 | extern ssize_t vcom_recvmsg (int __fd, struct msghdr *__message, int __flags); |
| 132 | |
| 133 | #ifdef __USE_GNU |
| 134 | extern int |
| 135 | vcom_recvmmsg (int __fd, struct mmsghdr *__vmessages, |
| 136 | unsigned int __vlen, int __flags, struct timespec *__tmo); |
| 137 | #endif |
| 138 | |
| 139 | extern int __THROW |
| 140 | vcom_getsockopt (int __fd, int __level, int __optname, |
| 141 | void *__restrict __optval, socklen_t * __restrict __optlen); |
| 142 | |
| 143 | extern int __THROW |
| 144 | vcom_setsockopt (int __fd, int __level, int __optname, |
| 145 | const void *__optval, socklen_t __optlen); |
| 146 | |
| 147 | extern int __THROW vcom_listen (int __fd, int __n); |
| 148 | |
| 149 | extern int |
| 150 | vcom_accept (int __fd, __SOCKADDR_ARG __addr, |
| 151 | socklen_t * __restrict __addr_len); |
| 152 | |
| 153 | #ifdef __USE_GNU |
| 154 | /* |
| 155 | * Similar to 'accept' but takes an additional parameter to specify |
| 156 | * flags. |
| 157 | * */ |
| 158 | /* TBD: implemented later */ |
| 159 | extern int |
| 160 | vcom_accept4 (int __fd, __SOCKADDR_ARG __addr, |
| 161 | socklen_t * __restrict __addr_len, int __flags); |
| 162 | #endif |
| 163 | |
| 164 | extern int __THROW vcom_shutdown (int __fd, int __how); |
| 165 | |
| 166 | extern int __THROW vcom_epoll_create (int __size); |
| 167 | |
| 168 | extern int __THROW vcom_epoll_create1 (int __flags); |
| 169 | |
| 170 | extern int __THROW |
| 171 | vcom_epoll_ctl (int __epfd, int __op, int __fd, struct epoll_event *__event); |
| 172 | |
| 173 | extern int |
| 174 | vcom_epoll_wait (int __epfd, struct epoll_event *__events, |
| 175 | int __maxevents, int __timeout); |
| 176 | |
| 177 | extern int |
| 178 | vcom_epoll_pwait (int __epfd, struct epoll_event *__events, |
| 179 | int __maxevents, int __timeout, const __sigset_t * __ss); |
| 180 | |
shrinivasan ganapathy | 1d35963 | 2017-10-15 15:46:09 -0700 | [diff] [blame] | 181 | /* |
| 182 | * NOTE: observed __nfds is less than 128 from kubecon strace files |
| 183 | * for the POC, it's fair to assume that nfds is less than 1024. |
| 184 | * TBD: make it thread safe and design to scale. |
| 185 | * */ |
| 186 | #define MAX_POLL_NFDS_DEFAULT 1024 |
Keith Burns (alagalah) | b327c2b | 2017-10-09 08:52:59 -0700 | [diff] [blame] | 187 | extern int vcom_poll (struct pollfd *__fds, nfds_t __nfds, int __timeout); |
| 188 | |
| 189 | #ifdef __USE_GNU |
| 190 | extern int |
| 191 | vcom_ppoll (struct pollfd *__fds, nfds_t __nfds, |
| 192 | const struct timespec *__timeout, const __sigset_t * __ss); |
| 193 | #endif |
| 194 | |
| 195 | |
| 196 | #endif /* included_vcom_h */ |
| 197 | |
| 198 | /* |
| 199 | * fd.io coding-style-patch-verification: ON |
| 200 | * |
| 201 | * Local Variables: |
| 202 | * eval: (c-set-style "gnu") |
| 203 | * End: |
| 204 | */ |