blob: f3af300238c802054aaac983b3a1d6a2aefaac73 [file] [log] [blame]
Florin Corase86a8ed2018-01-05 03:20:25 -08001/*
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 Coras4d9b9d82018-01-14 12:25:50 -080022#include <svm/ssvm.h>
Florin Corase86a8ed2018-01-05 03:20:25 -080023#include <vppinfra/file.h>
24
25#define API_SOCKET_FILE "/run/vpp-api.sock"
26
27typedef struct
28{
29 clib_file_t *clib_file;
30 vl_api_registration_t *regp;
31 u8 *data;
32} vl_socket_args_for_process_t;
33
34typedef struct
35{
36 /* Server port number */
37 u8 *socket_name;
38
39 /* By default, localhost... */
40 u32 bind_address;
41
42 /*
43 * (listen, server, client) registrations. Shared memory
44 * registrations are in shared memory
45 */
46 vl_api_registration_t *registration_pool;
47 /*
48 * Chain-drag variables, so message API handlers
49 * (generally) don't know whether they're talking to a socket
50 * or to a shared-memory connection.
51 */
52 vl_api_registration_t *current_rp;
53 clib_file_t *current_uf;
54 /* One input buffer, shared across all sockets */
55 i8 *input_buffer;
56
57 /* pool of process args for socket clients */
58 vl_socket_args_for_process_t *process_args;
59
60 /* Listen for API connections here */
61 clib_socket_t socksvr_listen_socket;
62} socket_main_t;
63
64extern socket_main_t socket_main;
65
66void vl_socket_free_registration_index (u32 pool_index);
67clib_error_t *vl_socket_read_ready (struct clib_file *uf);
Florin Corase86a8ed2018-01-05 03:20:25 -080068clib_error_t *vl_socket_write_ready (struct clib_file *uf);
69void vl_socket_api_send (vl_api_registration_t * rp, u8 * elem);
70void vl_socket_process_api_msg (clib_file_t * uf, vl_api_registration_t * rp,
71 i8 * input_v);
72void vl_sock_api_dump_clients (vlib_main_t * vm, api_main_t * am);
73clib_error_t *vl_sock_api_init (vlib_main_t * vm);
Florin Coras466f2892018-08-03 02:50:43 -070074clib_error_t *vl_sock_api_send_fd_msg (int socket_fd, int fds[], int n_fds);
75clib_error_t *vl_sock_api_recv_fd_msg (int socket_fd, int fds[], int n_fds,
Florin Corasb384b542018-01-15 01:08:33 -080076 u32 wait);
Florin Corase86a8ed2018-01-05 03:20:25 -080077
Florin Coras2881dec2018-10-02 18:29:25 -070078vl_api_registration_t *vl_socket_api_client_handle_to_registration (u32 idx);
79u8 vl_socket_api_registration_handle_is_valid (u32 reg_index);
Ole Troan94495f22018-08-02 11:58:12 +020080
Florin Corase86a8ed2018-01-05 03:20:25 -080081#endif /* SRC_VLIBMEMORY_SOCKET_API_H_ */
82
83/*
84 * fd.io coding-style-patch-verification: ON
85 *
86 * Local Variables:
87 * eval: (c-set-style "gnu")
88 * End:
89 */