blob: f7bddefbb3b4ce9e65c9d9610b9b1d75c309a62b [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 Coras460dce62018-07-27 05:45:06 -070024 .init = 0,
Florin Coras697faea2018-06-27 17:10:49 -070025 .my_client_index = ~0
26};
27
28vppcom_main_t *vcm = &_vppcom_main;
29
30void
31vppcom_cfg_init (vppcom_cfg_t * vcl_cfg)
32{
Florin Coras697faea2018-06-27 17:10:49 -070033 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 Coras697faea2018-06-27 17:10:49 -070050}
51
Florin Coras99368312018-08-02 10:45:44 -070052#define VCFG_DBG(_lvl, _fmt, _args...) \
53{ \
Florin Coras54693d22018-07-17 10:46:29 -070054 if (vcm->debug > _lvl) \
Florin Coras99368312018-08-02 10:45:44 -070055 fprintf (stderr, _fmt "\n", ##_args); \
56}
Florin Coras697faea2018-06-27 17:10:49 -070057void
58vppcom_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 Coras99368312018-08-02 10:45:44 -070076 VCFG_DBG (0, "VCL<%d>: using default heapsize %lu (0x%lx)",
77 getpid (), vcl_cfg->heapsize, vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -070078 goto defaulted;
79 }
80
81 argv = calloc (1, sizeof (char *));
82 if (argv == NULL)
83 {
Florin Coras99368312018-08-02 10:45:44 -070084 VCFG_DBG (0, "VCL<%d>: calloc failed, using default heapsize %lu"
85 " (0x%lx)", getpid (), vcl_cfg->heapsize, vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -070086 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 Coras99368312018-08-02 10:45:44 -0700102 VCFG_DBG (0, "VCL<%d>: realloc failed, using default "
103 "heapsize %lu (0x%lx)", getpid (),
104 vcl_cfg->heapsize, vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700105 goto defaulted;
106 }
107 argv = tmp;
108 arg = strndup (p, 1024);
109 if (arg == NULL)
110 {
Florin Coras99368312018-08-02 10:45:44 -0700111 VCFG_DBG (0, "VCL<%d>: strndup failed, using default "
112 "heapsize %ld (0x%lx)", getpid (),
113 vcl_cfg->heapsize, vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700114 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 Coras99368312018-08-02 10:45:44 -0700127 VCFG_DBG (0, "VCL<%d>: realloc failed, using default heapsize %ld "
128 "(0x%lx)", getpid (), vcl_cfg->heapsize, vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700129 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 Coras99368312018-08-02 10:45:44 -0700154 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 Coras697faea2018-06-27 17:10:49 -0700157 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 Coras99368312018-08-02 10:45:44 -0700166 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 Coras697faea2018-06-27 17:10:49 -0700169 goto defaulted;
170 }
171 }
172 }
173
174defaulted:
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 Coras99368312018-08-02 10:45:44 -0700184 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 Coras697faea2018-06-27 17:10:49 -0700188 ASSERT (vcl_mem != MAP_FAILED);
189 return;
190 }
Dave Barach6a5adc32018-07-04 10:56:23 -0400191 heap = clib_mem_init_thread_safe (vcl_mem, vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700192 if (!heap)
193 {
Florin Coras54693d22018-07-17 10:46:29 -0700194 fprintf (stderr, "VCL<%d>: ERROR: clib_mem_init() failed!", getpid ());
Florin Coras697faea2018-06-27 17:10:49 -0700195 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 Coras99368312018-08-02 10:45:44 -0700209 VCFG_DBG (0, "VCL<%d>: allocated VCL heap = %p, size %ld (0x%lx)",
210 getpid (), heap, vcl_cfg->heapsize, vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700211}
212
213void
214vppcom_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 Coras99368312018-08-02 10:45:44 -0700220 u8 vc_cfg_input = 0, *chroot_path;
Florin Coras697faea2018-06-27 17:10:49 -0700221 struct stat s;
222 u32 uid, gid, q_len;
223
224 fd = open (conf_fname, O_RDONLY);
225 if (fd < 0)
226 {
Florin Coras99368312018-08-02 10:45:44 -0700227 VCFG_DBG (0, "VCL<%d>: using default configuration.", getpid ());
Florin Coras697faea2018-06-27 17:10:49 -0700228 goto file_done;
229 }
230
231 if (fstat (fd, &s) < 0)
232 {
Florin Coras99368312018-08-02 10:45:44 -0700233 VCFG_DBG (0,
234 "VCL<%d>: failed to stat `%s', using default configuration",
235 getpid (), conf_fname);
Florin Coras697faea2018-06-27 17:10:49 -0700236 goto file_done;
237 }
238
239 if (!(S_ISREG (s.st_mode) || S_ISLNK (s.st_mode)))
240 {
Florin Coras99368312018-08-02 10:45:44 -0700241 VCFG_DBG (0, "VCL<%d>: not a regular file `%s', using default "
242 "configuration", getpid (), conf_fname);
Florin Coras697faea2018-06-27 17:10:49 -0700243 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 Coras99368312018-08-02 10:45:44 -0700264 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 Coras697faea2018-06-27 17:10:49 -0700268 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 Coras99368312018-08-02 10:45:44 -0700279 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 Coras697faea2018-06-27 17:10:49 -0700283 chroot_path = 0; /* Don't vec_free() it! */
284 }
Florin Coras99368312018-08-02 10:45:44 -0700285 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 Coras697faea2018-06-27 17:10:49 -0700292 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 Coras99368312018-08-02 10:45:44 -0700296 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 Coras697faea2018-06-27 17:10:49 -0700300 }
301 else
302 {
303 vcl_cfg->vpp_api_q_length = q_len;
304
Florin Coras99368312018-08-02 10:45:44 -0700305 VCFG_DBG (0, "VCL<%d>: configured vpp-api-q-length %u",
306 getpid (), vcl_cfg->vpp_api_q_length);
Florin Coras697faea2018-06-27 17:10:49 -0700307 }
308 }
309 else if (unformat (line_input, "uid %d", &uid))
310 {
311 vl_set_memory_uid (uid);
Florin Coras99368312018-08-02 10:45:44 -0700312 VCFG_DBG (0, "VCL<%d>: configured uid %d", getpid (), uid);
Florin Coras697faea2018-06-27 17:10:49 -0700313 }
314 else if (unformat (line_input, "gid %d", &gid))
315 {
316 vl_set_memory_gid (gid);
Florin Coras99368312018-08-02 10:45:44 -0700317 VCFG_DBG (0, "VCL<%d>: configured gid %d", getpid (), gid);
Florin Coras697faea2018-06-27 17:10:49 -0700318 }
Florin Coras99368312018-08-02 10:45:44 -0700319 else if (unformat (line_input, "segment-baseva 0x%x",
Florin Coras697faea2018-06-27 17:10:49 -0700320 &vcl_cfg->segment_baseva))
321 {
Florin Coras99368312018-08-02 10:45:44 -0700322 VCFG_DBG (0, "VCL<%d>: configured segment_baseva 0x%lx",
323 getpid (), vcl_cfg->segment_baseva);
Florin Coras697faea2018-06-27 17:10:49 -0700324 }
Florin Coras99368312018-08-02 10:45:44 -0700325 else if (unformat (line_input, "segment-size 0x%x",
Florin Coras697faea2018-06-27 17:10:49 -0700326 &vcl_cfg->segment_size))
327 {
Florin Coras99368312018-08-02 10:45:44 -0700328 VCFG_DBG (0, "VCL<%d>: configured segment_size 0x%x (%d)",
329 getpid (), vcl_cfg->segment_size,
330 vcl_cfg->segment_size);
Florin Coras697faea2018-06-27 17:10:49 -0700331 }
Florin Coras99368312018-08-02 10:45:44 -0700332 else if (unformat (line_input, "segment-size %d",
Florin Coras697faea2018-06-27 17:10:49 -0700333 &vcl_cfg->segment_size))
334 {
Florin Coras99368312018-08-02 10:45:44 -0700335 VCFG_DBG (0, "VCL<%d>: configured segment_size %d (0x%x)",
336 getpid (), vcl_cfg->segment_size,
337 vcl_cfg->segment_size);
Florin Coras697faea2018-06-27 17:10:49 -0700338 }
Florin Coras99368312018-08-02 10:45:44 -0700339 else if (unformat (line_input, "add-segment-size 0x%x",
Florin Coras697faea2018-06-27 17:10:49 -0700340 &vcl_cfg->add_segment_size))
341 {
Florin Coras99368312018-08-02 10:45:44 -0700342 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 Coras697faea2018-06-27 17:10:49 -0700345 }
Florin Coras99368312018-08-02 10:45:44 -0700346 else if (unformat (line_input, "add-segment-size %d",
Florin Coras697faea2018-06-27 17:10:49 -0700347 &vcl_cfg->add_segment_size))
348 {
Florin Coras99368312018-08-02 10:45:44 -0700349 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 Coras697faea2018-06-27 17:10:49 -0700352 }
353 else if (unformat (line_input, "preallocated-fifo-pairs %d",
354 &vcl_cfg->preallocated_fifo_pairs))
355 {
Florin Coras99368312018-08-02 10:45:44 -0700356 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 Coras697faea2018-06-27 17:10:49 -0700359 }
360 else if (unformat (line_input, "rx-fifo-size 0x%lx",
361 &vcl_cfg->rx_fifo_size))
362 {
Florin Coras99368312018-08-02 10:45:44 -0700363 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 Coras697faea2018-06-27 17:10:49 -0700366 }
Florin Coras99368312018-08-02 10:45:44 -0700367 else if (unformat (line_input, "rx-fifo-size %d",
Florin Coras697faea2018-06-27 17:10:49 -0700368 &vcl_cfg->rx_fifo_size))
369 {
Florin Coras99368312018-08-02 10:45:44 -0700370 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 Coras697faea2018-06-27 17:10:49 -0700373 }
374 else if (unformat (line_input, "tx-fifo-size 0x%lx",
375 &vcl_cfg->tx_fifo_size))
376 {
Florin Coras99368312018-08-02 10:45:44 -0700377 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 Coras697faea2018-06-27 17:10:49 -0700380 }
381 else if (unformat (line_input, "tx-fifo-size %ld",
382 &vcl_cfg->tx_fifo_size))
383 {
Florin Coras99368312018-08-02 10:45:44 -0700384 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 Coras697faea2018-06-27 17:10:49 -0700387 }
388 else if (unformat (line_input, "event-queue-size 0x%lx",
389 &vcl_cfg->event_queue_size))
390 {
Florin Coras99368312018-08-02 10:45:44 -0700391 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 Coras697faea2018-06-27 17:10:49 -0700394 }
395 else if (unformat (line_input, "event-queue-size %ld",
396 &vcl_cfg->event_queue_size))
397 {
Florin Coras99368312018-08-02 10:45:44 -0700398 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 Coras697faea2018-06-27 17:10:49 -0700401 }
402 else if (unformat (line_input, "listen-queue-size 0x%lx",
403 &vcl_cfg->listen_queue_size))
404 {
Florin Coras99368312018-08-02 10:45:44 -0700405 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 Coras697faea2018-06-27 17:10:49 -0700408 }
409 else if (unformat (line_input, "listen-queue-size %ld",
410 &vcl_cfg->listen_queue_size))
411 {
Florin Coras99368312018-08-02 10:45:44 -0700412 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 Coras697faea2018-06-27 17:10:49 -0700415 }
416 else if (unformat (line_input, "app-timeout %f",
417 &vcl_cfg->app_timeout))
418 {
Florin Coras99368312018-08-02 10:45:44 -0700419 VCFG_DBG (0, "VCL<%d>: configured app_timeout %f",
420 getpid (), vcl_cfg->app_timeout);
Florin Coras697faea2018-06-27 17:10:49 -0700421 }
422 else if (unformat (line_input, "session-timeout %f",
423 &vcl_cfg->session_timeout))
424 {
Florin Coras99368312018-08-02 10:45:44 -0700425 VCFG_DBG (0, "VCL<%d>: configured session_timeout %f",
426 getpid (), vcl_cfg->session_timeout);
Florin Coras697faea2018-06-27 17:10:49 -0700427 }
428 else if (unformat (line_input, "accept-timeout %f",
429 &vcl_cfg->accept_timeout))
430 {
Florin Coras99368312018-08-02 10:45:44 -0700431 VCFG_DBG (0, "VCL<%d>: configured accept_timeout %f",
432 getpid (), vcl_cfg->accept_timeout);
Florin Coras697faea2018-06-27 17:10:49 -0700433 }
434 else if (unformat (line_input, "app-proxy-transport-tcp"))
435 {
436 vcl_cfg->app_proxy_transport_tcp = 1;
Florin Coras99368312018-08-02 10:45:44 -0700437 VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_tcp (%d)",
438 getpid (), vcl_cfg->app_proxy_transport_tcp);
Florin Coras697faea2018-06-27 17:10:49 -0700439 }
440 else if (unformat (line_input, "app-proxy-transport-udp"))
441 {
442 vcl_cfg->app_proxy_transport_udp = 1;
Florin Coras99368312018-08-02 10:45:44 -0700443 VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_udp (%d)",
444 getpid (), vcl_cfg->app_proxy_transport_udp);
Florin Coras697faea2018-06-27 17:10:49 -0700445 }
446 else if (unformat (line_input, "app-scope-local"))
447 {
448 vcl_cfg->app_scope_local = 1;
Florin Coras99368312018-08-02 10:45:44 -0700449 VCFG_DBG (0, "VCL<%d>: configured app_scope_local (%d)",
450 getpid (), vcl_cfg->app_scope_local);
Florin Coras697faea2018-06-27 17:10:49 -0700451 }
452 else if (unformat (line_input, "app-scope-global"))
453 {
454 vcl_cfg->app_scope_global = 1;
Florin Coras99368312018-08-02 10:45:44 -0700455 VCFG_DBG (0, "VCL<%d>: configured app_scope_global (%d)",
456 getpid (), vcl_cfg->app_scope_global);
Florin Coras697faea2018-06-27 17:10:49 -0700457 }
458 else if (unformat (line_input, "namespace-secret %lu",
459 &vcl_cfg->namespace_secret))
460 {
Florin Coras99368312018-08-02 10:45:44 -0700461 VCFG_DBG (0, "VCL<%d>: configured namespace_secret %lu (0x%lx)",
462 getpid (), vcl_cfg->namespace_secret,
463 vcl_cfg->namespace_secret);
Florin Coras697faea2018-06-27 17:10:49 -0700464 }
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 Coras99368312018-08-02 10:45:44 -0700473 VCFG_DBG (0, "VCL<%d>: configured namespace_id is too long,"
474 " truncated to %d characters!",
475 getpid (), max_nsid_vec_len);
Florin Coras697faea2018-06-27 17:10:49 -0700476 }
477
Florin Coras99368312018-08-02 10:45:44 -0700478 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 Coras697faea2018-06-27 17:10:49 -0700486 }
487 else if (unformat (line_input, "}"))
488 {
489 vc_cfg_input = 0;
Florin Coras99368312018-08-02 10:45:44 -0700490 VCFG_DBG (0, "VCL<%d>: completed parsing vppcom config!",
491 getpid ());
Florin Coras697faea2018-06-27 17:10:49 -0700492 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
506input_done:
507 unformat_free (input);
508
509file_done:
510 if (fd >= 0)
511 close (fd);
512}
513
514void
515vppcom_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 Coras9686eac2018-08-01 17:24:08 -0700525 {
Florin Coras99368312018-08-02 10:45:44 -0700526 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 Coras9686eac2018-08-01 17:24:08 -0700529 }
Florin Coras697faea2018-06-27 17:10:49 -0700530 else
531 {
532 vcm->debug = tmp;
Florin Coras99368312018-08-02 10:45:44 -0700533 VCFG_DBG (0, "VCL<%d>: configured VCL debug level (%u) from "
534 VPPCOM_ENV_DEBUG "!", getpid (), vcm->debug);
Florin Coras697faea2018-06-27 17:10:49 -0700535 }
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 Coras99368312018-08-02 10:45:44 -0700551 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 Coras697faea2018-06-27 17:10:49 -0700554 }
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 Coras99368312018-08-02 10:45:44 -0700564 VCFG_DBG (0, "VCL<%d>: configured namespace_id (%s) from "
565 VPPCOM_ENV_APP_NAMESPACE_ID "!", getpid (),
566 (char *) vcm->cfg.namespace_id);
Florin Coras697faea2018-06-27 17:10:49 -0700567 }
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 Coras99368312018-08-02 10:45:44 -0700573 {
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 Coras697faea2018-06-27 17:10:49 -0700579 else
580 {
581 vcm->cfg.namespace_secret = tmp;
Florin Coras99368312018-08-02 10:45:44 -0700582 VCFG_DBG (0, "VCL<%d>: configured namespace secret (%lu) from "
583 VPPCOM_ENV_APP_NAMESPACE_SECRET "!", getpid (),
584 vcm->cfg.namespace_secret);
Florin Coras697faea2018-06-27 17:10:49 -0700585 }
586 }
587 if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP))
588 {
589 vcm->cfg.app_proxy_transport_tcp = 1;
Florin Coras99368312018-08-02 10:45:44 -0700590 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 Coras697faea2018-06-27 17:10:49 -0700593 }
594 if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP))
595 {
596 vcm->cfg.app_proxy_transport_udp = 1;
Florin Coras99368312018-08-02 10:45:44 -0700597 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 Coras697faea2018-06-27 17:10:49 -0700600 }
601 if (getenv (VPPCOM_ENV_APP_SCOPE_LOCAL))
602 {
603 vcm->cfg.app_scope_local = 1;
Florin Coras99368312018-08-02 10:45:44 -0700604 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 Coras697faea2018-06-27 17:10:49 -0700607 }
608 if (getenv (VPPCOM_ENV_APP_SCOPE_GLOBAL))
609 {
610 vcm->cfg.app_scope_global = 1;
Florin Coras99368312018-08-02 10:45:44 -0700611 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 Coras697faea2018-06-27 17:10:49 -0700621 }
622}
623
624/*
625 * fd.io coding-style-patch-verification: ON
626 *
627 * Local Variables:
628 * eval: (c-set-style "gnu")
629 * End:
630 */