/* * 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. */ #include #include #include #define vl_typedefs /* define message structures */ #include #undef vl_typedefs /* declare message handlers for each api */ #define vl_endianfun /* define message structures */ #include #undef vl_endianfun /* instantiate all the print functions we know about */ #define vl_print(handle, ...) #define vl_printfun #include #undef vl_printfun static u8 * format_api_error (u8 * s, va_list * args) { i32 error = va_arg (*args, u32); uword *p; p = hash_get (vcm->error_string_by_error_number, -error); if (p) s = format (s, "%s (%d)", p[0], error); else s = format (s, "%d", error); return s; } static void vl_api_session_enable_disable_reply_t_handler (vl_api_session_enable_disable_reply_t * mp) { vcl_worker_t *wrk = vcl_worker_get (0); if (mp->retval) { clib_warning ("VCL<%d>: session_enable_disable failed: %U", getpid (), format_api_error, ntohl (mp->retval)); } else wrk->bapi_app_state = STATE_APP_ENABLED; } static void vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t * mp) { vcl_worker_t *wrk = vcl_worker_get (0); u64 segment_handle; int *fds = 0, i, rv; u32 n_fds = 0; char *segment_name = 0; if (mp->retval) { VERR ("attach failed: %U", format_api_error, ntohl (mp->retval)); goto failed; } vcl_set_worker_index (0); segment_handle = clib_net_to_host_u64 (mp->segment_handle); if (segment_handle == VCL_INVALID_SEGMENT_HANDLE) { VERR ("invalid segment handle"); goto failed; } if (mp->n_fds) { vec_validate (fds, mp->n_fds); if (vl_socket_client_recv_fd_msg2 (&wrk->bapi_sock_ctx, fds, mp->n_fds, 5)) goto failed; if (mp->fd_flags & SESSION_FD_F_VPP_MQ_SEGMENT) if (vcl_segment_attach (vcl_vpp_worker_segment_handle (0), "vpp-mq-seg", SSVM_SEGMENT_MEMFD, fds[n_fds++])) goto failed; if (mp->fd_flags & SESSION_FD_F_MEMFD_SEGMENT) { segment_name = vl_api_from_api_to_new_c_string (&mp->segment_name); rv = vcl_segment_attach (segment_handle, segment_name, SSVM_SEGMENT_MEMFD, fds[n_fds++]); vec_free (segment_name); if (rv != 0) goto failed; } vcl_segment_attach_mq (segment_handle, mp->app_mq, 0, &wrk->app_event_queue); if (mp->fd_flags & SESSION_FD_F_MQ_EVENTFD) { svm_msg_q_set_eventfd (wrk->app_event_queue, fds[n_fds]); vcl_mq_epoll_add_evfd (wrk, wrk->app_event_queue); n_fds++; } vcl_segment_discover_mqs (vcl_vpp_worker_segment_handle (0), fds + n_fds, mp->n_fds - n_fds); vcl_segment_attach_mq (vcl_vpp_worker_segment_handle (0), mp->vpp_ctrl_mq, mp->vpp_ctrl_mq_thread, &wrk->ctrl_mq); vcm->ctrl_mq = wrk->ctrl_mq; vec_free (fds); } else { segment_name = vl_api_from_api_to_new_c_string (&mp->segment_name); rv = vcl_segment_attach (segment_handle, segment_name, SSVM_SEGMENT_SHM, -1); vec_free (segment_name); if (rv != 0) goto failed; } vcm->app_index = clib_net_to_host_u32 (mp->app_index); wrk->bapi_app_state = STATE_APP_ATTACHED; return; failed: wrk->bapi_app_state = STATE_APP_FAILED; for (i = clib_max (n_fds - 1, 0); i < vec_len (fds); i++) close (fds[i]); vec_free (fds); } static void vl_api_app_worker_add_del_reply_t_handler (vl_api_app_worker_add_del_reply_t * mp) { int n_fds = 0, *fds = 0, i, rv; u64 segment_handle; vcl_worker_t *wrk; u32 wrk_index; char *segment_name = 0; if (!mp->is_add) return; wrk_index = mp->context; wrk = vcl_worker_get_if_valid (wrk_index); if (!wrk) return; if (mp->retval) { clib_warning ("VCL<%d>: add/del worker failed: %U", getpid (), format_api_error, ntohl (mp->retval)); goto failed; } vcl_set_worker_index (wrk_index); wrk->vpp_wrk_index = clib_net_to_host_u32 (mp->wrk_index); wrk->ctrl_mq = vcm->ctrl_mq; segment_handle = clib_net_to_host_u64 (mp->segment_handle); if (segment_handle == VCL_INVALID_SEGMENT_HANDLE) { clib_warning ("invalid segment handle"); goto failed; } if (mp->n_fds) { vec_validate (fds, mp->n_fds); if (vl_socket_client_recv_fd_msg2 (&wrk->bapi_sock_ctx, fds, mp->n_fds, 5)) goto failed; if (mp->fd_flags & SESSION_FD_F_VPP_MQ_SEGMENT) if (vcl_segment_attach (vcl_vpp_worker_segment_handle (wrk_index), "vpp-worker-seg", SSVM_SEGMENT_MEMFD, fds[n_fds++])) goto failed; if (mp->fd_flags & SESSION_FD_F_MEMFD_SEGMENT) { segment_name = vl_api_from_api_to_new_c_string (&mp->segment_name); rv = vcl_segment_attach (segment_handle, segment_name, SSVM_SEGMENT_MEMFD, fds[n_fds++]); vec_free (segment_name); if (rv != 0) goto failed; } vcl_segment_attach_mq (segment_handle, mp->app_event_queue_address, 0, &wrk->app_event_queue); if (mp->fd_flags & SESSION_FD_F_MQ_EVENTFD) { svm_msg_q_set_eventfd (wrk->app_event_queue, fds[n_fds]); vcl_mq_epoll_add_evfd (wrk, wrk->app_event_queue); n_fds++; } vec_free (fds); } else { segment_name = vl_api_from_api_to_new_c_string (&mp->segment_name); rv = vcl_segment_attach (segment_handle, segment_name, SSVM_SEGMENT_SHM, -1); vec_free (segment_name); if (rv != 0) goto failed; } wrk->bapi_app_state = STATE_APP_READY; VDBG (0, "worker %u vpp-worker %u added", wrk_index, wrk->vpp_wrk_index); return; failed: wrk->bapi_app_state = STATE_APP_FAILED; for (i = clib_max (n_fds - 1, 0); i < vec_len (fds); i++) close (fds[i]); vec_free (fds); } static void vl_api_app_add_cert_key_pair_reply_t_handler ( vl_api_app_add_cert_key_pair_reply_t *mp) { vcl_worker_t *wrk = vcl_worker_get_current (); if (mp->retval) { VDBG (0, "Adding cert and key failed: %U", format_api_error, ntohl (mp->retval)); return; } wrk->bapi_return = clib_net_to_host_u32 (mp->index); wrk->bapi_app_state = STATE_APP_READY; } static void vl_api_app_del_cert_key_pair_reply_t_handler ( vl_api_app_del_cert_key_pair_reply_t *mp) { if (mp->retval) { VDBG (0, "Deleting cert and key failed: %U", format_api_error, ntohl (mp->retval)); return; } } #define foreach_sock_msg \ _ (SESSION_ENABLE_DISABLE_REPLY, session_enable_disable_reply) \ _ (APP_ATTACH_REPLY, app_attach_reply) \ _ (APP_ADD_CERT_KEY_PAIR_REPLY, app_add_cert_key_pair_reply) \ _ (APP_DEL_CERT_KEY_PAIR_REPLY, app_del_cert_key_pair_reply) \ _ (APP_WORKER_ADD_DEL_REPLY, app_worker_add_del_reply) static void vcl_bapi_hookup (void) { #define _(N, n) \ vl_msg_api_set_handlers(VL_API_##N, #n, \ vl_api_##n##_t_handler, \ vl_noop_handler, \ vl_api_##n##_t_endian, \ vl_api_##n##_t_print, \
/*
 * 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.

 */

