summaryrefslogtreecommitdiffstats
path: root/src/vnet/unix/tapcli.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/unix/tapcli.c')
-rw-r--r--src/vnet/unix/tapcli.c923
1 files changed, 495 insertions, 428 deletions
diff --git a/src/vnet/unix/tapcli.c b/src/vnet/unix/tapcli.c
index 3ad8338a200..10a86a457e8 100644
--- a/src/vnet/unix/tapcli.c
+++ b/src/vnet/unix/tapcli.c
@@ -49,12 +49,13 @@ static vnet_hw_interface_class_t tapcli_interface_class;
static vlib_node_registration_t tapcli_rx_node;
static void tapcli_nopunt_frame (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame);
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame);
/**
* @brief Struct for the tapcli interface
*/
-typedef struct {
+typedef struct
+{
u32 unix_fd;
u32 clib_file_index;
u32 provision_fd;
@@ -71,7 +72,8 @@ typedef struct {
/**
* @brief Struct for RX trace
*/
-typedef struct {
+typedef struct
+{
u16 sw_if_index;
} tapcli_rx_trace_t;
@@ -84,14 +86,14 @@ typedef struct {
* @return *s - u8 - formatted string
*
*/
-u8 * format_tapcli_rx_trace (u8 * s, va_list * va)
+u8 *
+format_tapcli_rx_trace (u8 * s, va_list * va)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
- vnet_main_t * vnm = vnet_get_main();
- tapcli_rx_trace_t * t = va_arg (*va, tapcli_rx_trace_t *);
- s = format (s, "%U", format_vnet_sw_if_index_name,
- vnm, t->sw_if_index);
+ vnet_main_t *vnm = vnet_get_main ();
+ tapcli_rx_trace_t *t = va_arg (*va, tapcli_rx_trace_t *);
+ s = format (s, "%U", format_vnet_sw_if_index_name, vnm, t->sw_if_index);
return s;
}
@@ -102,18 +104,19 @@ typedef struct
{
/** Vector of VLIB rx buffers to use. We allocate them in blocks
of VLIB_FRAME_SIZE (256). */
- u32 * rx_buffers;
+ u32 *rx_buffers;
/** Vector of iovecs for readv/writev calls. */
- struct iovec * iovecs;
+ struct iovec *iovecs;
} tapcli_per_thread_t;
/**
* @brief TAPCLI main state struct
*/
-typedef struct {
+typedef struct
+{
/** per thread variables */
- tapcli_per_thread_t * threads;
+ tapcli_per_thread_t *threads;
/** tap device destination MAC address. Required, or Linux drops pkts */
u8 ether_dst_mac[6];
@@ -122,30 +125,30 @@ typedef struct {
u32 mtu_bytes, mtu_buffers;
/** Vector of tap interfaces */
- tapcli_interface_t * tapcli_interfaces;
+ tapcli_interface_t *tapcli_interfaces;
/** Vector of deleted tap interfaces */
- u32 * tapcli_inactive_interfaces;
+ u32 *tapcli_inactive_interfaces;
/** Bitmap of tap interfaces with pending reads */
- uword * pending_read_bitmap;
+ uword *pending_read_bitmap;
/** Hash table to find tapcli interface given hw_if_index */
- uword * tapcli_interface_index_by_sw_if_index;
+ uword *tapcli_interface_index_by_sw_if_index;
/** Hash table to find tapcli interface given unix fd */
- uword * tapcli_interface_index_by_unix_fd;
+ uword *tapcli_interface_index_by_unix_fd;
/** renumbering table */
- u32 * show_dev_instance_by_real_dev_instance;
+ u32 *show_dev_instance_by_real_dev_instance;
/** 1 => disable CLI */
int is_disabled;
/** convenience - vlib_main_t */
- vlib_main_t * vlib_main;
+ vlib_main_t *vlib_main;
/** convenience - vnet_main_t */
- vnet_main_t * vnet_main;
+ vnet_main_t *vnet_main;
} tapcli_main_t;
static tapcli_main_t tapcli_main;
@@ -165,48 +168,46 @@ static tapcli_main_t tapcli_main;
*
*/
static uword
-tapcli_tx (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+tapcli_tx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- u32 * buffers = vlib_frame_args (frame);
+ u32 *buffers = vlib_frame_args (frame);
uword n_packets = frame->n_vectors;
- tapcli_main_t * tm = &tapcli_main;
- tapcli_interface_t * ti;
+ tapcli_main_t *tm = &tapcli_main;
+ tapcli_interface_t *ti;
int i;
u16 thread_index = vlib_get_thread_index ();
for (i = 0; i < n_packets; i++)
{
- struct iovec * iov;
- vlib_buffer_t * b;
+ struct iovec *iov;
+ vlib_buffer_t *b;
uword l;
- vnet_hw_interface_t * hw;
- uword * p;
+ vnet_hw_interface_t *hw;
+ uword *p;
u32 tx_sw_if_index;
b = vlib_get_buffer (vm, buffers[i]);
- tx_sw_if_index = vnet_buffer(b)->sw_if_index[VLIB_TX];
- if (tx_sw_if_index == (u32)~0)
- tx_sw_if_index = vnet_buffer(b)->sw_if_index[VLIB_RX];
-
- ASSERT(tx_sw_if_index != (u32)~0);
+ tx_sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_TX];
+ if (tx_sw_if_index == (u32) ~ 0)
+ tx_sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
+
+ ASSERT (tx_sw_if_index != (u32) ~ 0);
/* Use the sup intfc to finesse vlan subifs */
hw = vnet_get_sup_hw_interface (tm->vnet_main, tx_sw_if_index);
tx_sw_if_index = hw->sw_if_index;
- p = hash_get (tm->tapcli_interface_index_by_sw_if_index,
- tx_sw_if_index);
+ p = hash_get (tm->tapcli_interface_index_by_sw_if_index,
+ tx_sw_if_index);
if (p == 0)
- {
- clib_warning ("sw_if_index %d unknown", tx_sw_if_index);
- /* $$$ leak, but this should never happen... */
- continue;
- }
+ {
+ clib_warning ("sw_if_index %d unknown", tx_sw_if_index);
+ /* $$$ leak, but this should never happen... */
+ continue;
+ }
else
- ti = vec_elt_at_index (tm->tapcli_interfaces, p[0]);
+ ti = vec_elt_at_index (tm->tapcli_interfaces, p[0]);
/* Re-set iovecs if present. */
if (tm->threads[thread_index].iovecs)
@@ -219,15 +220,17 @@ tapcli_tx (vlib_main_t * vm,
if (PREDICT_FALSE (b->flags & VLIB_BUFFER_NEXT_PRESENT))
{
- do {
- b = vlib_get_buffer (vm, b->next_buffer);
+ do
+ {
+ b = vlib_get_buffer (vm, b->next_buffer);
- vec_add2 (tm->threads[thread_index].iovecs, iov, 1);
+ vec_add2 (tm->threads[thread_index].iovecs, iov, 1);
- iov->iov_base = b->data + b->current_data;
- iov->iov_len = b->current_length;
- l += b->current_length;
- } while (b->flags & VLIB_BUFFER_NEXT_PRESENT);
+ iov->iov_base = b->data + b->current_data;
+ iov->iov_len = b->current_length;
+ l += b->current_length;
+ }
+ while (b->flags & VLIB_BUFFER_NEXT_PRESENT);
}
if (writev (ti->unix_fd, tm->threads[thread_index].iovecs,
@@ -235,17 +238,19 @@ tapcli_tx (vlib_main_t * vm,
clib_unix_warning ("writev");
}
- vlib_buffer_free(vm, vlib_frame_vector_args(frame), frame->n_vectors);
+ vlib_buffer_free (vm, vlib_frame_vector_args (frame), frame->n_vectors);
return n_packets;
}
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (tapcli_tx_node,static) = {
.function = tapcli_tx,
.name = "tapcli-tx",
.type = VLIB_NODE_TYPE_INTERNAL,
.vector_size = 4,
};
+/* *INDENT-ON* */
/**
* @brief Dispatch tapcli RX node function for node tap_cli_rx
@@ -258,141 +263,164 @@ VLIB_REGISTER_NODE (tapcli_tx_node,static) = {
* @return n_packets - uword
*
*/
-static uword tapcli_rx_iface(vlib_main_t * vm,
- vlib_node_runtime_t * node,
- tapcli_interface_t * ti)
+static uword
+tapcli_rx_iface (vlib_main_t * vm,
+ vlib_node_runtime_t * node, tapcli_interface_t * ti)
{
- tapcli_main_t * tm = &tapcli_main;
+ tapcli_main_t *tm = &tapcli_main;
const uword buffer_size = VLIB_BUFFER_DATA_SIZE;
u32 n_trace = vlib_get_trace_count (vm, node);
u8 set_trace = 0;
u16 thread_index = vlib_get_thread_index ();
vnet_main_t *vnm;
- vnet_sw_interface_t * si;
+ vnet_sw_interface_t *si;
u8 admin_down;
u32 next = node->cached_next_index;
u32 n_left_to_next, next_index;
u32 *to_next;
- vnm = vnet_get_main();
+ vnm = vnet_get_main ();
si = vnet_get_sw_interface (vnm, ti->sw_if_index);
admin_down = !(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP);
- vlib_get_next_frame(vm, node, next, to_next, n_left_to_next);
-
- while (n_left_to_next) { // Fill at most one vector
- vlib_buffer_t *b_first, *b, *prev;
- u32 bi_first, bi;
- word n_bytes_in_packet;
- int j, n_bytes_left;
-
- if (PREDICT_FALSE(vec_len(tm->threads[thread_index].rx_buffers) <
- tm->mtu_buffers)) {
- uword len = vec_len(tm->threads[thread_index].rx_buffers);
- _vec_len(tm->threads[thread_index].rx_buffers) +=
- vlib_buffer_alloc_from_free_list(vm, &tm->threads[thread_index].rx_buffers[len],
- VLIB_FRAME_SIZE - len, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
- if (PREDICT_FALSE(vec_len(tm->threads[thread_index].rx_buffers) <
- tm->mtu_buffers)) {
- vlib_node_increment_counter(vm, tapcli_rx_node.index,
- TAPCLI_ERROR_BUFFER_ALLOC,
- tm->mtu_buffers -
- vec_len(tm->threads[thread_index].rx_buffers));
- break;
- }
- }
-
- uword i_rx = vec_len (tm->threads[thread_index].rx_buffers) - 1;
-
- /* Allocate RX buffers from end of rx_buffers.
- Turn them into iovecs to pass to readv. */
- vec_validate (tm->threads[thread_index].iovecs, tm->mtu_buffers - 1);
- for (j = 0; j < tm->mtu_buffers; j++) {
- b = vlib_get_buffer (vm, tm->threads[thread_index].rx_buffers[i_rx - j]);
- tm->threads[thread_index].iovecs[j].iov_base = b->data;
- tm->threads[thread_index].iovecs[j].iov_len = buffer_size;
- }
+ vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
- n_bytes_left = readv (ti->unix_fd, tm->threads[thread_index].iovecs,
- tm->mtu_buffers);
- n_bytes_in_packet = n_bytes_left;
- if (n_bytes_left <= 0) {
- if (errno != EAGAIN) {
- vlib_node_increment_counter(vm, tapcli_rx_node.index,
- TAPCLI_ERROR_READ, 1);
- }
- break;
- }
+ while (n_left_to_next)
+ { // Fill at most one vector
+ vlib_buffer_t *b_first, *b, *prev;
+ u32 bi_first, bi;
+ word n_bytes_in_packet;
+ int j, n_bytes_left;
- bi_first = tm->threads[thread_index].rx_buffers[i_rx];
- b = b_first = vlib_get_buffer (vm,
- tm->threads[thread_index].rx_buffers[i_rx]);
- prev = NULL;
+ if (PREDICT_FALSE (vec_len (tm->threads[thread_index].rx_buffers) <
+ tm->mtu_buffers))
+ {
+ uword len = vec_len (tm->threads[thread_index].rx_buffers);
+ _vec_len (tm->threads[thread_index].rx_buffers) +=
+ vlib_buffer_alloc_from_free_list (vm,
+ &tm->threads[thread_index].
+ rx_buffers[len],
+ VLIB_FRAME_SIZE - len,
+ VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
+ if (PREDICT_FALSE
+ (vec_len (tm->threads[thread_index].rx_buffers) <
+ tm->mtu_buffers))
+ {
+ vlib_node_increment_counter (vm, tapcli_rx_node.index,
+ TAPCLI_ERROR_BUFFER_ALLOC,
+ tm->mtu_buffers -
+ vec_len (tm->threads
+ [thread_index].
+ rx_buffers));
+ break;
+ }
+ }
- while (1) {
- b->current_length = n_bytes_left < buffer_size ? n_bytes_left : buffer_size;
- n_bytes_left -= buffer_size;
+ uword i_rx = vec_len (tm->threads[thread_index].rx_buffers) - 1;
- if (prev) {
- prev->next_buffer = bi;
- prev->flags |= VLIB_BUFFER_NEXT_PRESENT;
- }
- prev = b;
+ /* Allocate RX buffers from end of rx_buffers.
+ Turn them into iovecs to pass to readv. */
+ vec_validate (tm->threads[thread_index].iovecs, tm->mtu_buffers - 1);
+ for (j = 0; j < tm->mtu_buffers; j++)
+ {
+ b =
+ vlib_get_buffer (vm,
+ tm->threads[thread_index].rx_buffers[i_rx - j]);
+ tm->threads[thread_index].iovecs[j].iov_base = b->data;
+ tm->threads[thread_index].iovecs[j].iov_len = buffer_size;
+ }
- /* last segment */
+ n_bytes_left = readv (ti->unix_fd, tm->threads[thread_index].iovecs,
+ tm->mtu_buffers);
+ n_bytes_in_packet = n_bytes_left;
if (n_bytes_left <= 0)
- break;
+ {
+ if (errno != EAGAIN)
+ {
+ vlib_node_increment_counter (vm, tapcli_rx_node.index,
+ TAPCLI_ERROR_READ, 1);
+ }
+ break;
+ }
- i_rx--;
- bi = tm->threads[thread_index].rx_buffers[i_rx];
- b = vlib_get_buffer (vm, bi);
- }
+ bi_first = tm->threads[thread_index].rx_buffers[i_rx];
+ b = b_first = vlib_get_buffer (vm,
+ tm->threads[thread_index].
+ rx_buffers[i_rx]);
+ prev = NULL;
- _vec_len (tm->threads[thread_index].rx_buffers) = i_rx;
+ while (1)
+ {
+ b->current_length =
+ n_bytes_left < buffer_size ? n_bytes_left : buffer_size;
+ n_bytes_left -= buffer_size;
+
+ if (prev)
+ {
+ prev->next_buffer = bi;
+ prev->flags |= VLIB_BUFFER_NEXT_PRESENT;
+ }
+ prev = b;
+
+ /* last segment */
+ if (n_bytes_left <= 0)
+ break;
+
+ i_rx--;
+ bi = tm->threads[thread_index].rx_buffers[i_rx];
+ b = vlib_get_buffer (vm, bi);
+ }
- b_first->total_length_not_including_first_buffer =
- (n_bytes_in_packet > buffer_size) ? n_bytes_in_packet - buffer_size : 0;
- b_first->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
+ _vec_len (tm->threads[thread_index].rx_buffers) = i_rx;
- VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b_first);
+ b_first->total_length_not_including_first_buffer =
+ (n_bytes_in_packet >
+ buffer_size) ? n_bytes_in_packet - buffer_size : 0;
+ b_first->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
- vnet_buffer (b_first)->sw_if_index[VLIB_RX] = ti->sw_if_index;
- vnet_buffer (b_first)->sw_if_index[VLIB_TX] = (u32)~0;
+ VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b_first);
- b_first->error = node->errors[TAPCLI_ERROR_NONE];
- next_index = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT;
- next_index = (ti->per_interface_next_index != ~0) ?
- ti->per_interface_next_index : next_index;
- next_index = admin_down ? VNET_DEVICE_INPUT_NEXT_DROP : next_index;
+ vnet_buffer (b_first)->sw_if_index[VLIB_RX] = ti->sw_if_index;
+ vnet_buffer (b_first)->sw_if_index[VLIB_TX] = (u32) ~ 0;
- to_next[0] = bi_first;
- to_next++;
- n_left_to_next--;
+ b_first->error = node->errors[TAPCLI_ERROR_NONE];
+ next_index = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT;
+ next_index = (ti->per_interface_next_index != ~0) ?
+ ti->per_interface_next_index : next_index;
+ next_index = admin_down ? VNET_DEVICE_INPUT_NEXT_DROP : next_index;
- vnet_feature_start_device_input_x1 (ti->sw_if_index, &next_index, b_first);
+ to_next[0] = bi_first;
+ to_next++;
+ n_left_to_next--;
- vlib_validate_buffer_enqueue_x1 (vm, node, next,
- to_next, n_left_to_next,
- bi_first, next_index);
+ vnet_feature_start_device_input_x1 (ti->sw_if_index, &next_index,
+ b_first);
- /* Interface counters for tapcli interface. */
- if (PREDICT_TRUE(!admin_down)) {
- vlib_increment_combined_counter (
- vnet_main.interface_main.combined_sw_if_counters
- + VNET_INTERFACE_COUNTER_RX,
- thread_index, ti->sw_if_index,
- 1, n_bytes_in_packet);
+ vlib_validate_buffer_enqueue_x1 (vm, node, next,
+ to_next, n_left_to_next,
+ bi_first, next_index);
- if (PREDICT_FALSE(n_trace > 0)) {
- vlib_trace_buffer (vm, node, next_index,
- b_first, /* follow_chain */ 1);
- n_trace--;
- set_trace = 1;
- tapcli_rx_trace_t *t0 = vlib_add_trace (vm, node, b_first, sizeof (*t0));
- t0->sw_if_index = si->sw_if_index;
- }
+ /* Interface counters for tapcli interface. */
+ if (PREDICT_TRUE (!admin_down))
+ {
+ vlib_increment_combined_counter (vnet_main.interface_main.
+ combined_sw_if_counters +
+ VNET_INTERFACE_COUNTER_RX,
+ thread_index, ti->sw_if_index, 1,
+ n_bytes_in_packet);
+
+ if (PREDICT_FALSE (n_trace > 0))
+ {
+ vlib_trace_buffer (vm, node, next_index,
+ b_first, /* follow_chain */ 1);
+ n_trace--;
+ set_trace = 1;
+ tapcli_rx_trace_t *t0 =
+ vlib_add_trace (vm, node, b_first, sizeof (*t0));
+ t0->sw_if_index = si->sw_if_index;
+ }
+ }
}
- }
vlib_put_next_frame (vm, node, next, n_left_to_next);
if (set_trace)
vlib_set_trace_count (vm, node, n_trace);
@@ -413,44 +441,46 @@ static uword tapcli_rx_iface(vlib_main_t * vm,
*
*/
static uword
-tapcli_rx (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+tapcli_rx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- tapcli_main_t * tm = &tapcli_main;
- static u32 * ready_interface_indices;
- tapcli_interface_t * ti;
+ tapcli_main_t *tm = &tapcli_main;
+ static u32 *ready_interface_indices;
+ tapcli_interface_t *ti;
int i;
u32 total_count = 0;
vec_reset_length (ready_interface_indices);
+ /* *INDENT-OFF* */
clib_bitmap_foreach (i, tm->pending_read_bitmap,
({
vec_add1 (ready_interface_indices, i);
}));
+ /* *INDENT-ON* */
if (vec_len (ready_interface_indices) == 0)
return 0;
- for (i = 0; i < vec_len(ready_interface_indices); i++)
- {
- tm->pending_read_bitmap =
- clib_bitmap_set (tm->pending_read_bitmap,
- ready_interface_indices[i], 0);
+ for (i = 0; i < vec_len (ready_interface_indices); i++)
+ {
+ tm->pending_read_bitmap =
+ clib_bitmap_set (tm->pending_read_bitmap,
+ ready_interface_indices[i], 0);
- ti = vec_elt_at_index (tm->tapcli_interfaces, ready_interface_indices[i]);
- total_count += tapcli_rx_iface(vm, node, ti);
- }
- return total_count; //This might return more than 256.
+ ti =
+ vec_elt_at_index (tm->tapcli_interfaces, ready_interface_indices[i]);
+ total_count += tapcli_rx_iface (vm, node, ti);
+ }
+ return total_count; //This might return more than 256.
}
/** TAPCLI error strings */
-static char * tapcli_rx_error_strings[] = {
+static char *tapcli_rx_error_strings[] = {
#define _(sym,string) string,
foreach_tapcli_error
#undef _
};
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (tapcli_rx_node, static) = {
.function = tapcli_rx,
.name = "tapcli-rx",
@@ -462,6 +492,7 @@ VLIB_REGISTER_NODE (tapcli_rx_node, static) = {
.error_strings = tapcli_rx_error_strings,
.format_trace = format_tapcli_rx_trace,
};
+/* *INDENT-ON* */
/**
@@ -472,11 +503,12 @@ VLIB_REGISTER_NODE (tapcli_rx_node, static) = {
* @return error - clib_error_t
*
*/
-static clib_error_t * tapcli_read_ready (clib_file_t * uf)
+static clib_error_t *
+tapcli_read_ready (clib_file_t * uf)
{
- vlib_main_t * vm = vlib_get_main();
- tapcli_main_t * tm = &tapcli_main;
- uword * p;
+ vlib_main_t *vm = vlib_get_main ();
+ tapcli_main_t *tm = &tapcli_main;
+ uword *p;
/** Schedule the rx node */
vlib_node_set_interrupt_pending (vm, tapcli_rx_node.index);
@@ -486,7 +518,7 @@ static clib_error_t * tapcli_read_ready (clib_file_t * uf)
/** Mark the specific tap interface ready-to-read */
if (p)
tm->pending_read_bitmap = clib_bitmap_set (tm->pending_read_bitmap,
- p[0], 1);
+ p[0], 1);
else
clib_warning ("fd %d not in hash table", uf->file_descriptor);
@@ -513,16 +545,16 @@ tapcli_config (vlib_main_t * vm, unformat_input_t * input)
if (unformat (input, "mtu %d", &tm->mtu_bytes))
;
else if (unformat (input, "disable"))
- tm->is_disabled = 1;
+ tm->is_disabled = 1;
else
- return clib_error_return (0, "unknown input `%U'",
- format_unformat_error, input);
+ return clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, input);
}
if (tm->is_disabled)
return 0;
- if (geteuid())
+ if (geteuid ())
{
clib_warning ("tapcli disabled: must be superuser");
tm->is_disabled = 1;
@@ -543,15 +575,15 @@ tapcli_config (vlib_main_t * vm, unformat_input_t * input)
* @return rc - int
*
*/
-static int tap_name_renumber (vnet_hw_interface_t * hi,
- u32 new_dev_instance)
+static int
+tap_name_renumber (vnet_hw_interface_t * hi, u32 new_dev_instance)
{
tapcli_main_t *tm = &tapcli_main;
vec_validate_init_empty (tm->show_dev_instance_by_real_dev_instance,
- hi->dev_instance, ~0);
+ hi->dev_instance, ~0);
- tm->show_dev_instance_by_real_dev_instance [hi->dev_instance] =
+ tm->show_dev_instance_by_real_dev_instance[hi->dev_instance] =
new_dev_instance;
return 0;
@@ -569,19 +601,20 @@ VLIB_CONFIG_FUNCTION (tapcli_config, "tapcli");
*/
static void
tapcli_nopunt_frame (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- u32 * buffers = vlib_frame_args (frame);
+ u32 *buffers = vlib_frame_args (frame);
uword n_packets = frame->n_vectors;
vlib_buffer_free (vm, buffers, n_packets);
vlib_frame_free (vm, node, frame);
}
+/* *INDENT-OFF* */
VNET_HW_INTERFACE_CLASS (tapcli_interface_class,static) = {
.name = "tapcli",
.flags = VNET_HW_INTERFACE_CLASS_FLAG_P2P,
};
+/* *INDENT-ON* */
/**
* @brief Formatter for TAPCLI interface name
@@ -592,11 +625,12 @@ VNET_HW_INTERFACE_CLASS (tapcli_interface_class,static) = {
* @return *s - formatted string
*
*/
-static u8 * format_tapcli_interface_name (u8 * s, va_list * args)
+static u8 *
+format_tapcli_interface_name (u8 * s, va_list * args)
{
u32 i = va_arg (*args, u32);
u32 show_dev_instance = ~0;
- tapcli_main_t * tm = &tapcli_main;
+ tapcli_main_t *tm = &tapcli_main;
if (i < vec_len (tm->show_dev_instance_by_real_dev_instance))
show_dev_instance = tm->show_dev_instance_by_real_dev_instance[i];
@@ -618,14 +652,13 @@ static u8 * format_tapcli_interface_name (u8 * s, va_list * args)
* @return rc - u32
*
*/
-static u32 tapcli_flag_change (vnet_main_t * vnm,
- vnet_hw_interface_t * hw,
- u32 flags)
+static u32
+tapcli_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hw, u32 flags)
{
tapcli_main_t *tm = &tapcli_main;
tapcli_interface_t *ti;
- ti = vec_elt_at_index (tm->tapcli_interfaces, hw->dev_instance);
+ ti = vec_elt_at_index (tm->tapcli_interfaces, hw->dev_instance);
if (flags & ETHERNET_INTERFACE_FLAG_MTU)
{
@@ -633,7 +666,7 @@ static u32 tapcli_flag_change (vnet_main_t * vnm,
tm->mtu_bytes = hw->max_packet_bytes;
tm->mtu_buffers = (tm->mtu_bytes + (buffer_size - 1)) / buffer_size;
}
- else
+ else
{
struct ifreq ifr;
u32 want_promisc;
@@ -642,27 +675,27 @@ static u32 tapcli_flag_change (vnet_main_t * vnm,
/* get flags, modify to bring up interface... */
if (ioctl (ti->provision_fd, SIOCGIFFLAGS, &ifr) < 0)
- {
- clib_unix_warning ("Couldn't get interface flags for %s", hw->name);
- return 0;
- }
+ {
+ clib_unix_warning ("Couldn't get interface flags for %s", hw->name);
+ return 0;
+ }
want_promisc = (flags & ETHERNET_INTERFACE_FLAG_ACCEPT_ALL) != 0;
if (want_promisc == ti->is_promisc)
- return 0;
+ return 0;
if (flags & ETHERNET_INTERFACE_FLAG_ACCEPT_ALL)
- ifr.ifr_flags |= IFF_PROMISC;
+ ifr.ifr_flags |= IFF_PROMISC;
else
- ifr.ifr_flags &= ~(IFF_PROMISC);
+ ifr.ifr_flags &= ~(IFF_PROMISC);
/* get flags, modify to bring up interface... */
if (ioctl (ti->provision_fd, SIOCSIFFLAGS, &ifr) < 0)
- {
- clib_unix_warning ("Couldn't set interface flags for %s", hw->name);
- return 0;
- }
+ {
+ clib_unix_warning ("Couldn't set interface flags for %s", hw->name);
+ return 0;
+ }
ti->is_promisc = want_promisc;
}
@@ -678,9 +711,9 @@ static u32 tapcli_flag_change (vnet_main_t * vnm,
* @param node_index - u32
*
*/
-static void tapcli_set_interface_next_node (vnet_main_t *vnm,
- u32 hw_if_index,
- u32 node_index)
+static void
+tapcli_set_interface_next_node (vnet_main_t * vnm,
+ u32 hw_if_index, u32 node_index)
{
tapcli_main_t *tm = &tapcli_main;
tapcli_interface_t *ti;
@@ -725,6 +758,7 @@ tapcli_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
return 0;
}
+/* *INDENT-OFF* */
VNET_DEVICE_CLASS (tapcli_dev_class,static) = {
.name = "tapcli",
.tx_function = tapcli_tx,
@@ -733,6 +767,7 @@ VNET_DEVICE_CLASS (tapcli_dev_class,static) = {
.name_renumber = tap_name_renumber,
.admin_up_down_function = tapcli_interface_admin_up_down,
};
+/* *INDENT-ON* */
/**
* @brief Dump TAP interfaces
@@ -742,20 +777,23 @@ VNET_DEVICE_CLASS (tapcli_dev_class,static) = {
* @return rc - int
*
*/
-int vnet_tap_dump_ifs (tapcli_interface_details_t **out_tapids)
+int
+vnet_tap_dump_ifs (tapcli_interface_details_t ** out_tapids)
{
- tapcli_main_t * tm = &tapcli_main;
- tapcli_interface_t * ti;
+ tapcli_main_t *tm = &tapcli_main;
+ tapcli_interface_t *ti;
- tapcli_interface_details_t * r_tapids = NULL;
- tapcli_interface_details_t * tapid = NULL;
+ tapcli_interface_details_t *r_tapids = NULL;
+ tapcli_interface_details_t *tapid = NULL;
- vec_foreach (ti, tm->tapcli_interfaces) {
+ vec_foreach (ti, tm->tapcli_interfaces)
+ {
if (!ti->active)
- continue;
- vec_add2(r_tapids, tapid, 1);
+ continue;
+ vec_add2 (r_tapids, tapid, 1);
tapid->sw_if_index = ti->sw_if_index;
- strncpy((char *)tapid->dev_name, ti->ifr.ifr_name, sizeof (ti->ifr.ifr_name)-1);
+ strncpy ((char *) tapid->dev_name, ti->ifr.ifr_name,
+ sizeof (ti->ifr.ifr_name) - 1);
}
*out_tapids = r_tapids;
@@ -769,23 +807,26 @@ int vnet_tap_dump_ifs (tapcli_interface_details_t **out_tapids)
* @return interface - tapcli_interface_t
*
*/
-static tapcli_interface_t *tapcli_get_new_tapif()
+static tapcli_interface_t *
+tapcli_get_new_tapif ()
{
- tapcli_main_t * tm = &tapcli_main;
+ tapcli_main_t *tm = &tapcli_main;
tapcli_interface_t *ti = NULL;
- int inactive_cnt = vec_len(tm->tapcli_inactive_interfaces);
+ int inactive_cnt = vec_len (tm->tapcli_inactive_interfaces);
// if there are any inactive ifaces
- if (inactive_cnt > 0) {
- // take last
- u32 ti_idx = tm->tapcli_inactive_interfaces[inactive_cnt - 1];
- if (vec_len(tm->tapcli_interfaces) > ti_idx) {
- ti = vec_elt_at_index (tm->tapcli_interfaces, ti_idx);
- clib_warning("reusing tap interface");
+ if (inactive_cnt > 0)
+ {
+ // take last
+ u32 ti_idx = tm->tapcli_inactive_interfaces[inactive_cnt - 1];
+ if (vec_len (tm->tapcli_interfaces) > ti_idx)
+ {
+ ti = vec_elt_at_index (tm->tapcli_interfaces, ti_idx);
+ clib_warning ("reusing tap interface");
+ }
+ // "remove" from inactive list
+ _vec_len (tm->tapcli_inactive_interfaces) -= 1;
}
- // "remove" from inactive list
- _vec_len(tm->tapcli_inactive_interfaces) -= 1;
- }
// ti was not retrieved from inactive ifaces - create new
if (!ti)
@@ -794,32 +835,33 @@ static tapcli_interface_t *tapcli_get_new_tapif()
return ti;
}
-typedef struct
+typedef struct
{
- ip6_address_t addr;
- u32 mask_width;
- unsigned int ifindex;
+ ip6_address_t addr;
+ u32 mask_width;
+ unsigned int ifindex;
} ip6_ifreq_t;
/**
* @brief Connect a TAP interface
*
* @param vm - vlib_main_t
- * @param ap - vnet_tap_connect_args_t
+ * @param ap - vnet_tap_connect_args_t
*
* @return rc - int
*
*/
-int vnet_tap_connect (vlib_main_t * vm, vnet_tap_connect_args_t *ap)
+int
+vnet_tap_connect (vlib_main_t * vm, vnet_tap_connect_args_t * ap)
{
- tapcli_main_t * tm = &tapcli_main;
- tapcli_interface_t * ti = NULL;
+ tapcli_main_t *tm = &tapcli_main;
+ tapcli_interface_t *ti = NULL;
struct ifreq ifr;
int flags;
int dev_net_tun_fd;
int dev_tap_fd = -1;
- clib_error_t * error;
- u8 hwaddr [6];
+ clib_error_t *error;
+ u8 hwaddr[6];
int rv = 0;
if (tm->is_disabled)
@@ -833,17 +875,16 @@ int vnet_tap_connect (vlib_main_t * vm, vnet_tap_connect_args_t *ap)
return VNET_API_ERROR_SYSCALL_ERROR_1;
memset (&ifr, 0, sizeof (ifr));
- strncpy(ifr.ifr_name, (char *) ap->intfc_name, sizeof (ifr.ifr_name)-1);
+ strncpy (ifr.ifr_name, (char *) ap->intfc_name, sizeof (ifr.ifr_name) - 1);
ifr.ifr_flags = flags;
- if (ioctl (dev_net_tun_fd, TUNSETIFF, (void *)&ifr) < 0)
+ if (ioctl (dev_net_tun_fd, TUNSETIFF, (void *) &ifr) < 0)
{
rv = VNET_API_ERROR_SYSCALL_ERROR_2;
goto error;
}
-
+
/* Open a provisioning socket */
- if ((dev_tap_fd = socket(PF_PACKET, SOCK_RAW,
- htons(ETH_P_ALL))) < 0 )
+ if ((dev_tap_fd = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL))) < 0)
{
rv = VNET_API_ERROR_SYSCALL_ERROR_3;
goto error;
@@ -854,24 +895,25 @@ int vnet_tap_connect (vlib_main_t * vm, vnet_tap_connect_args_t *ap)
struct ifreq ifr;
struct sockaddr_ll sll;
- memset (&ifr, 0, sizeof(ifr));
- strncpy (ifr.ifr_name, (char *) ap->intfc_name, sizeof (ifr.ifr_name)-1);
- if (ioctl (dev_tap_fd, SIOCGIFINDEX, &ifr) < 0 )
+ memset (&ifr, 0, sizeof (ifr));
+ strncpy (ifr.ifr_name, (char *) ap->intfc_name,
+ sizeof (ifr.ifr_name) - 1);
+ if (ioctl (dev_tap_fd, SIOCGIFINDEX, &ifr) < 0)
{
- rv = VNET_API_ERROR_SYSCALL_ERROR_4;
- goto error;
+ rv = VNET_API_ERROR_SYSCALL_ERROR_4;
+ goto error;
}
/* Bind the provisioning socket to the interface. */
- memset(&sll, 0, sizeof(sll));
- sll.sll_family = AF_PACKET;
- sll.sll_ifindex = ifr.ifr_ifindex;
- sll.sll_protocol = htons(ETH_P_ALL);
+ memset (&sll, 0, sizeof (sll));
+ sll.sll_family = AF_PACKET;
+ sll.sll_ifindex = ifr.ifr_ifindex;
+ sll.sll_protocol = htons (ETH_P_ALL);
- if (bind(dev_tap_fd, (struct sockaddr*) &sll, sizeof(sll)) < 0)
+ if (bind (dev_tap_fd, (struct sockaddr *) &sll, sizeof (sll)) < 0)
{
- rv = VNET_API_ERROR_SYSCALL_ERROR_5;
- goto error;
+ rv = VNET_API_ERROR_SYSCALL_ERROR_5;
+ goto error;
}
}
@@ -880,7 +922,7 @@ int vnet_tap_connect (vlib_main_t * vm, vnet_tap_connect_args_t *ap)
int one = 1;
if (ioctl (dev_net_tun_fd, FIONBIO, &one) < 0)
{
- rv = VNET_API_ERROR_SYSCALL_ERROR_6;
+ rv = VNET_API_ERROR_SYSCALL_ERROR_6;
goto error;
}
}
@@ -912,35 +954,35 @@ int vnet_tap_connect (vlib_main_t * vm, vnet_tap_connect_args_t *ap)
/* ip4: mask defaults to /24 */
u32 mask = clib_host_to_net_u32 (0xFFFFFF00);
- memset(&sin, 0, sizeof(sin));
+ memset (&sin, 0, sizeof (sin));
sin.sin_family = AF_INET;
/* sin.sin_port = 0; */
sin.sin_addr.s_addr = ap->ip4_address->as_u32;
memcpy (&ifr.ifr_ifru.ifru_addr, &sin, sizeof (sin));
if (ioctl (dev_tap_fd, SIOCSIFADDR, &ifr) < 0)
- {
- rv = VNET_API_ERROR_SYSCALL_ERROR_10;
- goto error;
- }
+ {
+ rv = VNET_API_ERROR_SYSCALL_ERROR_10;
+ goto error;
+ }
if (ap->ip4_mask_width > 0 && ap->ip4_mask_width < 33)
- {
- mask = ~0;
- mask <<= (32 - ap->ip4_mask_width);
- }
+ {
+ mask = ~0;
+ mask <<= (32 - ap->ip4_mask_width);
+ }
- mask = clib_host_to_net_u32(mask);
+ mask = clib_host_to_net_u32 (mask);
sin.sin_family = AF_INET;
sin.sin_port = 0;
sin.sin_addr.s_addr = mask;
memcpy (&ifr.ifr_ifru.ifru_addr, &sin, sizeof (sin));
if (ioctl (dev_tap_fd, SIOCSIFNETMASK, &ifr) < 0)
- {
- rv = VNET_API_ERROR_SYSCALL_ERROR_10;
- goto error;
- }
+ {
+ rv = VNET_API_ERROR_SYSCALL_ERROR_10;
+ goto error;
+ }
}
if (ap->ip6_address_set)
@@ -949,61 +991,60 @@ int vnet_tap_connect (vlib_main_t * vm, vnet_tap_connect_args_t *ap)
ip6_ifreq_t ifr6;
int sockfd6;
- sockfd6 = socket(AF_INET6, SOCK_DGRAM, IPPROTO_IP);
+ sockfd6 = socket (AF_INET6, SOCK_DGRAM, IPPROTO_IP);
if (sockfd6 < 0)
- {
- rv = VNET_API_ERROR_SYSCALL_ERROR_10;
- goto error;
- }
-
- memset (&ifr2, 0, sizeof(ifr));
- strncpy (ifr2.ifr_name, (char *) ap->intfc_name,
- sizeof (ifr2.ifr_name)-1);
- if (ioctl (sockfd6, SIOCGIFINDEX, &ifr2) < 0 )
- {
- close (sockfd6);
- rv = VNET_API_ERROR_SYSCALL_ERROR_4;
- goto error;
- }
-
+ {
+ rv = VNET_API_ERROR_SYSCALL_ERROR_10;
+ goto error;
+ }
+
+ memset (&ifr2, 0, sizeof (ifr));
+ strncpy (ifr2.ifr_name, (char *) ap->intfc_name,
+ sizeof (ifr2.ifr_name) - 1);
+ if (ioctl (sockfd6, SIOCGIFINDEX, &ifr2) < 0)
+ {
+ close (sockfd6);
+ rv = VNET_API_ERROR_SYSCALL_ERROR_4;
+ goto error;
+ }
+
memcpy (&ifr6.addr, ap->ip6_address, sizeof (ip6_address_t));
ifr6.mask_width = ap->ip6_mask_width;
ifr6.ifindex = ifr2.ifr_ifindex;
-
+
if (ioctl (sockfd6, SIOCSIFADDR, &ifr6) < 0)
- {
- close (sockfd6);
- clib_unix_warning ("ifr6");
- rv = VNET_API_ERROR_SYSCALL_ERROR_10;
- goto error;
- }
+ {
+ close (sockfd6);
+ clib_unix_warning ("ifr6");
+ rv = VNET_API_ERROR_SYSCALL_ERROR_10;
+ goto error;
+ }
close (sockfd6);
}
- ti = tapcli_get_new_tapif();
+ ti = tapcli_get_new_tapif ();
ti->per_interface_next_index = ~0;
if (ap->hwaddr_arg != 0)
- clib_memcpy(hwaddr, ap->hwaddr_arg, 6);
+ clib_memcpy (hwaddr, ap->hwaddr_arg, 6);
else
{
- f64 now = vlib_time_now(vm);
+ f64 now = vlib_time_now (vm);
u32 rnd;
rnd = (u32) (now * 1e6);
rnd = random_u32 (&rnd);
- memcpy (hwaddr+2, &rnd, sizeof(rnd));
+ memcpy (hwaddr + 2, &rnd, sizeof (rnd));
hwaddr[0] = 2;
hwaddr[1] = 0xfe;
}
error = ethernet_register_interface
- (tm->vnet_main,
- tapcli_dev_class.index,
- ti - tm->tapcli_interfaces /* device instance */,
- hwaddr /* ethernet address */,
- &ti->hw_if_index,
- tapcli_flag_change);
+ (tm->vnet_main,
+ tapcli_dev_class.index,
+ ti - tm->tapcli_interfaces /* device instance */ ,
+ hwaddr /* ethernet address */ ,
+ &ti->hw_if_index, tapcli_flag_change);
if (error)
{
@@ -1013,7 +1054,7 @@ int vnet_tap_connect (vlib_main_t * vm, vnet_tap_connect_args_t *ap)
}
{
- clib_file_t template = {0};
+ clib_file_t template = { 0 };
template.read_function = tapcli_read_ready;
template.file_descriptor = dev_net_tun_fd;
ti->clib_file_index = clib_file_add (&file_main, &template);
@@ -1021,32 +1062,33 @@ int vnet_tap_connect (vlib_main_t * vm, vnet_tap_connect_args_t *ap)
ti->provision_fd = dev_tap_fd;
clib_memcpy (&ti->ifr, &ifr, sizeof (ifr));
}
-
+
{
- vnet_hw_interface_t * hw;
+ vnet_hw_interface_t *hw;
hw = vnet_get_hw_interface (tm->vnet_main, ti->hw_if_index);
hw->min_supported_packet_bytes = TAP_MTU_MIN;
hw->max_supported_packet_bytes = TAP_MTU_MAX;
- hw->max_l3_packet_bytes[VLIB_RX] = hw->max_l3_packet_bytes[VLIB_TX] = hw->max_supported_packet_bytes - sizeof(ethernet_header_t);
+ hw->max_l3_packet_bytes[VLIB_RX] = hw->max_l3_packet_bytes[VLIB_TX] =
+ hw->max_supported_packet_bytes - sizeof (ethernet_header_t);
ti->sw_if_index = hw->sw_if_index;
if (ap->sw_if_indexp)
*(ap->sw_if_indexp) = hw->sw_if_index;
}
ti->active = 1;
-
+
hash_set (tm->tapcli_interface_index_by_sw_if_index, ti->sw_if_index,
- ti - tm->tapcli_interfaces);
-
+ ti - tm->tapcli_interfaces);
+
hash_set (tm->tapcli_interface_index_by_unix_fd, ti->unix_fd,
- ti - tm->tapcli_interfaces);
-
+ ti - tm->tapcli_interfaces);
+
return rv;
- error:
+error:
close (dev_net_tun_fd);
if (dev_tap_fd >= 0)
- close (dev_tap_fd);
+ close (dev_tap_fd);
return rv;
}
@@ -1064,13 +1106,14 @@ int vnet_tap_connect (vlib_main_t * vm, vnet_tap_connect_args_t *ap)
* @return rc - int
*
*/
-int vnet_tap_connect_renumber (vlib_main_t * vm,
- vnet_tap_connect_args_t *ap)
+int
+vnet_tap_connect_renumber (vlib_main_t * vm, vnet_tap_connect_args_t * ap)
{
- int rv = vnet_tap_connect(vm, ap);
+ int rv = vnet_tap_connect (vm, ap);
if (!rv && ap->renumber)
- vnet_interface_name_renumber (*(ap->sw_if_indexp), ap->custom_dev_instance);
+ vnet_interface_name_renumber (*(ap->sw_if_indexp),
+ ap->custom_dev_instance);
return rv;
}
@@ -1083,26 +1126,28 @@ int vnet_tap_connect_renumber (vlib_main_t * vm,
* @return rc - int
*
*/
-static int tapcli_tap_disconnect (tapcli_interface_t *ti)
+static int
+tapcli_tap_disconnect (tapcli_interface_t * ti)
{
int rv = 0;
- vnet_main_t * vnm = vnet_get_main();
- tapcli_main_t * tm = &tapcli_main;
+ vnet_main_t *vnm = vnet_get_main ();
+ tapcli_main_t *tm = &tapcli_main;
u32 sw_if_index = ti->sw_if_index;
// bring interface down
vnet_sw_interface_set_flags (vnm, sw_if_index, 0);
- if (ti->clib_file_index != ~0) {
- clib_file_del (&file_main, file_main.file_pool + ti->clib_file_index);
- ti->clib_file_index = ~0;
- }
+ if (ti->clib_file_index != ~0)
+ {
+ clib_file_del (&file_main, file_main.file_pool + ti->clib_file_index);
+ ti->clib_file_index = ~0;
+ }
else
- close(ti->unix_fd);
+ close (ti->unix_fd);
hash_unset (tm->tapcli_interface_index_by_unix_fd, ti->unix_fd);
hash_unset (tm->tapcli_interface_index_by_sw_if_index, ti->sw_if_index);
- close(ti->provision_fd);
+ close (ti->provision_fd);
ti->unix_fd = -1;
ti->provision_fd = -1;
@@ -1118,26 +1163,27 @@ static int tapcli_tap_disconnect (tapcli_interface_t *ti)
* @return rc - int
*
*/
-int vnet_tap_delete(vlib_main_t *vm, u32 sw_if_index)
+int
+vnet_tap_delete (vlib_main_t * vm, u32 sw_if_index)
{
int rv = 0;
- tapcli_main_t * tm = &tapcli_main;
+ tapcli_main_t *tm = &tapcli_main;
tapcli_interface_t *ti;
uword *p = NULL;
- p = hash_get (tm->tapcli_interface_index_by_sw_if_index,
- sw_if_index);
- if (p == 0) {
- clib_warning ("sw_if_index %d unknown", sw_if_index);
- return VNET_API_ERROR_INVALID_SW_IF_INDEX;
- }
+ p = hash_get (tm->tapcli_interface_index_by_sw_if_index, sw_if_index);
+ if (p == 0)
+ {
+ clib_warning ("sw_if_index %d unknown", sw_if_index);
+ return VNET_API_ERROR_INVALID_SW_IF_INDEX;
+ }
ti = vec_elt_at_index (tm->tapcli_interfaces, p[0]);
// inactive
ti->active = 0;
- tapcli_tap_disconnect(ti);
+ tapcli_tap_disconnect (ti);
// add to inactive list
- vec_add1(tm->tapcli_inactive_interfaces, ti - tm->tapcli_interfaces);
+ vec_add1 (tm->tapcli_inactive_interfaces, ti - tm->tapcli_interfaces);
// reset renumbered iface
if (p[0] < vec_len (tm->show_dev_instance_by_real_dev_instance))
@@ -1159,10 +1205,9 @@ int vnet_tap_delete(vlib_main_t *vm, u32 sw_if_index)
*/
static clib_error_t *
tap_delete_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
- tapcli_main_t * tm = &tapcli_main;
+ tapcli_main_t *tm = &tapcli_main;
u32 sw_if_index = ~0;
if (tm->is_disabled)
@@ -1171,29 +1216,35 @@ tap_delete_command_fn (vlib_main_t * vm,
}
if (unformat (input, "%U", unformat_vnet_sw_interface, tm->vnet_main,
- &sw_if_index))
- ;
+ &sw_if_index))
+ ;
else
return clib_error_return (0, "unknown input `%U'",
- format_unformat_error, input);
+ format_unformat_error, input);
int rc = vnet_tap_delete (vm, sw_if_index);
- if (!rc) {
- vlib_cli_output (vm, "Deleted.");
- } else {
- vlib_cli_output (vm, "Error during deletion of tap interface. (rc: %d)", rc);
- }
+ if (!rc)
+ {
+ vlib_cli_output (vm, "Deleted.");
+ }
+ else
+ {
+ vlib_cli_output (vm, "Error during deletion of tap interface. (rc: %d)",
+ rc);
+ }
return 0;
}
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (tap_delete_command, static) = {
.path = "tap delete",
.short_help = "tap delete <vpp-tap-intfc-name>",
.function = tap_delete_command_fn,
};
+/* *INDENT-ON* */
/**
* @brief Modifies tap interface - can result in new interface being created
@@ -1209,16 +1260,17 @@ VLIB_CLI_COMMAND (tap_delete_command, static) = {
* @return rc - int
*
*/
-int vnet_tap_modify (vlib_main_t * vm, vnet_tap_connect_args_t *ap)
+int
+vnet_tap_modify (vlib_main_t * vm, vnet_tap_connect_args_t * ap)
{
- int rv = vnet_tap_delete (vm, ap->orig_sw_if_index);
+ int rv = vnet_tap_delete (vm, ap->orig_sw_if_index);
- if (rv)
- return rv;
+ if (rv)
+ return rv;
- rv = vnet_tap_connect_renumber(vm, ap);
+ rv = vnet_tap_connect_renumber (vm, ap);
- return rv;
+ return rv;
}
/**
@@ -1233,16 +1285,15 @@ int vnet_tap_modify (vlib_main_t * vm, vnet_tap_connect_args_t *ap)
*/
static clib_error_t *
tap_modify_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
- u8 * intfc_name;
- tapcli_main_t * tm = &tapcli_main;
+ u8 *intfc_name;
+ tapcli_main_t *tm = &tapcli_main;
u32 sw_if_index = ~0;
u32 new_sw_if_index = ~0;
int user_hwaddr = 0;
u8 hwaddr[6];
- vnet_tap_connect_args_t _a, *ap= &_a;
+ vnet_tap_connect_args_t _a, *ap = &_a;
if (tm->is_disabled)
{
@@ -1250,24 +1301,23 @@ tap_modify_command_fn (vlib_main_t * vm,
}
if (unformat (input, "%U", unformat_vnet_sw_interface, tm->vnet_main,
- &sw_if_index))
- ;
+ &sw_if_index))
+ ;
else
return clib_error_return (0, "unknown input `%U'",
- format_unformat_error, input);
+ format_unformat_error, input);
if (unformat (input, "%s", &intfc_name))
;
else
return clib_error_return (0, "unknown input `%U'",
- format_unformat_error, input);
+ format_unformat_error, input);
- if (unformat(input, "hwaddr %U", unformat_ethernet_address,
- &hwaddr))
+ if (unformat (input, "hwaddr %U", unformat_ethernet_address, &hwaddr))
user_hwaddr = 1;
- memset (ap, 0, sizeof(*ap));
+ memset (ap, 0, sizeof (*ap));
ap->orig_sw_if_index = sw_if_index;
ap->intfc_name = intfc_name;
ap->sw_if_indexp = &new_sw_if_index;
@@ -1276,22 +1326,29 @@ tap_modify_command_fn (vlib_main_t * vm,
int rc = vnet_tap_modify (vm, ap);
- if (!rc) {
- vlib_cli_output (vm, "Modified %U for Linux tap '%s'",
- format_vnet_sw_if_index_name, tm->vnet_main,
- *(ap->sw_if_indexp), ap->intfc_name);
- } else {
- vlib_cli_output (vm, "Error during modification of tap interface. (rc: %d)", rc);
- }
+ if (!rc)
+ {
+ vlib_cli_output (vm, "Modified %U for Linux tap '%s'",
+ format_vnet_sw_if_index_name, tm->vnet_main,
+ *(ap->sw_if_indexp), ap->intfc_name);
+ }
+ else
+ {
+ vlib_cli_output (vm,
+ "Error during modification of tap interface. (rc: %d)",
+ rc);
+ }
return 0;
}
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (tap_modify_command, static) = {
.path = "tap modify",
.short_help = "tap modify <vpp-tap-intfc-name> <linux-intfc-name> [hwaddr <addr>]",
.function = tap_modify_command_fn,
};
+/* *INDENT-ON* */
/**
* @brief CLI function to connect TAP interface
@@ -1305,13 +1362,12 @@ VLIB_CLI_COMMAND (tap_modify_command, static) = {
*/
static clib_error_t *
tap_connect_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
- u8 * intfc_name = 0;
+ u8 *intfc_name = 0;
unformat_input_t _line_input, *line_input = &_line_input;
- vnet_tap_connect_args_t _a, *ap= &_a;
- tapcli_main_t * tm = &tapcli_main;
+ vnet_tap_connect_args_t _a, *ap = &_a;
+ tapcli_main_t *tm = &tapcli_main;
u8 hwaddr[6];
u8 *hwaddr_arg = 0;
u32 sw_if_index;
@@ -1331,32 +1387,32 @@ tap_connect_command_fn (vlib_main_t * vm,
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
- if (unformat(line_input, "hwaddr %U", unformat_ethernet_address,
- &hwaddr))
- hwaddr_arg = hwaddr;
-
+ if (unformat (line_input, "hwaddr %U", unformat_ethernet_address,
+ &hwaddr))
+ hwaddr_arg = hwaddr;
+
/* It is here for backward compatibility */
- else if (unformat(line_input, "hwaddr random"))
- ;
-
+ else if (unformat (line_input, "hwaddr random"))
+ ;
+
else if (unformat (line_input, "address %U/%d",
- unformat_ip4_address, &ip4_address, &ip4_mask_width))
- ip4_address_set = 1;
-
+ unformat_ip4_address, &ip4_address, &ip4_mask_width))
+ ip4_address_set = 1;
+
else if (unformat (line_input, "address %U/%d",
- unformat_ip6_address, &ip6_address, &ip6_mask_width))
- ip6_address_set = 1;
-
+ unformat_ip6_address, &ip6_address, &ip6_mask_width))
+ ip6_address_set = 1;
+
else if (unformat (line_input, "%s", &intfc_name))
- ;
+ ;
else
- {
- error = clib_error_return (0, "unknown input `%U'",
- format_unformat_error, line_input);
- goto done;
- }
+ {
+ error = clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, line_input);
+ goto done;
+ }
}
-
+
if (intfc_name == 0)
{
error = clib_error_return (0, "interface name must be specified");
@@ -1382,64 +1438,65 @@ tap_connect_command_fn (vlib_main_t * vm,
ap->sw_if_indexp = &sw_if_index;
- int rv = vnet_tap_connect(vm, ap);
+ int rv = vnet_tap_connect (vm, ap);
- switch (rv)
+ switch (rv)
{
case VNET_API_ERROR_SYSCALL_ERROR_1:
error = clib_error_return (0, "Couldn't open /dev/net/tun");
goto done;
-
+
case VNET_API_ERROR_SYSCALL_ERROR_2:
- error = clib_error_return (0, "Error setting flags on '%s'", intfc_name);
+ error =
+ clib_error_return (0, "Error setting flags on '%s'", intfc_name);
goto done;
case VNET_API_ERROR_SYSCALL_ERROR_3:
- error = clib_error_return (0, "Couldn't open provisioning socket");
+ error = clib_error_return (0, "Couldn't open provisioning socket");
goto done;
case VNET_API_ERROR_SYSCALL_ERROR_4:
- error = clib_error_return (0, "Couldn't get if_index");
+ error = clib_error_return (0, "Couldn't get if_index");
goto done;
-
+
case VNET_API_ERROR_SYSCALL_ERROR_5:
- error = clib_error_return (0, "Couldn't bind provisioning socket");
+ error = clib_error_return (0, "Couldn't bind provisioning socket");
goto done;
case VNET_API_ERROR_SYSCALL_ERROR_6:
- error = clib_error_return (0, "Couldn't set device non-blocking flag");
+ error = clib_error_return (0, "Couldn't set device non-blocking flag");
goto done;
case VNET_API_ERROR_SYSCALL_ERROR_7:
- error = clib_error_return (0, "Couldn't set device MTU");
+ error = clib_error_return (0, "Couldn't set device MTU");
goto done;
case VNET_API_ERROR_SYSCALL_ERROR_8:
- error = clib_error_return (0, "Couldn't get interface flags");
+ error = clib_error_return (0, "Couldn't get interface flags");
goto done;
case VNET_API_ERROR_SYSCALL_ERROR_9:
- error = clib_error_return (0, "Couldn't set intfc admin state up");
+ error = clib_error_return (0, "Couldn't set intfc admin state up");
goto done;
case VNET_API_ERROR_SYSCALL_ERROR_10:
- error = clib_error_return (0, "Couldn't set intfc address/mask");
+ error = clib_error_return (0, "Couldn't set intfc address/mask");
goto done;
case VNET_API_ERROR_INVALID_REGISTRATION:
- error = clib_error_return (0, "Invalid registration");
+ error = clib_error_return (0, "Invalid registration");
goto done;
case 0:
break;
default:
- error = clib_error_return (0, "Unknown error: %d", rv);
+ error = clib_error_return (0, "Unknown error: %d", rv);
goto done;
}
- vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name,
- vnet_get_main(), sw_if_index);
+ vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
+ vnet_get_main (), sw_if_index);
done:
unformat_free (line_input);
@@ -1447,12 +1504,14 @@ done:
return error;
}
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (tap_connect_command, static) = {
.path = "tap connect",
.short_help =
- "tap connect <intfc-name> [address <ip-addr>/mw] [hwaddr <addr>]",
+ "tap connect <intfc-name> [address <ip-addr>/mw] [hwaddr <addr>]",
.function = tap_connect_command_fn,
};
+/* *INDENT-ON* */
/**
* @brief TAPCLI main init
@@ -1465,27 +1524,35 @@ VLIB_CLI_COMMAND (tap_connect_command, static) = {
clib_error_t *
tapcli_init (vlib_main_t * vm)
{
- tapcli_main_t * tm = &tapcli_main;
- vlib_thread_main_t * m = vlib_get_thread_main ();
- tapcli_per_thread_t * thread;
+ tapcli_main_t *tm = &tapcli_main;
+ vlib_thread_main_t *m = vlib_get_thread_main ();
+ tapcli_per_thread_t *thread;
tm->vlib_main = vm;
- tm->vnet_main = vnet_get_main();
+ tm->vnet_main = vnet_get_main ();
tm->mtu_bytes = TAP_MTU_DEFAULT;
- tm->tapcli_interface_index_by_sw_if_index = hash_create (0, sizeof(uword));
+ tm->tapcli_interface_index_by_sw_if_index = hash_create (0, sizeof (uword));
tm->tapcli_interface_index_by_unix_fd = hash_create (0, sizeof (uword));
vm->os_punt_frame = tapcli_nopunt_frame;
vec_validate_aligned (tm->threads, m->n_vlib_mains - 1,
CLIB_CACHE_LINE_BYTES);
vec_foreach (thread, tm->threads)
- {
- thread->iovecs = 0;
- thread->rx_buffers = 0;
- vec_alloc(thread->rx_buffers, VLIB_FRAME_SIZE);
- vec_reset_length(thread->rx_buffers);
- }
+ {
+ thread->iovecs = 0;
+ thread->rx_buffers = 0;
+ vec_alloc (thread->rx_buffers, VLIB_FRAME_SIZE);
+ vec_reset_length (thread->rx_buffers);
+ }
return 0;
}
VLIB_INIT_FUNCTION (tapcli_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */