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)
86 return (sr - srt->rules);
96 RTT (mma_mask_or_match) *
key,
u32 rule_index)
103 rp =
RT (mma_rules_table_get_rule) (srt, rule_index);
108 for (
i = 0;
i <
vec_len (rp->next_indices);
i++)
114 return (rp->action_index);
119 RTT (mma_mask_or_match) *
key,
127 rp =
RT (mma_rules_table_get_rule) (srt, rule_index);
132 for (
i = 0;
i <
vec_len (rp->next_indices);
i++)
145 int RT (mma_sort_indices) (
void *e1,
void *e2)
147 u32 *ri1 = e1, *ri2 = e2;
148 RTT (mma_rule) * rule1, *rule2;
149 rule1 =
RT (mma_rules_table_get_rule) (
RTT (sort_srt), *ri1);
150 rule2 =
RT (mma_rules_table_get_rule) (
RTT (sort_srt), *ri2);
151 return RTT (sort_srt)->rule_cmp_fn (rule1, rule2);
156 RTT (sort_srt) = srt;
162 RTT (mma_rule) * rule)
164 u32 parent_index,
i, *next_indices = 0, added = 0, rule_index;
165 RTT (mma_rule) * parent, *child;
170 parent =
RT (mma_rules_table_get_rule) (srt, parent_index);
173 parent->action_index = rule->action_index;
174 RT (mma_rule_free) (srt, rule);
178 if (
vec_len (parent->next_indices) == 0)
180 vec_add1 (parent->next_indices, rule_index);
185 for (
i = 0;
i <
vec_len (parent->next_indices);
i++)
187 child =
RT (mma_rules_table_get_rule) (srt, parent->next_indices[
i]);
190 vec_add1 (rule->next_indices, parent->next_indices[
i]);
193 vec_add1 (next_indices, rule_index);
199 if (!added && srt->rule_cmp_fn (rule, child) < 0)
201 vec_add1 (next_indices, rule_index);
204 vec_add1 (next_indices, parent->next_indices[
i]);
208 vec_add1 (next_indices, rule_index);
210 parent->next_indices = next_indices;
216 RTT (mma_rule) * rule,
u32 rule_index)
223 rp =
RT (mma_rules_table_get_rule) (srt, rule_index);
229 if (rule_index == srt->root_index)
233 for (
i = 0;
i <
vec_len (rp->next_indices);
i++)
238 RTT (mma_rule) * child;
239 u32 *next_indices = 0, *new_elts, left_to_add;
240 child =
RT (mma_rules_table_get_rule) (srt, rp->next_indices[
i]);
248 if (
vec_len (child->next_indices))
249 vec_append (next_indices, child->next_indices);
250 left_to_add =
vec_len (rp->next_indices) -
i - 1;
253 vec_add2 (next_indices, new_elts, left_to_add);
255 left_to_add * sizeof (
u32));
257 RT (mma_rule_free) (srt, child);
259 rp->next_indices = next_indices;