2 * Copyright (c) 2017-2020 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef included_vppcom_h
17 #define included_vppcom_h
20 #include <sys/types.h>
21 #endif /* __FreeBSD__ */
26 #include <sys/epoll.h>
28 /* clang-format off */
36 * VPPCOM Public API Definitions, Enums, and Data Structures
38 #define INVALID_SESSION_ID ((u32)~0)
39 #define VPPCOM_CONF_DEFAULT "/etc/vpp/vcl.conf"
40 #define VPPCOM_ENV_CONF "VCL_CONFIG"
41 #define VPPCOM_ENV_DEBUG "VCL_DEBUG"
42 #define VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP "VCL_APP_PROXY_TRANSPORT_TCP"
43 #define VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP "VCL_APP_PROXY_TRANSPORT_UDP"
44 #define VPPCOM_ENV_APP_NAMESPACE_ID "VCL_APP_NAMESPACE_ID"
45 #define VPPCOM_ENV_APP_NAMESPACE_SECRET "VCL_APP_NAMESPACE_SECRET"
46 #define VPPCOM_ENV_APP_SCOPE_LOCAL "VCL_APP_SCOPE_LOCAL"
47 #define VPPCOM_ENV_APP_SCOPE_GLOBAL "VCL_APP_SCOPE_GLOBAL"
48 #define VPPCOM_ENV_APP_USE_MQ_EVENTFD "VCL_APP_USE_MQ_EVENTFD"
49 #define VPPCOM_ENV_VPP_API_SOCKET "VCL_VPP_API_SOCKET"
50 #define VPPCOM_ENV_VPP_SAPI_SOCKET "VCL_VPP_SAPI_SOCKET"
52 typedef enum vppcom_proto_
69 typedef struct vppcom_endpt_tlv_t_
76 typedef struct vppcom_endpt_t_
78 uint8_t unused; /**< unused */
79 uint8_t is_ip4; /**< flag set if if ip is ipv4 */
80 uint8_t *ip; /**< pointer to ip address */
81 uint16_t port; /**< transport port */
82 uint64_t unused2; /**< unused */
83 uint32_t app_tlv_len; /**< length of app provided tlvs */
84 vppcom_endpt_tlv_t *app_tlvs; /**< array of app provided tlvs */
87 #define VCL_UDP_OPTS_BASE (VPPCOM_PROTO_UDP << 16)
88 #define VCL_UDP_SEGMENT (VCL_UDP_OPTS_BASE + 0)
90 /* By convention we'll use 127 for IP since we don't support IP as protocol */
91 #define VCL_IP_OPTS_BASE (127 << 16)
92 #define VCL_IP_PKTINFO (VCL_IP_OPTS_BASE + 1)
94 #define VCL_EP_APP_TLV_LEN(tlv_) (sizeof (vppcom_endpt_tlv_t) + tlv->data_len)
95 #define VCL_EP_APP_TLV_POS(ep_, tlv_) ((void *)ep_->app_tlvs - (void *)tlv_)
96 #define VCL_EP_APP_TLV_LEN_LEFT(ep_, tlv_) \
97 (ep_->app_tlv_len - VCL_EP_APP_TLV_POS (ep_, tlv_))
98 #define VCL_EP_NEXT_APP_TLV(ep_, tlv_) \
99 (VCL_EP_APP_TLV_LEN (tlv_) < VCL_EP_APP_TLV_POS (ep_, tlv_) ? ( \
100 (vppcom_endpt_tlv_t *)((uint8_t *)tlv_ + VCL_EP_APP_TLV_LEN (tlv_))) \
103 typedef uint32_t vcl_session_handle_t;
105 typedef struct vppcom_cert_key_pair_
111 } vppcom_cert_key_pair_t;
116 VPPCOM_EAGAIN = -EAGAIN,
117 VPPCOM_EWOULDBLOCK = -EWOULDBLOCK,
118 VPPCOM_EINPROGRESS = -EINPROGRESS,
119 VPPCOM_EFAULT = -EFAULT,
120 VPPCOM_ENOMEM = -ENOMEM,
121 VPPCOM_EINVAL = -EINVAL,
123 VPPCOM_EBADFD = -EBADFD,
125 VPPCOM_EBADFD = -EBADF,
126 #endif /* __linux__ */
127 VPPCOM_EAFNOSUPPORT = -EAFNOSUPPORT,
128 VPPCOM_ECONNABORTED = -ECONNABORTED,
129 VPPCOM_ECONNRESET = -ECONNRESET,
130 VPPCOM_ENOTCONN = -ENOTCONN,
131 VPPCOM_ECONNREFUSED = -ECONNREFUSED,
132 VPPCOM_ETIMEDOUT = -ETIMEDOUT,
133 VPPCOM_EEXIST = -EEXIST,
134 VPPCOM_ENOPROTOOPT = -ENOPROTOOPT,
135 VPPCOM_EPIPE = -EPIPE,
136 VPPCOM_ENOENT = -ENOENT,
137 VPPCOM_EADDRINUSE = -EADDRINUSE,
138 VPPCOM_ENOTSUP = -ENOTSUP
143 VPPCOM_ATTR_GET_NREAD,
144 VPPCOM_ATTR_GET_NWRITE,
145 VPPCOM_ATTR_GET_FLAGS,
146 VPPCOM_ATTR_SET_FLAGS,
147 VPPCOM_ATTR_GET_LCL_ADDR,
148 VPPCOM_ATTR_SET_LCL_ADDR,
149 VPPCOM_ATTR_GET_PEER_ADDR,
150 VPPCOM_ATTR_GET_LIBC_EPFD,
151 VPPCOM_ATTR_SET_LIBC_EPFD,
152 VPPCOM_ATTR_GET_PROTOCOL,
153 VPPCOM_ATTR_GET_LISTEN,
154 VPPCOM_ATTR_GET_ERROR,
155 VPPCOM_ATTR_GET_TX_FIFO_LEN,
156 VPPCOM_ATTR_SET_TX_FIFO_LEN,
157 VPPCOM_ATTR_GET_RX_FIFO_LEN,
158 VPPCOM_ATTR_SET_RX_FIFO_LEN,
159 VPPCOM_ATTR_GET_REUSEADDR,
160 VPPCOM_ATTR_SET_REUSEADDR,
161 VPPCOM_ATTR_GET_REUSEPORT,
162 VPPCOM_ATTR_SET_REUSEPORT,
163 VPPCOM_ATTR_GET_BROADCAST,
164 VPPCOM_ATTR_SET_BROADCAST,
165 VPPCOM_ATTR_GET_V6ONLY,
166 VPPCOM_ATTR_SET_V6ONLY,
167 VPPCOM_ATTR_GET_KEEPALIVE,
168 VPPCOM_ATTR_SET_KEEPALIVE,
169 VPPCOM_ATTR_GET_TCP_NODELAY,
170 VPPCOM_ATTR_SET_TCP_NODELAY,
171 VPPCOM_ATTR_GET_TCP_KEEPIDLE,
172 VPPCOM_ATTR_SET_TCP_KEEPIDLE,
173 VPPCOM_ATTR_GET_TCP_KEEPINTVL,
174 VPPCOM_ATTR_SET_TCP_KEEPINTVL,
175 VPPCOM_ATTR_GET_TCP_USER_MSS,
176 VPPCOM_ATTR_SET_TCP_USER_MSS,
177 VPPCOM_ATTR_SET_CONNECTED,
178 VPPCOM_ATTR_SET_CKPAIR,
181 VPPCOM_ATTR_GET_DOMAIN,
182 VPPCOM_ATTR_SET_ENDPT_EXT_CFG,
183 VPPCOM_ATTR_SET_DSCP,
184 VPPCOM_ATTR_SET_IP_PKTINFO,
185 VPPCOM_ATTR_GET_IP_PKTINFO,
186 VPPCOM_ATTR_GET_ORIGINAL_DST,
189 typedef struct _vcl_poll
192 vcl_session_handle_t sh;
197 typedef struct vppcom_data_segment_
201 } vppcom_data_segment_t;
203 typedef vppcom_data_segment_t vppcom_data_segments_t[2];
205 typedef unsigned long vcl_si_set;
208 * VPPCOM Public API Functions
211 extern int vppcom_app_create (const char *app_name);
212 extern void vppcom_app_destroy (void);
214 extern int vppcom_session_create (uint8_t proto, uint8_t is_nonblocking);
215 extern int vppcom_session_shutdown (uint32_t session_handle, int how);
216 extern int vppcom_session_close (uint32_t session_handle);
217 extern int vppcom_session_bind (uint32_t session_handle, vppcom_endpt_t * ep);
218 extern int vppcom_session_listen (uint32_t session_handle, uint32_t q_len);
220 extern int vppcom_session_accept (uint32_t session_handle,
221 vppcom_endpt_t * client_ep, uint32_t flags);
223 extern int vppcom_session_connect (uint32_t session_handle,
224 vppcom_endpt_t * server_ep);
225 extern int vppcom_session_stream_connect (uint32_t session_handle,
226 uint32_t parent_session_handle);
227 extern int vppcom_session_read (uint32_t session_handle, void *buf, size_t n);
228 extern int vppcom_session_write (uint32_t session_handle, void *buf,
230 extern int vppcom_session_write_msg (uint32_t session_handle, void *buf,
233 extern int vppcom_select (int n_bits, vcl_si_set * read_map,
234 vcl_si_set * write_map, vcl_si_set * except_map,
235 double wait_for_time);
237 extern int vppcom_epoll_create (void);
238 extern int vppcom_epoll_ctl (uint32_t vep_handle, int op,
239 uint32_t session_handle,
240 struct epoll_event *event);
241 extern int vppcom_epoll_wait (uint32_t vep_handle, struct epoll_event *events,
242 int maxevents, double wait_for_time);
243 extern int vppcom_session_attr (uint32_t session_handle, uint32_t op,
244 void *buffer, uint32_t * buflen);
245 extern int vppcom_session_recvfrom (uint32_t session_handle, void *buffer,
246 uint32_t buflen, int flags,
247 vppcom_endpt_t * ep);
248 extern int vppcom_session_sendto (uint32_t session_handle, void *buffer,
249 uint32_t buflen, int flags,
250 vppcom_endpt_t * ep);
251 extern int vppcom_poll (vcl_poll_t * vp, uint32_t n_sids,
252 double wait_for_time);
253 extern int vppcom_mq_epoll_fd (void);
254 extern int vppcom_session_index (vcl_session_handle_t session_handle);
255 extern int vppcom_session_worker (vcl_session_handle_t session_handle);
257 extern int vppcom_session_read_segments (uint32_t session_handle,
258 vppcom_data_segment_t * ds,
261 extern void vppcom_session_free_segments (uint32_t session_handle,
263 extern int vppcom_add_cert_key_pair (vppcom_cert_key_pair_t *ckpair);
264 extern int vppcom_del_cert_key_pair (uint32_t ckpair_index);
265 extern int vppcom_unformat_proto (uint8_t * proto, char *proto_str);
266 extern int vppcom_session_is_connectable_listener (uint32_t session_handle);
267 extern int vppcom_session_listener (uint32_t session_handle);
268 extern int vppcom_session_n_accepted (uint32_t session_handle);
270 extern const char *vppcom_proto_str (vppcom_proto_t proto);
271 extern const char *vppcom_retval_str (int retval);
274 * Request from application to register a new worker
276 * Expectation is that applications will make use of this after a new pthread
279 extern int vppcom_worker_register (void);
282 * Unregister current worker
284 extern void vppcom_worker_unregister (void);
287 * Retrieve current worker index
289 extern int vppcom_worker_index (void);
292 * Set current worker index
294 extern void vppcom_worker_index_set (int);
297 * Returns the current worker's message queues epoll fd
299 * This only works if vcl is configured to do eventfd based message queue
302 extern int vppcom_worker_mqs_epfd (void);
305 * Returns Session error
307 * Application can use this API to find the detailed session error
309 extern int vppcom_session_get_error (uint32_t session_handle);
312 * Returns true if current worker is disconnected from vpp
314 * Application can use this API to check if VPP is disconnected
315 * as long as `use-mq-eventfd` is being set
317 extern int vppcom_worker_is_detached (void);
322 /* clang-format on */
324 #endif /* included_vppcom_h */
327 * fd.io coding-style-patch-verification: ON
330 * eval: (c-set-style "gnu")