diff options
author | Martin Gálik <magalik@cisco.com> | 2017-04-25 01:25:08 -0700 |
---|---|---|
committer | Martin Gálik <magalik@cisco.com> | 2017-04-26 05:17:42 -0700 |
commit | 9806eae1f5f3953f7ac2c5bd07061a94387d757e (patch) | |
tree | 7eb4650f32e7bd0e157f3e1cd12213f366f78151 /src | |
parent | 6bc8c6493c8e7e1401130f8c9ca34c9b2915a7ad (diff) |
CGN: Session dump, test naming for ports fixed
Change-Id: Ib542b2b3ee023fbe3d0e01ceaf4b4ab7a0ec80dc
Signed-off-by: Martin Gálik <magalik@cisco.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/snat/snat.api | 35 | ||||
-rw-r--r-- | src/plugins/snat/snat.c | 69 | ||||
-rw-r--r-- | src/plugins/snat/snat_test.c | 52 |
3 files changed, 153 insertions, 3 deletions
diff --git a/src/plugins/snat/snat.api b/src/plugins/snat/snat.api index 5990eae5a24..e92675de867 100644 --- a/src/plugins/snat/snat.api +++ b/src/plugins/snat/snat.api @@ -565,3 +565,38 @@ autoreply define snat_det_close_session_in { u8 ext_addr[16]; u16 ext_port; }; + +/** \brief Dump S-NAT deterministic sessions + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_ip4 - 1 if address type is IPv4 + @param user_addr - address of an inside user whose sessions to dump +*/ +define snat_det_session_dump { + u32 client_index; + u32 context; + u8 is_ip4; + u8 user_addr[16]; +}; + +/** \brief S-NAT deterministic sessions reply + @param context - sender context, to match reply w/ request + @param is_ip4 - 1 if address type is IPv4 + @param in_port - inside port + @param ext_addr - external host address + @param ext_port - external host port + @param out_port - outside NAT port + @param state - session state + @param expire - session expiration timestamp +*/ +define snat_det_session_details { + u32 client_index; + u32 context; + u8 is_ip4; + u16 in_port; + u8 ext_addr[16]; + u16 ext_port; + u16 out_port; + u8 state; + u32 expire; +}; diff --git a/src/plugins/snat/snat.c b/src/plugins/snat/snat.c index 594afa62c80..c6783e47b6d 100644 --- a/src/plugins/snat/snat.c +++ b/src/plugins/snat/snat.c @@ -1811,6 +1811,72 @@ static void *vl_api_snat_det_close_session_in_t_print FINISH; } +static void +send_snat_det_session_details +(snat_det_session_t * s, unix_shared_memory_queue_t * q, u32 context) +{ + vl_api_snat_det_session_details_t * rmp; + snat_main_t * sm = &snat_main; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_SNAT_DET_SESSION_DETAILS+sm->msg_id_base); + rmp->is_ip4 = 1; + rmp->in_port = s->in_port; + clib_memcpy (rmp->ext_addr, &s->out.ext_host_addr, 4); + rmp->ext_port = s->out.ext_host_port; + rmp->out_port = s->out.out_port; + rmp->state = s->state; + rmp->expire = ntohl (s->expire); + rmp->context = context; + + vl_msg_api_send_shmem (q, (u8 *) & rmp); +} + +static void +vl_api_snat_det_session_dump_t_handler +(vl_api_snat_det_session_dump_t * mp) +{ + unix_shared_memory_queue_t *q; + snat_main_t * sm = &snat_main; + ip4_address_t user_addr; + snat_det_map_t * dm; + snat_det_session_t * s, empty_ses; + u16 i; + + q = vl_api_client_index_to_input_queue (mp->client_index); + if (q == 0) + return; + if (!mp->is_ip4) + return; + + memset (&empty_ses, 0, sizeof (empty_ses)); + clib_memcpy (&user_addr, mp->user_addr, 4); + dm = snat_det_map_by_user (sm, &user_addr); + if (!dm) + return; + + s = dm->sessions + snat_det_user_ses_offset (&user_addr, dm->in_plen); + for (i = 0; i < SNAT_DET_SES_PER_USER; i++) + { + if (s->out.as_u64) + send_snat_det_session_details (s, q, mp->context); + s++; + } +} + +static void *vl_api_snat_det_session_dump_t_print +(vl_api_snat_det_session_dump_t * mp, void * handle) +{ + u8 *s; + + s = format (0, "SCRIPT: snat_det_session_dump "); + s = format (s, "user_addr %U\n", + format_ip4_address, mp->user_addr); + + FINISH; +} + /* List of message types that this plugin understands */ #define foreach_snat_plugin_api_msg \ _(SNAT_ADD_ADDRESS_RANGE, snat_add_address_range) \ @@ -1835,7 +1901,8 @@ _(SNAT_DET_MAP_DUMP, snat_det_map_dump) \ _(SNAT_DET_SET_TIMEOUTS, snat_det_set_timeouts) \ _(SNAT_DET_GET_TIMEOUTS, snat_det_get_timeouts) \ _(SNAT_DET_CLOSE_SESSION_OUT, snat_det_close_session_out) \ -_(SNAT_DET_CLOSE_SESSION_IN, snat_det_close_session_in) +_(SNAT_DET_CLOSE_SESSION_IN, snat_det_close_session_in) \ +_(SNAT_DET_SESSION_DUMP, snat_det_session_dump) /* Set up the API message handling tables */ diff --git a/src/plugins/snat/snat_test.c b/src/plugins/snat/snat_test.c index 14e8d1990b7..905b8fac66c 100644 --- a/src/plugins/snat/snat_test.c +++ b/src/plugins/snat/snat_test.c @@ -121,7 +121,8 @@ _(SNAT_DET_GET_TIMEOUTS_REPLY, snat_det_get_timeouts_reply) \ _(SNAT_DET_CLOSE_SESSION_OUT_REPLY, \ snat_det_close_session_out_reply) \ _(SNAT_DET_CLOSE_SESSION_IN_REPLY, \ - snat_det_close_session_in_reply) + snat_det_close_session_in_reply) \ +_(SNAT_DET_SESSION_DETAILS, snat_det_session_details) static int api_snat_add_address_range (vat_main_t * vam) { @@ -1033,6 +1034,52 @@ static int api_snat_det_close_session_in (vat_main_t * vam) return ret; } +static void vl_api_snat_det_session_details_t_handler + (vl_api_snat_det_session_details_t *mp) +{ + snat_test_main_t * sm = &snat_test_main; + vat_main_t *vam = sm->vat_main; + + fformat(vam->ofp, "deterministic session, external host address %U, " + "external host port %d, outer port %d, inside port %d", + format_ip4_address, mp->ext_addr, mp->ext_port, + mp->out_port, mp->in_port); +} + +static int api_snat_det_session_dump(vat_main_t * vam) +{ + unformat_input_t* i = vam->input; + vl_api_snat_det_session_dump_t * mp; + vl_api_snat_control_ping_t *mp_ping; + ip4_address_t user_addr; + int ret; + + if (vam->json_output) + { + clib_warning ("JSON output not supported for snat_det_session_dump"); + return -99; + } + + if (unformat (i, "user_addr %U", unformat_ip4_address, &user_addr)) + ; + else + { + clib_warning ("unknown input '%U'", format_unformat_error, i); + return -99; + } + + M(SNAT_DET_SESSION_DUMP, mp); + clib_memcpy (&mp->user_addr, &user_addr, 4); + S(mp); + + /* Use a control ping for synchronization */ + M(SNAT_CONTROL_PING, mp_ping); + S(mp_ping); + + W (ret); + return ret; +} + /* * List of messages that the api test plugin sends, * and that the data plane plugin processes @@ -1069,7 +1116,8 @@ _(snat_det_get_timeouts, "") \ _(snat_det_close_session_out, "<out_addr>:<out_port> " \ "<ext_addr>:<ext_port>") \ _(snat_det_close_session_in, "<in_addr>:<in_port> " \ - "<out_addr>:<out_port>") + "<out_addr>:<out_port>") \ +_(snat_det_session_dump, "ip_address <user_addr>") static void snat_vat_api_hookup (vat_main_t *vam) |