summaryrefslogtreecommitdiffstats
path: root/src/vnet/devices/virtio/cli.c
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2017-12-01 13:34:24 +0100
committerDamjan Marion <dmarion.lists@gmail.com>2017-12-02 10:11:25 +0000
commit91c6ef7cae2d20ca17a69003a44090614412c63f (patch)
tree28a0ae8030e840a0bc8f65e28f9d5bc2868bf39d /src/vnet/devices/virtio/cli.c
parent9fa1581cc40b656b6e00d77479fc2424cd50a126 (diff)
tap_v2: multiple improvements
- add support for assigning tap interface to the bridge - add support for assigning tap interface host side ip4 and ip6 address - host namespace can be specified as PID (pid:12345) or full path to file - automatically bring linux interface up Change-Id: I1cf7c3cad9a740e430cc1b9c2bb0aad0ba4cc8d8 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vnet/devices/virtio/cli.c')
-rw-r--r--src/vnet/devices/virtio/cli.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/src/vnet/devices/virtio/cli.c b/src/vnet/devices/virtio/cli.c
index 0c1b75f8c4e..efd14355627 100644
--- a/src/vnet/devices/virtio/cli.c
+++ b/src/vnet/devices/virtio/cli.c
@@ -22,6 +22,9 @@
#include <vlib/vlib.h>
#include <vlib/unix/unix.h>
#include <vnet/ethernet/ethernet.h>
+#include <vnet/ip/ip4_packet.h>
+#include <vnet/ip/ip6_packet.h>
+#include <vnet/ip/format.h>
#include <linux/virtio_net.h>
#include <linux/vhost.h>
#include <vnet/devices/virtio/virtio.h>
@@ -32,8 +35,8 @@ tap_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
vlib_cli_command_t * cmd)
{
unformat_input_t _line_input, *line_input = &_line_input;
- int rv;
tap_create_if_args_t args = { 0 };
+ int ip_addr_set = 0;
/* Get a line of input. */
if (!unformat_user (input, unformat_line_input, line_input))
@@ -43,8 +46,18 @@ tap_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
{
if (unformat (line_input, "name %s", &args.name))
;
- else if (unformat (line_input, "host-ns %s", &args.net_ns))
+ else if (unformat (line_input, "host-ns %s", &args.host_namespace))
+ ;
+ else if (unformat (line_input, "host-bridge %s", &args.host_bridge))
;
+ else if (unformat (line_input, "host-ip4-addr %U/%d",
+ unformat_ip4_address, &args.host_ip4_addr,
+ &args.host_ip4_prefix_len))
+ ip_addr_set = 1;
+ else if (unformat (line_input, "host-ip6-addr %U/%d",
+ unformat_ip6_address, &args.host_ip6_addr,
+ &args.host_ip6_prefix_len))
+ ip_addr_set = 1;
else if (unformat (line_input, "rx-ring-size %d", &args.rx_ring_sz))
;
else if (unformat (line_input, "tx-ring-size %d", &args.tx_ring_sz))
@@ -58,34 +71,27 @@ tap_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
}
unformat_free (line_input);
- rv = tap_create_if (vm, &args);
+ if (ip_addr_set && args.host_bridge)
+ return clib_error_return (0, "Please specify either host ip address or "
+ "host bridge");
+
+ tap_create_if (vm, &args);
vec_free (args.name);
+ vec_free (args.host_namespace);
+ vec_free (args.host_bridge);
- if (rv == VNET_API_ERROR_SYSCALL_ERROR_1)
- return clib_error_return_unix (0, "open '/dev/vhost-net'");
- else if (rv == VNET_API_ERROR_SYSCALL_ERROR_2)
- return clib_error_return_unix (0, "open '/dev/net/tun'");
- else if (rv == VNET_API_ERROR_UNSUPPORTED)
- return clib_error_return (0, "vhost-net backend doesn't support needed"
- " features");
- else if (rv == VNET_API_ERROR_NAMESPACE_CREATE)
- return clib_error_return (0, "failed to create netlink namespace");
- else if (rv == VNET_API_ERROR_VIRTIO_INIT)
- return clib_error_return (0, "failed to init virtio ring");
- else if (rv == VNET_API_ERROR_INVALID_REGISTRATION)
- return clib_error_return (0, "failed to register interface");
- else if (rv != 0)
- return clib_error_return (0, "error on creating tap interface");
+ return args.error;
- return 0;
}
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (tap_create_command, static) = {
.path = "create tap",
- .short_help = "create tap {name <if-name>} [hw-addr <mac-address>]"
- "[rx-ring-size <size>] [tx-ring-size <size>] [host-ns <netns>]",
+ .short_help = "create tap {name <if-name>} [hw-addr <mac-address>] "
+ "[rx-ring-size <size>] [tx-ring-size <size>] [host-ns <netns>] "
+ "[host-bridge <bridge-name>] [host-ip4-addr <ip4addr/mask>] "
+ "[host-ip6-addr <ip6-addr]",
.function = tap_create_command_fn,
};
/* *INDENT-ON* */
s="p">[0] # don't ask to debug SanityTestCase @classmethod def wait_for_enter(cls, pid=0): pass @classmethod def _debug_quit(cls): try: cls.vpp.poll() except AttributeError: pass if __name__ == '__main__': rc = 0 tc = SanityTestCase x, y = Pipe() reporter = KeepAliveReporter() reporter.pipe = y try: tc.setUpClass() except VppDiedError: rc = -1 else: try: tc.tearDownClass() except Exception: rc = -1 x.close() y.close() if rc == 0: print('Sanity test case passed.') else: print('Sanity test case failed.') sys.exit(rc)