+uword
+unformat_stream_session_id (unformat_input_t * input, va_list * args)
+{
+ u8 *proto = va_arg (*args, u8 *);
+ ip46_address_t *lcl = va_arg (*args, ip46_address_t *);
+ ip46_address_t *rmt = va_arg (*args, ip46_address_t *);
+ u16 *lcl_port = va_arg (*args, u16 *);
+ u16 *rmt_port = va_arg (*args, u16 *);
+ u8 *is_ip4 = va_arg (*args, u8 *);
+ u8 tuple_is_set = 0;
+
+ memset (lcl, 0, sizeof (*lcl));
+ memset (rmt, 0, sizeof (*rmt));
+
+ if (unformat (input, "tcp"))
+ {
+ *proto = TRANSPORT_PROTO_TCP;
+ }
+ if (unformat (input, "udp"))
+ {
+ *proto = TRANSPORT_PROTO_UDP;
+ }
+ if (unformat (input, "%U:%d->%U:%d", unformat_ip4_address, &lcl->ip4,
+ lcl_port, unformat_ip4_address, &rmt->ip4, rmt_port))
+ {
+ *is_ip4 = 1;
+ tuple_is_set = 1;
+ }
+ else if (unformat (input, "%U:%d->%U:%d", unformat_ip6_address, &lcl->ip6,
+ lcl_port, unformat_ip6_address, &rmt->ip6, rmt_port))
+ {
+ *is_ip4 = 0;
+ tuple_is_set = 1;
+ }
+
+ return tuple_is_set;
+}
+
+uword
+unformat_stream_session (unformat_input_t * input, va_list * args)
+{
+ stream_session_t **result = va_arg (*args, stream_session_t **);
+ stream_session_t *s;
+ u8 proto = ~0;
+ ip46_address_t lcl, rmt;
+ u32 lcl_port = 0, rmt_port = 0, fib_index = 0;
+ u8 is_ip4 = 0;
+
+ if (!unformat (input, "%U", unformat_stream_session_id, &proto, &lcl, &rmt,
+ &lcl_port, &rmt_port, &is_ip4))
+ return 0;
+
+ if (is_ip4)
+ s = session_lookup_safe4 (fib_index, &lcl.ip4, &rmt.ip4,
+ clib_host_to_net_u16 (lcl_port),
+ clib_host_to_net_u16 (rmt_port), proto);
+ else
+ s = session_lookup_safe6 (fib_index, &lcl.ip6, &rmt.ip6,
+ clib_host_to_net_u16 (lcl_port),
+ clib_host_to_net_u16 (rmt_port), proto);
+ if (s)
+ {
+ *result = s;
+ session_pool_remove_peeker (s->thread_index);
+ return 1;
+ }
+ return 0;
+}
+
+uword
+unformat_transport_connection (unformat_input_t * input, va_list * args)
+{
+ transport_connection_t **result = va_arg (*args, transport_connection_t **);
+ u32 suggested_proto = va_arg (*args, u32);
+ transport_connection_t *tc;
+ u8 proto = ~0;
+ ip46_address_t lcl, rmt;
+ u32 lcl_port = 0, rmt_port = 0, fib_index = 0;
+ u8 is_ip4 = 0;
+
+ if (!unformat (input, "%U", unformat_stream_session_id, &proto, &lcl, &rmt,
+ &lcl_port, &rmt_port, &is_ip4))
+ return 0;
+
+ proto = (proto == (u8) ~ 0) ? suggested_proto : proto;
+ if (proto == (u8) ~ 0)
+ return 0;
+ if (is_ip4)
+ tc = session_lookup_connection4 (fib_index, &lcl.ip4, &rmt.ip4,
+ clib_host_to_net_u16 (lcl_port),
+ clib_host_to_net_u16 (rmt_port), proto);
+ else
+ tc = session_lookup_connection6 (fib_index, &lcl.ip6, &rmt.ip6,
+ clib_host_to_net_u16 (lcl_port),
+ clib_host_to_net_u16 (rmt_port), proto);
+
+ if (tc)
+ {
+ *result = tc;
+ return 1;
+ }
+ return 0;
+}
+