X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fip%2Fip4_forward.c;h=35ebaa436d1c58395038069d89bfb616c4c00eae;hb=dd2eff6d060c787e4a49863c9b97bde7215f7740;hp=be381718312c642431dcf5a34afadf1ddf1f9784;hpb=625a1f1824e4b21e8343e1dc50c4f5400080d0ed;p=vpp.git diff --git a/src/vnet/ip/ip4_forward.c b/src/vnet/ip/ip4_forward.c index be381718312..35ebaa436d1 100644 --- a/src/vnet/ip/ip4_forward.c +++ b/src/vnet/ip/ip4_forward.c @@ -52,6 +52,7 @@ #include #include #include +#include #include #include /* for mFIB table and entry creation */ #include @@ -60,6 +61,7 @@ #include #include #include +#include /** @brief IPv4 lookup node. @node ip4-lookup @@ -653,14 +655,13 @@ ip4_add_del_interface_address_internal (vlib_main_t * vm, u32 if_address_index; ip4_address_fib_t ip4_af, *addr_fib = 0; - /* local0 interface doesn't support IP addressing */ - if (sw_if_index == 0) + error = vnet_sw_interface_supports_addressing (vnm, sw_if_index); + if (error) { - return - clib_error_create ("local0 interface doesn't support IP addressing"); + vnm->api_errno = VNET_API_ERROR_UNSUPPORTED; + return error; } - vec_validate (im->fib_index_by_sw_if_index, sw_if_index); ip4_addr_fib_init (&ip4_af, address, vec_elt (im->fib_index_by_sw_if_index, sw_if_index)); vec_add1 (addr_fib, ip4_af); @@ -888,9 +889,6 @@ ip4_sw_interface_admin_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags) ip4_address_t *a; u32 is_admin_up, fib_index; - /* Fill in lookup tables with default table (0). */ - vec_validate (im->fib_index_by_sw_if_index, sw_if_index); - vec_validate_init_empty (im-> lookup_main.if_address_pool_index_by_sw_if_index, sw_if_index, ~0); @@ -1067,11 +1065,16 @@ ip4_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add) { ip4_main_t *im = &ip4_main; - /* Fill in lookup tables with default table (0). */ - vec_validate (im->fib_index_by_sw_if_index, sw_if_index); - vec_validate (im->mfib_index_by_sw_if_index, sw_if_index); + vec_validate_init_empty (im->fib_index_by_sw_if_index, sw_if_index, ~0); + vec_validate_init_empty (im->mfib_index_by_sw_if_index, sw_if_index, ~0); - if (!is_add) + if (is_add) + { + /* Fill in lookup tables with default table (0). */ + im->fib_index_by_sw_if_index[sw_if_index] = 0; + im->mfib_index_by_sw_if_index[sw_if_index] = 0; + } + else { ip4_main_t *im4 = &ip4_main; ip_lookup_main_t *lm4 = &im4->lookup_main; @@ -1088,6 +1091,15 @@ ip4_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add) })); /* *INDENT-ON* */ ip4_mfib_interface_enable_disable (sw_if_index, 0); + + if (0 != im4->fib_index_by_sw_if_index[sw_if_index]) + fib_table_bind (FIB_PROTOCOL_IP4, sw_if_index, 0); + if (0 != im4->mfib_index_by_sw_if_index[sw_if_index]) + mfib_table_bind (FIB_PROTOCOL_IP4, sw_if_index, 0); + + /* Erase the lookup tables just in case */ + im4->fib_index_by_sw_if_index[sw_if_index] = ~0; + im4->mfib_index_by_sw_if_index[sw_if_index] = ~0; } vnet_feature_enable_disable ("ip4-unicast", "ip4-not-enabled", sw_if_index, @@ -1386,10 +1398,9 @@ ip4_tcp_udp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0) #endif /* *INDENT-OFF* */ -VNET_FEATURE_ARC_INIT (ip4_local) = -{ - .arc_name = "ip4-local", - .start_nodes = VNET_FEATURES ("ip4-local"), +VNET_FEATURE_ARC_INIT (ip4_local) = { + .arc_name = "ip4-local", + .start_nodes = VNET_FEATURES ("ip4-local", "ip4-receive"), .last_in_arc = "ip4-local-end-of-arc", }; /* *INDENT-ON* */ @@ -1468,10 +1479,10 @@ ip4_local_check_l4_csum_x2 (vlib_main_t * vm, vlib_buffer_t ** b, if (PREDICT_FALSE (ip4_local_need_csum_check (is_tcp_udp[0], b[0]) || ip4_local_need_csum_check (is_tcp_udp[1], b[1]))) { - if (is_tcp_udp[0]) + if (is_tcp_udp[0] && !ip4_local_csum_is_offloaded (b[0])) ip4_local_l4_csum_validate (vm, b[0], ih[0], is_udp[0], &error[0], &good_tcp_udp[0]); - if (is_tcp_udp[1]) + if (is_tcp_udp[1] && !ip4_local_csum_is_offloaded (b[1])) ip4_local_l4_csum_validate (vm, b[1], ih[1], is_udp[1], &error[1], &good_tcp_udp[1]); } @@ -1497,9 +1508,8 @@ ip4_local_set_next_and_error (vlib_node_runtime_t * error_node, next_index = *next; if (PREDICT_TRUE (error == (u8) IP4_ERROR_UNKNOWN_PROTOCOL)) { - vnet_feature_arc_start (arc_index, - vnet_buffer (b)->sw_if_index[VLIB_RX], - &next_index, b); + vnet_feature_arc_start ( + arc_index, vnet_buffer (b)->ip.rx_sw_if_index, &next_index, b); *next = next_index; } } @@ -1507,18 +1517,19 @@ ip4_local_set_next_and_error (vlib_node_runtime_t * error_node, typedef struct { + /* The src and fib-index together determine if packet n is the same as n-1 */ ip4_address_t src; + u32 fib_index; u32 lbi; u8 error; u8 first; } ip4_local_last_check_t; static inline void -ip4_local_check_src (vlib_buffer_t * b, ip4_header_t * ip0, - ip4_local_last_check_t * last_check, u8 * error0) +ip4_local_check_src (vlib_buffer_t *b, ip4_header_t *ip0, + ip4_local_last_check_t *last_check, u8 *error0, + int is_receive_dpo) { - ip4_fib_mtrie_leaf_t leaf0; - ip4_fib_mtrie_t *mtrie0; const dpo_id_t *dpo0; load_balance_t *lb0; u32 lbi0; @@ -1527,20 +1538,27 @@ ip4_local_check_src (vlib_buffer_t * b, ip4_header_t * ip0, vnet_buffer (b)->sw_if_index[VLIB_TX] != ~0 ? vnet_buffer (b)->sw_if_index[VLIB_TX] : vnet_buffer (b)->ip.fib_index; + vnet_buffer (b)->ip.rx_sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX]; + if (is_receive_dpo) + { + receive_dpo_t *rd; + rd = receive_dpo_get (vnet_buffer (b)->ip.adj_index[VLIB_TX]); + if (rd->rd_sw_if_index != ~0) + vnet_buffer (b)->ip.rx_sw_if_index = rd->rd_sw_if_index; + } + /* * vnet_buffer()->ip.adj_index[VLIB_RX] will be set to the index of the * adjacency for the destination address (the local interface address). * vnet_buffer()->ip.adj_index[VLIB_TX] will be set to the index of the * adjacency for the source address (the remote sender's address) */ - if (PREDICT_TRUE (last_check->src.as_u32 != ip0->src_address.as_u32) || + if (PREDICT_TRUE ((last_check->src.as_u32 != ip0->src_address.as_u32)) || + (last_check->fib_index != vnet_buffer (b)->ip.fib_index) || last_check->first) { - mtrie0 = &ip4_fib_get (vnet_buffer (b)->ip.fib_index)->mtrie; - leaf0 = ip4_fib_mtrie_lookup_step_one (mtrie0, &ip0->src_address); - leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 2); - leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 3); - lbi0 = ip4_fib_mtrie_leaf_get_adj_index (leaf0); + lbi0 = ip4_fib_forwarding_lookup (vnet_buffer (b)->ip.fib_index, + &ip0->src_address); vnet_buffer (b)->ip.adj_index[VLIB_RX] = vnet_buffer (b)->ip.adj_index[VLIB_TX]; @@ -1572,6 +1590,7 @@ ip4_local_check_src (vlib_buffer_t * b, ip4_header_t * ip0, last_check->lbi = lbi0; last_check->error = *error0; last_check->first = 0; + last_check->fib_index = vnet_buffer (b)->ip.fib_index; } else { @@ -1583,11 +1602,10 @@ ip4_local_check_src (vlib_buffer_t * b, ip4_header_t * ip0, } static inline void -ip4_local_check_src_x2 (vlib_buffer_t ** b, ip4_header_t ** ip, - ip4_local_last_check_t * last_check, u8 * error) +ip4_local_check_src_x2 (vlib_buffer_t **b, ip4_header_t **ip, + ip4_local_last_check_t *last_check, u8 *error, + int is_receive_dpo) { - ip4_fib_mtrie_leaf_t leaf[2]; - ip4_fib_mtrie_t *mtrie[2]; const dpo_id_t *dpo[2]; load_balance_t *lb[2]; u32 not_last_hit; @@ -1607,6 +1625,24 @@ ip4_local_check_src_x2 (vlib_buffer_t ** b, ip4_header_t ** ip, vnet_buffer (b[1])->sw_if_index[VLIB_TX] : vnet_buffer (b[1])->ip.fib_index; + not_last_hit |= vnet_buffer (b[0])->ip.fib_index ^ last_check->fib_index; + not_last_hit |= vnet_buffer (b[1])->ip.fib_index ^ last_check->fib_index; + + vnet_buffer (b[0])->ip.rx_sw_if_index = + vnet_buffer (b[0])->sw_if_index[VLIB_RX]; + vnet_buffer (b[1])->ip.rx_sw_if_index = + vnet_buffer (b[1])->sw_if_index[VLIB_RX]; + if (is_receive_dpo) + { + const receive_dpo_t *rd0, *rd1; + rd0 = receive_dpo_get (vnet_buffer (b[0])->ip.adj_index[VLIB_TX]); + rd1 = receive_dpo_get (vnet_buffer (b[1])->ip.adj_index[VLIB_TX]); + if (rd0->rd_sw_if_index != ~0) + vnet_buffer (b[0])->ip.rx_sw_if_index = rd0->rd_sw_if_index; + if (rd1->rd_sw_if_index != ~0) + vnet_buffer (b[1])->ip.rx_sw_if_index = rd1->rd_sw_if_index; + } + /* * vnet_buffer()->ip.adj_index[VLIB_RX] will be set to the index of the * adjacency for the destination address (the local interface address). @@ -1615,24 +1651,9 @@ ip4_local_check_src_x2 (vlib_buffer_t ** b, ip4_header_t ** ip, */ if (PREDICT_TRUE (not_last_hit)) { - mtrie[0] = &ip4_fib_get (vnet_buffer (b[0])->ip.fib_index)->mtrie; - mtrie[1] = &ip4_fib_get (vnet_buffer (b[1])->ip.fib_index)->mtrie; - - leaf[0] = ip4_fib_mtrie_lookup_step_one (mtrie[0], &ip[0]->src_address); - leaf[1] = ip4_fib_mtrie_lookup_step_one (mtrie[1], &ip[1]->src_address); - - leaf[0] = ip4_fib_mtrie_lookup_step (mtrie[0], leaf[0], - &ip[0]->src_address, 2); - leaf[1] = ip4_fib_mtrie_lookup_step (mtrie[1], leaf[1], - &ip[1]->src_address, 2); - - leaf[0] = ip4_fib_mtrie_lookup_step (mtrie[0], leaf[0], - &ip[0]->src_address, 3); - leaf[1] = ip4_fib_mtrie_lookup_step (mtrie[1], leaf[1], - &ip[1]->src_address, 3); - - lbi[0] = ip4_fib_mtrie_leaf_get_adj_index (leaf[0]); - lbi[1] = ip4_fib_mtrie_leaf_get_adj_index (leaf[1]); + ip4_fib_forwarding_lookup_x2 ( + vnet_buffer (b[0])->ip.fib_index, vnet_buffer (b[1])->ip.fib_index, + &ip[0]->src_address, &ip[1]->src_address, &lbi[0], &lbi[1]); vnet_buffer (b[0])->ip.adj_index[VLIB_RX] = vnet_buffer (b[0])->ip.adj_index[VLIB_TX]; @@ -1668,6 +1689,7 @@ ip4_local_check_src_x2 (vlib_buffer_t ** b, ip4_header_t ** ip, last_check->lbi = lbi[1]; last_check->error = error[1]; last_check->first = 0; + last_check->fib_index = vnet_buffer (b[1])->ip.fib_index; } else { @@ -1718,9 +1740,9 @@ ip4_local_classify (vlib_buffer_t * b, ip4_header_t * ip, u16 * next) } static inline uword -ip4_local_inline (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame, int head_of_feature_arc) +ip4_local_inline (vlib_main_t *vm, vlib_node_runtime_t *node, + vlib_frame_t *frame, int head_of_feature_arc, + int is_receive_dpo) { u32 *from, n_left_from; vlib_node_runtime_t *error_node = @@ -1737,10 +1759,11 @@ ip4_local_inline (vlib_main_t * vm, * member to make sure the .lbi is initialised for the first * packet. */ - .src = {.as_u32 = 0}, + .src = { .as_u32 = 0 }, .lbi = ~0, .error = IP4_ERROR_UNKNOWN_PROTOCOL, .first = 1, + .fib_index = 0, }; from = vlib_frame_vector_args (frame); @@ -1785,19 +1808,21 @@ ip4_local_inline (vlib_main_t * vm, if (PREDICT_TRUE (not_batch == 0)) { ip4_local_check_l4_csum_x2 (vm, b, ip, error); - ip4_local_check_src_x2 (b, ip, &last_check, error); + ip4_local_check_src_x2 (b, ip, &last_check, error, is_receive_dpo); } else { if (!pt[0]) { ip4_local_check_l4_csum (vm, b[0], ip[0], &error[0]); - ip4_local_check_src (b[0], ip[0], &last_check, &error[0]); + ip4_local_check_src (b[0], ip[0], &last_check, &error[0], + is_receive_dpo); } if (!pt[1]) { ip4_local_check_l4_csum (vm, b[1], ip[1], &error[1]); - ip4_local_check_src (b[1], ip[1], &last_check, &error[1]); + ip4_local_check_src (b[1], ip[1], &last_check, &error[1], + is_receive_dpo); } } @@ -1825,7 +1850,8 @@ ip4_local_inline (vlib_main_t * vm, goto skip_check; ip4_local_check_l4_csum (vm, b[0], ip[0], &error[0]); - ip4_local_check_src (b[0], ip[0], &last_check, &error[0]); + ip4_local_check_src (b[0], ip[0], &last_check, &error[0], + is_receive_dpo); skip_check: @@ -1844,17 +1870,17 @@ ip4_local_inline (vlib_main_t * vm, VLIB_NODE_FN (ip4_local_node) (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { - return ip4_local_inline (vm, node, frame, 1 /* head of feature arc */ ); + return ip4_local_inline (vm, node, frame, 1 /* head of feature arc */, + 0 /* is_receive_dpo */); } -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (ip4_local_node) = { .name = "ip4-local", .vector_size = sizeof (u32), .format_trace = format_ip4_forward_next_trace, .n_errors = IP4_N_ERROR, - .error_strings = ip4_error_strings, + .error_counters = ip4_error_counters, .n_next_nodes = IP_LOCAL_N_NEXT, .next_nodes = { @@ -1862,20 +1888,32 @@ VLIB_REGISTER_NODE (ip4_local_node) = [IP_LOCAL_NEXT_PUNT] = "ip4-punt", [IP_LOCAL_NEXT_UDP_LOOKUP] = "ip4-udp-lookup", [IP_LOCAL_NEXT_ICMP] = "ip4-icmp-input", - [IP_LOCAL_NEXT_REASSEMBLY] = "ip4-full-reassembly", + [IP_LOCAL_NEXT_REASSEMBLY] = "ip4-local-full-reassembly", }, }; -/* *INDENT-ON* */ +VLIB_NODE_FN (ip4_receive_local_node) +(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame) +{ + return ip4_local_inline (vm, node, frame, 1 /* head of feature arc */, + 1 /* is_receive_dpo */); +} + +VLIB_REGISTER_NODE (ip4_receive_local_node) = { + .name = "ip4-receive", + .vector_size = sizeof (u32), + .format_trace = format_ip4_forward_next_trace, + .sibling_of = "ip4-local" +}; VLIB_NODE_FN (ip4_local_end_of_arc_node) (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { - return ip4_local_inline (vm, node, frame, 0 /* head of feature arc */ ); + return ip4_local_inline (vm, node, frame, 0 /* head of feature arc */, + 0 /* is_receive_dpo */); } -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (ip4_local_end_of_arc_node) = { .name = "ip4-local-end-of-arc", .vector_size = sizeof (u32), @@ -1889,7 +1927,6 @@ VNET_FEATURE_INIT (ip4_local_end_of_arc, static) = { .node_name = "ip4-local-end-of-arc", .runs_before = 0, /* not before any other features */ }; -/* *INDENT-ON* */ #ifndef CLIB_MARCH_VARIANT void @@ -2026,7 +2063,9 @@ ip4_ttl_inc (vlib_buffer_t * b, ip4_header_t * ip) ttl += 1; ip->ttl = ttl; - ASSERT (ip4_header_checksum_is_valid (ip)); + ASSERT (ip4_header_checksum_is_valid (ip) || + (vnet_buffer (b)->oflags & VNET_BUFFER_OFFLOAD_F_IP_CKSUM) || + (vnet_buffer (b)->oflags & VNET_BUFFER_OFFLOAD_F_OUTER_IP_CKSUM)); } /* Decrement TTL & update checksum. @@ -2068,7 +2107,8 @@ ip4_ttl_and_checksum_check (vlib_buffer_t * b, ip4_header_t * ip, u16 * next, /* Verify checksum. */ ASSERT (ip4_header_checksum_is_valid (ip) || - (vnet_buffer (b)->oflags & VNET_BUFFER_OFFLOAD_F_IP_CKSUM)); + (vnet_buffer (b)->oflags & VNET_BUFFER_OFFLOAD_F_IP_CKSUM) || + (vnet_buffer (b)->oflags & VNET_BUFFER_OFFLOAD_F_OUTER_IP_CKSUM)); } always_inline uword