blob: bf1b0e3f17c302aab9c00ab5ba35d6a9bfaa5004 [file] [log] [blame]
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -07001/*
Florin Corasc5df8c72019-04-08 07:42:30 -07002 * Copyright (c) 2017-2019 Cisco and/or its affiliates.
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -07003 * 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/*
17 * Copyright (c) 2005-2008 Jelmer Vernooij <jelmer@samba.org>
18 * Copyright (C) 2006-2014 Stefan Metzmacher <metze@samba.org>
19 * Copyright (C) 2013-2014 Andreas Schneider <asn@samba.org>
20 *
21 * All rights reserved.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 *
30 * 2. Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in the
32 * documentation and/or other materials provided with the distribution.
33 *
34 * 3. Neither the name of the author nor the names of its contributors
35 * may be used to endorse or promote products derived from this software
36 * without specific prior written permission.
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
39 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
42 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
44 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 *
50 */
51
52/*
53 Socket wrapper library. Passes all socket communication over
54 unix domain sockets if the environment variable SOCKET_WRAPPER_DIR
55 is set.
56*/
57
Dave Wallace2a865272018-02-07 21:00:42 -050058#ifndef included_ldp_socket_wrapper_h
59#define included_ldp_socket_wrapper_h
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -070060
61#include <sys/types.h>
62#include <sys/socket.h>
63#include <sys/ioctl.h>
64#include <sys/select.h>
65#include <sys/epoll.h>
shrinivasan ganapathy1d359632017-10-15 15:46:09 -070066#include <poll.h>
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -070067#include <sys/uio.h>
68#include <stdlib.h>
Dave Wallace2a865272018-02-07 21:00:42 -050069#include <vcl/ldp.h>
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -070070
71
72/* GCC have printf type attribute check. */
73#ifdef HAVE_FUNCTION_ATTRIBUTE_FORMAT
74#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
75#else
76#define PRINTF_ATTRIBUTE(a,b)
77#endif /* HAVE_FUNCTION_ATTRIBUTE_FORMAT */
78
79#define HAVE_CONSTRUCTOR_ATTRIBUTE
80#ifdef HAVE_CONSTRUCTOR_ATTRIBUTE
81#define CONSTRUCTOR_ATTRIBUTE __attribute__ ((constructor))
82#else
83#define CONSTRUCTOR_ATTRIBUTE
84#endif /* HAVE_CONSTRUCTOR_ATTRIBUTE */
85
86#define HAVE_DESTRUCTOR_ATTRIBUTE
87#ifdef HAVE_DESTRUCTOR_ATTRIBUTE
88#define DESTRUCTOR_ATTRIBUTE __attribute__ ((destructor))
89#else
90#define DESTRUCTOR_ATTRIBUTE
91#endif
92
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -070093/*
94 * IMPORTANT
95 *
96 * Functions especially from libc need to be loaded individually, you can't load
97 * all at once or gdb will segfault at startup. The same applies to valgrind and
98 * has probably something todo with with the linker.
99 * So we need load each function at the point it is called the first time.
100 */
Florin Coras36847942023-02-02 12:56:16 -0800101int libc_accept4 (int sockfd, __SOCKADDR_ARG addr, socklen_t *addrlen,
Dave Wallace59179392017-11-07 02:20:07 -0500102 int flags);
103
Florin Coras36847942023-02-02 12:56:16 -0800104int libc_accept (int sockfd, __SOCKADDR_ARG addr, socklen_t *addrlen);
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -0700105
Florin Coras36847942023-02-02 12:56:16 -0800106int libc_bind (int sockfd, __CONST_SOCKADDR_ARG addr, socklen_t addrlen);
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -0700107
108int libc_close (int fd);
109
Florin Coras36847942023-02-02 12:56:16 -0800110int libc_connect (int sockfd, __CONST_SOCKADDR_ARG addr, socklen_t addrlen);
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -0700111
112#if 0
113/* TBD: dup and dup2 to be implemented later */
114int libc_dup (int fd);
115
116int libc_dup2 (int oldfd, int newfd);
117#endif
118
119#ifdef HAVE_EVENTFD
120int libc_eventfd (int count, int flags);
121#endif
122
Benoît Ganne9fb6d402019-04-15 15:28:21 +0200123int libc_vfcntl (int fd, int cmd, va_list ap);
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -0700124
Florin Coras0ab36f52020-05-26 19:45:45 +0000125#ifdef HAVE_FCNTL64
Benoît Ganne9fb6d402019-04-15 15:28:21 +0200126int libc_vfcntl64 (int fd, int cmd, va_list ap);
Florin Coras0ab36f52020-05-26 19:45:45 +0000127#endif
Carl Smithe16707b2019-11-13 14:37:39 +1300128
Benoît Ganne9fb6d402019-04-15 15:28:21 +0200129int libc_vioctl (int fd, int cmd, va_list ap);
Stevenb59f2272017-10-12 17:10:33 -0700130
Florin Coras36847942023-02-02 12:56:16 -0800131int libc_getpeername (int sockfd, __SOCKADDR_ARG addr, socklen_t *addrlen);
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -0700132
Florin Coras36847942023-02-02 12:56:16 -0800133int libc_getsockname (int sockfd, __SOCKADDR_ARG addr, socklen_t *addrlen);
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -0700134
135int
136libc_getsockopt (int sockfd,
137 int level, int optname, void *optval, socklen_t * optlen);
138
139int libc_listen (int sockfd, int backlog);
140
141int libc_read (int fd, void *buf, size_t count);
142
143ssize_t libc_readv (int fd, const struct iovec *iov, int iovcnt);
144
145int libc_recv (int sockfd, void *buf, size_t len, int flags);
146
Florin Coras36847942023-02-02 12:56:16 -0800147int libc_recvfrom (int sockfd, void *buf, size_t len, int flags,
148 __SOCKADDR_ARG src_addr, socklen_t *addrlen);
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -0700149
150int libc_recvmsg (int sockfd, struct msghdr *msg, int flags);
151
Florin Coras36847942023-02-02 12:56:16 -0800152#ifdef _GNU_SOURCE
153int libc_recvmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen,
154 int flags, struct timespec *tmo);
155#endif
156
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -0700157int libc_send (int sockfd, const void *buf, size_t len, int flags);
158
Dave Wallace227867f2017-11-13 21:21:53 -0500159ssize_t libc_sendfile (int out_fd, int in_fd, off_t * offset, size_t len);
160
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -0700161int libc_sendmsg (int sockfd, const struct msghdr *msg, int flags);
162
Florin Coras36847942023-02-02 12:56:16 -0800163#ifdef _GNU_SOURCE
164int libc_sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen,
165 int flags);
166#endif
167
168int libc_sendto (int sockfd, const void *buf, size_t len, int flags,
169 __CONST_SOCKADDR_ARG dst_addr, socklen_t addrlen);
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -0700170
171int
172libc_setsockopt (int sockfd,
173 int level, int optname, const void *optval,
174 socklen_t optlen);
175
176int libc_socket (int domain, int type, int protocol);
177
178int libc_socketpair (int domain, int type, int protocol, int sv[2]);
179
180ssize_t libc_write (int fd, const void *buf, size_t count);
181
182ssize_t libc_writev (int fd, const struct iovec *iov, int iovcnt);
183
184int libc_shutdown (int fd, int how);
185
186int
187libc_select (int __nfds, fd_set * __restrict __readfds,
188 fd_set * __restrict __writefds,
189 fd_set * __restrict __exceptfds,
190 struct timeval *__restrict __timeout);
191
192#ifdef __USE_XOPEN2K
193int
194libc_pselect (int __nfds, fd_set * __restrict __readfds,
195 fd_set * __restrict __writefds,
196 fd_set * __restrict __exceptfds,
197 const struct timespec *__restrict __timeout,
198 const __sigset_t * __restrict __sigmask);
199#endif
200
201int libc_epoll_create (int __size);
202
203int libc_epoll_create1 (int __flags);
204
205int libc_epoll_ctl (int __epfd, int __op, int __fd,
206 struct epoll_event *__event);
207
208int libc_epoll_wait (int __epfd, struct epoll_event *__events,
209 int __maxevents, int __timeout);
210
211int libc_epoll_pwait (int __epfd, struct epoll_event *__events,
212 int __maxevents, int __timeout,
213 const __sigset_t * __ss);
214
shrinivasan ganapathy1d359632017-10-15 15:46:09 -0700215int libc_poll (struct pollfd *__fds, nfds_t __nfds, int __timeout);
216
Florin Coras36847942023-02-02 12:56:16 -0800217#ifdef _GNU_SOURCE
shrinivasan ganapathy1d359632017-10-15 15:46:09 -0700218int libc_ppoll (struct pollfd *__fds, nfds_t __nfds,
219 const struct timespec *__timeout, const __sigset_t * __ss);
220#endif
221
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -0700222void swrap_constructor (void);
223
224void swrap_destructor (void);
225
Dave Wallace2a865272018-02-07 21:00:42 -0500226#endif /* included_ldp_socket_wrapper_h */
Keith Burns (alagalah)b327c2b2017-10-09 08:52:59 -0700227
228/*
229 * fd.io coding-style-patch-verification: ON
230 *
231 * Local Variables:
232 * eval: (c-set-style "gnu")
233 * End:
234 */