diff options
author | Damjan Marion <damarion@cisco.com> | 2016-04-13 09:48:56 +0200 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2016-04-29 17:22:16 +0000 |
commit | aca64c9de14225b0077b3fbc76b4dd7447aa6a7a (patch) | |
tree | 6dd71c77cf0a2e0a154527dc6dcf5673cc6fa455 | |
parent | 7deadac47eac81bd14fed9b999d73b08cc593f76 (diff) |
Add indirect next hop support
Change-Id: I0626c2650eba7961a15b1e87a664b57bef5503a2
Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r-- | vnet/vnet/ip/ip4_forward.c | 94 | ||||
-rw-r--r-- | vnet/vnet/ip/ip6_forward.c | 89 | ||||
-rw-r--r-- | vnet/vnet/ip/lookup.c | 3 | ||||
-rw-r--r-- | vnet/vnet/ip/lookup.h | 10 |
4 files changed, 156 insertions, 40 deletions
diff --git a/vnet/vnet/ip/ip4_forward.c b/vnet/vnet/ip/ip4_forward.c index bf101bbadab..63bc0ed8fbf 100644 --- a/vnet/vnet/ip/ip4_forward.c +++ b/vnet/vnet/ip/ip4_forward.c @@ -332,10 +332,12 @@ ip4_add_del_route_next_hop (ip4_main_t * im, } else { - vnm->api_errno = VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB; - error = clib_error_return (0, "next-hop %U/32 not in FIB", - format_ip4_address, next_hop); - goto done; + /* Next hop is not known, so create indirect adj */ + ip_adjacency_t add_adj; + 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; + ip_add_adjacency (lm, &add_adj, 1, &nh_adj_index); } } else @@ -624,7 +626,8 @@ always_inline uword ip4_lookup_inline (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame, - int lookup_for_responses_to_locally_received_packets) + int lookup_for_responses_to_locally_received_packets, + int is_indirect) { ip4_main_t * im = &ip4_main; ip_lookup_main_t * lm = &im->lookup_main; @@ -651,6 +654,7 @@ ip4_lookup_inline (vlib_main_t * vm, ip_adjacency_t * adj0, * adj1; ip4_fib_mtrie_t * mtrie0, * mtrie1; ip4_fib_mtrie_leaf_t leaf0, leaf1; + ip4_address_t * dst_addr0, *dst_addr1; __attribute__((unused)) u32 pi0, fib_index0, adj_index0, is_tcp_udp0; __attribute__((unused)) u32 pi1, fib_index1, adj_index1, is_tcp_udp1; u32 flow_hash_config0, flow_hash_config1; @@ -680,6 +684,20 @@ ip4_lookup_inline (vlib_main_t * vm, ip0 = vlib_buffer_get_current (p0); ip1 = vlib_buffer_get_current (p1); + if (is_indirect) + { + ip_adjacency_t * iadj0, * iadj1; + iadj0 = ip_get_adjacency (lm, vnet_buffer(p0)->ip.adj_index[VLIB_TX]); + iadj1 = ip_get_adjacency (lm, vnet_buffer(p1)->ip.adj_index[VLIB_TX]); + dst_addr0 = &iadj0->indirect.next_hop.ip4; + dst_addr1 = &iadj1->indirect.next_hop.ip4; + } + else + { + dst_addr0 = &ip0->dst_address; + dst_addr1 = &ip1->dst_address; + } + fib_index0 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p0)->sw_if_index[VLIB_RX]); fib_index1 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p1)->sw_if_index[VLIB_RX]); fib_index0 = (vnet_buffer(p0)->sw_if_index[VLIB_TX] == (u32)~0) ? @@ -695,8 +713,8 @@ ip4_lookup_inline (vlib_main_t * vm, leaf0 = leaf1 = IP4_FIB_MTRIE_LEAF_ROOT; - leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->dst_address, 0); - leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->dst_address, 0); + leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 0); + leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, dst_addr1, 0); } tcp0 = (void *) (ip0 + 1); @@ -709,20 +727,20 @@ ip4_lookup_inline (vlib_main_t * vm, if (! lookup_for_responses_to_locally_received_packets) { - leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->dst_address, 1); - leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->dst_address, 1); + leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 1); + leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, dst_addr1, 1); } if (! lookup_for_responses_to_locally_received_packets) { - leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->dst_address, 2); - leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->dst_address, 2); + leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 2); + leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, dst_addr1, 2); } if (! lookup_for_responses_to_locally_received_packets) { - leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->dst_address, 3); - leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->dst_address, 3); + leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 3); + leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, dst_addr1, 3); } if (lookup_for_responses_to_locally_received_packets) @@ -741,10 +759,10 @@ ip4_lookup_inline (vlib_main_t * vm, } ASSERT (adj_index0 == ip4_fib_lookup_with_table (im, fib_index0, - &ip0->dst_address, + dst_addr0, /* no_default_route */ 0)); ASSERT (adj_index1 == ip4_fib_lookup_with_table (im, fib_index1, - &ip1->dst_address, + dst_addr1, /* no_default_route */ 0)); adj0 = ip_get_adjacency (lm, adj_index0); adj1 = ip_get_adjacency (lm, adj_index1); @@ -840,6 +858,7 @@ ip4_lookup_inline (vlib_main_t * vm, ip_adjacency_t * adj0; ip4_fib_mtrie_t * mtrie0; ip4_fib_mtrie_leaf_t leaf0; + ip4_address_t * dst_addr0; __attribute__((unused)) u32 pi0, fib_index0, adj_index0, is_tcp_udp0; u32 flow_hash_config0, hash_c0; @@ -850,6 +869,17 @@ ip4_lookup_inline (vlib_main_t * vm, ip0 = vlib_buffer_get_current (p0); + if (is_indirect) + { + ip_adjacency_t * iadj0; + iadj0 = ip_get_adjacency (lm, vnet_buffer(p0)->ip.adj_index[VLIB_TX]); + dst_addr0 = &iadj0->indirect.next_hop.ip4; + } + else + { + dst_addr0 = &ip0->dst_address; + } + fib_index0 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p0)->sw_if_index[VLIB_RX]); fib_index0 = (vnet_buffer(p0)->sw_if_index[VLIB_TX] == (u32)~0) ? fib_index0 : vnet_buffer(p0)->sw_if_index[VLIB_TX]; @@ -860,7 +890,7 @@ ip4_lookup_inline (vlib_main_t * vm, leaf0 = IP4_FIB_MTRIE_LEAF_ROOT; - leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->dst_address, 0); + leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 0); } tcp0 = (void *) (ip0 + 1); @@ -869,13 +899,13 @@ ip4_lookup_inline (vlib_main_t * vm, || ip0->protocol == IP_PROTOCOL_UDP); if (! lookup_for_responses_to_locally_received_packets) - leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->dst_address, 1); + leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 1); if (! lookup_for_responses_to_locally_received_packets) - leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->dst_address, 2); + leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 2); if (! lookup_for_responses_to_locally_received_packets) - leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->dst_address, 3); + leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 3); if (lookup_for_responses_to_locally_received_packets) adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_RX]; @@ -887,7 +917,7 @@ ip4_lookup_inline (vlib_main_t * vm, } ASSERT (adj_index0 == ip4_fib_lookup_with_table (im, fib_index0, - &ip0->dst_address, + dst_addr0, /* no_default_route */ 0)); adj0 = ip_get_adjacency (lm, adj_index0); @@ -945,7 +975,9 @@ ip4_lookup (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { - return ip4_lookup_inline (vm, node, frame, /* lookup_for_responses_to_locally_received_packets */ 0); + return ip4_lookup_inline (vm, node, frame, + /* lookup_for_responses_to_locally_received_packets */ 0, + /* is_indirect */ 0); } @@ -1312,6 +1344,26 @@ VLIB_REGISTER_NODE (ip4_lookup_node) = { .next_nodes = IP4_LOOKUP_NEXT_NODES, }; +static uword +ip4_indirect (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * frame) +{ + return ip4_lookup_inline (vm, node, frame, + /* lookup_for_responses_to_locally_received_packets */ 0, + /* is_indirect */ 1); +} + +VLIB_REGISTER_NODE (ip4_indirect_node) = { + .function = ip4_indirect, + .name = "ip4-indirect", + .vector_size = sizeof (u32), + + .n_next_nodes = IP_LOOKUP_N_NEXT, + .next_nodes = IP4_LOOKUP_NEXT_NODES, +}; + + /* Global IP4 main. */ ip4_main_t ip4_main; diff --git a/vnet/vnet/ip/ip6_forward.c b/vnet/vnet/ip/ip6_forward.c index db74c75b37b..e57269a0844 100644 --- a/vnet/vnet/ip/ip6_forward.c +++ b/vnet/vnet/ip/ip6_forward.c @@ -367,10 +367,12 @@ ip6_add_del_route_next_hop (ip6_main_t * im, } else { - vnm->api_errno = VNET_API_ERROR_UNKNOWN_DESTINATION; - error = clib_error_return (0, "next-hop %U/128 not in FIB", - format_ip6_address, next_hop); - goto done; + ip_adjacency_t add_adj; + add_adj.lookup_next_index = IP_LOOKUP_NEXT_INDIRECT; + add_adj.indirect.next_hop.ip6.as_u64[0] = next_hop->as_u64[0]; + add_adj.indirect.next_hop.ip6.as_u64[1] = next_hop->as_u64[1]; + add_adj.explicit_fib_index = explicit_fib_index; + ip_add_adjacency (lm, &add_adj, 1, &nh_adj_index); } } else @@ -641,10 +643,11 @@ void ip6_delete_matching_routes (ip6_main_t * im, ip6_maybe_remap_adjacencies (im, table_index_or_table_id, flags); } -static uword -ip6_lookup (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) +always_inline uword +ip6_lookup_inline (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * frame, + int is_indirect) { ip6_main_t * im = &ip6_main; ip_lookup_main_t * lm = &im->lookup_main; @@ -669,6 +672,7 @@ ip6_lookup (vlib_main_t * vm, ip_lookup_next_t next0, next1; ip6_header_t * ip0, * ip1; ip_adjacency_t * adj0, * adj1; + ip6_address_t * dst_addr0, * dst_addr1; u32 fib_index0, fib_index1; u32 flow_hash_config0, flow_hash_config1; @@ -694,6 +698,20 @@ ip6_lookup (vlib_main_t * vm, ip0 = vlib_buffer_get_current (p0); ip1 = vlib_buffer_get_current (p1); + if (is_indirect) + { + ip_adjacency_t * iadj0, * iadj1; + iadj0 = ip_get_adjacency (lm, vnet_buffer(p0)->ip.adj_index[VLIB_TX]); + iadj1 = ip_get_adjacency (lm, vnet_buffer(p1)->ip.adj_index[VLIB_TX]); + dst_addr0 = &iadj0->indirect.next_hop.ip6; + dst_addr1 = &iadj1->indirect.next_hop.ip6; + } + else + { + dst_addr0 = &ip0->dst_address; + dst_addr1 = &ip1->dst_address; + } + fib_index0 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p0)->sw_if_index[VLIB_RX]); fib_index1 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p1)->sw_if_index[VLIB_RX]); @@ -702,10 +720,8 @@ ip6_lookup (vlib_main_t * vm, fib_index1 = (vnet_buffer(p1)->sw_if_index[VLIB_TX] == (u32)~0) ? fib_index1 : vnet_buffer(p1)->sw_if_index[VLIB_TX]; - adj_index0 = ip6_fib_lookup_with_table (im, fib_index0, - &ip0->dst_address); - adj_index1 = ip6_fib_lookup_with_table (im, fib_index1, - &ip1->dst_address); + adj_index0 = ip6_fib_lookup_with_table (im, fib_index0, dst_addr0); + adj_index1 = ip6_fib_lookup_with_table (im, fib_index1, dst_addr1); adj0 = ip_get_adjacency (lm, adj_index0); adj1 = ip_get_adjacency (lm, adj_index1); @@ -713,13 +729,13 @@ ip6_lookup (vlib_main_t * vm, if (PREDICT_FALSE (adj0->explicit_fib_index != ~0)) { adj_index0 = ip6_fib_lookup_with_table - (im, adj0->explicit_fib_index, &ip0->dst_address); + (im, adj0->explicit_fib_index, dst_addr0); adj0 = ip_get_adjacency (lm, adj_index0); } if (PREDICT_FALSE (adj1->explicit_fib_index != ~0)) { adj_index1 = ip6_fib_lookup_with_table - (im, adj1->explicit_fib_index, &ip1->dst_address); + (im, adj1->explicit_fib_index, dst_addr1); adj1 = ip_get_adjacency (lm, adj_index1); } @@ -818,6 +834,7 @@ ip6_lookup (vlib_main_t * vm, u32 pi0, adj_index0; ip_lookup_next_t next0; ip_adjacency_t * adj0; + ip6_address_t * dst_addr0; u32 fib_index0, flow_hash_config0; pi0 = from[0]; @@ -827,6 +844,17 @@ ip6_lookup (vlib_main_t * vm, ip0 = vlib_buffer_get_current (p0); + if (is_indirect) + { + ip_adjacency_t * iadj0; + iadj0 = ip_get_adjacency (lm, vnet_buffer(p0)->ip.adj_index[VLIB_TX]); + dst_addr0 = &iadj0->indirect.next_hop.ip6; + } + else + { + dst_addr0 = &ip0->dst_address; + } + fib_index0 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p0)->sw_if_index[VLIB_RX]); fib_index0 = (vnet_buffer(p0)->sw_if_index[VLIB_TX] == (u32)~0) ? fib_index0 : vnet_buffer(p0)->sw_if_index[VLIB_TX]; @@ -834,15 +862,14 @@ ip6_lookup (vlib_main_t * vm, flow_hash_config0 = vec_elt_at_index (im->fibs,fib_index0)->flow_hash_config; - adj_index0 = ip6_fib_lookup_with_table (im, fib_index0, - &ip0->dst_address); + adj_index0 = ip6_fib_lookup_with_table (im, fib_index0, dst_addr0); adj0 = ip_get_adjacency (lm, adj_index0); if (PREDICT_FALSE (adj0->explicit_fib_index != ~0)) { - adj_index0 = ip6_fib_lookup_with_table - (im, adj0->explicit_fib_index, &ip0->dst_address); + adj_index0 = ip6_fib_lookup_with_table + (im, adj0->explicit_fib_index, dst_addr0); adj0 = ip_get_adjacency (lm, adj_index0); } @@ -1206,6 +1233,14 @@ ip6_sw_interface_add_del (vnet_main_t * vnm, VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip6_sw_interface_add_del); +static uword +ip6_lookup (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * frame) +{ + return ip6_lookup_inline (vm, node, frame, /* is_indirect */ 0); +} + VLIB_REGISTER_NODE (ip6_lookup_node) = { .function = ip6_lookup, .name = "ip6-lookup", @@ -1215,6 +1250,24 @@ VLIB_REGISTER_NODE (ip6_lookup_node) = { .next_nodes = IP6_LOOKUP_NEXT_NODES, }; +static uword +ip6_indirect (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * frame) +{ + return ip6_lookup_inline (vm, node, frame, /* is_indirect */ 1); +} + + +VLIB_REGISTER_NODE (ip6_indirect_node) = { + .function = ip6_indirect, + .name = "ip6-indirect", + .vector_size = sizeof (u32), + + .n_next_nodes = IP_LOOKUP_N_NEXT, + .next_nodes = IP6_LOOKUP_NEXT_NODES, +}; + typedef struct { /* Adjacency taken. */ u32 adj_index; diff --git a/vnet/vnet/ip/lookup.c b/vnet/vnet/ip/lookup.c index df14a5fefe3..2f638f7799b 100644 --- a/vnet/vnet/ip/lookup.c +++ b/vnet/vnet/ip/lookup.c @@ -948,6 +948,7 @@ u8 * format_ip_lookup_next (u8 * s, va_list * args) case IP_LOOKUP_NEXT_MAP: t = "map"; break; case IP_LOOKUP_NEXT_MAP_T: t = "map-t"; break; case IP_LOOKUP_NEXT_SIXRD: t = "sixrd"; break; + case IP_LOOKUP_NEXT_INDIRECT: t="indirect"; break; case IP_LOOKUP_NEXT_REWRITE: break; } @@ -1009,6 +1010,8 @@ u8 * format_ip_adjacency (u8 * s, va_list * args) case IP_LOOKUP_NEXT_CLASSIFY: s = format (s, " table %d", adj->classify.table_index); + case IP_LOOKUP_NEXT_INDIRECT: + s = format (s, " via %U", format_ip46_address, &adj->indirect.next_hop); default: break; } diff --git a/vnet/vnet/ip/lookup.h b/vnet/vnet/ip/lookup.h index 62de2105133..e9a49124105 100644 --- a/vnet/vnet/ip/lookup.h +++ b/vnet/vnet/ip/lookup.h @@ -79,6 +79,9 @@ typedef enum { /* This packets needs to go to 6RD (RFC5969) */ IP_LOOKUP_NEXT_SIXRD, + /* This packets needs to go to indirect next hop */ + IP_LOOKUP_NEXT_INDIRECT, + /* Hop-by-hop header handling */ IP_LOOKUP_NEXT_HOP_BY_HOP, IP_LOOKUP_NEXT_ADD_HOP_BY_HOP, @@ -101,6 +104,7 @@ typedef enum { [IP_LOOKUP_NEXT_HOP_BY_HOP] = "ip4-hop-by-hop", \ [IP_LOOKUP_NEXT_ADD_HOP_BY_HOP] = "ip4-add-hop-by-hop", \ [IP_LOOKUP_NEXT_POP_HOP_BY_HOP] = "ip4-pop-hop-by-hop", \ + [IP_LOOKUP_NEXT_INDIRECT] = "ip4-indirect", \ } #define IP6_LOOKUP_NEXT_NODES { \ @@ -117,6 +121,7 @@ typedef enum { [IP_LOOKUP_NEXT_HOP_BY_HOP] = "ip6-hop-by-hop", \ [IP_LOOKUP_NEXT_ADD_HOP_BY_HOP] = "ip6-add-hop-by-hop", \ [IP_LOOKUP_NEXT_POP_HOP_BY_HOP] = "ip6-pop-hop-by-hop", \ + [IP_LOOKUP_NEXT_INDIRECT] = "ip6-indirect", \ } /* Flow hash configuration */ @@ -170,12 +175,15 @@ typedef struct { /* IP_LOOKUP_NEXT_ARP only */ struct { ip46_address_t next_hop; - u32 next_adj_index_with_same_next_hop; } arp; /* IP_LOOKUP_NEXT_CLASSIFY only */ struct { u16 table_index; } classify; + /* IP_LOOKUP_NEXT_INDIRECT only */ + struct { + ip46_address_t next_hop; + } indirect; }; STRUCT_MARK(signature_end); |