blob: e945c8a5d0806996509b9b0772b6c90add33c5d8 [file] [log] [blame]
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -07001/*
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
Dave Wallacee695cb42017-11-02 22:04:42 -040019#if (CLIB_DEBUG > 0)
20/* Set VCOM_DEBUG 2 for connection debug, 3 for read/write debug output */
21#define VCOM_DEBUG 1
22#else
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -070023#define VCOM_DEBUG 0
24#endif
25
Dave Wallace227867f2017-11-13 21:21:53 -050026#include <vppinfra/error.h>
27#include <vppinfra/types.h>
Dave Wallace5c7cf1c2017-10-24 04:12:18 -040028#include <vcl/vcom_glibc_socket.h>
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -070029
30#define MAX_VCOM_APP_NAME 256
31
32/* Returns 0 on success or -1 on error. */
33extern int vcom_set_app_name (char *__app_name);
34
35/*
36 *
37 * File descriptor based APIs
38 *
39 */
40
41/*
42 * vpp implementation of glibc APIs from <unistd.h>
43 */
44extern int vcom_close (int __fd);
45
46extern ssize_t __wur vcom_read (int __fd, void *__buf, size_t __nbytes);
47
48extern ssize_t __wur vcom_write (int __fd, const void *__buf, size_t __n);
49
50extern ssize_t __wur vcom_readv (int __fd, const struct iovec *__iov,
51 int __iovcnt);
52
53extern ssize_t __wur vcom_writev (int __fd, const struct iovec *__iov,
54 int __iovcnt);
55
56/*
57 * vpp implementation of glibc APIs from <fcntl.h>
58 */
59extern int vcom_fcntl (int __fd, int __cmd, ...);
60
61/*
Stevenb59f2272017-10-12 17:10:33 -070062 * VPP implementation of glibc APIs ioctl
63 */
64extern int vcom_ioctl (int __fd, unsigned long int __cmd, ...);
65
66/*
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -070067 * vpp implementation of glibc APIs from <sys/select.h>
68 */
69extern int
70vcom_select (int __nfds, fd_set * __restrict __readfds,
71 fd_set * __restrict __writefds,
72 fd_set * __restrict __exceptfds,
73 struct timeval *__restrict __timeout);
74
75#ifdef __USE_XOPEN2K
76extern int
77vcom_pselect (int __nfds, fd_set * __restrict __readfds,
78 fd_set * __restrict __writefds,
79 fd_set * __restrict __exceptfds,
80 const struct timespec *__restrict __timeout,
81 const __sigset_t * __restrict __sigmask);
82#endif
83
84/*
85 * vpp implementation of glibc APIs from <sys/socket.h>
86 */
87extern int __THROW vcom_socket (int __domain, int __type, int __protocol);
88
89/* On Linux, the only supported domain for this call is AF_UNIX
90* (or synonymously, AF_LOCAL). Most implementations have the
91* same restriction.
92* vpp does not implement AF_UNIX domain in this release.
93* */
94extern int __THROW
95vcom_socketpair (int __domain, int __type, int __protocol, int __fds[2]);
96
97extern int __THROW
98vcom_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
99
100extern int __THROW
101vcom_getsockname (int __fd, __SOCKADDR_ARG __addr,
102 socklen_t * __restrict __len);
103
104extern int
105vcom_connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
106
107extern int __THROW
108vcom_getpeername (int __fd, __SOCKADDR_ARG __addr,
109 socklen_t * __restrict __len);
110
111extern ssize_t
Dave Wallace227867f2017-11-13 21:21:53 -0500112vcom_sendfile (int __out_fd, int __in_fd, off_t * __offset, int __len);
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -0700113
114extern ssize_t vcom_recv (int __fd, void *__buf, size_t __n, int __flags);
115
116extern ssize_t
117vcom_sendto (int __fd, const void *__buf, size_t __n,
118 int __flags, __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len);
119
120extern ssize_t
121vcom_recvfrom (int __fd, void *__restrict __buf,
122 size_t __n, int __flags,
123 __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len);
124
125extern ssize_t
126vcom_sendmsg (int __fd, const struct msghdr *__message, int __flags);
127
128#ifdef __USE_GNU
129extern int
130sendmmsg (int __fd, struct mmsghdr *__vmessages,
131 unsigned int __vlen, int __flags);
132#endif
133
134extern ssize_t vcom_recvmsg (int __fd, struct msghdr *__message, int __flags);
135
136#ifdef __USE_GNU
137extern int
138vcom_recvmmsg (int __fd, struct mmsghdr *__vmessages,
139 unsigned int __vlen, int __flags, struct timespec *__tmo);
140#endif
141
142extern int __THROW
143vcom_getsockopt (int __fd, int __level, int __optname,
144 void *__restrict __optval, socklen_t * __restrict __optlen);
145
146extern int __THROW
147vcom_setsockopt (int __fd, int __level, int __optname,
148 const void *__optval, socklen_t __optlen);
149
150extern int __THROW vcom_listen (int __fd, int __n);
151
152extern int
153vcom_accept (int __fd, __SOCKADDR_ARG __addr,
154 socklen_t * __restrict __addr_len);
155
156#ifdef __USE_GNU
157/*
158 * Similar to 'accept' but takes an additional parameter to specify
159 * flags.
160 * */
161/* TBD: implemented later */
162extern int
163vcom_accept4 (int __fd, __SOCKADDR_ARG __addr,
164 socklen_t * __restrict __addr_len, int __flags);
165#endif
166
167extern int __THROW vcom_shutdown (int __fd, int __how);
168
169extern int __THROW vcom_epoll_create (int __size);
170
171extern int __THROW vcom_epoll_create1 (int __flags);
172
173extern int __THROW
174vcom_epoll_ctl (int __epfd, int __op, int __fd, struct epoll_event *__event);
175
176extern int
177vcom_epoll_wait (int __epfd, struct epoll_event *__events,
178 int __maxevents, int __timeout);
179
180extern int
181vcom_epoll_pwait (int __epfd, struct epoll_event *__events,
182 int __maxevents, int __timeout, const __sigset_t * __ss);
183
shrinivasan ganapathy1d359632017-10-15 15:46:09 -0700184/*
185 * NOTE: observed __nfds is less than 128 from kubecon strace files
186 * for the POC, it's fair to assume that nfds is less than 1024.
187 * TBD: make it thread safe and design to scale.
188 * */
189#define MAX_POLL_NFDS_DEFAULT 1024
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -0700190extern int vcom_poll (struct pollfd *__fds, nfds_t __nfds, int __timeout);
191
192#ifdef __USE_GNU
193extern int
194vcom_ppoll (struct pollfd *__fds, nfds_t __nfds,
195 const struct timespec *__timeout, const __sigset_t * __ss);
196#endif
197
198
199#endif /* included_vcom_h */
200
201/*
202 * fd.io coding-style-patch-verification: ON
203 *
204 * Local Variables:
205 * eval: (c-set-style "gnu")
206 * End:
207 */