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
23 #include <sys/epoll.h>
25 /* clang-format off */
33 * VPPCOM Public API Definitions, Enums, and Data Structures
35 #define INVALID_SESSION_ID ((u32)~0)
36 #define VPPCOM_CONF_DEFAULT "/etc/vpp/vcl.conf"
37 #define VPPCOM_ENV_CONF "VCL_CONFIG"
38 #define VPPCOM_ENV_DEBUG "VCL_DEBUG"
39 #define VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP "VCL_APP_PROXY_TRANSPORT_TCP"
40 #define VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP "VCL_APP_PROXY_TRANSPORT_UDP"
41 #define VPPCOM_ENV_APP_NAMESPACE_ID "VCL_APP_NAMESPACE_ID"
42 #define VPPCOM_ENV_APP_NAMESPACE_SECRET "VCL_APP_NAMESPACE_SECRET"
43 #define VPPCOM_ENV_APP_SCOPE_LOCAL "VCL_APP_SCOPE_LOCAL"
44 #define VPPCOM_ENV_APP_SCOPE_GLOBAL "VCL_APP_SCOPE_GLOBAL"
45 #define VPPCOM_ENV_APP_USE_MQ_EVENTFD "VCL_APP_USE_MQ_EVENTFD"
46 #define VPPCOM_ENV_VPP_API_SOCKET "VCL_VPP_API_SOCKET"
47 #define VPPCOM_ENV_VPP_SAPI_SOCKET "VCL_VPP_SAPI_SOCKET"
49 typedef enum vppcom_proto_
66 typedef struct vppcom_endpt_tlv_t_
73 typedef struct vppcom_endpt_t_
75 uint8_t unused; /**< unused */
76 uint8_t is_ip4; /**< flag set if if ip is ipv4 */
77 uint8_t *ip; /**< pointer to ip address */
78 uint16_t port; /**< transport port */
79 uint64_t unused2; /**< unused */
80 uint32_t app_tlv_len; /**< length of app provided tlvs */
81 vppcom_endpt_tlv_t *app_tlvs; /**< array of app provided tlvs */
84 #define VCL_UDP_OPTS_BASE (VPPCOM_PROTO_UDP << 16)
85 #define VCL_UDP_SEGMENT (VCL_UDP_OPTS_BASE + 0)
87 /* By convention we'll use 127 for IP since we don't support IP as protocol */
88 #define VCL_IP_OPTS_BASE (127 << 16)
89 #define VCL_IP_PKTINFO (VCL_IP_OPTS_BASE + 1)
91 #define VCL_EP_APP_TLV_LEN(tlv_) (sizeof (vppcom_endpt_tlv_t) + tlv->data_len)
92 #define VCL_EP_APP_TLV_POS(ep_, tlv_) ((void *)ep_->app_tlvs - (void *)tlv_)
93 #define VCL_EP_APP_TLV_LEN_LEFT(ep_, tlv_) \
94 (ep_->app_tlv_len - VCL_EP_APP_TLV_POS (ep_, tlv_))
95 #define VCL_EP_NEXT_APP_TLV(ep_, tlv_) \
96 (VCL_EP_APP_TLV_LEN (tlv_) < VCL_EP_APP_TLV_POS (ep_, tlv_) ? ( \
97 (vppcom_endpt_tlv_t *)((uint8_t *)tlv_ + VCL_EP_APP_TLV_LEN (tlv_))) \
100 typedef uint32_t vcl_session_handle_t;
102 typedef struct vppcom_cert_key_pair_
108 } vppcom_cert_key_pair_t;
113 VPPCOM_EAGAIN = -EAGAIN,
114 VPPCOM_EWOULDBLOCK = -EWOULDBLOCK,
115 VPPCOM_EINPROGRESS = -EINPROGRESS,
116 VPPCOM_EFAULT = -EFAULT,
117 VPPCOM_ENOMEM = -ENOMEM,
118 VPPCOM_EINVAL = -EINVAL,
119 VPPCOM_EBADFD = -EBADFD,
120 VPPCOM_EAFNOSUPPORT = -EAFNOSUPPORT,
121 VPPCOM_ECONNABORTED = -ECONNABORTED,
122 VPPCOM_ECONNRESET = -ECONNRESET,
123 VPPCOM_ENOTCONN = -ENOTCONN,
124 VPPCOM_ECONNREFUSED = -ECONNREFUSED,
125 VPPCOM_ETIMEDOUT = -ETIMEDOUT,
126 VPPCOM_EEXIST = -EEXIST,
127 VPPCOM_ENOPROTOOPT = -ENOPROTOOPT,
128 VPPCOM_EPIPE = -EPIPE,
129 VPPCOM_ENOENT = -ENOENT,
130 VPPCOM_EADDRINUSE = -EADDRINUSE,
131 VPPCOM_ENOTSUP = -ENOTSUP
136 VPPCOM_ATTR_GET_NREAD,
137 VPPCOM_ATTR_GET_NWRITE,
138 VPPCOM_ATTR_GET_FLAGS,
139 VPPCOM_ATTR_SET_FLAGS,
140 VPPCOM_ATTR_GET_LCL_ADDR,
141 VPPCOM_ATTR_SET_LCL_ADDR,
142 VPPCOM_ATTR_GET_PEER_ADDR,
143 VPPCOM_ATTR_GET_LIBC_EPFD,
144 VPPCOM_ATTR_SET_LIBC_EPFD,
145 VPPCOM_ATTR_GET_PROTOCOL,
146 VPPCOM_ATTR_GET_LISTEN,
147 VPPCOM_ATTR_GET_ERROR,
148 VPPCOM_ATTR_GET_TX_FIFO_LEN,
149 VPPCOM_ATTR_SET_TX_FIFO_LEN,
150 VPPCOM_ATTR_GET_RX_FIFO_LEN,
151 VPPCOM_ATTR_SET_RX_FIFO_LEN,
152 VPPCOM_ATTR_GET_REUSEADDR,
153 VPPCOM_ATTR_SET_REUSEADDR,
154 VPPCOM_ATTR_GET_REUSEPORT,
155 VPPCOM_ATTR_SET_REUSEPORT,
156 VPPCOM_ATTR_GET_BROADCAST,
157 VPPCOM_ATTR_SET_BROADCAST,
158 VPPCOM_ATTR_GET_V6ONLY,
159 VPPCOM_ATTR_SET_V6ONLY,
160 VPPCOM_ATTR_GET_KEEPALIVE,
161 VPPCOM_ATTR_SET_KEEPALIVE,
162 VPPCOM_ATTR_GET_TCP_NODELAY,
163 VPPCOM_ATTR_SET_TCP_NODELAY,
164 VPPCOM_ATTR_GET_TCP_KEEPIDLE,
165 VPPCOM_ATTR_SET_TCP_KEEPIDLE,
166 VPPCOM_ATTR_GET_TCP_KEEPINTVL,
167 VPPCOM_ATTR_SET_TCP_KEEPINTVL,
168 VPPCOM_ATTR_GET_TCP_USER_MSS,
169 VPPCOM_ATTR_SET_TCP_USER_MSS,
170 VPPCOM_ATTR_SET_CONNECTED,
171 VPPCOM_ATTR_SET_CKPAIR,
174 VPPCOM_ATTR_GET_DOMAIN,
175 VPPCOM_ATTR_SET_ENDPT_EXT_CFG,
176 VPPCOM_ATTR_SET_DSCP,
177 VPPCOM_ATTR_SET_IP_PKTINFO,
178 VPPCOM_ATTR_GET_IP_PKTINFO,
179 VPPCOM_ATTR_GET_ORIGINAL_DST,
182 typedef struct _vcl_poll
185 vcl_session_handle_t sh;
190 typedef struct vppcom_data_segment_
194 } vppcom_data_segment_t;
196 typedef vppcom_data_segment_t vppcom_data_segments_t[2];
198 typedef unsigned long vcl_si_set;
201 * VPPCOM Public API Functions
204 extern int vppcom_app_create (const char *app_name);
205 extern void vppcom_app_destroy (void);
207 extern int vppcom_session_create (uint8_t proto, uint8_t is_nonblocking);
208 extern int vppcom_session_shutdown (uint32_t session_handle, int how);
209 extern int vppcom_session_close (uint32_t session_handle);
210 extern int vppcom_session_bind (uint32_t session_handle, vppcom_endpt_t * ep);
211 extern int vppcom_session_listen (uint32_t session_handle, uint32_t q_len);
213 extern int vppcom_session_accept (uint32_t session_handle,
214 vppcom_endpt_t * client_ep, uint32_t flags);
216 extern int vppcom_session_connect (uint32_t session_handle,
217 vppcom_endpt_t * server_ep);
218 extern int vppcom_session_stream_connect (uint32_t session_handle,
219 uint32_t parent_session_handle);
220 extern int vppcom_session_read (uint32_t session_handle, void *buf, size_t n);
221 extern int vppcom_session_write (uint32_t session_handle, void *buf,
223 extern int vppcom_session_write_msg (uint32_t session_handle, void *buf,
226 extern int vppcom_select (int n_bits, vcl_si_set * read_map,
227 vcl_si_set * write_map, vcl_si_set * except_map,
228 double wait_for_time);
230 extern int vppcom_epoll_create (void);
231 extern int vppcom_epoll_ctl (uint32_t vep_handle, int op,
232 uint32_t session_handle,
233 struct epoll_event *event);
234 extern int vppcom_epoll_wait (uint32_t vep_handle, struct epoll_event *events,
235 int maxevents, double wait_for_time);
236 extern int vppcom_session_attr (uint32_t session_handle, uint32_t op,
237 void *buffer, uint32_t * buflen);
238 extern int vppcom_session_recvfrom (uint32_t session_handle, void *buffer,
239 uint32_t buflen, int flags,
240 vppcom_endpt_t * ep);
241 extern int vppcom_session_sendto (uint32_t session_handle, void *buffer,
242 uint32_t buflen, int flags,
243 vppcom_endpt_t * ep);
244 extern int vppcom_poll (vcl_poll_t * vp, uint32_t n_sids,
245 double wait_for_time);
246 extern int vppcom_mq_epoll_fd (void);
247 extern int vppcom_session_index (vcl_session_handle_t session_handle);
248 extern int vppcom_session_worker (vcl_session_handle_t session_handle);
250 extern int vppcom_session_read_segments (uint32_t session_handle,
251 vppcom_data_segment_t * ds,
254 extern void vppcom_session_free_segments (uint32_t session_handle,
256 extern int vppcom_add_cert_key_pair (vppcom_cert_key_pair_t *ckpair);
257 extern int vppcom_del_cert_key_pair (uint32_t ckpair_index);
258 extern int vppcom_unformat_proto (uint8_t * proto, char *proto_str);
259 extern int vppcom_session_is_connectable_listener (uint32_t session_handle);
260 extern int vppcom_session_listener (uint32_t session_handle);
261 extern int vppcom_session_n_accepted (uint32_t session_handle);
263 extern const char *vppcom_proto_str (vppcom_proto_t proto);
264 extern const char *vppcom_retval_str (int retval);
267 * Request from application to register a new worker
269 * Expectation is that applications will make use of this after a new pthread
272 extern int vppcom_worker_register (void);
275 * Unregister current worker
277 extern void vppcom_worker_unregister (void);
280 * Retrieve current worker index
282 extern int vppcom_worker_index (void);
285 * Set current worker index
287 extern void vppcom_worker_index_set (int);
290 * Returns the current worker's message queues epoll fd
292 * This only works if vcl is configured to do eventfd based message queue
295 extern int vppcom_worker_mqs_epfd (void);
298 * Returns Session error
300 * Application can use this API to find the detailed session error
302 extern int vppcom_session_get_error (uint32_t session_handle);
305 * Returns true if current worker is disconnected from vpp
307 * Application can use this API to check if VPP is disconnected
308 * as long as `use-mq-eventfd` is being set
310 extern int vppcom_worker_is_detached (void);
315 /* clang-format on */
317 #endif /* included_vppcom_h */
320 * fd.io coding-style-patch-verification: ON
323 * eval: (c-set-style "gnu")