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,
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,
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;
603 vlib_cli_output (vm,
"%U", format_session_rule4, srt, sr4);
610 mma_rules_table_40_t *srt6;
612 srt6 = &srt->session_rules_tables_40;
617 vlib_cli_output (vm,
"%U", format_session_rule6, srt, sr6);
fib_protocol_t fp_proto
protocol type
void session_rules_table_add_tag(session_rules_table_t *srt, u8 *tag, u32 rule_index, u8 is_ip4)
mma_rule_40_t * session_rules_table_alloc_rule_40(mma_rules_table_40_t *srt, fib_prefix_t *lcl, u16 lcl_port, fib_prefix_t *rmt, u16 rmt_port)
void session_rules_table_init(session_rules_table_t *srt)
void ip6_preflen_to_mask(u8 pref_len, ip6_address_t *mask)
#define hash_set(h, key, value)
void ip4_preflen_to_mask(u8 pref_len, ip4_address_t *ip)
void session_rules_table_cli_dump(vlib_main_t *vm, session_rules_table_t *srt, u8 fib_proto)
#define hash_unset(h, key)
struct _session_rules_table_t session_rules_table_t
int rule_cmp_16(mma_rule_16_t *rule1, mma_rule_16_t *rule2)
#define clib_memcpy_fast(a, b, c)
u8 * session_rules_table_rule_tag(session_rules_table_t *srt, u32 ri, u8 is_ip4)
static void fib_pref_normalize(fib_prefix_t *pref)
#define hash_set_mem(h, key, value)
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
u32 session_rules_table_lookup4(session_rules_table_t *srt, ip4_address_t *lcl_ip, ip4_address_t *rmt_ip, u16 lcl_port, u16 rmt_port)
mma_rule_16_t * session_rules_table_alloc_rule_16(mma_rules_table_16_t *srt, fib_prefix_t *lcl, u16 lcl_port, fib_prefix_t *rmt, u16 rmt_port)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
u32 session_rules_table_rule_for_tag(session_rules_table_t *srt, u8 *tag)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
void * session_rules_table_get(session_rules_table_t *srt, u8 fib_proto)
void ip6_prefix_max_address_host_order(ip6_address_t *ip, u8 plen, ip6_address_t *res)
void ip4_address_normalize(ip4_address_t *ip4, u8 preflen)
Aggregrate type for a prefix.
void session_rules_table_init_rule_16(mma_rule_16_t *rule, fib_prefix_t *lcl, u16 lcl_port, fib_prefix_t *rmt, u16 rmt_port)
u16 fp_len
The mask length.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
#define hash_unset_mem(h, key)
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
struct _rule_tag session_rule_tag_t
void ip6_address_normalize(ip6_address_t *ip6, u8 preflen)
#define pool_put(P, E)
Free an object E in pool P.
#define vec_dup(V)
Return copy of vector (no header, no alignment)
u32 session_rules_table_lookup_rule4(session_rules_table_t *srt, ip4_address_t *lcl_ip, ip4_address_t *rmt_ip, u16 lcl_port, u16 rmt_port)
int rule_cmp_40(mma_rule_40_t *rule1, mma_rule_40_t *rule2)
u32 ip6_mask_to_preflen(ip6_address_t *mask)
u32 session_rules_table_lookup6(session_rules_table_t *srt, ip6_address_t *lcl_ip, ip6_address_t *rmt_ip, u16 lcl_port, u16 rmt_port)
void session_rule_tag_key_index_parse(u32 rti_key, u32 *ri, u8 *is_ip4)
u8 * format_session_rule6(u8 *s, va_list *args)
#define SESSION_RULES_TABLE_INVALID_INDEX
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
u32 ip4_mask_to_preflen(ip4_address_t *mask)
u8 * format_session_rule4(u8 *s, va_list *args)
#define hash_create(elts, value_bytes)
u32 session_rule_tag_key_index(u32 ri, u8 is_ip4)
u32 session_rules_table_lookup_rule6(session_rules_table_t *srt, ip6_address_t *lcl_ip, ip6_address_t *rmt_ip, u16 lcl_port, u16 rmt_port)
void session_rules_table_show_rule(vlib_main_t *vm, session_rules_table_t *srt, ip46_address_t *lcl_ip, u16 lcl_port, ip46_address_t *rmt_ip, u16 rmt_port, u8 is_ip4)
#define hash_create_vec(elts, key_bytes, value_bytes)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void ip4_prefix_max_address_host_order(ip4_address_t *ip, u8 plen, ip4_address_t *res)
#define hash_get_mem(h, key)
struct _session_rules_table_add_del_args session_rule_table_add_del_args_t
int session_rules_table_add_del(session_rules_table_t *srt, session_rule_table_add_del_args_t *args)
Add/delete session rule.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
void session_rules_table_init_rule_40(mma_rule_40_t *rule, fib_prefix_t *lcl, u16 lcl_port, fib_prefix_t *rmt, u16 rmt_port)
void session_rules_table_del_tag(session_rules_table_t *srt, u8 *tag, u8 is_ip4)