FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
unix.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 /*
16  * unix.h: Unix specific main state
17  *
18  * Copyright (c) 2008 Eliot Dresselhaus
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 
40 #ifndef included_unix_unix_h
41 #define included_unix_unix_h
42 
43 #include <vppinfra/file.h>
44 #include <vppinfra/socket.h>
45 #include <termios.h>
46 
47 typedef struct
48 {
52 
53 typedef struct
54 {
55  /* Back pointer to main structure. */
57 
59  /* Run interactively or as daemon (background process). */
60 #define UNIX_FLAG_INTERACTIVE (1 << 0)
61 #define UNIX_FLAG_NODAEMON (1 << 1)
62 #define UNIX_FLAG_NOSYSLOG (1 << 2)
63 #define UNIX_FLAG_NOCOLOR (1 << 3)
64 #define UNIX_FLAG_NOBANNER (1 << 4)
65 
66 
67  /* CLI listen socket. */
69 
70  /* Circular buffer of last unix errors. */
71  unix_error_history_t error_history[128];
74 
75  /* startup-config filename */
77 
78  /* runtime directory path */
80 
81  /* pidfile filename */
83 
84  /* unix config complete */
85  volatile int unix_config_complete;
86 
87  /* CLI log file. GIGO. */
89  int log_fd;
90 
91  /* Don't put CLI connections into character mode */
93 
94  /* Maximum amount of command line history to keep per session */
96 
97  /* Suppress the welcome banner at CLI session start */
99 
100  /* Maximum pager buffer size */
102 
103  /* Suppress the pager */
105 
106  /* Store the original state of stdin when it's a tty */
107  struct termios tio_stdin;
109 
111 
112 } unix_main_t;
113 
114 /** CLI session events. */
115 typedef enum
116 {
117  UNIX_CLI_PROCESS_EVENT_READ_READY, /**< A file descriptor has data to be
118  read. */
119  UNIX_CLI_PROCESS_EVENT_QUIT, /**< A CLI session wants to close. */
121 
122 /* Global main structure. */
123 extern unix_main_t unix_main;
125 
126 always_inline void
128 {
131  eh->error = error;
132  eh->time = vlib_time_now (um->vlib_main);
133  um->n_total_errors += 1;
134  if (++um->error_history_index >= ARRAY_LEN (um->error_history))
135  um->error_history_index = 0;
136 }
137 
138 /* Main function for Unix VLIB. */
139 int vlib_unix_main (int argc, char *argv[]);
140 
141 /* Set prompt for CLI. */
142 void vlib_unix_cli_set_prompt (char *prompt);
143 
144 static inline unix_main_t *
146 {
147  return &unix_main;
148 }
149 
150 static inline char *
152 {
153  return (char *) unix_main.runtime_dir;
154 }
155 
156 /* thread stack array; vec_len = max number of threads */
157 extern u8 **vlib_thread_stacks;
158 
159 /* utils */
160 
161 clib_error_t *foreach_directory_file (char *dir_name,
162  clib_error_t * (*f) (void *arg,
163  u8 * path_name,
164  u8 * file_name),
165  void *arg, int scan_dirs);
166 
168 
170  const char *path,
171  u8 ** full_path);
172 
173 #endif /* included_unix_unix_h */
174 
175 /*
176  * fd.io coding-style-patch-verification: ON
177  *
178  * Local Variables:
179  * eval: (c-set-style "gnu")
180  * End:
181  */
unix_main_t::unix_config_complete
volatile int unix_config_complete
Definition: unix.h:85
unix_main_t::flags
u32 flags
Definition: unix.h:58
vlib_unix_get_main
static unix_main_t * vlib_unix_get_main(void)
Definition: unix.h:145
foreach_directory_file
clib_error_t * foreach_directory_file(char *dir_name, clib_error_t *(*f)(void *arg, u8 *path_name, u8 *file_name), void *arg, int scan_dirs)
Definition: util.c:49
unix_cli_process_event_type_t
unix_cli_process_event_type_t
CLI session events.
Definition: unix.h:115
f
vlib_frame_t * f
Definition: interface_output.c:1098
vlib_unix_validate_runtime_file
clib_error_t * vlib_unix_validate_runtime_file(unix_main_t *um, const char *path, u8 **full_path)
Definition: util.c:138
path
vl_api_fib_path_t path
Definition: mfib_types.api:44
vlib_unix_main
int vlib_unix_main(int argc, char *argv[])
Definition: main.c:694
unix_main_t
Definition: unix.h:53
vlib_unix_cli_set_prompt
void vlib_unix_cli_set_prompt(char *prompt)
Set the CLI prompt.
Definition: cli.c:3288
unix_main_t::error_history_index
u32 error_history_index
Definition: unix.h:72
clib_file_main_t
Definition: file.h:85
unix_main_t::runtime_dir
u8 * runtime_dir
Definition: unix.h:79
unix_save_error
static void unix_save_error(unix_main_t *um, clib_error_t *error)
Definition: unix.h:127
unix_main_t::log_fd
int log_fd
Definition: unix.h:89
error
Definition: cJSON.c:88
unix_main_t::vlib_main
vlib_main_t * vlib_main
Definition: unix.h:56
unix_main_t::pidfile
u8 * pidfile
Definition: unix.h:82
unix_main_t::cli_listen_socket
clib_socket_t cli_listen_socket
Definition: unix.h:68
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
unix_main_t::cli_pager_buffer_limit
u32 cli_pager_buffer_limit
Definition: unix.h:101
UNIX_CLI_PROCESS_EVENT_QUIT
@ UNIX_CLI_PROCESS_EVENT_QUIT
A CLI session wants to close.
Definition: unix.h:119
unix_error_history_t::time
f64 time
Definition: unix.h:49
vlib_unix_get_runtime_dir
static char * vlib_unix_get_runtime_dir(void)
Definition: unix.h:151
unix_main_t::poll_sleep_usec
u32 poll_sleep_usec
Definition: unix.h:110
f64
double f64
Definition: types.h:142
vlib_unix_recursive_mkdir
clib_error_t * vlib_unix_recursive_mkdir(char *path)
Definition: util.c:103
unix_main_t::log_filename
u8 * log_filename
Definition: unix.h:88
unix_main_t::startup_config_filename
u8 * startup_config_filename
Definition: unix.h:76
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
UNIX_CLI_PROCESS_EVENT_READ_READY
@ UNIX_CLI_PROCESS_EVENT_READ_READY
A file descriptor has data to be read.
Definition: unix.h:117
u64
unsigned long u64
Definition: types.h:89
unix_main_t::n_total_errors
u64 n_total_errors
Definition: unix.h:73
u32
unsigned int u32
Definition: types.h:88
unix_main_t::cli_history_limit
u32 cli_history_limit
Definition: unix.h:95
unix_main_t::cli_no_banner
int cli_no_banner
Definition: unix.h:98
unix_main
unix_main_t unix_main
Definition: main.c:62
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
unix_main_t::error_history
unix_error_history_t error_history[128]
Definition: unix.h:71
unix_main_t::cli_no_pager
int cli_no_pager
Definition: unix.h:104
file.h
file_main
clib_file_main_t file_main
Definition: main.c:63
vlib_time_now
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:327
socket.h
clib_socket_t
struct _socket_t clib_socket_t
unix_main_t::cli_line_mode
int cli_line_mode
Definition: unix.h:92
unix_error_history_t::error
clib_error_t * error
Definition: unix.h:50
vlib_thread_stacks
u8 ** vlib_thread_stacks
Definition: main.c:659
unix_main_t::tio_isset
int tio_isset
Definition: unix.h:108
unix_error_history_t
Definition: unix.h:47
clib_error_free_vector
__clib_export void * clib_error_free_vector(clib_error_t *errors)
Definition: error.c:182