| 956 | } |
| 957 | |
| 958 | static void |
| 959 | acx_init(void) |
| 960 | { |
| 961 | int ret; |
| 962 | FILE *f; |
| 963 | struct rte_acl_config cfg; |
| 964 | |
| 965 | memset(&cfg, 0, sizeof(cfg)); |
| 966 | |
| 967 | /* setup ACL build config. */ |
| 968 | if (config.ipv6 == IPV6_FRMT_U32) { |
| 969 | cfg.num_fields = RTE_DIM(ipv6_defs); |
| 970 | memcpy(&cfg.defs, ipv6_defs, sizeof(ipv6_defs)); |
| 971 | } else if (config.ipv6 == IPV6_FRMT_U64) { |
| 972 | cfg.num_fields = RTE_DIM(ipv6_u64_defs); |
| 973 | memcpy(&cfg.defs, ipv6_u64_defs, sizeof(ipv6_u64_defs)); |
| 974 | } else { |
| 975 | cfg.num_fields = RTE_DIM(ipv4_defs); |
| 976 | memcpy(&cfg.defs, ipv4_defs, sizeof(ipv4_defs)); |
| 977 | } |
| 978 | cfg.num_categories = config.bld_categories; |
| 979 | cfg.max_size = config.max_size; |
| 980 | |
| 981 | /* setup ACL creation parameters. */ |
| 982 | prm.rule_size = RTE_ACL_RULE_SZ(cfg.num_fields); |
| 983 | prm.max_rule_num = config.nb_rules; |
| 984 | |
| 985 | config.acx = rte_acl_create(&prm); |
| 986 | if (config.acx == NULL) |
| 987 | rte_exit(rte_errno, "failed to create ACL context\n"); |
| 988 | |
| 989 | /* set default classify method for this context. */ |
| 990 | if (config.alg.alg != RTE_ACL_CLASSIFY_DEFAULT) { |
| 991 | ret = rte_acl_set_ctx_classify(config.acx, config.alg.alg); |
| 992 | if (ret != 0) |
| 993 | rte_exit(ret, "failed to setup %s method " |
| 994 | "for ACL context\n", config.alg.name); |
| 995 | } |
| 996 | |
| 997 | /* add ACL rules. */ |
| 998 | f = fopen(config.rule_file, "r"); |
| 999 | if (f == NULL) |
| 1000 | rte_exit(-EINVAL, "failed to open file %s\n", |
| 1001 | config.rule_file); |
| 1002 | |
| 1003 | ret = add_cb_rules(f, config.acx); |
| 1004 | if (ret != 0) |
| 1005 | rte_exit(ret, "failed to add rules into ACL context\n"); |
| 1006 | |
| 1007 | fclose(f); |
| 1008 | |
| 1009 | /* perform build. */ |
| 1010 | ret = rte_acl_build(config.acx, &cfg); |
| 1011 | |
| 1012 | dump_verbose(DUMP_NONE, stdout, |
| 1013 | "rte_acl_build(%u) finished with %d\n", |
| 1014 | config.bld_categories, ret); |
| 1015 |
no test coverage detected