Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * Copyright (c) 2018 Cisco and/or its affiliates. |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at: |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | *------------------------------------------------------------------ |
| 16 | */ |
| 17 | |
| 18 | #ifndef SRC_VLIBMEMORY_SOCKET_API_H_ |
| 19 | #define SRC_VLIBMEMORY_SOCKET_API_H_ |
| 20 | |
| 21 | #include <vlibapi/api_common.h> |
Florin Coras | 4d9b9d8 | 2018-01-14 12:25:50 -0800 | [diff] [blame] | 22 | #include <svm/ssvm.h> |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 23 | #include <vppinfra/file.h> |
| 24 | |
Ole Troan | 6595ff7 | 2019-08-07 13:41:39 +0200 | [diff] [blame] | 25 | /* Deprecated */ |
| 26 | #define API_SOCKET_FILE "/run/vpp/api.sock" |
| 27 | |
| 28 | #define API_SOCKET_FILENAME "api.sock" |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 29 | |
| 30 | typedef struct |
| 31 | { |
| 32 | clib_file_t *clib_file; |
| 33 | vl_api_registration_t *regp; |
| 34 | u8 *data; |
| 35 | } vl_socket_args_for_process_t; |
| 36 | |
| 37 | typedef struct |
| 38 | { |
| 39 | /* Server port number */ |
| 40 | u8 *socket_name; |
| 41 | |
| 42 | /* By default, localhost... */ |
| 43 | u32 bind_address; |
| 44 | |
| 45 | /* |
| 46 | * (listen, server, client) registrations. Shared memory |
| 47 | * registrations are in shared memory |
| 48 | */ |
| 49 | vl_api_registration_t *registration_pool; |
| 50 | /* |
| 51 | * Chain-drag variables, so message API handlers |
| 52 | * (generally) don't know whether they're talking to a socket |
| 53 | * or to a shared-memory connection. |
| 54 | */ |
| 55 | vl_api_registration_t *current_rp; |
| 56 | clib_file_t *current_uf; |
| 57 | /* One input buffer, shared across all sockets */ |
| 58 | i8 *input_buffer; |
| 59 | |
| 60 | /* pool of process args for socket clients */ |
| 61 | vl_socket_args_for_process_t *process_args; |
| 62 | |
| 63 | /* Listen for API connections here */ |
| 64 | clib_socket_t socksvr_listen_socket; |
| 65 | } socket_main_t; |
| 66 | |
| 67 | extern socket_main_t socket_main; |
| 68 | |
| 69 | void vl_socket_free_registration_index (u32 pool_index); |
| 70 | clib_error_t *vl_socket_read_ready (struct clib_file *uf); |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 71 | clib_error_t *vl_socket_write_ready (struct clib_file *uf); |
| 72 | void vl_socket_api_send (vl_api_registration_t * rp, u8 * elem); |
| 73 | void vl_socket_process_api_msg (clib_file_t * uf, vl_api_registration_t * rp, |
| 74 | i8 * input_v); |
| 75 | void vl_sock_api_dump_clients (vlib_main_t * vm, api_main_t * am); |
| 76 | clib_error_t *vl_sock_api_init (vlib_main_t * vm); |
Florin Coras | 466f289 | 2018-08-03 02:50:43 -0700 | [diff] [blame] | 77 | clib_error_t *vl_sock_api_send_fd_msg (int socket_fd, int fds[], int n_fds); |
| 78 | clib_error_t *vl_sock_api_recv_fd_msg (int socket_fd, int fds[], int n_fds, |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 79 | u32 wait); |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 80 | |
Florin Coras | 2881dec | 2018-10-02 18:29:25 -0700 | [diff] [blame] | 81 | vl_api_registration_t *vl_socket_api_client_handle_to_registration (u32 idx); |
| 82 | u8 vl_socket_api_registration_handle_is_valid (u32 reg_index); |
Ole Troan | 94495f2 | 2018-08-02 11:58:12 +0200 | [diff] [blame] | 83 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 84 | #endif /* SRC_VLIBMEMORY_SOCKET_API_H_ */ |
| 85 | |
| 86 | /* |
| 87 | * fd.io coding-style-patch-verification: ON |
| 88 | * |
| 89 | * Local Variables: |
| 90 | * eval: (c-set-style "gnu") |
| 91 | * End: |
| 92 | */ |