/* * Copyright (c) 2018-2019 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this * 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 SRC_VCL_VCL_PRIVATE_H_ #define SRC_VCL_VCL_PRIVATE_H_ #include #include #include #if (CLIB_DEBUG > 0) /* Set VPPCOM_DEBUG_INIT 2 for connection debug, * 3 for read/write debug output * or * export VCL_DEBUG=<#> to set dynamically. */ #define VPPCOM_DEBUG_INIT 1 #else #define VPPCOM_DEBUG_INIT 0 #endif #define VPPCOM_DEBUG vcm->debug extern __thread uword __vcl_worker_index; static inline void vcl_set_worker_index (uword wrk_index) { __vcl_worker_index = wrk_index; } static inline uword vcl_get_worker_index (void) { return __vcl_worker_index; } /* * VPPCOM Private definitions and functions. */ typedef enum { STATE_APP_START, STATE_APP_CONN_VPP, STATE_APP_ENABLED, STATE_APP_ATTACHED, STATE_APP_ADDING_WORKER, STATE_APP_ADDING_TLS_DATA, STATE_APP_FAILED, STATE_APP_READY } app_state_t; typedef enum { STATE_CLOSED = 0, STATE_CONNECT = 0x01, STATE_LISTEN = 0x02, STATE_ACCEPT = 0x04, STATE_VPP_CLOSING = 0x08, STATE_DISCONNECT = 0x10, STATE_DETACHED = 0x20, STATE_UPDATED = 0x40, STATE_LISTEN_NO_MQ = 0x80, } vcl_session_state_t; #define SERVER_STATE_OPEN (STATE_ACCEPT|STATE_VPP_CLOSING) #define CLIENT_STATE_OPEN (STATE_CONNECT|STATE_VPP_CLOSING) #define STATE_OPEN (SERVER_STATE_OPEN | CLIENT_STATE_OPEN) typedef struct epoll_event vppcom_epoll_event_t; typedef struct { u32 next_sh; u32 prev_sh; u32 vep_sh; vppcom_epoll_event_t ev; #define VEP_DEFAULT_ET_MASK (EPOLLIN|EPOLLOUT) #define VEP_UNSUPPORTED_EVENTS (EPOLLONESHOT|EPOLLEXCLUSIVE) u32 et_mask; } vppcom_epoll_t; /* Select uses the vcl_si_set as if a clib_bitmap. Make sure they are the * same size */ STATIC_ASSERT (sizeof (clib_bitmap_t) == sizeof (vcl_si_set), "vppcom bitmap size mismatch"); typedef struct { u8 is_ip4; ip46_address_t ip46; } vppcom_ip46_t; #define VCL_ACCEPTED_F_CLOSED (1 << 0) #define VCL_ACCEPTED_F_RESET (1 << 1) typedef struct vcl_session_msg { union { session_accepted_msg_t accepted_msg; }; u32 flags; } vcl_session_msg_t; typedef enum { VCL_SESS_ATTR_SERVER, VCL_SESS_ATTR_CUT_THRU, VCL_SESS_ATTR_VEP, VCL_SESS_ATTR_VEP_SESSION, VCL_SESS_ATTR_LISTEN, // SOL_SOCKET,SO_ACCEPTCONN VCL_SESS_ATTR_NONBLOCK, // fcntl,O_NONBLOCK VCL_SESS_ATTR_REUSEADDR, // SOL_SOCKET,SO_REUSEADDR VCL_SESS_ATTR_REUSEPORT, // SOL_SOCKET,SO_REUSEPORT VCL_SESS_ATTR_BROADCAST, // SOL_SOCKET,SO_BROADCAST VCL_SESS_ATTR_V6ONLY, // SOL_TCP,IPV6_V6ONLY VCL_SESS_ATTR_KEEPALIVE, // SOL_SOCKET,SO_KEEPALIVE VCL_SESS_ATTR_TCP_NODELAY, // SOL_TCP,TCP_NODELAY VCL_SESS_ATTR_TCP_KEEPIDLE, // SOL_TCP,TCP_KEEPIDLE VCL_SESS_ATTR_TCP_KEEPINTVL, // SOL_TCP,TCP_KEEPINTVL VCL_SESS_ATTR_SHUT_RD, VCL_SESS_ATTR_SHUT_WR, VCL_SESS_ATTR_MAX } vppcom_session_attr_t; #define VCL_SESS_ATTR_SET(ATTR, VAL) \ do { \ (ATTR) |= 1 << (VAL); \ } while (0) #define VCL_SESS_ATTR_CLR(ATTR, VAL) \ do { \ (ATTR) &= ~(1 << (VAL)); \ } while (0) #define VCL_SESS_ATTR_TEST(ATTR, VAL) \ ((ATTR) & (1 << (VAL)) ? 1 : 0) typedef enum vcl_session_flags_ { VCL_SESSION_F_CONNECTED = 1 << 0, } __clib_packed vcl_session_flags_t; typedef struct { CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); #define _(type, name) type name; foreach_app_session_field #undef _ u32 sndbuf_size; // VPP-TBD: Hack until support setsockopt(SO_SNDBUF) u32 rcvbuf_size; // VPP-TBD: Hack until support setsockopt(SO_RCVBUF) u32 user_mss; // VPP-TBD: Hack until support setsockopt(TCP_MAXSEG) u64 vpp_handle; u32 vpp_thread_index; svm_fifo_t *ct_rx_fifo; svm_fifo_t *ct_tx_fifo; /* Socket configuration state */ u8 is_vep; u8 is_vep_session; vcl_session_flags_t flags; /* VCL session index of the listening session (if any) */ u32 listener_index; /* Accepted sessions on this listener */ int n_accepted_sessions; u8 has_rx_evt; u32 attr; u64 parent_handle; vppcom_epoll_t vep; int libc_epfd; svm_msg_q_t *our_evt_q; vcl_session_msg_t *accept_evts_fifo; #if VCL_ELOG elog_tr

_address_t * ip, vppcom_endpt_t * ep, u8 is_ip4) { ep->is_ip4 = is_ip4; if (is_ip4) clib_memcpy_fast (ep->ip, &ip->ip4, sizeof (ip4_address_t)); else clib_memcpy_fast (ep->ip, &ip->ip6, sizeof (ip6_address_t)); } static inline int vcl_proto_is_dgram (uint8_t proto) { return proto == VPPCOM_PROTO_UDP; } /* * Helpers */ int vcl_wait_for_app_state_change (app_state_t app_state); vcl_mq_evt_conn_t *vcl_mq_evt_conn_alloc (vcl_worker_t * wrk); u32 vcl_mq_evt_conn_index (vcl_worker_t * wrk, vcl_mq_evt_conn_t * mqc); vcl_mq_evt_conn_t *vcl_mq_evt_conn_get (vcl_worker_t * wrk, u32 mq_conn_idx); int vcl_mq_epoll_add_evfd (vcl_worker_t * wrk, svm_msg_q_t * mq); int vcl_mq_epoll_del_evfd (vcl_worker_t * wrk, u32 mqc_index); vcl_worker_t *vcl_worker_alloc_and_init (void); void vcl_worker_cleanup (vcl_worker_t * wrk, u8 notify_vpp); int vcl_worker_register_with_vpp (void); int vcl_worker_set_bapi (void); svm_msg_q_t *vcl_worker_ctrl_mq (vcl_worker_t * wrk); void vcl_flush_mq_events (void); void vcl_cleanup_bapi (void); int vcl_session_cleanup (vcl_worker_t * wrk, vcl_session_t * session, vcl_session_handle_t sh, u8 do_disconnect); void vcl_segment_table_add (u64 segment_handle, u32 svm_segment_index); u32 vcl_segment_table_lookup (u64 segment_handle); void vcl_segment_table_del (u64 segment_handle); int vcl_session_read_ready (vcl_session_t * session); int vcl_session_write_ready (vcl_session_t * session); static inline vcl_worker_t * vcl_worker_get (u32 wrk_index) { return pool_elt_at_index (vcm->workers, wrk_index); } static inline vcl_worker_t * vcl_worker_get_if_valid (u32 wrk_index) { if (pool_is_free_index (vcm->workers, wrk_index)) return 0; return pool_elt_at_index (vcm->workers, wrk_index); } static inline vcl_worker_t * vcl_worker_get_current (void) { return vcl_worker_get (vcl_get_worker_index ()); } static inline u8 vcl_n_workers (void) { return pool_elts (vcm->workers); } static inline svm_msg_q_t * vcl_session_vpp_evt_q (vcl_worker_t * wrk, vcl_session_t * s) { return wrk->vpp_event_queues[s->vpp_thread_index]; } void vcl_send_session_worker_update (vcl_worker_t * wrk, vcl_session_t * s, u32 wrk_index); int vcl_send_worker_rpc (u32 dst_wrk_index, void *data, u32 data_len); /* * VCL Binary API */ int vppcom_connect_to_vpp (const char *app_name); void vppcom_disconnect_from_vpp (void); void vppcom_init_error_string_table (void); void vppcom_send_session_enable_disable (u8 is_enable); void vppcom_app_send_attach (void); void vppcom_app_send_detach (void); void vcl_send_session_unlisten (vcl_worker_t * wrk, vcl_session_t * s); void vppcom_send_disconnect_session (u64 vpp_handle); void vppcom_api_hookup (void); void vppcom_send_application_tls_cert_add (vcl_session_t * session, char *cert, u32 cert_len); void vppcom_send_application_tls_key_add (vcl_session_t * session, char *key, u32 key_len); void vcl_send_app_worker_add_del (u8 is_add); void vcl_send_child_worker_del (vcl_worker_t * wrk); int vcl_segment_attach (u64 segment_handle, char *name, ssvm_segment_type_t type, int fd); void vcl_segment_detach (u64 segment_handle); u32 vcl_max_nsid_len (void); void vls_init (); #endif /* SRC_VCL_VCL_PRIVATE_H_ */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */