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 | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 25 | .app_index = ~0, |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 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 | } |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 173 | free (argv[i]); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | defaulted: |
| 177 | if (fp != NULL) |
| 178 | fclose (fp); |
| 179 | if (argv != NULL) |
| 180 | free (argv); |
| 181 | |
| 182 | vcl_mem = mmap (0, vcl_cfg->heapsize, PROT_READ | PROT_WRITE, |
| 183 | MAP_SHARED | MAP_ANONYMOUS, -1, 0); |
| 184 | if (vcl_mem == MAP_FAILED) |
| 185 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 186 | VCFG_DBG (0, "VCL<%d>: ERROR: mmap(0, %ld == 0x%lx, " |
| 187 | "PROT_READ | PROT_WRITE,MAP_SHARED | MAP_ANONYMOUS, " |
| 188 | "-1, 0) failed!", getpid (), vcl_cfg->heapsize, |
| 189 | vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 190 | ASSERT (vcl_mem != MAP_FAILED); |
| 191 | return; |
| 192 | } |
Dave Barach | 6a5adc3 | 2018-07-04 10:56:23 -0400 | [diff] [blame] | 193 | heap = clib_mem_init_thread_safe (vcl_mem, vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 194 | if (!heap) |
| 195 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 196 | fprintf (stderr, "VCL<%d>: ERROR: clib_mem_init() failed!", getpid ()); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 197 | ASSERT (heap); |
| 198 | return; |
| 199 | } |
| 200 | vcl_mem = clib_mem_alloc (sizeof (_vppcom_main)); |
| 201 | if (!vcl_mem) |
| 202 | { |
| 203 | clib_warning ("VCL<%d>: ERROR: clib_mem_alloc() failed!", getpid ()); |
| 204 | ASSERT (vcl_mem); |
| 205 | return; |
| 206 | } |
| 207 | |
| 208 | clib_memcpy (vcl_mem, &_vppcom_main, sizeof (_vppcom_main)); |
| 209 | vcm = vcl_mem; |
| 210 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 211 | VCFG_DBG (0, "VCL<%d>: allocated VCL heap = %p, size %ld (0x%lx)", |
| 212 | getpid (), heap, vcl_cfg->heapsize, vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | void |
| 216 | vppcom_cfg_read_file (char *conf_fname) |
| 217 | { |
| 218 | vppcom_cfg_t *vcl_cfg = &vcm->cfg; |
| 219 | int fd; |
| 220 | unformat_input_t _input, *input = &_input; |
| 221 | unformat_input_t _line_input, *line_input = &_line_input; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 222 | u8 vc_cfg_input = 0, *chroot_path; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 223 | struct stat s; |
| 224 | u32 uid, gid, q_len; |
| 225 | |
| 226 | fd = open (conf_fname, O_RDONLY); |
| 227 | if (fd < 0) |
| 228 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 229 | VCFG_DBG (0, "VCL<%d>: using default configuration.", getpid ()); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 230 | goto file_done; |
| 231 | } |
| 232 | |
| 233 | if (fstat (fd, &s) < 0) |
| 234 | { |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 235 | VCFG_DBG (0, "VCL<%d>: failed to stat `%s' using default configuration", |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 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; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 257 | unformat_free (line_input); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 258 | continue; |
| 259 | } |
| 260 | |
| 261 | if (vc_cfg_input) |
| 262 | { |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 263 | if (unformat (line_input, "heapsize %U", unformat_memory_size, |
| 264 | &vcl_cfg->heapsize)) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 265 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 266 | VCFG_DBG (0, "VCL<%d>: configured heapsize %lu", getpid (), |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 267 | vcl_cfg->heapsize); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 268 | } |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 269 | else |
| 270 | if (unformat |
| 271 | (line_input, "max-workers %u", &vcl_cfg->max_workers)) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 272 | { |
| 273 | VCFG_DBG (0, "VCL<%d>: configured max-workers %u", getpid (), |
| 274 | vcl_cfg->max_workers); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 275 | } |
| 276 | else if (unformat (line_input, "api-prefix %s", &chroot_path)) |
| 277 | { |
| 278 | vec_terminate_c_string (chroot_path); |
| 279 | if (vcl_cfg->vpp_api_filename) |
| 280 | vec_free (vcl_cfg->vpp_api_filename); |
| 281 | vcl_cfg->vpp_api_filename = format (0, "/%s-vpe-api%c", |
| 282 | chroot_path, 0); |
| 283 | vl_set_memory_root_path ((char *) chroot_path); |
| 284 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 285 | VCFG_DBG (0, "VCL<%d>: configured api-prefix (%s) and api " |
| 286 | "filename (%s)", getpid (), chroot_path, |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 287 | vcl_cfg->vpp_api_filename); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 288 | chroot_path = 0; /* Don't vec_free() it! */ |
| 289 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 290 | else if (unformat (line_input, "api-socket-name %s", |
| 291 | &vcl_cfg->vpp_api_socket_name)) |
| 292 | { |
| 293 | vec_terminate_c_string (vcl_cfg->vpp_api_socket_name); |
| 294 | VCFG_DBG (0, "VCL<%d>: configured api-socket-name (%s)", |
| 295 | getpid (), vcl_cfg->vpp_api_socket_name); |
| 296 | } |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 297 | else if (unformat (line_input, "vpp-api-q-length %d", &q_len)) |
| 298 | { |
| 299 | if (q_len < vcl_cfg->vpp_api_q_length) |
| 300 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 301 | fprintf (stderr, |
| 302 | "VCL<%d>: ERROR: configured vpp-api-q-length " |
| 303 | "(%u) is too small! Using default: %u ", getpid (), |
| 304 | q_len, vcl_cfg->vpp_api_q_length); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 305 | } |
| 306 | else |
| 307 | { |
| 308 | vcl_cfg->vpp_api_q_length = q_len; |
| 309 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 310 | VCFG_DBG (0, "VCL<%d>: configured vpp-api-q-length %u", |
| 311 | getpid (), vcl_cfg->vpp_api_q_length); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | else if (unformat (line_input, "uid %d", &uid)) |
| 315 | { |
| 316 | vl_set_memory_uid (uid); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 317 | VCFG_DBG (0, "VCL<%d>: configured uid %d", getpid (), uid); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 318 | } |
| 319 | else if (unformat (line_input, "gid %d", &gid)) |
| 320 | { |
| 321 | vl_set_memory_gid (gid); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 322 | VCFG_DBG (0, "VCL<%d>: configured gid %d", getpid (), gid); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 323 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 324 | else if (unformat (line_input, "segment-baseva 0x%x", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 325 | &vcl_cfg->segment_baseva)) |
| 326 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 327 | VCFG_DBG (0, "VCL<%d>: configured segment_baseva 0x%lx", |
| 328 | getpid (), vcl_cfg->segment_baseva); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 329 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 330 | else if (unformat (line_input, "segment-size 0x%x", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 331 | &vcl_cfg->segment_size)) |
| 332 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 333 | VCFG_DBG (0, "VCL<%d>: configured segment_size 0x%x (%d)", |
| 334 | getpid (), vcl_cfg->segment_size, |
| 335 | vcl_cfg->segment_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 336 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 337 | else if (unformat (line_input, "segment-size %d", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 338 | &vcl_cfg->segment_size)) |
| 339 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 340 | VCFG_DBG (0, "VCL<%d>: configured segment_size %d (0x%x)", |
| 341 | getpid (), vcl_cfg->segment_size, |
| 342 | vcl_cfg->segment_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 343 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 344 | else if (unformat (line_input, "add-segment-size 0x%x", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 345 | &vcl_cfg->add_segment_size)) |
| 346 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 347 | VCFG_DBG (0, "VCL<%d>: configured add_segment_size 0x%x (%d)", |
| 348 | getpid (), vcl_cfg->add_segment_size, |
| 349 | vcl_cfg->add_segment_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 350 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 351 | else if (unformat (line_input, "add-segment-size %d", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 352 | &vcl_cfg->add_segment_size)) |
| 353 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 354 | VCFG_DBG (0, "VCL<%d>: configured add_segment_size %d (0x%x)", |
| 355 | getpid (), vcl_cfg->add_segment_size, |
| 356 | vcl_cfg->add_segment_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 357 | } |
| 358 | else if (unformat (line_input, "preallocated-fifo-pairs %d", |
| 359 | &vcl_cfg->preallocated_fifo_pairs)) |
| 360 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 361 | VCFG_DBG (0, "VCL<%d>: configured preallocated_fifo_pairs %d " |
| 362 | "(0x%x)", getpid (), vcl_cfg->preallocated_fifo_pairs, |
| 363 | vcl_cfg->preallocated_fifo_pairs); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 364 | } |
| 365 | else if (unformat (line_input, "rx-fifo-size 0x%lx", |
| 366 | &vcl_cfg->rx_fifo_size)) |
| 367 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 368 | VCFG_DBG (0, "VCL<%d>: configured rx_fifo_size 0x%x (%d)", |
| 369 | getpid (), vcl_cfg->rx_fifo_size, |
| 370 | vcl_cfg->rx_fifo_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 371 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 372 | else if (unformat (line_input, "rx-fifo-size %d", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 373 | &vcl_cfg->rx_fifo_size)) |
| 374 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 375 | VCFG_DBG (0, "VCL<%d>: configured rx_fifo_size %d (0x%x)", |
| 376 | getpid (), vcl_cfg->rx_fifo_size, |
| 377 | vcl_cfg->rx_fifo_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 378 | } |
| 379 | else if (unformat (line_input, "tx-fifo-size 0x%lx", |
| 380 | &vcl_cfg->tx_fifo_size)) |
| 381 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 382 | VCFG_DBG (0, "VCL<%d>: configured tx_fifo_size 0x%x (%d)", |
| 383 | getpid (), vcl_cfg->tx_fifo_size, |
| 384 | vcl_cfg->tx_fifo_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 385 | } |
| 386 | else if (unformat (line_input, "tx-fifo-size %ld", |
| 387 | &vcl_cfg->tx_fifo_size)) |
| 388 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 389 | VCFG_DBG (0, "VCL<%d>: configured tx_fifo_size %d (0x%x)", |
| 390 | getpid (), vcl_cfg->tx_fifo_size, |
| 391 | vcl_cfg->tx_fifo_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 392 | } |
| 393 | else if (unformat (line_input, "event-queue-size 0x%lx", |
| 394 | &vcl_cfg->event_queue_size)) |
| 395 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 396 | VCFG_DBG (0, "VCL<%d>: configured event_queue_size 0x%x (%d)", |
| 397 | getpid (), vcl_cfg->event_queue_size, |
| 398 | vcl_cfg->event_queue_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 399 | } |
| 400 | else if (unformat (line_input, "event-queue-size %ld", |
| 401 | &vcl_cfg->event_queue_size)) |
| 402 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 403 | VCFG_DBG (0, "VCL<%d>: configured event_queue_size %d (0x%x)", |
| 404 | getpid (), vcl_cfg->event_queue_size, |
| 405 | vcl_cfg->event_queue_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 406 | } |
| 407 | else if (unformat (line_input, "listen-queue-size 0x%lx", |
| 408 | &vcl_cfg->listen_queue_size)) |
| 409 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 410 | VCFG_DBG (0, "VCL<%d>: configured listen_queue_size 0x%x (%u)", |
| 411 | getpid (), vcl_cfg->listen_queue_size, |
| 412 | vcl_cfg->listen_queue_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 413 | } |
| 414 | else if (unformat (line_input, "listen-queue-size %ld", |
| 415 | &vcl_cfg->listen_queue_size)) |
| 416 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 417 | VCFG_DBG (0, "VCL<%d>: configured listen_queue_size %u (0x%x)", |
| 418 | getpid (), vcl_cfg->listen_queue_size, |
| 419 | vcl_cfg->listen_queue_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 420 | } |
| 421 | else if (unformat (line_input, "app-timeout %f", |
| 422 | &vcl_cfg->app_timeout)) |
| 423 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 424 | VCFG_DBG (0, "VCL<%d>: configured app_timeout %f", |
| 425 | getpid (), vcl_cfg->app_timeout); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 426 | } |
| 427 | else if (unformat (line_input, "session-timeout %f", |
| 428 | &vcl_cfg->session_timeout)) |
| 429 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 430 | VCFG_DBG (0, "VCL<%d>: configured session_timeout %f", |
| 431 | getpid (), vcl_cfg->session_timeout); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 432 | } |
| 433 | else if (unformat (line_input, "accept-timeout %f", |
| 434 | &vcl_cfg->accept_timeout)) |
| 435 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 436 | VCFG_DBG (0, "VCL<%d>: configured accept_timeout %f", |
| 437 | getpid (), vcl_cfg->accept_timeout); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 438 | } |
| 439 | else if (unformat (line_input, "app-proxy-transport-tcp")) |
| 440 | { |
| 441 | vcl_cfg->app_proxy_transport_tcp = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 442 | VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_tcp (%d)", |
| 443 | getpid (), vcl_cfg->app_proxy_transport_tcp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 444 | } |
| 445 | else if (unformat (line_input, "app-proxy-transport-udp")) |
| 446 | { |
| 447 | vcl_cfg->app_proxy_transport_udp = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 448 | VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_udp (%d)", |
| 449 | getpid (), vcl_cfg->app_proxy_transport_udp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 450 | } |
| 451 | else if (unformat (line_input, "app-scope-local")) |
| 452 | { |
| 453 | vcl_cfg->app_scope_local = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 454 | VCFG_DBG (0, "VCL<%d>: configured app_scope_local (%d)", |
| 455 | getpid (), vcl_cfg->app_scope_local); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 456 | } |
| 457 | else if (unformat (line_input, "app-scope-global")) |
| 458 | { |
| 459 | vcl_cfg->app_scope_global = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 460 | VCFG_DBG (0, "VCL<%d>: configured app_scope_global (%d)", |
| 461 | getpid (), vcl_cfg->app_scope_global); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 462 | } |
| 463 | else if (unformat (line_input, "namespace-secret %lu", |
| 464 | &vcl_cfg->namespace_secret)) |
| 465 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 466 | VCFG_DBG (0, "VCL<%d>: configured namespace_secret %lu (0x%lx)", |
| 467 | getpid (), vcl_cfg->namespace_secret, |
| 468 | vcl_cfg->namespace_secret); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 469 | } |
| 470 | else if (unformat (line_input, "namespace-id %v", |
| 471 | &vcl_cfg->namespace_id)) |
| 472 | { |
| 473 | u32 max_nsid_vec_len = vcl_max_nsid_len (); |
| 474 | u32 nsid_vec_len = vec_len (vcl_cfg->namespace_id); |
| 475 | if (nsid_vec_len > max_nsid_vec_len) |
| 476 | { |
| 477 | _vec_len (vcl_cfg->namespace_id) = max_nsid_vec_len; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 478 | VCFG_DBG (0, "VCL<%d>: configured namespace_id is too long," |
| 479 | " truncated to %d characters!", |
| 480 | getpid (), max_nsid_vec_len); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 483 | VCFG_DBG (0, "VCL<%d>: configured namespace_id %s", |
| 484 | getpid (), (char *) vcl_cfg->namespace_id); |
| 485 | } |
| 486 | else if (unformat (line_input, "use-mq-eventfd")) |
| 487 | { |
| 488 | vcl_cfg->use_mq_eventfd = 1; |
| 489 | VCFG_DBG (0, "VCL<%d>: configured with mq with eventfd", |
| 490 | getpid ()); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 491 | } |
| 492 | else if (unformat (line_input, "}")) |
| 493 | { |
| 494 | vc_cfg_input = 0; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 495 | VCFG_DBG (0, "VCL<%d>: completed parsing vppcom config!", |
| 496 | getpid ()); |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 497 | unformat_free (line_input); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 498 | goto input_done; |
| 499 | } |
| 500 | else |
| 501 | { |
| 502 | if (line_input->buffer[line_input->index] != '#') |
| 503 | { |
| 504 | clib_warning ("VCL<%d>: Unknown vppcom config option: '%s'", |
| 505 | getpid (), (char *) |
| 506 | &line_input->buffer[line_input->index]); |
| 507 | } |
| 508 | } |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 509 | unformat_free (line_input); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
| 513 | input_done: |
| 514 | unformat_free (input); |
| 515 | |
| 516 | file_done: |
| 517 | if (fd >= 0) |
| 518 | close (fd); |
| 519 | } |
| 520 | |
| 521 | void |
| 522 | vppcom_cfg (vppcom_cfg_t * vcl_cfg) |
| 523 | { |
| 524 | char *conf_fname, *env_var_str; |
| 525 | |
| 526 | vppcom_cfg_init (vcl_cfg); |
| 527 | env_var_str = getenv (VPPCOM_ENV_DEBUG); |
| 528 | if (env_var_str) |
| 529 | { |
| 530 | u32 tmp; |
| 531 | if (sscanf (env_var_str, "%u", &tmp) != 1) |
Florin Coras | 9686eac | 2018-08-01 17:24:08 -0700 | [diff] [blame] | 532 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 533 | VCFG_DBG (0, "VCL<%d>: WARNING: Invalid debug level specified " |
| 534 | "in the environment variable " VPPCOM_ENV_DEBUG |
| 535 | " (%s)!\n", getpid (), env_var_str); |
Florin Coras | 9686eac | 2018-08-01 17:24:08 -0700 | [diff] [blame] | 536 | } |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 537 | else |
| 538 | { |
| 539 | vcm->debug = tmp; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 540 | VCFG_DBG (0, "VCL<%d>: configured VCL debug level (%u) from " |
| 541 | VPPCOM_ENV_DEBUG "!", getpid (), vcm->debug); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | conf_fname = getenv (VPPCOM_ENV_CONF); |
| 545 | if (!conf_fname) |
| 546 | conf_fname = VPPCOM_CONF_DEFAULT; |
| 547 | vppcom_cfg_heapsize (conf_fname); |
| 548 | vppcom_cfg_read_file (conf_fname); |
| 549 | |
| 550 | env_var_str = getenv (VPPCOM_ENV_API_PREFIX); |
| 551 | if (env_var_str) |
| 552 | { |
| 553 | if (vcl_cfg->vpp_api_filename) |
| 554 | vec_free (vcl_cfg->vpp_api_filename); |
| 555 | vcl_cfg->vpp_api_filename = format (0, "/%s-vpe-api%c", env_var_str, 0); |
| 556 | vl_set_memory_root_path ((char *) env_var_str); |
| 557 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 558 | VCFG_DBG (0, "VCL<%d>: configured api prefix (%s) and filename (%s) " |
| 559 | "from " VPPCOM_ENV_API_PREFIX "!", getpid (), env_var_str, |
| 560 | vcl_cfg->vpp_api_filename); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 561 | } |
| 562 | env_var_str = getenv (VPPCOM_ENV_APP_NAMESPACE_ID); |
| 563 | if (env_var_str) |
| 564 | { |
| 565 | u32 ns_id_vec_len = strlen (env_var_str); |
| 566 | |
| 567 | vec_reset_length (vcm->cfg.namespace_id); |
| 568 | vec_validate (vcm->cfg.namespace_id, ns_id_vec_len - 1); |
| 569 | clib_memcpy (vcm->cfg.namespace_id, env_var_str, ns_id_vec_len); |
| 570 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 571 | VCFG_DBG (0, "VCL<%d>: configured namespace_id (%s) from " |
| 572 | VPPCOM_ENV_APP_NAMESPACE_ID "!", getpid (), |
| 573 | (char *) vcm->cfg.namespace_id); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 574 | } |
| 575 | env_var_str = getenv (VPPCOM_ENV_APP_NAMESPACE_SECRET); |
| 576 | if (env_var_str) |
| 577 | { |
| 578 | u64 tmp; |
| 579 | if (sscanf (env_var_str, "%lu", &tmp) != 1) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 580 | { |
| 581 | VCFG_DBG (0, "VCL<%d>: WARNING: Invalid namespace secret specified" |
| 582 | " in the environment variable " |
| 583 | VPPCOM_ENV_APP_NAMESPACE_SECRET " (%s)!\n", getpid (), |
| 584 | env_var_str); |
| 585 | } |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 586 | else |
| 587 | { |
| 588 | vcm->cfg.namespace_secret = tmp; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 589 | VCFG_DBG (0, "VCL<%d>: configured namespace secret (%lu) from " |
| 590 | VPPCOM_ENV_APP_NAMESPACE_SECRET "!", getpid (), |
| 591 | vcm->cfg.namespace_secret); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 592 | } |
| 593 | } |
| 594 | if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP)) |
| 595 | { |
| 596 | vcm->cfg.app_proxy_transport_tcp = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 597 | VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_tcp (%u) from " |
| 598 | VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP "!", getpid (), |
| 599 | vcm->cfg.app_proxy_transport_tcp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 600 | } |
| 601 | if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP)) |
| 602 | { |
| 603 | vcm->cfg.app_proxy_transport_udp = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 604 | VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_udp (%u) from " |
| 605 | VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP "!", getpid (), |
| 606 | vcm->cfg.app_proxy_transport_udp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 607 | } |
| 608 | if (getenv (VPPCOM_ENV_APP_SCOPE_LOCAL)) |
| 609 | { |
| 610 | vcm->cfg.app_scope_local = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 611 | VCFG_DBG (0, "VCL<%d>: configured app_scope_local (%u) from " |
| 612 | VPPCOM_ENV_APP_SCOPE_LOCAL "!", getpid (), |
| 613 | vcm->cfg.app_scope_local); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 614 | } |
| 615 | if (getenv (VPPCOM_ENV_APP_SCOPE_GLOBAL)) |
| 616 | { |
| 617 | vcm->cfg.app_scope_global = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 618 | VCFG_DBG (0, "VCL<%d>: configured app_scope_global (%u) from " |
| 619 | VPPCOM_ENV_APP_SCOPE_GLOBAL "!", getpid (), |
| 620 | vcm->cfg.app_scope_global); |
| 621 | } |
| 622 | env_var_str = getenv (VPPCOM_ENV_VPP_API_SOCKET); |
| 623 | if (env_var_str) |
| 624 | { |
| 625 | vcm->cfg.vpp_api_socket_name = format (0, "%s%c", env_var_str, 0); |
| 626 | VCFG_DBG (0, "VCL<%d>: configured api-socket-name (%s)", getpid (), |
| 627 | vcl_cfg->vpp_api_socket_name); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 628 | } |
| 629 | } |
| 630 | |
| 631 | /* |
| 632 | * fd.io coding-style-patch-verification: ON |
| 633 | * |
| 634 | * Local Variables: |
| 635 | * eval: (c-set-style "gnu") |
| 636 | * End: |
| 637 | */ |