| 426 | }; |
| 427 | |
| 428 | int |
| 429 | parse_cfg_file(const char *cfg_filename) |
| 430 | { |
| 431 | struct cmdline *cl = cmdline_stdin_new(ipsec_ctx, ""); |
| 432 | FILE *f = fopen(cfg_filename, "r"); |
| 433 | char str[1024] = {0}, *get_s = NULL; |
| 434 | uint32_t line_num = 0; |
| 435 | struct parse_status status = {0}; |
| 436 | |
| 437 | if (f == NULL) { |
| 438 | rte_panic("Error: invalid file descriptor %s\n", cfg_filename); |
| 439 | goto error_exit; |
| 440 | } |
| 441 | |
| 442 | if (cl == NULL) { |
| 443 | rte_panic("Error: cannot create cmdline instance\n"); |
| 444 | goto error_exit; |
| 445 | } |
| 446 | |
| 447 | cfg_sp_add_rule.data = &status; |
| 448 | cfg_sa_add_rule.data = &status; |
| 449 | cfg_rt_add_rule.data = &status; |
| 450 | cfg_flow_add_rule.data = &status; |
| 451 | cfg_neigh_add_rule.data = &status; |
| 452 | |
| 453 | do { |
| 454 | char oneline[1024]; |
| 455 | char *pos; |
| 456 | get_s = fgets(oneline, 1024, f); |
| 457 | |
| 458 | if (!get_s) |
| 459 | break; |
| 460 | |
| 461 | line_num++; |
| 462 | |
| 463 | if (strlen(oneline) > 1022) { |
| 464 | rte_panic("%s:%u: error: " |
| 465 | "the line contains more characters the parser can handle\n", |
| 466 | cfg_filename, line_num); |
| 467 | goto error_exit; |
| 468 | } |
| 469 | |
| 470 | /* process comment char '#' */ |
| 471 | if (oneline[0] == '#') |
| 472 | continue; |
| 473 | |
| 474 | pos = strchr(oneline, '#'); |
| 475 | if (pos != NULL) |
| 476 | *pos = '\0'; |
| 477 | |
| 478 | /* process line concatenator '\' */ |
| 479 | pos = strchr(oneline, 92); |
| 480 | if (pos != NULL) { |
| 481 | if (pos != oneline+strlen(oneline) - 2) { |
| 482 | rte_panic("%s:%u: error: " |
| 483 | "no character should exist after '\\'\n", |
| 484 | cfg_filename, line_num); |
| 485 | goto error_exit; |
no test coverage detected