blob: 3fdda9cd6042a98e4dc8072357925a79ba58ec4e [file] [log] [blame]
Florin Coras697faea2018-06-27 17:10:49 -07001/*
Florin Coras5e062572019-03-14 19:07:51 -07002 * Copyright (c) 2018-2019 Cisco and/or its affiliates.
Florin Coras697faea2018-06-27 17:10:49 -07003 * 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 */
Florin Corasce815de2020-04-16 18:47:27 +000022vppcom_main_t _vppcom_main = {
Florin Coras697faea2018-06-27 17:10:49 -070023 .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};
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);
Florin Coras134a9962018-08-28 11:32:04 -070036 vcl_cfg->max_workers = 16;
Florin Coras697faea2018-06-27 17:10:49 -070037 vcl_cfg->vpp_api_q_length = 1024;
David Johnsond9818dd2018-12-14 14:53:41 -050038 vcl_cfg->segment_baseva = HIGH_SEGMENT_BASEVA;
Florin Coras697faea2018-06-27 17:10:49 -070039 vcl_cfg->segment_size = (256 << 20);
40 vcl_cfg->add_segment_size = (128 << 20);
41 vcl_cfg->preallocated_fifo_pairs = 8;
42 vcl_cfg->rx_fifo_size = (1 << 20);
43 vcl_cfg->tx_fifo_size = (1 << 20);
44 vcl_cfg->event_queue_size = 2048;
45 vcl_cfg->listen_queue_size = CLIB_CACHE_LINE_BYTES / sizeof (u32);
46 vcl_cfg->app_timeout = 10 * 60.0;
47 vcl_cfg->session_timeout = 10 * 60.0;
48 vcl_cfg->accept_timeout = 60.0;
49 vcl_cfg->event_ring_size = (128 << 10);
50 vcl_cfg->event_log_path = "/dev/shm";
Florin Coras697faea2018-06-27 17:10:49 -070051}
52
Florin Coras99368312018-08-02 10:45:44 -070053#define VCFG_DBG(_lvl, _fmt, _args...) \
54{ \
Florin Coras54693d22018-07-17 10:46:29 -070055 if (vcm->debug > _lvl) \
Florin Coras99368312018-08-02 10:45:44 -070056 fprintf (stderr, _fmt "\n", ##_args); \
57}
Florin Coras697faea2018-06-27 17:10:49 -070058void
59vppcom_cfg_heapsize (char *conf_fname)
60{
61 vppcom_cfg_t *vcl_cfg = &vcm->cfg;
62 FILE *fp;
63 char inbuf[4096];
64 int argc = 1;
65 char **argv = NULL;
66 char *arg = NULL;
67 char *p;
68 int i;
69 u8 *sizep;
70 u32 size;
71 void *vcl_mem;
72 void *heap;
73
74 fp = fopen (conf_fname, "r");
75 if (fp == NULL)
76 {
Florin Coras99368312018-08-02 10:45:44 -070077 VCFG_DBG (0, "VCL<%d>: using default heapsize %lu (0x%lx)",
David Johnsond9818dd2018-12-14 14:53:41 -050078 getpid (), (unsigned long) vcl_cfg->heapsize,
79 (unsigned long) 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"
David Johnsond9818dd2018-12-14 14:53:41 -050087 " (0x%lx)", getpid (), (unsigned long) vcl_cfg->heapsize,
88 (unsigned long) vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -070089 goto defaulted;
90 }
91
92 while (1)
93 {
94 if (fgets (inbuf, 4096, fp) == 0)
95 break;
96 p = strtok (inbuf, " \t\n");
97 while (p != NULL)
98 {
99 if (*p == '#')
100 break;
101 argc++;
102 char **tmp = realloc (argv, argc * sizeof (char *));
103 if (tmp == NULL)
104 {
Florin Coras99368312018-08-02 10:45:44 -0700105 VCFG_DBG (0, "VCL<%d>: realloc failed, using default "
106 "heapsize %lu (0x%lx)", getpid (),
David Johnsond9818dd2018-12-14 14:53:41 -0500107 (unsigned long) vcl_cfg->heapsize,
108 (unsigned long) vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700109 goto defaulted;
110 }
111 argv = tmp;
112 arg = strndup (p, 1024);
113 if (arg == NULL)
114 {
Florin Coras99368312018-08-02 10:45:44 -0700115 VCFG_DBG (0, "VCL<%d>: strndup failed, using default "
David Johnsond9818dd2018-12-14 14:53:41 -0500116 "heapsize %lu (0x%lx)", getpid (),
117 (unsigned long) vcl_cfg->heapsize,
118 (unsigned long) vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700119 goto defaulted;
120 }
121 argv[argc - 1] = arg;
122 p = strtok (NULL, " \t\n");
123 }
124 }
125
126 fclose (fp);
127 fp = NULL;
128
129 char **tmp = realloc (argv, (argc + 1) * sizeof (char *));
130 if (tmp == NULL)
131 {
David Johnsond9818dd2018-12-14 14:53:41 -0500132 VCFG_DBG (0, "VCL<%d>: realloc failed, using default heapsize %lu "
133 "(0x%lx)", getpid (), (unsigned long) vcl_cfg->heapsize,
134 (unsigned long) vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700135 goto defaulted;
136 }
137 argv = tmp;
138 argv[argc] = NULL;
139
140 /*
141 * Look for and parse the "heapsize" config parameter.
142 * Manual since none of the clib infra has been bootstrapped yet.
143 *
144 * Format: heapsize <nn>[mM][gG]
145 */
146
147 for (i = 1; i < (argc - 1); i++)
148 {
149 if (!strncmp (argv[i], "heapsize", 8))
150 {
151 sizep = (u8 *) argv[i + 1];
152 size = 0;
153 while (*sizep >= '0' && *sizep <= '9')
154 {
155 size *= 10;
156 size += *sizep++ - '0';
157 }
158 if (size == 0)
159 {
Florin Coras99368312018-08-02 10:45:44 -0700160 VCFG_DBG (0, "VCL<%d>: parse error '%s %s', using default "
David Johnsond9818dd2018-12-14 14:53:41 -0500161 "heapsize %lu (0x%lx)", getpid (), argv[i],
162 argv[i + 1], (unsigned long) vcl_cfg->heapsize,
163 (unsigned long) vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700164 goto defaulted;
165 }
166
167 if (*sizep == 'g' || *sizep == 'G')
168 vcl_cfg->heapsize = size << 30;
169 else if (*sizep == 'm' || *sizep == 'M')
170 vcl_cfg->heapsize = size << 20;
171 else
172 {
Florin Coras99368312018-08-02 10:45:44 -0700173 VCFG_DBG (0, "VCL<%d>: parse error '%s %s', using default "
David Johnsond9818dd2018-12-14 14:53:41 -0500174 "heapsize %lu (0x%lx)", getpid (), argv[i],
175 argv[i + 1], (unsigned long) vcl_cfg->heapsize,
176 (unsigned long) vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700177 goto defaulted;
178 }
179 }
Florin Coras053a0e42018-11-13 15:52:38 -0800180 free (argv[i]);
Florin Coras697faea2018-06-27 17:10:49 -0700181 }
182
183defaulted:
184 if (fp != NULL)
185 fclose (fp);
186 if (argv != NULL)
187 free (argv);
188
189 vcl_mem = mmap (0, vcl_cfg->heapsize, PROT_READ | PROT_WRITE,
190 MAP_SHARED | MAP_ANONYMOUS, -1, 0);
191 if (vcl_mem == MAP_FAILED)
192 {
David Johnsond9818dd2018-12-14 14:53:41 -0500193 VCFG_DBG (0, "VCL<%d>: ERROR: mmap(0, %lu == 0x%lx, "
Florin Coras99368312018-08-02 10:45:44 -0700194 "PROT_READ | PROT_WRITE,MAP_SHARED | MAP_ANONYMOUS, "
David Johnsond9818dd2018-12-14 14:53:41 -0500195 "-1, 0) failed!", getpid (),
196 (unsigned long) vcl_cfg->heapsize,
197 (unsigned long) vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700198 ASSERT (vcl_mem != MAP_FAILED);
199 return;
200 }
Dave Barach6a5adc32018-07-04 10:56:23 -0400201 heap = clib_mem_init_thread_safe (vcl_mem, vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700202 if (!heap)
203 {
Florin Coras54693d22018-07-17 10:46:29 -0700204 fprintf (stderr, "VCL<%d>: ERROR: clib_mem_init() failed!", getpid ());
Florin Coras697faea2018-06-27 17:10:49 -0700205 ASSERT (heap);
206 return;
207 }
208 vcl_mem = clib_mem_alloc (sizeof (_vppcom_main));
209 if (!vcl_mem)
210 {
211 clib_warning ("VCL<%d>: ERROR: clib_mem_alloc() failed!", getpid ());
212 ASSERT (vcl_mem);
213 return;
214 }
215
216 clib_memcpy (vcl_mem, &_vppcom_main, sizeof (_vppcom_main));
217 vcm = vcl_mem;
218
David Johnsond9818dd2018-12-14 14:53:41 -0500219 VCFG_DBG (0, "VCL<%d>: allocated VCL heap = %p, size %lu (0x%lx)",
220 getpid (), heap, (unsigned long) vcl_cfg->heapsize,
221 (unsigned long) vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700222}
223
224void
225vppcom_cfg_read_file (char *conf_fname)
226{
227 vppcom_cfg_t *vcl_cfg = &vcm->cfg;
228 int fd;
229 unformat_input_t _input, *input = &_input;
230 unformat_input_t _line_input, *line_input = &_line_input;
Florin Corasd4c70922019-11-28 14:21:21 -0800231 u8 vc_cfg_input = 0;
Florin Coras697faea2018-06-27 17:10:49 -0700232 struct stat s;
233 u32 uid, gid, q_len;
234
235 fd = open (conf_fname, O_RDONLY);
236 if (fd < 0)
237 {
Florin Coras99368312018-08-02 10:45:44 -0700238 VCFG_DBG (0, "VCL<%d>: using default configuration.", getpid ());
Florin Coras697faea2018-06-27 17:10:49 -0700239 goto file_done;
240 }
241
242 if (fstat (fd, &s) < 0)
243 {
Florin Coras053a0e42018-11-13 15:52:38 -0800244 VCFG_DBG (0, "VCL<%d>: failed to stat `%s' using default configuration",
Florin Coras99368312018-08-02 10:45:44 -0700245 getpid (), conf_fname);
Florin Coras697faea2018-06-27 17:10:49 -0700246 goto file_done;
247 }
248
249 if (!(S_ISREG (s.st_mode) || S_ISLNK (s.st_mode)))
250 {
Florin Coras99368312018-08-02 10:45:44 -0700251 VCFG_DBG (0, "VCL<%d>: not a regular file `%s', using default "
252 "configuration", getpid (), conf_fname);
Florin Coras697faea2018-06-27 17:10:49 -0700253 goto file_done;
254 }
255
256 unformat_init_clib_file (input, fd);
257
258 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
259 {
260 (void) unformat_user (input, unformat_line_input, line_input);
261 unformat_skip_white_space (line_input);
262
263 if (unformat (line_input, "vcl {"))
264 {
265 vc_cfg_input = 1;
Florin Coras053a0e42018-11-13 15:52:38 -0800266 unformat_free (line_input);
Florin Coras697faea2018-06-27 17:10:49 -0700267 continue;
268 }
269
270 if (vc_cfg_input)
271 {
Florin Coras053a0e42018-11-13 15:52:38 -0800272 if (unformat (line_input, "heapsize %U", unformat_memory_size,
273 &vcl_cfg->heapsize))
Florin Coras697faea2018-06-27 17:10:49 -0700274 {
Florin Coras134a9962018-08-28 11:32:04 -0700275 VCFG_DBG (0, "VCL<%d>: configured heapsize %lu", getpid (),
David Johnsond9818dd2018-12-14 14:53:41 -0500276 (unsigned long) vcl_cfg->heapsize);
Florin Coras134a9962018-08-28 11:32:04 -0700277 }
Florin Coras053a0e42018-11-13 15:52:38 -0800278 else
279 if (unformat
280 (line_input, "max-workers %u", &vcl_cfg->max_workers))
Florin Coras134a9962018-08-28 11:32:04 -0700281 {
282 VCFG_DBG (0, "VCL<%d>: configured max-workers %u", getpid (),
283 vcl_cfg->max_workers);
Florin Coras697faea2018-06-27 17:10:49 -0700284 }
Florin Corasd4c70922019-11-28 14:21:21 -0800285 else if (unformat (line_input, "api-prefix %s",
Florin Corasb88de902020-09-08 16:47:57 -0700286 &vcl_cfg->vpp_bapi_chroot))
Florin Coras697faea2018-06-27 17:10:49 -0700287 {
Florin Corasb88de902020-09-08 16:47:57 -0700288 vec_terminate_c_string (vcl_cfg->vpp_bapi_chroot);
Florin Corasd4c70922019-11-28 14:21:21 -0800289 VCFG_DBG (0, "VCL<%d>: configured api-prefix (%s) ", getpid (),
Florin Corasb88de902020-09-08 16:47:57 -0700290 vcl_cfg->vpp_bapi_chroot);
Florin Coras697faea2018-06-27 17:10:49 -0700291 }
Florin Coras99368312018-08-02 10:45:44 -0700292 else if (unformat (line_input, "api-socket-name %s",
Florin Corasb88de902020-09-08 16:47:57 -0700293 &vcl_cfg->vpp_bapi_socket_name))
Florin Coras99368312018-08-02 10:45:44 -0700294 {
Florin Corasb88de902020-09-08 16:47:57 -0700295 vec_terminate_c_string (vcl_cfg->vpp_bapi_socket_name);
Florin Coras99368312018-08-02 10:45:44 -0700296 VCFG_DBG (0, "VCL<%d>: configured api-socket-name (%s)",
Florin Corasb88de902020-09-08 16:47:57 -0700297 getpid (), vcl_cfg->vpp_bapi_socket_name);
Florin Coras99368312018-08-02 10:45:44 -0700298 }
Florin Coras935ce752020-09-08 22:43:47 -0700299 else if (unformat (line_input, "app-socket-api %s",
300 &vcl_cfg->vpp_app_socket_api))
301 {
302 vec_terminate_c_string (vcl_cfg->vpp_app_socket_api);
303 VCFG_DBG (0, "VCL<%d>: configured app-socket-api (%s)",
304 getpid (), vcl_cfg->vpp_app_socket_api);
305 }
Florin Coras697faea2018-06-27 17:10:49 -0700306 else if (unformat (line_input, "vpp-api-q-length %d", &q_len))
307 {
308 if (q_len < vcl_cfg->vpp_api_q_length)
309 {
Florin Coras99368312018-08-02 10:45:44 -0700310 fprintf (stderr,
311 "VCL<%d>: ERROR: configured vpp-api-q-length "
312 "(%u) is too small! Using default: %u ", getpid (),
313 q_len, vcl_cfg->vpp_api_q_length);
Florin Coras697faea2018-06-27 17:10:49 -0700314 }
315 else
316 {
317 vcl_cfg->vpp_api_q_length = q_len;
318
Florin Coras99368312018-08-02 10:45:44 -0700319 VCFG_DBG (0, "VCL<%d>: configured vpp-api-q-length %u",
320 getpid (), vcl_cfg->vpp_api_q_length);
Florin Coras697faea2018-06-27 17:10:49 -0700321 }
322 }
323 else if (unformat (line_input, "uid %d", &uid))
324 {
325 vl_set_memory_uid (uid);
Florin Coras99368312018-08-02 10:45:44 -0700326 VCFG_DBG (0, "VCL<%d>: configured uid %d", getpid (), uid);
Florin Coras697faea2018-06-27 17:10:49 -0700327 }
328 else if (unformat (line_input, "gid %d", &gid))
329 {
330 vl_set_memory_gid (gid);
Florin Coras99368312018-08-02 10:45:44 -0700331 VCFG_DBG (0, "VCL<%d>: configured gid %d", getpid (), gid);
Florin Coras697faea2018-06-27 17:10:49 -0700332 }
Florin Corasd18528f2020-03-27 18:41:54 +0000333 else if (unformat (line_input, "segment-baseva 0x%lx",
Florin Coras697faea2018-06-27 17:10:49 -0700334 &vcl_cfg->segment_baseva))
335 {
Florin Coras99368312018-08-02 10:45:44 -0700336 VCFG_DBG (0, "VCL<%d>: configured segment_baseva 0x%lx",
David Johnsond9818dd2018-12-14 14:53:41 -0500337 getpid (), (unsigned long) vcl_cfg->segment_baseva);
Florin Coras697faea2018-06-27 17:10:49 -0700338 }
Florin Corasd18528f2020-03-27 18:41:54 +0000339 else if (unformat (line_input, "segment-size 0x%lx",
Florin Coras697faea2018-06-27 17:10:49 -0700340 &vcl_cfg->segment_size))
341 {
Florin Corasd18528f2020-03-27 18:41:54 +0000342 VCFG_DBG (0, "VCL<%d>: configured segment_size 0x%lx (%lu)",
Florin Coras99368312018-08-02 10:45:44 -0700343 getpid (), vcl_cfg->segment_size,
344 vcl_cfg->segment_size);
Florin Coras697faea2018-06-27 17:10:49 -0700345 }
Florin Corasd18528f2020-03-27 18:41:54 +0000346 else if (unformat (line_input, "segment-size %lu",
Florin Coras697faea2018-06-27 17:10:49 -0700347 &vcl_cfg->segment_size))
348 {
Florin Corasd18528f2020-03-27 18:41:54 +0000349 VCFG_DBG (0, "VCL<%d>: configured segment_size %lu (0x%lx)",
Florin Coras99368312018-08-02 10:45:44 -0700350 getpid (), vcl_cfg->segment_size,
351 vcl_cfg->segment_size);
Florin Coras697faea2018-06-27 17:10:49 -0700352 }
Florin Corasd18528f2020-03-27 18:41:54 +0000353 else if (unformat (line_input, "add-segment-size 0x%lx",
Florin Coras697faea2018-06-27 17:10:49 -0700354 &vcl_cfg->add_segment_size))
355 {
Florin Corasd18528f2020-03-27 18:41:54 +0000356 VCFG_DBG (0, "VCL<%d>: configured add_segment_size 0x%lx (%lu)",
Florin Coras99368312018-08-02 10:45:44 -0700357 getpid (), vcl_cfg->add_segment_size,
358 vcl_cfg->add_segment_size);
Florin Coras697faea2018-06-27 17:10:49 -0700359 }
Florin Corasd18528f2020-03-27 18:41:54 +0000360 else if (unformat (line_input, "add-segment-size %lu",
Florin Coras697faea2018-06-27 17:10:49 -0700361 &vcl_cfg->add_segment_size))
362 {
Florin Corasd18528f2020-03-27 18:41:54 +0000363 VCFG_DBG (0, "VCL<%d>: configured add_segment_size %lu (0x%lx)",
Florin Coras99368312018-08-02 10:45:44 -0700364 getpid (), vcl_cfg->add_segment_size,
365 vcl_cfg->add_segment_size);
Florin Coras697faea2018-06-27 17:10:49 -0700366 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700367 else if (unformat (line_input, "preallocated-fifo-pairs %u",
Florin Coras697faea2018-06-27 17:10:49 -0700368 &vcl_cfg->preallocated_fifo_pairs))
369 {
Florin Coras1a3d2372019-07-28 10:25:40 -0700370 VCFG_DBG (0, "VCL<%d>: configured preallocated_fifo_pairs %u "
Florin Coras99368312018-08-02 10:45:44 -0700371 "(0x%x)", getpid (), vcl_cfg->preallocated_fifo_pairs,
372 vcl_cfg->preallocated_fifo_pairs);
Florin Coras697faea2018-06-27 17:10:49 -0700373 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700374 else if (unformat (line_input, "rx-fifo-size 0x%x",
Florin Coras697faea2018-06-27 17:10:49 -0700375 &vcl_cfg->rx_fifo_size))
376 {
Florin Coras1a3d2372019-07-28 10:25:40 -0700377 VCFG_DBG (0, "VCL<%d>: configured rx_fifo_size 0x%x (%u)",
Florin Coras99368312018-08-02 10:45:44 -0700378 getpid (), vcl_cfg->rx_fifo_size,
379 vcl_cfg->rx_fifo_size);
Florin Coras697faea2018-06-27 17:10:49 -0700380 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700381 else if (unformat (line_input, "rx-fifo-size %u",
Florin Coras697faea2018-06-27 17:10:49 -0700382 &vcl_cfg->rx_fifo_size))
383 {
Florin Coras1a3d2372019-07-28 10:25:40 -0700384 VCFG_DBG (0, "VCL<%d>: configured rx_fifo_size %u (0x%x)",
Florin Coras99368312018-08-02 10:45:44 -0700385 getpid (), vcl_cfg->rx_fifo_size,
386 vcl_cfg->rx_fifo_size);
Florin Coras697faea2018-06-27 17:10:49 -0700387 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700388 else if (unformat (line_input, "tx-fifo-size 0x%x",
Florin Coras697faea2018-06-27 17:10:49 -0700389 &vcl_cfg->tx_fifo_size))
390 {
Florin Coras1a3d2372019-07-28 10:25:40 -0700391 VCFG_DBG (0, "VCL<%d>: configured tx_fifo_size 0x%x (%u)",
Florin Coras99368312018-08-02 10:45:44 -0700392 getpid (), vcl_cfg->tx_fifo_size,
393 vcl_cfg->tx_fifo_size);
Florin Coras697faea2018-06-27 17:10:49 -0700394 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700395 else if (unformat (line_input, "tx-fifo-size %u",
Florin Coras697faea2018-06-27 17:10:49 -0700396 &vcl_cfg->tx_fifo_size))
397 {
Florin Coras1a3d2372019-07-28 10:25:40 -0700398 VCFG_DBG (0, "VCL<%d>: configured tx_fifo_size %u (0x%x)",
Florin Coras99368312018-08-02 10:45:44 -0700399 getpid (), vcl_cfg->tx_fifo_size,
400 vcl_cfg->tx_fifo_size);
Florin Coras697faea2018-06-27 17:10:49 -0700401 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700402 else if (unformat (line_input, "event-queue-size 0x%x",
Florin Coras697faea2018-06-27 17:10:49 -0700403 &vcl_cfg->event_queue_size))
404 {
Florin Coras1a3d2372019-07-28 10:25:40 -0700405 VCFG_DBG (0, "VCL<%d>: configured event_queue_size 0x%x (%u)",
Florin Coras99368312018-08-02 10:45:44 -0700406 getpid (), vcl_cfg->event_queue_size,
407 vcl_cfg->event_queue_size);
Florin Coras697faea2018-06-27 17:10:49 -0700408 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700409 else if (unformat (line_input, "event-queue-size %u",
Florin Coras697faea2018-06-27 17:10:49 -0700410 &vcl_cfg->event_queue_size))
411 {
Florin Coras1a3d2372019-07-28 10:25:40 -0700412 VCFG_DBG (0, "VCL<%d>: configured event_queue_size %u (0x%x)",
Florin Coras99368312018-08-02 10:45:44 -0700413 getpid (), vcl_cfg->event_queue_size,
414 vcl_cfg->event_queue_size);
Florin Coras697faea2018-06-27 17:10:49 -0700415 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700416 else if (unformat (line_input, "listen-queue-size 0x%x",
Florin Coras697faea2018-06-27 17:10:49 -0700417 &vcl_cfg->listen_queue_size))
418 {
Florin Coras99368312018-08-02 10:45:44 -0700419 VCFG_DBG (0, "VCL<%d>: configured listen_queue_size 0x%x (%u)",
420 getpid (), vcl_cfg->listen_queue_size,
421 vcl_cfg->listen_queue_size);
Florin Coras697faea2018-06-27 17:10:49 -0700422 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700423 else if (unformat (line_input, "listen-queue-size %u",
Florin Coras697faea2018-06-27 17:10:49 -0700424 &vcl_cfg->listen_queue_size))
425 {
Florin Coras99368312018-08-02 10:45:44 -0700426 VCFG_DBG (0, "VCL<%d>: configured listen_queue_size %u (0x%x)",
427 getpid (), vcl_cfg->listen_queue_size,
428 vcl_cfg->listen_queue_size);
Florin Coras697faea2018-06-27 17:10:49 -0700429 }
430 else if (unformat (line_input, "app-timeout %f",
431 &vcl_cfg->app_timeout))
432 {
Florin Coras99368312018-08-02 10:45:44 -0700433 VCFG_DBG (0, "VCL<%d>: configured app_timeout %f",
434 getpid (), vcl_cfg->app_timeout);
Florin Coras697faea2018-06-27 17:10:49 -0700435 }
436 else if (unformat (line_input, "session-timeout %f",
437 &vcl_cfg->session_timeout))
438 {
Florin Coras99368312018-08-02 10:45:44 -0700439 VCFG_DBG (0, "VCL<%d>: configured session_timeout %f",
440 getpid (), vcl_cfg->session_timeout);
Florin Coras697faea2018-06-27 17:10:49 -0700441 }
442 else if (unformat (line_input, "accept-timeout %f",
443 &vcl_cfg->accept_timeout))
444 {
Florin Coras99368312018-08-02 10:45:44 -0700445 VCFG_DBG (0, "VCL<%d>: configured accept_timeout %f",
446 getpid (), vcl_cfg->accept_timeout);
Florin Coras697faea2018-06-27 17:10:49 -0700447 }
448 else if (unformat (line_input, "app-proxy-transport-tcp"))
449 {
450 vcl_cfg->app_proxy_transport_tcp = 1;
Florin Coras99368312018-08-02 10:45:44 -0700451 VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_tcp (%d)",
452 getpid (), vcl_cfg->app_proxy_transport_tcp);
Florin Coras697faea2018-06-27 17:10:49 -0700453 }
454 else if (unformat (line_input, "app-proxy-transport-udp"))
455 {
456 vcl_cfg->app_proxy_transport_udp = 1;
Florin Coras99368312018-08-02 10:45:44 -0700457 VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_udp (%d)",
458 getpid (), vcl_cfg->app_proxy_transport_udp);
Florin Coras697faea2018-06-27 17:10:49 -0700459 }
460 else if (unformat (line_input, "app-scope-local"))
461 {
462 vcl_cfg->app_scope_local = 1;
Florin Coras99368312018-08-02 10:45:44 -0700463 VCFG_DBG (0, "VCL<%d>: configured app_scope_local (%d)",
464 getpid (), vcl_cfg->app_scope_local);
Florin Coras697faea2018-06-27 17:10:49 -0700465 }
466 else if (unformat (line_input, "app-scope-global"))
467 {
468 vcl_cfg->app_scope_global = 1;
Florin Coras99368312018-08-02 10:45:44 -0700469 VCFG_DBG (0, "VCL<%d>: configured app_scope_global (%d)",
470 getpid (), vcl_cfg->app_scope_global);
Florin Coras697faea2018-06-27 17:10:49 -0700471 }
472 else if (unformat (line_input, "namespace-secret %lu",
473 &vcl_cfg->namespace_secret))
474 {
Florin Coras1a3d2372019-07-28 10:25:40 -0700475 VCFG_DBG (0, "VCL<%d>: configured namespace_secret %llu "
476 "(0x%llx)", getpid (),
David Johnsond9818dd2018-12-14 14:53:41 -0500477 (unsigned long long) vcl_cfg->namespace_secret,
478 (unsigned long long) vcl_cfg->namespace_secret);
Florin Coras697faea2018-06-27 17:10:49 -0700479 }
480 else if (unformat (line_input, "namespace-id %v",
481 &vcl_cfg->namespace_id))
482 {
Florin Corasb88de902020-09-08 16:47:57 -0700483 u32 max_nsid_vec_len = vcl_bapi_max_nsid_len ();
Florin Coras697faea2018-06-27 17:10:49 -0700484 u32 nsid_vec_len = vec_len (vcl_cfg->namespace_id);
485 if (nsid_vec_len > max_nsid_vec_len)
486 {
487 _vec_len (vcl_cfg->namespace_id) = max_nsid_vec_len;
Florin Coras99368312018-08-02 10:45:44 -0700488 VCFG_DBG (0, "VCL<%d>: configured namespace_id is too long,"
489 " truncated to %d characters!",
490 getpid (), max_nsid_vec_len);
Florin Coras697faea2018-06-27 17:10:49 -0700491 }
492
Florin Coras99368312018-08-02 10:45:44 -0700493 VCFG_DBG (0, "VCL<%d>: configured namespace_id %s",
494 getpid (), (char *) vcl_cfg->namespace_id);
495 }
496 else if (unformat (line_input, "use-mq-eventfd"))
497 {
498 vcl_cfg->use_mq_eventfd = 1;
499 VCFG_DBG (0, "VCL<%d>: configured with mq with eventfd",
500 getpid ());
Florin Coras697faea2018-06-27 17:10:49 -0700501 }
Florin Corasd747c3c2019-10-20 19:55:56 -0700502 else if (unformat (line_input, "tls-engine %u",
503 &vcl_cfg->tls_engine))
504 {
505 VCFG_DBG (0, "VCL<%d>: configured tls-engine %u (0x%x)",
506 getpid (), vcl_cfg->tls_engine, vcl_cfg->tls_engine);
507 }
Florin Corasff40d8f2020-08-11 22:05:28 -0700508 else if (unformat (line_input, "multi-thread-workers"))
hanlina3a48962020-07-13 11:09:15 +0800509 {
Florin Corasff40d8f2020-08-11 22:05:28 -0700510 vcl_cfg->mt_wrk_supported = 1;
511 VCFG_DBG (0, "VCL<%d>: configured with multithread workers",
512 getpid ());
hanlina3a48962020-07-13 11:09:15 +0800513 }
Florin Coras697faea2018-06-27 17:10:49 -0700514 else if (unformat (line_input, "}"))
515 {
516 vc_cfg_input = 0;
Florin Coras99368312018-08-02 10:45:44 -0700517 VCFG_DBG (0, "VCL<%d>: completed parsing vppcom config!",
518 getpid ());
Florin Coras053a0e42018-11-13 15:52:38 -0800519 unformat_free (line_input);
Florin Coras697faea2018-06-27 17:10:49 -0700520 goto input_done;
521 }
522 else
523 {
524 if (line_input->buffer[line_input->index] != '#')
525 {
526 clib_warning ("VCL<%d>: Unknown vppcom config option: '%s'",
527 getpid (), (char *)
528 &line_input->buffer[line_input->index]);
529 }
530 }
Florin Coras053a0e42018-11-13 15:52:38 -0800531 unformat_free (line_input);
Florin Coras697faea2018-06-27 17:10:49 -0700532 }
533 }
534
535input_done:
536 unformat_free (input);
537
538file_done:
539 if (fd >= 0)
540 close (fd);
541}
542
543void
544vppcom_cfg (vppcom_cfg_t * vcl_cfg)
545{
546 char *conf_fname, *env_var_str;
547
548 vppcom_cfg_init (vcl_cfg);
549 env_var_str = getenv (VPPCOM_ENV_DEBUG);
550 if (env_var_str)
551 {
552 u32 tmp;
553 if (sscanf (env_var_str, "%u", &tmp) != 1)
Florin Coras9686eac2018-08-01 17:24:08 -0700554 {
Florin Coras99368312018-08-02 10:45:44 -0700555 VCFG_DBG (0, "VCL<%d>: WARNING: Invalid debug level specified "
556 "in the environment variable " VPPCOM_ENV_DEBUG
557 " (%s)!\n", getpid (), env_var_str);
Florin Coras9686eac2018-08-01 17:24:08 -0700558 }
Florin Coras697faea2018-06-27 17:10:49 -0700559 else
560 {
561 vcm->debug = tmp;
Florin Coras99368312018-08-02 10:45:44 -0700562 VCFG_DBG (0, "VCL<%d>: configured VCL debug level (%u) from "
563 VPPCOM_ENV_DEBUG "!", getpid (), vcm->debug);
Florin Coras697faea2018-06-27 17:10:49 -0700564 }
565 }
566 conf_fname = getenv (VPPCOM_ENV_CONF);
567 if (!conf_fname)
568 conf_fname = VPPCOM_CONF_DEFAULT;
569 vppcom_cfg_heapsize (conf_fname);
570 vppcom_cfg_read_file (conf_fname);
571
Florin Corasd4c70922019-11-28 14:21:21 -0800572 /* Regrab cfg after heap initialization */
573 vcl_cfg = &vcm->cfg;
Florin Coras697faea2018-06-27 17:10:49 -0700574 env_var_str = getenv (VPPCOM_ENV_API_PREFIX);
575 if (env_var_str)
576 {
Florin Corasb88de902020-09-08 16:47:57 -0700577 vcl_cfg->vpp_bapi_chroot = format (0, "%s", env_var_str);
578 vec_terminate_c_string (vcl_cfg->vpp_bapi_chroot);
Florin Corasd4c70922019-11-28 14:21:21 -0800579 VCFG_DBG (0, "VCL<%d>: configured api prefix (%s) from "
580 VPPCOM_ENV_API_PREFIX "!", getpid (), env_var_str);
Florin Coras697faea2018-06-27 17:10:49 -0700581 }
582 env_var_str = getenv (VPPCOM_ENV_APP_NAMESPACE_ID);
583 if (env_var_str)
584 {
585 u32 ns_id_vec_len = strlen (env_var_str);
586
587 vec_reset_length (vcm->cfg.namespace_id);
588 vec_validate (vcm->cfg.namespace_id, ns_id_vec_len - 1);
589 clib_memcpy (vcm->cfg.namespace_id, env_var_str, ns_id_vec_len);
590
Florin Coras99368312018-08-02 10:45:44 -0700591 VCFG_DBG (0, "VCL<%d>: configured namespace_id (%s) from "
BenoƮt Gannefe67afd2019-07-12 11:53:07 +0200592 VPPCOM_ENV_APP_NAMESPACE_ID "!", getpid (), env_var_str);
Florin Coras697faea2018-06-27 17:10:49 -0700593 }
594 env_var_str = getenv (VPPCOM_ENV_APP_NAMESPACE_SECRET);
595 if (env_var_str)
596 {
597 u64 tmp;
David Johnsond9818dd2018-12-14 14:53:41 -0500598 if (sscanf (env_var_str, "%llu", (unsigned long long *) &tmp) != 1)
Florin Coras99368312018-08-02 10:45:44 -0700599 {
600 VCFG_DBG (0, "VCL<%d>: WARNING: Invalid namespace secret specified"
601 " in the environment variable "
602 VPPCOM_ENV_APP_NAMESPACE_SECRET " (%s)!\n", getpid (),
603 env_var_str);
604 }
Florin Coras697faea2018-06-27 17:10:49 -0700605 else
606 {
607 vcm->cfg.namespace_secret = tmp;
David Johnsond9818dd2018-12-14 14:53:41 -0500608 VCFG_DBG (0, "VCL<%d>: configured namespace secret (%llu) from "
Florin Coras99368312018-08-02 10:45:44 -0700609 VPPCOM_ENV_APP_NAMESPACE_SECRET "!", getpid (),
David Johnsond9818dd2018-12-14 14:53:41 -0500610 (unsigned long long) vcm->cfg.namespace_secret);
Florin Coras697faea2018-06-27 17:10:49 -0700611 }
612 }
613 if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP))
614 {
615 vcm->cfg.app_proxy_transport_tcp = 1;
Florin Coras99368312018-08-02 10:45:44 -0700616 VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_tcp (%u) from "
617 VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP "!", getpid (),
618 vcm->cfg.app_proxy_transport_tcp);
Florin Coras697faea2018-06-27 17:10:49 -0700619 }
620 if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP))
621 {
622 vcm->cfg.app_proxy_transport_udp = 1;
Florin Coras99368312018-08-02 10:45:44 -0700623 VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_udp (%u) from "
624 VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP "!", getpid (),
625 vcm->cfg.app_proxy_transport_udp);
Florin Coras697faea2018-06-27 17:10:49 -0700626 }
627 if (getenv (VPPCOM_ENV_APP_SCOPE_LOCAL))
628 {
629 vcm->cfg.app_scope_local = 1;
Florin Coras99368312018-08-02 10:45:44 -0700630 VCFG_DBG (0, "VCL<%d>: configured app_scope_local (%u) from "
631 VPPCOM_ENV_APP_SCOPE_LOCAL "!", getpid (),
632 vcm->cfg.app_scope_local);
Florin Coras697faea2018-06-27 17:10:49 -0700633 }
634 if (getenv (VPPCOM_ENV_APP_SCOPE_GLOBAL))
635 {
636 vcm->cfg.app_scope_global = 1;
Florin Coras99368312018-08-02 10:45:44 -0700637 VCFG_DBG (0, "VCL<%d>: configured app_scope_global (%u) from "
638 VPPCOM_ENV_APP_SCOPE_GLOBAL "!", getpid (),
639 vcm->cfg.app_scope_global);
640 }
641 env_var_str = getenv (VPPCOM_ENV_VPP_API_SOCKET);
642 if (env_var_str)
643 {
Florin Corasb88de902020-09-08 16:47:57 -0700644 vcm->cfg.vpp_bapi_socket_name = format (0, "%s%c", env_var_str, 0);
Florin Coras99368312018-08-02 10:45:44 -0700645 VCFG_DBG (0, "VCL<%d>: configured api-socket-name (%s)", getpid (),
Florin Corasb88de902020-09-08 16:47:57 -0700646 vcl_cfg->vpp_bapi_socket_name);
Florin Coras697faea2018-06-27 17:10:49 -0700647 }
648}
649
650/*
651 * fd.io coding-style-patch-verification: ON
652 *
653 * Local Variables:
654 * eval: (c-set-style "gnu")
655 * End:
656 */