| 169 | } |
| 170 | |
| 171 | static int |
| 172 | parse_file(FILE *f, struct rule *tbl, int rule_tbl) |
| 173 | { |
| 174 | int ret, i, j = 0; |
| 175 | char *s, *sp, *in[CB_RULE_NUM]; |
| 176 | static const char *dlm = " \t\n"; |
| 177 | int string_tok_nb = RTE_DIM(in); |
| 178 | |
| 179 | string_tok_nb -= (rule_tbl == 0) ? 1 : 0; |
| 180 | while (fgets(line, sizeof(line), f) != NULL) { |
| 181 | s = line; |
| 182 | for (i = 0; i != string_tok_nb; i++) { |
| 183 | in[i] = strtok_r(s, dlm, &sp); |
| 184 | if (in[i] == NULL) |
| 185 | return -EINVAL; |
| 186 | s = NULL; |
| 187 | } |
| 188 | GET_CB_FIELD(in[CB_RULE_SPI], tbl[j].tuple.v4.spi, 0, |
| 189 | UINT32_MAX, 0); |
| 190 | |
| 191 | if (config.ipv6) |
| 192 | ret = inet_pton(AF_INET6, in[CB_RULE_DIP], |
| 193 | &tbl[j].tuple.v6.dip); |
| 194 | else |
| 195 | ret = inet_pton(AF_INET, in[CB_RULE_DIP], |
| 196 | &tbl[j].tuple.v4.dip); |
| 197 | if (ret != 1) |
| 198 | return -EINVAL; |
| 199 | if (config.ipv6) |
| 200 | ret = inet_pton(AF_INET6, in[CB_RULE_SIP], |
| 201 | &tbl[j].tuple.v6.sip); |
| 202 | else |
| 203 | ret = inet_pton(AF_INET, in[CB_RULE_SIP], |
| 204 | &tbl[j].tuple.v4.sip); |
| 205 | if (ret != 1) |
| 206 | return -EINVAL; |
| 207 | if ((rule_tbl) && (in[CB_RULE_LEN] != NULL)) { |
| 208 | if (strcmp(in[CB_RULE_LEN], "SPI_DIP_SIP") == 0) { |
| 209 | tbl[j].rule_type = RTE_IPSEC_SAD_SPI_DIP_SIP; |
| 210 | config.nb_rules_96++; |
| 211 | } else if (strcmp(in[CB_RULE_LEN], "SPI_DIP") == 0) { |
| 212 | tbl[j].rule_type = RTE_IPSEC_SAD_SPI_DIP; |
| 213 | config.nb_rules_64++; |
| 214 | } else if (strcmp(in[CB_RULE_LEN], "SPI") == 0) { |
| 215 | tbl[j].rule_type = RTE_IPSEC_SAD_SPI_ONLY; |
| 216 | config.nb_rules_32++; |
| 217 | } else { |
| 218 | return -EINVAL; |
| 219 | } |
| 220 | } |
| 221 | j++; |
| 222 | } |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | static uint64_t |
| 227 | get_rnd_rng(uint64_t l, uint64_t u) |