*/
#include <vnet/vnet.h>
+#include <vnet/ip/icmp46_packet.h>
+#include <vnet/ip/ip4.h>
+#include <vnet/ip/ip6.h>
+#include <vnet/udp/udp_packet.h>
#include <vnet/feature/feature.h>
typedef struct
interface_output_trace_t *t = va_arg (*va, interface_output_trace_t *);
vnet_main_t *vnm = vnet_get_main ();
vnet_sw_interface_t *si;
- uword indent;
+ u32 indent;
if (t->sw_if_index != (u32) ~ 0)
{
}
}
-static never_inline u32
-slow_path (vlib_main_t * vm,
- u32 bi,
- vlib_buffer_t * b,
- u32 n_left_to_tx, u32 * to_tx, u32 * n_slow_bytes_result)
-{
- /* We've already enqueued a single buffer. */
- u32 n_buffers = 0;
- u32 n_slow_bytes = 0;
-
- while (n_left_to_tx > 0)
- {
- to_tx[0] = bi;
- to_tx += 1;
- n_left_to_tx -= 1;
- n_buffers += 1;
- n_slow_bytes += vlib_buffer_length_in_chain (vm, b);
-
- /* Be grumpy about zero length buffers for benefit of
- driver tx function. */
- ASSERT (b->current_length > 0);
-
- if (!(b->flags & VLIB_BUFFER_NEXT_PRESENT))
- break;
-
- bi = b->next_buffer;
- b = vlib_get_buffer (vm, bi);
- }
-
- /* Ran out of space in next frame trying to enqueue buffers? */
- if (b->flags & VLIB_BUFFER_NEXT_PRESENT)
- return 0;
-
- *n_slow_bytes_result = n_slow_bytes;
- return n_buffers;
-}
-
-/*
- * Increment TX stats. Roll up consecutive increments to the same sw_if_index
- * into one increment.
- */
static_always_inline void
-incr_output_stats (vnet_main_t * vnm,
- u32 cpu_index,
- u32 length,
- u32 sw_if_index,
- u32 * last_sw_if_index, u32 * n_packets, u32 * n_bytes)
-{
- vnet_interface_main_t *im;
-
- if (PREDICT_TRUE (sw_if_index == *last_sw_if_index))
- {
- *n_packets += 1;
- *n_bytes += length;
- }
- else
- {
- if (PREDICT_TRUE (*last_sw_if_index != ~0))
- {
- im = &vnm->interface_main;
-
- vlib_increment_combined_counter (im->combined_sw_if_counters
- + VNET_INTERFACE_COUNTER_TX,
- cpu_index,
- *last_sw_if_index,
- *n_packets, *n_bytes);
- }
- *last_sw_if_index = sw_if_index;
- *n_packets = 1;
- *n_bytes = length;
- }
-}
-
-
-/* Interface output functions. */
-uword
-vnet_interface_output_node_flatten (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+calc_checksums (vlib_main_t * vm, vlib_buffer_t * b)
{
- vnet_main_t *vnm = vnet_get_main ();
- vnet_interface_output_runtime_t *rt = (void *) node->runtime_data;
- vnet_sw_interface_t *si;
- vnet_hw_interface_t *hi;
- u32 n_left_to_tx, *from, *from_end, *to_tx;
- u32 n_bytes, n_buffers, n_packets;
- u32 last_sw_if_index;
- u32 cpu_index = vm->cpu_index;
+ ip4_header_t *ip4;
+ ip6_header_t *ip6;
+ tcp_header_t *th;
+ udp_header_t *uh;
- n_buffers = frame->n_vectors;
-
- if (node->flags & VLIB_NODE_FLAG_TRACE)
- vnet_interface_output_trace (vm, node, frame, n_buffers);
+ int is_ip4 = (b->flags & VNET_BUFFER_F_IS_IP4) != 0;
+ int is_ip6 = (b->flags & VNET_BUFFER_F_IS_IP6) != 0;
- from = vlib_frame_args (frame);
+ ASSERT (!(is_ip4 && is_ip6));
- if (rt->is_deleted)
- return vlib_error_drop_buffers (vm, node, from,
- /* buffer stride */ 1,
- n_buffers,
- VNET_INTERFACE_OUTPUT_NEXT_DROP,
- node->node_index,
- VNET_INTERFACE_OUTPUT_ERROR_INTERFACE_DELETED);
+ ip4 = (ip4_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset);
+ ip6 = (ip6_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset);
+ th = (tcp_header_t *) (b->data + vnet_buffer (b)->l4_hdr_offset);
+ uh = (udp_header_t *) (b->data + vnet_buffer (b)->l4_hdr_offset);
- si = vnet_get_sw_interface (vnm, rt->sw_if_index);
- hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index);
- if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ||
- !(hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP))
+ if (is_ip4)
{
- vlib_simple_counter_main_t *cm;
-
- cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
- VNET_INTERFACE_COUNTER_TX_ERROR);
- vlib_increment_simple_counter (cm, cpu_index,
- rt->sw_if_index, n_buffers);
- return vlib_error_drop_buffers (vm, node, from,
- /* buffer stride */ 1,
- n_buffers,
- VNET_INTERFACE_OUTPUT_NEXT_DROP,
- node->node_index,
- VNET_INTERFACE_OUTPUT_ERROR_INTERFACE_DOWN);
+ ip4 = (ip4_header_t *) (b->data + vnet_buffer (b)->l3_hdr_offset);
+ if (b->flags & VNET_BUFFER_F_OFFLOAD_IP_CKSUM)
+ ip4->checksum = ip4_header_checksum (ip4);
+ if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
+ th->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip4);
+ if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM)
+ uh->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip4);
}
-
- from_end = from + n_buffers;
-
- /* Total byte count of all buffers. */
- n_bytes = 0;
- n_packets = 0;
- last_sw_if_index = ~0;
-
- while (from < from_end)
+ if (is_ip6)
{
- /* Get new next frame since previous incomplete frame may have less
- than VNET_FRAME_SIZE vectors in it. */
- vlib_get_new_next_frame (vm, node, VNET_INTERFACE_OUTPUT_NEXT_TX,
- to_tx, n_left_to_tx);
-
- while (from + 4 <= from_end && n_left_to_tx >= 2)
- {
- u32 bi0, bi1;
- vlib_buffer_t *b0, *b1;
-
- /* Prefetch next iteration. */
- vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
- vlib_prefetch_buffer_with_index (vm, from[3], LOAD);
-
- bi0 = from[0];
- bi1 = from[1];
- to_tx[0] = bi0;
- to_tx[1] = bi1;
- from += 2;
- to_tx += 2;
- n_left_to_tx -= 2;
-
- b0 = vlib_get_buffer (vm, bi0);
- b1 = vlib_get_buffer (vm, bi1);
-
- /* Be grumpy about zero length buffers for benefit of
- driver tx function. */
- ASSERT (b0->current_length > 0);
- ASSERT (b1->current_length > 0);
-
- if (PREDICT_FALSE
- ((b0->flags | b1->flags) & VLIB_BUFFER_NEXT_PRESENT))
- {
- u32 n_buffers, n_slow_bytes, i;
-
- /* Undo. */
- from -= 2;
- to_tx -= 2;
- n_left_to_tx += 2;
-
- /* Do slow path two times. */
- for (i = 0; i < 2; i++)
- {
- u32 bi = i ? bi1 : bi0;
- vlib_buffer_t *b = i ? b1 : b0;
-
- n_buffers = slow_path (vm, bi, b,
- n_left_to_tx, to_tx, &n_slow_bytes);
-
- /* Not enough room for single packet? */
- if (n_buffers == 0)
- goto put;
-
- from += 1;
- to_tx += n_buffers;
- n_left_to_tx -= n_buffers;
- incr_output_stats (vnm, cpu_index, n_slow_bytes,
- vnet_buffer (b)->sw_if_index[VLIB_TX],
- &last_sw_if_index, &n_packets, &n_bytes);
- }
- }
- else
- {
- incr_output_stats (vnm, cpu_index,
- vlib_buffer_length_in_chain (vm, b0),
- vnet_buffer (b0)->sw_if_index[VLIB_TX],
- &last_sw_if_index, &n_packets, &n_bytes);
- incr_output_stats (vnm, cpu_index,
- vlib_buffer_length_in_chain (vm, b0),
- vnet_buffer (b1)->sw_if_index[VLIB_TX],
- &last_sw_if_index, &n_packets, &n_bytes);
- }
- }
-
- while (from + 1 <= from_end && n_left_to_tx >= 1)
- {
- u32 bi0;
- vlib_buffer_t *b0;
-
- bi0 = from[0];
- to_tx[0] = bi0;
- from += 1;
- to_tx += 1;
- n_left_to_tx -= 1;
-
- b0 = vlib_get_buffer (vm, bi0);
-
- /* Be grumpy about zero length buffers for benefit of
- driver tx function. */
- ASSERT (b0->current_length > 0);
-
- if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_NEXT_PRESENT))
- {
- u32 n_buffers, n_slow_bytes;
-
- /* Undo. */
- from -= 1;
- to_tx -= 1;
- n_left_to_tx += 1;
-
- n_buffers = slow_path (vm, bi0, b0,
- n_left_to_tx, to_tx, &n_slow_bytes);
-
- /* Not enough room for single packet? */
- if (n_buffers == 0)
- goto put;
-
- from += 1;
- to_tx += n_buffers;
- n_left_to_tx -= n_buffers;
- }
- incr_output_stats (vnm, cpu_index,
- vlib_buffer_length_in_chain (vm, b0),
- vnet_buffer (b0)->sw_if_index[VLIB_TX],
- &last_sw_if_index, &n_packets, &n_bytes);
- }
-
- put:
- vlib_put_next_frame (vm, node, VNET_INTERFACE_OUTPUT_NEXT_TX,
- n_left_to_tx);
+ int bogus;
+ if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM)
+ th->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus);
+ if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM)
+ uh->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus);
}
- /* Final update of interface stats. */
- incr_output_stats (vnm, cpu_index, 0, ~0, /* ~0 will flush stats */
- &last_sw_if_index, &n_packets, &n_bytes);
-
- return n_buffers;
+ b->flags &= ~VNET_BUFFER_F_OFFLOAD_TCP_CKSUM;
+ b->flags &= ~VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
+ b->flags &= ~VNET_BUFFER_F_OFFLOAD_IP_CKSUM;
}
-VLIB_NODE_FUNCTION_MULTIARCH_CLONE (vnet_interface_output_node_flatten);
-CLIB_MULTIARCH_SELECT_FN (vnet_interface_output_node_flatten);
-
-uword
-vnet_interface_output_node (vlib_main_t * vm,
- vlib_node_runtime_t * node, vlib_frame_t * frame)
+static_always_inline uword
+vnet_interface_output_node_inline (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame, vnet_main_t * vnm,
+ vnet_hw_interface_t * hi,
+ int do_tx_offloads)
{
- vnet_main_t *vnm = vnet_get_main ();
vnet_interface_output_runtime_t *rt = (void *) node->runtime_data;
vnet_sw_interface_t *si;
- vnet_hw_interface_t *hi;
u32 n_left_to_tx, *from, *from_end, *to_tx;
u32 n_bytes, n_buffers, n_packets;
u32 n_bytes_b0, n_bytes_b1, n_bytes_b2, n_bytes_b3;
- u32 cpu_index = vm->cpu_index;
+ u32 thread_index = vm->thread_index;
vnet_interface_main_t *im = &vnm->interface_main;
u32 next_index = VNET_INTERFACE_OUTPUT_NEXT_TX;
u32 current_config_index = ~0;
si = vnet_get_sw_interface (vnm, rt->sw_if_index);
hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index);
- if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ||
+ if (!(si->flags & (VNET_SW_INTERFACE_FLAG_ADMIN_UP |
+ VNET_SW_INTERFACE_FLAG_BOND_SLAVE)) ||
!(hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP))
{
vlib_simple_counter_main_t *cm;
cm = vec_elt_at_index (vnm->interface_main.sw_if_counters,
VNET_INTERFACE_COUNTER_TX_ERROR);
- vlib_increment_simple_counter (cm, cpu_index,
+ vlib_increment_simple_counter (cm, thread_index,
rt->sw_if_index, n_buffers);
return vlib_error_drop_buffers (vm, node, from,
u32 bi0, bi1, bi2, bi3;
vlib_buffer_t *b0, *b1, *b2, *b3;
u32 tx_swif0, tx_swif1, tx_swif2, tx_swif3;
+ u32 or_flags;
/* Prefetch next iteration. */
vlib_prefetch_buffer_with_index (vm, from[4], LOAD);
{
vlib_increment_combined_counter (im->combined_sw_if_counters +
VNET_INTERFACE_COUNTER_TX,
- cpu_index, tx_swif0, 1,
+ thread_index, tx_swif0, 1,
n_bytes_b0);
}
vlib_increment_combined_counter (im->combined_sw_if_counters +
VNET_INTERFACE_COUNTER_TX,
- cpu_index, tx_swif1, 1,
+ thread_index, tx_swif1, 1,
n_bytes_b1);
}
vlib_increment_combined_counter (im->combined_sw_if_counters +
VNET_INTERFACE_COUNTER_TX,
- cpu_index, tx_swif2, 1,
+ thread_index, tx_swif2, 1,
n_bytes_b2);
}
if (PREDICT_FALSE (tx_swif3 != rt->sw_if_index))
vlib_increment_combined_counter (im->combined_sw_if_counters +
VNET_INTERFACE_COUNTER_TX,
- cpu_index, tx_swif3, 1,
+ thread_index, tx_swif3, 1,
n_bytes_b3);
}
+
+ or_flags = b0->flags | b1->flags | b2->flags | b3->flags;
+
+ if (do_tx_offloads)
+ {
+ if (or_flags &
+ (VNET_BUFFER_F_OFFLOAD_TCP_CKSUM |
+ VNET_BUFFER_F_OFFLOAD_UDP_CKSUM |
+ VNET_BUFFER_F_OFFLOAD_IP_CKSUM))
+ {
+ calc_checksums (vm, b0);
+ calc_checksums (vm, b1);
+ calc_checksums (vm, b2);
+ calc_checksums (vm, b3);
+ }
+ }
}
while (from + 1 <= from_end && n_left_to_tx >= 1)
vlib_increment_combined_counter (im->combined_sw_if_counters +
VNET_INTERFACE_COUNTER_TX,
- cpu_index, tx_swif0, 1,
+ thread_index, tx_swif0, 1,
n_bytes_b0);
}
+
+ if (do_tx_offloads)
+ calc_checksums (vm, b0);
}
vlib_put_next_frame (vm, node, next_index, n_left_to_tx);
/* Update main interface stats. */
vlib_increment_combined_counter (im->combined_sw_if_counters
+ VNET_INTERFACE_COUNTER_TX,
- cpu_index,
+ thread_index,
rt->sw_if_index, n_packets, n_bytes);
return n_buffers;
}
+static_always_inline uword
+vnet_interface_output_node (vlib_main_t * vm, vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ vnet_main_t *vnm = vnet_get_main ();
+ vnet_hw_interface_t *hi;
+ vnet_interface_output_runtime_t *rt = (void *) node->runtime_data;
+ hi = vnet_get_sup_hw_interface (vnm, rt->sw_if_index);
+
+ if (hi->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD)
+ return vnet_interface_output_node_inline (vm, node, frame, vnm, hi,
+ /* do_tx_offloads */ 0);
+ else
+ return vnet_interface_output_node_inline (vm, node, frame, vnm, hi,
+ /* do_tx_offloads */ 1);
+}
+
VLIB_NODE_FUNCTION_MULTIARCH_CLONE (vnet_interface_output_node);
CLIB_MULTIARCH_SELECT_FN (vnet_interface_output_node);
u32 current_sw_if_index, n_errors_current_sw_if_index;
u64 current_counter;
vlib_simple_counter_main_t *cm;
- u32 cpu_index = vm->cpu_index;
+ u32 thread_index = vm->thread_index;
static vlib_error_t memory[VNET_ERROR_N_DISPOSITION];
static char memory_init[VNET_ERROR_N_DISPOSITION];
current_counter -= 2;
n_errors_current_sw_if_index -= 2;
- vlib_increment_simple_counter (cm, cpu_index, sw_if_index0, 1);
- vlib_increment_simple_counter (cm, cpu_index, sw_if_index1, 1);
+ vlib_increment_simple_counter (cm, thread_index, sw_if_index0, 1);
+ vlib_increment_simple_counter (cm, thread_index, sw_if_index1, 1);
/* Increment super-interface drop/punt counters for
sub-interfaces. */
sw_if0 = vnet_get_sw_interface (vnm, sw_if_index0);
vlib_increment_simple_counter
- (cm, cpu_index, sw_if0->sup_sw_if_index,
+ (cm, thread_index, sw_if0->sup_sw_if_index,
sw_if0->sup_sw_if_index != sw_if_index0);
sw_if1 = vnet_get_sw_interface (vnm, sw_if_index1);
vlib_increment_simple_counter
- (cm, cpu_index, sw_if1->sup_sw_if_index,
+ (cm, thread_index, sw_if1->sup_sw_if_index,
sw_if1->sup_sw_if_index != sw_if_index1);
em->counters[current_counter_index] = current_counter;
sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
/* Increment drop/punt counters. */
- vlib_increment_simple_counter (cm, cpu_index, sw_if_index0, 1);
+ vlib_increment_simple_counter (cm, thread_index, sw_if_index0, 1);
/* Increment super-interface drop/punt counters for sub-interfaces. */
sw_if0 = vnet_get_sw_interface (vnm, sw_if_index0);
- vlib_increment_simple_counter (cm, cpu_index, sw_if0->sup_sw_if_index,
+ vlib_increment_simple_counter (cm, thread_index,
+ sw_if0->sup_sw_if_index,
sw_if0->sup_sw_if_index != sw_if_index0);
if (PREDICT_FALSE (e0 != current_error))
{
vnet_sw_interface_t *si;
- vlib_increment_simple_counter (cm, cpu_index, current_sw_if_index,
+ vlib_increment_simple_counter (cm, thread_index, current_sw_if_index,
n_errors_current_sw_if_index);
si = vnet_get_sw_interface (vnm, current_sw_if_index);
if (si->sup_sw_if_index != current_sw_if_index)
- vlib_increment_simple_counter (cm, cpu_index, si->sup_sw_if_index,
+ vlib_increment_simple_counter (cm, thread_index, si->sup_sw_if_index,
n_errors_current_sw_if_index);
}
if (im->pcap_filename)
vec_free (im->pcap_filename);
- vec_add1 (filename, 0);
im->pcap_filename = chroot_filename;
+ im->pcap_main.file_name = (char *) im->pcap_filename;
matched = 1;
}
else if (unformat (input, "status"))