examples/ip_pipeline: fix build in old environments
[dpdk.git] / examples / ip_pipeline / config_parse.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 #include <stdint.h>
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <ctype.h>
37 #include <getopt.h>
38 #include <errno.h>
39 #include <stdarg.h>
40 #include <string.h>
41 #include <libgen.h>
42 #include <unistd.h>
43 #include <sys/wait.h>
44
45 #include <rte_errno.h>
46 #include <rte_cfgfile.h>
47 #include <rte_string_fns.h>
48
49 #include "app.h"
50
51 /**
52  * Default config values
53  **/
54
55 static struct app_params app_params_default = {
56         .config_file = "./config/ip_pipeline.cfg",
57         .log_level = APP_LOG_LEVEL_HIGH,
58
59         .eal_params = {
60                 .channels = 4,
61         },
62 };
63
64 static const struct app_mempool_params mempool_params_default = {
65         .parsed = 0,
66         .buffer_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
67         .pool_size = 32 * 1024,
68         .cache_size = 256,
69         .cpu_socket_id = 0,
70 };
71
72 static const struct app_link_params link_params_default = {
73         .parsed = 0,
74         .pmd_id = 0,
75         .arp_q = 0,
76         .tcp_syn_local_q = 0,
77         .ip_local_q = 0,
78         .tcp_local_q = 0,
79         .udp_local_q = 0,
80         .sctp_local_q = 0,
81         .state = 0,
82         .ip = 0,
83         .depth = 0,
84         .mac_addr = 0,
85
86         .conf = {
87                 .link_speed = 0,
88                 .link_duplex = 0,
89                 .rxmode = {
90                         .mq_mode = ETH_MQ_RX_NONE,
91
92                         .header_split   = 0, /* Header split */
93                         .hw_ip_checksum = 0, /* IP checksum offload */
94                         .hw_vlan_filter = 0, /* VLAN filtering */
95                         .hw_vlan_strip  = 0, /* VLAN strip */
96                         .hw_vlan_extend = 0, /* Extended VLAN */
97                         .jumbo_frame    = 0, /* Jumbo frame support */
98                         .hw_strip_crc   = 0, /* CRC strip by HW */
99                         .enable_scatter = 0, /* Scattered packets RX handler */
100
101                         .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
102                         .split_hdr_size = 0, /* Header split buffer size */
103                 },
104                 .txmode = {
105                         .mq_mode = ETH_MQ_TX_NONE,
106                 },
107                 .lpbk_mode = 0,
108         },
109
110         .promisc = 1,
111 };
112
113 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
114         .parsed = 0,
115         .mempool_id = 0,
116         .size = 128,
117         .burst = 32,
118
119         .conf = {
120                 .rx_thresh = {
121                                 .pthresh = 8,
122                                 .hthresh = 8,
123                                 .wthresh = 4,
124                 },
125                 .rx_free_thresh = 64,
126                 .rx_drop_en = 0,
127                 .rx_deferred_start = 0,
128         }
129 };
130
131 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
132         .parsed = 0,
133         .size = 512,
134         .burst = 32,
135         .dropless = 0,
136         .n_retries = 0,
137
138         .conf = {
139                 .tx_thresh = {
140                         .pthresh = 36,
141                         .hthresh = 0,
142                         .wthresh = 0,
143                 },
144                 .tx_rs_thresh = 0,
145                 .tx_free_thresh = 0,
146                 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
147                         ETH_TXQ_FLAGS_NOOFFLOADS,
148                 .tx_deferred_start = 0,
149         }
150 };
151
152 static const struct app_pktq_swq_params default_swq_params = {
153         .parsed = 0,
154         .size = 256,
155         .burst_read = 32,
156         .burst_write = 32,
157         .dropless = 0,
158         .n_retries = 0,
159         .cpu_socket_id = 0,
160         .ipv4_frag = 0,
161         .ipv6_frag = 0,
162         .ipv4_ras = 0,
163         .ipv6_ras = 0,
164         .mtu = 0,
165         .metadata_size = 0,
166         .mempool_direct_id = 0,
167         .mempool_indirect_id = 0,
168 };
169
170 struct app_pktq_tm_params default_tm_params = {
171         .parsed = 0,
172         .file_name = "./config/tm_profile.cfg",
173         .burst_read = 64,
174         .burst_write = 32,
175 };
176
177 struct app_pktq_source_params default_source_params = {
178         .parsed = 0,
179         .mempool_id = 0,
180         .burst = 32,
181 };
182
183 struct app_pktq_sink_params default_sink_params = {
184         .parsed = 0,
185 };
186
187 struct app_msgq_params default_msgq_params = {
188         .parsed = 0,
189         .size = 64,
190         .cpu_socket_id = 0,
191 };
192
193 struct app_pipeline_params default_pipeline_params = {
194         .parsed = 0,
195         .socket_id = 0,
196         .core_id = 0,
197         .hyper_th_id = 0,
198         .n_pktq_in = 0,
199         .n_pktq_out = 0,
200         .n_msgq_in = 0,
201         .n_msgq_out = 0,
202         .timer_period = 1,
203         .n_args = 0,
204 };
205
206 static const char app_usage[] =
207         "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] -p PORT_MASK "
208         "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
209         "\n"
210         "Arguments:\n"
211         "\t-f CONFIG_FILE: Default config file is %s\n"
212         "\t-p PORT_MASK: Mask of NIC port IDs in hexadecimal format\n"
213         "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
214         "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
215         "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
216         "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
217         "\n";
218
219 static void
220 app_print_usage(char *prgname)
221 {
222         rte_exit(0, app_usage, prgname, app_params_default.config_file);
223 }
224
225 #define skip_white_spaces(pos)                  \
226 ({                                              \
227         __typeof__(pos) _p = (pos);             \
228         for ( ; isspace(*_p); _p++);            \
229         _p;                                     \
230 })
231
232 #define PARSER_IMPLICIT_PARAM_ADD_CHECK(result, section_name)           \
233 do {                                                                    \
234         APP_CHECK((result != -EINVAL),                                  \
235                 "CFG: [%s] name too long", section_name);               \
236         APP_CHECK(result != -ENOMEM,                                    \
237                 "CFG: [%s] too much sections", section_name);           \
238         APP_CHECK(result >= 0,                                          \
239                 "CFG: [%s] Unknown error while adding '%s'",            \
240                 section_name, section_name);                            \
241 } while (0)
242
243 #define PARSER_PARAM_ADD_CHECK(result, params_array, section_name)      \
244 do {                                                                    \
245         APP_CHECK((result != -EINVAL),                                  \
246                 "CFG: [%s] name too long", section_name);               \
247         APP_CHECK((result != -ENOMEM),                                  \
248                 "CFG: [%s] too much sections", section_name);           \
249         APP_CHECK(((result >= 0) && (params_array)[result].parsed == 0),\
250                 "CFG: [%s] duplicate section", section_name);           \
251         APP_CHECK((result >= 0),                                        \
252                 "CFG: [%s] Unknown error while adding '%s'",            \
253                 section_name, section_name);                            \
254 } while (0)
255
256 static int
257 parser_read_arg_bool(const char *p)
258 {
259         p = skip_white_spaces(p);
260         int result = -EINVAL;
261
262         if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) ||
263                 ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) {
264                 p += 3;
265                 result = 1;
266         }
267
268         if (((p[0] == 'o') && (p[1] == 'n')) ||
269                 ((p[0] == 'O') && (p[1] == 'N'))) {
270                 p += 2;
271                 result = 1;
272         }
273
274         if (((p[0] == 'n') && (p[1] == 'o')) ||
275                 ((p[0] == 'N') && (p[1] == 'O'))) {
276                 p += 2;
277                 result = 0;
278         }
279
280         if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) ||
281                 ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) {
282                 p += 3;
283                 result = 0;
284         }
285
286         p = skip_white_spaces(p);
287
288         if (p[0] != '\0')
289                 return -EINVAL;
290
291         return result;
292 }
293
294 #define PARSE_ERROR(exp, section, entry)                                \
295 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
296
297 #define PARSE_ERROR_MALLOC(exp)                                         \
298 APP_CHECK(exp, "Parse error: no free memory\n")
299
300 #define PARSE_ERROR_SECTION(exp, section)                               \
301 APP_CHECK(exp, "Parse error in section \"%s\"", section)
302
303 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section)                    \
304 APP_CHECK(exp, "Parse error in section \"%s\": no entries\n", section)
305
306 #define PARSE_WARNING_IGNORED(exp, section, entry)                      \
307 do                                                                      \
308 if (!(exp))                                                             \
309         fprintf(stderr, "Parse warning in section \"%s\": "             \
310                 "entry \"%s\" is ignored\n", section, entry);           \
311 while (0)
312
313 #define PARSE_ERROR_INVALID(exp, section, entry)                        \
314 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"\n",\
315         section, entry)
316
317 #define PARSE_ERROR_DUPLICATE(exp, section, entry)                      \
318 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"\n",\
319         section, entry)
320
321 static int
322 parser_read_uint64(uint64_t *value, const char *p)
323 {
324         char *next;
325         uint64_t val;
326
327         p = skip_white_spaces(p);
328         if (!isdigit(*p))
329                 return -EINVAL;
330
331         val = strtoul(p, &next, 10);
332         if (p == next)
333                 return -EINVAL;
334
335         p = next;
336         switch (*p) {
337         case 'T':
338                 val *= 1024ULL;
339                 /* fall trought */
340         case 'G':
341                 val *= 1024ULL;
342                 /* fall trought */
343         case 'M':
344                 val *= 1024ULL;
345                 /* fall trought */
346         case 'k':
347         case 'K':
348                 val *= 1024ULL;
349                 p++;
350                 break;
351         }
352
353         p = skip_white_spaces(p);
354         if (*p != '\0')
355                 return -EINVAL;
356
357         *value = val;
358         return 0;
359 }
360
361 static int
362 parser_read_uint32(uint32_t *value, const char *p)
363 {
364         uint64_t val = 0;
365         int ret = parser_read_uint64(&val, p);
366
367         if (ret < 0)
368                 return ret;
369         else if (val > UINT32_MAX)
370                 return -ERANGE;
371
372         *value = val;
373         return 0;
374 }
375
376 int
377 parse_pipeline_core(uint32_t *socket,
378         uint32_t *core,
379         uint32_t *ht,
380         const char *entry)
381 {
382         size_t num_len;
383         char num[8];
384
385         uint32_t s = 0, c = 0, h = 0, val;
386         uint8_t s_parsed = 0, c_parsed = 0, h_parsed = 0;
387         const char *next = skip_white_spaces(entry);
388         char type;
389
390         /* Expect <CORE> or [sX][cY][h]. At least one parameter is required. */
391         while (*next != '\0') {
392                 /* If everything parsed nothing should left */
393                 if (s_parsed && c_parsed && h_parsed)
394                         return -EINVAL;
395
396                 type = *next;
397                 switch (type) {
398                 case 's':
399                 case 'S':
400                         if (s_parsed || c_parsed || h_parsed)
401                                 return -EINVAL;
402                         s_parsed = 1;
403                         next++;
404                         break;
405                 case 'c':
406                 case 'C':
407                         if (c_parsed || h_parsed)
408                                 return -EINVAL;
409                         c_parsed = 1;
410                         next++;
411                         break;
412                 case 'h':
413                 case 'H':
414                         if (h_parsed)
415                                 return -EINVAL;
416                         h_parsed = 1;
417                         next++;
418                         break;
419                 default:
420                         /* If it start from digit it must be only core id. */
421                         if (!isdigit(*next) || s_parsed || c_parsed || h_parsed)
422                                 return -EINVAL;
423
424                         type = 'C';
425                 }
426
427                 for (num_len = 0; *next != '\0'; next++, num_len++) {
428                         if (num_len == RTE_DIM(num))
429                                 return -EINVAL;
430
431                         if (!isdigit(*next))
432                                 break;
433
434                         num[num_len] = *next;
435                 }
436
437                 if (num_len == 0 && type != 'h' && type != 'H')
438                         return -EINVAL;
439
440                 if (num_len != 0 && (type == 'h' || type == 'H'))
441                         return -EINVAL;
442
443                 num[num_len] = '\0';
444                 val = strtol(num, NULL, 10);
445
446                 h = 0;
447                 switch (type) {
448                 case 's':
449                 case 'S':
450                         s = val;
451                         break;
452                 case 'c':
453                 case 'C':
454                         c = val;
455                         break;
456                 case 'h':
457                 case 'H':
458                         h = 1;
459                         break;
460                 }
461         }
462
463         *socket = s;
464         *core = c;
465         *ht = h;
466         return 0;
467 }
468
469 static uint32_t
470 get_hex_val(char c)
471 {
472         switch (c) {
473         case '0': case '1': case '2': case '3': case '4': case '5':
474         case '6': case '7': case '8': case '9':
475                 return c - '0';
476         case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
477                 return c - 'A' + 10;
478         case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
479                 return c - 'a' + 10;
480         default:
481                 return 0;
482         }
483 }
484
485 int
486 parse_hex_string(char *src, uint8_t *dst, uint32_t *size)
487 {
488         char *c;
489         uint32_t len, i;
490
491         /* Check input parameters */
492         if ((src == NULL) ||
493                 (dst == NULL) ||
494                 (size == NULL) ||
495                 (*size == 0))
496                 return -1;
497
498         len = strlen(src);
499         if (((len & 3) != 0) ||
500                 (len > (*size) * 2))
501                 return -1;
502         *size = len / 2;
503
504         for (c = src; *c != 0; c++) {
505                 if ((((*c) >= '0') && ((*c) <= '9')) ||
506                         (((*c) >= 'A') && ((*c) <= 'F')) ||
507                         (((*c) >= 'a') && ((*c) <= 'f')))
508                         continue;
509
510                 return -1;
511         }
512
513         /* Convert chars to bytes */
514         for (i = 0; i < *size; i++)
515                 dst[i] = get_hex_val(src[2 * i]) * 16 +
516                         get_hex_val(src[2 * i + 1]);
517
518         return 0;
519 }
520
521 static size_t
522 skip_digits(const char *src)
523 {
524         size_t i;
525
526         for (i = 0; isdigit(src[i]); i++);
527
528         return i;
529 }
530
531 static int
532 validate_name(const char *name, const char *prefix, int num)
533 {
534         size_t i, j;
535
536         for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
537                 if (name[i] != prefix[i])
538                         return -1;
539         }
540
541         if (prefix[i] != '\0')
542                 return -1;
543
544         if (!num) {
545                 if (name[i] != '\0')
546                         return -1;
547                 else
548                         return 0;
549         }
550
551         if (num == 2) {
552                 j = skip_digits(&name[i]);
553                 i += j;
554                 if ((j == 0) || (name[i] != '.'))
555                         return -1;
556                 i++;
557         }
558
559         if (num == 1) {
560                 j = skip_digits(&name[i]);
561                 i += j;
562                 if ((j == 0) || (name[i] != '\0'))
563                         return -1;
564         }
565
566         return 0;
567 }
568
569 static void
570 parse_eal(struct app_params *app,
571         const char *section_name,
572         struct rte_cfgfile *cfg)
573 {
574         struct app_eal_params *p = &app->eal_params;
575         struct rte_cfgfile_entry *entries;
576         int n_entries, i;
577
578         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
579         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
580
581         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
582         PARSE_ERROR_MALLOC(entries != NULL);
583
584         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
585
586         for (i = 0; i < n_entries; i++) {
587                 struct rte_cfgfile_entry *entry = &entries[i];
588
589                 /* coremask */
590                 if (strcmp(entry->name, "c") == 0) {
591                         PARSE_WARNING_IGNORED(0, section_name, entry->name);
592                         continue;
593                 }
594
595                 /* corelist */
596                 if (strcmp(entry->name, "l") == 0) {
597                         PARSE_WARNING_IGNORED(0, section_name, entry->name);
598                         continue;
599                 }
600
601                 /* coremap */
602                 if (strcmp(entry->name, "lcores") == 0) {
603                         PARSE_ERROR_DUPLICATE((p->coremap == NULL),
604                                 section_name,
605                                 entry->name);
606                         p->coremap = strdup(entry->value);
607                         continue;
608                 }
609
610                 /* master_lcore */
611                 if (strcmp(entry->name, "master_lcore") == 0) {
612                         int status;
613
614                         PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
615                                 section_name,
616                                 entry->name);
617                         p->master_lcore_present = 1;
618
619                         status = parser_read_uint32(&p->master_lcore,
620                                 entry->value);
621                         PARSE_ERROR((status == 0), section_name, entry->name);
622                         continue;
623                 }
624
625                 /* channels */
626                 if (strcmp(entry->name, "n") == 0) {
627                         int status;
628
629                         PARSE_ERROR_DUPLICATE((p->channels_present == 0),
630                                 section_name,
631                                 entry->name);
632                         p->channels_present = 1;
633
634                         status = parser_read_uint32(&p->channels, entry->value);
635                         PARSE_ERROR((status == 0), section_name, entry->name);
636                         continue;
637                 }
638
639                 /* memory */
640                 if (strcmp(entry->name, "m") == 0) {
641                         int status;
642
643                         PARSE_ERROR_DUPLICATE((p->memory_present == 0),
644                                 section_name,
645                                 entry->name);
646                         p->memory_present = 1;
647
648                         status = parser_read_uint32(&p->memory, entry->value);
649                         PARSE_ERROR((status == 0), section_name, entry->name);
650                         continue;
651                 }
652
653                 /* ranks */
654                 if (strcmp(entry->name, "r") == 0) {
655                         int status;
656
657                         PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
658                                 section_name,
659                                 entry->name);
660                         p->ranks_present = 1;
661
662                         status = parser_read_uint32(&p->ranks, entry->value);
663                         PARSE_ERROR((status == 0), section_name, entry->name);
664                         continue;
665                 }
666
667                 /* pci_blacklist */
668                 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
669                         (strcmp(entry->name, "b") == 0)) {
670                         PARSE_ERROR_DUPLICATE((p->pci_blacklist == NULL),
671                                 section_name,
672                                 entry->name);
673                         p->pci_blacklist = strdup(entry->value);
674                         continue;
675                 }
676
677                 /* pci_whitelist */
678                 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
679                         (strcmp(entry->name, "w") == 0)) {
680                         PARSE_ERROR_DUPLICATE((p->pci_whitelist == NULL),
681                                 section_name,
682                                 entry->name);
683                         p->pci_whitelist = strdup(entry->value);
684                         continue;
685                 }
686
687                 /* vdev */
688                 if (strcmp(entry->name, "vdev") == 0) {
689                         PARSE_ERROR_DUPLICATE((p->vdev == NULL),
690                                 section_name,
691                                 entry->name);
692                         p->vdev = strdup(entry->value);
693                         continue;
694                 }
695
696                 /* vmware_tsc_map */
697                 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
698                         int val;
699
700                         PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
701                                 section_name,
702                                 entry->name);
703                         p->vmware_tsc_map_present = 1;
704
705                         val = parser_read_arg_bool(entry->value);
706                         PARSE_ERROR((val >= 0), section_name, entry->name);
707                         p->vmware_tsc_map = val;
708                         continue;
709                 }
710
711                 /* proc_type */
712                 if (strcmp(entry->name, "proc_type") == 0) {
713                         PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
714                                 section_name,
715                                 entry->name);
716                         p->proc_type = strdup(entry->value);
717                         continue;
718                 }
719
720                 /* syslog */
721                 if (strcmp(entry->name, "syslog") == 0) {
722                         PARSE_ERROR_DUPLICATE((p->syslog == NULL),
723                                 section_name,
724                                 entry->name);
725                         p->syslog = strdup(entry->value);
726                         continue;
727                 }
728
729                 /* log_level */
730                 if (strcmp(entry->name, "log_level") == 0) {
731                         int status;
732
733                         PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
734                                 section_name,
735                                 entry->name);
736                         p->log_level_present = 1;
737
738                         status = parser_read_uint32(&p->log_level,
739                                 entry->value);
740                         PARSE_ERROR((status == 0), section_name, entry->name);
741                         continue;
742                 }
743
744                 /* version */
745                 if (strcmp(entry->name, "v") == 0) {
746                         int val;
747
748                         PARSE_ERROR_DUPLICATE((p->version_present == 0),
749                                 section_name,
750                                 entry->name);
751                         p->version_present = 1;
752
753                         val = parser_read_arg_bool(entry->value);
754                         PARSE_ERROR((val >= 0), section_name, entry->name);
755                         p->version = val;
756                         continue;
757                 }
758
759                 /* help */
760                 if ((strcmp(entry->name, "help") == 0) ||
761                         (strcmp(entry->name, "h") == 0)) {
762                         int val;
763
764                         PARSE_ERROR_DUPLICATE((p->help_present == 0),
765                                 section_name,
766                                 entry->name);
767                         p->help_present = 1;
768
769                         val = parser_read_arg_bool(entry->value);
770                         PARSE_ERROR((val >= 0), section_name, entry->name);
771                         p->help = val;
772                         continue;
773                 }
774
775                 /* no_huge */
776                 if (strcmp(entry->name, "no_huge") == 0) {
777                         int val;
778
779                         PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
780                                 section_name,
781                                 entry->name);
782                         p->no_huge_present = 1;
783
784                         val = parser_read_arg_bool(entry->value);
785                         PARSE_ERROR((val >= 0), section_name, entry->name);
786                         p->no_huge = val;
787                         continue;
788                 }
789
790                 /* no_pci */
791                 if (strcmp(entry->name, "no_pci") == 0) {
792                         int val;
793
794                         PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
795                                 section_name,
796                                 entry->name);
797                         p->no_pci_present = 1;
798
799                         val = parser_read_arg_bool(entry->value);
800                         PARSE_ERROR((val >= 0), section_name, entry->name);
801                         p->no_pci = val;
802                         continue;
803                 }
804
805                 /* no_hpet */
806                 if (strcmp(entry->name, "no_hpet") == 0) {
807                         int val;
808
809                         PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
810                                 section_name,
811                                 entry->name);
812                         p->no_hpet_present = 1;
813
814                         val = parser_read_arg_bool(entry->value);
815                         PARSE_ERROR((val >= 0), section_name, entry->name);
816                         p->no_hpet = val;
817                         continue;
818                 }
819
820                 /* no_shconf */
821                 if (strcmp(entry->name, "no_shconf") == 0) {
822                         int val;
823
824                         PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
825                                 section_name,
826                                 entry->name);
827                         p->no_shconf_present = 1;
828
829                         val = parser_read_arg_bool(entry->value);
830                         PARSE_ERROR((val >= 0), section_name, entry->name);
831                         p->no_shconf = val;
832                         continue;
833                 }
834
835                 /* add_driver */
836                 if (strcmp(entry->name, "d") == 0) {
837                         PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
838                                 section_name,
839                                 entry->name);
840                         p->add_driver = strdup(entry->value);
841                         continue;
842                 }
843
844                 /* socket_mem */
845                 if (strcmp(entry->name, "socket_mem") == 0) {
846                         PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
847                                 section_name,
848                                 entry->name);
849                         p->socket_mem = strdup(entry->value);
850                         continue;
851                 }
852
853                 /* huge_dir */
854                 if (strcmp(entry->name, "huge_dir") == 0) {
855                         PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
856                                 section_name,
857                                 entry->name);
858                         p->huge_dir = strdup(entry->value);
859                         continue;
860                 }
861
862                 /* file_prefix */
863                 if (strcmp(entry->name, "file_prefix") == 0) {
864                         PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
865                                 section_name,
866                                 entry->name);
867                         p->file_prefix = strdup(entry->value);
868                         continue;
869                 }
870
871                 /* base_virtaddr */
872                 if (strcmp(entry->name, "base_virtaddr") == 0) {
873                         PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
874                                 section_name,
875                                 entry->name);
876                         p->base_virtaddr = strdup(entry->value);
877                         continue;
878                 }
879
880                 /* create_uio_dev */
881                 if (strcmp(entry->name, "create_uio_dev") == 0) {
882                         int val;
883
884                         PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
885                                 section_name,
886                                 entry->name);
887                         p->create_uio_dev_present = 1;
888
889                         val = parser_read_arg_bool(entry->value);
890                         PARSE_ERROR((val >= 0), section_name, entry->name);
891                         p->create_uio_dev = val;
892                         continue;
893                 }
894
895                 /* vfio_intr */
896                 if (strcmp(entry->name, "vfio_intr") == 0) {
897                         PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
898                                 section_name,
899                                 entry->name);
900                         p->vfio_intr = strdup(entry->value);
901                         continue;
902                 }
903
904                 /* xen_dom0 */
905                 if (strcmp(entry->name, "xen_dom0") == 0) {
906                         int val;
907
908                         PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
909                                 section_name,
910                                 entry->name);
911                         p->xen_dom0_present = 1;
912
913                         val = parser_read_arg_bool(entry->value);
914                         PARSE_ERROR((val >= 0), section_name, entry->name);
915                         p->xen_dom0 = val;
916                         continue;
917                 }
918
919                 /* unrecognized */
920                 PARSE_ERROR_INVALID(0, section_name, entry->name);
921         }
922
923         free(entries);
924 }
925
926 static int
927 parse_pipeline_pktq_in(struct app_params *app,
928         struct app_pipeline_params *p,
929         const char *value)
930 {
931         const char *next = value;
932         char *end;
933         char name[APP_PARAM_NAME_SIZE];
934         size_t name_len;
935
936         while (*next != '\0') {
937                 enum app_pktq_in_type type;
938                 int id;
939
940                 end = strchr(next, ' ');
941                 if (!end)
942                         name_len = strlen(next);
943                 else
944                         name_len = end - next;
945
946                 if (name_len == 0 || name_len == sizeof(name))
947                         return -EINVAL;
948
949                 strncpy(name, next, name_len);
950                 name[name_len] = '\0';
951                 next += name_len;
952                 if (*next != '\0')
953                         next++;
954
955                 if (validate_name(name, "RXQ", 2) == 0) {
956                         type = APP_PKTQ_IN_HWQ;
957                         id = APP_PARAM_ADD(app->hwq_in_params, name);
958                 } else if (validate_name(name, "SWQ", 1) == 0) {
959                         type = APP_PKTQ_IN_SWQ;
960                         id = APP_PARAM_ADD(app->swq_params, name);
961                 } else if (validate_name(name, "TM", 1) == 0) {
962                         type = APP_PKTQ_IN_TM;
963                         id = APP_PARAM_ADD(app->tm_params, name);
964                 } else if (validate_name(name, "SOURCE", 1) == 0) {
965                         type = APP_PKTQ_IN_SOURCE;
966                         id = APP_PARAM_ADD(app->source_params, name);
967                 } else
968                         return -EINVAL;
969
970                 if (id < 0)
971                         return id;
972
973                 p->pktq_in[p->n_pktq_in].type = type;
974                 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
975                 p->n_pktq_in++;
976         }
977
978         return 0;
979 }
980
981 static int
982 parse_pipeline_pktq_out(struct app_params *app,
983         struct app_pipeline_params *p,
984         const char *value)
985 {
986         const char *next = value;
987         char *end;
988         char name[APP_PARAM_NAME_SIZE];
989         size_t name_len;
990
991         while (*next != '\0') {
992                 enum app_pktq_out_type type;
993                 int id;
994
995                 end = strchr(next, ' ');
996                 if (!end)
997                         name_len = strlen(next);
998                 else
999                         name_len = end - next;
1000
1001                 if (name_len == 0 || name_len == sizeof(name))
1002                         return -EINVAL;
1003
1004                 strncpy(name, next, name_len);
1005                 name[name_len] = '\0';
1006                 next += name_len;
1007                 if (*next != '\0')
1008                         next++;
1009
1010                 if (validate_name(name, "TXQ", 2) == 0) {
1011                         type = APP_PKTQ_OUT_HWQ;
1012                         id = APP_PARAM_ADD(app->hwq_out_params, name);
1013                 } else if (validate_name(name, "SWQ", 1) == 0) {
1014                         type = APP_PKTQ_OUT_SWQ;
1015                         id = APP_PARAM_ADD(app->swq_params, name);
1016                 } else if (validate_name(name, "TM", 1) == 0) {
1017                         type = APP_PKTQ_OUT_TM;
1018                         id = APP_PARAM_ADD(app->tm_params, name);
1019                 } else if (validate_name(name, "SINK", 1) == 0) {
1020                         type = APP_PKTQ_OUT_SINK;
1021                         id = APP_PARAM_ADD(app->sink_params, name);
1022                 } else
1023                         return -EINVAL;
1024
1025                 if (id < 0)
1026                         return id;
1027
1028                 p->pktq_out[p->n_pktq_out].type = type;
1029                 p->pktq_out[p->n_pktq_out].id = id;
1030                 p->n_pktq_out++;
1031         }
1032
1033         return 0;
1034 }
1035
1036 static int
1037 parse_pipeline_msgq_in(struct app_params *app,
1038         struct app_pipeline_params *p,
1039         const char *value)
1040 {
1041         const char *next = value;
1042         char *end;
1043         char name[APP_PARAM_NAME_SIZE];
1044         size_t name_len;
1045         ssize_t idx;
1046
1047         while (*next != '\0') {
1048                 end = strchr(next, ' ');
1049                 if (!end)
1050                         name_len = strlen(next);
1051                 else
1052                         name_len = end - next;
1053
1054                 if (name_len == 0 || name_len == sizeof(name))
1055                         return -EINVAL;
1056
1057                 strncpy(name, next, name_len);
1058                 name[name_len] = '\0';
1059                 next += name_len;
1060                 if (*next != '\0')
1061                         next++;
1062
1063                 if (validate_name(name, "MSGQ", 1) != 0)
1064                         return -EINVAL;
1065
1066                 idx = APP_PARAM_ADD(app->msgq_params, name);
1067                 if (idx < 0)
1068                         return idx;
1069
1070                 p->msgq_in[p->n_msgq_in] = idx;
1071                 p->n_msgq_in++;
1072         }
1073
1074         return 0;
1075 }
1076
1077 static int
1078 parse_pipeline_msgq_out(struct app_params *app,
1079         struct app_pipeline_params *p,
1080         const char *value)
1081 {
1082         const char *next = value;
1083         char *end;
1084         char name[APP_PARAM_NAME_SIZE];
1085         size_t name_len;
1086         ssize_t idx;
1087
1088         while (*next != '\0') {
1089                 end = strchr(next, ' ');
1090                 if (!end)
1091                         name_len = strlen(next);
1092                 else
1093                         name_len = end - next;
1094
1095                 if (name_len == 0 || name_len == sizeof(name))
1096                         return -EINVAL;
1097
1098                 strncpy(name, next, name_len);
1099                 name[name_len] = '\0';
1100                 next += name_len;
1101                 if (*next != '\0')
1102                         next++;
1103
1104                 if (validate_name(name, "MSGQ", 1) != 0)
1105                         return -EINVAL;
1106
1107                 idx = APP_PARAM_ADD(app->msgq_params, name);
1108                 if (idx < 0)
1109                         return idx;
1110
1111                 p->msgq_out[p->n_msgq_out] = idx;
1112                 p->n_msgq_out++;
1113         }
1114
1115         return 0;
1116 }
1117
1118
1119 static void
1120 parse_pipeline(struct app_params *app,
1121         const char *section_name,
1122         struct rte_cfgfile *cfg)
1123 {
1124         char name[CFG_NAME_LEN];
1125         struct app_pipeline_params *param;
1126         struct rte_cfgfile_entry *entries;
1127         ssize_t param_idx;
1128         int n_entries, ret, i;
1129
1130         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1131         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1132
1133         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1134         PARSE_ERROR_MALLOC(entries != NULL);
1135
1136         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1137
1138         param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1139         PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);
1140
1141         param = &app->pipeline_params[param_idx];
1142         param->parsed = 1;
1143
1144         for (i = 0; i < n_entries; i++) {
1145                 struct rte_cfgfile_entry *ent = &entries[i];
1146
1147                 if (strcmp(ent->name, "type") == 0) {
1148                         ret = snprintf(param->type,
1149                                 RTE_DIM(param->type),
1150                                 "%s",
1151                                 ent->value);
1152                         if ((ret > 0) && (ret < (int)RTE_DIM(param->type)))
1153                                 ret = 0;
1154                         else
1155                                 ret = -EINVAL;
1156                 } else if (strcmp(ent->name, "core") == 0)
1157                         ret = parse_pipeline_core(&param->socket_id,
1158                                 &param->core_id,
1159                                 &param->hyper_th_id,
1160                                 ent->value);
1161                 else if (strcmp(ent->name, "pktq_in") == 0)
1162                         ret = parse_pipeline_pktq_in(app, param, ent->value);
1163                 else if (strcmp(ent->name, "pktq_out") == 0)
1164                         ret = parse_pipeline_pktq_out(app, param, ent->value);
1165                 else if (strcmp(ent->name, "msgq_in") == 0)
1166                         ret = parse_pipeline_msgq_in(app, param, ent->value);
1167                 else if (strcmp(ent->name, "msgq_out") == 0)
1168                         ret = parse_pipeline_msgq_out(app, param, ent->value);
1169                 else if (strcmp(ent->name, "timer_period") == 0)
1170                         ret = parser_read_uint32(&param->timer_period,
1171                                 ent->value);
1172                 else {
1173                         APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1174                                 "CFG: [%s] out of memory",
1175                                 section_name);
1176
1177                         param->args_name[param->n_args] = strdup(ent->name);
1178                         param->args_value[param->n_args] = strdup(ent->value);
1179
1180                         APP_CHECK((param->args_name[param->n_args] != NULL) &&
1181                                 (param->args_value[param->n_args] != NULL),
1182                                 "CFG: [%s] out of memory",
1183                                 section_name);
1184
1185                         param->n_args++;
1186                         ret = 0;
1187                 }
1188
1189                 APP_CHECK(ret == 0,
1190                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1191                         section_name,
1192                         ent->name,
1193                         ent->value);
1194         }
1195
1196         snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1197         param_idx = APP_PARAM_ADD(app->msgq_params, name);
1198         PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1199         app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1200         param->msgq_in[param->n_msgq_in++] = param_idx;
1201
1202         snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1203         param_idx = APP_PARAM_ADD(app->msgq_params, name);
1204         PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1205         app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1206         param->msgq_out[param->n_msgq_out++] = param_idx;
1207
1208         snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1209                 param->socket_id,
1210                 param->core_id,
1211                 (param->hyper_th_id) ? "h" : "");
1212         param_idx = APP_PARAM_ADD(app->msgq_params, name);
1213         PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1214         app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1215
1216         snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1217                 param->socket_id,
1218                 param->core_id,
1219                 (param->hyper_th_id) ? "h" : "");
1220         param_idx = APP_PARAM_ADD(app->msgq_params, name);
1221         PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1222         app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1223
1224         free(entries);
1225 }
1226
1227 static void
1228 parse_mempool(struct app_params *app,
1229         const char *section_name,
1230         struct rte_cfgfile *cfg)
1231 {
1232         struct app_mempool_params *param;
1233         struct rte_cfgfile_entry *entries;
1234         ssize_t param_idx;
1235         int n_entries, ret, i;
1236
1237         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1238         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1239
1240         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1241         PARSE_ERROR_MALLOC(entries != NULL);
1242
1243         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1244
1245         param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1246         PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);
1247
1248         param = &app->mempool_params[param_idx];
1249         param->parsed = 1;
1250
1251         for (i = 0; i < n_entries; i++) {
1252                 struct rte_cfgfile_entry *ent = &entries[i];
1253
1254                 ret = -ESRCH;
1255                 if (strcmp(ent->name, "buffer_size") == 0)
1256                         ret = parser_read_uint32(&param->buffer_size,
1257                                 ent->value);
1258                 else if (strcmp(ent->name, "pool_size") == 0)
1259                         ret = parser_read_uint32(&param->pool_size,
1260                                 ent->value);
1261                 else if (strcmp(ent->name, "cache_size") == 0)
1262                         ret = parser_read_uint32(&param->cache_size,
1263                                 ent->value);
1264                 else if (strcmp(ent->name, "cpu") == 0)
1265                         ret = parser_read_uint32(&param->cpu_socket_id,
1266                                 ent->value);
1267
1268                 APP_CHECK(ret != -ESRCH,
1269                         "CFG: [%s] entry '%s': unknown entry\n",
1270                         section_name,
1271                         ent->name);
1272                 APP_CHECK(ret == 0,
1273                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1274                         section_name,
1275                         ent->name,
1276                         ent->value);
1277         }
1278
1279         free(entries);
1280 }
1281
1282 static void
1283 parse_link(struct app_params *app,
1284         const char *section_name,
1285         struct rte_cfgfile *cfg)
1286 {
1287         struct app_link_params *param;
1288         struct rte_cfgfile_entry *entries;
1289         int n_entries, ret, i;
1290         ssize_t param_idx;
1291
1292         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1293         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1294
1295         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1296         PARSE_ERROR_MALLOC(entries != NULL);
1297
1298         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1299
1300         param_idx = APP_PARAM_ADD(app->link_params, section_name);
1301         PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);
1302
1303         param = &app->link_params[param_idx];
1304         param->parsed = 1;
1305
1306         for (i = 0; i < n_entries; i++) {
1307                 struct rte_cfgfile_entry *ent = &entries[i];
1308
1309                 ret = -ESRCH;
1310                 if (strcmp(ent->name, "promisc") == 0) {
1311                         ret = parser_read_arg_bool(ent->value);
1312                         if (ret >= 0) {
1313                                 param->promisc = ret;
1314                                 ret = 0;
1315                         }
1316                 } else if (strcmp(ent->name, "arp_q") == 0)
1317                         ret = parser_read_uint32(&param->arp_q,
1318                                 ent->value);
1319                 else if (strcmp(ent->name, "tcp_syn_q") == 0)
1320                         ret = parser_read_uint32(&param->tcp_syn_local_q,
1321                                 ent->value);
1322                 else if (strcmp(ent->name, "ip_local_q") == 0)
1323                         ret = parser_read_uint32(&param->ip_local_q,
1324                                 ent->value);
1325                 else if (strcmp(ent->name, "tcp_local_q") == 0)
1326                         ret = parser_read_uint32(&param->tcp_local_q,
1327                                 ent->value);
1328                 else if (strcmp(ent->name, "udp_local_q") == 0)
1329                         ret = parser_read_uint32(&param->udp_local_q,
1330                                 ent->value);
1331                 else if (strcmp(ent->name, "sctp_local_q") == 0)
1332                         ret = parser_read_uint32(&param->sctp_local_q,
1333                                 ent->value);
1334
1335                 APP_CHECK(ret != -ESRCH,
1336                         "CFG: [%s] entry '%s': unknown entry\n",
1337                         section_name,
1338                         ent->name);
1339                 APP_CHECK(ret == 0,
1340                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1341                         section_name,
1342                         ent->name,
1343                         ent->value);
1344         }
1345
1346         free(entries);
1347 }
1348
1349 static void
1350 parse_rxq(struct app_params *app,
1351         const char *section_name,
1352         struct rte_cfgfile *cfg)
1353 {
1354         struct app_pktq_hwq_in_params *param;
1355         struct rte_cfgfile_entry *entries;
1356         int n_entries, ret, i;
1357         ssize_t param_idx;
1358
1359         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1360         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1361
1362         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1363         PARSE_ERROR_MALLOC(entries != NULL);
1364
1365         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1366
1367         param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1368         PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);
1369
1370         param = &app->hwq_in_params[param_idx];
1371         param->parsed = 1;
1372
1373         for (i = 0; i < n_entries; i++) {
1374                 struct rte_cfgfile_entry *ent = &entries[i];
1375
1376                 ret = -ESRCH;
1377                 if (strcmp(ent->name, "mempool") == 0) {
1378                         int status = validate_name(ent->value, "MEMPOOL", 1);
1379                         ssize_t idx;
1380
1381                         APP_CHECK((status == 0),
1382                                 "CFG: [%s] entry '%s': invalid mempool\n",
1383                                 section_name,
1384                                 ent->name);
1385
1386                         idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1387                         PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1388                         param->mempool_id = idx;
1389                         ret = 0;
1390                 } else if (strcmp(ent->name, "size") == 0)
1391                         ret = parser_read_uint32(&param->size,
1392                                 ent->value);
1393                 else if (strcmp(ent->name, "burst") == 0)
1394                         ret = parser_read_uint32(&param->burst,
1395                                 ent->value);
1396
1397                 APP_CHECK(ret != -ESRCH,
1398                         "CFG: [%s] entry '%s': unknown entry\n",
1399                         section_name,
1400                         ent->name);
1401                 APP_CHECK(ret == 0,
1402                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1403                         section_name,
1404                         ent->name,
1405                         ent->value);
1406         }
1407
1408         free(entries);
1409 }
1410
1411 static void
1412 parse_txq(struct app_params *app,
1413         const char *section_name,
1414         struct rte_cfgfile *cfg)
1415 {
1416         struct app_pktq_hwq_out_params *param;
1417         struct rte_cfgfile_entry *entries;
1418         int n_entries, ret, i;
1419         ssize_t param_idx;
1420
1421         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1422         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1423
1424         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1425         PARSE_ERROR_MALLOC(entries != NULL);
1426
1427         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1428
1429         param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1430         PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);
1431
1432         param = &app->hwq_out_params[param_idx];
1433         param->parsed = 1;
1434
1435         for (i = 0; i < n_entries; i++) {
1436                 struct rte_cfgfile_entry *ent = &entries[i];
1437
1438                 ret = -ESRCH;
1439                 if (strcmp(ent->name, "size") == 0)
1440                         ret = parser_read_uint32(&param->size, ent->value);
1441                 else if (strcmp(ent->name, "burst") == 0)
1442                         ret = parser_read_uint32(&param->burst, ent->value);
1443                 else if (strcmp(ent->name, "dropless") == 0) {
1444                         ret = parser_read_arg_bool(ent->value);
1445                         if (ret >= 0) {
1446                                 param->dropless = ret;
1447                                 ret = 0;
1448                         }
1449                 }
1450
1451                 APP_CHECK(ret != -ESRCH,
1452                         "CFG: [%s] entry '%s': unknown entry\n",
1453                         section_name,
1454                         ent->name);
1455                 APP_CHECK(ret == 0,
1456                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1457                         section_name,
1458                         ent->name,
1459                         ent->value);
1460         }
1461
1462         free(entries);
1463 }
1464
1465 static void
1466 parse_swq(struct app_params *app,
1467         const char *section_name,
1468         struct rte_cfgfile *cfg)
1469 {
1470         struct app_pktq_swq_params *param;
1471         struct rte_cfgfile_entry *entries;
1472         int n_entries, ret, i;
1473         unsigned frag_entries = 0;
1474         ssize_t param_idx;
1475
1476         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1477         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1478
1479         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1480         PARSE_ERROR_MALLOC(entries != NULL);
1481
1482         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1483
1484         param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1485         PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);
1486
1487         param = &app->swq_params[param_idx];
1488         param->parsed = 1;
1489
1490         for (i = 0; i < n_entries; i++) {
1491                 struct rte_cfgfile_entry *ent = &entries[i];
1492
1493                 ret = -ESRCH;
1494                 if (strcmp(ent->name, "size") == 0)
1495                         ret = parser_read_uint32(&param->size,
1496                                 ent->value);
1497                 else if (strcmp(ent->name, "burst_read") == 0)
1498                         ret = parser_read_uint32(&param->burst_read,
1499                                 ent->value);
1500                 else if (strcmp(ent->name, "burst_write") == 0)
1501                         ret = parser_read_uint32(&param->burst_write,
1502                                 ent->value);
1503                 else if (strcmp(ent->name, "dropless") == 0) {
1504                         ret = parser_read_arg_bool(ent->value);
1505                         if (ret >= 0) {
1506                                 param->dropless = ret;
1507                                 ret = 0;
1508                         }
1509                 } else if (strcmp(ent->name, "n_retries") == 0)
1510                         ret = parser_read_uint64(&param->n_retries,
1511                                 ent->value);
1512                 else if (strcmp(ent->name, "cpu") == 0)
1513                         ret = parser_read_uint32(&param->cpu_socket_id,
1514                                 ent->value);
1515                 else if (strcmp(ent->name, "ipv4_frag") == 0) {
1516                         ret = parser_read_arg_bool(ent->value);
1517                         if (ret >= 0) {
1518                                 param->ipv4_frag = ret;
1519                                 if (param->mtu == 0)
1520                                         param->mtu = 1500;
1521                                 ret = 0;
1522                         }
1523                 } else if (strcmp(ent->name, "ipv6_frag") == 0) {
1524                         ret = parser_read_arg_bool(ent->value);
1525                         if (ret >= 0) {
1526                                 param->ipv6_frag = ret;
1527                                 if (param->mtu == 0)
1528                                         param->mtu = 1320;
1529                                 ret = 0;
1530                         }
1531                 } else if (strcmp(ent->name, "ipv4_ras") == 0) {
1532                         ret = parser_read_arg_bool(ent->value);
1533                         if (ret >= 0) {
1534                                 param->ipv4_ras = ret;
1535                                 ret = 0;
1536                         }
1537                 } else if (strcmp(ent->name, "ipv6_ras") == 0) {
1538                         ret = parser_read_arg_bool(ent->value);
1539                         if (ret >= 0) {
1540                                 param->ipv6_ras = ret;
1541                                 ret = 0;
1542                         }
1543                 } else if (strcmp(ent->name, "mtu") == 0) {
1544                         frag_entries = 1;
1545                         ret = parser_read_uint32(&param->mtu,
1546                                 ent->value);
1547                 } else if (strcmp(ent->name, "metadata_size") == 0) {
1548                         frag_entries = 1;
1549                         ret = parser_read_uint32(&param->metadata_size,
1550                                 ent->value);
1551                 } else if (strcmp(ent->name, "mempool_direct") == 0) {
1552                         int status = validate_name(ent->value, "MEMPOOL", 1);
1553                         ssize_t idx;
1554
1555                         APP_CHECK((status == 0),
1556                                 "CFG: [%s] entry '%s': invalid mempool\n",
1557                                 section_name,
1558                                 ent->name);
1559
1560                         idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1561                         PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1562                         param->mempool_direct_id = idx;
1563                         frag_entries = 1;
1564                         ret = 0;
1565                 } else if (strcmp(ent->name, "mempool_indirect") == 0) {
1566                         int status = validate_name(ent->value, "MEMPOOL", 1);
1567                         ssize_t idx;
1568
1569                         APP_CHECK((status == 0),
1570                                 "CFG: [%s] entry '%s': invalid mempool\n",
1571                                 section_name,
1572                                 ent->name);
1573
1574                         idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1575                         PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1576                         param->mempool_indirect_id = idx;
1577                         frag_entries = 1;
1578                         ret = 0;
1579                 }
1580
1581                 APP_CHECK(ret != -ESRCH,
1582                         "CFG: [%s] entry '%s': unknown entry\n",
1583                         section_name,
1584                         ent->name);
1585                 APP_CHECK(ret == 0,
1586                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1587                         section_name,
1588                         ent->name,
1589                         ent->value);
1590         }
1591
1592         if (frag_entries == 1) {
1593                 APP_CHECK(((param->ipv4_frag == 1) || (param->ipv6_frag == 1)),
1594                         "CFG: [%s] ipv4/ipv6 frag is off : unsupported entries on this"
1595                         " configuration\n",
1596                         section_name);
1597         }
1598
1599         free(entries);
1600 }
1601
1602 static void
1603 parse_tm(struct app_params *app,
1604         const char *section_name,
1605         struct rte_cfgfile *cfg)
1606 {
1607         struct app_pktq_tm_params *param;
1608         struct rte_cfgfile_entry *entries;
1609         int n_entries, ret, i;
1610         ssize_t param_idx;
1611
1612         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1613         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1614
1615         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1616         PARSE_ERROR_MALLOC(entries != NULL);
1617
1618         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1619
1620         param_idx = APP_PARAM_ADD(app->tm_params, section_name);
1621         PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);
1622
1623         param = &app->tm_params[param_idx];
1624         param->parsed = 1;
1625
1626         for (i = 0; i < n_entries; i++) {
1627                 struct rte_cfgfile_entry *ent = &entries[i];
1628
1629                 ret = -ESRCH;
1630                 if (strcmp(ent->name, "cfg") == 0) {
1631                         param->file_name = strdup(ent->value);
1632                         if (param->file_name == NULL)
1633                                 ret = -EINVAL;
1634
1635                         ret = 0;
1636                 } else if (strcmp(ent->name, "burst_read") == 0)
1637                         ret = parser_read_uint32(&param->burst_read,
1638                                 ent->value);
1639                 else if (strcmp(ent->name, "burst_write") == 0)
1640                         ret = parser_read_uint32(&param->burst_write,
1641                                 ent->value);
1642
1643                 APP_CHECK(ret != -ESRCH,
1644                         "CFG: [%s] entry '%s': unknown entry\n",
1645                         section_name,
1646                         ent->name);
1647                 APP_CHECK(ret != -EBADF,
1648                         "CFG: [%s] entry '%s': TM cfg parse error '%s'\n",
1649                         section_name,
1650                         ent->name,
1651                         ent->value);
1652                 APP_CHECK(ret == 0,
1653                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1654                         section_name,
1655                         ent->name,
1656                         ent->value);
1657         }
1658
1659         free(entries);
1660 }
1661
1662 static void
1663 parse_source(struct app_params *app,
1664         const char *section_name,
1665         struct rte_cfgfile *cfg)
1666 {
1667         struct app_pktq_source_params *param;
1668         struct rte_cfgfile_entry *entries;
1669         int n_entries, ret, i;
1670         ssize_t param_idx;
1671
1672         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1673         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1674
1675         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1676         PARSE_ERROR_MALLOC(entries != NULL);
1677
1678         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1679
1680         param_idx = APP_PARAM_ADD(app->source_params, section_name);
1681         PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);
1682
1683         param = &app->source_params[param_idx];
1684         param->parsed = 1;
1685
1686         for (i = 0; i < n_entries; i++) {
1687                 struct rte_cfgfile_entry *ent = &entries[i];
1688
1689                 ret = -ESRCH;
1690                 if (strcmp(ent->name, "mempool") == 0) {
1691                         int status = validate_name(ent->value, "MEMPOOL", 1);
1692                         ssize_t idx;
1693
1694                         APP_CHECK((status == 0),
1695                                 "CFG: [%s] entry '%s': invalid mempool\n",
1696                                         section_name,
1697                                         ent->name);
1698
1699                         idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1700                         PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1701                         param->mempool_id = idx;
1702                         ret = 0;
1703                 } else if (strcmp(ent->name, "burst") == 0)
1704                         ret = parser_read_uint32(&param->burst, ent->value);
1705
1706                 APP_CHECK(ret != -ESRCH,
1707                         "CFG: [%s] entry '%s': unknown entry\n",
1708                         section_name,
1709                         ent->name);
1710                 APP_CHECK(ret == 0,
1711                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1712                         section_name,
1713                         ent->name,
1714                         ent->value);
1715         }
1716
1717         free(entries);
1718 }
1719
1720 static void
1721 parse_msgq_req_pipeline(struct app_params *app,
1722         const char *section_name,
1723         struct rte_cfgfile *cfg)
1724 {
1725         struct app_msgq_params *param;
1726         struct rte_cfgfile_entry *entries;
1727         int n_entries, ret, i;
1728         ssize_t param_idx;
1729
1730         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1731         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1732
1733         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1734         PARSE_ERROR_MALLOC(entries != NULL);
1735
1736         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1737
1738         param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1739         PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
1740
1741         param = &app->msgq_params[param_idx];
1742         param->parsed = 1;
1743
1744         for (i = 0; i < n_entries; i++) {
1745                 struct rte_cfgfile_entry *ent = &entries[i];
1746
1747                 ret = -ESRCH;
1748                 if (strcmp(ent->name, "size") == 0)
1749                         ret = parser_read_uint32(&param->size, ent->value);
1750
1751                 APP_CHECK(ret != -ESRCH,
1752                         "CFG: [%s] entry '%s': unknown entry\n",
1753                         section_name,
1754                         ent->name);
1755                 APP_CHECK(ret == 0,
1756                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1757                         section_name,
1758                         ent->name,
1759                         ent->value);
1760         }
1761
1762         free(entries);
1763 }
1764
1765 static void
1766 parse_msgq_rsp_pipeline(struct app_params *app,
1767         const char *section_name,
1768         struct rte_cfgfile *cfg)
1769 {
1770         struct app_msgq_params *param;
1771         struct rte_cfgfile_entry *entries;
1772         int n_entries, ret, i;
1773         ssize_t param_idx;
1774
1775         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1776         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1777
1778         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1779         PARSE_ERROR_MALLOC(entries != NULL);
1780
1781         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1782
1783         param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1784         PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
1785
1786         param = &app->msgq_params[param_idx];
1787         param->parsed = 1;
1788
1789         for (i = 0; i < n_entries; i++) {
1790                 struct rte_cfgfile_entry *ent = &entries[i];
1791
1792                 ret = -ESRCH;
1793                 if (strcmp(ent->name, "size") == 0)
1794                         ret = parser_read_uint32(&param->size, ent->value);
1795
1796                 APP_CHECK(ret != -ESRCH,
1797                         "CFG: [%s] entry '%s': unknown entry\n",
1798                         section_name,
1799                         ent->name);
1800                 APP_CHECK(ret == 0,
1801                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1802                         section_name,
1803                         ent->name,
1804                         ent->value);
1805         }
1806
1807         free(entries);
1808 }
1809
1810 static void
1811 parse_msgq(struct app_params *app,
1812         const char *section_name,
1813         struct rte_cfgfile *cfg)
1814 {
1815         struct app_msgq_params *param;
1816         struct rte_cfgfile_entry *entries;
1817         int n_entries, ret, i;
1818         ssize_t param_idx;
1819
1820         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1821         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1822
1823         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1824         PARSE_ERROR_MALLOC(entries != NULL);
1825
1826         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1827
1828         param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1829         PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
1830
1831         param = &app->msgq_params[param_idx];
1832         param->parsed = 1;
1833
1834         for (i = 0; i < n_entries; i++) {
1835                 struct rte_cfgfile_entry *ent = &entries[i];
1836
1837                 ret = -ESRCH;
1838                 if (strcmp(ent->name, "size") == 0)
1839                         ret = parser_read_uint32(&param->size,
1840                                 ent->value);
1841                 else if (strcmp(ent->name, "cpu") == 0)
1842                         ret = parser_read_uint32(&param->cpu_socket_id,
1843                                 ent->value);
1844
1845                 APP_CHECK(ret != -ESRCH,
1846                         "CFG: [%s] entry '%s': unknown entry\n",
1847                         section_name,
1848                         ent->name);
1849                 APP_CHECK(ret == 0,
1850                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1851                         section_name,
1852                         ent->name,
1853                         ent->value);
1854         }
1855
1856         free(entries);
1857 }
1858
1859 typedef void (*config_section_load)(struct app_params *p,
1860         const char *section_name,
1861         struct rte_cfgfile *cfg);
1862
1863 struct config_section {
1864         const char prefix[CFG_NAME_LEN];
1865         int numbers;
1866         config_section_load load;
1867 };
1868
1869 static const struct config_section cfg_file_scheme[] = {
1870         {"EAL", 0, parse_eal},
1871         {"PIPELINE", 1, parse_pipeline},
1872         {"MEMPOOL", 1, parse_mempool},
1873         {"LINK", 1, parse_link},
1874         {"RXQ", 2, parse_rxq},
1875         {"TXQ", 2, parse_txq},
1876         {"SWQ", 1, parse_swq},
1877         {"TM", 1, parse_tm},
1878         {"SOURCE", 1, parse_source},
1879         {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
1880         {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
1881         {"MSGQ", 1, parse_msgq},
1882 };
1883
1884 static void
1885 create_implicit_mempools(struct app_params *app)
1886 {
1887         ssize_t idx;
1888
1889         idx = APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
1890         PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, "start-up");
1891 }
1892
1893 static void
1894 parse_port_mask(struct app_params *app, uint64_t port_mask)
1895 {
1896         uint32_t pmd_id, link_id;
1897
1898         link_id = 0;
1899         for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
1900                 char name[APP_PARAM_NAME_SIZE];
1901                 ssize_t idx;
1902
1903                 if ((port_mask & (1LLU << pmd_id)) == 0)
1904                         continue;
1905
1906                 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
1907                 idx = APP_PARAM_ADD(app->link_params, name);
1908                 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, name);
1909
1910                 app->link_params[idx].pmd_id = pmd_id;
1911                 link_id++;
1912         }
1913 }
1914
1915 int
1916 app_config_parse(struct app_params *app, const char *file_name)
1917 {
1918         struct rte_cfgfile *cfg;
1919         char **section_names;
1920         int i, j, sect_count;
1921
1922         /* Implicit mempools */
1923         create_implicit_mempools(app);
1924
1925         /* Port mask */
1926         parse_port_mask(app, app->port_mask);
1927
1928         /* Load application configuration file */
1929         cfg = rte_cfgfile_load(file_name, 0);
1930         APP_CHECK(cfg != NULL, "Unable to load config file %s", file_name);
1931
1932         sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
1933         section_names = malloc(sect_count * sizeof(char *));
1934         for (i = 0; i < sect_count; i++)
1935                 section_names[i] = malloc(CFG_NAME_LEN);
1936
1937         rte_cfgfile_sections(cfg, section_names, sect_count);
1938
1939         for (i = 0; i < sect_count; i++) {
1940                 const struct config_section *sch_s;
1941                 int len, cfg_name_len;
1942
1943                 cfg_name_len = strlen(section_names[i]);
1944
1945                 /* Find section type */
1946                 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
1947                         sch_s = &cfg_file_scheme[j];
1948                         len = strlen(sch_s->prefix);
1949
1950                         if (cfg_name_len < len)
1951                                 continue;
1952
1953                         /* After section name we expect only '\0' or digit or
1954                          * digit dot digit, so protect against false matching,
1955                          * for example: "ABC" should match section name
1956                          * "ABC0.0", but it should not match section_name
1957                          * "ABCDEF".
1958                          */
1959                         if ((section_names[i][len] != '\0') &&
1960                                 !isdigit(section_names[i][len]))
1961                                 continue;
1962
1963                         if (strncmp(sch_s->prefix, section_names[i], len) == 0)
1964                                 break;
1965                 }
1966
1967                 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
1968                         "Unknown section %s",
1969                         section_names[i]);
1970
1971                 APP_CHECK(validate_name(section_names[i],
1972                         sch_s->prefix,
1973                         sch_s->numbers) == 0,
1974                         "Invalid section name '%s'",
1975                         section_names[i]);
1976
1977                 sch_s->load(app, section_names[i], cfg);
1978         }
1979
1980         for (i = 0; i < sect_count; i++)
1981                 free(section_names[i]);
1982
1983         free(section_names);
1984
1985         rte_cfgfile_close(cfg);
1986
1987         APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
1988         APP_PARAM_COUNT(app->link_params, app->n_links);
1989         APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
1990         APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
1991         APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
1992         APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
1993         APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
1994         APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
1995         APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
1996         APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
1997
1998         /* Save configuration to output file */
1999         app_config_save(app, app->output_file);
2000
2001         /* Load TM configuration files */
2002         app_config_parse_tm(app);
2003
2004         return 0;
2005 }
2006
2007 static void
2008 save_eal_params(struct app_params *app, FILE *f)
2009 {
2010         struct app_eal_params *p = &app->eal_params;
2011
2012         fprintf(f, "[EAL]\n");
2013
2014         if (p->coremap)
2015                 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2016
2017         if (p->master_lcore_present)
2018                 fprintf(f, "%s = %" PRIu32 "\n",
2019                         "master_lcore", p->master_lcore);
2020
2021         fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2022
2023         if (p->memory_present)
2024                 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2025
2026         if (p->ranks_present)
2027                 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2028
2029         if (p->pci_blacklist)
2030                 fprintf(f, "%s = %s\n", "pci_blacklist", p->pci_blacklist);
2031
2032         if (p->pci_whitelist)
2033                 fprintf(f, "%s = %s\n", "pci_whitelist", p->pci_whitelist);
2034
2035         if (p->vdev)
2036                 fprintf(f, "%s = %s\n", "vdev", p->vdev);
2037
2038         if (p->vmware_tsc_map_present)
2039                 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2040                         (p->vmware_tsc_map) ? "yes" : "no");
2041
2042         if (p->proc_type)
2043                 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2044
2045         if (p->syslog)
2046                 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2047
2048         if (p->log_level_present)
2049                 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2050
2051         if (p->version_present)
2052                 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2053
2054         if (p->help_present)
2055                 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2056
2057         if (p->no_huge_present)
2058                 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2059
2060         if (p->no_pci_present)
2061                 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2062
2063         if (p->no_hpet_present)
2064                 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2065
2066         if (p->no_shconf_present)
2067                 fprintf(f, "%s = %s\n", "no_shconf",
2068                         (p->no_shconf) ? "yes" : "no");
2069
2070         if (p->add_driver)
2071                 fprintf(f, "%s = %s\n", "d", p->add_driver);
2072
2073         if (p->socket_mem)
2074                 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2075
2076         if (p->huge_dir)
2077                 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2078
2079         if (p->file_prefix)
2080                 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2081
2082         if (p->base_virtaddr)
2083                 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2084
2085         if (p->create_uio_dev_present)
2086                 fprintf(f, "%s = %s\n", "create_uio_dev",
2087                         (p->create_uio_dev) ? "yes" : "no");
2088
2089         if (p->vfio_intr)
2090                 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2091
2092         if (p->xen_dom0_present)
2093                 fprintf(f, "%s = %s\n", "xen_dom0",
2094                         (p->xen_dom0) ? "yes" : "no");
2095
2096         fputc('\n', f);
2097 }
2098
2099 static void
2100 save_mempool_params(struct app_params *app, FILE *f)
2101 {
2102         struct app_mempool_params *p;
2103         size_t i, count;
2104
2105         count = RTE_DIM(app->mempool_params);
2106         for (i = 0; i < count; i++) {
2107                 p = &app->mempool_params[i];
2108                 if (!APP_PARAM_VALID(p))
2109                         continue;
2110
2111                 fprintf(f, "[%s]\n", p->name);
2112                 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2113                 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2114                 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2115                 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2116
2117                 fputc('\n', f);
2118         }
2119 }
2120
2121 static void
2122 save_links_params(struct app_params *app, FILE *f)
2123 {
2124         struct app_link_params *p;
2125         size_t i, count;
2126
2127         count = RTE_DIM(app->link_params);
2128         for (i = 0; i < count; i++) {
2129                 p = &app->link_params[i];
2130                 if (!APP_PARAM_VALID(p))
2131                         continue;
2132
2133                 fprintf(f, "[%s]\n", p->name);
2134                 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2135                 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2136                 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2137                 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_local_q",
2138                         p->tcp_syn_local_q);
2139                 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2140                 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2141                 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2142                 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2143                         p->sctp_local_q);
2144
2145                 fputc('\n', f);
2146         }
2147 }
2148
2149 static void
2150 save_rxq_params(struct app_params *app, FILE *f)
2151 {
2152         struct app_pktq_hwq_in_params *p;
2153         size_t i, count;
2154
2155         count = RTE_DIM(app->hwq_in_params);
2156         for (i = 0; i < count; i++) {
2157                 p = &app->hwq_in_params[i];
2158                 if (!APP_PARAM_VALID(p))
2159                         continue;
2160
2161                 fprintf(f, "[%s]\n", p->name);
2162                 fprintf(f, "%s = %s\n",
2163                         "mempool",
2164                         app->mempool_params[p->mempool_id].name);
2165                 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2166                 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2167
2168                 fputc('\n', f);
2169         }
2170 }
2171
2172 static void
2173 save_txq_params(struct app_params *app, FILE *f)
2174 {
2175         struct app_pktq_hwq_out_params *p;
2176         size_t i, count;
2177
2178         count = RTE_DIM(app->hwq_out_params);
2179         for (i = 0; i < count; i++) {
2180                 p = &app->hwq_out_params[i];
2181                 if (!APP_PARAM_VALID(p))
2182                         continue;
2183
2184                 fprintf(f, "[%s]\n", p->name);
2185                 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2186                 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2187                 fprintf(f, "%s = %s\n",
2188                         "dropless",
2189                         p->dropless ? "yes" : "no");
2190
2191                 fputc('\n', f);
2192         }
2193 }
2194
2195 static void
2196 save_swq_params(struct app_params *app, FILE *f)
2197 {
2198         struct app_pktq_swq_params *p;
2199         size_t i, count;
2200
2201         count = RTE_DIM(app->swq_params);
2202         for (i = 0; i < count; i++) {
2203                 p = &app->swq_params[i];
2204                 if (!APP_PARAM_VALID(p))
2205                         continue;
2206
2207                 fprintf(f, "[%s]\n", p->name);
2208                 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2209                 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2210                 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2211                 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2212                 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2213                 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2214                 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2215                 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2216                 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2217                 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2218                 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2219                         fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2220                         fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2221                         fprintf(f, "%s = %s\n",
2222                                 "mempool_direct",
2223                                 app->mempool_params[p->mempool_direct_id].name);
2224                         fprintf(f, "%s = %s\n",
2225                                 "mempool_indirect",
2226                                 app->mempool_params[p->mempool_indirect_id].name);
2227                 }
2228
2229                 fputc('\n', f);
2230         }
2231 }
2232
2233 static void
2234 save_tm_params(struct app_params *app, FILE *f)
2235 {
2236         struct app_pktq_tm_params *p;
2237         size_t i, count;
2238
2239         count = RTE_DIM(app->tm_params);
2240         for (i = 0; i < count; i++) {
2241                 p = &app->tm_params[i];
2242                 if (!APP_PARAM_VALID(p))
2243                         continue;
2244
2245                 fprintf(f, "[%s]\n", p->name);
2246                 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2247                 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2248                 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2249
2250                 fputc('\n', f);
2251         }
2252 }
2253
2254 static void
2255 save_source_params(struct app_params *app, FILE *f)
2256 {
2257         struct app_pktq_source_params *p;
2258         size_t i, count;
2259
2260         count = RTE_DIM(app->source_params);
2261         for (i = 0; i < count; i++) {
2262                 p = &app->source_params[i];
2263                 if (!APP_PARAM_VALID(p))
2264                         continue;
2265
2266                 fprintf(f, "[%s]\n", p->name);
2267                 fprintf(f, "%s = %s\n",
2268                         "mempool",
2269                         app->mempool_params[p->mempool_id].name);
2270                 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2271                 fputc('\n', f);
2272         }
2273 }
2274
2275 static void
2276 save_msgq_params(struct app_params *app, FILE *f)
2277 {
2278         struct app_msgq_params *p;
2279         size_t i, count;
2280
2281         count = RTE_DIM(app->msgq_params);
2282         for (i = 0; i < count; i++) {
2283                 p = &app->msgq_params[i];
2284                 if (!APP_PARAM_VALID(p))
2285                         continue;
2286
2287                 fprintf(f, "[%s]\n", p->name);
2288                 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2289                 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2290
2291                 fputc('\n', f);
2292         }
2293 }
2294
2295 static void
2296 save_pipeline_params(struct app_params *app, FILE *f)
2297 {
2298         size_t i, count;
2299
2300         count = RTE_DIM(app->pipeline_params);
2301         for (i = 0; i < count; i++) {
2302                 struct app_pipeline_params *p = &app->pipeline_params[i];
2303
2304                 if (!APP_PARAM_VALID(p))
2305                         continue;
2306
2307                 /* section name */
2308                 fprintf(f, "[%s]\n", p->name);
2309
2310                 /* type */
2311                 fprintf(f, "type = %s\n", p->type);
2312
2313                 /* core */
2314                 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2315                         p->socket_id,
2316                         p->core_id,
2317                         (p->hyper_th_id) ? "h" : "");
2318
2319                 /* pktq_in */
2320                 if (p->n_pktq_in) {
2321                         uint32_t j;
2322
2323                         fprintf(f, "pktq_in =");
2324                         for (j = 0; j < p->n_pktq_in; j++) {
2325                                 struct app_pktq_in_params *pp = &p->pktq_in[j];
2326                                 char *name;
2327
2328                                 switch (pp->type) {
2329                                 case APP_PKTQ_IN_HWQ:
2330                                         name = app->hwq_in_params[pp->id].name;
2331                                         break;
2332                                 case APP_PKTQ_IN_SWQ:
2333                                         name = app->swq_params[pp->id].name;
2334                                         break;
2335                                 case APP_PKTQ_IN_TM:
2336                                         name = app->tm_params[pp->id].name;
2337                                         break;
2338                                 case APP_PKTQ_IN_SOURCE:
2339                                         name = app->source_params[pp->id].name;
2340                                         break;
2341                                 default:
2342                                         APP_CHECK(0, "Error\n");
2343                                 }
2344
2345                                 fprintf(f, " %s", name);
2346                         }
2347                         fprintf(f, "\n");
2348                 }
2349
2350                 /* pktq_in */
2351                 if (p->n_pktq_out) {
2352                         uint32_t j;
2353
2354                         fprintf(f, "pktq_out =");
2355                         for (j = 0; j < p->n_pktq_out; j++) {
2356                                 struct app_pktq_out_params *pp =
2357                                         &p->pktq_out[j];
2358                                 char *name;
2359
2360                                 switch (pp->type) {
2361                                 case APP_PKTQ_OUT_HWQ:
2362                                         name = app->hwq_out_params[pp->id].name;
2363                                         break;
2364                                 case APP_PKTQ_OUT_SWQ:
2365                                         name = app->swq_params[pp->id].name;
2366                                         break;
2367                                 case APP_PKTQ_OUT_TM:
2368                                         name = app->tm_params[pp->id].name;
2369                                         break;
2370                                 case APP_PKTQ_OUT_SINK:
2371                                         name = app->sink_params[pp->id].name;
2372                                         break;
2373                                 default:
2374                                         APP_CHECK(0, "Error\n");
2375                                 }
2376
2377                                 fprintf(f, " %s", name);
2378                         }
2379                         fprintf(f, "\n");
2380                 }
2381
2382                 /* msgq_in */
2383                 if (p->n_msgq_in) {
2384                         uint32_t j;
2385
2386                         fprintf(f, "msgq_in =");
2387                         for (j = 0; j < p->n_msgq_in; j++) {
2388                                 uint32_t id = p->msgq_in[j];
2389                                 char *name = app->msgq_params[id].name;
2390
2391                                 fprintf(f, " %s", name);
2392                         }
2393                         fprintf(f, "\n");
2394                 }
2395
2396                 /* msgq_out */
2397                 if (p->n_msgq_in) {
2398                         uint32_t j;
2399
2400                         fprintf(f, "msgq_out =");
2401                         for (j = 0; j < p->n_msgq_out; j++) {
2402                                 uint32_t id = p->msgq_out[j];
2403                                 char *name = app->msgq_params[id].name;
2404
2405                                 fprintf(f, " %s", name);
2406                         }
2407                         fprintf(f, "\n");
2408                 }
2409
2410                 /* timer_period */
2411                 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
2412
2413                 /* args */
2414                 if (p->n_args) {
2415                         uint32_t j;
2416
2417                         for (j = 0; j < p->n_args; j++)
2418                                 fprintf(f, "%s = %s\n", p->args_name[j],
2419                                         p->args_value[j]);
2420                 }
2421
2422                 fprintf(f, "\n");
2423         }
2424 }
2425
2426 void
2427 app_config_save(struct app_params *app, const char *file_name)
2428 {
2429         FILE *file;
2430         char *name, *dir_name;
2431         int status;
2432
2433         name = strdup(file_name);
2434         dir_name = dirname(name);
2435         status = access(dir_name, W_OK);
2436         APP_CHECK((status == 0),
2437                 "Need write access to directory \"%s\" to save configuration\n",
2438                 dir_name);
2439
2440         file = fopen(file_name, "w");
2441         APP_CHECK((file != NULL),
2442                 "Failed to save configuration to file \"%s\"", file_name);
2443
2444         save_eal_params(app, file);
2445         save_pipeline_params(app, file);
2446         save_mempool_params(app, file);
2447         save_links_params(app, file);
2448         save_rxq_params(app, file);
2449         save_txq_params(app, file);
2450         save_swq_params(app, file);
2451         save_tm_params(app, file);
2452         save_source_params(app, file);
2453         save_msgq_params(app, file);
2454
2455         fclose(file);
2456         free(name);
2457 }
2458
2459 int
2460 app_config_init(struct app_params *app)
2461 {
2462         size_t i;
2463
2464         memcpy(app, &app_params_default, sizeof(struct app_params));
2465
2466         for (i = 0; i < RTE_DIM(app->mempool_params); i++)
2467                 memcpy(&app->mempool_params[i],
2468                         &mempool_params_default,
2469                         sizeof(struct app_mempool_params));
2470
2471         for (i = 0; i < RTE_DIM(app->link_params); i++)
2472                 memcpy(&app->link_params[i],
2473                         &link_params_default,
2474                         sizeof(struct app_link_params));
2475
2476         for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
2477                 memcpy(&app->hwq_in_params[i],
2478                         &default_hwq_in_params,
2479                         sizeof(default_hwq_in_params));
2480
2481         for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
2482                 memcpy(&app->hwq_out_params[i],
2483                         &default_hwq_out_params,
2484                         sizeof(default_hwq_out_params));
2485
2486         for (i = 0; i < RTE_DIM(app->swq_params); i++)
2487                 memcpy(&app->swq_params[i],
2488                         &default_swq_params,
2489                         sizeof(default_swq_params));
2490
2491         for (i = 0; i < RTE_DIM(app->tm_params); i++)
2492                 memcpy(&app->tm_params[i],
2493                         &default_tm_params,
2494                         sizeof(default_tm_params));
2495
2496         for (i = 0; i < RTE_DIM(app->source_params); i++)
2497                 memcpy(&app->source_params[i],
2498                         &default_source_params,
2499                         sizeof(default_source_params));
2500
2501         for (i = 0; i < RTE_DIM(app->sink_params); i++)
2502                 memcpy(&app->sink_params[i],
2503                         &default_sink_params,
2504                         sizeof(default_sink_params));
2505
2506         for (i = 0; i < RTE_DIM(app->msgq_params); i++)
2507                 memcpy(&app->msgq_params[i],
2508                         &default_msgq_params,
2509                         sizeof(default_msgq_params));
2510
2511         for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
2512                 memcpy(&app->pipeline_params[i],
2513                         &default_pipeline_params,
2514                         sizeof(default_pipeline_params));
2515
2516         return 0;
2517 }
2518
2519 static char *
2520 filenamedup(const char *filename, const char *suffix)
2521 {
2522         char *s = malloc(strlen(filename) + strlen(suffix) + 1);
2523
2524         if (!s)
2525                 return NULL;
2526
2527         sprintf(s, "%s%s", filename, suffix);
2528         return s;
2529 }
2530
2531 int
2532 app_config_args(struct app_params *app, int argc, char **argv)
2533 {
2534         const char *optname;
2535         int opt, option_index;
2536         int f_present, s_present, p_present, l_present;
2537         int preproc_present, preproc_params_present;
2538         int scaned = 0;
2539
2540         static struct option lgopts[] = {
2541                 { "preproc", 1, 0, 0 },
2542                 { "preproc-args", 1, 0, 0 },
2543                 { NULL,  0, 0, 0 }
2544         };
2545
2546         /* Copy application name */
2547         strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
2548
2549         f_present = 0;
2550         s_present = 0;
2551         p_present = 0;
2552         l_present = 0;
2553         preproc_present = 0;
2554         preproc_params_present = 0;
2555
2556         while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
2557                         &option_index)) != EOF)
2558                 switch (opt) {
2559                 case 'f':
2560                         if (f_present)
2561                                 rte_panic("Error: Config file is provided "
2562                                         "more than once\n");
2563                         f_present = 1;
2564
2565                         if (!strlen(optarg))
2566                                 rte_panic("Error: Config file name is null\n");
2567
2568                         app->config_file = strdup(optarg);
2569                         if (app->config_file == NULL)
2570                                 rte_panic("Error: Memory allocation failure\n");
2571
2572                         break;
2573
2574                 case 's':
2575                         if (s_present)
2576                                 rte_panic("Error: Script file is provided "
2577                                         "more than once\n");
2578                         s_present = 1;
2579
2580                         if (!strlen(optarg))
2581                                 rte_panic("Error: Script file name is null\n");
2582
2583                         app->script_file = strdup(optarg);
2584                         if (app->script_file == NULL)
2585                                 rte_panic("Error: Memory allocation failure\n");
2586
2587                         break;
2588
2589                 case 'p':
2590                         if (p_present)
2591                                 rte_panic("Error: PORT_MASK is provided "
2592                                         "more than once\n");
2593                         p_present = 1;
2594
2595                         if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
2596                                 &scaned) != 1) ||
2597                                 ((size_t) scaned != strlen(optarg)))
2598                                 rte_panic("Error: PORT_MASK is not "
2599                                         "a hexadecimal integer\n");
2600
2601                         if (app->port_mask == 0)
2602                                 rte_panic("Error: PORT_MASK is null\n");
2603
2604                         break;
2605
2606                 case 'l':
2607                         if (l_present)
2608                                 rte_panic("Error: LOG_LEVEL is provided "
2609                                         "more than once\n");
2610                         l_present = 1;
2611
2612                         if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
2613                                 &scaned) != 1) ||
2614                                 ((size_t) scaned != strlen(optarg)) ||
2615                                 (app->log_level >= APP_LOG_LEVELS))
2616                                 rte_panic("Error: LOG_LEVEL invalid value\n");
2617
2618                         break;
2619
2620                 case 0:
2621                         optname = lgopts[option_index].name;
2622
2623                         if (strcmp(optname, "preproc") == 0) {
2624                                 if (preproc_present)
2625                                         rte_panic("Error: Preprocessor argument "
2626                                                 "is provided more than once\n");
2627                                 preproc_present = 1;
2628
2629                                 app->preproc = strdup(optarg);
2630                                 break;
2631                         }
2632
2633                         if (strcmp(optname, "preproc-args") == 0) {
2634                                 if (preproc_params_present)
2635                                         rte_panic("Error: Preprocessor args "
2636                                                 "are provided more than once\n");
2637                                 preproc_params_present = 1;
2638
2639                                 app->preproc_args = strdup(optarg);
2640                                 break;
2641                         }
2642
2643                         app_print_usage(argv[0]);
2644                         break;
2645
2646                 default:
2647                         app_print_usage(argv[0]);
2648                 }
2649
2650         optind = 0; /* reset getopt lib */
2651
2652         /* Check that mandatory args have been provided */
2653         if (!p_present)
2654                 rte_panic("Error: PORT_MASK is not provided\n");
2655
2656         /* Check dependencies between args */
2657         if (preproc_params_present && (preproc_present == 0))
2658                 rte_panic("Error: Preprocessor args specified while "
2659                         "preprocessor is not defined\n");
2660
2661         app->parser_file = preproc_present ?
2662                 filenamedup(app->config_file, ".preproc") :
2663                 strdup(app->config_file);
2664         app->output_file = filenamedup(app->config_file, ".out");
2665
2666         return 0;
2667 }
2668
2669 int
2670 app_config_preproc(struct app_params *app)
2671 {
2672         char buffer[256];
2673         int status;
2674
2675         if (app->preproc == NULL)
2676                 return 0;
2677
2678         status = access(app->config_file, F_OK | R_OK);
2679         APP_CHECK((status == 0), "Unable to open file %s", app->config_file);
2680
2681         snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
2682                 app->preproc,
2683                 app->preproc_args ? app->preproc_args : "",
2684                 app->config_file,
2685                 app->parser_file);
2686
2687         status = system(buffer);
2688         APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
2689                 "Error while preprocessing file \"%s\"\n", app->config_file);
2690
2691         return status;
2692 }