19 #include <sys/ioctl.h> 28 #include <linux/virtio_net.h> 29 #include <linux/vhost.h> 55 else if (
unformat (line_input,
"host-mac-addr %U",
60 else if (
unformat (line_input,
"host-ip4-addr %U/%d",
64 else if (
unformat (line_input,
"host-ip4-gw %U",
67 else if (
unformat (line_input,
"host-ip6-addr %U/%d",
71 else if (
unformat (line_input,
"host-ip6-gw %U",
78 else if (
unformat (line_input,
"hw-addr %U",
107 .path =
"create tap",
108 .short_help =
"create tap {id <if-id>} [hw-addr <mac-address>] " 109 "[rx-ring-size <size>] [tx-ring-size <size>] [host-ns <netns>] " 110 "[host-bridge <bridge-name>] [host-ip4-addr <ip4addr/mask>] " 111 "[host-ip6-addr <ip6-addr>] [host-ip4-gw <ip4-addr>] " 112 "[host-ip6-gw <ip6-addr>] [host-if-name <name>]",
132 if (
unformat (line_input,
"sw_if_index %d", &sw_if_index))
143 if (sw_if_index == ~0)
145 "please specify interface name or sw_if_index");
148 if (rv == VNET_API_ERROR_INVALID_SW_IF_INDEX)
159 .path =
"delete tap",
160 .short_help =
"delete tap {<interface> | sw_if_index <sw_idx>}",
174 u32 hw_if_index, *hw_if_indices = 0;
182 struct feat_struct *feat_entry;
184 static struct feat_struct feat_array[] = {
185 #define _(s,b) { .str = #s, .bit = b, }, 191 struct feat_struct *flag_entry;
192 static struct feat_struct flags_array[] = {
193 #define _(b,e,s) { .bit = b, .str = s, }, 203 vec_add1 (hw_if_indices, hw_if_index);
204 else if (
unformat (input,
"descriptors"))
214 if (
vec_len (hw_if_indices) == 0)
223 for (hw_if_index = 0; hw_if_index <
vec_len (hw_if_indices); hw_if_index++)
235 flag_entry = (
struct feat_struct *) &flags_array;
236 while (flag_entry->str)
238 if (vif->
flags & (1ULL << flag_entry->bit))
246 feat_entry = (
struct feat_struct *) &feat_array;
247 while (feat_entry->str)
249 if (vif->
features & (1ULL << feat_entry->bit))
255 feat_entry = (
struct feat_struct *) &feat_array;
256 while (feat_entry->str)
269 " qsz %d, last_used_idx %d, desc_next %d, desc_in_use %d",
273 " avail.flags 0x%x avail.idx %d used.flags 0x%x used.idx %d",
275 vring->
used->flags, vring->
used->idx);
282 " id addr len flags next user_addr\n");
284 " ===== ================== ===== ====== ===== ==================\n");
286 for (j = 0; j < vring->
size; j++)
288 struct vring_desc *desc = &vring->
desc[j];
290 " %-5d 0x%016lx %-5d 0x%04x %-5d 0x%016lx\n",
293 desc->flags, desc->next, desc->addr);
306 .short_help =
"show tap {<interface>] [descriptors]",
unformat_function_t unformat_vnet_hw_interface
#define vec_foreach_index(var, v)
Iterate over vector indices.
ip4_address_t host_ip4_addr
vnet_main_t * vnet_get_main(void)
static clib_error_t * tap_show_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define foreach_virtio_net_features
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
unformat_function_t unformat_vnet_sw_interface
format_function_t format_vnet_sw_if_index_name
clib_error_t * tap_cli_init(vlib_main_t *vm)
static clib_error_t * tap_delete_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
struct vring_avail * avail
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
#define VLIB_INIT_FUNCTION(x)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
int tap_delete_if(vlib_main_t *vm, u32 sw_if_index)
#define clib_error_return(e, args...)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
ip4_address_t host_ip4_gw
ip6_address_t host_ip6_addr
#define vec_free(V)
Free vector's memory (no header).
static clib_error_t * tap_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define VLIB_CLI_COMMAND(x,...)
uword unformat_ethernet_address(unformat_input_t *input, va_list *args)
ip6_address_t host_ip6_gw
virtio_main_t virtio_main
void tap_create_if(vlib_main_t *vm, tap_create_if_args_t *args)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)