| 1319 | } |
| 1320 | |
| 1321 | int |
| 1322 | pipeline_table_rule_add(const char *pipeline_name, |
| 1323 | uint32_t table_id, |
| 1324 | struct table_rule_match *match, |
| 1325 | struct table_rule_action *action) |
| 1326 | { |
| 1327 | struct pipeline *p; |
| 1328 | struct table *table; |
| 1329 | struct pipeline_msg_req *req; |
| 1330 | struct pipeline_msg_rsp *rsp; |
| 1331 | struct table_rule *rule; |
| 1332 | int status; |
| 1333 | |
| 1334 | /* Check input params */ |
| 1335 | if ((pipeline_name == NULL) || |
| 1336 | (match == NULL) || |
| 1337 | (action == NULL)) |
| 1338 | return -1; |
| 1339 | |
| 1340 | p = pipeline_find(pipeline_name); |
| 1341 | if ((p == NULL) || |
| 1342 | (table_id >= p->n_tables) || |
| 1343 | match_check(match, p, table_id) || |
| 1344 | action_check(action, p, table_id)) |
| 1345 | return -1; |
| 1346 | |
| 1347 | table = &p->table[table_id]; |
| 1348 | |
| 1349 | rule = calloc(1, sizeof(struct table_rule)); |
| 1350 | if (rule == NULL) |
| 1351 | return -1; |
| 1352 | |
| 1353 | memcpy(&rule->match, match, sizeof(*match)); |
| 1354 | memcpy(&rule->action, action, sizeof(*action)); |
| 1355 | |
| 1356 | if (!pipeline_is_running(p)) { |
| 1357 | union table_rule_match_low_level match_ll; |
| 1358 | struct rte_pipeline_table_entry *data_in, *data_out; |
| 1359 | int key_found; |
| 1360 | uint8_t *buffer; |
| 1361 | |
| 1362 | buffer = calloc(TABLE_RULE_ACTION_SIZE_MAX, sizeof(uint8_t)); |
| 1363 | if (buffer == NULL) { |
| 1364 | free(rule); |
| 1365 | return -1; |
| 1366 | } |
| 1367 | |
| 1368 | /* Table match-action rule conversion */ |
| 1369 | data_in = (struct rte_pipeline_table_entry *)buffer; |
| 1370 | |
| 1371 | status = match_convert(match, &match_ll, 1); |
| 1372 | if (status) { |
| 1373 | free(buffer); |
| 1374 | free(rule); |
| 1375 | return -1; |
| 1376 | } |
| 1377 | |
| 1378 | status = action_convert(table->a, action, data_in); |
no test coverage detected