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 | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 52 | #define VCFG_DBG(_lvl, _fmt, _args...) \ |
| 53 | { \ |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 54 | if (vcm->debug > _lvl) \ |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 55 | fprintf (stderr, _fmt "\n", ##_args); \ |
| 56 | } |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 57 | void |
| 58 | vppcom_cfg_heapsize (char *conf_fname) |
| 59 | { |
| 60 | vppcom_cfg_t *vcl_cfg = &vcm->cfg; |
| 61 | FILE *fp; |
| 62 | char inbuf[4096]; |
| 63 | int argc = 1; |
| 64 | char **argv = NULL; |
| 65 | char *arg = NULL; |
| 66 | char *p; |
| 67 | int i; |
| 68 | u8 *sizep; |
| 69 | u32 size; |
| 70 | void *vcl_mem; |
| 71 | void *heap; |
| 72 | |
| 73 | fp = fopen (conf_fname, "r"); |
| 74 | if (fp == NULL) |
| 75 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 76 | VCFG_DBG (0, "VCL<%d>: using default heapsize %lu (0x%lx)", |
| 77 | getpid (), vcl_cfg->heapsize, vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 78 | goto defaulted; |
| 79 | } |
| 80 | |
| 81 | argv = calloc (1, sizeof (char *)); |
| 82 | if (argv == NULL) |
| 83 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 84 | VCFG_DBG (0, "VCL<%d>: calloc failed, using default heapsize %lu" |
| 85 | " (0x%lx)", getpid (), vcl_cfg->heapsize, vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 86 | goto defaulted; |
| 87 | } |
| 88 | |
| 89 | while (1) |
| 90 | { |
| 91 | if (fgets (inbuf, 4096, fp) == 0) |
| 92 | break; |
| 93 | p = strtok (inbuf, " \t\n"); |
| 94 | while (p != NULL) |
| 95 | { |
| 96 | if (*p == '#') |
| 97 | break; |
| 98 | argc++; |
| 99 | char **tmp = realloc (argv, argc * sizeof (char *)); |
| 100 | if (tmp == NULL) |
| 101 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 102 | VCFG_DBG (0, "VCL<%d>: realloc failed, using default " |
| 103 | "heapsize %lu (0x%lx)", getpid (), |
| 104 | vcl_cfg->heapsize, vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 105 | goto defaulted; |
| 106 | } |
| 107 | argv = tmp; |
| 108 | arg = strndup (p, 1024); |
| 109 | if (arg == NULL) |
| 110 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 111 | VCFG_DBG (0, "VCL<%d>: strndup failed, using default " |
| 112 | "heapsize %ld (0x%lx)", getpid (), |
| 113 | vcl_cfg->heapsize, vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 114 | goto defaulted; |
| 115 | } |
| 116 | argv[argc - 1] = arg; |
| 117 | p = strtok (NULL, " \t\n"); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | fclose (fp); |
| 122 | fp = NULL; |
| 123 | |
| 124 | char **tmp = realloc (argv, (argc + 1) * sizeof (char *)); |
| 125 | if (tmp == NULL) |
| 126 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 127 | VCFG_DBG (0, "VCL<%d>: realloc failed, using default heapsize %ld " |
| 128 | "(0x%lx)", getpid (), vcl_cfg->heapsize, 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 | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 154 | VCFG_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 | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 166 | VCFG_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 | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 184 | VCFG_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 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 209 | VCFG_DBG (0, "VCL<%d>: allocated VCL heap = %p, size %ld (0x%lx)", |
| 210 | getpid (), heap, vcl_cfg->heapsize, vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 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; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 220 | u8 vc_cfg_input = 0, *chroot_path; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 221 | struct stat s; |
| 222 | u32 uid, gid, q_len; |
| 223 | |
| 224 | fd = open (conf_fname, O_RDONLY); |
| 225 | if (fd < 0) |
| 226 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 227 | VCFG_DBG (0, "VCL<%d>: using default configuration.", getpid ()); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 228 | goto file_done; |
| 229 | } |
| 230 | |
| 231 | if (fstat (fd, &s) < 0) |
| 232 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 233 | VCFG_DBG (0, |
| 234 | "VCL<%d>: failed to stat `%s', using default configuration", |
| 235 | getpid (), conf_fname); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 236 | goto file_done; |
| 237 | } |
| 238 | |
| 239 | if (!(S_ISREG (s.st_mode) || S_ISLNK (s.st_mode))) |
| 240 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 241 | VCFG_DBG (0, "VCL<%d>: not a regular file `%s', using default " |
| 242 | "configuration", getpid (), conf_fname); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 243 | goto file_done; |
| 244 | } |
| 245 | |
| 246 | unformat_init_clib_file (input, fd); |
| 247 | |
| 248 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 249 | { |
| 250 | (void) unformat_user (input, unformat_line_input, line_input); |
| 251 | unformat_skip_white_space (line_input); |
| 252 | |
| 253 | if (unformat (line_input, "vcl {")) |
| 254 | { |
| 255 | vc_cfg_input = 1; |
| 256 | continue; |
| 257 | } |
| 258 | |
| 259 | if (vc_cfg_input) |
| 260 | { |
| 261 | if (unformat (line_input, "heapsize %s", &chroot_path)) |
| 262 | { |
| 263 | vec_terminate_c_string (chroot_path); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 264 | VCFG_DBG (0, |
| 265 | "VCL<%d>: configured heapsize %s, actual heapsize %ld" |
| 266 | " (0x%lx)", getpid (), chroot_path, vcl_cfg->heapsize, |
| 267 | vcl_cfg->heapsize); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 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 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 279 | VCFG_DBG (0, |
| 280 | "VCL<%d>: configured api-prefix (%s) and api filename" |
| 281 | " (%s)", getpid (), chroot_path, |
| 282 | vcl_cfg->vpp_api_filename); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 283 | chroot_path = 0; /* Don't vec_free() it! */ |
| 284 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 285 | else if (unformat (line_input, "api-socket-name %s", |
| 286 | &vcl_cfg->vpp_api_socket_name)) |
| 287 | { |
| 288 | vec_terminate_c_string (vcl_cfg->vpp_api_socket_name); |
| 289 | VCFG_DBG (0, "VCL<%d>: configured api-socket-name (%s)", |
| 290 | getpid (), vcl_cfg->vpp_api_socket_name); |
| 291 | } |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 292 | else if (unformat (line_input, "vpp-api-q-length %d", &q_len)) |
| 293 | { |
| 294 | if (q_len < vcl_cfg->vpp_api_q_length) |
| 295 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 296 | fprintf (stderr, |
| 297 | "VCL<%d>: ERROR: configured vpp-api-q-length " |
| 298 | "(%u) is too small! Using default: %u ", getpid (), |
| 299 | q_len, vcl_cfg->vpp_api_q_length); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 300 | } |
| 301 | else |
| 302 | { |
| 303 | vcl_cfg->vpp_api_q_length = q_len; |
| 304 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 305 | VCFG_DBG (0, "VCL<%d>: configured vpp-api-q-length %u", |
| 306 | getpid (), vcl_cfg->vpp_api_q_length); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | else if (unformat (line_input, "uid %d", &uid)) |
| 310 | { |
| 311 | vl_set_memory_uid (uid); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 312 | VCFG_DBG (0, "VCL<%d>: configured uid %d", getpid (), uid); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 313 | } |
| 314 | else if (unformat (line_input, "gid %d", &gid)) |
| 315 | { |
| 316 | vl_set_memory_gid (gid); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 317 | VCFG_DBG (0, "VCL<%d>: configured gid %d", getpid (), gid); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 318 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 319 | else if (unformat (line_input, "segment-baseva 0x%x", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 320 | &vcl_cfg->segment_baseva)) |
| 321 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 322 | VCFG_DBG (0, "VCL<%d>: configured segment_baseva 0x%lx", |
| 323 | getpid (), vcl_cfg->segment_baseva); |
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-size 0x%x", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 326 | &vcl_cfg->segment_size)) |
| 327 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 328 | VCFG_DBG (0, "VCL<%d>: configured segment_size 0x%x (%d)", |
| 329 | getpid (), vcl_cfg->segment_size, |
| 330 | vcl_cfg->segment_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 331 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 332 | else if (unformat (line_input, "segment-size %d", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 333 | &vcl_cfg->segment_size)) |
| 334 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 335 | VCFG_DBG (0, "VCL<%d>: configured segment_size %d (0x%x)", |
| 336 | getpid (), vcl_cfg->segment_size, |
| 337 | vcl_cfg->segment_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 338 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 339 | else if (unformat (line_input, "add-segment-size 0x%x", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 340 | &vcl_cfg->add_segment_size)) |
| 341 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 342 | VCFG_DBG (0, "VCL<%d>: configured add_segment_size 0x%x (%d)", |
| 343 | getpid (), vcl_cfg->add_segment_size, |
| 344 | vcl_cfg->add_segment_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 345 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 346 | else if (unformat (line_input, "add-segment-size %d", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 347 | &vcl_cfg->add_segment_size)) |
| 348 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 349 | VCFG_DBG (0, "VCL<%d>: configured add_segment_size %d (0x%x)", |
| 350 | getpid (), vcl_cfg->add_segment_size, |
| 351 | vcl_cfg->add_segment_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 352 | } |
| 353 | else if (unformat (line_input, "preallocated-fifo-pairs %d", |
| 354 | &vcl_cfg->preallocated_fifo_pairs)) |
| 355 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 356 | VCFG_DBG (0, "VCL<%d>: configured preallocated_fifo_pairs %d " |
| 357 | "(0x%x)", getpid (), vcl_cfg->preallocated_fifo_pairs, |
| 358 | vcl_cfg->preallocated_fifo_pairs); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 359 | } |
| 360 | else if (unformat (line_input, "rx-fifo-size 0x%lx", |
| 361 | &vcl_cfg->rx_fifo_size)) |
| 362 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 363 | VCFG_DBG (0, "VCL<%d>: configured rx_fifo_size 0x%x (%d)", |
| 364 | getpid (), vcl_cfg->rx_fifo_size, |
| 365 | vcl_cfg->rx_fifo_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 366 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 367 | else if (unformat (line_input, "rx-fifo-size %d", |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 368 | &vcl_cfg->rx_fifo_size)) |
| 369 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 370 | VCFG_DBG (0, "VCL<%d>: configured rx_fifo_size %d (0x%x)", |
| 371 | getpid (), vcl_cfg->rx_fifo_size, |
| 372 | vcl_cfg->rx_fifo_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 373 | } |
| 374 | else if (unformat (line_input, "tx-fifo-size 0x%lx", |
| 375 | &vcl_cfg->tx_fifo_size)) |
| 376 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 377 | VCFG_DBG (0, "VCL<%d>: configured tx_fifo_size 0x%x (%d)", |
| 378 | getpid (), vcl_cfg->tx_fifo_size, |
| 379 | vcl_cfg->tx_fifo_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 380 | } |
| 381 | else if (unformat (line_input, "tx-fifo-size %ld", |
| 382 | &vcl_cfg->tx_fifo_size)) |
| 383 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 384 | VCFG_DBG (0, "VCL<%d>: configured tx_fifo_size %d (0x%x)", |
| 385 | getpid (), vcl_cfg->tx_fifo_size, |
| 386 | vcl_cfg->tx_fifo_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 387 | } |
| 388 | else if (unformat (line_input, "event-queue-size 0x%lx", |
| 389 | &vcl_cfg->event_queue_size)) |
| 390 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 391 | VCFG_DBG (0, "VCL<%d>: configured event_queue_size 0x%x (%d)", |
| 392 | getpid (), vcl_cfg->event_queue_size, |
| 393 | vcl_cfg->event_queue_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 394 | } |
| 395 | else if (unformat (line_input, "event-queue-size %ld", |
| 396 | &vcl_cfg->event_queue_size)) |
| 397 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 398 | VCFG_DBG (0, "VCL<%d>: configured event_queue_size %d (0x%x)", |
| 399 | getpid (), vcl_cfg->event_queue_size, |
| 400 | vcl_cfg->event_queue_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 401 | } |
| 402 | else if (unformat (line_input, "listen-queue-size 0x%lx", |
| 403 | &vcl_cfg->listen_queue_size)) |
| 404 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 405 | VCFG_DBG (0, "VCL<%d>: configured listen_queue_size 0x%x (%u)", |
| 406 | getpid (), vcl_cfg->listen_queue_size, |
| 407 | vcl_cfg->listen_queue_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 408 | } |
| 409 | else if (unformat (line_input, "listen-queue-size %ld", |
| 410 | &vcl_cfg->listen_queue_size)) |
| 411 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 412 | VCFG_DBG (0, "VCL<%d>: configured listen_queue_size %u (0x%x)", |
| 413 | getpid (), vcl_cfg->listen_queue_size, |
| 414 | vcl_cfg->listen_queue_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 415 | } |
| 416 | else if (unformat (line_input, "app-timeout %f", |
| 417 | &vcl_cfg->app_timeout)) |
| 418 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 419 | VCFG_DBG (0, "VCL<%d>: configured app_timeout %f", |
| 420 | getpid (), vcl_cfg->app_timeout); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 421 | } |
| 422 | else if (unformat (line_input, "session-timeout %f", |
| 423 | &vcl_cfg->session_timeout)) |
| 424 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 425 | VCFG_DBG (0, "VCL<%d>: configured session_timeout %f", |
| 426 | getpid (), vcl_cfg->session_timeout); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 427 | } |
| 428 | else if (unformat (line_input, "accept-timeout %f", |
| 429 | &vcl_cfg->accept_timeout)) |
| 430 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 431 | VCFG_DBG (0, "VCL<%d>: configured accept_timeout %f", |
| 432 | getpid (), vcl_cfg->accept_timeout); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 433 | } |
| 434 | else if (unformat (line_input, "app-proxy-transport-tcp")) |
| 435 | { |
| 436 | vcl_cfg->app_proxy_transport_tcp = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 437 | VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_tcp (%d)", |
| 438 | getpid (), vcl_cfg->app_proxy_transport_tcp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 439 | } |
| 440 | else if (unformat (line_input, "app-proxy-transport-udp")) |
| 441 | { |
| 442 | vcl_cfg->app_proxy_transport_udp = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 443 | VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_udp (%d)", |
| 444 | getpid (), vcl_cfg->app_proxy_transport_udp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 445 | } |
| 446 | else if (unformat (line_input, "app-scope-local")) |
| 447 | { |
| 448 | vcl_cfg->app_scope_local = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 449 | VCFG_DBG (0, "VCL<%d>: configured app_scope_local (%d)", |
| 450 | getpid (), vcl_cfg->app_scope_local); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 451 | } |
| 452 | else if (unformat (line_input, "app-scope-global")) |
| 453 | { |
| 454 | vcl_cfg->app_scope_global = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 455 | VCFG_DBG (0, "VCL<%d>: configured app_scope_global (%d)", |
| 456 | getpid (), vcl_cfg->app_scope_global); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 457 | } |
| 458 | else if (unformat (line_input, "namespace-secret %lu", |
| 459 | &vcl_cfg->namespace_secret)) |
| 460 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 461 | VCFG_DBG (0, "VCL<%d>: configured namespace_secret %lu (0x%lx)", |
| 462 | getpid (), vcl_cfg->namespace_secret, |
| 463 | vcl_cfg->namespace_secret); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 464 | } |
| 465 | else if (unformat (line_input, "namespace-id %v", |
| 466 | &vcl_cfg->namespace_id)) |
| 467 | { |
| 468 | u32 max_nsid_vec_len = vcl_max_nsid_len (); |
| 469 | u32 nsid_vec_len = vec_len (vcl_cfg->namespace_id); |
| 470 | if (nsid_vec_len > max_nsid_vec_len) |
| 471 | { |
| 472 | _vec_len (vcl_cfg->namespace_id) = max_nsid_vec_len; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 473 | VCFG_DBG (0, "VCL<%d>: configured namespace_id is too long," |
| 474 | " truncated to %d characters!", |
| 475 | getpid (), max_nsid_vec_len); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 478 | VCFG_DBG (0, "VCL<%d>: configured namespace_id %s", |
| 479 | getpid (), (char *) vcl_cfg->namespace_id); |
| 480 | } |
| 481 | else if (unformat (line_input, "use-mq-eventfd")) |
| 482 | { |
| 483 | vcl_cfg->use_mq_eventfd = 1; |
| 484 | VCFG_DBG (0, "VCL<%d>: configured with mq with eventfd", |
| 485 | getpid ()); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 486 | } |
| 487 | else if (unformat (line_input, "}")) |
| 488 | { |
| 489 | vc_cfg_input = 0; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 490 | VCFG_DBG (0, "VCL<%d>: completed parsing vppcom config!", |
| 491 | getpid ()); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 492 | goto input_done; |
| 493 | } |
| 494 | else |
| 495 | { |
| 496 | if (line_input->buffer[line_input->index] != '#') |
| 497 | { |
| 498 | clib_warning ("VCL<%d>: Unknown vppcom config option: '%s'", |
| 499 | getpid (), (char *) |
| 500 | &line_input->buffer[line_input->index]); |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | input_done: |
| 507 | unformat_free (input); |
| 508 | |
| 509 | file_done: |
| 510 | if (fd >= 0) |
| 511 | close (fd); |
| 512 | } |
| 513 | |
| 514 | void |
| 515 | vppcom_cfg (vppcom_cfg_t * vcl_cfg) |
| 516 | { |
| 517 | char *conf_fname, *env_var_str; |
| 518 | |
| 519 | vppcom_cfg_init (vcl_cfg); |
| 520 | env_var_str = getenv (VPPCOM_ENV_DEBUG); |
| 521 | if (env_var_str) |
| 522 | { |
| 523 | u32 tmp; |
| 524 | if (sscanf (env_var_str, "%u", &tmp) != 1) |
Florin Coras | 9686eac | 2018-08-01 17:24:08 -0700 | [diff] [blame] | 525 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 526 | VCFG_DBG (0, "VCL<%d>: WARNING: Invalid debug level specified " |
| 527 | "in the environment variable " VPPCOM_ENV_DEBUG |
| 528 | " (%s)!\n", getpid (), env_var_str); |
Florin Coras | 9686eac | 2018-08-01 17:24:08 -0700 | [diff] [blame] | 529 | } |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 530 | else |
| 531 | { |
| 532 | vcm->debug = tmp; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 533 | VCFG_DBG (0, "VCL<%d>: configured VCL debug level (%u) from " |
| 534 | VPPCOM_ENV_DEBUG "!", getpid (), vcm->debug); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | conf_fname = getenv (VPPCOM_ENV_CONF); |
| 538 | if (!conf_fname) |
| 539 | conf_fname = VPPCOM_CONF_DEFAULT; |
| 540 | vppcom_cfg_heapsize (conf_fname); |
| 541 | vppcom_cfg_read_file (conf_fname); |
| 542 | |
| 543 | env_var_str = getenv (VPPCOM_ENV_API_PREFIX); |
| 544 | if (env_var_str) |
| 545 | { |
| 546 | if (vcl_cfg->vpp_api_filename) |
| 547 | vec_free (vcl_cfg->vpp_api_filename); |
| 548 | vcl_cfg->vpp_api_filename = format (0, "/%s-vpe-api%c", env_var_str, 0); |
| 549 | vl_set_memory_root_path ((char *) env_var_str); |
| 550 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 551 | VCFG_DBG (0, "VCL<%d>: configured api prefix (%s) and filename (%s) " |
| 552 | "from " VPPCOM_ENV_API_PREFIX "!", getpid (), env_var_str, |
| 553 | vcl_cfg->vpp_api_filename); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 554 | } |
| 555 | env_var_str = getenv (VPPCOM_ENV_APP_NAMESPACE_ID); |
| 556 | if (env_var_str) |
| 557 | { |
| 558 | u32 ns_id_vec_len = strlen (env_var_str); |
| 559 | |
| 560 | vec_reset_length (vcm->cfg.namespace_id); |
| 561 | vec_validate (vcm->cfg.namespace_id, ns_id_vec_len - 1); |
| 562 | clib_memcpy (vcm->cfg.namespace_id, env_var_str, ns_id_vec_len); |
| 563 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 564 | VCFG_DBG (0, "VCL<%d>: configured namespace_id (%s) from " |
| 565 | VPPCOM_ENV_APP_NAMESPACE_ID "!", getpid (), |
| 566 | (char *) vcm->cfg.namespace_id); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 567 | } |
| 568 | env_var_str = getenv (VPPCOM_ENV_APP_NAMESPACE_SECRET); |
| 569 | if (env_var_str) |
| 570 | { |
| 571 | u64 tmp; |
| 572 | if (sscanf (env_var_str, "%lu", &tmp) != 1) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 573 | { |
| 574 | VCFG_DBG (0, "VCL<%d>: WARNING: Invalid namespace secret specified" |
| 575 | " in the environment variable " |
| 576 | VPPCOM_ENV_APP_NAMESPACE_SECRET " (%s)!\n", getpid (), |
| 577 | env_var_str); |
| 578 | } |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 579 | else |
| 580 | { |
| 581 | vcm->cfg.namespace_secret = tmp; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 582 | VCFG_DBG (0, "VCL<%d>: configured namespace secret (%lu) from " |
| 583 | VPPCOM_ENV_APP_NAMESPACE_SECRET "!", getpid (), |
| 584 | vcm->cfg.namespace_secret); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 585 | } |
| 586 | } |
| 587 | if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP)) |
| 588 | { |
| 589 | vcm->cfg.app_proxy_transport_tcp = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 590 | VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_tcp (%u) from " |
| 591 | VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP "!", getpid (), |
| 592 | vcm->cfg.app_proxy_transport_tcp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 593 | } |
| 594 | if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP)) |
| 595 | { |
| 596 | vcm->cfg.app_proxy_transport_udp = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 597 | VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_udp (%u) from " |
| 598 | VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP "!", getpid (), |
| 599 | vcm->cfg.app_proxy_transport_udp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 600 | } |
| 601 | if (getenv (VPPCOM_ENV_APP_SCOPE_LOCAL)) |
| 602 | { |
| 603 | vcm->cfg.app_scope_local = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 604 | VCFG_DBG (0, "VCL<%d>: configured app_scope_local (%u) from " |
| 605 | VPPCOM_ENV_APP_SCOPE_LOCAL "!", getpid (), |
| 606 | vcm->cfg.app_scope_local); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 607 | } |
| 608 | if (getenv (VPPCOM_ENV_APP_SCOPE_GLOBAL)) |
| 609 | { |
| 610 | vcm->cfg.app_scope_global = 1; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 611 | VCFG_DBG (0, "VCL<%d>: configured app_scope_global (%u) from " |
| 612 | VPPCOM_ENV_APP_SCOPE_GLOBAL "!", getpid (), |
| 613 | vcm->cfg.app_scope_global); |
| 614 | } |
| 615 | env_var_str = getenv (VPPCOM_ENV_VPP_API_SOCKET); |
| 616 | if (env_var_str) |
| 617 | { |
| 618 | vcm->cfg.vpp_api_socket_name = format (0, "%s%c", env_var_str, 0); |
| 619 | VCFG_DBG (0, "VCL<%d>: configured api-socket-name (%s)", getpid (), |
| 620 | vcl_cfg->vpp_api_socket_name); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | * fd.io coding-style-patch-verification: ON |
| 626 | * |
| 627 | * Local Variables: |
| 628 | * eval: (c-set-style "gnu") |
| 629 | * End: |
| 630 | */ |