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