| 847 | } |
| 848 | |
| 849 | static int |
| 850 | pipeline_table_entries_add(struct rte_swx_ctl_pipeline *p, |
| 851 | const char *table_name, |
| 852 | FILE *file, |
| 853 | uint32_t *file_line_number) |
| 854 | { |
| 855 | char *line = NULL; |
| 856 | uint32_t line_id = 0; |
| 857 | int status = 0; |
| 858 | |
| 859 | /* Buffer allocation. */ |
| 860 | line = malloc(MAX_LINE_SIZE); |
| 861 | if (!line) |
| 862 | return -ENOMEM; |
| 863 | |
| 864 | /* File read. */ |
| 865 | for (line_id = 1; ; line_id++) { |
| 866 | struct rte_swx_table_entry *entry; |
| 867 | int is_blank_or_comment; |
| 868 | |
| 869 | if (fgets(line, MAX_LINE_SIZE, file) == NULL) |
| 870 | break; |
| 871 | |
| 872 | entry = rte_swx_ctl_pipeline_table_entry_read(p, |
| 873 | table_name, |
| 874 | line, |
| 875 | &is_blank_or_comment); |
| 876 | if (!entry) { |
| 877 | if (is_blank_or_comment) |
| 878 | continue; |
| 879 | |
| 880 | status = -EINVAL; |
| 881 | goto error; |
| 882 | } |
| 883 | |
| 884 | status = rte_swx_ctl_pipeline_table_entry_add(p, |
| 885 | table_name, |
| 886 | entry); |
| 887 | table_entry_free(entry); |
| 888 | if (status) |
| 889 | goto error; |
| 890 | } |
| 891 | |
| 892 | error: |
| 893 | free(line); |
| 894 | *file_line_number = line_id; |
| 895 | return status; |
| 896 | } |
| 897 | |
| 898 | static const char cmd_pipeline_table_add_help[] = |
| 899 | "pipeline <pipeline_name> table <table_name> add <file_name>\n"; |
no test coverage detected