#ifndef __included_warnings_h__
#define __included_warnings_h__

/* Macros to check compiler version */
#if defined(__GNUC__)
#define COMPILER_VERSION_GTE(major, minor) \
  (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
#elif defined(__clang__)
#define COMPILER_VERSION_GTE(major, minor) \
  (__clang_major__ > (major) ||            \
   (__clang_major__ == (major) && __clang_minor__ >= (minor)))
#else /* disable all warning customization for all other compilers */
#define COMPILER_VERSION_GTE(maj, min) 0
#endif

/* '#' needs to preceed a macro parameter */
#define WARN_TOSTR(x) #x

/*
 * Macros to toggle off/on warnings
 *
 * Start by silenging pragma warnings so that we can explicitely silence
 * a warning introduced on some compiler version and not get a warning on older
 * versions of that same compiler.
 *
 * gcc corresponding warnign is "Wpargma"
 * clang corresponding warnign is "Wunknown-warning-option"
 *
 * For example, Wtautological-compare is introduced in gcc-6 and this would
 * trigger a Wpargma warning on gcc-5.
 *
 * Example usage to disable -Wtautological-compare warning:
 *   WARN_OFF(tautological-compare)
 *   if (...) {
 *   WARN_ON(tautological-compare)
 *     ; // conditional code
 *   }
 */
#if defined(__GNUC__) && COMPILER_VERSION_GTE(4, 6)
/*
 * GCC option to locally ignore warning was introduced in gcc-4.6
 * gcc.gnu.org/gcc-4.6/changes.html
 */
#define WARN_PRAGMA(x) _Pragma (WARN_TOSTR (GCC diagnostic x))
#define WARN_OFF(x)                                    \
  WARN_PRAGMA (push) WARN_PRAGMA (ignored "-Wpragmas") \
  WARN_PRAGMA (push) WARN_PRAGMA (ignored WARN_TOSTR (-W##x))
#define WARN_ON(x)  \
  WARN_PRAGMA (pop) \
  WARN_PRAGMA (pop)

#elif defined(__clang__) && COMPILER_VERSION_GTE(3, 3)
/*
 * clang option to locally ignore warning was introduced in clang-3.3
 * releases.llvm.org/3.3/tools/clang/docs/UsersManual.html#controlling-diagnostics-via-pragmas
 */
#define WARN_PRAGMA(x) _Pragma (WARN_TOSTR (clang diagnostic x))
#define WARN_OFF(x)                                                   \
  WARN_PRAGMA (push) WARN_PRAGMA (ignored "-Wunknown-warning-option") \
  WARN_PRAGMA (push) WARN_PRAGMA (ignored WARN_TOSTR (-W##x))
#define WARN_ON(x)  \
  WARN_PRAGMA (pop) \
  WARN_PRAGMA (pop)
#else
/* Ignore WARN_* instruction for all other compilers */
#define WARN_OFF(x)
#define WARN_ON(x)
#endif

/*
 * Clang supports a wider range of warnings than gcc.
 * Use those specific macros for the warnings that are only supported by clang
 */
#ifdef __clang__
#define WARN_OFF_CLANG(x) WARN_OFF (x)
#define WARN_ON_CLANG(x) WARN_ON (x)
#else
#define WARN_OFF_CLANG(x)
#define WARN_ON_CLANG(x)
#endif

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
#endif /* __included_warnings_h__ */
/* Don't wait for reply */ vcl_bapi_send_app_del_cert_key_pair (ckpair_index); return 0; } int vcl_bapi_worker_set (void) { vcl_worker_t *wrk = vcl_worker_get_current (); int i; /* Find the first worker with the same pid */ for (i = 0; i < vec_len (vcm->workers); i++) { if (i == wrk->wrk_index) continue; if (vcm->workers[i].current_pid == wrk->current_pid) { wrk->vl_input_queue = vcm->workers[i].vl_input_queue; wrk->api_client_handle = vcm->workers[i].api_client_handle; return 0; } } return -1; } /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */