From 7cf94623e905a7092a1deff1b730c79a8307c7af Mon Sep 17 00:00:00 2001 From: Hongjun Ni Date: Fri, 2 Jun 2017 18:34:52 +0800 Subject: Fix adj lookup failure for NSH over Eth Change-Id: If5b090b7d03b3ad1567c9659cb235c6a54d438ae Signed-off-by: Hongjun Ni --- nsh-plugin/nsh/nsh.c | 31 ++++++++++++++++++++++++++++++- nsh-plugin/nsh/nsh.h | 1 + 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/nsh-plugin/nsh/nsh.c b/nsh-plugin/nsh/nsh.c index 5d4ad41..8e4ce58 100644 --- a/nsh-plugin/nsh/nsh.c +++ b/nsh-plugin/nsh/nsh.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -515,6 +516,7 @@ int nsh_add_del_map (nsh_add_del_map_args_t *a, u32 * map_indexp) map->sw_if_index = a->map.sw_if_index; map->rx_sw_if_index = a->map.rx_sw_if_index; map->next_node = a->map.next_node; + map->adj_index = a->map.adj_index; key_copy = clib_mem_alloc (sizeof (*key_copy)); @@ -661,6 +663,24 @@ static uword unformat_nsh_action (unformat_input_t * input, va_list * args) return 1; } +static adj_index_t +nsh_get_adj_by_sw_if_index(u32 sw_if_index) +{ + adj_index_t ai = ~0; + + /* *INDENT-OFF* */ + pool_foreach_index(ai, adj_pool, + ({ + if (sw_if_index == adj_get_sw_if_index(ai)) + { + return ai; + } + })); + /* *INDENT-ON* */ + + return ~0; +} + static clib_error_t * nsh_add_del_map_command_fn (vlib_main_t * vm, unformat_input_t * input, @@ -672,6 +692,7 @@ nsh_add_del_map_command_fn (vlib_main_t * vm, int nsp_set = 0, nsi_set = 0, mapped_nsp_set = 0, mapped_nsi_set = 0; int nsh_action_set = 0; u32 next_node = ~0; + u32 adj_index = ~0; u32 sw_if_index = ~0; // temporary requirement to get this moved over to NSHSFC u32 rx_sw_if_index = ~0; // temporary requirement to get this moved over to NSHSFC nsh_add_del_map_args_t _a, * a = &_a; @@ -709,7 +730,10 @@ nsh_add_del_map_command_fn (vlib_main_t * vm, else if (unformat (line_input, "encap-vxlan6-intf %d", &sw_if_index)) next_node = NSH_NODE_NEXT_ENCAP_VXLAN6; else if (unformat (line_input, "encap-eth-intf %d", &sw_if_index)) - next_node = NSH_NODE_NEXT_ENCAP_ETHERNET; + { + next_node = NSH_NODE_NEXT_ENCAP_ETHERNET; + adj_index = nsh_get_adj_by_sw_if_index(sw_if_index); + } else if (unformat (line_input, "encap-none %d %d", &sw_if_index, &rx_sw_if_index)) next_node = NSH_NODE_NEXT_DECAP_ETH_INPUT; else @@ -741,6 +765,7 @@ nsh_add_del_map_command_fn (vlib_main_t * vm, a->map.sw_if_index = sw_if_index; a->map.rx_sw_if_index = rx_sw_if_index; a->map.next_node = next_node; + a->map.adj_index = adj_index; rv = nsh_add_del_map(a, &map_index); @@ -1779,6 +1804,7 @@ nsh_input_map (vlib_main_t * vm, /* set up things for next node to transmit ie which node to handle it and where */ next0 = map0->next_node; vnet_buffer(b0)->sw_if_index[VLIB_TX] = map0->sw_if_index; + vnet_buffer(b0)->ip.adj_index[VLIB_TX] = map0->adj_index; if(PREDICT_FALSE(map0->nsh_action == NSH_ACTION_POP)) { @@ -1882,6 +1908,7 @@ nsh_input_map (vlib_main_t * vm, /* set up things for next node to transmit ie which node to handle it and where */ next1 = map1->next_node; vnet_buffer(b1)->sw_if_index[VLIB_TX] = map1->sw_if_index; + vnet_buffer(b1)->ip.adj_index[VLIB_TX] = map1->adj_index; if(PREDICT_FALSE(map1->nsh_action == NSH_ACTION_POP)) { @@ -2068,6 +2095,8 @@ nsh_input_map (vlib_main_t * vm, /* set up things for next node to transmit ie which node to handle it and where */ next0 = map0->next_node; vnet_buffer(b0)->sw_if_index[VLIB_TX] = map0->sw_if_index; + vnet_buffer(b0)->ip.adj_index[VLIB_TX] = map0->adj_index; + vnet_buffer(b0)->sw_if_index[VLIB_RX] = map0->nsh_sw_if; if(PREDICT_FALSE(map0->nsh_action == NSH_ACTION_POP)) { diff --git a/nsh-plugin/nsh/nsh.h b/nsh-plugin/nsh/nsh.h index e67e64a..ea4e192 100644 --- a/nsh-plugin/nsh/nsh.h +++ b/nsh-plugin/nsh/nsh.h @@ -76,6 +76,7 @@ typedef struct { u32 sw_if_index; u32 rx_sw_if_index; u32 next_node; + u32 adj_index; } nsh_map_t; typedef struct { -- cgit 1.2.3-korg