+ tcp = ip4_next_header (ip4);
+ vnet_buffer (b)->tcp.hdr_offset = (u8 *) tcp - (u8 *) ip4;
+ n_advance_bytes = (ip_hdr_bytes + tcp_header_bytes (tcp));
+ n_data_bytes = clib_net_to_host_u16 (ip4->length) - n_advance_bytes;
+
+ /* Length check. Checksum computed by ipx_local no need to compute again */
+ if (PREDICT_FALSE (n_data_bytes < 0))
+ {
+ *error = TCP_ERROR_LENGTH;
+ return 0;
+ }
+
+ tc = session_lookup_connection_wt4 (fib_index, &ip4->dst_address,
+ &ip4->src_address, tcp->dst_port,
+ tcp->src_port, TRANSPORT_PROTO_TCP,
+ thread_index, &is_filtered);
+ }
+ else
+ {
+ ip6_header_t *ip6 = vlib_buffer_get_current (b);
+ if (PREDICT_FALSE (b->current_length < sizeof (*ip6) + sizeof (*tcp)))
+ {
+ *error = TCP_ERROR_LENGTH;
+ return 0;
+ }
+ tcp = ip6_next_header (ip6);
+ vnet_buffer (b)->tcp.hdr_offset = (u8 *) tcp - (u8 *) ip6;
+ n_advance_bytes = tcp_header_bytes (tcp);
+ n_data_bytes = clib_net_to_host_u16 (ip6->payload_length)
+ - n_advance_bytes;
+ n_advance_bytes += sizeof (ip6[0]);
+
+ if (PREDICT_FALSE (n_data_bytes < 0))
+ {
+ *error = TCP_ERROR_LENGTH;
+ return 0;
+ }
+
+ tc = session_lookup_connection_wt6 (fib_index, &ip6->dst_address,
+ &ip6->src_address, tcp->dst_port,
+ tcp->src_port, TRANSPORT_PROTO_TCP,
+ thread_index, &is_filtered);
+ }
+
+ vnet_buffer (b)->tcp.seq_number = clib_net_to_host_u32 (tcp->seq_number);
+ vnet_buffer (b)->tcp.ack_number = clib_net_to_host_u32 (tcp->ack_number);
+ vnet_buffer (b)->tcp.data_offset = n_advance_bytes;
+ vnet_buffer (b)->tcp.data_len = n_data_bytes;
+ vnet_buffer (b)->tcp.seq_end = vnet_buffer (b)->tcp.seq_number
+ + n_data_bytes;
+ vnet_buffer (b)->tcp.flags = 0;
+
+ *error = is_filtered ? TCP_ERROR_FILTERED : *error;
+
+ return tcp_get_connection_from_transport (tc);
+}
+
+static inline void
+tcp_input_dispatch_buffer (tcp_main_t * tm, tcp_connection_t * tc,
+ vlib_buffer_t * b, u16 * next, u32 * error)
+{
+ tcp_header_t *tcp;
+ u8 flags;
+
+ tcp = tcp_buffer_hdr (b);
+ flags = tcp->flags & filter_flags;
+ *next = tm->dispatch_table[tc->state][flags].next;
+ *error = tm->dispatch_table[tc->state][flags].error;
+
+ if (PREDICT_FALSE (*error == TCP_ERROR_DISPATCH
+ || *next == TCP_INPUT_NEXT_RESET))
+ {
+ /* Overload tcp flags to store state */
+ tcp_state_t state = tc->state;
+ vnet_buffer (b)->tcp.flags = tc->state;
+
+ if (*error == TCP_ERROR_DISPATCH)
+ clib_warning ("tcp conn %u disp error state %U flags %U",
+ tc->c_c_index, format_tcp_state, state,
+ format_tcp_flags, (int) flags);