26 return ((ri << 1) | is_ip4);
32 *is_ip4 = rti_key & 1;
68 rtip =
hash_get (srt->tags_by_rules, rti_key);
83 u32 rule_index,
u8 is_ip4)
98 hash_set (srt->tags_by_rules, rti_key,
rt - srt->rule_tags);
124 mma_rule_16_t *sr = va_arg (*args, mma_rule_16_t *);
125 session_mask_or_match_4_t *
mask, *match;
126 mma_rules_table_16_t *srt4;
127 u8 *tag = 0, *null_tag =
format (0,
"none");
131 srt4 = &srt->session_rules_tables_16;
132 ri = mma_rules_table_rule_index_16 (srt4, sr);
134 match = (session_mask_or_match_4_t *) & sr->match;
135 mask = (session_mask_or_match_4_t *) & sr->mask;
137 s =
format (s,
"[%d] rule: %U/%d %d %U/%d %d action: %d tag: %v", ri,
142 clib_net_to_host_u16 (match->rmt_port), sr->action_index,
143 tag ? tag : null_tag);
144 if (
vec_len (sr->next_indices))
146 s =
format (s,
"\n children: ");
147 for (
i = 0;
i <
vec_len (sr->next_indices);
i++)
148 s =
format (s,
"%d ", sr->next_indices[
i]);
158 mma_rule_40_t *sr = va_arg (*args, mma_rule_40_t *);
159 session_mask_or_match_6_t *
mask, *match;
160 mma_rules_table_40_t *srt6;
161 u8 *tag = 0, *null_tag =
format (0,
"none");
165 srt6 = &srt->session_rules_tables_40;
166 ri = mma_rules_table_rule_index_40 (srt6, sr);
168 match = (session_mask_or_match_6_t *) & sr->match;
169 mask = (session_mask_or_match_6_t *) & sr->mask;
171 s =
format (s,
"[%d] rule: %U/%d %d %U/%d %d action: %d tag: %v", ri,
176 clib_net_to_host_u16 (match->rmt_port), sr->action_index,
177 tag ? tag : null_tag);
178 if (
vec_len (sr->next_indices))
180 s =
format (s,
"\n children: ");
181 for (
i = 0;
i <
vec_len (sr->next_indices);
i++)
182 s =
format (s,
"%d ", sr->next_indices[
i]);
192 return &srt->session_rules_tables_16;
194 return &srt->session_rules_tables_40;
201 session_mask_or_match_4_t *m1, *m2;
203 m1 = (session_mask_or_match_4_t *) & rule1->max_match;
204 m2 = (session_mask_or_match_4_t *) & rule2->max_match;
205 if (m1->rmt_ip.as_u32 != m2->rmt_ip.as_u32)
206 return (m1->rmt_ip.as_u32 < m2->rmt_ip.as_u32 ? -1 : 1);
207 if (m1->lcl_ip.as_u32 != m2->lcl_ip.as_u32)
208 return (m1->lcl_ip.as_u32 < m2->lcl_ip.as_u32 ? -1 : 1);
209 if (m1->rmt_port != m2->rmt_port)
210 return (m1->rmt_port < m2->rmt_port ? -1 : 1);
211 if (m1->lcl_port != m2->lcl_port)
212 return (m1->lcl_port < m2->lcl_port ? -1 : 1);
219 session_mask_or_match_6_t *r1, *r2;
220 r1 = (session_mask_or_match_6_t *) & rule1->max_match;
221 r2 = (session_mask_or_match_6_t *) & rule2->max_match;
222 if (r1->rmt_ip.as_u64[0] != r2->rmt_ip.as_u64[0])
223 return (r1->rmt_ip.as_u64[0] < r2->rmt_ip.as_u64[0] ? -1 : 1);
224 if (r1->rmt_ip.as_u64[1] != r2->rmt_ip.as_u64[1])
225 return (r1->rmt_ip.as_u64[1] < r2->rmt_ip.as_u64[1] ? -1 : 1);
226 if (r1->lcl_ip.as_u64[0] != r2->lcl_ip.as_u64[0])
227 return (r1->lcl_ip.as_u64[0] < r2->lcl_ip.as_u64[0] ? -1 : 1);
228 if (r1->lcl_ip.as_u64[1] != r2->lcl_ip.as_u64[1])
229 return (r1->lcl_ip.as_u64[1] < r2->lcl_ip.as_u64[1]) ? -1 : 1;
230 if (r1->rmt_port != r2->rmt_port)
231 return (r1->rmt_port < r2->rmt_port ? -1 : 1);
232 if (r1->lcl_port != r2->lcl_port)
233 return (r1->lcl_port < r2->lcl_port ? -1 : 1);
242 session_mask_or_match_4_t *match, *
mask, *max_match;
245 match = (session_mask_or_match_4_t *) & rule->match;
246 match->lcl_ip.as_u32 = lcl->
fp_addr.ip4.as_u32;
247 match->rmt_ip.as_u32 = rmt->
fp_addr.ip4.as_u32;
248 match->lcl_port = lcl_port;
249 match->rmt_port = rmt_port;
250 mask = (session_mask_or_match_4_t *) & rule->mask;
253 mask->lcl_port = lcl_port == 0 ? 0 : (
u16) ~ 0;
254 mask->rmt_port = rmt_port == 0 ? 0 : (
u16) ~ 0;
255 max_match = (session_mask_or_match_4_t *) & rule->max_match;
260 max_match->lcl_port = lcl_port == 0 ? (
u16) ~ 0 : lcl_port;
261 max_match->rmt_port = rmt_port == 0 ? (
u16) ~ 0 : rmt_port;
269 session_mask_or_match_6_t *match, *
mask, *max_match;
272 match = (session_mask_or_match_6_t *) & rule->match;
274 sizeof (match->lcl_ip));
276 sizeof (match->rmt_ip));
277 match->lcl_port = lcl_port;
278 match->rmt_port = rmt_port;
279 mask = (session_mask_or_match_6_t *) & rule->mask;
282 mask->lcl_port = lcl_port == 0 ? 0 : (
u16) ~ 0;
283 mask->rmt_port = rmt_port == 0 ? 0 : (
u16) ~ 0;
284 max_match = (session_mask_or_match_6_t *) & rule->max_match;
289 max_match->lcl_port = lcl_port == 0 ? (
u16) ~ 0 : lcl_port;
290 max_match->rmt_port = rmt_port == 0 ? (
u16) ~ 0 : rmt_port;
298 mma_rule_16_t *rule = 0;
299 rule = mma_rules_table_rule_alloc_16 (srt);
310 rule = mma_rules_table_rule_alloc_40 (srt);
321 mma_rules_table_16_t *srt4 = &srt->session_rules_tables_16;
322 session_mask_or_match_4_t
key = {
323 .lcl_ip.as_u32 = lcl_ip->
as_u32,
324 .rmt_ip.as_u32 = rmt_ip->
as_u32,
325 .lcl_port = lcl_port,
326 .rmt_port = rmt_port,
328 return mma_rules_table_lookup_rule_16 (srt4,
329 (mma_mask_or_match_16_t *) &
key,
336 u16 lcl_port,
u16 rmt_port)
338 mma_rules_table_16_t *srt4 = &srt->session_rules_tables_16;
339 session_mask_or_match_4_t
key = {
340 .lcl_ip.as_u32 = lcl_ip->
as_u32,
341 .rmt_ip.as_u32 = rmt_ip->
as_u32,
342 .lcl_port = lcl_port,
343 .rmt_port = rmt_port,
345 return mma_rules_table_lookup_16 (srt4, (mma_mask_or_match_16_t *) &
key,
351 ip6_address_t * lcl_ip,
352 ip6_address_t * rmt_ip,
u16 lcl_port,
355 mma_rules_table_40_t *srt6 = &srt->session_rules_tables_40;
356 session_mask_or_match_6_t
key = {
357 .lcl_port = lcl_port,
358 .rmt_port = rmt_port,
362 return mma_rules_table_lookup_rule_40 (srt6,
363 (mma_mask_or_match_40_t *) &
key,
369 ip6_address_t * lcl_ip, ip6_address_t * rmt_ip,
370 u16 lcl_port,
u16 rmt_port)
372 mma_rules_table_40_t *srt6 = &srt->session_rules_tables_40;
373 session_mask_or_match_6_t
key = {
374 .lcl_port = lcl_port,
375 .rmt_port = rmt_port,
379 return mma_rules_table_lookup_40 (srt6, (mma_mask_or_match_40_t *) &
key,
395 u8 fib_proto = args->rmt.fp_proto, *
rt;
401 return VNET_API_ERROR_INVALID_VALUE;
405 mma_rules_table_16_t *srt4;
406 srt4 = &srt->session_rules_tables_16;
409 mma_rule_16_t *rule4;
414 rule4->action_index = args->action_index;
415 rv = mma_rules_table_add_rule_16 (srt4, rule4);
418 ri = mma_rules_table_rule_index_16 (srt4, rule4);
424 &args->lcl.fp_addr.ip4,
425 &args->rmt.fp_addr.ip4,
441 rule = mma_rules_table_get_rule_16 (srt4, ri_from_tag);
442 mma_rules_table_del_rule_16 (srt4, rule, srt4->root_index);
451 args->lcl_port, &args->rmt,
453 mma_rules_table_del_rule_16 (srt4, rule, srt4->root_index);
459 mma_rules_table_40_t *srt6;
460 mma_rule_40_t *rule6;
461 srt6 = &srt->session_rules_tables_40;
468 rule6->action_index = args->action_index;
469 rv = mma_rules_table_add_rule_40 (srt6, rule6);
472 ri = mma_rules_table_rule_index_40 (srt6, rule6);
478 &args->lcl.fp_addr.ip6,
479 &args->rmt.fp_addr.ip6,
495 rule = mma_rules_table_get_rule_40 (srt6, ri_from_tag);
496 mma_rules_table_del_rule_40 (srt6, rule, srt6->root_index);
505 args->lcl_port, &args->rmt,
507 mma_rules_table_del_rule_40 (srt6, rule, srt6->root_index);
512 return VNET_API_ERROR_INVALID_VALUE_2;
519 mma_rules_table_16_t *srt4;
520 mma_rules_table_40_t *srt6;
521 mma_rule_16_t *rule4;
522 mma_rule_40_t *rule6;
525 clib_memset (&null_prefix, 0,
sizeof (null_prefix));
527 srt4 = &srt->session_rules_tables_16;
531 srt4->root_index = mma_rules_table_rule_index_16 (srt4, rule4);
534 srt6 = &srt->session_rules_tables_40;
538 srt6->root_index = mma_rules_table_rule_index_40 (srt6, rule6);
547 ip46_address_t * lcl_ip,
u16 lcl_port,
548 ip46_address_t * rmt_ip,
u16 rmt_port,
551 mma_rules_table_16_t *srt4;
552 mma_rules_table_40_t *srt6;
560 session_mask_or_match_4_t
key = {
561 .lcl_ip.as_u32 = lcl_ip->ip4.as_u32,
562 .rmt_ip.as_u32 = rmt_ip->ip4.as_u32,
563 .lcl_port = lcl_port,
564 .rmt_port = rmt_port,
567 mma_rules_table_lookup_rule_16 (srt4,
568 (mma_mask_or_match_16_t *) &
key,
570 sr4 = mma_rules_table_get_rule_16 (srt4, ri);
576 session_mask_or_match_6_t
key = {
577 .lcl_port = lcl_port,
578 .rmt_port = rmt_port,
582 ri = mma_rules_table_lookup_rule_40 (srt6,
583 (mma_mask_or_match_40_t *) &
key,
585 sr6 = mma_rules_table_get_rule_40 (srt6, ri);
596 mma_rules_table_16_t *srt4;
598 srt4 = &srt->session_rules_tables_16;
610 mma_rules_table_40_t *srt6;
612 srt6 = &srt->session_rules_tables_40;