blob: 7b0710f5faf4baf33a50401787ee899c79cab98e [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;
David Johnsond9818dd2018-12-14 14:53:41 -050037 vcl_cfg->segment_baseva = HIGH_SEGMENT_BASEVA;
Florin Coras697faea2018-06-27 17:10:49 -070038 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)",
David Johnsond9818dd2018-12-14 14:53:41 -050077 getpid (), (unsigned long) vcl_cfg->heapsize,
78 (unsigned long) vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -070079 goto defaulted;
80 }
81
82 argv = calloc (1, sizeof (char *));
83 if (argv == NULL)
84 {
Florin Coras99368312018-08-02 10:45:44 -070085 VCFG_DBG (0, "VCL<%d>: calloc failed, using default heapsize %lu"
David Johnsond9818dd2018-12-14 14:53:41 -050086 " (0x%lx)", getpid (), (unsigned long) vcl_cfg->heapsize,
87 (unsigned long) 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 (),
David Johnsond9818dd2018-12-14 14:53:41 -0500106 (unsigned long) vcl_cfg->heapsize,
107 (unsigned long) vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700108 goto defaulted;
109 }
110 argv = tmp;
111 arg = strndup (p, 1024);
112 if (arg == NULL)
113 {
Florin Coras99368312018-08-02 10:45:44 -0700114 VCFG_DBG (0, "VCL<%d>: strndup failed, using default "
David Johnsond9818dd2018-12-14 14:53:41 -0500115 "heapsize %lu (0x%lx)", getpid (),
116 (unsigned long) vcl_cfg->heapsize,
117 (unsigned long) vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700118 goto defaulted;
119 }
120 argv[argc - 1] = arg;
121 p = strtok (NULL, " \t\n");
122 }
123 }
124
125 fclose (fp);
126 fp = NULL;
127
128 char **tmp = realloc (argv, (argc + 1) * sizeof (char *));
129 if (tmp == NULL)
130 {
David Johnsond9818dd2018-12-14 14:53:41 -0500131 VCFG_DBG (0, "VCL<%d>: realloc failed, using default heapsize %lu "
132 "(0x%lx)", getpid (), (unsigned long) vcl_cfg->heapsize,
133 (unsigned long) vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700134 goto defaulted;
135 }
136 argv = tmp;
137 argv[argc] = NULL;
138
139 /*
140 * Look for and parse the "heapsize" config parameter.
141 * Manual since none of the clib infra has been bootstrapped yet.
142 *
143 * Format: heapsize <nn>[mM][gG]
144 */
145
146 for (i = 1; i < (argc - 1); i++)
147 {
148 if (!strncmp (argv[i], "heapsize", 8))
149 {
150 sizep = (u8 *) argv[i + 1];
151 size = 0;
152 while (*sizep >= '0' && *sizep <= '9')
153 {
154 size *= 10;
155 size += *sizep++ - '0';
156 }
157 if (size == 0)
158 {
Florin Coras99368312018-08-02 10:45:44 -0700159 VCFG_DBG (0, "VCL<%d>: parse error '%s %s', using default "
David Johnsond9818dd2018-12-14 14:53:41 -0500160 "heapsize %lu (0x%lx)", getpid (), argv[i],
161 argv[i + 1], (unsigned long) vcl_cfg->heapsize,
162 (unsigned long) vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700163 goto defaulted;
164 }
165
166 if (*sizep == 'g' || *sizep == 'G')
167 vcl_cfg->heapsize = size << 30;
168 else if (*sizep == 'm' || *sizep == 'M')
169 vcl_cfg->heapsize = size << 20;
170 else
171 {
Florin Coras99368312018-08-02 10:45:44 -0700172 VCFG_DBG (0, "VCL<%d>: parse error '%s %s', using default "
David Johnsond9818dd2018-12-14 14:53:41 -0500173 "heapsize %lu (0x%lx)", getpid (), argv[i],
174 argv[i + 1], (unsigned long) vcl_cfg->heapsize,
175 (unsigned long) vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700176 goto defaulted;
177 }
178 }
Florin Coras053a0e42018-11-13 15:52:38 -0800179 free (argv[i]);
Florin Coras697faea2018-06-27 17:10:49 -0700180 }
181
182defaulted:
183 if (fp != NULL)
184 fclose (fp);
185 if (argv != NULL)
186 free (argv);
187
188 vcl_mem = mmap (0, vcl_cfg->heapsize, PROT_READ | PROT_WRITE,
189 MAP_SHARED | MAP_ANONYMOUS, -1, 0);
190 if (vcl_mem == MAP_FAILED)
191 {
David Johnsond9818dd2018-12-14 14:53:41 -0500192 VCFG_DBG (0, "VCL<%d>: ERROR: mmap(0, %lu == 0x%lx, "
Florin Coras99368312018-08-02 10:45:44 -0700193 "PROT_READ | PROT_WRITE,MAP_SHARED | MAP_ANONYMOUS, "
David Johnsond9818dd2018-12-14 14:53:41 -0500194 "-1, 0) failed!", getpid (),
195 (unsigned long) vcl_cfg->heapsize,
196 (unsigned long) vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700197 ASSERT (vcl_mem != MAP_FAILED);
198 return;
199 }
Dave Barach6a5adc32018-07-04 10:56:23 -0400200 heap = clib_mem_init_thread_safe (vcl_mem, vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700201 if (!heap)
202 {
Florin Coras54693d22018-07-17 10:46:29 -0700203 fprintf (stderr, "VCL<%d>: ERROR: clib_mem_init() failed!", getpid ());
Florin Coras697faea2018-06-27 17:10:49 -0700204 ASSERT (heap);
205 return;
206 }
207 vcl_mem = clib_mem_alloc (sizeof (_vppcom_main));
208 if (!vcl_mem)
209 {
210 clib_warning ("VCL<%d>: ERROR: clib_mem_alloc() failed!", getpid ());
211 ASSERT (vcl_mem);
212 return;
213 }
214
215 clib_memcpy (vcl_mem, &_vppcom_main, sizeof (_vppcom_main));
216 vcm = vcl_mem;
217
David Johnsond9818dd2018-12-14 14:53:41 -0500218 VCFG_DBG (0, "VCL<%d>: allocated VCL heap = %p, size %lu (0x%lx)",
219 getpid (), heap, (unsigned long) vcl_cfg->heapsize,
220 (unsigned long) vcl_cfg->heapsize);
Florin Coras697faea2018-06-27 17:10:49 -0700221}
222
223void
224vppcom_cfg_read_file (char *conf_fname)
225{
226 vppcom_cfg_t *vcl_cfg = &vcm->cfg;
227 int fd;
228 unformat_input_t _input, *input = &_input;
229 unformat_input_t _line_input, *line_input = &_line_input;
Florin Corasd4c70922019-11-28 14:21:21 -0800230 u8 vc_cfg_input = 0;
Florin Coras697faea2018-06-27 17:10:49 -0700231 struct stat s;
Florin Corasca78b562020-11-09 19:59:16 -0800232 u32 uid, gid;
Florin Coras697faea2018-06-27 17:10:49 -0700233
234 fd = open (conf_fname, O_RDONLY);
235 if (fd < 0)
236 {
Florin Coras99368312018-08-02 10:45:44 -0700237 VCFG_DBG (0, "VCL<%d>: using default configuration.", getpid ());
Florin Coras697faea2018-06-27 17:10:49 -0700238 goto file_done;
239 }
240
241 if (fstat (fd, &s) < 0)
242 {
Florin Coras053a0e42018-11-13 15:52:38 -0800243 VCFG_DBG (0, "VCL<%d>: failed to stat `%s' using default configuration",
Florin Coras99368312018-08-02 10:45:44 -0700244 getpid (), conf_fname);
Florin Coras697faea2018-06-27 17:10:49 -0700245 goto file_done;
246 }
247
248 if (!(S_ISREG (s.st_mode) || S_ISLNK (s.st_mode)))
249 {
Florin Coras99368312018-08-02 10:45:44 -0700250 VCFG_DBG (0, "VCL<%d>: not a regular file `%s', using default "
251 "configuration", getpid (), conf_fname);
Florin Coras697faea2018-06-27 17:10:49 -0700252 goto file_done;
253 }
254
255 unformat_init_clib_file (input, fd);
256
257 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
258 {
259 (void) unformat_user (input, unformat_line_input, line_input);
260 unformat_skip_white_space (line_input);
261
262 if (unformat (line_input, "vcl {"))
263 {
264 vc_cfg_input = 1;
Florin Coras053a0e42018-11-13 15:52:38 -0800265 unformat_free (line_input);
Florin Coras697faea2018-06-27 17:10:49 -0700266 continue;
267 }
268
269 if (vc_cfg_input)
270 {
Florin Coras053a0e42018-11-13 15:52:38 -0800271 if (unformat (line_input, "heapsize %U", unformat_memory_size,
272 &vcl_cfg->heapsize))
Florin Coras697faea2018-06-27 17:10:49 -0700273 {
Florin Coras134a9962018-08-28 11:32:04 -0700274 VCFG_DBG (0, "VCL<%d>: configured heapsize %lu", getpid (),
David Johnsond9818dd2018-12-14 14:53:41 -0500275 (unsigned long) vcl_cfg->heapsize);
Florin Coras134a9962018-08-28 11:32:04 -0700276 }
Florin Coras053a0e42018-11-13 15:52:38 -0800277 else
278 if (unformat
279 (line_input, "max-workers %u", &vcl_cfg->max_workers))
Florin Coras134a9962018-08-28 11:32:04 -0700280 {
281 VCFG_DBG (0, "VCL<%d>: configured max-workers %u", getpid (),
282 vcl_cfg->max_workers);
Florin Coras697faea2018-06-27 17:10:49 -0700283 }
Florin Coras99368312018-08-02 10:45:44 -0700284 else if (unformat (line_input, "api-socket-name %s",
Florin Corasb88de902020-09-08 16:47:57 -0700285 &vcl_cfg->vpp_bapi_socket_name))
Florin Coras99368312018-08-02 10:45:44 -0700286 {
Florin Corasb88de902020-09-08 16:47:57 -0700287 vec_terminate_c_string (vcl_cfg->vpp_bapi_socket_name);
Florin Coras99368312018-08-02 10:45:44 -0700288 VCFG_DBG (0, "VCL<%d>: configured api-socket-name (%s)",
Florin Corasb88de902020-09-08 16:47:57 -0700289 getpid (), vcl_cfg->vpp_bapi_socket_name);
Florin Coras99368312018-08-02 10:45:44 -0700290 }
Florin Coras935ce752020-09-08 22:43:47 -0700291 else if (unformat (line_input, "app-socket-api %s",
292 &vcl_cfg->vpp_app_socket_api))
293 {
294 vec_terminate_c_string (vcl_cfg->vpp_app_socket_api);
295 VCFG_DBG (0, "VCL<%d>: configured app-socket-api (%s)",
296 getpid (), vcl_cfg->vpp_app_socket_api);
297 }
Florin Coras697faea2018-06-27 17:10:49 -0700298 else if (unformat (line_input, "uid %d", &uid))
299 {
300 vl_set_memory_uid (uid);
Florin Coras99368312018-08-02 10:45:44 -0700301 VCFG_DBG (0, "VCL<%d>: configured uid %d", getpid (), uid);
Florin Coras697faea2018-06-27 17:10:49 -0700302 }
303 else if (unformat (line_input, "gid %d", &gid))
304 {
305 vl_set_memory_gid (gid);
Florin Coras99368312018-08-02 10:45:44 -0700306 VCFG_DBG (0, "VCL<%d>: configured gid %d", getpid (), gid);
Florin Coras697faea2018-06-27 17:10:49 -0700307 }
Florin Corasd18528f2020-03-27 18:41:54 +0000308 else if (unformat (line_input, "segment-baseva 0x%lx",
Florin Coras697faea2018-06-27 17:10:49 -0700309 &vcl_cfg->segment_baseva))
310 {
Florin Coras99368312018-08-02 10:45:44 -0700311 VCFG_DBG (0, "VCL<%d>: configured segment_baseva 0x%lx",
David Johnsond9818dd2018-12-14 14:53:41 -0500312 getpid (), (unsigned long) vcl_cfg->segment_baseva);
Florin Coras697faea2018-06-27 17:10:49 -0700313 }
Florin Corasd18528f2020-03-27 18:41:54 +0000314 else if (unformat (line_input, "segment-size 0x%lx",
Florin Coras697faea2018-06-27 17:10:49 -0700315 &vcl_cfg->segment_size))
316 {
Florin Corasd18528f2020-03-27 18:41:54 +0000317 VCFG_DBG (0, "VCL<%d>: configured segment_size 0x%lx (%lu)",
Florin Coras99368312018-08-02 10:45:44 -0700318 getpid (), vcl_cfg->segment_size,
319 vcl_cfg->segment_size);
Florin Coras697faea2018-06-27 17:10:49 -0700320 }
Florin Corasd18528f2020-03-27 18:41:54 +0000321 else if (unformat (line_input, "segment-size %lu",
Florin Coras697faea2018-06-27 17:10:49 -0700322 &vcl_cfg->segment_size))
323 {
Florin Corasd18528f2020-03-27 18:41:54 +0000324 VCFG_DBG (0, "VCL<%d>: configured segment_size %lu (0x%lx)",
Florin Coras99368312018-08-02 10:45:44 -0700325 getpid (), vcl_cfg->segment_size,
326 vcl_cfg->segment_size);
Florin Coras697faea2018-06-27 17:10:49 -0700327 }
Florin Corasd18528f2020-03-27 18:41:54 +0000328 else if (unformat (line_input, "add-segment-size 0x%lx",
Florin Coras697faea2018-06-27 17:10:49 -0700329 &vcl_cfg->add_segment_size))
330 {
Florin Corasd18528f2020-03-27 18:41:54 +0000331 VCFG_DBG (0, "VCL<%d>: configured add_segment_size 0x%lx (%lu)",
Florin Coras99368312018-08-02 10:45:44 -0700332 getpid (), vcl_cfg->add_segment_size,
333 vcl_cfg->add_segment_size);
Florin Coras697faea2018-06-27 17:10:49 -0700334 }
Florin Corasd18528f2020-03-27 18:41:54 +0000335 else if (unformat (line_input, "add-segment-size %lu",
Florin Coras697faea2018-06-27 17:10:49 -0700336 &vcl_cfg->add_segment_size))
337 {
Florin Corasd18528f2020-03-27 18:41:54 +0000338 VCFG_DBG (0, "VCL<%d>: configured add_segment_size %lu (0x%lx)",
Florin Coras99368312018-08-02 10:45:44 -0700339 getpid (), vcl_cfg->add_segment_size,
340 vcl_cfg->add_segment_size);
Florin Coras697faea2018-06-27 17:10:49 -0700341 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700342 else if (unformat (line_input, "preallocated-fifo-pairs %u",
Florin Coras697faea2018-06-27 17:10:49 -0700343 &vcl_cfg->preallocated_fifo_pairs))
344 {
Florin Coras1a3d2372019-07-28 10:25:40 -0700345 VCFG_DBG (0, "VCL<%d>: configured preallocated_fifo_pairs %u "
Florin Coras99368312018-08-02 10:45:44 -0700346 "(0x%x)", getpid (), vcl_cfg->preallocated_fifo_pairs,
347 vcl_cfg->preallocated_fifo_pairs);
Florin Coras697faea2018-06-27 17:10:49 -0700348 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700349 else if (unformat (line_input, "rx-fifo-size 0x%x",
Florin Coras697faea2018-06-27 17:10:49 -0700350 &vcl_cfg->rx_fifo_size))
351 {
Florin Coras1a3d2372019-07-28 10:25:40 -0700352 VCFG_DBG (0, "VCL<%d>: configured rx_fifo_size 0x%x (%u)",
Florin Coras99368312018-08-02 10:45:44 -0700353 getpid (), vcl_cfg->rx_fifo_size,
354 vcl_cfg->rx_fifo_size);
Florin Coras697faea2018-06-27 17:10:49 -0700355 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700356 else if (unformat (line_input, "rx-fifo-size %u",
Florin Coras697faea2018-06-27 17:10:49 -0700357 &vcl_cfg->rx_fifo_size))
358 {
Florin Coras1a3d2372019-07-28 10:25:40 -0700359 VCFG_DBG (0, "VCL<%d>: configured rx_fifo_size %u (0x%x)",
Florin Coras99368312018-08-02 10:45:44 -0700360 getpid (), vcl_cfg->rx_fifo_size,
361 vcl_cfg->rx_fifo_size);
Florin Coras697faea2018-06-27 17:10:49 -0700362 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700363 else if (unformat (line_input, "tx-fifo-size 0x%x",
Florin Coras697faea2018-06-27 17:10:49 -0700364 &vcl_cfg->tx_fifo_size))
365 {
Florin Coras1a3d2372019-07-28 10:25:40 -0700366 VCFG_DBG (0, "VCL<%d>: configured tx_fifo_size 0x%x (%u)",
Florin Coras99368312018-08-02 10:45:44 -0700367 getpid (), vcl_cfg->tx_fifo_size,
368 vcl_cfg->tx_fifo_size);
Florin Coras697faea2018-06-27 17:10:49 -0700369 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700370 else if (unformat (line_input, "tx-fifo-size %u",
Florin Coras697faea2018-06-27 17:10:49 -0700371 &vcl_cfg->tx_fifo_size))
372 {
Florin Coras1a3d2372019-07-28 10:25:40 -0700373 VCFG_DBG (0, "VCL<%d>: configured tx_fifo_size %u (0x%x)",
Florin Coras99368312018-08-02 10:45:44 -0700374 getpid (), vcl_cfg->tx_fifo_size,
375 vcl_cfg->tx_fifo_size);
Florin Coras697faea2018-06-27 17:10:49 -0700376 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700377 else if (unformat (line_input, "event-queue-size 0x%x",
Florin Coras697faea2018-06-27 17:10:49 -0700378 &vcl_cfg->event_queue_size))
379 {
Florin Coras1a3d2372019-07-28 10:25:40 -0700380 VCFG_DBG (0, "VCL<%d>: configured event_queue_size 0x%x (%u)",
Florin Coras99368312018-08-02 10:45:44 -0700381 getpid (), vcl_cfg->event_queue_size,
382 vcl_cfg->event_queue_size);
Florin Coras697faea2018-06-27 17:10:49 -0700383 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700384 else if (unformat (line_input, "event-queue-size %u",
Florin Coras697faea2018-06-27 17:10:49 -0700385 &vcl_cfg->event_queue_size))
386 {
Florin Coras1a3d2372019-07-28 10:25:40 -0700387 VCFG_DBG (0, "VCL<%d>: configured event_queue_size %u (0x%x)",
Florin Coras99368312018-08-02 10:45:44 -0700388 getpid (), vcl_cfg->event_queue_size,
389 vcl_cfg->event_queue_size);
Florin Coras697faea2018-06-27 17:10:49 -0700390 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700391 else if (unformat (line_input, "listen-queue-size 0x%x",
Florin Coras697faea2018-06-27 17:10:49 -0700392 &vcl_cfg->listen_queue_size))
393 {
Florin Coras99368312018-08-02 10:45:44 -0700394 VCFG_DBG (0, "VCL<%d>: configured listen_queue_size 0x%x (%u)",
395 getpid (), vcl_cfg->listen_queue_size,
396 vcl_cfg->listen_queue_size);
Florin Coras697faea2018-06-27 17:10:49 -0700397 }
Florin Coras1a3d2372019-07-28 10:25:40 -0700398 else if (unformat (line_input, "listen-queue-size %u",
Florin Coras697faea2018-06-27 17:10:49 -0700399 &vcl_cfg->listen_queue_size))
400 {
Florin Coras99368312018-08-02 10:45:44 -0700401 VCFG_DBG (0, "VCL<%d>: configured listen_queue_size %u (0x%x)",
402 getpid (), vcl_cfg->listen_queue_size,
403 vcl_cfg->listen_queue_size);
Florin Coras697faea2018-06-27 17:10:49 -0700404 }
405 else if (unformat (line_input, "app-timeout %f",
406 &vcl_cfg->app_timeout))
407 {
Florin Coras99368312018-08-02 10:45:44 -0700408 VCFG_DBG (0, "VCL<%d>: configured app_timeout %f",
409 getpid (), vcl_cfg->app_timeout);
Florin Coras697faea2018-06-27 17:10:49 -0700410 }
411 else if (unformat (line_input, "session-timeout %f",
412 &vcl_cfg->session_timeout))
413 {
Florin Coras99368312018-08-02 10:45:44 -0700414 VCFG_DBG (0, "VCL<%d>: configured session_timeout %f",
415 getpid (), vcl_cfg->session_timeout);
Florin Coras697faea2018-06-27 17:10:49 -0700416 }
417 else if (unformat (line_input, "accept-timeout %f",
418 &vcl_cfg->accept_timeout))
419 {
Florin Coras99368312018-08-02 10:45:44 -0700420 VCFG_DBG (0, "VCL<%d>: configured accept_timeout %f",
421 getpid (), vcl_cfg->accept_timeout);
Florin Coras697faea2018-06-27 17:10:49 -0700422 }
423 else if (unformat (line_input, "app-proxy-transport-tcp"))
424 {
425 vcl_cfg->app_proxy_transport_tcp = 1;
Florin Coras99368312018-08-02 10:45:44 -0700426 VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_tcp (%d)",
427 getpid (), vcl_cfg->app_proxy_transport_tcp);
Florin Coras697faea2018-06-27 17:10:49 -0700428 }
429 else if (unformat (line_input, "app-proxy-transport-udp"))
430 {
431 vcl_cfg->app_proxy_transport_udp = 1;
Florin Coras99368312018-08-02 10:45:44 -0700432 VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_udp (%d)",
433 getpid (), vcl_cfg->app_proxy_transport_udp);
Florin Coras697faea2018-06-27 17:10:49 -0700434 }
435 else if (unformat (line_input, "app-scope-local"))
436 {
437 vcl_cfg->app_scope_local = 1;
Florin Coras99368312018-08-02 10:45:44 -0700438 VCFG_DBG (0, "VCL<%d>: configured app_scope_local (%d)",
439 getpid (), vcl_cfg->app_scope_local);
Florin Coras697faea2018-06-27 17:10:49 -0700440 }
441 else if (unformat (line_input, "app-scope-global"))
442 {
443 vcl_cfg->app_scope_global = 1;
Florin Coras99368312018-08-02 10:45:44 -0700444 VCFG_DBG (0, "VCL<%d>: configured app_scope_global (%d)",
445 getpid (), vcl_cfg->app_scope_global);
Florin Coras697faea2018-06-27 17:10:49 -0700446 }
447 else if (unformat (line_input, "namespace-secret %lu",
448 &vcl_cfg->namespace_secret))
449 {
Florin Coras1a3d2372019-07-28 10:25:40 -0700450 VCFG_DBG (0, "VCL<%d>: configured namespace_secret %llu "
451 "(0x%llx)", getpid (),
David Johnsond9818dd2018-12-14 14:53:41 -0500452 (unsigned long long) vcl_cfg->namespace_secret,
453 (unsigned long long) vcl_cfg->namespace_secret);
Florin Coras697faea2018-06-27 17:10:49 -0700454 }
455 else if (unformat (line_input, "namespace-id %v",
456 &vcl_cfg->namespace_id))
457 {
Florin Corasb88de902020-09-08 16:47:57 -0700458 u32 max_nsid_vec_len = vcl_bapi_max_nsid_len ();
Florin Coras697faea2018-06-27 17:10:49 -0700459 u32 nsid_vec_len = vec_len (vcl_cfg->namespace_id);
460 if (nsid_vec_len > max_nsid_vec_len)
461 {
462 _vec_len (vcl_cfg->namespace_id) = max_nsid_vec_len;
Florin Coras99368312018-08-02 10:45:44 -0700463 VCFG_DBG (0, "VCL<%d>: configured namespace_id is too long,"
464 " truncated to %d characters!",
465 getpid (), max_nsid_vec_len);
Florin Coras697faea2018-06-27 17:10:49 -0700466 }
467
Florin Coras99368312018-08-02 10:45:44 -0700468 VCFG_DBG (0, "VCL<%d>: configured namespace_id %s",
469 getpid (), (char *) vcl_cfg->namespace_id);
470 }
471 else if (unformat (line_input, "use-mq-eventfd"))
472 {
473 vcl_cfg->use_mq_eventfd = 1;
474 VCFG_DBG (0, "VCL<%d>: configured with mq with eventfd",
475 getpid ());
Florin Coras697faea2018-06-27 17:10:49 -0700476 }
Florin Corasd747c3c2019-10-20 19:55:56 -0700477 else if (unformat (line_input, "tls-engine %u",
478 &vcl_cfg->tls_engine))
479 {
480 VCFG_DBG (0, "VCL<%d>: configured tls-engine %u (0x%x)",
481 getpid (), vcl_cfg->tls_engine, vcl_cfg->tls_engine);
482 }
Florin Corasff40d8f2020-08-11 22:05:28 -0700483 else if (unformat (line_input, "multi-thread-workers"))
hanlina3a48962020-07-13 11:09:15 +0800484 {
Florin Corasff40d8f2020-08-11 22:05:28 -0700485 vcl_cfg->mt_wrk_supported = 1;
486 VCFG_DBG (0, "VCL<%d>: configured with multithread workers",
487 getpid ());
hanlina3a48962020-07-13 11:09:15 +0800488 }
Florin Coras697faea2018-06-27 17:10:49 -0700489 else if (unformat (line_input, "}"))
490 {
491 vc_cfg_input = 0;
Florin Coras99368312018-08-02 10:45:44 -0700492 VCFG_DBG (0, "VCL<%d>: completed parsing vppcom config!",
493 getpid ());
Florin Coras053a0e42018-11-13 15:52:38 -0800494 unformat_free (line_input);
Florin Coras697faea2018-06-27 17:10:49 -0700495 goto input_done;
496 }
497 else
498 {
499 if (line_input->buffer[line_input->index] != '#')
500 {
501 clib_warning ("VCL<%d>: Unknown vppcom config option: '%s'",
502 getpid (), (char *)
503 &line_input->buffer[line_input->index]);
504 }
505 }
Florin Coras053a0e42018-11-13 15:52:38 -0800506 unformat_free (line_input);
Florin Coras697faea2018-06-27 17:10:49 -0700507 }
508 }
509
510input_done:
511 unformat_free (input);
512
513file_done:
514 if (fd >= 0)
515 close (fd);
516}
517
518void
519vppcom_cfg (vppcom_cfg_t * vcl_cfg)
520{
521 char *conf_fname, *env_var_str;
522
523 vppcom_cfg_init (vcl_cfg);
524 env_var_str = getenv (VPPCOM_ENV_DEBUG);
525 if (env_var_str)
526 {
527 u32 tmp;
528 if (sscanf (env_var_str, "%u", &tmp) != 1)
Florin Coras9686eac2018-08-01 17:24:08 -0700529 {
Florin Coras99368312018-08-02 10:45:44 -0700530 VCFG_DBG (0, "VCL<%d>: WARNING: Invalid debug level specified "
531 "in the environment variable " VPPCOM_ENV_DEBUG
532 " (%s)!\n", getpid (), env_var_str);
Florin Coras9686eac2018-08-01 17:24:08 -0700533 }
Florin Coras697faea2018-06-27 17:10:49 -0700534 else
535 {
536 vcm->debug = tmp;
Florin Coras99368312018-08-02 10:45:44 -0700537 VCFG_DBG (0, "VCL<%d>: configured VCL debug level (%u) from "
538 VPPCOM_ENV_DEBUG "!", getpid (), vcm->debug);
Florin Coras697faea2018-06-27 17:10:49 -0700539 }
540 }
541 conf_fname = getenv (VPPCOM_ENV_CONF);
542 if (!conf_fname)
543 conf_fname = VPPCOM_CONF_DEFAULT;
544 vppcom_cfg_heapsize (conf_fname);
545 vppcom_cfg_read_file (conf_fname);
546
Florin Corasd4c70922019-11-28 14:21:21 -0800547 /* Regrab cfg after heap initialization */
548 vcl_cfg = &vcm->cfg;
Florin Coras697faea2018-06-27 17:10:49 -0700549 env_var_str = getenv (VPPCOM_ENV_APP_NAMESPACE_ID);
550 if (env_var_str)
551 {
552 u32 ns_id_vec_len = strlen (env_var_str);
553
554 vec_reset_length (vcm->cfg.namespace_id);
555 vec_validate (vcm->cfg.namespace_id, ns_id_vec_len - 1);
556 clib_memcpy (vcm->cfg.namespace_id, env_var_str, ns_id_vec_len);
557
Florin Coras99368312018-08-02 10:45:44 -0700558 VCFG_DBG (0, "VCL<%d>: configured namespace_id (%s) from "
BenoƮt Gannefe67afd2019-07-12 11:53:07 +0200559 VPPCOM_ENV_APP_NAMESPACE_ID "!", getpid (), env_var_str);
Florin Coras697faea2018-06-27 17:10:49 -0700560 }
561 env_var_str = getenv (VPPCOM_ENV_APP_NAMESPACE_SECRET);
562 if (env_var_str)
563 {
564 u64 tmp;
David Johnsond9818dd2018-12-14 14:53:41 -0500565 if (sscanf (env_var_str, "%llu", (unsigned long long *) &tmp) != 1)
Florin Coras99368312018-08-02 10:45:44 -0700566 {
567 VCFG_DBG (0, "VCL<%d>: WARNING: Invalid namespace secret specified"
568 " in the environment variable "
569 VPPCOM_ENV_APP_NAMESPACE_SECRET " (%s)!\n", getpid (),
570 env_var_str);
571 }
Florin Coras697faea2018-06-27 17:10:49 -0700572 else
573 {
574 vcm->cfg.namespace_secret = tmp;
David Johnsond9818dd2018-12-14 14:53:41 -0500575 VCFG_DBG (0, "VCL<%d>: configured namespace secret (%llu) from "
Florin Coras99368312018-08-02 10:45:44 -0700576 VPPCOM_ENV_APP_NAMESPACE_SECRET "!", getpid (),
David Johnsond9818dd2018-12-14 14:53:41 -0500577 (unsigned long long) vcm->cfg.namespace_secret);
Florin Coras697faea2018-06-27 17:10:49 -0700578 }
579 }
580 if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP))
581 {
582 vcm->cfg.app_proxy_transport_tcp = 1;
Florin Coras99368312018-08-02 10:45:44 -0700583 VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_tcp (%u) from "
584 VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP "!", getpid (),
585 vcm->cfg.app_proxy_transport_tcp);
Florin Coras697faea2018-06-27 17:10:49 -0700586 }
587 if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP))
588 {
589 vcm->cfg.app_proxy_transport_udp = 1;
Florin Coras99368312018-08-02 10:45:44 -0700590 VCFG_DBG (0, "VCL<%d>: configured app_proxy_transport_udp (%u) from "
591 VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP "!", getpid (),
592 vcm->cfg.app_proxy_transport_udp);
Florin Coras697faea2018-06-27 17:10:49 -0700593 }
594 if (getenv (VPPCOM_ENV_APP_SCOPE_LOCAL))
595 {
596 vcm->cfg.app_scope_local = 1;
Florin Coras99368312018-08-02 10:45:44 -0700597 VCFG_DBG (0, "VCL<%d>: configured app_scope_local (%u) from "
598 VPPCOM_ENV_APP_SCOPE_LOCAL "!", getpid (),
599 vcm->cfg.app_scope_local);
Florin Coras697faea2018-06-27 17:10:49 -0700600 }
601 if (getenv (VPPCOM_ENV_APP_SCOPE_GLOBAL))
602 {
603 vcm->cfg.app_scope_global = 1;
Florin Coras99368312018-08-02 10:45:44 -0700604 VCFG_DBG (0, "VCL<%d>: configured app_scope_global (%u) from "
605 VPPCOM_ENV_APP_SCOPE_GLOBAL "!", getpid (),
606 vcm->cfg.app_scope_global);
607 }
608 env_var_str = getenv (VPPCOM_ENV_VPP_API_SOCKET);
609 if (env_var_str)
610 {
Florin Corasb88de902020-09-08 16:47:57 -0700611 vcm->cfg.vpp_bapi_socket_name = format (0, "%s%c", env_var_str, 0);
Florin Coras99368312018-08-02 10:45:44 -0700612 VCFG_DBG (0, "VCL<%d>: configured api-socket-name (%s)", getpid (),
Florin Corasb88de902020-09-08 16:47:57 -0700613 vcl_cfg->vpp_bapi_socket_name);
Florin Coras697faea2018-06-27 17:10:49 -0700614 }
Florin Coras165f3ae2020-11-08 18:04:33 -0800615 env_var_str = getenv (VPPCOM_ENV_VPP_SAPI_SOCKET);
616 if (env_var_str)
617 {
618 vcm->cfg.vpp_app_socket_api = format (0, "%s%c", env_var_str, 0);
619 VCFG_DBG (0, "VCL<%d>: configured app-socket-api (%s)", getpid (),
620 vcl_cfg->vpp_app_socket_api);
621 }
Florin Coras697faea2018-06-27 17:10:49 -0700622}
623
624/*
625 * fd.io coding-style-patch-verification: ON
626 *
627 * Local Variables:
628 * eval: (c-set-style "gnu")
629 * End:
630 */