diff options
author | Nathan Skrzypczak <nathan.skrzypczak@gmail.com> | 2021-02-25 11:01:41 +0100 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2021-02-26 01:55:07 +0000 |
commit | 27647a27c7b1e800547e3a3ea97b099b25618177 (patch) | |
tree | 9d5a9cb030eb3e1f6616d5dd5ce9944ec6811c68 /src/plugins/cnat/cnat_session.c | |
parent | b80d67ca43e13305734aebf7a493bb6fbb8db31e (diff) |
cnat: fixes & prepare maglev
Notable changes:
- ip[46]-cnat-snat is renamed to cnat-snat-ip[46]
- indent fixes
- common trace primitives
- bihash is now 40_56 with alias
Type: refactor
Change-Id: I0a82cfe3b40efd96473e51061d7135ffe412ddfc
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
Diffstat (limited to 'src/plugins/cnat/cnat_session.c')
-rw-r--r-- | src/plugins/cnat/cnat_session.c | 74 |
1 files changed, 44 insertions, 30 deletions
diff --git a/src/plugins/cnat/cnat_session.c b/src/plugins/cnat/cnat_session.c index c3d8aa7eb3d..bb04de07c82 100644 --- a/src/plugins/cnat/cnat_session.c +++ b/src/plugins/cnat/cnat_session.c @@ -20,8 +20,7 @@ #include <vppinfra/bihash_template.h> #include <vppinfra/bihash_template.c> - -clib_bihash_40_48_t cnat_session_db; +cnat_bihash_t cnat_session_db; void (*cnat_free_port_cb) (u16 port, ip_protocol_t iproto); typedef struct cnat_session_walk_ctx_t_ @@ -54,7 +53,7 @@ cnat_session_walk (cnat_session_walk_cb_t cb, void *ctx) typedef struct cnat_session_purge_walk_t_ { - clib_bihash_kv_40_48_t *keys; + cnat_bihash_kv_t *keys; } cnat_session_purge_walk_ctx_t; static int @@ -68,6 +67,28 @@ cnat_session_purge_walk (BVT (clib_bihash_kv) * key, void *arg) } u8 * +format_cnat_session_location (u8 *s, va_list *args) +{ + u8 location = va_arg (*args, int); + switch (location) + { + case CNAT_LOCATION_INPUT: + s = format (s, "input"); + break; + case CNAT_LOCATION_OUTPUT: + s = format (s, "output"); + break; + case CNAT_LOCATION_FIB: + s = format (s, "fib"); + break; + default: + s = format (s, "unknown"); + break; + } + return (s); +} + +u8 * format_cnat_session (u8 * s, va_list * args) { cnat_session_t *sess = va_arg (*args, cnat_session_t *); @@ -76,19 +97,17 @@ format_cnat_session (u8 * s, va_list * args) if (!pool_is_free_index (cnat_timestamps, sess->value.cs_ts_index)) ts = cnat_timestamp_exp (sess->value.cs_ts_index); - s = - format (s, - "session:[%U;%d -> %U;%d, %U] => %U;%d -> %U;%d lb:%d age:%f", - format_ip46_address, &sess->key.cs_ip[VLIB_RX], IP46_TYPE_ANY, - clib_host_to_net_u16 (sess->key.cs_port[VLIB_RX]), - format_ip46_address, &sess->key.cs_ip[VLIB_TX], IP46_TYPE_ANY, - clib_host_to_net_u16 (sess->key.cs_port[VLIB_TX]), - format_ip_protocol, sess->key.cs_proto, format_ip46_address, - &sess->value.cs_ip[VLIB_RX], IP46_TYPE_ANY, - clib_host_to_net_u16 (sess->value.cs_port[VLIB_RX]), - format_ip46_address, &sess->value.cs_ip[VLIB_TX], IP46_TYPE_ANY, - clib_host_to_net_u16 (sess->value.cs_port[VLIB_TX]), - sess->value.cs_lbi, ts); + s = format ( + s, "session:[%U;%d -> %U;%d, %U] => %U;%d -> %U;%d %U lb:%d age:%f", + format_ip46_address, &sess->key.cs_ip[VLIB_RX], IP46_TYPE_ANY, + clib_host_to_net_u16 (sess->key.cs_port[VLIB_RX]), format_ip46_address, + &sess->key.cs_ip[VLIB_TX], IP46_TYPE_ANY, + clib_host_to_net_u16 (sess->key.cs_port[VLIB_TX]), format_ip_protocol, + sess->key.cs_proto, format_ip46_address, &sess->value.cs_ip[VLIB_RX], + IP46_TYPE_ANY, clib_host_to_net_u16 (sess->value.cs_port[VLIB_RX]), + format_ip46_address, &sess->value.cs_ip[VLIB_TX], IP46_TYPE_ANY, + clib_host_to_net_u16 (sess->value.cs_port[VLIB_TX]), + format_cnat_session_location, sess->key.cs_loc, sess->value.cs_lbi, ts); return (s); } @@ -114,19 +133,17 @@ cnat_session_show (vlib_main_t * vm, return (NULL); } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (cnat_session_show_cmd_node, static) = { .path = "show cnat session", .function = cnat_session_show, .short_help = "show cnat session", .is_mp_safe = 1, }; -/* *INDENT-ON* */ void cnat_session_free (cnat_session_t * session) { - clib_bihash_kv_40_48_t *bkey = (clib_bihash_kv_40_48_t *) session; + cnat_bihash_kv_t *bkey = (cnat_bihash_kv_t *) session; /* age it */ if (session->value.flags & CNAT_SESSION_FLAG_ALLOC_PORT) cnat_free_port_cb (session->value.cs_port[VLIB_RX], @@ -135,7 +152,7 @@ cnat_session_free (cnat_session_t * session) cnat_client_free_by_ip (&session->key.cs_ip[VLIB_TX], session->key.cs_af); cnat_timestamp_free (session->value.cs_ts_index); - clib_bihash_add_del_40_48 (&cnat_session_db, bkey, 0 /* is_add */ ); + cnat_bihash_add_del (&cnat_session_db, bkey, 0 /* is_add */); } int @@ -143,7 +160,7 @@ cnat_session_purge (void) { /* flush all the session from the DB */ cnat_session_purge_walk_ctx_t ctx = { }; - clib_bihash_kv_40_48_t *key; + cnat_bihash_kv_t *key; BV (clib_bihash_foreach_key_value_pair) (&cnat_session_db, cnat_session_purge_walk, &ctx); @@ -242,25 +259,22 @@ cnat_timestamp_show (vlib_main_t * vm, { cnat_timestamp_t *ts; clib_rwlock_reader_lock (&cnat_main.ts_lock); - /* *INDENT-OFF* */ - pool_foreach (ts, cnat_timestamps) { - vlib_cli_output (vm, "[%d] last_seen:%f lifetime:%u ref:%u", - ts - cnat_timestamps, - ts->last_seen, ts->lifetime, ts->refcnt); - } - /* *INDENT-ON* */ + pool_foreach (ts, cnat_timestamps) + { + vlib_cli_output (vm, "[%d] last_seen:%f lifetime:%u ref:%u", + ts - cnat_timestamps, ts->last_seen, ts->lifetime, + ts->refcnt); + } clib_rwlock_reader_unlock (&cnat_main.ts_lock); return (NULL); } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (cnat_timestamp_show_cmd, static) = { .path = "show cnat timestamp", .function = cnat_timestamp_show, .short_help = "show cnat timestamp", .is_mp_safe = 1, }; -/* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON |