24 if (
key->match.as_u64[
i] !=
r->match.as_u64[
i])
29 if (
key->mask.as_u64[
i] !=
r->mask.as_u64[
i])
38 RTT (mma_mask_or_match) _tmp_key, *tkp = &_tmp_key;
43 tkp->as_u64[
i] &=
r->mask.as_u64[
i];
46 if (tkp->as_u64[
i] !=
r->match.as_u64[
i])
52 RTT (mma_rule) *
RT (mma_rules_table_rule_alloc) (
RTT (mma_rules_table) * srt)
54 RTT (mma_rule) * rule;
61 RT (mma_rule_free) (
RTT (mma_rules_table) * srt,
RTT (mma_rule) * rule)
81 return (sr - srt->rules);
91 RTT (mma_mask_or_match) *
key,
u32 rule_index)
98 rp =
RT (mma_rules_table_get_rule) (srt, rule_index);
103 for (
i = 0;
i <
vec_len (rp->next_indices);
i++)
109 return (rp->action_index);
114 RTT (mma_mask_or_match) *
key,
122 rp =
RT (mma_rules_table_get_rule) (srt, rule_index);
127 for (
i = 0;
i <
vec_len (rp->next_indices);
i++)
140 int RT (mma_sort_indices) (
void *e1,
void *e2)
142 u32 *ri1 = e1, *ri2 = e2;
143 RTT (mma_rule) * rule1, *rule2;
144 rule1 =
RT (mma_rules_table_get_rule) (
RTT (sort_srt), *ri1);
145 rule2 =
RT (mma_rules_table_get_rule) (
RTT (sort_srt), *ri2);
146 return RTT (sort_srt)->rule_cmp_fn (rule1, rule2);
151 RTT (sort_srt) = srt;
157 RTT (mma_rule) * rule)
159 u32 parent_index,
i, *next_indices = 0, added = 0, rule_index;
160 RTT (mma_rule) * parent, *child;
165 parent =
RT (mma_rules_table_get_rule) (srt, parent_index);
168 parent->action_index = rule->action_index;
169 RT (mma_rule_free) (srt, rule);
173 if (
vec_len (parent->next_indices) == 0)
175 vec_add1 (parent->next_indices, rule_index);
180 for (
i = 0;
i <
vec_len (parent->next_indices);
i++)
182 child =
RT (mma_rules_table_get_rule) (srt, parent->next_indices[
i]);
185 vec_add1 (rule->next_indices, parent->next_indices[
i]);
188 vec_add1 (next_indices, rule_index);
194 if (!added && srt->rule_cmp_fn (rule, child) < 0)
196 vec_add1 (next_indices, rule_index);
199 vec_add1 (next_indices, parent->next_indices[
i]);
203 vec_add1 (next_indices, rule_index);
205 parent->next_indices = next_indices;
211 RTT (mma_rule) * rule,
u32 rule_index)
218 rp =
RT (mma_rules_table_get_rule) (srt, rule_index);
224 if (rule_index == srt->root_index)
228 for (
i = 0;
i <
vec_len (rp->next_indices);
i++)
233 RTT (mma_rule) * child;
234 u32 *next_indices = 0, *new_elts, left_to_add;
235 child =
RT (mma_rules_table_get_rule) (srt, rp->next_indices[
i]);
243 if (
vec_len (child->next_indices))
244 vec_append (next_indices, child->next_indices);
245 left_to_add =
vec_len (rp->next_indices) -
i - 1;
248 vec_add2 (next_indices, new_elts, left_to_add);
250 left_to_add * sizeof (
u32));
252 RT (mma_rule_free) (srt, child);
254 rp->next_indices = next_indices;