blob: 402bb91315fc89b3a8a972e4fdcc2340b30979f4 [file] [log] [blame]
Florin Coras697faea2018-06-27 17:10:49 -07001/*
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 */
22static vppcom_main_t _vppcom_main = {
23 .debug = VPPCOM_DEBUG_INIT,
Florin Coras134a9962018-08-28 11:32:04 -070024 .is_init = 0,
Florin Corasc1f5a432018-11-20 11:31:26 -080025 .app_index = ~0,
Florin Coras697faea2018-06-27 17:10:49 -070026 .my_client_index = ~0
27};
28
29vppcom_main_t *vcm = &_vppcom_main;
30
31void
32vppcom_cfg_init (vppcom_cfg_t * vcl_cfg)
33{
Florin Coras697faea2018-06-27 17:10:49 -070034 ASSERT (vcl_cfg);
35
36 vcl_cfg->heapsize = (256ULL << 20);
Florin Coras134a9962018-08-28 11:32:04 -070037 vcl_cfg->max_workers = 16;
Florin Coras697faea2018-06-27 17:10:49 -070038 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 Coras697faea2018-06-27 17:10:49 -070052}
53
Florin Coras99368312018-08-02 10:45:44 -070054#define VCFG_DBG(_lvl, _fmt, _args...) \
55{ \
Florin Coras54693d22018-07-17 10:46:29 -070056 if (vcm->debug > _lvl) \
Florin Coras99368312018-08-02 10:45:44 -070057 fprintf (stderr, _fmt "\n", ##_args); \
58}
Florin Coras697faea2018-06-27 17:10:49 -070059void
60vppcom_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 Coras99368312018-08-02 10:45:44 -070078 VCFG_DBG (0, "VCL<%d>: using default heapsize %lu (0x%lx)",
79 getpid (), vcl_cfg->heapsize, vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -070080 goto defaulted;
81 }
82
83 argv = calloc (1, sizeof (char *));
84 if (argv == NULL)
85 {
Florin Coras99368312018-08-02 10:45:44 -070086 VCFG_DBG (0, "VCL<%d>: calloc failed, using default heapsize %lu"
87 " (0x%lx)", getpid (), vcl_cfg->heapsize, vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -070088 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 Coras99368312018-08-02 10:45:44 -0700104 VCFG_DBG (0, "VCL<%d>: realloc failed, using default "
105 "heapsize %lu (0x%lx)", getpid (),
106 vcl_cfg->heapsize, vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700107 goto defaulted;
108 }
109 argv = tmp;
110 arg = strndup (p, 1024);
111 if (arg == NULL)
112 {
Florin Coras99368312018-08-02 10:45:44 -0700113 VCFG_DBG (0, "VCL<%d>: strndup failed, using default "
114 "heapsize %ld (0x%lx)", getpid (),
115 vcl_cfg->heapsize, vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700116 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 Coras99368312018-08-02 10:45:44 -0700129 VCFG_DBG (0, "VCL<%d>: realloc failed, using default heapsize %ld "
130 "(0x%lx)", getpid (), vcl_cfg->heapsize, vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700131 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 Coras99368312018-08-02 10:45:44 -0700156 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 Coras697faea2018-06-27 17:10:49 -0700159 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 Coras99368312018-08-02 10:45:44 -0700168 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 Coras697faea2018-06-27 17:10:49 -0700171 goto defaulted;
172 }
173 }
Florin Coras053a0e42018-11-13 15:52:38 -0800174 free (argv[i]);
Florin Coras697faea2018-06-27 17:10:49 -0700175 }
176
177defaulted:
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 Coras99368312018-08-02 10:45:44 -0700187 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 Coras697faea2018-06-27 17:10:49 -0700191 ASSERT (vcl_mem != MAP_FAILED);
192 return;
193 }
Dave Barach6a5adc32018-07-04 10:56:23 -0400194 heap = clib_mem_init_thread_safe (vcl_mem, vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700195 if (!heap)
196 {
Florin Coras54693d22018-07-17 10:46:29 -0700197 fprintf (stderr, "VCL<%d>: ERROR: clib_mem_init() failed!", getpid ());
Florin Coras697faea2018-06-27 17:10:49 -0700198 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 Coras99368312018-08-02 10:45:44 -0700212 VCFG_DBG (0, "VCL<%d>: allocated VCL heap = %p, size %ld (0x%lx)",
213 getpid (), heap, vcl_cfg->heapsize, vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700214}
215
216void
217vppcom_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 Coras99368312018-08-02 10:45:44 -0700223 u8 vc_cfg_input = 0, *chroot_path;
Florin Coras697faea2018-06-27 17:10:49 -0700224 struct stat s;
225 u32 uid, gid, q_len;
226
227 fd = open (conf_fname, O_RDONLY);
228 if (fd < 0)
229 {
Florin Coras99368312018-08-02 10:45:44 -0700230 VCFG_DBG (0, "VCL<%d>: using default configuration.", getpid ());
Florin Coras697faea2018-06-27 17:10:49 -0700231 goto file_done;
232 }
233
234 if (fstat (fd, &s) < 0)
235 {
Florin Coras053a0e42018-11-13 15:52:38 -0800236 VCFG_DBG (0, "VCL<%d>: failed to stat `%s' using default configuration",
Florin Coras99368312018-08-02 10:45:44 -0700237 getpid (), conf_fname);
Florin Coras697faea2018-06-27 17:10:49 -0700238 goto file_done;
239 }
240
241 if (!(S_ISREG (s.st_mode) || S_ISLNK (s.st_mode)))
242 {
Florin Coras99368312018-08-02 10:45:44 -0700243 VCFG_DBG (0, "VCL<%d>: not a regular file `%s', using default "
244 "configuration", getpid (), conf_fname);
Florin Coras697faea2018-06-27 17:10:49 -0700245 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 Coras053a0e42018-11-13 15:52:38 -0800258 unformat_free (line_input);
Florin Coras697faea2018-06-27 17:10:49 -0700259 continue;
260 }
261
262 if (vc_cfg_input)
263 {
Florin Coras053a0e42018-11-13 15:52:38 -0800264 if (unformat (line_input, "heapsize %U", unformat_memory_size,
265 &vcl_cfg->heapsize))
Florin Coras697faea2018-06-27 17:10:49 -0700266 {
Florin Coras134a9962018-08-28 11:32:04 -0700267 VCFG_DBG (0, "VCL<%d>: configured heapsize %lu", getpid (),
Florin Coras99368312018-08-02 10:45:44 -0700268 vcl_cfg->heapsize);
Florin Coras134a9962018-08-28 11:32:04 -0700269 }
Florin Coras053a0e42018-11-13 15:52:38 -0800270 else
271 if (unformat
272 (line_input, "max-workers %u", &vcl_cfg->max_workers))
Florin Coras134a9962018-08-28 11:32:04 -0700273 {
274 VCFG_DBG (0, "VCL<%d>: configured max-workers %u", getpid (),
275 vcl_cfg->max_workers);
Florin Coras697faea2018-06-27 17:10:49 -0700276 }
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 Coras134a9962018-08-28 11:32:04 -0700286 VCFG_DBG (0, "VCL<%d>: configured api-prefix (%s) and api "
287 "filename (%s)", getpid (), chroot_path,
Florin Coras99368312018-08-02 10:45:44 -0700288 vcl_cfg->vpp_api_filename);
Florin Coras697faea2018-06-27 17:10:49 -0700289 chroot_path = 0; /* Don't vec_free() it! */
290 }
Florin Coras99368312018-08-02 10:45:44 -0700291 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 Coras697faea2018-06-27 17:10:49 -0700298 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 Coras99368312018-08-02 10:45:44 -0700302 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 Coras697faea2018-06-27 17:10:49 -0700306 }
307 else
308 {
309 vcl_cfg->vpp_api_q_length = q_len;
310
Florin Coras99368312018-08-02 10:45:44 -0700311 VCFG_DBG (0, "VCL<%d>: configured vpp-api-q-length %u",
312 getpid (), vcl_cfg->vpp_api_q_length);
Florin Coras697faea2018-06-27 17:10:49 -0700313 }
314 }
315 else if (unformat (line_input, "uid %d", &uid))
316 {
317 vl_set_memory_uid (uid);
Florin Coras99368312018-08-02 10:45:44 -0700318 VCFG_DBG (0, "VCL<%d>: configured uid %d", getpid (), uid);
Florin Coras697faea2018-06-27 17:10:49 -0700319 }
320 else if (unformat (line_input, "gid %d", &gid))
321 {
322 vl_set_memory_gid (gid);
Florin Coras99368312018-08-02 10:45:44 -0700323 VCFG_DBG (0, "VCL<%d>: configured gid %d", getpid (), gid);
Florin Coras697faea2018-06-27 17:10:49 -0700324 }
Florin Coras99368312018-08-02 10:45:44 -0700325 else if (unformat (line_input, "segment-baseva 0x%x",
Florin Coras697faea2018-06-27 17:10:49 -0700326 &vcl_cfg->segment_baseva))
327 {
Florin Coras99368312018-08-02 10:45:44 -0700328 VCFG_DBG (0, "VCL<%d>: configured segment_baseva 0x%lx",
329 getpid (), vcl_cfg->segment_baseva);
Florin Coras697faea2018-06-27 17:10:49 -0700330 }
Florin Coras99368312018-08-02 10:45:44 -0700331 else if (unformat (line_input, "segment-size 0x%x",
Florin Coras697faea2018-06-27 17:10:49 -0700332 &vcl_cfg->segment_size))
333 {
Florin Coras99368312018-08-02 10:45:44 -0700334 VCFG_DBG (0, "VCL<%d>: configured segment_size 0x%x (%d)",
335 getpid (), vcl_cfg->segment_size,
336 vcl_cfg->segment_size);
Florin Coras697faea2018-06-27 17:10:49 -0700337 }
Florin Coras99368312018-08-02 10:45:44 -0700338 else if (unformat (line_input, "segment-size %d",
Florin Coras697faea2018-06-27 17:10:49 -0700339 &vcl_cfg->segment_size))
340 {
Florin Coras99368312018-08-02 10:45:44 -0700341 VCFG_DBG (0, "VCL<%d>: configured segment_size %d (0x%x)",
342 getpid (), vcl_cfg->segment_size,
343 vcl_cfg->segment_size);
Florin Coras697faea2018-06-27 17:10:49 -0700344 }
Florin Coras99368312018-08-02 10:45:44 -0700345 else if (unformat (line_input, "add-segment-size 0x%x",
Florin Coras697faea2018-06-27 17:10:49 -0700346 &vcl_cfg->add_segment_size))
347 {
Florin Coras99368312018-08-02 10:45:44 -0700348 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 Coras697faea2018-06-27 17:10:49 -0700351 }
Florin Coras99368312018-08-02 10:45:44 -0700352 else if (unformat (line_input, "add-segment-size %d",
Florin Coras697faea2018-06-27 17:10:49 -0700353 &vcl_cfg->add_segment_size))
354 {
Florin Coras99368312018-08-02 10:45:44 -0700355 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 Coras697faea2018-06-27 17:10:49 -0700358 }
359 else if (unformat (line_input, "preallocated-fifo-pairs %d",
360 &vcl_cfg->preallocated_fifo_pairs))
361 {
Florin Coras99368312018-08-02 10:45:44 -0700362 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 Coras697faea2018-06-27 17:10:49 -0700365 }
366 else if (unformat (line_input, "rx-fifo-size 0x%lx",
367 &vcl_cfg->rx_fifo_size))
368 {
Florin Coras99368312018-08-02 10:45:44 -0700369 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 Coras697faea2018-06-27 17:10:49 -0700372 }
Florin Coras99368312018-08-02 10:45:44 -0700373 else if (unformat (line_input, "rx-fifo-size %d",
Florin Coras697faea2018-06-27 17:10:49 -0700374 &vcl_cfg->rx_fifo_size))
375 {
Florin Coras99368312018-08-02 10:45:44 -0700376 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 Coras697faea2018-06-27 17:10:49 -0700379 }
380 else if (unformat (line_input, "tx-fifo-size 0x%lx",
381 &vcl_cfg->tx_fifo_size))
382 {
Florin Coras99368312018-08-02 10:45:44 -0700383 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 Coras697faea2018-06-27 17:10:49 -0700386 }
387 else if (unformat (line_input, "tx-fifo-size %ld",
388 &vcl_cfg->tx_fifo_size))
389 {
Florin Coras99368312018-08-02 10:45:44 -0700390 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 Coras697faea2018-06-27 17:10:49 -0700393 }
394 else if (unformat (line_input, "event-queue-size 0x%lx",
395 &vcl_cfg->event_queue_size))
396 {
Florin Coras99368312018-08-02 10:45:44 -0700397 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 Coras697faea2018-06-27 17:10:49 -0700400 }
401 else if (unformat (line_input, "event-queue-size %ld",
402 &vcl_cfg->event_queue_size))
403 {
Florin Coras99368312018-08-02 10:45:44 -0700404 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 Coras697faea2018-06-27 17:10:49 -0700407 }
408 else if (unformat (line_input, "listen-queue-size 0x%lx",
409 &vcl_cfg->listen_queue_size))
410 {
Florin Coras99368312018-08-02 10:45:44 -0700411 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 Coras697faea2018-06-27 17:10:49 -0700414 }
415 else if (unformat (line_input, "listen-queue-size %ld",
416 &vcl_cfg->listen_queue_size))
417 {
Florin Coras99368312018-08-02 10:45:44 -0700418 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 Coras697faea2018-06-27 17:10:49 -0700421 }
422 else if (unformat (line_input, "app-timeout %f",
423 &vcl_cfg->app_timeout))
424 {
Florin Coras99368312018-08-02 10:45:44 -0700425 VCFG_DBG (0, "VCL<%d>: configured app_timeout %f",
426 getpid (), vcl_cfg->app_timeout);
Florin Coras697faea2018-06-27 17:10:49 -0700427 }
428 else if (unformat (line_input, "session-timeout %f",
429 &vcl_cfg->session_timeout))
430 {
Florin Coras99368312018-08-02 10:45:44 -0700431 VCFG_DBG (0, "VCL<%d>: configured session_timeout %f",
432 getpid (), vcl_cfg->session_timeout);
Florin Coras697faea2018-06-27 17:10:49 -0700433 }
434 else if (unformat (line_input, "accept-timeout %f",
435 &vcl_cfg->accept_timeout))
436 {
Florin Coras99368312018-08-02 10:45:44 -0700437 VCFG_DBG (0, "VCL<%d>: configured accept_timeout %f",
438 getpid (), vcl_cfg->accept_timeout);
Florin Coras697faea2018-06-27 17:10:49 -0700439 }
440 else if (unformat (line_input, "app-proxy-transport-tcp"))
441 {
442 vcl_cfg->app_proxy_transport_tcp = 1;
Florin Coras99368312018-08-02 10:45:44 -0700443 VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_tcp (%d)",
444 getpid (), vcl_cfg->app_proxy_transport_tcp);
Florin Coras697faea2018-06-27 17:10:49 -0700445 }
446 else if (unformat (line_input, "app-proxy-transport-udp"))
447 {
448 vcl_cfg->app_proxy_transport_udp = 1;
Florin Coras99368312018-08-02 10:45:44 -0700449 VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_udp (%d)",
450 getpid (), vcl_cfg->app_proxy_transport_udp);
Florin Coras697faea2018-06-27 17:10:49 -0700451 }
452 else if (unformat (line_input, "app-scope-local"))
453 {
454 vcl_cfg->app_scope_local = 1;
Florin Coras99368312018-08-02 10:45:44 -0700455 VCFG_DBG (0, "VCL<%d>: configured app_scope_local (%d)",
456 getpid (), vcl_cfg->app_scope_local);
Florin Coras697faea2018-06-27 17:10:49 -0700457 }
458 else if (unformat (line_input, "app-scope-global"))
459 {
460 vcl_cfg->app_scope_global = 1;
Florin Coras99368312018-08-02 10:45:44 -0700461 VCFG_DBG (0, "VCL<%d>: configured app_scope_global (%d)",
462 getpid (), vcl_cfg->app_scope_global);
Florin Coras697faea2018-06-27 17:10:49 -0700463 }
464 else if (unformat (line_input, "namespace-secret %lu",
465 &vcl_cfg->namespace_secret))
466 {
Florin Coras99368312018-08-02 10:45:44 -0700467 VCFG_DBG (0, "VCL<%d>: configured namespace_secret %lu (0x%lx)",
468 getpid (), vcl_cfg->namespace_secret,
469 vcl_cfg->namespace_secret);
Florin Coras697faea2018-06-27 17:10:49 -0700470 }
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 Coras99368312018-08-02 10:45:44 -0700479 VCFG_DBG (0, "VCL<%d>: configured namespace_id is too long,"
480 " truncated to %d characters!",
481 getpid (), max_nsid_vec_len);
Florin Coras697faea2018-06-27 17:10:49 -0700482 }
483
Florin Coras99368312018-08-02 10:45:44 -0700484 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 Coras697faea2018-06-27 17:10:49 -0700492 }
493 else if (unformat (line_input, "}"))
494 {
495 vc_cfg_input = 0;
Florin Coras99368312018-08-02 10:45:44 -0700496 VCFG_DBG (0, "VCL<%d>: completed parsing vppcom config!",
497 getpid ());
Florin Coras053a0e42018-11-13 15:52:38 -0800498 unformat_free (line_input);
Florin Coras697faea2018-06-27 17:10:49 -0700499 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 Coras053a0e42018-11-13 15:52:38 -0800510 unformat_free (line_input);
Florin Coras697faea2018-06-27 17:10:49 -0700511 }
512 }
513
514input_done:
515 unformat_free (input);
516
517file_done:
518 if (fd >= 0)
519 close (fd);
520}
521
522void
523vppcom_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 Coras9686eac2018-08-01 17:24:08 -0700533 {
Florin Coras99368312018-08-02 10:45:44 -0700534 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 Coras9686eac2018-08-01 17:24:08 -0700537 }
Florin Coras697faea2018-06-27 17:10:49 -0700538 else
539 {
540 vcm->debug = tmp;
Florin Coras99368312018-08-02 10:45:44 -0700541 VCFG_DBG (0, "VCL<%d>: configured VCL debug level (%u) from "
542 VPPCOM_ENV_DEBUG "!", getpid (), vcm->debug);
Florin Coras697faea2018-06-27 17:10:49 -0700543 }
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 Coras99368312018-08-02 10:45:44 -0700559 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 Coras697faea2018-06-27 17:10:49 -0700562 }
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 Coras99368312018-08-02 10:45:44 -0700572 VCFG_DBG (0, "VCL<%d>: configured namespace_id (%s) from "
573 VPPCOM_ENV_APP_NAMESPACE_ID "!", getpid (),
574 (char *) vcm->cfg.namespace_id);
Florin Coras697faea2018-06-27 17:10:49 -0700575 }
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 Coras99368312018-08-02 10:45:44 -0700581 {
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 Coras697faea2018-06-27 17:10:49 -0700587 else
588 {
589 vcm->cfg.namespace_secret = tmp;
Florin Coras99368312018-08-02 10:45:44 -0700590 VCFG_DBG (0, "VCL<%d>: configured namespace secret (%lu) from "
591 VPPCOM_ENV_APP_NAMESPACE_SECRET "!", getpid (),
592 vcm->cfg.namespace_secret);
Florin Coras697faea2018-06-27 17:10:49 -0700593 }
594 }
595 if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP))
596 {
597 vcm->cfg.app_proxy_transport_tcp = 1;
Florin Coras99368312018-08-02 10:45:44 -0700598 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 Coras697faea2018-06-27 17:10:49 -0700601 }
602 if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP))
603 {
604 vcm->cfg.app_proxy_transport_udp = 1;
Florin Coras99368312018-08-02 10:45:44 -0700605 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 Coras697faea2018-06-27 17:10:49 -0700608 }
609 if (getenv (VPPCOM_ENV_APP_SCOPE_LOCAL))
610 {
611 vcm->cfg.app_scope_local = 1;
Florin Coras99368312018-08-02 10:45:44 -0700612 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 Coras697faea2018-06-27 17:10:49 -0700615 }
616 if (getenv (VPPCOM_ENV_APP_SCOPE_GLOBAL))
617 {
618 vcm->cfg.app_scope_global = 1;
Florin Coras99368312018-08-02 10:45:44 -0700619 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 Coras697faea2018-06-27 17:10:49 -0700629 }
630}
631
632/*
633 * fd.io coding-style-patch-verification: ON
634 *
635 * Local Variables:
636 * eval: (c-set-style "gnu")
637 * End:
638 */