aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/snat/nat64_cli.c24
-rw-r--r--src/plugins/snat/nat64_db.c110
-rw-r--r--src/plugins/snat/nat64_db.h14
-rw-r--r--src/plugins/snat/snat.api12
-rw-r--r--test/test_snat.py20
-rw-r--r--test/vpp_papi_provider.py8
6 files changed, 123 insertions, 65 deletions
diff --git a/src/plugins/snat/nat64_cli.c b/src/plugins/snat/nat64_cli.c
index d48cb724..ca60b12c 100644
--- a/src/plugins/snat/nat64_cli.c
+++ b/src/plugins/snat/nat64_cli.c
@@ -433,7 +433,7 @@ nat64_show_bib_command_fn (vlib_main_t * vm,
unformat_input_t _line_input, *line_input = &_line_input;
clib_error_t *error = 0;
u32 proto = ~0;
- u8 p = 0;
+ u8 p = 255;
if (nm->is_disabled)
return clib_error_return (0,
@@ -445,6 +445,8 @@ nat64_show_bib_command_fn (vlib_main_t * vm,
if (unformat (line_input, "%U", unformat_snat_protocol, &proto))
p = snat_proto_to_ip_proto (proto);
else if (unformat (line_input, "unknown"))
+ p = 0;
+ else if (unformat (line_input, "all"))
;
else
{
@@ -453,7 +455,11 @@ nat64_show_bib_command_fn (vlib_main_t * vm,
goto done;
}
- vlib_cli_output (vm, "NAT64 %U BIB:", format_snat_protocol, proto);
+ if (p == 255)
+ vlib_cli_output (vm, "NAT64 BIB entries:");
+ else
+ vlib_cli_output (vm, "NAT64 %U BIB entries:", format_snat_protocol,
+ proto);
nat64_db_bib_walk (&nm->db, p, nat64_cli_bib_walk, vm);
done:
@@ -632,7 +638,7 @@ nat64_show_st_command_fn (vlib_main_t * vm,
unformat_input_t _line_input, *line_input = &_line_input;
clib_error_t *error = 0;
u32 proto = ~0;
- u8 p = 0;
+ u8 p = 255;
if (nm->is_disabled)
return clib_error_return (0,
@@ -644,6 +650,8 @@ nat64_show_st_command_fn (vlib_main_t * vm,
if (unformat (line_input, "%U", unformat_snat_protocol, &proto))
p = snat_proto_to_ip_proto (proto);
else if (unformat (line_input, "unknown"))
+ p = 0;
+ else if (unformat (line_input, "all"))
;
else
{
@@ -652,8 +660,10 @@ nat64_show_st_command_fn (vlib_main_t * vm,
goto done;
}
- vlib_cli_output (vm, "NAT64 %U session table:", format_snat_protocol,
- proto);
+ if (p == 255)
+ vlib_cli_output (vm, "NAT64 sessions:");
+ else
+ vlib_cli_output (vm, "NAT64 %U sessions:", format_snat_protocol, proto);
nat64_db_st_walk (&nm->db, p, nat64_cli_st_walk, vm);
done:
@@ -860,7 +870,7 @@ VLIB_CLI_COMMAND (nat64_add_del_static_bib_command, static) = {
?*/
VLIB_CLI_COMMAND (show_nat64_bib_command, static) = {
.path = "show nat64 bib",
- .short_help = "show nat64 bib tcp|udp|icmp|unknown",
+ .short_help = "show nat64 bib all|tcp|udp|icmp|unknown",
.function = nat64_show_bib_command_fn,
};
@@ -924,7 +934,7 @@ VLIB_CLI_COMMAND (show_nat64_timeouts_command, static) = {
?*/
VLIB_CLI_COMMAND (show_nat64_st_command, static) = {
.path = "show nat64 session table",
- .short_help = "show nat64 session table tcp|udp|icmp|unknown",
+ .short_help = "show nat64 session table all|tcp|udp|icmp|unknown",
.function = nat64_show_st_command_fn,
};
diff --git a/src/plugins/snat/nat64_db.c b/src/plugins/snat/nat64_db.c
index b6e199c6..9584827e 100644
--- a/src/plugins/snat/nat64_db.c
+++ b/src/plugins/snat/nat64_db.c
@@ -217,28 +217,49 @@ nat64_db_bib_walk (nat64_db_t * db, u8 proto,
{
nat64_db_bib_entry_t *bib, *bibe;
- switch (ip_proto_to_snat_proto (proto))
+ if (proto == 255)
{
-/* *INDENT-OFF* */
-#define _(N, i, n, s) \
- case SNAT_PROTOCOL_##N: \
+ /* *INDENT-OFF* */
+ #define _(N, i, n, s) \
bib = db->bib._##n##_bib; \
- break;
+ pool_foreach (bibe, bib, ({ \
+ if (fn (bibe, ctx)) \
+ return; \
+ }));
foreach_snat_protocol
-#undef _
-/* *INDENT-ON* */
- default:
+ #undef _
bib = db->bib._unk_proto_bib;
- break;
+ pool_foreach (bibe, bib, ({
+ if (fn (bibe, ctx))
+ return;
+ }));
+ /* *INDENT-ON* */
+ }
+ else
+ {
+ switch (ip_proto_to_snat_proto (proto))
+ {
+ /* *INDENT-OFF* */
+ #define _(N, i, n, s) \
+ case SNAT_PROTOCOL_##N: \
+ bib = db->bib._##n##_bib; \
+ break;
+ foreach_snat_protocol
+ #undef _
+ /* *INDENT-ON* */
+ default:
+ bib = db->bib._unk_proto_bib;
+ break;
+ }
+
+ /* *INDENT-OFF* */
+ pool_foreach (bibe, bib,
+ ({
+ if (fn (bibe, ctx))
+ return;
+ }));
+ /* *INDENT-ON* */
}
-
- /* *INDENT-OFF* */
- pool_foreach (bibe, bib,
- ({
- if (fn (bibe, ctx))
- return;
- }));
- /* *INDENT-ON* */
}
nat64_db_bib_entry_t *
@@ -270,28 +291,49 @@ nat64_db_st_walk (nat64_db_t * db, u8 proto,
{
nat64_db_st_entry_t *st, *ste;
- switch (ip_proto_to_snat_proto (proto))
+ if (proto == 255)
{
-/* *INDENT-OFF* */
-#define _(N, i, n, s) \
- case SNAT_PROTOCOL_##N: \
+ /* *INDENT-OFF* */
+ #define _(N, i, n, s) \
st = db->st._##n##_st; \
- break;
+ pool_foreach (ste, st, ({ \
+ if (fn (ste, ctx)) \
+ return; \
+ }));
foreach_snat_protocol
-#undef _
-/* *INDENT-ON* */
- default:
+ #undef _
st = db->st._unk_proto_st;
- break;
+ pool_foreach (ste, st, ({
+ if (fn (ste, ctx))
+ return;
+ }));
+ /* *INDENT-ON* */
+ }
+ else
+ {
+ switch (ip_proto_to_snat_proto (proto))
+ {
+ /* *INDENT-OFF* */
+ #define _(N, i, n, s) \
+ case SNAT_PROTOCOL_##N: \
+ st = db->st._##n##_st; \
+ break;
+ foreach_snat_protocol
+ #undef _
+ /* *INDENT-ON* */
+ default:
+ st = db->st._unk_proto_st;
+ break;
+ }
+
+ /* *INDENT-OFF* */
+ pool_foreach (ste, st,
+ ({
+ if (fn (ste, ctx))
+ return;
+ }));
+ /* *INDENT-ON* */
}
-
- /* *INDENT-OFF* */
- pool_foreach (ste, st,
- ({
- if (fn (ste, ctx))
- return;
- }));
- /* *INDENT-ON* */
}
nat64_db_st_entry_t *
diff --git a/src/plugins/snat/nat64_db.h b/src/plugins/snat/nat64_db.h
index 4511fb26..1e2dcc93 100644
--- a/src/plugins/snat/nat64_db.h
+++ b/src/plugins/snat/nat64_db.h
@@ -171,7 +171,12 @@ typedef int (*nat64_db_bib_walk_fn_t) (nat64_db_bib_entry_t * bibe,
* @brief Walk NAT64 BIB.
*
* @param db NAT64 DB.
- * @param proto L4 protocol.
+ * @param proto BIB L4 protocol:
+ * - 255 all BIBs
+ * - 6 TCP BIB
+ * - 17 UDP BIB
+ * - 1/58 ICMP BIB
+ * - otherwise "unknown" protocol BIB
* @param fn The function to invoke on each entry visited.
* @param ctx A context passed in the visit function.
*/
@@ -263,7 +268,12 @@ typedef int (*nat64_db_st_walk_fn_t) (nat64_db_st_entry_t * ste, void *ctx);
* @brief Walk NAT64 session table.
*
* @param db NAT64 DB.
- * @param proto L4 protocol.
+ * @param proto L4 protocol:
+ * - 255 all session tables
+ * - 6 TCP session table
+ * - 17 UDP session table
+ * - 1/58 ICMP session table
+ * - otherwise "unknown" protocol session table
* @param fn The function to invoke on each entry visited.
* @param ctx A context passed in the visit function.
*/
diff --git a/src/plugins/snat/snat.api b/src/plugins/snat/snat.api
index f68a5aaa..3c493dda 100644
--- a/src/plugins/snat/snat.api
+++ b/src/plugins/snat/snat.api
@@ -735,7 +735,11 @@ define nat64_interface_details {
/** \brief Dump NAT64 BIB
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
- @param proto - protocol of the BIB
+ @param proto - protocol of the BIB: 255 - all BIBs
+ 6 - TCP BIB
+ 17 - UDP BIB
+ 1/58 - ICMP BIB
+ otherwise - "unknown" protocol BIB
*/
define nat64_bib_dump {
u32 client_index;
@@ -816,7 +820,11 @@ define nat64_get_timeouts_reply {
/** \brief Dump NAT64 session table
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
- @param proto - protocol of the session table
+ @param proto - protocol of the session table: 255 - all STs
+ 6 - TCP ST
+ 17 - UDP ST
+ 1/58 - ICMP ST
+ otherwise - "unknown" proto ST
*/
define nat64_st_dump {
u32 client_index;
diff --git a/test/test_snat.py b/test/test_snat.py
index 8fd05fa8..eb47bbb8 100644
--- a/test/test_snat.py
+++ b/test/test_snat.py
@@ -3642,14 +3642,8 @@ class TestNAT64(MethodHolder):
"""
Return number of active NAT64 sessions.
"""
- ses_num = 0
- st = self.vapi.nat64_st_dump(IP_PROTOS.tcp)
- ses_num += len(st)
- st = self.vapi.nat64_st_dump(IP_PROTOS.udp)
- ses_num += len(st)
- st = self.vapi.nat64_st_dump(IP_PROTOS.icmp)
- ses_num += len(st)
- return ses_num
+ st = self.vapi.nat64_st_dump()
+ return len(st)
def clear_nat64(self):
"""
@@ -3716,14 +3710,8 @@ class TestNAT64(MethodHolder):
self.logger.info(self.vapi.cli("show nat64 pool"))
self.logger.info(self.vapi.cli("show nat64 interfaces"))
self.logger.info(self.vapi.cli("show nat64 prefix"))
- self.logger.info(self.vapi.cli("show nat64 bib tcp"))
- self.logger.info(self.vapi.cli("show nat64 bib udp"))
- self.logger.info(self.vapi.cli("show nat64 bib icmp"))
- self.logger.info(self.vapi.cli("show nat64 bib unknown"))
- self.logger.info(self.vapi.cli("show nat64 session table tcp"))
- self.logger.info(self.vapi.cli("show nat64 session table udp"))
- self.logger.info(self.vapi.cli("show nat64 session table icmp"))
- self.logger.info(self.vapi.cli("show nat64 session table unknown"))
+ self.logger.info(self.vapi.cli("show nat64 bib all"))
+ self.logger.info(self.vapi.cli("show nat64 session table all"))
self.clear_nat64()
if __name__ == '__main__':
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index c99d4583..1daa2a9e 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -1466,10 +1466,10 @@ class VppPapiProvider(object):
'proto': protocol,
'is_add': is_add})
- def nat64_bib_dump(self, protocol):
+ def nat64_bib_dump(self, protocol=255):
"""Dump NAT64 BIB
- :param protocol: IP protocol
+ :param protocol: IP protocol (Default value = 255, all BIBs)
:returns: Dictionary of NAT64 BIB entries
"""
return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
@@ -1499,10 +1499,10 @@ class VppPapiProvider(object):
"""
return self.api(self.papi.nat64_get_timeouts, {})
- def nat64_st_dump(self, protocol):
+ def nat64_st_dump(self, protocol=255):
"""Dump NAT64 session table
- :param protocol: IP protocol
+ :param protocol: IP protocol (Default value = 255, all STs)
:returns: Dictionary of NAT64 sesstion table entries
"""
return self.api(self.papi.nat64_st_dump, {'proto': protocol})