X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=vnet%2Fvnet%2Fip%2Fip4_forward.c;h=5327ba50730553c8582bfccfacc5ffc17079430c;hb=820e363a8d60ec05f1cf18c0c3bf7a200f5a896d;hp=5c2ac3828a1ea95f473d219fd3b2631aeaaf4e3e;hpb=3419d0b9c1f64c6f477601eeea6b0e5465a89dce;p=vpp.git diff --git a/vnet/vnet/ip/ip4_forward.c b/vnet/vnet/ip/ip4_forward.c index 5c2ac3828a1..5327ba50730 100644 --- a/vnet/vnet/ip/ip4_forward.c +++ b/vnet/vnet/ip/ip4_forward.c @@ -344,6 +344,8 @@ ip4_add_del_route_next_hop (ip4_main_t * im, { /* Next hop is not known, so create indirect adj */ ip_adjacency_t add_adj; + memset (&add_adj, 0, sizeof(add_adj)); + add_adj.n_adj = 1; add_adj.lookup_next_index = IP_LOOKUP_NEXT_INDIRECT; add_adj.indirect.next_hop.ip4.as_u32 = next_hop->as_u32; add_adj.explicit_fib_index = explicit_fib_index; @@ -632,6 +634,12 @@ void ip4_delete_matching_routes (ip4_main_t * im, ip4_maybe_remap_adjacencies (im, table_index_or_table_id, flags); } +void +ip4_forward_next_trace (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * frame, + vlib_rx_or_tx_t which_adj_index); + always_inline uword ip4_lookup_inline (vlib_main_t * vm, vlib_node_runtime_t * node, @@ -977,6 +985,9 @@ ip4_lookup_inline (vlib_main_t * vm, vlib_put_next_frame (vm, node, next, n_left_to_next); } + if (node->flags & VLIB_NODE_FLAG_TRACE) + ip4_forward_next_trace(vm, node, frame, VLIB_TX); + return frame->n_vectors; } @@ -1344,12 +1355,15 @@ ip4_sw_interface_add_del (vnet_main_t * vnm, VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip4_sw_interface_add_del); +static u8 * format_ip4_lookup_trace (u8 * s, va_list * args); VLIB_REGISTER_NODE (ip4_lookup_node) = { .function = ip4_lookup, .name = "ip4-lookup", .vector_size = sizeof (u32), + .format_trace = format_ip4_lookup_trace, + .n_next_nodes = IP_LOOKUP_N_NEXT, .next_nodes = IP4_LOOKUP_NEXT_NODES, }; @@ -1371,6 +1385,8 @@ VLIB_REGISTER_NODE (ip4_indirect_node) = { .name = "ip4-indirect", .vector_size = sizeof (u32), + .format_trace = format_ip4_lookup_trace, + .n_next_nodes = IP_LOOKUP_N_NEXT, .next_nodes = IP4_LOOKUP_NEXT_NODES, }; @@ -1451,33 +1467,52 @@ typedef struct { } ip4_forward_next_trace_t; static u8 * format_ip4_forward_next_trace (u8 * s, va_list * args) +{ + CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); + CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); + ip4_forward_next_trace_t * t = va_arg (*args, ip4_forward_next_trace_t *); + uword indent = format_get_indent (s); + s = format (s, "%U%U", + format_white_space, indent, + format_ip4_header, t->packet_data); + return s; +} + +static u8 * format_ip4_lookup_trace (u8 * s, va_list * args) { CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); ip4_forward_next_trace_t * t = va_arg (*args, ip4_forward_next_trace_t *); vnet_main_t * vnm = vnet_get_main(); ip4_main_t * im = &ip4_main; - ip_adjacency_t * adj; uword indent = format_get_indent (s); - adj = ip_get_adjacency (&im->lookup_main, t->adj_index); s = format (s, "fib %d adj-idx %d : %U flow hash: 0x%08x", - t->fib_index, t->adj_index, format_ip_adjacency, - vnm, &im->lookup_main, t->adj_index, t->flow_hash); - switch (adj->lookup_next_index) - { - case IP_LOOKUP_NEXT_REWRITE: - s = format (s, "\n%U%U", - format_white_space, indent, - format_ip_adjacency_packet_data, - vnm, &im->lookup_main, t->adj_index, - t->packet_data, sizeof (t->packet_data)); - break; + t->fib_index, t->adj_index, format_ip_adjacency, + vnm, &im->lookup_main, t->adj_index, t->flow_hash); + s = format (s, "\n%U%U", + format_white_space, indent, + format_ip4_header, t->packet_data); + return s; +} - default: - break; - } +static u8 * format_ip4_rewrite_trace (u8 * s, va_list * args) +{ + CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); + CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); + ip4_forward_next_trace_t * t = va_arg (*args, ip4_forward_next_trace_t *); + vnet_main_t * vnm = vnet_get_main(); + ip4_main_t * im = &ip4_main; + uword indent = format_get_indent (s); + s = format (s, "tx_sw_if_index %d adj-idx %d : %U flow hash: 0x%08x", + t->fib_index, t->adj_index, format_ip_adjacency, + vnm, &im->lookup_main, t->adj_index, t->flow_hash); + s = format (s, "\n%U%U", + format_white_space, indent, + format_ip_adjacency_packet_data, + vnm, &im->lookup_main, t->adj_index, + t->packet_data, sizeof (t->packet_data)); return s; } @@ -1515,8 +1550,11 @@ ip4_forward_next_trace (vlib_main_t * vm, t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index]; t0->flow_hash = vnet_buffer (b0)->ip.flow_hash; - t0->fib_index = vec_elt (im->fib_index_by_sw_if_index, - vnet_buffer(b0)->sw_if_index[VLIB_RX]); + t0->fib_index = (vnet_buffer(b0)->sw_if_index[VLIB_TX] != (u32)~0) ? + vnet_buffer(b0)->sw_if_index[VLIB_TX] : + vec_elt (im->fib_index_by_sw_if_index, + vnet_buffer(b0)->sw_if_index[VLIB_RX]); + clib_memcpy (t0->packet_data, vlib_buffer_get_current (b0), sizeof (t0->packet_data)); @@ -1526,8 +1564,10 @@ ip4_forward_next_trace (vlib_main_t * vm, t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0])); t1->adj_index = vnet_buffer (b1)->ip.adj_index[which_adj_index]; t1->flow_hash = vnet_buffer (b1)->ip.flow_hash; - t1->fib_index = vec_elt (im->fib_index_by_sw_if_index, - vnet_buffer(b1)->sw_if_index[VLIB_RX]); + t1->fib_index = (vnet_buffer(b1)->sw_if_index[VLIB_TX] != (u32)~0) ? + vnet_buffer(b1)->sw_if_index[VLIB_TX] : + vec_elt (im->fib_index_by_sw_if_index, + vnet_buffer(b1)->sw_if_index[VLIB_RX]); clib_memcpy (t1->packet_data, vlib_buffer_get_current (b1), sizeof (t1->packet_data)); @@ -1551,8 +1591,10 @@ ip4_forward_next_trace (vlib_main_t * vm, t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index]; t0->flow_hash = vnet_buffer (b0)->ip.flow_hash; - t0->fib_index = vec_elt (im->fib_index_by_sw_if_index, - vnet_buffer(b0)->sw_if_index[VLIB_RX]); + t0->fib_index = (vnet_buffer(b0)->sw_if_index[VLIB_TX] != (u32)~0) ? + vnet_buffer(b0)->sw_if_index[VLIB_TX] : + vec_elt (im->fib_index_by_sw_if_index, + vnet_buffer(b0)->sw_if_index[VLIB_RX]); clib_memcpy (t0->packet_data, vlib_buffer_get_current (b0), sizeof (t0->packet_data)); @@ -1785,8 +1827,8 @@ ip4_local (vlib_main_t * vm, /* Treat IP frag packets as "experimental" protocol for now until support of IP frag reassembly is implemented */ - proto0 = (ip0->flags_and_fragment_offset << 2) ? 0xfe : ip0->protocol; - proto1 = (ip1->flags_and_fragment_offset << 2) ? 0xfe : ip1->protocol; + proto0 = ip4_is_fragment(ip0) ? 0xfe : ip0->protocol; + proto1 = ip4_is_fragment(ip1) ? 0xfe : ip1->protocol; is_udp0 = proto0 == IP_PROTOCOL_UDP; is_udp1 = proto1 == IP_PROTOCOL_UDP; is_tcp_udp0 = is_udp0 || proto0 == IP_PROTOCOL_TCP; @@ -1980,7 +2022,7 @@ ip4_local (vlib_main_t * vm, /* Treat IP frag packets as "experimental" protocol for now until support of IP frag reassembly is implemented */ - proto0 = (ip0->flags_and_fragment_offset << 2) ? 0xfe : ip0->protocol; + proto0 = ip4_is_fragment(ip0) ? 0xfe : ip0->protocol; is_udp0 = proto0 == IP_PROTOCOL_UDP; is_tcp_udp0 = is_udp0 || proto0 == IP_PROTOCOL_TCP; @@ -2750,7 +2792,7 @@ VLIB_REGISTER_NODE (ip4_rewrite_node) = { .name = "ip4-rewrite-transit", .vector_size = sizeof (u32), - .format_trace = format_ip4_forward_next_trace, + .format_trace = format_ip4_rewrite_trace, .n_next_nodes = 2, .next_nodes = { @@ -2761,20 +2803,16 @@ VLIB_REGISTER_NODE (ip4_rewrite_node) = { VLIB_NODE_FUNCTION_MULTIARCH (ip4_rewrite_node, ip4_rewrite_transit) -VLIB_REGISTER_NODE (ip4_rewrite_local_node,static) = { +VLIB_REGISTER_NODE (ip4_rewrite_local_node) = { .function = ip4_rewrite_local, .name = "ip4-rewrite-local", .vector_size = sizeof (u32), .sibling_of = "ip4-rewrite-transit", - .format_trace = format_ip4_forward_next_trace, + .format_trace = format_ip4_rewrite_trace, - .n_next_nodes = 2, - .next_nodes = { - [IP4_REWRITE_NEXT_DROP] = "error-drop", - [IP4_REWRITE_NEXT_ARP] = "ip4-arp", - }, + .n_next_nodes = 0, }; VLIB_NODE_FUNCTION_MULTIARCH (ip4_rewrite_local_node, ip4_rewrite_local) @@ -3040,6 +3078,9 @@ ip4_lookup_multicast (vlib_main_t * vm, vlib_put_next_frame (vm, node, next, n_left_to_next); } + if (node->flags & VLIB_NODE_FLAG_TRACE) + ip4_forward_next_trace(vm, node, frame, VLIB_TX); + return frame->n_vectors; } @@ -3048,6 +3089,8 @@ VLIB_REGISTER_NODE (ip4_lookup_multicast_node,static) = { .name = "ip4-lookup-multicast", .vector_size = sizeof (u32), + .format_trace = format_ip4_lookup_trace, + .n_next_nodes = IP_LOOKUP_N_NEXT, .next_nodes = IP4_LOOKUP_NEXT_NODES, };