*/
#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)
{
u32 n_left, *from;
n_left = n_buffers;
- from = vlib_frame_args (frame);
+ from = vlib_frame_vector_args (frame);
while (n_left >= 4)
{
{
t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
- clib_memcpy (t0->data, vlib_buffer_get_current (b0),
- sizeof (t0->data));
+ clib_memcpy_fast (t0->data, vlib_buffer_get_current (b0),
+ sizeof (t0->data));
}
if (b1->flags & VLIB_BUFFER_IS_TRACED)
{
t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
t1->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_TX];
- clib_memcpy (t1->data, vlib_buffer_get_current (b1),
- sizeof (t1->data));
+ clib_memcpy_fast (t1->data, vlib_buffer_get_current (b1),
+ sizeof (t1->data));
}
from += 2;
n_left -= 2;
{
t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
t0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_TX];
- clib_memcpy (t0->data, vlib_buffer_get_current (b0),
- sizeof (t0->data));
+ clib_memcpy_fast (t0->data, vlib_buffer_get_current (b0),
+ sizeof (t0->data));
}
from += 1;
n_left -= 1;
}
}
-uword
-vnet_interface_output_node (vlib_main_t * vm,
- vlib_node_runtime_t * node, vlib_frame_t * frame)
+static_always_inline void
+calc_checksums (vlib_main_t * vm, vlib_buffer_t * b)
+{
+ ip4_header_t *ip4;
+ ip6_header_t *ip6;
+ tcp_header_t *th;
+ udp_header_t *uh;
+
+ int is_ip4 = (b->flags & VNET_BUFFER_F_IS_IP4) != 0;
+ int is_ip6 = (b->flags & VNET_BUFFER_F_IS_IP6) != 0;
+
+ ASSERT (!(is_ip4 && is_ip6));
+
+ 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);
+
+ if (is_ip4)
+ {
+ 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 = 0;
+ 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);
+ }
+ if (is_ip6)
+ {
+ 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);
+ }
+
+ b->flags &= ~VNET_BUFFER_F_OFFLOAD_TCP_CKSUM;
+ b->flags &= ~VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
+ b->flags &= ~VNET_BUFFER_F_OFFLOAD_IP_CKSUM;
+}
+
+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;
if (node->flags & VLIB_NODE_FLAG_TRACE)
vnet_interface_output_trace (vm, node, frame, n_buffers);
- from = vlib_frame_args (frame);
+ from = vlib_frame_vector_args (frame);
if (rt->is_deleted)
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);
if (PREDICT_FALSE (current_config_index != ~0))
{
- b0->feature_arc_index = arc;
- b1->feature_arc_index = arc;
- b2->feature_arc_index = arc;
- b3->feature_arc_index = arc;
+ vnet_buffer (b0)->feature_arc_index = arc;
+ vnet_buffer (b1)->feature_arc_index = arc;
+ vnet_buffer (b2)->feature_arc_index = arc;
+ vnet_buffer (b3)->feature_arc_index = arc;
b0->current_config_index = current_config_index;
b1->current_config_index = current_config_index;
b2->current_config_index = current_config_index;
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)
if (PREDICT_FALSE (current_config_index != ~0))
{
- b0->feature_arc_index = arc;
+ vnet_buffer (b0)->feature_arc_index = arc;
b0->current_config_index = current_config_index;
}
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);
return n_buffers;
}
-VLIB_NODE_FUNCTION_MULTIARCH_CLONE (vnet_interface_output_node);
-CLIB_MULTIARCH_SELECT_FN (vnet_interface_output_node);
+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);
+}
/* Use buffer's sw_if_index[VNET_TX] to choose output interface. */
static uword
n_left_from = frame->n_vectors;
- from = vlib_frame_args (frame);
+ from = vlib_frame_vector_args (frame);
next_index = node->cached_next_index;
while (n_left_from > 0)
vnet_buffer (b1)->sw_if_index
[VLIB_TX]);
- next0 = hi0->hw_if_index;
- next1 = hi1->hw_if_index;
+ next0 = hi0->output_node_next_index;
+ next1 = hi1->output_node_next_index;
vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
n_left_to_next, bi0, bi1, next0,
vnet_buffer (b0)->sw_if_index
[VLIB_TX]);
- next0 = hi0->hw_if_index;
+ next0 = hi0->output_node_next_index;
vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
n_left_to_next, bi0, next0);
validate_error_frame (vlib_main_t * vm,
vlib_node_runtime_t * node, vlib_frame_t * f)
{
- u32 *buffers = vlib_frame_args (f);
+ u32 *buffers = vlib_frame_vector_args (f);
vlib_buffer_t *b;
u8 *msg = 0;
uword i;
static vlib_error_t memory[VNET_ERROR_N_DISPOSITION];
static char memory_init[VNET_ERROR_N_DISPOSITION];
- buffers = vlib_frame_args (frame);
+ buffers = vlib_frame_vector_args (frame);
first_buffer = buffers;
{
};
/* *INDENT-ON* */
+/* Convenience node to drop a vector of buffers with a "misc error". */
+static uword
+misc_drop_buffers (vlib_main_t * vm,
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
+{
+ return vlib_error_drop_buffers (vm, node, vlib_frame_vector_args (frame),
+ /* buffer stride */ 1,
+ frame->n_vectors,
+ /* next */ 0,
+ node->node_index,
+ /* error */ 0);
+}
+
+static char *misc_drop_buffers_error_strings[] = {
+ [0] = "misc. errors",
+};
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (misc_drop_buffers_node,static) = {
+ .function = misc_drop_buffers,
+ .name = "misc-drop-buffers",
+ .vector_size = sizeof (u32),
+ .n_errors = 1,
+ .n_next_nodes = 1,
+ .next_nodes = {
+ "error-drop",
+ },
+ .error_strings = misc_drop_buffers_error_strings,
+};
+/* *INDENT-ON* */
+
VLIB_NODE_FUNCTION_MULTIARCH (vnet_per_buffer_interface_output_node,
vnet_per_buffer_interface_output);
{
.arc_name = "interface-output",
.start_nodes = VNET_FEATURES (0),
+ .last_in_arc = "interface-tx",
.arc_index_ptr = &vnet_main.interface_main.output_feature_arc_index,
};
.runs_before = VNET_FEATURES ("interface-tx"),
};
+VNET_FEATURE_INIT (ipsec_if_tx, static) = {
+ .arc_name = "interface-output",
+ .node_name = "ipsec-if-output",
+ .runs_before = VNET_FEATURES ("interface-tx"),
+};
+
VNET_FEATURE_INIT (interface_tx, static) = {
.arc_name = "interface-output",
.node_name = "interface-tx",
vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
u32 next_index;
- next_index = vlib_node_add_next_with_slot
- (vnm->vlib_main, vnet_per_buffer_interface_output_node.index,
- hi->output_node_index,
- /* next_index */ hw_if_index);
+ if (hi->output_node_index == 0)
+ return 0;
- ASSERT (next_index == hw_if_index);
+ next_index = vlib_node_add_next
+ (vnm->vlib_main, vnet_per_buffer_interface_output_node.index,
+ hi->output_node_index);
+ hi->output_node_next_index = next_index;
return 0;
}
VNET_HW_INTERFACE_ADD_DEL_FUNCTION
(vnet_per_buffer_interface_output_hw_interface_add_del);
+void
+vnet_set_interface_output_node (vnet_main_t * vnm,
+ u32 hw_if_index, u32 node_index)
+{
+ ASSERT (node_index);
+ vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
+ u32 next_index = vlib_node_add_next
+ (vnm->vlib_main, vnet_per_buffer_interface_output_node.index, node_index);
+ hi->output_node_next_index = next_index;
+ hi->output_node_index = node_index;
+}
+
static clib_error_t *
pcap_drop_trace_command_fn (vlib_main_t * vm,
unformat_input_t * input,
if (im->pcap_filename == 0)
im->pcap_filename = format (0, "/tmp/drop.pcap%c", 0);
- memset (&im->pcap_main, 0, sizeof (im->pcap_main));
+ clib_memset (&im->pcap_main, 0, sizeof (im->pcap_main));
im->pcap_main.file_name = (char *) im->pcap_filename;
im->pcap_main.n_packets_to_capture = 100;
if (im->pcap_pkts_to_capture)