22 #undef __included_bihash_template_h__ 62 }) v4_connection_key_t;
87 u16 lcl_port,
u16 rmt_port,
u8 proto)
90 kv->
key[1] = (
u64) proto << 32 | (
u64) rmt_port << 16 | (
u64) lcl_port;
99 kv->
key[1] = (
u64) proto << 32 | (
u64) lcl_port;
107 kv->
key[1] = (
u64) proto << 32;
114 make_v4_ss_kv (kv, &tc->lcl_ip.ip4, &tc->rmt_ip.ip4, tc->lcl_port,
115 tc->rmt_port, tc->proto);
120 u16 lcl_port,
u16 rmt_port,
u8 proto)
126 kv->
key[4] = (
u64) proto << 32 | (
u64) rmt_port << 16 | (
u64) lcl_port;
139 kv->
key[4] = (
u64) proto << 32 | (
u64) lcl_port;
151 kv->
key[4] = (
u64) proto << 32;
159 make_v6_ss_kv (kv, &tc->lcl_ip.ip6, &tc->rmt_ip.ip6, tc->lcl_port,
160 tc->rmt_port, tc->proto);
168 if (
vec_len (fib_index_to_table_index[fib_proto]) <= fib_index)
172 vec_validate (fib_index_to_table_index[fib_proto], fib_index);
173 fib_index_to_table_index[fib_proto][fib_index] = table_index;
174 st->active_fib_proto = fib_proto;
180 table_index = fib_index_to_table_index[fib_proto][fib_index];
197 if (
vec_len (fib_index_to_table_index[fib_proto]) <= tc->fib_index)
206 if (
vec_len (fib_index_to_table_index[fib_proto]) <= fib_index)
214 if (
vec_len (fib_index_to_table_index[fib_proto]) <= fib_index)
216 return fib_index_to_table_index[fib_proto][fib_index];
244 return clib_bihash_add_del_16_8 (&st->v4_session_hash, &kv4,
251 return clib_bihash_add_del_48_8 (&st->v6_session_hash, &kv6,
270 sep->transport_proto);
272 return clib_bihash_add_del_16_8 (&st->v4_session_hash, &kv4, 1);
277 sep->transport_proto);
279 return clib_bihash_add_del_48_8 (&st->v6_session_hash, &kv6, 1);
297 sep->transport_proto);
298 return clib_bihash_add_del_16_8 (&st->v4_session_hash, &kv4, 0);
303 sep->transport_proto);
304 return clib_bihash_add_del_48_8 (&st->v6_session_hash, &kv6, 0);
329 return clib_bihash_add_del_16_8 (&st->v4_session_hash, &kv4,
335 return clib_bihash_add_del_48_8 (&st->v6_session_hash, &kv6,
345 ts = tp_vfts[tp].get_connection (s->connection_index, s->thread_index);
361 switch (action_index)
384 fib_proto, transport_proto);
405 u32 action_index, app_index;
421 u32 action_index, app_index;
457 sep->transport_proto);
458 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
464 srt = &st->session_rules[sep->transport_proto];
477 sep->transport_proto);
478 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
485 srt = &st->session_rules[sep->transport_proto];
533 srt = &st->session_rules[sep->transport_proto];
543 sep->transport_proto);
544 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
555 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
568 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
578 srt = &st->session_rules[sep->transport_proto];
585 sep->transport_proto);
586 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
596 kv6.
key[0] = kv6.
key[1] = 0;
597 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
603 kv6.
key[0] = kv6.
key[1] = 0;
609 kv6.
key[4] = kv6.
key[5] = 0;
610 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
619 u16 lcl_port,
u8 proto,
u8 use_wildcard)
628 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
638 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
651 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
671 u16 lcl_port,
u8 proto,
u8 ip_wildcard)
677 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
684 kv6.
key[0] = kv6.
key[1] = 0;
685 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
691 kv6.
key[0] = kv6.
key[1] = 0;
695 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
724 sep->transport_proto, 0);
727 sep->transport_proto, 0);
745 return clib_bihash_add_del_16_8 (&st->v4_half_open_hash, &kv4,
752 return clib_bihash_add_del_48_8 (&st->v6_half_open_hash, &kv6,
770 return clib_bihash_add_del_16_8 (&st->v4_half_open_hash, &kv4,
776 return clib_bihash_add_del_48_8 (&st->v6_half_open_hash, &kv6,
795 make_v4_ss_kv (&kv4, &tc->lcl_ip.ip4, &tc->rmt_ip.ip4, tc->lcl_port,
796 tc->rmt_port, tc->proto);
797 rv = clib_bihash_search_inline_16_8 (&st->v4_half_open_hash, &kv4);
803 make_v6_ss_kv (&kv6, &tc->lcl_ip.ip6, &tc->rmt_ip.ip6, tc->lcl_port,
804 tc->rmt_port, tc->proto);
805 rv = clib_bihash_search_inline_48_8 (&st->v6_half_open_hash, &kv6);
820 return tp_vfts[sst].get_half_open (handle & 0xFFFFFFFF);
854 u16 rmt_port,
u8 proto,
u32 thread_index,
871 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
880 return tp_vfts[proto].get_connection (s->connection_index,
887 rv = clib_bihash_search_inline_16_8 (&st->v4_half_open_hash, &kv4);
889 return tp_vfts[proto].get_half_open (kv4.
value & 0xFFFFFFFF);
895 rmt, lcl_port, rmt_port);
905 return tp_vfts[proto].get_listener (s->connection_index);
914 return tp_vfts[proto].get_listener (s->connection_index);
953 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
957 return tp_vfts[proto].get_connection (s->connection_index,
964 rv = clib_bihash_search_inline_16_8 (&st->v4_half_open_hash, &kv4);
966 return tp_vfts[proto].get_half_open (kv4.
value & 0xFFFFFFFF);
972 rmt, lcl_port, rmt_port);
979 return tp_vfts[proto].get_listener (s->connection_index);
988 return tp_vfts[proto].get_listener (s->connection_index);
1008 u16 lcl_port,
u16 rmt_port,
u8 proto)
1024 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
1032 rmt, lcl_port, rmt_port);
1078 u16 rmt_port,
u8 proto,
u32 thread_index,
1092 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
1102 return tp_vfts[proto].get_connection (s->connection_index,
1107 rv = clib_bihash_search_inline_48_8 (&st->v6_half_open_hash, &kv6);
1109 return tp_vfts[proto].get_half_open (kv6.
value & 0xFFFFFFFF);
1113 rmt, lcl_port, rmt_port);
1123 return tp_vfts[proto].get_listener (s->connection_index);
1130 return tp_vfts[proto].get_listener (s->connection_index);
1167 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
1171 return tp_vfts[proto].get_connection (s->connection_index,
1176 rv = clib_bihash_search_inline_48_8 (&st->v6_half_open_hash, &kv6);
1178 return tp_vfts[proto].get_half_open (kv6.
value & 0xFFFFFFFF);
1182 rmt, lcl_port, rmt_port);
1189 return tp_vfts[proto].get_listener (s->connection_index);
1196 return tp_vfts[proto].get_listener (s->connection_index);
1216 u16 lcl_port,
u16 rmt_port,
u8 proto)
1229 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
1235 rmt, lcl_port, rmt_port);
1263 if (args->scope > 3)
1269 "invalid transport proto");
1272 fib_proto = args->table_args.rmt.fp_proto;
1275 srt = &st->session_rules[args->transport_proto];
1284 clib_memset (&args->table_args.lcl, 0, sizeof (args->table_args.lcl));
1285 args->table_args.lcl.fp_proto = args->table_args.rmt.fp_proto;
1286 args->table_args.lcl_port = 0;
1288 srt = &st->session_rules[args->transport_proto];
1304 for (fp = 0; fp <
ARRAY_LEN (fib_index_to_table_index); fp++)
1317 u32 is_local = va_arg (*args,
u32), app_wrk_index, session_index;
1318 v4_connection_key_t *key = (v4_connection_key_t *) kvp->
key;
1332 &key->dst, clib_net_to_host_u16 (key->dst_port));
1333 s =
format (s,
"%-40v%-30v", str, app_name);
1342 clib_net_to_host_u16 (key->src_port));
1343 s =
format (s,
"%-30v%-30v", str, app_name);
1348 typedef struct _ip4_session_table_show_ctx_t
1365 u8 type,
u8 is_local)
1369 .is_local = is_local,
1391 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen = 0, rmt_plen = 0;
1392 u32 appns_index, scope = 0;
1393 ip46_address_t lcl_ip, rmt_ip;
1394 u8 is_ip4 = 1, conn_set = 0;
1395 u8 fib_proto, is_add = 1, *ns_id = 0;
1408 else if (
unformat (input,
"appns %_%v%_", &ns_id))
1410 else if (
unformat (input,
"scope global"))
1412 else if (
unformat (input,
"scope local"))
1414 else if (
unformat (input,
"scope all"))
1419 &lcl_ip.ip4, &lcl_plen, &lcl_port,
1427 &lcl_ip.ip6, &lcl_plen, &lcl_port,
1434 else if (
unformat (input,
"action %d", &action))
1436 else if (
unformat (input,
"tag %_%v%_", &tag))
1448 if (is_add && !conn_set && action == ~0)
1453 if (!is_add && !tag && !conn_set)
1481 .table_args.lcl.fp_addr = lcl_ip,
1482 .table_args.lcl.fp_len = lcl_plen,
1483 .table_args.lcl.fp_proto = fib_proto,
1484 .table_args.rmt.fp_addr = rmt_ip,
1485 .table_args.rmt.fp_len = rmt_plen,
1486 .table_args.rmt.fp_proto = fib_proto,
1487 .table_args.lcl_port = lcl_port,
1488 .table_args.rmt_port = rmt_port,
1489 .table_args.action_index = action,
1490 .table_args.is_add = is_add,
1491 .table_args.tag = tag,
1492 .appns_index = appns_index,
1503 .path =
"session rule",
1504 .short_help =
"session rule [add|del] appns <ns_id> proto <proto> " 1505 "<lcl-ip/plen> <lcl-port> <rmt-ip/plen> <rmt-port> action <action>",
1518 srt = &st->session_rules[transport_proto];
1530 srt = &st->session_rules[transport_proto];
1538 u32 transport_proto = ~0, lcl_port, rmt_port, lcl_plen, rmt_plen;
1539 u32 fib_index, scope = 0;
1540 ip46_address_t lcl_ip, rmt_ip;
1541 u8 is_ip4 = 1, show_one = 0;
1545 u8 *ns_id = 0, fib_proto;
1553 else if (
unformat (input,
"appns %_%v%_", &ns_id))
1555 else if (
unformat (input,
"scope global"))
1557 else if (
unformat (input,
"scope local"))
1560 &lcl_ip.ip4, &lcl_plen, &lcl_port,
1568 &lcl_ip.ip6, &lcl_plen, &lcl_port,
1580 if (transport_proto == ~0)
1600 if (scope == 1 || scope == 0)
1603 fib_index = is_ip4 ? app_ns->ip4_fib_index : app_ns->ip6_fib_index;
1613 srt = &st->session_rules[transport_proto];
1621 srt = &st->session_rules[transport_proto];
1632 .path =
"show session rules",
1633 .short_help =
"show session rules [<proto> appns <id> <lcl-ip/plen> " 1634 "<lcl-port> <rmt-ip/plen> <rmt-port> scope <scope>]",
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
#define SESSION_DROP_HANDLE
app_worker_t * app_worker_get(u32 wrk_index)
stream_session_t * session_lookup_listener6(u32 fib_index, ip6_address_t *lcl, u16 lcl_port, u8 proto)
int session_lookup_del_connection(transport_connection_t *tc)
Delete transport connection from session table.
static session_table_t * session_table_get_or_alloc_for_connection(transport_connection_t *tc)
session_table_t * session_table_alloc(void)
void session_lookup_show_table_entries(vlib_main_t *vm, session_table_t *table, u8 type, u8 is_local)
#define SESSION_RULES_TABLE_ACTION_DROP
u8 * format_transport_proto_short(u8 *s, va_list *args)
clib_bihash_kv_48_8_t session_kv6_t
void session_rules_table_cli_dump(vlib_main_t *vm, session_rules_table_t *srt, u8 fib_proto)
#define SESSION_TABLE_INVALID_INDEX
u64 session_lookup_endpoint_listener(u32 table_index, session_endpoint_t *sep, u8 use_rules)
Lookup listener for session endpoint in table.
static clib_error_t * session_rule_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static session_table_t * session_table_get_for_fib_index(u32 fib_proto, u32 fib_index)
struct _session_rules_table_t session_rules_table_t
transport_connection_t * session_lookup_connection_wt6(u32 fib_index, ip6_address_t *lcl, ip6_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto, u32 thread_index, u8 *result)
Lookup connection with ip6 and transport layer information.
struct _transport_connection transport_connection_t
clib_error_t * session_rules_table_add_del(session_rules_table_t *srt, session_rule_table_add_del_args_t *args)
Add/delete session rule.
static u8 session_lookup_action_index_is_valid(u32 action_index)
u32 app_namespace_index(app_namespace_t *app_ns)
stream_session_t * session_lookup_rules_table_session4(session_table_t *st, u8 proto, ip4_address_t *lcl, u16 lcl_port, ip4_address_t *rmt, u16 rmt_port)
UNUSED.
stream_session_t * session_lookup_listener4(u32 fib_index, ip4_address_t *lcl, u16 lcl_port, u8 proto)
void session_lookup_set_tables_appns(app_namespace_t *app_ns)
Mark (global) tables as pertaining to app ns.
static clib_error_t * show_session_rules_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u32 session_lookup_get_index_for_fib(u32 fib_proto, u32 fib_index)
struct _transport_proto_vft transport_proto_vft_t
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
int session_lookup_del_session(stream_session_t *s)
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)
static void make_v6_listener_kv(session_kv6_t *kv, ip6_address_t *lcl, u16 lcl_port, u8 proto)
static stream_session_t * session_get_from_handle(session_handle_t handle)
u64 session_lookup_half_open_handle(transport_connection_t *tc)
static void make_v6_ss_kv_from_tc(session_kv6_t *kv, transport_connection_t *tc)
stream_session_t * session_lookup_listener(u32 table_index, session_endpoint_t *sep)
Lookup listener, exact or proxy (inaddr_any:0) match.
static stream_session_t * session_lookup_listener6_i(session_table_t *st, ip6_address_t *lcl, u16 lcl_port, u8 proto, u8 ip_wildcard)
application_t * application_get_if_valid(u32 app_index)
transport_connection_t * session_lookup_connection6(u32 fib_index, ip6_address_t *lcl, ip6_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto)
Lookup connection with ip6 and transport layer information.
#define SESSION_INVALID_INDEX
clib_error_t * vnet_session_rule_add_del(session_rule_add_del_args_t *args)
transport_connection_t * session_lookup_connection_wt4(u32 fib_index, ip4_address_t *lcl, ip4_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto, u32 thread_index, u8 *result)
Lookup connection with ip4 and transport layer information.
transport_proto_vft_t * tp_vfts
Generate typed init functions for multiple hash table styles...
static void make_v6_ss_kv(session_kv6_t *kv, ip6_address_t *lcl, ip6_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto)
static stream_session_t * listen_session_get(u32 index)
#define clib_error_return(e, args...)
static int ip4_session_table_show(clib_bihash_kv_16_8_t *kvp, void *arg)
static void make_v6_proxy_kv(session_kv6_t *kv, ip6_address_t *lcl, u8 proto)
struct _stream_session_t stream_session_t
int session_lookup_del_half_open(transport_connection_t *tc)
transport_connection_t * session_lookup_connection4(u32 fib_index, ip4_address_t *lcl, ip4_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto)
Lookup connection with ip4 and transport layer information.
static transport_proto_t session_get_transport_proto(stream_session_t *s)
void session_table_init(session_table_t *slt, u8 fib_proto)
Initialize session table hash tables.
u32 app_namespace_get_fib_index(app_namespace_t *app_ns, u8 fib_proto)
struct _session_endpoint session_endpoint_t
struct _session_rule_add_del_args session_rule_add_del_args_t
void session_lookup_dump_rules_table(u32 fib_index, u8 fib_proto, u8 transport_proto)
const u8 * application_name_from_index(u32 app_index)
Returns app name for app-index.
static app_namespace_t * app_namespace_get_default(void)
stream_session_t * session_lookup_safe6(u32 fib_index, ip6_address_t *lcl, ip6_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto)
Lookup session with ip6 and transport layer information.
app_namespace_t * app_namespace_get(u32 index)
stream_session_t * app_worker_first_listener(app_worker_t *app, u8 fib_proto, u8 transport_proto)
static stream_session_t * session_get(u32 si, u32 thread_index)
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)
u64 session_lookup_local_endpoint(u32 table_index, session_endpoint_t *sep)
Look up endpoint in local session table.
static session_table_t * session_table_get_for_connection(transport_connection_t *tc)
static stream_session_t * session_lookup_listener4_i(session_table_t *st, ip4_address_t *lcl, u16 lcl_port, u8 proto, u8 use_wildcard)
static session_type_t session_type_from_proto_and_ip(transport_proto_t proto, u8 is_ip4)
static u32 * fib_index_to_table_index[2]
Network namespace index (i.e., fib index) to session lookup table.
#define SESSION_RULES_TABLE_INVALID_INDEX
session_table_t * app_namespace_get_local_table(app_namespace_t *app_ns)
#define vec_free(V)
Free vector's memory (no header).
int session_lookup_del_session_endpoint(u32 table_index, session_endpoint_t *sep)
static stream_session_t * session_get_from_handle_safe(u64 handle)
Get session from handle and 'lock' pool resize if not in same thread.
#define clib_warning(format, args...)
stream_session_t * session_lookup_safe4(u32 fib_index, ip4_address_t *lcl, ip4_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto)
Lookup session with ip4 and transport layer information.
#define SESSION_INVALID_HANDLE
u8 ip4_is_local_host(ip4_address_t *ip4_address)
static u8 transport_connection_fib_proto(transport_connection_t *tc)
u8 ip6_is_local_host(ip6_address_t *ip6_address)
int session_lookup_add_session_endpoint(u32 table_index, session_endpoint_t *sep, u64 value)
struct _app_namespace app_namespace_t
#define VLIB_CLI_COMMAND(x,...)
session_table_t * session_table_get(u32 table_index)
static void make_v4_proxy_kv(session_kv4_t *kv, ip4_address_t *lcl, u8 proto)
struct _ip4_session_table_show_ctx_t ip4_session_table_show_ctx_t
static stream_session_t * session_lookup_action_to_session(u32 action_index, u8 fib_proto, u8 transport_proto)
uword unformat_transport_proto(unformat_input_t *input, va_list *args)
static stream_session_t * session_lookup_app_listen_session(u32 app_index, u8 fib_proto, u8 transport_proto)
static u64 session_lookup_action_to_handle(u32 action_index)
void ip4_session_table_walk(clib_bihash_16_8_t *hash, ip4_session_table_walk_fn_t fn, void *arg)
#define clib_error_report(e)
#define SESSION_RULES_TABLE_ACTION_ALLOW
typedef CLIB_PACKED(struct{union{struct{ip4_address_t src;ip4_address_t dst;u16 src_port;u16 dst_port;u32 proto;};u64 as_u64[2];};})
static void make_v4_listener_kv(session_kv4_t *kv, ip4_address_t *lcl, u16 lcl_port, u8 proto)
static vlib_main_t * vlib_get_main(void)
#define HALF_OPEN_LOOKUP_INVALID_VALUE
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)
u8 * format_ip4_session_lookup_kvp(u8 *s, va_list *args)
#define SESSION_RULE_TAG_MAX_LEN
enum _transport_proto transport_proto_t
void session_lookup_init(void)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void session_lookup_dump_local_rules_table(u32 table_index, u8 fib_proto, u8 transport_proto)
app_worker_t * application_get_default_worker(application_t *app)
struct _session_lookup_table session_table_t
static session_table_t * session_table_get_or_alloc(u8 fib_proto, u8 fib_index)
int session_lookup_add_connection(transport_connection_t *tc, u64 value)
Add transport connection to a session table.
u32 session_table_index(session_table_t *slt)
#define clib_error_return_code(e, code, flags, args...)
static void make_v4_ss_kv(session_kv4_t *kv, ip4_address_t *lcl, ip4_address_t *rmt, u16 lcl_port, u16 rmt_port, u8 proto)
app_namespace_t * app_namespace_get_from_id(const u8 *ns_id)
int session_lookup_add_half_open(transport_connection_t *tc, u64 value)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
stream_session_t * session_lookup_rules_table_session6(session_table_t *st, u8 proto, ip6_address_t *lcl, u16 lcl_port, ip6_address_t *rmt, u16 rmt_port)
UNUSED.
u8 * format_transport_proto(u8 *s, va_list *args)
static void make_v4_ss_kv_from_tc(session_kv4_t *kv, transport_connection_t *tc)
transport_connection_t * session_lookup_half_open_connection(u64 handle, u8 proto, u8 is_ip4)
static void local_session_parse_handle(session_handle_t handle, u32 *app_or_wrk_index, u32 *session_index)
clib_bihash_kv_16_8_t session_kv4_t