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