From 206acf84d6a04590e385f427edba1094c3bdf195 Mon Sep 17 00:00:00 2001 From: Mohsin Kazmi Date: Mon, 6 Apr 2020 14:19:54 +0200 Subject: tap: add initial support for tun Type: feature Change-Id: I699a01ac925fe5c475a36032edb7018618bb4dd4 Signed-off-by: Mohsin Kazmi --- src/vnet/devices/tap/cli.c | 54 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'src/vnet/devices/tap/cli.c') diff --git a/src/vnet/devices/tap/cli.c b/src/vnet/devices/tap/cli.c index 68b8cef2a21..40086a588aa 100644 --- a/src/vnet/devices/tap/cli.c +++ b/src/vnet/devices/tap/cli.c @@ -96,6 +96,8 @@ tap_create_command_fn (vlib_main_t * vm, unformat_input_t * input, args.tap_flags |= TAP_FLAG_PERSIST; else if (unformat (line_input, "attach")) args.tap_flags |= TAP_FLAG_ATTACH; + else if (unformat (line_input, "tun")) + args.tap_flags |= TAP_FLAG_TUN; else if (unformat (line_input, "hw-addr %U", unformat_ethernet_address, args.mac_addr.bytes)) args.mac_addr_set = 1; @@ -136,7 +138,7 @@ VLIB_CLI_COMMAND (tap_create_command, static) = { "[host-ip6-addr ] [host-ip4-gw ] " "[host-ip6-gw ] [host-mac-addr ] " "[host-if-name ] [host-mtu-size ] [no-gso|gso|csum-offload] " - "[persist] [attach]", + "[persist] [attach] [tun]", .function = tap_create_command_fn, }; /* *INDENT-ON* */ @@ -306,6 +308,56 @@ VLIB_CLI_COMMAND (tap_show_command, static) = { }; /* *INDENT-ON* */ +static clib_error_t * +tun_show_command_fn (vlib_main_t * vm, unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + virtio_main_t *mm = &virtio_main; + virtio_if_t *vif; + vnet_main_t *vnm = vnet_get_main (); + int show_descr = 0; + clib_error_t *error = 0; + u32 hw_if_index, *hw_if_indices = 0; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat + (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) + vec_add1 (hw_if_indices, hw_if_index); + else if (unformat (input, "descriptors")) + show_descr = 1; + else + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, input); + goto done; + } + } + + if (vec_len (hw_if_indices) == 0) + { + /* *INDENT-OFF* */ + pool_foreach (vif, mm->interfaces, + vec_add1 (hw_if_indices, vif->hw_if_index); + ); + /* *INDENT-ON* */ + } + + virtio_show (vm, hw_if_indices, show_descr, VIRTIO_IF_TYPE_TUN); + +done: + vec_free (hw_if_indices); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (tun_show_command, static) = { + .path = "show tun", + .short_help = "show tun {] [descriptors]", + .function = tun_show_command_fn, +}; +/* *INDENT-ON* */ + clib_error_t * tap_cli_init (vlib_main_t * vm) { -- cgit 1.2.3-korg