Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this |
| 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 | #include <vcl/vcl_private.h> |
| 17 | |
| 18 | /* NOTE: _vppcom_main is only used until the heap is allocated. |
| 19 | * Do not access it directly -- use vcm which will point to |
| 20 | * the heap allocated copy after init. |
| 21 | */ |
| 22 | static vppcom_main_t _vppcom_main = { |
| 23 | .debug = VPPCOM_DEBUG_INIT, |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 24 | .is_init = 0, |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 25 | .my_client_index = ~0 |
| 26 | }; |
| 27 | |
| 28 | vppcom_main_t *vcm = &_vppcom_main; |
| 29 | |
| 30 | void |
| 31 | vppcom_cfg_init (vppcom_cfg_t * vcl_cfg) |
| 32 | { |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 33 | ASSERT (vcl_cfg); |
| 34 | |
| 35 | vcl_cfg->heapsize = (256ULL << 20); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 36 | vcl_cfg->max_workers = 16; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 37 | vcl_cfg->vpp_api_q_length = 1024; |
| 38 | vcl_cfg->segment_baseva = 0x200000000ULL; |
| 39 | vcl_cfg->segment_size = (256 << 20); |
| 40 | vcl_cfg->add_segment_size = (128 << 20); |
| 41 | vcl_cfg->preallocated_fifo_pairs = 8; |
| 42 | vcl_cfg->rx_fifo_size = (1 << 20); |
| 43 | vcl_cfg->tx_fifo_size = (1 << 20); |
| 44 | vcl_cfg->event_queue_size = 2048; |
| 45 | vcl_cfg->listen_queue_size = CLIB_CACHE_LINE_BYTES / sizeof (u32); |
| 46 | vcl_cfg->app_timeout = 10 * 60.0; |
| 47 | vcl_cfg->session_timeout = 10 * 60.0; |
| 48 | vcl_cfg->accept_timeout = 60.0; |
| 49 | vcl_cfg->event_ring_size = (128 << 10); |
| 50 | vcl_cfg->event_log_path = "/dev/shm"; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 53 | #define VCFG_DBG(_lvl, _fmt, _args...) \ |
| 54 | { \ |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 55 | if (vcm->debug > _lvl) \ |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 56 | fprintf (stderr, _fmt "\n", ##_args); \ |
| 57 | } |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 58 | void |
| 59 | vppcom_cfg_heapsize (char *conf_fname) |
| 60 | { |
| 61 | vppcom_cfg_t *vcl_cfg = &vcm->cfg; |
| 62 | FILE *fp; |
| 63 | char inbuf[4096]; |
| 64 | int argc = 1; |
| 65 | char **argv = NULL; |
| 66 | char *arg = NULL; |
| 67 | char *p; |
| 68 | int i; |
| 69 | u8 *sizep; |
| 70 | u32 size; |
| 71 | void *vcl_mem; |
| 72 | void *heap; |
| 73 | |
| 74 | fp = fopen (conf_fname, "r"); |
| 75 | if (fp == NULL) |
| 76 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 77 | VCFG_DBG (0, "VCL<%d>: using default heapsize %lu (0x%lx)", |
| 78 | getpid (), vcl_cfg->heapsize, vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 79 | goto defaulted; |
| 80 | } |
| 81 | |
| 82 | argv = calloc (1, sizeof (char *)); |
| 83 | if (argv == NULL) |
| 84 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 85 | VCFG_DBG (0, "VCL<%d>: calloc failed, using default heapsize %lu" |
| 86 | " (0x%lx)", getpid (), vcl_cfg->heapsize, vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 87 | goto defaulted; |
| 88 | } |
| 89 | |
| 90 | while (1) |
| 91 | { |
| 92 | if (fgets (inbuf, 4096, fp) == 0) |
| 93 | break; |
| 94 | p = strtok (inbuf, " \t\n"); |
| 95 | while (p != NULL) |
| 96 | { |
| 97 | if (*p == '#') |
| 98 | break; |
| 99 | argc++; |
| 100 | char **tmp = realloc (argv, argc * sizeof (char *)); |
| 101 | if (tmp == NULL) |
| 102 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 103 | VCFG_DBG (0, "VCL<%d>: realloc failed, using default " |
| 104 | "heapsize %lu (0x%lx)", getpid (), |
| 105 | vcl_cfg->heapsize, vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 106 | goto defaulted; |
| 107 | } |
| 108 | argv = tmp; |
| 109 | arg = strndup (p, 1024); |
| 110 | if (arg == NULL) |
| 111 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 112 | VCFG_DBG (0, "VCL<%d>: strndup failed, using default " |
| 113 | "heapsize %ld (0x%lx)", getpid (), |
| 114 | vcl_cfg->heapsize, vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 115 | goto defaulted; |
| 116 | } |
| 117 | argv[argc - 1] = arg; |
| 118 | p = strtok (NULL, " \t\n"); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | fclose (fp); |
| 123 | fp = NULL; |
| 124 | |
| 125 | char **tmp = realloc (argv, (argc + 1) * sizeof (char *)); |
| 126 | if (tmp == NULL) |
| 127 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 128 | VCFG_DBG (0, "VCL<%d>: realloc failed, using default heapsize %ld " |
| 129 | "(0x%lx)", getpid (), vcl_cfg->heapsize, vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 130 | goto defaulted; |
| 131 | } |
| 132 | argv = tmp; |
| 133 | argv[argc] = NULL; |
| 134 | |
| 135 | /* |
| 136 | * Look for and parse the "heapsize" config parameter. |
| 137 | * Manual since none of the clib infra has been bootstrapped yet. |
| 138 | * |
| 139 | * Format: heapsize <nn>[mM][gG] |
| 140 | */ |
| 141 | |
| 142 | for (i = 1; i < (argc - 1); i++) |
| 143 | { |
| 144 | if (!strncmp (argv[i], "heapsize", 8)) |
| 145 | { |
| 146 | sizep = (u8 *) argv[i + 1]; |
| 147 | size = 0; |
| 148 | while (*sizep >= '0' && *sizep <= '9') |
| 149 | { |
| 150 | size *= 10; |
| 151 | size += *sizep++ - '0'; |
| 152 | } |
| 153 | if (size == 0) |
| 154 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 155 | VCFG_DBG (0, "VCL<%d>: parse error '%s %s', using default " |
| 156 | "heapsize %ld (0x%lx)", getpid (), argv[i], |
| 157 | argv[i + 1], vcl_cfg->heapsize, vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 158 | goto defaulted; |
| 159 | } |
| 160 | |
| 161 | if (*sizep == 'g' || *sizep == 'G') |
| 162 | vcl_cfg->heapsize = size << 30; |
| 163 | else if (*sizep == 'm' || *sizep == 'M') |
| 164 | vcl_cfg->heapsize = size << 20; |
| 165 | else |
| 166 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 167 | VCFG_DBG (0, "VCL<%d>: parse error '%s %s', using default " |
| 168 | "heapsize %ld (0x%lx)", getpid (), argv[i], |
| 169 | argv[i + 1], vcl_cfg->heapsize, vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 170 | goto defaulted; |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | defaulted: |
| 176 | if (fp != NULL) |
| 177 | fclose (fp); |
| 178 | if (argv != NULL) |
| 179 | free (argv); |
| 180 | |
| 181 | vcl_mem = mmap (0, vcl_cfg->heapsize, PROT_READ | PROT_WRITE, |
| 182 | MAP_SHARED | MAP_ANONYMOUS, -1, 0); |
| 183 | if (vcl_mem == MAP_FAILED) |
| 184 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 185 | VCFG_DBG (0, "VCL<%d>: ERROR: mmap(0, %ld == 0x%lx, " |
| 186 | "PROT_READ | PROT_WRITE,MAP_SHARED | MAP_ANONYMOUS, " |
| 187 | "-1, 0) failed!", getpid (), vcl_cfg->heapsize, |
| 188 | vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 189 | ASSERT (vcl_mem != MAP_FAILED); |
| 190 | return; |
| 191 | } |
Dave Barach | 6a5adc3 | 2018-07-04 10:56:23 -0400 | [diff] [blame] | 192 | heap = clib_mem_init_thread_safe (vcl_mem, vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 193 | if (!heap) |
| 194 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 195 | fprintf (stderr, "VCL<%d>: ERROR: clib_mem_init() failed!", getpid ()); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 196 | ASSERT (heap); |
| 197 | return; |
| 198 | } |
| 199 | vcl_mem = clib_mem_alloc (sizeof (_vppcom_main)); |
| 200 | if (!vcl_mem) |
| 201 | { |
| 202 | clib_warning ("VCL<%d>: ERROR: clib_mem_alloc() failed!", getpid ()); |
| 203 | ASSERT (vcl_mem); |
| 204 | return; |
| 205 | } |
| 206 | |
| 207 | clib_memcpy (vcl_mem, &_vppcom_main, sizeof (_vppcom_main)); |
| 208 | vcm = vcl_mem; |
| 209 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 210 | VCFG_DBG (0, "VCL<%d>: allocated VCL heap = %p, size %ld (0x%lx)", |
| 211 | getpid (), heap, vcl_cfg->heapsize, vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | void |
| 215 | vppcom_cfg_read_file (char *conf_fname) |
| 216 | { |
| 217 | vppcom_cfg_t *vcl_cfg = &vcm->cfg; |
| 218 | int fd; |
| 219 | unformat_input_t _input, *input = &_input; |
| 220 | unformat_input_t _line_input, *line_input = &_line_input; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 221 | u8 vc_cfg_input = 0, *chroot_path; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 222 | struct stat s; |
| 223 | u32 uid, gid, q_len; |
| 224 | |
| 225 | fd = open (conf_fname, O_RDONLY); |
| 226 | if (fd < 0) |
| 227 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 228 | VCFG_DBG (0, "VCL<%d>: using default configuration.", getpid ()); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 229 | goto file_done; |
| 230 | } |
| 231 | |
| 232 | if (fstat (fd, &s) < 0) |
| 233 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 234 | VCFG_DBG (0, |
| 235 | "VCL<%d>: failed to stat `%s', using default configuration", |
| 236 | getpid (), conf_fname); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 237 | goto file_done; |
| 238 | } |
| 239 | |
| 240 | if (!(S_ISREG (s.st_mode) || S_ISLNK (s.st_mode))) |
| 241 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 242 | VCFG_DBG (0, "VCL<%d>: not a regular file `%s', using default " |
| 243 | "configuration", getpid (), conf_fname); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 244 | goto file_done; |
| 245 | } |
| 246 | |
| 247 | unformat_init_clib_file (input, fd); |
| 248 | |
| 249 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 250 | { |
| 251 | (void) unformat_user (input, unformat_line_input, line_input); |
| 252 | unformat_skip_white_space (line_input); |
| 253 | |
| 254 | if (unformat (line_input, "vcl {")) |
| 255 | { |
| 256 | vc_cfg_input = 1; |
| 257 | continue; |
| 258 | } |
| 259 | |
| 260 | if (vc_cfg_input) |
| 261 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 262 | if (unformat (line_input, "heapsize %lu", &vcl_cfg->heapsize)) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 263 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 264 | VCFG_DBG (0, "VCL<%d>: configured heapsize %lu", getpid (), |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 265 | vcl_cfg->heapsize); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 266 | } |
| 267 | if (unformat (line_input, "max-workers %u", &vcl_cfg->max_workers)) |
| 268 | { |
| 269 | VCFG_DBG (0, "VCL<%d>: configured max-workers %u", getpid (), |
| 270 | vcl_cfg->max_workers); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 271 | } |
| 272 | else if (unformat (line_input, "api-prefix %s", &chroot_path)) |
| 273 | { |
| 274 | vec_terminate_c_string (chroot_path); |
| 275 | if (vcl_cfg->vpp_api_filename) |
| 276 | vec_free (vcl_cfg->vpp_api_filename); |
| 277 | vcl_cfg->vpp_api_filename = format (0, "/%s-vpe-api%c", |
| 278 | chroot_path, 0); |
| 279 | vl_set_memory_root_path ((char *) chroot_path); |
| 280 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 281 | VCFG_DBG (0, "VCL<%d>: configured api-prefix (%s) and api " |
| 282 | "filename (%s)", getpid (), chroot_path, |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 283 | vcl_cfg->vpp_api_filename); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 284 | chroot_path = 0; /* Don't vec_free() it! */ |
| 285 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 286 | else if (unformat (line_input, "api-socket-name %s", |
| 287 | &vcl_cfg->vpp_api_socket_name)) |
| 288 | { |
| 289 | vec_terminate_c_string (vcl_cfg->vpp_api_socket_name); |
| 290 | VCFG_DBG (0, "VCL<%d>: configured api-socket-name (%s)", |
| 291 | getpid (), vcl_cfg->vpp_api_socket_name); |
| 292 | } |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 293 | else if (unformat (line_input, "vpp-api-q-length %d", &q_len)) |
| 294 | { |
| 295 | if (q_len < vcl_cfg->vpp_api_q_length) |
| 296 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 297 | fprintf (stderr, |
| 298 | "VCL<%d>: ERROR: configured vpp-api-q-length " |
| 299 | "(%u) is too small! Using default: %u ", getpid (), |
| 300 | q_len, vcl_cfg->vpp_api_q_length); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 301 | } |
| 302 | else |
| 303 | { |
| 304 | vcl_cfg->vpp_api_q_length = q_len; |
| 305 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 306 | VCFG_DBG (0, "VCL<%d>: configured vpp-api-q-length %u", |
| 307 | getpid (), vcl_cfg->vpp_api_q_length); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | else if (unformat (line_input, "uid %d", &uid)) |
| 311 | { |
| 312 | vl_set_memory_uid (uid); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 313 | VCFG_DBG (0, "VCL<%d>: configured uid %d", getpid (), uid); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 314 | } |
| 315 | else if (unformat (line_input, "gid %d", &gid)) |
| 316 | { |
| 317 | vl_set_memory_gid (gid); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 318 | VCFG_DBG (0, "VCL<%d>: configured gid %d", getpid (), gid); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 319 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 320 | else if (unformat (line_input, "segment-baseva 0x%x", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 321 | &vcl_cfg->segment_baseva)) |
| 322 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 323 | VCFG_DBG (0, "VCL<%d>: configured segment_baseva 0x%lx", |
| 324 | getpid (), vcl_cfg->segment_baseva); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 325 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 326 | else if (unformat (line_input, "segment-size 0x%x", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 327 | &vcl_cfg->segment_size)) |
| 328 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 329 | VCFG_DBG (0, "VCL<%d>: configured segment_size 0x%x (%d)", |
| 330 | getpid (), vcl_cfg->segment_size, |
| 331 | vcl_cfg->segment_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 332 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 333 | else if (unformat (line_input, "segment-size %d", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 334 | &vcl_cfg->segment_size)) |
| 335 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 336 | VCFG_DBG (0, "VCL<%d>: configured segment_size %d (0x%x)", |
| 337 | getpid (), vcl_cfg->segment_size, |
| 338 | vcl_cfg->segment_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 339 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 340 | else if (unformat (line_input, "add-segment-size 0x%x", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 341 | &vcl_cfg->add_segment_size)) |
| 342 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 343 | VCFG_DBG (0, "VCL<%d>: configured add_segment_size 0x%x (%d)", |
| 344 | getpid (), vcl_cfg->add_segment_size, |
| 345 | vcl_cfg->add_segment_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 346 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 347 | else if (unformat (line_input, "add-segment-size %d", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 348 | &vcl_cfg->add_segment_size)) |
| 349 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 350 | VCFG_DBG (0, "VCL<%d>: configured add_segment_size %d (0x%x)", |
| 351 | getpid (), vcl_cfg->add_segment_size, |
| 352 | vcl_cfg->add_segment_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 353 | } |
| 354 | else if (unformat (line_input, "preallocated-fifo-pairs %d", |
| 355 | &vcl_cfg->preallocated_fifo_pairs)) |
| 356 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 357 | VCFG_DBG (0, "VCL<%d>: configured preallocated_fifo_pairs %d " |
| 358 | "(0x%x)", getpid (), vcl_cfg->preallocated_fifo_pairs, |
| 359 | vcl_cfg->preallocated_fifo_pairs); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 360 | } |
| 361 | else if (unformat (line_input, "rx-fifo-size 0x%lx", |
| 362 | &vcl_cfg->rx_fifo_size)) |
| 363 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 364 | VCFG_DBG (0, "VCL<%d>: configured rx_fifo_size 0x%x (%d)", |
| 365 | getpid (), vcl_cfg->rx_fifo_size, |
| 366 | vcl_cfg->rx_fifo_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 367 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 368 | else if (unformat (line_input, "rx-fifo-size %d", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 369 | &vcl_cfg->rx_fifo_size)) |
| 370 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 371 | VCFG_DBG (0, "VCL<%d>: configured rx_fifo_size %d (0x%x)", |
| 372 | getpid (), vcl_cfg->rx_fifo_size, |
| 373 | vcl_cfg->rx_fifo_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 374 | } |
| 375 | else if (unformat (line_input, "tx-fifo-size 0x%lx", |
| 376 | &vcl_cfg->tx_fifo_size)) |
| 377 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 378 | VCFG_DBG (0, "VCL<%d>: configured tx_fifo_size 0x%x (%d)", |
| 379 | getpid (), vcl_cfg->tx_fifo_size, |
| 380 | vcl_cfg->tx_fifo_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 381 | } |
| 382 | else if (unformat (line_input, "tx-fifo-size %ld", |
| 383 | &vcl_cfg->tx_fifo_size)) |
| 384 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 385 | VCFG_DBG (0, "VCL<%d>: configured tx_fifo_size %d (0x%x)", |
| 386 | getpid (), vcl_cfg->tx_fifo_size, |
| 387 | vcl_cfg->tx_fifo_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 388 | } |
| 389 | else if (unformat (line_input, "event-queue-size 0x%lx", |
| 390 | &vcl_cfg->event_queue_size)) |
| 391 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 392 | VCFG_DBG (0, "VCL<%d>: configured event_queue_size 0x%x (%d)", |
| 393 | getpid (), vcl_cfg->event_queue_size, |
| 394 | vcl_cfg->event_queue_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 395 | } |
| 396 | else if (unformat (line_input, "event-queue-size %ld", |
| 397 | &vcl_cfg->event_queue_size)) |
| 398 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 399 | VCFG_DBG (0, "VCL<%d>: configured event_queue_size %d (0x%x)", |
| 400 | getpid (), vcl_cfg->event_queue_size, |
| 401 | vcl_cfg->event_queue_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 402 | } |
| 403 | else if (unformat (line_input, "listen-queue-size 0x%lx", |
| 404 | &vcl_cfg->listen_queue_size)) |
| 405 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 406 | VCFG_DBG (0, "VCL<%d>: configured listen_queue_size 0x%x (%u)", |
| 407 | getpid (), vcl_cfg->listen_queue_size, |
| 408 | vcl_cfg->listen_queue_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 409 | } |
| 410 | else if (unformat (line_input, "listen-queue-size %ld", |
| 411 | &vcl_cfg->listen_queue_size)) |
| 412 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 413 | VCFG_DBG (0, "VCL<%d>: configured listen_queue_size %u (0x%x)", |
| 414 | getpid (), vcl_cfg->listen_queue_size, |
| 415 | vcl_cfg->listen_queue_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 416 | } |
| 417 | else if (unformat (line_input, "app-timeout %f", |
| 418 | &vcl_cfg->app_timeout)) |
| 419 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 420 | VCFG_DBG (0, "VCL<%d>: configured app_timeout %f", |
| 421 | getpid (), vcl_cfg->app_timeout); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 422 | } |
| 423 | else if (unformat (line_input, "session-timeout %f", |
| 424 | &vcl_cfg->session_timeout)) |
| 425 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 426 | VCFG_DBG (0, "VCL<%d>: configured session_timeout %f", |
| 427 | getpid (), vcl_cfg->session_timeout); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 428 | } |
| 429 | else if (unformat (line_input, "accept-timeout %f", |
| 430 | &vcl_cfg->accept_timeout)) |
| 431 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 432 | VCFG_DBG (0, "VCL<%d>: configured accept_timeout %f", |
| 433 | getpid (), vcl_cfg->accept_timeout); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 434 | } |
| 435 | else if (unformat (line_input, "app-proxy-transport-tcp")) |
| 436 | { |
| 437 | vcl_cfg->app_proxy_transport_tcp = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 438 | VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_tcp (%d)", |
| 439 | getpid (), vcl_cfg->app_proxy_transport_tcp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 440 | } |
| 441 | else if (unformat (line_input, "app-proxy-transport-udp")) |
| 442 | { |
| 443 | vcl_cfg->app_proxy_transport_udp = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 444 | VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_udp (%d)", |
| 445 | getpid (), vcl_cfg->app_proxy_transport_udp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 446 | } |
| 447 | else if (unformat (line_input, "app-scope-local")) |
| 448 | { |
| 449 | vcl_cfg->app_scope_local = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 450 | VCFG_DBG (0, "VCL<%d>: configured app_scope_local (%d)", |
| 451 | getpid (), vcl_cfg->app_scope_local); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 452 | } |
| 453 | else if (unformat (line_input, "app-scope-global")) |
| 454 | { |
| 455 | vcl_cfg->app_scope_global = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 456 | VCFG_DBG (0, "VCL<%d>: configured app_scope_global (%d)", |
| 457 | getpid (), vcl_cfg->app_scope_global); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 458 | } |
| 459 | else if (unformat (line_input, "namespace-secret %lu", |
| 460 | &vcl_cfg->namespace_secret)) |
| 461 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 462 | VCFG_DBG (0, "VCL<%d>: configured namespace_secret %lu (0x%lx)", |
| 463 | getpid (), vcl_cfg->namespace_secret, |
| 464 | vcl_cfg->namespace_secret); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 465 | } |
| 466 | else if (unformat (line_input, "namespace-id %v", |
| 467 | &vcl_cfg->namespace_id)) |
| 468 | { |
| 469 | u32 max_nsid_vec_len = vcl_max_nsid_len (); |
| 470 | u32 nsid_vec_len = vec_len (vcl_cfg->namespace_id); |
| 471 | if (nsid_vec_len > max_nsid_vec_len) |
| 472 | { |
| 473 | _vec_len (vcl_cfg->namespace_id) = max_nsid_vec_len; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 474 | VCFG_DBG (0, "VCL<%d>: configured namespace_id is too long," |
| 475 | " truncated to %d characters!", |
| 476 | getpid (), max_nsid_vec_len); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 479 | VCFG_DBG (0, "VCL<%d>: configured namespace_id %s", |
| 480 | getpid (), (char *) vcl_cfg->namespace_id); |
| 481 | } |
| 482 | else if (unformat (line_input, "use-mq-eventfd")) |
| 483 | { |
| 484 | vcl_cfg->use_mq_eventfd = 1; |
| 485 | VCFG_DBG (0, "VCL<%d>: configured with mq with eventfd", |
| 486 | getpid ()); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 487 | } |
| 488 | else if (unformat (line_input, "}")) |
| 489 | { |
| 490 | vc_cfg_input = 0; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 491 | VCFG_DBG (0, "VCL<%d>: completed parsing vppcom config!", |
| 492 | getpid ()); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 493 | goto input_done; |
| 494 | } |
| 495 | else |
| 496 | { |
| 497 | if (line_input->buffer[line_input->index] != '#') |
| 498 | { |
| 499 | clib_warning ("VCL<%d>: Unknown vppcom config option: '%s'", |
| 500 | getpid (), (char *) |
| 501 | &line_input->buffer[line_input->index]); |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | input_done: |
| 508 | unformat_free (input); |
| 509 | |
| 510 | file_done: |
| 511 | if (fd >= 0) |
| 512 | close (fd); |
| 513 | } |
| 514 | |
| 515 | void |
| 516 | vppcom_cfg (vppcom_cfg_t * vcl_cfg) |
| 517 | { |
| 518 | char *conf_fname, *env_var_str; |
| 519 | |
| 520 | vppcom_cfg_init (vcl_cfg); |
| 521 | env_var_str = getenv (VPPCOM_ENV_DEBUG); |
| 522 | if (env_var_str) |
| 523 | { |
| 524 | u32 tmp; |
| 525 | if (sscanf (env_var_str, "%u", &tmp) != 1) |
Florin Coras | 9686eac | 2018-08-01 17:24:08 -0700 | [diff] [blame] | 526 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 527 | VCFG_DBG (0, "VCL<%d>: WARNING: Invalid debug level specified " |
| 528 | "in the environment variable " VPPCOM_ENV_DEBUG |
| 529 | " (%s)!\n", getpid (), env_var_str); |
Florin Coras | 9686eac | 2018-08-01 17:24:08 -0700 | [diff] [blame] | 530 | } |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 531 | else |
| 532 | { |
| 533 | vcm->debug = tmp; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 534 | VCFG_DBG (0, "VCL<%d>: configured VCL debug level (%u) from " |
| 535 | VPPCOM_ENV_DEBUG "!", getpid (), vcm->debug); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | conf_fname = getenv (VPPCOM_ENV_CONF); |
| 539 | if (!conf_fname) |
| 540 | conf_fname = VPPCOM_CONF_DEFAULT; |
| 541 | vppcom_cfg_heapsize (conf_fname); |
| 542 | vppcom_cfg_read_file (conf_fname); |
| 543 | |
| 544 | env_var_str = getenv (VPPCOM_ENV_API_PREFIX); |
| 545 | if (env_var_str) |
| 546 | { |
| 547 | if (vcl_cfg->vpp_api_filename) |
| 548 | vec_free (vcl_cfg->vpp_api_filename); |
| 549 | vcl_cfg->vpp_api_filename = format (0, "/%s-vpe-api%c", env_var_str, 0); |
| 550 | vl_set_memory_root_path ((char *) env_var_str); |
| 551 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 552 | VCFG_DBG (0, "VCL<%d>: configured api prefix (%s) and filename (%s) " |
| 553 | "from " VPPCOM_ENV_API_PREFIX "!", getpid (), env_var_str, |
| 554 | vcl_cfg->vpp_api_filename); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 555 | } |
| 556 | env_var_str = getenv (VPPCOM_ENV_APP_NAMESPACE_ID); |
| 557 | if (env_var_str) |
| 558 | { |
| 559 | u32 ns_id_vec_len = strlen (env_var_str); |
| 560 | |
| 561 | vec_reset_length (vcm->cfg.namespace_id); |
| 562 | vec_validate (vcm->cfg.namespace_id, ns_id_vec_len - 1); |
| 563 | clib_memcpy (vcm->cfg.namespace_id, env_var_str, ns_id_vec_len); |
| 564 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 565 | VCFG_DBG (0, "VCL<%d>: configured namespace_id (%s) from " |
| 566 | VPPCOM_ENV_APP_NAMESPACE_ID "!", getpid (), |
| 567 | (char *) vcm->cfg.namespace_id); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 568 | } |
| 569 | env_var_str = getenv (VPPCOM_ENV_APP_NAMESPACE_SECRET); |
| 570 | if (env_var_str) |
| 571 | { |
| 572 | u64 tmp; |
| 573 | if (sscanf (env_var_str, "%lu", &tmp) != 1) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 574 | { |
| 575 | VCFG_DBG (0, "VCL<%d>: WARNING: Invalid namespace secret specified" |
| 576 | " in the environment variable " |
| 577 | VPPCOM_ENV_APP_NAMESPACE_SECRET " (%s)!\n", getpid (), |
| 578 | env_var_str); |
| 579 | } |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 580 | else |
| 581 | { |
| 582 | vcm->cfg.namespace_secret = tmp; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 583 | VCFG_DBG (0, "VCL<%d>: configured namespace secret (%lu) from " |
| 584 | VPPCOM_ENV_APP_NAMESPACE_SECRET "!", getpid (), |
| 585 | vcm->cfg.namespace_secret); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP)) |
| 589 | { |
| 590 | vcm->cfg.app_proxy_transport_tcp = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 591 | VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_tcp (%u) from " |
| 592 | VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP "!", getpid (), |
| 593 | vcm->cfg.app_proxy_transport_tcp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 594 | } |
| 595 | if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP)) |
| 596 | { |
| 597 | vcm->cfg.app_proxy_transport_udp = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 598 | VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_udp (%u) from " |
| 599 | VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP "!", getpid (), |
| 600 | vcm->cfg.app_proxy_transport_udp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 601 | } |
| 602 | if (getenv (VPPCOM_ENV_APP_SCOPE_LOCAL)) |
| 603 | { |
| 604 | vcm->cfg.app_scope_local = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 605 | VCFG_DBG (0, "VCL<%d>: configured app_scope_local (%u) from " |
| 606 | VPPCOM_ENV_APP_SCOPE_LOCAL "!", getpid (), |
| 607 | vcm->cfg.app_scope_local); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 608 | } |
| 609 | if (getenv (VPPCOM_ENV_APP_SCOPE_GLOBAL)) |
| 610 | { |
| 611 | vcm->cfg.app_scope_global = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 612 | VCFG_DBG (0, "VCL<%d>: configured app_scope_global (%u) from " |
| 613 | VPPCOM_ENV_APP_SCOPE_GLOBAL "!", getpid (), |
| 614 | vcm->cfg.app_scope_global); |
| 615 | } |
| 616 | env_var_str = getenv (VPPCOM_ENV_VPP_API_SOCKET); |
| 617 | if (env_var_str) |
| 618 | { |
| 619 | vcm->cfg.vpp_api_socket_name = format (0, "%s%c", env_var_str, 0); |
| 620 | VCFG_DBG (0, "VCL<%d>: configured api-socket-name (%s)", getpid (), |
| 621 | vcl_cfg->vpp_api_socket_name); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | |
| 625 | /* |
| 626 | * fd.io coding-style-patch-verification: ON |
| 627 | * |
| 628 | * Local Variables: |
| 629 | * eval: (c-set-style "gnu") |
| 630 | * End: |
| 631 | */ |