aboutsummaryrefslogtreecommitdiffstats
path: root/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.h
blob: b616002ec45a9fe6d99d746a664b3ce7b9e574cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef included_vcom_socket_h
#define included_vcom_socket_h

#include <libvcl-ldpreload/vcom_glibc_socket.h>
#include <vppinfra/types.h>

#define INVALID_SESSION_ID (~0)
#define INVALID_FD (~0)

typedef enum
{
  SOCKET_TYPE_UNBOUND = 0,
  SOCKET_TYPE_KERNEL_BOUND,
  SOCKET_TYPE_VPPCOM_BOUND
} vcom_socket_type_t;

typedef struct
{
  /* file descriptor -
   * fd 0, 1, 2 have special meaning and are reserved,
   * -1 denote invalid fd */
  i32 fd;

  /* session id - -1 denote invalid sid */
  i32 sid;

  /* socket type */
  vcom_socket_type_t type;

  /* vcom socket attributes here */

} vcom_socket_t;

static inline char *
vcom_socket_type_str (vcom_socket_type_t t)
{
  switch (t)
    {
    case SOCKET_TYPE_UNBOUND:
      return "SOCKET_TYPE_UNBOUND";

    case SOCKET_TYPE_KERNEL_BOUND:
      return "SOCKET_TYPE_KERNEL_BOUND";

    case SOCKET_TYPE_VPPCOM_BOUND:
      return "SOCKET_TYPE_VPPCOM_BOUND";

    default:
      return "SOCKET_TYPE_UNKNOWN";
    }
}

static inline int
vcom_socket_type_is_vppcom_bound (vcom_socket_type_t t)
{
  return t == SOCKET_TYPE_VPPCOM_BOUND;
}

static inline void
vsocket_init (vcom_socket_t * vsock)
{
  vsock->fd = INVALID_FD;
  vsock->sid = INVALID_SESSION_ID;
  vsock->type = SOCKET_TYPE_UNBOUND;
  /* vcom socket attributes init here */
}

static inline void
vsocket_set (vcom_socket_t * vsock, i32 fd, i32 sid, vcom_socket_type_t type)
{
  vsock->fd = fd;
  vsock->sid = sid;
  vsock->type = type;
  /* vcom socket attributes set here */
}

static inline int
vsocket_is_vppcom_bound (vcom_socket_t * vsock)
{
  return vcom_socket_type_is_vppcom_bound (vsock->type);
}

int vcom_socket_open_socket (int domain, int type, int protocol);

int vcom_socket_close_socket (int fd);

int vcom_socket_main_init (void);

void vcom_socket_main_destroy (void);

void vcom_socket_main_show (void);

int vcom_socket_is_vcom_fd (int fd);

int vcom_socket_close (int __fd);

ssize_t vcom_socket_read (int __fd, void *__buf, size_t __nbytes);

ssize_t vcom_socket_write (int __fd, const void *__buf, size_t __n);

int vcom_socket_fcntl_va (int __fd, int __cmd, va_list __ap);

int
vcom_socket_select (int vcom_nfds, fd_set * __restrict vcom_readfds,
		    fd_set * __restrict vcom_writefds,
		    fd_set * __restrict vcom_exceptfds,
		    struct timeval *__restrict timeout);


int vcom_socket_socket (int __domain, int __type, int __protocol);

int
vcom_socket_socketpair (int __domain, int __type, int __protocol,
			int __fds[2]);

int vcom_socket_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);

int
vcom_socket_getsockname (int __fd, __SOCKADDR_ARG __addr,
			 socklen_t * __restrict __len);

int
vcom_socket_connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);

int
vcom_socket_getpeername (int __fd, __SOCKADDR_ARG __addr,
			 socklen_t * __restrict __len);

ssize_t
vcom_socket_send (int __fd, const void *__buf, size_t __n, int __flags);

ssize_t vcom_socket_recv (int __fd, void *__buf, size_t __n, int __flags);

/*
 * RETURN   1 if __fd is (SOCK_STREAM, SOCK_SEQPACKET),
 * 0 otherwise
 * */
int vcom_socket_is_connection_mode_socket (int __fd);

ssize_t
vcom_socket_sendto (int __fd, const void *__buf, size_t __n,
		    int __flags, __CONST_SOCKADDR_ARG __addr,
		    socklen_t __addr_len);

ssize_t
vcom_socket_recvfrom (int __fd, void *__restrict __buf, size_t __n,
		      int __flags, __SOCKADDR_ARG __addr,
		      socklen_t * __restrict __addr_len);

ssize_t
vcom_socket_sendmsg (int __fd, const struct msghdr *__message, int __flags);

#ifdef __USE_GNU
int
vcom_socket_sendmmsg (int __fd, struct mmsghdr *__vmessages,
		      unsigned int __vlen, int __flags);
#endif

ssize_t vcom_socket_recvmsg (int __fd, struct msghdr *__message, int __flags);

#ifdef __USE_GNU
int
vcom_socket_recvmmsg (int __fd, struct mmsghdr *__vmessages,
		      unsigned int __vlen, int __flags,
		      struct timespec *__tmo);
#endif

int
vcom_socket_getsockopt (int __fd, int __level, int __optname,
			void *__restrict __optval,
			socklen_t * __restrict __optlen);

int
vcom_socket_setsockopt (int __fd, int __level, int __optname,
			const void *__optval, socklen_t __optlen);

int vcom_socket_listen (int __fd, int __n);

int
vcom_socket_accept (int __fd, __SOCKADDR_ARG __addr,
		    socklen_t * __restrict __addr_len);

#ifdef __USE_GNU
int
vcom_socket_accept4 (int __fd, __SOCKADDR_ARG __addr,
		     socklen_t * __restrict __addr_len, int __flags);
#endif

int vcom_socket_shutdown (int __fd, int __how);

#endif /* included_vcom_socket_h */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */