+
+static clib_error_t *
+lb_set_interface_nat_command_fn (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd,
+ u8 is_nat6)
+{
+ unformat_input_t _line_input, *line_input = &_line_input;
+ vnet_main_t * vnm = vnet_get_main();
+ clib_error_t * error = 0;
+ u32 _sw_if_index, *sw_if_index = &_sw_if_index;
+ u32 * inside_sw_if_indices = 0;
+ int is_del = 0;
+
+ /* Get a line of input. */
+ if (!unformat_user (input, unformat_line_input, line_input))
+ return 0;
+
+ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (line_input, "in %U", unformat_vnet_sw_interface,
+ vnm, sw_if_index))
+ vec_add1 (inside_sw_if_indices, *sw_if_index);
+ else if (unformat (line_input, "del"))
+ is_del = 1;
+ else
+ {
+ error = clib_error_return (0, "unknown input '%U'",
+ format_unformat_error, line_input);
+ goto done;
+ }
+ }
+
+ vec_foreach (sw_if_index, inside_sw_if_indices)
+ {
+ if (!is_nat6)
+ {
+ if (lb_nat4_interface_add_del (*sw_if_index, is_del))
+ {
+ error = clib_error_return(
+ 0, "%s %U failed", is_del ? "del" : "add",
+ format_vnet_sw_interface_name, vnm,
+ vnet_get_sw_interface (vnm, *sw_if_index));
+ goto done;
+ }
+ }
+ else
+ {
+ if (lb_nat6_interface_add_del (*sw_if_index, is_del))
+ {
+ error = clib_error_return(
+ 0, "%s %U failed", is_del ? "del" : "add",
+ format_vnet_sw_interface_name, vnm,
+ vnet_get_sw_interface (vnm, *sw_if_index));
+ goto done;
+ }
+ }
+ }
+
+done:
+ unformat_free (line_input);
+ vec_free (inside_sw_if_indices);
+
+ return error;
+}
+
+static clib_error_t *
+lb_set_interface_nat4_command_fn (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ return lb_set_interface_nat_command_fn(vm, input, cmd, 0);
+}
+
+VLIB_CLI_COMMAND (lb_set_interface_nat4_command, static) = {
+ .path = "lb set interface nat4",
+ .function = lb_set_interface_nat4_command_fn,
+ .short_help = "lb set interface nat4 in <intfc> [del]",
+};
+
+static clib_error_t *
+lb_set_interface_nat6_command_fn (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ return lb_set_interface_nat_command_fn(vm, input, cmd, 1);
+}
+
+VLIB_CLI_COMMAND (lb_set_interface_nat6_command, static) = {
+ .path = "lb set interface nat6",
+ .function = lb_set_interface_nat6_command_fn,
+ .short_help = "lb set interface nat6 in <intfc> [del]",
+};
+
+static clib_error_t *
+lb_flowtable_flush_command_fn (vlib_main_t * vm,
+ unformat_input_t * input, vlib_cli_command_t * cmd)
+{
+ u32 thread_index;
+ vlib_thread_main_t *tm = vlib_get_thread_main();
+ lb_main_t *lbm = &lb_main;
+
+ for(thread_index = 0; thread_index < tm->n_vlib_mains; thread_index++ ) {
+ lb_hash_t *h = lbm->per_cpu[thread_index].sticky_ht;
+ if (h != NULL) {
+ u32 i;
+ lb_hash_bucket_t *b;
+
+ lb_hash_foreach_entry(h, b, i) {
+ vlib_refcount_add(&lbm->as_refcount, thread_index, b->value[i], -1);
+ vlib_refcount_add(&lbm->as_refcount, thread_index, 0, 1);
+ }
+
+ lb_hash_free(h);
+ lbm->per_cpu[thread_index].sticky_ht = 0;
+ }
+ }
+
+ return NULL;
+}
+
+/*
+ * flush all lb flowtables
+ * This is indented for debug and unit-tests purposes only
+ */
+VLIB_CLI_COMMAND (lb_flowtable_flush_command, static) =
+{
+ .path = "test lb flowtable flush",
+ .short_help = "test lb flowtable flush",
+ .function = lb_flowtable_flush_command_fn,
+};