| 469 | } |
| 470 | |
| 471 | static struct rte_acl_ctx * |
| 472 | acl4_init(const char *name, int32_t socketid, const struct acl4_rules *rules, |
| 473 | uint32_t rules_nb) |
| 474 | { |
| 475 | char s[PATH_MAX]; |
| 476 | struct rte_acl_param acl_param; |
| 477 | struct rte_acl_config acl_build_param; |
| 478 | struct rte_acl_ctx *ctx; |
| 479 | |
| 480 | printf("Creating SP context with %u rules\n", rules_nb); |
| 481 | |
| 482 | memset(&acl_param, 0, sizeof(acl_param)); |
| 483 | |
| 484 | /* Create ACL contexts */ |
| 485 | snprintf(s, sizeof(s), "%s_%d", name, socketid); |
| 486 | |
| 487 | printf("IPv4 %s entries [%u]:\n", s, rules_nb); |
| 488 | dump_ip4_rules(rules, rules_nb, 1); |
| 489 | |
| 490 | acl_param.name = s; |
| 491 | acl_param.socket_id = socketid; |
| 492 | acl_param.rule_size = RTE_ACL_RULE_SZ(RTE_DIM(ip4_defs)); |
| 493 | acl_param.max_rule_num = rules_nb; |
| 494 | |
| 495 | ctx = rte_acl_create(&acl_param); |
| 496 | if (ctx == NULL) |
| 497 | rte_exit(EXIT_FAILURE, "Failed to create ACL context\n"); |
| 498 | |
| 499 | if (rte_acl_add_rules(ctx, (const struct rte_acl_rule *)rules, |
| 500 | rules_nb) < 0) |
| 501 | rte_exit(EXIT_FAILURE, "add rules failed\n"); |
| 502 | |
| 503 | /* Perform builds */ |
| 504 | memset(&acl_build_param, 0, sizeof(acl_build_param)); |
| 505 | |
| 506 | acl_build_param.num_categories = DEFAULT_MAX_CATEGORIES; |
| 507 | acl_build_param.num_fields = RTE_DIM(ip4_defs); |
| 508 | memcpy(&acl_build_param.defs, ip4_defs, sizeof(ip4_defs)); |
| 509 | |
| 510 | if (rte_acl_build(ctx, &acl_build_param) != 0) |
| 511 | rte_exit(EXIT_FAILURE, "Failed to build ACL trie\n"); |
| 512 | |
| 513 | rte_acl_dump(ctx); |
| 514 | |
| 515 | return ctx; |
| 516 | } |
| 517 | |
| 518 | /* |
| 519 | * check that for each rule it's SPI has a correspondent entry in SAD |
no test coverage detected