X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fvnet%2Fpg%2Finput.c;h=940bf124c56bb7de563899e0f93812c27af7e216;hb=f0ca1e8d92114582ec9142bd15a40f1eb0102793;hp=138a5757c83f32a198b1bcfd984addc1ec6c4457;hpb=8934a04596d1421c35b194949b2027ca1fe71aef;p=vpp.git diff --git a/src/vnet/pg/input.c b/src/vnet/pg/input.c index 138a5757c83..940bf124c56 100644 --- a/src/vnet/pg/input.c +++ b/src/vnet/pg/input.c @@ -50,7 +50,11 @@ #include #include #include +#include +#include +#include #include +#include static int validate_buffer_data2 (vlib_buffer_t * b, pg_stream_t * s, @@ -1103,12 +1107,14 @@ init_buffers_inline (vlib_main_t * vm, b0 = vlib_get_buffer (vm, bi0); b1 = vlib_get_buffer (vm, bi1); + b0->flags |= s->buffer_flags; + b1->flags |= s->buffer_flags; vnet_buffer (b0)->sw_if_index[VLIB_RX] = vnet_buffer (b1)->sw_if_index[VLIB_RX] = s->sw_if_index[VLIB_RX]; vnet_buffer (b0)->sw_if_index[VLIB_TX] = - vnet_buffer (b1)->sw_if_index[VLIB_TX] = (u32) ~ 0; + vnet_buffer (b1)->sw_if_index[VLIB_TX] = s->sw_if_index[VLIB_TX]; if (set_data) { @@ -1132,9 +1138,9 @@ init_buffers_inline (vlib_main_t * vm, n_left -= 1; b0 = vlib_get_buffer (vm, bi0); + b0->flags |= s->buffer_flags; vnet_buffer (b0)->sw_if_index[VLIB_RX] = s->sw_if_index[VLIB_RX]; - /* s->sw_if_index[VLIB_TX]; */ - vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0; + vnet_buffer (b0)->sw_if_index[VLIB_TX] = s->sw_if_index[VLIB_TX]; if (set_data) clib_memcpy_fast (b0->data, data, n_data); @@ -1266,8 +1272,8 @@ pg_stream_fill_replay (pg_main_t * pg, pg_stream_t * s, u32 n_alloc) b = vlib_get_buffer (vm, buffers[current_buffer_index]); clib_memcpy_fast (b->data, d0 + data_offset, bytes_this_chunk); vnet_buffer (b)->sw_if_index[VLIB_RX] = s->sw_if_index[VLIB_RX]; - vnet_buffer (b)->sw_if_index[VLIB_TX] = (u32) ~ 0; - b->flags = 0; + vnet_buffer (b)->sw_if_index[VLIB_TX] = s->sw_if_index[VLIB_TX]; + b->flags = s->buffer_flags; b->next_buffer = 0; b->current_data = 0; b->current_length = bytes_this_chunk; @@ -1427,7 +1433,7 @@ format_pg_input_trace (u8 * s, va_list * va) s = format (s, "stream %d", t->stream_index); s = format (s, ", %d bytes", t->packet_length); - s = format (s, ", %d sw_if_index", t->sw_if_index); + s = format (s, ", sw_if_index %d", t->sw_if_index); s = format (s, "\n%U%U", format_white_space, indent, format_vnet_buffer, &t->buffer); @@ -1448,18 +1454,17 @@ format_pg_input_trace (u8 * s, va_list * va) return s; } -static void +static int pg_input_trace (pg_main_t * pg, - vlib_node_runtime_t * node, - pg_stream_t * s, u32 * buffers, u32 n_buffers) + vlib_node_runtime_t * node, u32 stream_index, u32 next_index, + u32 * buffers, const u32 n_buffers, const u32 n_trace) { vlib_main_t *vm = vlib_get_main (); - u32 *b, n_left, stream_index, next_index; + u32 *b, n_left; + u32 n_trace0 = 0, n_trace1 = 0; - n_left = n_buffers; + n_left = clib_min (n_buffers, n_trace); b = buffers; - stream_index = s - pg->streams; - next_index = s->next_index; while (n_left >= 2) { @@ -1475,8 +1480,10 @@ pg_input_trace (pg_main_t * pg, b0 = vlib_get_buffer (vm, bi0); b1 = vlib_get_buffer (vm, bi1); - vlib_trace_buffer (vm, node, next_index, b0, /* follow_chain */ 1); - vlib_trace_buffer (vm, node, next_index, b1, /* follow_chain */ 1); + n_trace0 += + vlib_trace_buffer (vm, node, next_index, b0, /* follow_chain */ 1); + n_trace1 += + vlib_trace_buffer (vm, node, next_index, b1, /* follow_chain */ 1); t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0])); @@ -1513,7 +1520,8 @@ pg_input_trace (pg_main_t * pg, b0 = vlib_get_buffer (vm, bi0); - vlib_trace_buffer (vm, node, next_index, b0, /* follow_chain */ 1); + n_trace0 += + vlib_trace_buffer (vm, node, next_index, b0, /* follow_chain */ 1); t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); t0->stream_index = stream_index; @@ -1524,6 +1532,86 @@ pg_input_trace (pg_main_t * pg, clib_memcpy_fast (t0->buffer.pre_data, b0->data, sizeof (t0->buffer.pre_data)); } + + return n_trace - n_trace0 - n_trace1; +} + +static_always_inline void +fill_buffer_offload_flags (vlib_main_t * vm, u32 * buffers, u32 n_buffers, + int gso_enabled, u32 gso_size) +{ + for (int i = 0; i < n_buffers; i++) + { + vlib_buffer_t *b0 = vlib_get_buffer (vm, buffers[i]); + u8 l4_proto = 0; + + ethernet_header_t *eh = + (ethernet_header_t *) vlib_buffer_get_current (b0); + u16 ethertype = clib_net_to_host_u16 (eh->type); + u16 l2hdr_sz = sizeof (ethernet_header_t); + + if (ethernet_frame_is_tagged (ethertype)) + { + ethernet_vlan_header_t *vlan = (ethernet_vlan_header_t *) (eh + 1); + + ethertype = clib_net_to_host_u16 (vlan->type); + l2hdr_sz += sizeof (*vlan); + if (ethertype == ETHERNET_TYPE_VLAN) + { + vlan++; + ethertype = clib_net_to_host_u16 (vlan->type); + l2hdr_sz += sizeof (*vlan); + } + } + + vnet_buffer (b0)->l2_hdr_offset = 0; + vnet_buffer (b0)->l3_hdr_offset = l2hdr_sz; + + if (PREDICT_TRUE (ethertype == ETHERNET_TYPE_IP4)) + { + ip4_header_t *ip4 = + (ip4_header_t *) (vlib_buffer_get_current (b0) + l2hdr_sz); + vnet_buffer (b0)->l4_hdr_offset = l2hdr_sz + ip4_header_bytes (ip4); + l4_proto = ip4->protocol; + b0->flags |= + (VNET_BUFFER_F_IS_IP4 | VNET_BUFFER_F_OFFLOAD_IP_CKSUM); + b0->flags |= (VNET_BUFFER_F_L2_HDR_OFFSET_VALID + | VNET_BUFFER_F_L3_HDR_OFFSET_VALID | + VNET_BUFFER_F_L4_HDR_OFFSET_VALID); + } + else if (PREDICT_TRUE (ethertype == ETHERNET_TYPE_IP6)) + { + ip6_header_t *ip6 = + (ip6_header_t *) (vlib_buffer_get_current (b0) + l2hdr_sz); + vnet_buffer (b0)->l4_hdr_offset = l2hdr_sz + sizeof (ip6_header_t); + /* FIXME IPv6 EH traversal */ + l4_proto = ip6->protocol; + b0->flags |= + (VNET_BUFFER_F_IS_IP6 | VNET_BUFFER_F_L2_HDR_OFFSET_VALID | + VNET_BUFFER_F_L3_HDR_OFFSET_VALID | + VNET_BUFFER_F_L4_HDR_OFFSET_VALID); + } + + if (l4_proto == IP_PROTOCOL_TCP) + { + b0->flags |= VNET_BUFFER_F_OFFLOAD_TCP_CKSUM; + + /* only set GSO flag for chained buffers */ + if (gso_enabled && (b0->flags & VLIB_BUFFER_NEXT_PRESENT)) + { + b0->flags |= VNET_BUFFER_F_GSO; + tcp_header_t *tcp = + (tcp_header_t *) (vlib_buffer_get_current (b0) + + vnet_buffer (b0)->l4_hdr_offset); + vnet_buffer2 (b0)->gso_l4_hdr_sz = tcp_header_bytes (tcp); + vnet_buffer2 (b0)->gso_size = gso_size; + } + } + else if (l4_proto == IP_PROTOCOL_UDP) + { + b0->flags |= VNET_BUFFER_F_OFFLOAD_UDP_CKSUM; + } + } } static uword @@ -1541,8 +1629,11 @@ pg_generate_packets (vlib_node_runtime_t * node, u8 feature_arc_index = fm->device_input_feature_arc_index; cm = &fm->feature_config_mains[feature_arc_index]; u32 current_config_index = ~(u32) 0; + pg_interface_t *pi; int i; + pi = pool_elt_at_index (pg->interfaces, + pg->if_id_by_sw_if_index[s->sw_if_index[VLIB_RX]]); bi0 = s->buffer_indices; n_packets_in_fifo = pg_stream_fill (pg, s, n_packets_to_generate); @@ -1558,6 +1649,9 @@ pg_generate_packets (vlib_node_runtime_t * node, &next_index, 0); } + if (PREDICT_FALSE (pi->coalesce_enabled)) + vnet_gro_flow_table_schedule_node_on_dispatcher (vm, pi->flow_table); + while (n_packets_to_generate > 0) { u32 *head, *start, *end; @@ -1567,16 +1661,15 @@ pg_generate_packets (vlib_node_runtime_t * node, vlib_next_frame_t *nf; vlib_frame_t *f; ethernet_input_frame_t *ef; - pg_interface_t *pi; vlib_get_new_next_frame (vm, node, next_index, to_next, n_left); nf = vlib_node_runtime_get_next_frame (vm, node, next_index); - f = vlib_get_frame (vm, nf->frame_index); + f = vlib_get_frame (vm, nf->frame); f->flags = ETH_INPUT_FRAME_F_SINGLE_SW_IF_IDX; ef = vlib_frame_scalar_args (f); - pi = pool_elt_at_index (pg->interfaces, s->pg_if_index); ef->sw_if_index = pi->sw_if_index; ef->hw_if_index = pi->hw_if_index; + vlib_frame_no_append (f); } else vlib_get_next_frame (vm, node, next_index, to_next, n_left); @@ -1617,12 +1710,22 @@ pg_generate_packets (vlib_node_runtime_t * node, vnet_buffer (b)->feature_arc_index = feature_arc_index; } + if (pi->gso_enabled || + (s->buffer_flags & (VNET_BUFFER_F_OFFLOAD_TCP_CKSUM | + VNET_BUFFER_F_OFFLOAD_UDP_CKSUM | + VNET_BUFFER_F_OFFLOAD_IP_CKSUM))) + { + fill_buffer_offload_flags (vm, to_next, n_this_frame, + pi->gso_enabled, pi->gso_size); + } + n_trace = vlib_get_trace_count (vm, node); - if (n_trace > 0) + if (PREDICT_FALSE (n_trace > 0)) { - u32 n = clib_min (n_trace, n_this_frame); - pg_input_trace (pg, node, s, to_next, n); - vlib_set_trace_count (vm, node, n_trace - n); + n_trace = + pg_input_trace (pg, node, s - pg->streams, next_index, to_next, + n_this_frame, n_trace); + vlib_set_trace_count (vm, node, n_trace); } n_packets_to_generate -= n_this_frame; n_packets_generated += n_this_frame; @@ -1632,7 +1735,7 @@ pg_generate_packets (vlib_node_runtime_t * node, int i; vlib_buffer_t *b; - for (i = 0; i < VLIB_FRAME_SIZE - n_left; i++) + for (i = 0; i < n_this_frame; i++) { b = vlib_get_buffer (vm, to_next[i]); ASSERT ((b->flags & VLIB_BUFFER_NEXT_PRESENT) == 0 || @@ -1682,8 +1785,8 @@ pg_input_stream (vlib_node_runtime_t * node, pg_main_t * pg, pg_stream_t * s) n_packets = s->n_packets_limit - s->n_packets_generated; /* Generate up to one frame's worth of packets. */ - if (n_packets > VLIB_FRAME_SIZE) - n_packets = VLIB_FRAME_SIZE; + if (n_packets > s->n_max_frame) + n_packets = s->n_max_frame; if (n_packets > 0) n_packets = pg_generate_packets (node, pg, s, n_packets); @@ -1705,10 +1808,10 @@ pg_input (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) worker_index = vlib_get_current_worker_index (); /* *INDENT-OFF* */ - clib_bitmap_foreach (i, pg->enabled_streams[worker_index], ({ + clib_bitmap_foreach (i, pg->enabled_streams[worker_index]) { pg_stream_t *s = vec_elt_at_index (pg->streams, i); n_packets += pg_input_stream (node, pg, s); - })); + } /* *INDENT-ON* */ return n_packets; @@ -1717,6 +1820,7 @@ pg_input (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) /* *INDENT-OFF* */ VLIB_REGISTER_NODE (pg_input_node) = { .function = pg_input, + .flags = VLIB_NODE_FLAG_TRACE_SUPPORTED, .name = "pg-input", .sibling_of = "device-input", .type = VLIB_NODE_TYPE_INPUT, @@ -1728,6 +1832,124 @@ VLIB_REGISTER_NODE (pg_input_node) = { }; /* *INDENT-ON* */ +VLIB_NODE_FN (pg_input_mac_filter) (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * frame) +{ + vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs; + u16 nexts[VLIB_FRAME_SIZE], *next; + pg_main_t *pg = &pg_main; + u32 n_left, *from; + + from = vlib_frame_vector_args (frame); + n_left = frame->n_vectors; + next = nexts; + + clib_memset_u16 (next, 0, VLIB_FRAME_SIZE); + + vlib_get_buffers (vm, from, bufs, n_left); + + while (n_left) + { + const ethernet_header_t *eth; + pg_interface_t *pi; + mac_address_t in; + + pi = pool_elt_at_index + (pg->interfaces, + pg->if_id_by_sw_if_index[vnet_buffer (b[0])->sw_if_index[VLIB_RX]]); + eth = vlib_buffer_get_current (b[0]); + + mac_address_from_bytes (&in, eth->dst_address); + + if (PREDICT_FALSE (ethernet_address_cast (in.bytes))) + { + mac_address_t *allowed; + + if (0 != vec_len (pi->allowed_mcast_macs)) + { + vec_foreach (allowed, pi->allowed_mcast_macs) + { + if (0 != mac_address_cmp (allowed, &in)) + break; + } + + if (vec_is_member (allowed, pi->allowed_mcast_macs)) + vnet_feature_next_u16 (&next[0], b[0]); + } + } + + b += 1; + next += 1; + n_left -= 1; + } + + vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors); + + return (frame->n_vectors); +} + +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (pg_input_mac_filter) = { + .name = "pg-input-mac-filter", + .vector_size = sizeof (u32), + .format_trace = format_pg_input_trace, + .n_next_nodes = 1, + .next_nodes = { + [0] = "error-drop", + }, +}; +VNET_FEATURE_INIT (pg_input_mac_filter_feat, static) = { + .arc_name = "device-input", + .node_name = "pg-input-mac-filter", +}; +/* *INDENT-ON* */ + +static clib_error_t * +pg_input_mac_filter_cfg (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u32 sw_if_index = ~0; + int is_enable = 1; + + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "%U", + unformat_vnet_sw_interface, + vnet_get_main (), &sw_if_index)) + ; + else if (unformat (line_input, "%U", + unformat_vlib_enable_disable, &is_enable)) + ; + else + return clib_error_create ("unknown input `%U'", + format_unformat_error, line_input); + } + unformat_free (line_input); + + if (~0 == sw_if_index) + return clib_error_create ("specify interface"); + + vnet_feature_enable_disable ("device-input", + "pg-input-mac-filter", + sw_if_index, is_enable, 0, 0); + + return NULL; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (enable_streams_cli, static) = { + .path = "packet-generator mac-filter", + .short_help = "packet-generator mac-filter ", + .function = pg_input_mac_filter_cfg, +}; +/* *INDENT-ON* */ + + /* * fd.io coding-style-patch-verification: ON *