2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 /** Generate typed init functions for multiple hash table styles... */
17 #include <vppinfra/bihash_16_8.h>
18 #include <vppinfra/bihash_template.h>
20 #include <vppinfra/bihash_template.c>
22 #undef __included_bihash_template_h__
24 #include <vppinfra/bihash_48_8.h>
25 #include <vppinfra/bihash_template.h>
27 #include <vppinfra/bihash_template.c>
28 #include <vnet/session/session_lookup.h>
29 #include <vnet/session/session.h>
30 #include <vnet/session/application.h>
33 * External vector of per transport virtual functions table
35 extern transport_proto_vft_t *tp_vfts;
38 * Network namespace index (i.e., fib index) to session lookup table. We
39 * should have one per network protocol type but for now we only support IP4/6
41 static u32 *fib_index_to_table_index[2];
45 typedef CLIB_PACKED (struct {
54 /* align by making this 4 octets even though its a 1-bit field
55 * NOTE: avoid key overlap with other transports that use 5 tuples for
56 * session identification.
62 }) v4_connection_key_t;
64 typedef CLIB_PACKED (struct {
79 }) v6_connection_key_t;
82 typedef clib_bihash_kv_16_8_t session_kv4_t;
83 typedef clib_bihash_kv_48_8_t session_kv6_t;
86 make_v4_ss_kv (session_kv4_t * kv, ip4_address_t * lcl, ip4_address_t * rmt,
87 u16 lcl_port, u16 rmt_port, u8 proto)
89 v4_connection_key_t *key = (v4_connection_key_t *) kv->key;
91 key->src.as_u32 = lcl->as_u32;
92 key->dst.as_u32 = rmt->as_u32;
93 key->src_port = lcl_port;
94 key->dst_port = rmt_port;
101 make_v4_listener_kv (session_kv4_t * kv, ip4_address_t * lcl, u16 lcl_port,
104 v4_connection_key_t *key = (v4_connection_key_t *) kv->key;
106 key->src.as_u32 = lcl->as_u32;
108 key->src_port = lcl_port;
116 make_v4_ss_kv_from_tc (session_kv4_t * kv, transport_connection_t * t)
118 make_v4_ss_kv (kv, &t->lcl_ip.ip4, &t->rmt_ip.ip4, t->lcl_port, t->rmt_port,
119 session_type_from_proto_and_ip (t->proto, 1));
123 make_v6_ss_kv (session_kv6_t * kv, ip6_address_t * lcl, ip6_address_t * rmt,
124 u16 lcl_port, u16 rmt_port, u8 proto)
126 v6_connection_key_t *key = (v6_connection_key_t *) kv->key;
128 key->src.as_u64[0] = lcl->as_u64[0];
129 key->src.as_u64[1] = lcl->as_u64[1];
130 key->dst.as_u64[0] = rmt->as_u64[0];
131 key->dst.as_u64[1] = rmt->as_u64[1];
132 key->src_port = lcl_port;
133 key->dst_port = rmt_port;
141 make_v6_listener_kv (session_kv6_t * kv, ip6_address_t * lcl, u16 lcl_port,
144 v6_connection_key_t *key = (v6_connection_key_t *) kv->key;
146 key->src.as_u64[0] = lcl->as_u64[0];
147 key->src.as_u64[1] = lcl->as_u64[1];
148 key->dst.as_u64[0] = 0;
149 key->dst.as_u64[1] = 0;
150 key->src_port = lcl_port;
159 make_v6_ss_kv_from_tc (session_kv6_t * kv, transport_connection_t * t)
161 make_v6_ss_kv (kv, &t->lcl_ip.ip6, &t->rmt_ip.ip6, t->lcl_port, t->rmt_port,
162 session_type_from_proto_and_ip (t->proto, 0));
166 static session_table_t *
167 session_table_get_or_alloc_for_connection (transport_connection_t * tc)
170 u32 table_index, fib_proto = transport_connection_fib_proto (tc);
171 if (vec_len (fib_index_to_table_index[fib_proto]) <= tc->fib_index)
173 st = session_table_alloc ();
174 table_index = session_table_index (st);
175 vec_validate (fib_index_to_table_index[fib_proto], tc->fib_index);
176 fib_index_to_table_index[fib_proto][tc->fib_index] = table_index;
181 table_index = fib_index_to_table_index[fib_proto][tc->fib_index];
182 return session_table_get (table_index);
186 static session_table_t *
187 session_table_get_for_connection (transport_connection_t * tc)
189 u32 fib_proto = transport_connection_fib_proto (tc);
190 if (vec_len (fib_index_to_table_index[fib_proto]) <= tc->fib_index)
193 session_table_get (fib_index_to_table_index[fib_proto][tc->fib_index]);
196 static session_table_t *
197 session_table_get_for_fib_index (u32 fib_proto, u32 fib_index)
199 if (vec_len (fib_index_to_table_index[fib_proto]) <= fib_index)
201 return session_table_get (fib_index_to_table_index[fib_proto][fib_index]);
205 session_lookup_get_index_for_fib (u32 fib_proto, u32 fib_index)
207 if (vec_len (fib_index_to_table_index[fib_proto]) <= fib_index)
208 return SESSION_TABLE_INVALID_INDEX;
209 return fib_index_to_table_index[fib_proto][fib_index];
213 * Add transport connection to a session table
215 * Session lookup 5-tuple (src-ip, dst-ip, src-port, dst-port, session-type)
216 * is added to requested session table.
218 * @param tc transport connection to be added
219 * @param value value to be stored
221 * @return non-zero if failure
224 session_lookup_add_connection (transport_connection_t * tc, u64 value)
230 st = session_table_get_or_alloc_for_connection (tc);
235 make_v4_ss_kv_from_tc (&kv4, tc);
237 return clib_bihash_add_del_16_8 (&st->v4_session_hash, &kv4,
242 make_v6_ss_kv_from_tc (&kv6, tc);
244 return clib_bihash_add_del_48_8 (&st->v6_session_hash, &kv6,
250 session_lookup_add_session_endpoint (u32 table_index,
251 session_endpoint_t * sep, u64 value)
257 st = session_table_get (table_index);
262 make_v4_listener_kv (&kv4, &sep->ip.ip4, sep->port,
263 sep->transport_proto);
265 return clib_bihash_add_del_16_8 (&st->v4_session_hash, &kv4, 1);
269 make_v6_listener_kv (&kv6, &sep->ip.ip6, sep->port,
270 sep->transport_proto);
272 return clib_bihash_add_del_48_8 (&st->v6_session_hash, &kv6, 1);
277 session_lookup_del_session_endpoint (u32 table_index,
278 session_endpoint_t * sep)
284 st = session_table_get (table_index);
289 make_v4_listener_kv (&kv4, &sep->ip.ip4, sep->port,
290 sep->transport_proto);
291 return clib_bihash_add_del_16_8 (&st->v4_session_hash, &kv4, 0);
295 make_v6_listener_kv (&kv6, &sep->ip.ip6, sep->port,
296 sep->transport_proto);
297 return clib_bihash_add_del_48_8 (&st->v6_session_hash, &kv6, 0);
302 * Delete transport connection from session table
304 * @param table_index session table index
305 * @param tc transport connection to be removed
307 * @return non-zero if failure
310 session_lookup_del_connection (transport_connection_t * tc)
316 st = session_table_get_for_connection (tc);
321 make_v4_ss_kv_from_tc (&kv4, tc);
322 return clib_bihash_add_del_16_8 (&st->v4_session_hash, &kv4,
327 make_v6_ss_kv_from_tc (&kv6, tc);
328 return clib_bihash_add_del_48_8 (&st->v6_session_hash, &kv6,
334 session_lookup_del_session (stream_session_t * s)
336 transport_connection_t *ts;
337 ts = tp_vfts[s->session_type].get_connection (s->connection_index,
339 return session_lookup_del_connection (ts);
343 session_lookup_session_endpoint (u32 table_index, session_endpoint_t * sep)
350 st = session_table_get (table_index);
352 return SESSION_INVALID_HANDLE;
355 make_v4_listener_kv (&kv4, &sep->ip.ip4, sep->port,
356 sep->transport_proto);
357 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
363 make_v6_listener_kv (&kv6, &sep->ip.ip6, sep->port,
364 sep->transport_proto);
365 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
369 return SESSION_INVALID_HANDLE;
373 session_lookup_global_session_endpoint (session_endpoint_t * sep)
382 fib_proto = session_endpoint_fib_proto (sep);
383 table_index = session_lookup_get_index_for_fib (fib_proto, sep->fib_index);
384 st = session_table_get (table_index);
389 make_v4_listener_kv (&kv4, &sep->ip.ip4, sep->port,
390 sep->transport_proto);
391 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
393 return session_get_from_handle (kv4.value);
397 make_v6_listener_kv (&kv6, &sep->ip.ip6, sep->port,
398 sep->transport_proto);
399 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
401 return session_get_from_handle (kv6.value);
407 session_lookup_local_session_endpoint (u32 table_index,
408 session_endpoint_t * sep)
415 st = session_table_get (table_index);
417 return SESSION_INVALID_INDEX;
420 make_v4_listener_kv (&kv4, &sep->ip.ip4, sep->port,
421 sep->transport_proto);
422 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
424 return (u32) kv4.value;
427 * Zero out the ip. Logic is that connect to local ips, say
428 * 127.0.0.1:port, can match 0.0.0.0:port
431 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
433 return (u32) kv4.value;
437 make_v6_listener_kv (&kv6, &sep->ip.ip6, sep->port,
438 sep->transport_proto);
439 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
441 return (u32) kv6.value;
444 * Zero out the ip. Same logic as above.
446 kv6.key[0] = kv6.key[1] = 0;
447 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
449 return (u32) kv6.value;
451 return SESSION_INVALID_INDEX;
454 static stream_session_t *
455 session_lookup_listener4_i (session_table_t * st, ip4_address_t * lcl,
456 u16 lcl_port, u8 proto)
461 make_v4_listener_kv (&kv4, lcl, lcl_port, proto);
462 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
464 return session_manager_get_listener (proto, (u32) kv4.value);
466 /* Zero out the lcl ip */
468 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
470 return session_manager_get_listener (proto, (u32) kv4.value);
476 session_lookup_listener4 (u32 fib_index, ip4_address_t * lcl, u16 lcl_port,
480 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP4, fib_index);
483 return session_lookup_listener4_i (st, lcl, lcl_port, proto);
486 static stream_session_t *
487 session_lookup_listener6_i (session_table_t * st, ip6_address_t * lcl,
488 u16 lcl_port, u8 proto)
493 make_v6_listener_kv (&kv6, lcl, lcl_port, proto);
494 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
496 return session_manager_get_listener (proto, (u32) kv6.value);
498 /* Zero out the lcl ip */
499 kv6.key[0] = kv6.key[1] = 0;
500 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
502 return session_manager_get_listener (proto, (u32) kv6.value);
508 session_lookup_listener6 (u32 fib_index, ip6_address_t * lcl, u16 lcl_port,
512 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP6, fib_index);
515 return session_lookup_listener6_i (st, lcl, lcl_port, proto);
519 session_lookup_listener (u32 table_index, session_endpoint_t * sep)
522 st = session_table_get (table_index);
526 return session_lookup_listener4_i (st, &sep->ip.ip4, sep->port,
527 sep->transport_proto);
529 return session_lookup_listener6_i (st, &sep->ip.ip6, sep->port,
530 sep->transport_proto);
535 session_lookup_add_half_open (transport_connection_t * tc, u64 value)
541 st = session_table_get_or_alloc_for_connection (tc);
546 make_v4_ss_kv_from_tc (&kv4, tc);
548 return clib_bihash_add_del_16_8 (&st->v4_half_open_hash, &kv4,
553 make_v6_ss_kv_from_tc (&kv6, tc);
555 return clib_bihash_add_del_48_8 (&st->v6_half_open_hash, &kv6,
561 session_lookup_del_half_open (transport_connection_t * tc)
567 st = session_table_get_for_connection (tc);
572 make_v4_ss_kv_from_tc (&kv4, tc);
573 return clib_bihash_add_del_16_8 (&st->v4_half_open_hash, &kv4,
578 make_v6_ss_kv_from_tc (&kv6, tc);
579 return clib_bihash_add_del_48_8 (&st->v6_half_open_hash, &kv6,
585 session_lookup_half_open_handle (transport_connection_t * tc)
592 st = session_table_get_for_fib_index (transport_connection_fib_proto (tc),
595 return HALF_OPEN_LOOKUP_INVALID_VALUE;
598 make_v4_ss_kv (&kv4, &tc->lcl_ip.ip4, &tc->rmt_ip.ip4, tc->lcl_port,
599 tc->rmt_port, tc->proto);
600 rv = clib_bihash_search_inline_16_8 (&st->v4_half_open_hash, &kv4);
606 make_v6_ss_kv (&kv6, &tc->lcl_ip.ip6, &tc->rmt_ip.ip6, tc->lcl_port,
607 tc->rmt_port, tc->proto);
608 rv = clib_bihash_search_inline_48_8 (&st->v6_half_open_hash, &kv6);
612 return HALF_OPEN_LOOKUP_INVALID_VALUE;
615 transport_connection_t *
616 session_lookup_half_open_connection (u64 handle, u8 proto, u8 is_ip4)
620 if (handle != HALF_OPEN_LOOKUP_INVALID_VALUE)
622 sst = session_type_from_proto_and_ip (proto, is_ip4);
623 return tp_vfts[sst].get_half_open (handle & 0xFFFFFFFF);
629 * Lookup connection with ip4 and transport layer information
631 * This is used on the fast path so it needs to be fast. Thereby,
632 * duplication of code and 'hacks' allowed.
634 * The lookup is incremental and returns whenever something is matched. The
636 * - Try to find an established session
637 * - Try to find a fully-formed or local source wildcarded (listener bound to
638 * all interfaces) listener session
639 * - Try to find a half-open connection
642 * @param fib_index index of fib wherein the connection was received
643 * @param lcl local ip4 address
644 * @param rmt remote ip4 address
645 * @param lcl_port local port
646 * @param rmt_port remote port
647 * @param proto transport protocol (e.g., tcp, udp)
648 * @param thread_index thread index for request
650 * @return pointer to transport connection, if one is found, 0 otherwise
652 transport_connection_t *
653 session_lookup_connection_wt4 (u32 fib_index, ip4_address_t * lcl,
654 ip4_address_t * rmt, u16 lcl_port,
655 u16 rmt_port, u8 proto, u32 thread_index)
662 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP4, fib_index);
663 if (PREDICT_FALSE (!st))
666 /* Lookup session amongst established ones */
667 make_v4_ss_kv (&kv4, lcl, rmt, lcl_port, rmt_port, proto);
668 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
671 ASSERT ((u32) (kv4.value >> 32) == thread_index);
672 s = session_get (kv4.value & 0xFFFFFFFFULL, thread_index);
673 return tp_vfts[s->session_type].get_connection (s->connection_index,
677 /* If nothing is found, check if any listener is available */
678 s = session_lookup_listener4_i (st, lcl, lcl_port, proto);
680 return tp_vfts[s->session_type].get_listener (s->connection_index);
682 /* Finally, try half-open connections */
683 rv = clib_bihash_search_inline_16_8 (&st->v4_half_open_hash, &kv4);
686 u32 sst = session_type_from_proto_and_ip (proto, 1);
687 return tp_vfts[sst].get_half_open (kv4.value & 0xFFFFFFFF);
693 * Lookup connection with ip4 and transport layer information
695 * Not optimized. This is used on the fast path so it needs to be fast.
696 * Thereby, duplication of code and 'hacks' allowed. Lookup logic is identical
697 * to that of @ref session_lookup_connection_wt4
699 * @param fib_index index of the fib wherein the connection was received
700 * @param lcl local ip4 address
701 * @param rmt remote ip4 address
702 * @param lcl_port local port
703 * @param rmt_port remote port
704 * @param proto transport protocol (e.g., tcp, udp)
706 * @return pointer to transport connection, if one is found, 0 otherwise
708 transport_connection_t *
709 session_lookup_connection4 (u32 fib_index, ip4_address_t * lcl,
710 ip4_address_t * rmt, u16 lcl_port, u16 rmt_port,
718 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP4, fib_index);
719 if (PREDICT_FALSE (!st))
722 /* Lookup session amongst established ones */
723 make_v4_ss_kv (&kv4, lcl, rmt, lcl_port, rmt_port, proto);
724 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
727 s = session_get_from_handle (kv4.value);
728 return tp_vfts[s->session_type].get_connection (s->connection_index,
732 /* If nothing is found, check if any listener is available */
733 s = session_lookup_listener4_i (st, lcl, lcl_port, proto);
735 return tp_vfts[s->session_type].get_listener (s->connection_index);
737 /* Finally, try half-open connections */
738 rv = clib_bihash_search_inline_16_8 (&st->v4_half_open_hash, &kv4);
741 u32 sst = session_type_from_proto_and_ip (proto, 1);
742 return tp_vfts[sst].get_half_open (kv4.value & 0xFFFFFFFF);
748 * Lookup session with ip4 and transport layer information
750 * Important note: this may look into another thread's pool table and
751 * register as 'peeker'. Caller should call @ref session_pool_remove_peeker as
752 * if needed as soon as possible.
754 * Lookup logic is similar to that of @ref session_lookup_connection_wt4 but
755 * this returns a session as opposed to a transport connection and it does not
756 * try to lookup half-open sessions.
758 * Typically used by dgram connections
761 session_lookup_safe4 (u32 fib_index, ip4_address_t * lcl, ip4_address_t * rmt,
762 u16 lcl_port, u16 rmt_port, u8 proto)
769 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP4, fib_index);
770 if (PREDICT_FALSE (!st))
773 /* Lookup session amongst established ones */
774 make_v4_ss_kv (&kv4, lcl, rmt, lcl_port, rmt_port, proto);
775 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
777 return session_get_from_handle_safe (kv4.value);
779 /* If nothing is found, check if any listener is available */
780 if ((s = session_lookup_listener4_i (st, lcl, lcl_port, proto)))
786 * Lookup connection with ip6 and transport layer information
788 * This is used on the fast path so it needs to be fast. Thereby,
789 * duplication of code and 'hacks' allowed.
791 * The lookup is incremental and returns whenever something is matched. The
793 * - Try to find an established session
794 * - Try to find a fully-formed or local source wildcarded (listener bound to
795 * all interfaces) listener session
796 * - Try to find a half-open connection
799 * @param fib_index index of the fib wherein the connection was received
800 * @param lcl local ip6 address
801 * @param rmt remote ip6 address
802 * @param lcl_port local port
803 * @param rmt_port remote port
804 * @param proto transport protocol (e.g., tcp, udp)
805 * @param thread_index thread index for request
807 * @return pointer to transport connection, if one is found, 0 otherwise
809 transport_connection_t *
810 session_lookup_connection_wt6 (u32 fib_index, ip6_address_t * lcl,
811 ip6_address_t * rmt, u16 lcl_port,
812 u16 rmt_port, u8 proto, u32 thread_index)
819 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP6, fib_index);
820 if (PREDICT_FALSE (!st))
823 make_v6_ss_kv (&kv6, lcl, rmt, lcl_port, rmt_port, proto);
824 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
827 ASSERT ((u32) (kv6.value >> 32) == thread_index);
828 s = session_get (kv6.value & 0xFFFFFFFFULL, thread_index);
829 return tp_vfts[s->session_type].get_connection (s->connection_index,
833 /* If nothing is found, check if any listener is available */
834 s = session_lookup_listener6_i (st, lcl, lcl_port, proto);
836 return tp_vfts[s->session_type].get_listener (s->connection_index);
838 /* Finally, try half-open connections */
839 rv = clib_bihash_search_inline_48_8 (&st->v6_half_open_hash, &kv6);
842 u32 sst = session_type_from_proto_and_ip (proto, 1);
843 return tp_vfts[sst].get_half_open (kv6.value & 0xFFFFFFFF);
850 * Lookup connection with ip6 and transport layer information
852 * Not optimized. This is used on the fast path so it needs to be fast.
853 * Thereby, duplication of code and 'hacks' allowed. Lookup logic is identical
854 * to that of @ref session_lookup_connection_wt4
856 * @param fib_index index of the fib wherein the connection was received
857 * @param lcl local ip6 address
858 * @param rmt remote ip6 address
859 * @param lcl_port local port
860 * @param rmt_port remote port
861 * @param proto transport protocol (e.g., tcp, udp)
863 * @return pointer to transport connection, if one is found, 0 otherwise
865 transport_connection_t *
866 session_lookup_connection6 (u32 fib_index, ip6_address_t * lcl,
867 ip6_address_t * rmt, u16 lcl_port, u16 rmt_port,
875 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP6, fib_index);
876 if (PREDICT_FALSE (!st))
879 make_v6_ss_kv (&kv6, lcl, rmt, lcl_port, rmt_port, proto);
880 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
883 s = session_get_from_handle (kv6.value);
884 return tp_vfts[s->session_type].get_connection (s->connection_index,
888 /* If nothing is found, check if any listener is available */
889 s = session_lookup_listener6 (fib_index, lcl, lcl_port, proto);
891 return tp_vfts[s->session_type].get_listener (s->connection_index);
893 /* Finally, try half-open connections */
894 rv = clib_bihash_search_inline_48_8 (&st->v6_half_open_hash, &kv6);
897 u32 sst = session_type_from_proto_and_ip (proto, 1);
898 return tp_vfts[sst].get_half_open (kv6.value & 0xFFFFFFFF);
905 * Lookup session with ip6 and transport layer information
907 * Important note: this may look into another thread's pool table and
908 * register as 'peeker'. Caller should call @ref session_pool_remove_peeker as
909 * if needed as soon as possible.
911 * Lookup logic is similar to that of @ref session_lookup_connection_wt6 but
912 * this returns a session as opposed to a transport connection and it does not
913 * try to lookup half-open sessions.
915 * Typically used by dgram connections
918 session_lookup_safe6 (u32 fib_index, ip6_address_t * lcl, ip6_address_t * rmt,
919 u16 lcl_port, u16 rmt_port, u8 proto)
926 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP6, fib_index);
927 if (PREDICT_FALSE (!st))
930 make_v6_ss_kv (&kv6, lcl, rmt, lcl_port, rmt_port, proto);
931 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
933 return session_get_from_handle_safe (kv6.value);
935 /* If nothing is found, check if any listener is available */
936 if ((s = session_lookup_listener6_i (st, lcl, lcl_port, proto)))
942 session_lookup_local_listener_make_handle (session_endpoint_t * sep)
944 return ((u64) SESSION_LOCAL_TABLE_PREFIX << 32
945 | (u32) sep->port << 16 | (u32) sep->transport_proto << 8
946 | (u32) sep->is_ip4);
950 session_lookup_local_is_handle (u64 handle)
952 if (handle >> 32 == SESSION_LOCAL_TABLE_PREFIX)
958 session_lookup_local_listener_parse_handle (u64 handle,
959 session_endpoint_t * sep)
961 u32 local_table_handle;
962 if (handle >> 32 != SESSION_LOCAL_TABLE_PREFIX)
964 local_table_handle = handle & 0xFFFFFFFFULL;
965 sep->is_ip4 = local_table_handle & 0xff;
966 local_table_handle >>= 8;
967 sep->transport_proto = local_table_handle & 0xff;
968 sep->port = local_table_handle >> 8;
973 format_ip4_session_lookup_kvp (u8 * s, va_list * args)
975 clib_bihash_kv_16_8_t *kvp = va_arg (*args, clib_bihash_kv_16_8_t *);
976 u32 is_local = va_arg (*args, u32);
977 u8 *app_name, *str = 0;
978 stream_session_t *session;
979 v4_connection_key_t *key = (v4_connection_key_t *) kvp->key;
981 char *proto = key->proto == TRANSPORT_PROTO_TCP ? "T" : "U";
984 session = session_get_from_handle (kvp->value);
985 app_name = application_name_from_index (session->app_index);
986 str = format (0, "[%s] %U:%d->%U:%d", proto, format_ip4_address,
987 &key->src, clib_net_to_host_u16 (key->src_port),
988 format_ip4_address, &key->dst,
989 clib_net_to_host_u16 (key->dst_port));
990 s = format (s, "%-40v%-30v", str, app_name);
994 app_name = application_name_from_index (kvp->value);
995 str = format (0, "[%s] %U:%d", proto, format_ip4_address,
996 &key->src, clib_net_to_host_u16 (key->src_port));
997 s = format (s, "%-30v%-30v", str, app_name);
1003 typedef struct _ip4_session_table_show_ctx_t
1007 } ip4_session_table_show_ctx_t;
1010 ip4_session_table_show (clib_bihash_kv_16_8_t * kvp, void *arg)
1012 ip4_session_table_show_ctx_t *ctx = arg;
1013 vlib_cli_output (ctx->vm, "%U", format_ip4_session_lookup_kvp, kvp,
1019 session_lookup_show_table_entries (vlib_main_t * vm, session_table_t * table,
1020 u8 type, u8 is_local)
1022 ip4_session_table_show_ctx_t ctx = {
1024 .is_local = is_local,
1027 vlib_cli_output (vm, "%-40s%-30s", "Session", "Application");
1029 vlib_cli_output (vm, "%-30s%-30s", "Listener", "Application");
1034 ip4_session_table_walk (&table->v4_session_hash, ip4_session_table_show,
1038 clib_warning ("not supported");
1043 session_lookup_init (void)
1046 * Allocate default table and map it to fib_index 0
1048 session_table_t *st = session_table_alloc ();
1049 vec_validate (fib_index_to_table_index[FIB_PROTOCOL_IP4], 0);
1050 fib_index_to_table_index[FIB_PROTOCOL_IP4][0] = session_table_index (st);
1051 session_table_init (st);
1052 st = session_table_alloc ();
1053 vec_validate (fib_index_to_table_index[FIB_PROTOCOL_IP6], 0);
1054 fib_index_to_table_index[FIB_PROTOCOL_IP6][0] = session_table_index (st);
1055 session_table_init (st);
1059 * fd.io coding-style-patch-verification: ON
1062 * eval: (c-set-style "gnu")