2 * Copyright (c) 2017-2019 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 * Network namespace index (i.e., fib index) to session lookup table. We
34 * should have one per network protocol type but for now we only support IP4/6
36 static u32 *fib_index_to_table_index[2];
40 typedef CLIB_PACKED (struct {
49 /* align by making this 4 octets even though its a 1-bit field
50 * NOTE: avoid key overlap with other transports that use 5 tuples for
51 * session identification.
57 }) v4_connection_key_t;
59 typedef CLIB_PACKED (struct {
74 }) v6_connection_key_t;
77 typedef clib_bihash_kv_16_8_t session_kv4_t;
78 typedef clib_bihash_kv_48_8_t session_kv6_t;
81 make_v4_ss_kv (session_kv4_t * kv, ip4_address_t * lcl, ip4_address_t * rmt,
82 u16 lcl_port, u16 rmt_port, u8 proto)
84 kv->key[0] = (u64) rmt->as_u32 << 32 | (u64) lcl->as_u32;
85 kv->key[1] = (u64) proto << 32 | (u64) rmt_port << 16 | (u64) lcl_port;
90 make_v4_listener_kv (session_kv4_t * kv, ip4_address_t * lcl, u16 lcl_port,
93 kv->key[0] = (u64) lcl->as_u32;
94 kv->key[1] = (u64) proto << 32 | (u64) lcl_port;
99 make_v4_proxy_kv (session_kv4_t * kv, ip4_address_t * lcl, u8 proto)
101 kv->key[0] = (u64) lcl->as_u32;
102 kv->key[1] = (u64) proto << 32;
107 make_v4_ss_kv_from_tc (session_kv4_t * kv, transport_connection_t * tc)
109 make_v4_ss_kv (kv, &tc->lcl_ip.ip4, &tc->rmt_ip.ip4, tc->lcl_port,
110 tc->rmt_port, tc->proto);
114 make_v6_ss_kv (session_kv6_t * kv, ip6_address_t * lcl, ip6_address_t * rmt,
115 u16 lcl_port, u16 rmt_port, u8 proto)
117 kv->key[0] = lcl->as_u64[0];
118 kv->key[1] = lcl->as_u64[1];
119 kv->key[2] = rmt->as_u64[0];
120 kv->key[3] = rmt->as_u64[1];
121 kv->key[4] = (u64) proto << 32 | (u64) rmt_port << 16 | (u64) lcl_port;
127 make_v6_listener_kv (session_kv6_t * kv, ip6_address_t * lcl, u16 lcl_port,
130 kv->key[0] = lcl->as_u64[0];
131 kv->key[1] = lcl->as_u64[1];
134 kv->key[4] = (u64) proto << 32 | (u64) lcl_port;
140 make_v6_proxy_kv (session_kv6_t * kv, ip6_address_t * lcl, u8 proto)
142 kv->key[0] = lcl->as_u64[0];
143 kv->key[1] = lcl->as_u64[1];
146 kv->key[4] = (u64) proto << 32;
152 make_v6_ss_kv_from_tc (session_kv6_t * kv, transport_connection_t * tc)
154 make_v6_ss_kv (kv, &tc->lcl_ip.ip6, &tc->rmt_ip.ip6, tc->lcl_port,
155 tc->rmt_port, tc->proto);
158 static session_table_t *
159 session_table_get_or_alloc (u8 fib_proto, u32 fib_index)
163 ASSERT (fib_index != ~0);
164 if (vec_len (fib_index_to_table_index[fib_proto]) > fib_index &&
165 fib_index_to_table_index[fib_proto][fib_index] != ~0)
167 table_index = fib_index_to_table_index[fib_proto][fib_index];
168 return session_table_get (table_index);
172 st = session_table_alloc ();
173 table_index = session_table_index (st);
174 vec_validate_init_empty (fib_index_to_table_index[fib_proto], fib_index,
176 fib_index_to_table_index[fib_proto][fib_index] = table_index;
177 st->active_fib_proto = fib_proto;
178 session_table_init (st, fib_proto);
183 static session_table_t *
184 session_table_get_or_alloc_for_connection (transport_connection_t * tc)
187 fib_proto = transport_connection_fib_proto (tc);
188 return session_table_get_or_alloc (fib_proto, tc->fib_index);
191 static session_table_t *
192 session_table_get_for_connection (transport_connection_t * tc)
194 u32 fib_proto = transport_connection_fib_proto (tc);
195 if (vec_len (fib_index_to_table_index[fib_proto]) <= tc->fib_index)
198 session_table_get (fib_index_to_table_index[fib_proto][tc->fib_index]);
201 static session_table_t *
202 session_table_get_for_fib_index (u32 fib_proto, u32 fib_index)
204 if (vec_len (fib_index_to_table_index[fib_proto]) <= fib_index)
206 return session_table_get (fib_index_to_table_index[fib_proto][fib_index]);
210 session_lookup_get_index_for_fib (u32 fib_proto, u32 fib_index)
212 if (vec_len (fib_index_to_table_index[fib_proto]) <= fib_index)
213 return SESSION_TABLE_INVALID_INDEX;
214 return fib_index_to_table_index[fib_proto][fib_index];
218 session_lookup_get_or_alloc_index_for_fib (u32 fib_proto, u32 fib_index)
221 st = session_table_get_or_alloc (fib_proto, fib_index);
222 return session_table_index (st);
226 * Add transport connection to a session table
228 * Session lookup 5-tuple (src-ip, dst-ip, src-port, dst-port, session-type)
229 * is added to requested session table.
231 * @param tc transport connection to be added
232 * @param value value to be stored
234 * @return non-zero if failure
237 session_lookup_add_connection (transport_connection_t * tc, u64 value)
243 st = session_table_get_or_alloc_for_connection (tc);
248 make_v4_ss_kv_from_tc (&kv4, tc);
250 return clib_bihash_add_del_16_8 (&st->v4_session_hash, &kv4,
255 make_v6_ss_kv_from_tc (&kv6, tc);
257 return clib_bihash_add_del_48_8 (&st->v6_session_hash, &kv6,
263 session_lookup_add_session_endpoint (u32 table_index,
264 session_endpoint_t * sep, u64 value)
270 st = session_table_get (table_index);
275 make_v4_listener_kv (&kv4, &sep->ip.ip4, sep->port,
276 sep->transport_proto);
278 return clib_bihash_add_del_16_8 (&st->v4_session_hash, &kv4, 1);
282 make_v6_listener_kv (&kv6, &sep->ip.ip6, sep->port,
283 sep->transport_proto);
285 return clib_bihash_add_del_48_8 (&st->v6_session_hash, &kv6, 1);
290 session_lookup_del_session_endpoint (u32 table_index,
291 session_endpoint_t * sep)
297 st = session_table_get (table_index);
302 make_v4_listener_kv (&kv4, &sep->ip.ip4, sep->port,
303 sep->transport_proto);
304 return clib_bihash_add_del_16_8 (&st->v4_session_hash, &kv4, 0);
308 make_v6_listener_kv (&kv6, &sep->ip.ip6, sep->port,
309 sep->transport_proto);
310 return clib_bihash_add_del_48_8 (&st->v6_session_hash, &kv6, 0);
315 session_lookup_del_session_endpoint2 (session_endpoint_t * sep)
317 fib_protocol_t fib_proto;
322 fib_proto = sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
323 st = session_table_get_for_fib_index (fib_proto, sep->fib_index);
328 make_v4_listener_kv (&kv4, &sep->ip.ip4, sep->port,
329 sep->transport_proto);
330 return clib_bihash_add_del_16_8 (&st->v4_session_hash, &kv4, 0);
334 make_v6_listener_kv (&kv6, &sep->ip.ip6, sep->port,
335 sep->transport_proto);
336 return clib_bihash_add_del_48_8 (&st->v6_session_hash, &kv6, 0);
341 * Delete transport connection from session table
343 * @param table_index session table index
344 * @param tc transport connection to be removed
346 * @return non-zero if failure
349 session_lookup_del_connection (transport_connection_t * tc)
355 st = session_table_get_for_connection (tc);
360 make_v4_ss_kv_from_tc (&kv4, tc);
361 return clib_bihash_add_del_16_8 (&st->v4_session_hash, &kv4,
366 make_v6_ss_kv_from_tc (&kv6, tc);
367 return clib_bihash_add_del_48_8 (&st->v6_session_hash, &kv6,
373 session_lookup_del_session (session_t * s)
375 transport_connection_t *ts;
376 ts = transport_get_connection (session_get_transport_proto (s),
377 s->connection_index, s->thread_index);
378 if (!ts || (ts->flags & TRANSPORT_CONNECTION_F_NO_LOOKUP))
380 return session_lookup_del_connection (ts);
384 session_lookup_action_index_is_valid (u32 action_index)
386 if (action_index == SESSION_RULES_TABLE_ACTION_ALLOW
387 || action_index == SESSION_RULES_TABLE_INVALID_INDEX)
393 session_lookup_action_to_handle (u32 action_index)
395 switch (action_index)
397 case SESSION_RULES_TABLE_ACTION_DROP:
398 return SESSION_DROP_HANDLE;
399 case SESSION_RULES_TABLE_ACTION_ALLOW:
400 case SESSION_RULES_TABLE_INVALID_INDEX:
401 return SESSION_INVALID_HANDLE;
403 /* application index */
409 session_lookup_app_listen_session (u32 app_index, u8 fib_proto,
413 app = application_get_if_valid (app_index);
417 return app_worker_first_listener (application_get_default_worker (app),
418 fib_proto, transport_proto);
422 session_lookup_action_to_session (u32 action_index, u8 fib_proto,
426 app_index = session_lookup_action_to_handle (action_index);
427 /* Nothing sophisticated for now, action index is app index */
428 return session_lookup_app_listen_session (app_index, fib_proto,
434 session_lookup_rules_table_session4 (session_table_t * st, u8 proto,
435 ip4_address_t * lcl, u16 lcl_port,
436 ip4_address_t * rmt, u16 rmt_port)
438 session_rules_table_t *srt = &st->session_rules[proto];
439 u32 action_index, app_index;
440 action_index = session_rules_table_lookup4 (srt, lcl, rmt, lcl_port,
442 app_index = session_lookup_action_to_handle (action_index);
443 /* Nothing sophisticated for now, action index is app index */
444 return session_lookup_app_listen_session (app_index, FIB_PROTOCOL_IP4,
450 session_lookup_rules_table_session6 (session_table_t * st, u8 proto,
451 ip6_address_t * lcl, u16 lcl_port,
452 ip6_address_t * rmt, u16 rmt_port)
454 session_rules_table_t *srt = &st->session_rules[proto];
455 u32 action_index, app_index;
456 action_index = session_rules_table_lookup6 (srt, lcl, rmt, lcl_port,
458 app_index = session_lookup_action_to_handle (action_index);
459 return session_lookup_app_listen_session (app_index, FIB_PROTOCOL_IP6,
464 * Lookup listener for session endpoint in table
466 * @param table_index table where the endpoint should be looked up
467 * @param sep session endpoint to be looked up
468 * @param use_rules flag that indicates if the session rules of the table
470 * @return invalid handle if nothing is found, the handle of a valid listener
471 * or an action derived handle if a rule is hit
474 session_lookup_endpoint_listener (u32 table_index, session_endpoint_t * sep,
477 session_rules_table_t *srt;
482 st = session_table_get (table_index);
484 return SESSION_INVALID_HANDLE;
490 make_v4_listener_kv (&kv4, &sep->ip.ip4, sep->port,
491 sep->transport_proto);
492 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
497 clib_memset (&lcl4, 0, sizeof (lcl4));
498 srt = &st->session_rules[sep->transport_proto];
499 ai = session_rules_table_lookup4 (srt, &lcl4, &sep->ip.ip4, 0,
501 if (session_lookup_action_index_is_valid (ai))
502 return session_lookup_action_to_handle (ai);
510 make_v6_listener_kv (&kv6, &sep->ip.ip6, sep->port,
511 sep->transport_proto);
512 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
518 clib_memset (&lcl6, 0, sizeof (lcl6));
519 srt = &st->session_rules[sep->transport_proto];
520 ai = session_rules_table_lookup6 (srt, &lcl6, &sep->ip.ip6, 0,
522 if (session_lookup_action_index_is_valid (ai))
523 return session_lookup_action_to_handle (ai);
526 return SESSION_INVALID_HANDLE;
530 * Look up endpoint in local session table
532 * The result, for now, is an application index and it may in the future
533 * be extended to a more complicated "action object". The only action we
534 * emulate now is "drop" and for that we return a special app index.
536 * Lookup logic is to check in order:
537 * - the rules in the table (connect acls)
538 * - session sub-table for a listener
539 * - session sub-table for a local listener (zeroed addr)
541 * @param table_index table where the lookup should be done
542 * @param sep session endpoint to be looked up
543 * @return session handle that can be interpreted as an adjacency
546 session_lookup_local_endpoint (u32 table_index, session_endpoint_t * sep)
548 session_rules_table_t *srt;
553 st = session_table_get (table_index);
555 return SESSION_INVALID_INDEX;
556 ASSERT (st->is_local);
564 * Check if endpoint has special rules associated
566 clib_memset (&lcl4, 0, sizeof (lcl4));
567 srt = &st->session_rules[sep->transport_proto];
568 ai = session_rules_table_lookup4 (srt, &lcl4, &sep->ip.ip4, 0,
570 if (session_lookup_action_index_is_valid (ai))
571 return session_lookup_action_to_handle (ai);
574 * Check if session endpoint is a listener
576 make_v4_listener_kv (&kv4, &sep->ip.ip4, sep->port,
577 sep->transport_proto);
578 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
583 * Zero out the ip. Logic is that connect to local ips, say
584 * 127.0.0.1:port, can match 0.0.0.0:port
586 if (ip4_is_local_host (&sep->ip.ip4))
589 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
599 * Zero out the port and check if we have proxy
602 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
611 clib_memset (&lcl6, 0, sizeof (lcl6));
612 srt = &st->session_rules[sep->transport_proto];
613 ai = session_rules_table_lookup6 (srt, &lcl6, &sep->ip.ip6, 0,
615 if (session_lookup_action_index_is_valid (ai))
616 return session_lookup_action_to_handle (ai);
618 make_v6_listener_kv (&kv6, &sep->ip.ip6, sep->port,
619 sep->transport_proto);
620 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
625 * Zero out the ip. Same logic as above.
628 if (ip6_is_local_host (&sep->ip.ip6))
630 kv6.key[0] = kv6.key[1] = 0;
631 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
637 kv6.key[0] = kv6.key[1] = 0;
641 * Zero out the port. Same logic as above.
643 kv6.key[4] = kv6.key[5] = 0;
644 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
648 return SESSION_INVALID_HANDLE;
651 static inline session_t *
652 session_lookup_listener4_i (session_table_t * st, ip4_address_t * lcl,
653 u16 lcl_port, u8 proto, u8 use_wildcard)
659 * First, try a fully formed listener
661 make_v4_listener_kv (&kv4, lcl, lcl_port, proto);
662 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
664 return listen_session_get ((u32) kv4.value);
667 * Zero out the lcl ip and check if any 0/0 port binds have been done
672 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
674 return listen_session_get ((u32) kv4.value);
682 * Zero out port and check if we have a proxy set up for our ip
684 make_v4_proxy_kv (&kv4, lcl, proto);
685 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
687 return listen_session_get ((u32) kv4.value);
693 session_lookup_listener4 (u32 fib_index, ip4_address_t * lcl, u16 lcl_port,
694 u8 proto, u8 use_wildcard)
697 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP4, fib_index);
700 return session_lookup_listener4_i (st, lcl, lcl_port, proto, use_wildcard);
704 session_lookup_listener6_i (session_table_t * st, ip6_address_t * lcl,
705 u16 lcl_port, u8 proto, u8 ip_wildcard)
710 make_v6_listener_kv (&kv6, lcl, lcl_port, proto);
711 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
713 return listen_session_get ((u32) kv6.value);
715 /* Zero out the lcl ip */
718 kv6.key[0] = kv6.key[1] = 0;
719 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
721 return listen_session_get ((u32) kv6.value);
725 kv6.key[0] = kv6.key[1] = 0;
728 make_v6_proxy_kv (&kv6, lcl, proto);
729 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
731 return listen_session_get ((u32) kv6.value);
736 session_lookup_listener6 (u32 fib_index, ip6_address_t * lcl, u16 lcl_port,
737 u8 proto, u8 use_wildcard)
740 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP6, fib_index);
743 return session_lookup_listener6_i (st, lcl, lcl_port, proto, use_wildcard);
747 * Lookup listener, exact or proxy (inaddr_any:0) match
750 session_lookup_listener (u32 table_index, session_endpoint_t * sep)
753 st = session_table_get (table_index);
757 return session_lookup_listener4_i (st, &sep->ip.ip4, sep->port,
758 sep->transport_proto, 0);
760 return session_lookup_listener6_i (st, &sep->ip.ip6, sep->port,
761 sep->transport_proto, 0);
766 * Lookup listener wildcard match
769 session_lookup_listener_wildcard (u32 table_index, session_endpoint_t * sep)
772 st = session_table_get (table_index);
776 return session_lookup_listener4_i (st, &sep->ip.ip4, sep->port,
777 sep->transport_proto,
778 1 /* use_wildcard */ );
780 return session_lookup_listener6_i (st, &sep->ip.ip6, sep->port,
781 sep->transport_proto,
782 1 /* use_wildcard */ );
787 session_lookup_add_half_open (transport_connection_t * tc, u64 value)
793 st = session_table_get_or_alloc_for_connection (tc);
798 make_v4_ss_kv_from_tc (&kv4, tc);
800 return clib_bihash_add_del_16_8 (&st->v4_half_open_hash, &kv4,
805 make_v6_ss_kv_from_tc (&kv6, tc);
807 return clib_bihash_add_del_48_8 (&st->v6_half_open_hash, &kv6,
813 session_lookup_del_half_open (transport_connection_t * tc)
819 st = session_table_get_for_connection (tc);
824 make_v4_ss_kv_from_tc (&kv4, tc);
825 return clib_bihash_add_del_16_8 (&st->v4_half_open_hash, &kv4,
830 make_v6_ss_kv_from_tc (&kv6, tc);
831 return clib_bihash_add_del_48_8 (&st->v6_half_open_hash, &kv6,
837 session_lookup_half_open_handle (transport_connection_t * tc)
844 st = session_table_get_for_fib_index (transport_connection_fib_proto (tc),
847 return HALF_OPEN_LOOKUP_INVALID_VALUE;
850 make_v4_ss_kv (&kv4, &tc->lcl_ip.ip4, &tc->rmt_ip.ip4, tc->lcl_port,
851 tc->rmt_port, tc->proto);
852 rv = clib_bihash_search_inline_16_8 (&st->v4_half_open_hash, &kv4);
858 make_v6_ss_kv (&kv6, &tc->lcl_ip.ip6, &tc->rmt_ip.ip6, tc->lcl_port,
859 tc->rmt_port, tc->proto);
860 rv = clib_bihash_search_inline_48_8 (&st->v6_half_open_hash, &kv6);
864 return HALF_OPEN_LOOKUP_INVALID_VALUE;
867 transport_connection_t *
868 session_lookup_half_open_connection (u64 handle, u8 proto, u8 is_ip4)
870 if (handle != HALF_OPEN_LOOKUP_INVALID_VALUE)
872 u32 sst = session_type_from_proto_and_ip (proto, is_ip4);
873 return transport_get_half_open (sst, handle & 0xFFFFFFFF);
879 * Lookup connection with ip4 and transport layer information
881 * This is used on the fast path so it needs to be fast. Thereby,
882 * duplication of code and 'hacks' allowed.
884 * The lookup is incremental and returns whenever something is matched. The
886 * - Try to find an established session
887 * - Try to find a half-open connection
888 * - Try session rules table
889 * - Try to find a fully-formed or local source wildcarded (listener bound to
890 * all interfaces) listener session
893 * @param fib_index index of fib wherein the connection was received
894 * @param lcl local ip4 address
895 * @param rmt remote ip4 address
896 * @param lcl_port local port
897 * @param rmt_port remote port
898 * @param proto transport protocol (e.g., tcp, udp)
899 * @param thread_index thread index for request
900 * @param is_filtered return flag that indicates if connection was filtered.
902 * @return pointer to transport connection, if one is found, 0 otherwise
904 transport_connection_t *
905 session_lookup_connection_wt4 (u32 fib_index, ip4_address_t * lcl,
906 ip4_address_t * rmt, u16 lcl_port,
907 u16 rmt_port, u8 proto, u32 thread_index,
916 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP4, fib_index);
917 if (PREDICT_FALSE (!st))
921 * Lookup session amongst established ones
923 make_v4_ss_kv (&kv4, lcl, rmt, lcl_port, rmt_port, proto);
924 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
927 if (PREDICT_FALSE ((u32) (kv4.value >> 32) != thread_index))
929 *result = SESSION_LOOKUP_RESULT_WRONG_THREAD;
932 s = session_get (kv4.value & 0xFFFFFFFFULL, thread_index);
933 return transport_get_connection (proto, s->connection_index,
938 * Try half-open connections
940 rv = clib_bihash_search_inline_16_8 (&st->v4_half_open_hash, &kv4);
942 return transport_get_half_open (proto, kv4.value & 0xFFFFFFFF);
945 * Check the session rules table
947 action_index = session_rules_table_lookup4 (&st->session_rules[proto], lcl,
948 rmt, lcl_port, rmt_port);
949 if (session_lookup_action_index_is_valid (action_index))
951 if (action_index == SESSION_RULES_TABLE_ACTION_DROP)
953 *result = SESSION_LOOKUP_RESULT_FILTERED;
956 if ((s = session_lookup_action_to_session (action_index,
957 FIB_PROTOCOL_IP4, proto)))
958 return transport_get_listener (proto, s->connection_index);
963 * If nothing is found, check if any listener is available
965 s = session_lookup_listener4_i (st, lcl, lcl_port, proto, 1);
967 return transport_get_listener (proto, s->connection_index);
973 * Lookup connection with ip4 and transport layer information
975 * Not optimized. Lookup logic is identical to that of
976 * @ref session_lookup_connection_wt4
978 * @param fib_index index of the fib wherein the connection was received
979 * @param lcl local ip4 address
980 * @param rmt remote ip4 address
981 * @param lcl_port local port
982 * @param rmt_port remote port
983 * @param proto transport protocol (e.g., tcp, udp)
985 * @return pointer to transport connection, if one is found, 0 otherwise
987 transport_connection_t *
988 session_lookup_connection4 (u32 fib_index, ip4_address_t * lcl,
989 ip4_address_t * rmt, u16 lcl_port, u16 rmt_port,
998 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP4, fib_index);
999 if (PREDICT_FALSE (!st))
1003 * Lookup session amongst established ones
1005 make_v4_ss_kv (&kv4, lcl, rmt, lcl_port, rmt_port, proto);
1006 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
1009 s = session_get_from_handle (kv4.value);
1010 return transport_get_connection (proto, s->connection_index,
1015 * Try half-open connections
1017 rv = clib_bihash_search_inline_16_8 (&st->v4_half_open_hash, &kv4);
1019 return transport_get_half_open (proto, kv4.value & 0xFFFFFFFF);
1022 * Check the session rules table
1024 action_index = session_rules_table_lookup4 (&st->session_rules[proto], lcl,
1025 rmt, lcl_port, rmt_port);
1026 if (session_lookup_action_index_is_valid (action_index))
1028 if (action_index == SESSION_RULES_TABLE_ACTION_DROP)
1030 if ((s = session_lookup_action_to_session (action_index,
1031 FIB_PROTOCOL_IP4, proto)))
1032 return transport_get_listener (proto, s->connection_index);
1037 * If nothing is found, check if any listener is available
1039 s = session_lookup_listener4_i (st, lcl, lcl_port, proto, 1);
1041 return transport_get_listener (proto, s->connection_index);
1047 * Lookup session with ip4 and transport layer information
1049 * Important note: this may look into another thread's pool table
1051 * Lookup logic is similar to that of @ref session_lookup_connection_wt4 but
1052 * this returns a session as opposed to a transport connection and it does not
1053 * try to lookup half-open sessions.
1055 * Typically used by dgram connections
1058 session_lookup_safe4 (u32 fib_index, ip4_address_t * lcl, ip4_address_t * rmt,
1059 u16 lcl_port, u16 rmt_port, u8 proto)
1061 session_table_t *st;
1067 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP4, fib_index);
1068 if (PREDICT_FALSE (!st))
1072 * Lookup session amongst established ones
1074 make_v4_ss_kv (&kv4, lcl, rmt, lcl_port, rmt_port, proto);
1075 rv = clib_bihash_search_inline_16_8 (&st->v4_session_hash, &kv4);
1077 return session_get_from_handle_safe (kv4.value);
1080 * Check the session rules table
1082 action_index = session_rules_table_lookup4 (&st->session_rules[proto], lcl,
1083 rmt, lcl_port, rmt_port);
1084 if (session_lookup_action_index_is_valid (action_index))
1086 if (action_index == SESSION_RULES_TABLE_ACTION_DROP)
1088 return session_lookup_action_to_session (action_index, FIB_PROTOCOL_IP4,
1093 * If nothing is found, check if any listener is available
1095 if ((s = session_lookup_listener4_i (st, lcl, lcl_port, proto, 1)))
1102 * Lookup connection with ip6 and transport layer information
1104 * This is used on the fast path so it needs to be fast. Thereby,
1105 * duplication of code and 'hacks' allowed.
1107 * The lookup is incremental and returns whenever something is matched. The
1109 * - Try to find an established session
1110 * - Try to find a half-open connection
1111 * - Try session rules table
1112 * - Try to find a fully-formed or local source wildcarded (listener bound to
1113 * all interfaces) listener session
1116 * @param fib_index index of the fib wherein the connection was received
1117 * @param lcl local ip6 address
1118 * @param rmt remote ip6 address
1119 * @param lcl_port local port
1120 * @param rmt_port remote port
1121 * @param proto transport protocol (e.g., tcp, udp)
1122 * @param thread_index thread index for request
1124 * @return pointer to transport connection, if one is found, 0 otherwise
1126 transport_connection_t *
1127 session_lookup_connection_wt6 (u32 fib_index, ip6_address_t * lcl,
1128 ip6_address_t * rmt, u16 lcl_port,
1129 u16 rmt_port, u8 proto, u32 thread_index,
1132 session_table_t *st;
1138 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP6, fib_index);
1139 if (PREDICT_FALSE (!st))
1142 make_v6_ss_kv (&kv6, lcl, rmt, lcl_port, rmt_port, proto);
1143 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
1146 ASSERT ((u32) (kv6.value >> 32) == thread_index);
1147 if (PREDICT_FALSE ((u32) (kv6.value >> 32) != thread_index))
1149 *result = SESSION_LOOKUP_RESULT_WRONG_THREAD;
1152 s = session_get (kv6.value & 0xFFFFFFFFULL, thread_index);
1153 return transport_get_connection (proto, s->connection_index,
1157 /* Try half-open connections */
1158 rv = clib_bihash_search_inline_48_8 (&st->v6_half_open_hash, &kv6);
1160 return transport_get_half_open (proto, kv6.value & 0xFFFFFFFF);
1162 /* Check the session rules table */
1163 action_index = session_rules_table_lookup6 (&st->session_rules[proto], lcl,
1164 rmt, lcl_port, rmt_port);
1165 if (session_lookup_action_index_is_valid (action_index))
1167 if (action_index == SESSION_RULES_TABLE_ACTION_DROP)
1169 *result = SESSION_LOOKUP_RESULT_FILTERED;
1172 if ((s = session_lookup_action_to_session (action_index,
1173 FIB_PROTOCOL_IP6, proto)))
1174 return transport_get_listener (proto, s->connection_index);
1178 /* If nothing is found, check if any listener is available */
1179 s = session_lookup_listener6_i (st, lcl, lcl_port, proto, 1);
1181 return transport_get_listener (proto, s->connection_index);
1187 * Lookup connection with ip6 and transport layer information
1189 * Not optimized. This is used on the fast path so it needs to be fast.
1190 * Thereby, duplication of code and 'hacks' allowed. Lookup logic is identical
1191 * to that of @ref session_lookup_connection_wt4
1193 * @param fib_index index of the fib wherein the connection was received
1194 * @param lcl local ip6 address
1195 * @param rmt remote ip6 address
1196 * @param lcl_port local port
1197 * @param rmt_port remote port
1198 * @param proto transport protocol (e.g., tcp, udp)
1200 * @return pointer to transport connection, if one is found, 0 otherwise
1202 transport_connection_t *
1203 session_lookup_connection6 (u32 fib_index, ip6_address_t * lcl,
1204 ip6_address_t * rmt, u16 lcl_port, u16 rmt_port,
1207 session_table_t *st;
1213 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP6, fib_index);
1214 if (PREDICT_FALSE (!st))
1217 make_v6_ss_kv (&kv6, lcl, rmt, lcl_port, rmt_port, proto);
1218 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
1221 s = session_get_from_handle (kv6.value);
1222 return transport_get_connection (proto, s->connection_index,
1226 /* Try half-open connections */
1227 rv = clib_bihash_search_inline_48_8 (&st->v6_half_open_hash, &kv6);
1229 return transport_get_half_open (proto, kv6.value & 0xFFFFFFFF);
1231 /* Check the session rules table */
1232 action_index = session_rules_table_lookup6 (&st->session_rules[proto], lcl,
1233 rmt, lcl_port, rmt_port);
1234 if (session_lookup_action_index_is_valid (action_index))
1236 if (action_index == SESSION_RULES_TABLE_ACTION_DROP)
1238 if ((s = session_lookup_action_to_session (action_index,
1239 FIB_PROTOCOL_IP6, proto)))
1240 return transport_get_listener (proto, s->connection_index);
1244 /* If nothing is found, check if any listener is available */
1245 s = session_lookup_listener6_i (st, lcl, lcl_port, proto, 1);
1247 return transport_get_listener (proto, s->connection_index);
1253 * Lookup session with ip6 and transport layer information
1255 * Important note: this may look into another thread's pool table and
1256 * register as 'peeker'. Caller should call @ref session_pool_remove_peeker as
1257 * if needed as soon as possible.
1259 * Lookup logic is similar to that of @ref session_lookup_connection_wt6 but
1260 * this returns a session as opposed to a transport connection and it does not
1261 * try to lookup half-open sessions.
1263 * Typically used by dgram connections
1266 session_lookup_safe6 (u32 fib_index, ip6_address_t * lcl, ip6_address_t * rmt,
1267 u16 lcl_port, u16 rmt_port, u8 proto)
1269 session_table_t *st;
1275 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP6, fib_index);
1276 if (PREDICT_FALSE (!st))
1279 make_v6_ss_kv (&kv6, lcl, rmt, lcl_port, rmt_port, proto);
1280 rv = clib_bihash_search_inline_48_8 (&st->v6_session_hash, &kv6);
1282 return session_get_from_handle_safe (kv6.value);
1284 /* Check the session rules table */
1285 action_index = session_rules_table_lookup6 (&st->session_rules[proto], lcl,
1286 rmt, lcl_port, rmt_port);
1287 if (session_lookup_action_index_is_valid (action_index))
1289 if (action_index == SESSION_RULES_TABLE_ACTION_DROP)
1291 return session_lookup_action_to_session (action_index, FIB_PROTOCOL_IP6,
1295 /* If nothing is found, check if any listener is available */
1296 if ((s = session_lookup_listener6_i (st, lcl, lcl_port, proto, 1)))
1301 transport_connection_t *
1302 session_lookup_connection (u32 fib_index, ip46_address_t * lcl,
1303 ip46_address_t * rmt, u16 lcl_port, u16 rmt_port,
1304 u8 proto, u8 is_ip4)
1307 return session_lookup_connection4 (fib_index, &lcl->ip4, &rmt->ip4,
1308 lcl_port, rmt_port, proto);
1310 return session_lookup_connection6 (fib_index, &lcl->ip6, &rmt->ip6,
1311 lcl_port, rmt_port, proto);
1315 vnet_session_rule_add_del (session_rule_add_del_args_t *args)
1317 app_namespace_t *app_ns = app_namespace_get (args->appns_index);
1318 session_rules_table_t *srt;
1319 session_table_t *st;
1325 return SESSION_E_INVALID_NS;
1327 if (args->scope > 3)
1328 return SESSION_E_INVALID;
1330 if (args->transport_proto != TRANSPORT_PROTO_TCP
1331 && args->transport_proto != TRANSPORT_PROTO_UDP)
1332 return SESSION_E_INVALID;
1334 if ((args->scope & SESSION_RULE_SCOPE_GLOBAL) || args->scope == 0)
1336 fib_proto = args->table_args.rmt.fp_proto;
1337 fib_index = app_namespace_get_fib_index (app_ns, fib_proto);
1338 st = session_table_get_for_fib_index (fib_proto, fib_index);
1339 srt = &st->session_rules[args->transport_proto];
1340 if ((rv = session_rules_table_add_del (srt, &args->table_args)))
1343 if (args->scope & SESSION_RULE_SCOPE_LOCAL)
1345 clib_memset (&args->table_args.lcl, 0, sizeof (args->table_args.lcl));
1346 args->table_args.lcl.fp_proto = args->table_args.rmt.fp_proto;
1347 args->table_args.lcl_port = 0;
1348 st = app_namespace_get_local_table (app_ns);
1349 srt = &st->session_rules[args->transport_proto];
1350 rv = session_rules_table_add_del (srt, &args->table_args);
1356 * Mark (global) tables as pertaining to app ns
1359 session_lookup_set_tables_appns (app_namespace_t * app_ns)
1361 session_table_t *st;
1365 for (fp = 0; fp < ARRAY_LEN (fib_index_to_table_index); fp++)
1367 fib_index = app_namespace_get_fib_index (app_ns, fp);
1368 st = session_table_get_or_alloc (fp, fib_index);
1370 st->appns_index = app_namespace_index (app_ns);
1375 format_ip4_session_lookup_kvp (u8 * s, va_list * args)
1377 clib_bihash_kv_16_8_t *kvp = va_arg (*args, clib_bihash_kv_16_8_t *);
1378 u32 is_local = va_arg (*args, u32);
1379 v4_connection_key_t *key = (v4_connection_key_t *) kvp->key;
1381 app_worker_t *app_wrk;
1387 session = session_get_from_handle (kvp->value);
1388 app_wrk = app_worker_get (session->app_wrk_index);
1389 app_name = application_name_from_index (app_wrk->app_index);
1390 str = format (0, "[%U] %U:%d->%U:%d", format_transport_proto_short,
1391 key->proto, format_ip4_address, &key->src,
1392 clib_net_to_host_u16 (key->src_port), format_ip4_address,
1393 &key->dst, clib_net_to_host_u16 (key->dst_port));
1394 s = format (s, "%-40v%-30v", str, app_name);
1398 session = session_get_from_handle (kvp->value);
1399 app_wrk = app_worker_get (session->app_wrk_index);
1400 app_name = application_name_from_index (app_wrk->app_index);
1401 str = format (0, "[%U] %U:%d", format_transport_proto_short, key->proto,
1402 format_ip4_address, &key->src,
1403 clib_net_to_host_u16 (key->src_port));
1404 s = format (s, "%-30v%-30v", str, app_name);
1409 typedef struct _ip4_session_table_show_ctx_t
1413 } ip4_session_table_show_ctx_t;
1416 ip4_session_table_show (clib_bihash_kv_16_8_t * kvp, void *arg)
1418 ip4_session_table_show_ctx_t *ctx = arg;
1419 vlib_cli_output (ctx->vm, "%U", format_ip4_session_lookup_kvp, kvp,
1425 session_lookup_show_table_entries (vlib_main_t * vm, session_table_t * table,
1426 u8 type, u8 is_local)
1428 ip4_session_table_show_ctx_t ctx = {
1430 .is_local = is_local,
1433 vlib_cli_output (vm, "%-40s%-30s", "Session", "Application");
1435 vlib_cli_output (vm, "%-30s%-30s", "Listener", "Application");
1440 ip4_session_table_walk (&table->v4_session_hash, ip4_session_table_show,
1444 clib_warning ("not supported");
1448 static clib_error_t *
1449 session_rule_command_fn (vlib_main_t * vm, unformat_input_t * input,
1450 vlib_cli_command_t * cmd)
1452 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen = 0, rmt_plen = 0;
1453 clib_error_t *error = 0;
1454 u32 appns_index, scope = 0;
1455 ip46_address_t lcl_ip, rmt_ip;
1456 u8 is_ip4 = 1, conn_set = 0;
1457 u8 fib_proto, is_add = 1, *ns_id = 0;
1459 app_namespace_t *app_ns;
1462 session_cli_return_if_not_enabled ();
1464 clib_memset (&lcl_ip, 0, sizeof (lcl_ip));
1465 clib_memset (&rmt_ip, 0, sizeof (rmt_ip));
1466 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1468 if (unformat (input, "del"))
1470 else if (unformat (input, "add"))
1472 else if (unformat (input, "appns %_%v%_", &ns_id))
1474 else if (unformat (input, "scope global"))
1475 scope = SESSION_RULE_SCOPE_GLOBAL;
1476 else if (unformat (input, "scope local"))
1477 scope = SESSION_RULE_SCOPE_LOCAL;
1478 else if (unformat (input, "scope all"))
1479 scope = SESSION_RULE_SCOPE_LOCAL | SESSION_RULE_SCOPE_GLOBAL;
1480 else if (unformat (input, "proto %U", unformat_transport_proto, &proto))
1482 else if (unformat (input, "%U/%d %d %U/%d %d", unformat_ip4_address,
1483 &lcl_ip.ip4, &lcl_plen, &lcl_port,
1484 unformat_ip4_address, &rmt_ip.ip4, &rmt_plen,
1490 else if (unformat (input, "%U/%d %d %U/%d %d", unformat_ip6_address,
1491 &lcl_ip.ip6, &lcl_plen, &lcl_port,
1492 unformat_ip6_address, &rmt_ip.ip6, &rmt_plen,
1498 else if (unformat (input, "action %d", &action))
1500 else if (unformat (input, "tag %_%v%_", &tag))
1504 error = clib_error_return (0, "unknown input `%U'",
1505 format_unformat_error, input);
1512 vlib_cli_output (vm, "proto must be set");
1515 if (is_add && !conn_set && action == ~0)
1517 vlib_cli_output (vm, "connection and action must be set for add");
1520 if (!is_add && !tag && !conn_set)
1522 vlib_cli_output (vm, "connection or tag must be set for delete");
1525 if (vec_len (tag) > SESSION_RULE_TAG_MAX_LEN)
1527 vlib_cli_output (vm, "tag too long (max u64)");
1533 app_ns = app_namespace_get_from_id (ns_id);
1536 vlib_cli_output (vm, "namespace %v does not exist", ns_id);
1542 app_ns = app_namespace_get_default ();
1544 appns_index = app_namespace_index (app_ns);
1546 fib_proto = is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
1547 session_rule_add_del_args_t args = {
1548 .transport_proto = proto,
1549 .table_args.lcl.fp_addr = lcl_ip,
1550 .table_args.lcl.fp_len = lcl_plen,
1551 .table_args.lcl.fp_proto = fib_proto,
1552 .table_args.rmt.fp_addr = rmt_ip,
1553 .table_args.rmt.fp_len = rmt_plen,
1554 .table_args.rmt.fp_proto = fib_proto,
1555 .table_args.lcl_port = lcl_port,
1556 .table_args.rmt_port = rmt_port,
1557 .table_args.action_index = action,
1558 .table_args.is_add = is_add,
1559 .table_args.tag = tag,
1560 .appns_index = appns_index,
1563 if ((rv = vnet_session_rule_add_del (&args)))
1564 error = clib_error_return (0, "rule add del returned %u", rv);
1573 VLIB_CLI_COMMAND (session_rule_command, static) =
1575 .path = "session rule",
1576 .short_help = "session rule [add|del] appns <ns_id> proto <proto> "
1577 "<lcl-ip/plen> <lcl-port> <rmt-ip/plen> <rmt-port> action <action>",
1578 .function = session_rule_command_fn,
1583 session_lookup_dump_rules_table (u32 fib_index, u8 fib_proto,
1586 vlib_main_t *vm = vlib_get_main ();
1587 session_rules_table_t *srt;
1588 session_table_t *st;
1589 st = session_table_get_for_fib_index (fib_index, fib_proto);
1590 srt = &st->session_rules[transport_proto];
1591 session_rules_table_cli_dump (vm, srt, fib_proto);
1595 session_lookup_dump_local_rules_table (u32 table_index, u8 fib_proto,
1598 vlib_main_t *vm = vlib_get_main ();
1599 session_rules_table_t *srt;
1600 session_table_t *st;
1601 st = session_table_get (table_index);
1602 srt = &st->session_rules[transport_proto];
1603 session_rules_table_cli_dump (vm, srt, fib_proto);
1606 static clib_error_t *
1607 show_session_rules_command_fn (vlib_main_t * vm, unformat_input_t * input,
1608 vlib_cli_command_t * cmd)
1610 u32 transport_proto = ~0, lcl_port, rmt_port, lcl_plen, rmt_plen;
1611 u32 fib_index, scope = 0;
1612 ip46_address_t lcl_ip, rmt_ip;
1613 u8 is_ip4 = 1, show_one = 0;
1614 app_namespace_t *app_ns;
1615 session_rules_table_t *srt;
1616 session_table_t *st;
1617 u8 *ns_id = 0, fib_proto;
1619 session_cli_return_if_not_enabled ();
1621 clib_memset (&lcl_ip, 0, sizeof (lcl_ip));
1622 clib_memset (&rmt_ip, 0, sizeof (rmt_ip));
1623 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1625 if (unformat (input, "%U", unformat_transport_proto, &transport_proto))
1627 else if (unformat (input, "appns %_%v%_", &ns_id))
1629 else if (unformat (input, "scope global"))
1631 else if (unformat (input, "scope local"))
1633 else if (unformat (input, "%U/%d %d %U/%d %d", unformat_ip4_address,
1634 &lcl_ip.ip4, &lcl_plen, &lcl_port,
1635 unformat_ip4_address, &rmt_ip.ip4, &rmt_plen,
1641 else if (unformat (input, "%U/%d %d %U/%d %d", unformat_ip6_address,
1642 &lcl_ip.ip6, &lcl_plen, &lcl_port,
1643 unformat_ip6_address, &rmt_ip.ip6, &rmt_plen,
1650 return clib_error_return (0, "unknown input `%U'",
1651 format_unformat_error, input);
1654 if (transport_proto == ~0)
1656 vlib_cli_output (vm, "transport proto must be set");
1662 app_ns = app_namespace_get_from_id (ns_id);
1665 vlib_cli_output (vm, "appns %v doesn't exist", ns_id);
1671 app_ns = app_namespace_get_default ();
1674 if (scope == 1 || scope == 0)
1676 fib_proto = is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
1677 fib_index = is_ip4 ? app_ns->ip4_fib_index : app_ns->ip6_fib_index;
1678 st = session_table_get_for_fib_index (fib_proto, fib_index);
1682 st = app_namespace_get_local_table (app_ns);
1687 srt = &st->session_rules[transport_proto];
1688 session_rules_table_show_rule (vm, srt, &lcl_ip, lcl_port, &rmt_ip,
1693 vlib_cli_output (vm, "%U rules table", format_transport_proto,
1695 srt = &st->session_rules[transport_proto];
1696 session_rules_table_cli_dump (vm, srt, FIB_PROTOCOL_IP4);
1697 session_rules_table_cli_dump (vm, srt, FIB_PROTOCOL_IP6);
1704 VLIB_CLI_COMMAND (show_session_rules_command, static) =
1706 .path = "show session rules",
1707 .short_help = "show session rules [<proto> appns <id> <lcl-ip/plen> "
1708 "<lcl-port> <rmt-ip/plen> <rmt-port> scope <scope>]",
1709 .function = show_session_rules_command_fn,
1714 format_session_lookup_tables (u8 *s, va_list *args)
1716 u32 fib_proto = va_arg (*args, u32);
1717 u32 *fibs, num_fibs = 0, fib_index, indent;
1718 session_table_t *st;
1721 fibs = fib_index_to_table_index[fib_proto];
1723 for (fib_index = 0; fib_index < vec_len (fibs); fib_index++)
1725 if (fibs[fib_index] == ~0)
1729 st = session_table_get (fibs[fib_index]);
1730 total_mem += session_table_memory_size (st);
1733 indent = format_get_indent (s);
1734 s = format (s, "active fibs:\t%u\n", num_fibs);
1735 s = format (s, "%Umax fib-index:\t%u\n", format_white_space, indent,
1736 vec_len (fibs) - 1);
1737 s = format (s, "%Utable memory:\t%U\n", format_white_space, indent,
1738 format_memory_size, total_mem);
1739 s = format (s, "%Uvec memory:\t%U\n", format_white_space, indent,
1740 format_memory_size, vec_mem_size (fibs));
1745 static clib_error_t *
1746 show_session_lookup_command_fn (vlib_main_t *vm, unformat_input_t *input,
1747 vlib_cli_command_t *cmd)
1749 session_table_t *st;
1752 session_cli_return_if_not_enabled ();
1753 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1755 if (unformat (input, "table %u", &fib_index))
1758 return clib_error_return (0, "unknown input `%U'",
1759 format_unformat_error, input);
1762 if (fib_index != ~0)
1764 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP4, fib_index);
1766 vlib_cli_output (vm, "%U", format_session_table, st);
1768 vlib_cli_output (vm, "no ip4 table for fib-index %u", fib_index);
1769 st = session_table_get_for_fib_index (FIB_PROTOCOL_IP6, fib_index);
1771 vlib_cli_output (vm, "%U", format_session_table, st);
1773 vlib_cli_output (vm, "no ip6 table for fib-index %u", fib_index);
1777 vlib_cli_output (vm, "ip4 fib lookup tables:\n %U",
1778 format_session_lookup_tables, FIB_PROTOCOL_IP4);
1779 vlib_cli_output (vm, "ip6 fib lookup tables:\n %U",
1780 format_session_lookup_tables, FIB_PROTOCOL_IP6);
1786 VLIB_CLI_COMMAND (show_session_lookup_command, static) = {
1787 .path = "show session lookup",
1788 .short_help = "show session lookup [table <fib-index>]",
1789 .function = show_session_lookup_command_fn,
1793 session_lookup_init (void)
1796 * Allocate default table and map it to fib_index 0
1798 session_table_t *st = session_table_alloc ();
1799 vec_validate (fib_index_to_table_index[FIB_PROTOCOL_IP4], 0);
1800 fib_index_to_table_index[FIB_PROTOCOL_IP4][0] = session_table_index (st);
1801 st->active_fib_proto = FIB_PROTOCOL_IP4;
1802 session_table_init (st, FIB_PROTOCOL_IP4);
1803 st = session_table_alloc ();
1804 vec_validate (fib_index_to_table_index[FIB_PROTOCOL_IP6], 0);
1805 fib_index_to_table_index[FIB_PROTOCOL_IP6][0] = session_table_index (st);
1806 st->active_fib_proto = FIB_PROTOCOL_IP6;
1807 session_table_init (st, FIB_PROTOCOL_IP6);
1811 * fd.io coding-style-patch-verification: ON
1814 * eval: (c-set-style "gnu")