diff options
Diffstat (limited to 'vnet/vnet/rewrite.c')
-rw-r--r-- | vnet/vnet/rewrite.c | 80 |
1 files changed, 60 insertions, 20 deletions
diff --git a/vnet/vnet/rewrite.c b/vnet/vnet/rewrite.c index 42d0688a5cc..53d548bc8ae 100644 --- a/vnet/vnet/rewrite.c +++ b/vnet/vnet/rewrite.c @@ -184,38 +184,51 @@ done: return error == 0; } +u32 +vnet_tx_node_index_for_sw_interface (vnet_main_t * vnm, u32 sw_if_index) +{ + vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sw_if_index); + return (hw->output_node_index); +} + +void +vnet_rewrite_init (vnet_main_t * vnm, + u32 sw_if_index, + u32 this_node, u32 next_node, vnet_rewrite_header_t * rw) +{ + rw->sw_if_index = sw_if_index; + rw->node_index = this_node; + rw->next_index = vlib_node_add_next (vnm->vlib_main, this_node, next_node); + rw->max_l3_packet_bytes = + vnet_sw_interface_get_mtu (vnm, sw_if_index, VLIB_TX); +} + void vnet_rewrite_for_sw_interface (vnet_main_t * vnm, - vnet_l3_packet_type_t packet_type, + vnet_link_t link_type, u32 sw_if_index, u32 node_index, void *dst_address, vnet_rewrite_header_t * rw, u32 max_rewrite_bytes) { + vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sw_if_index); vnet_hw_interface_class_t *hc = vnet_get_hw_interface_class (vnm, hw->hw_class_index); - static u8 *rw_tmp = 0; - uword n_rw_tmp; + u8 *rewrite = NULL; - rw->sw_if_index = sw_if_index; - rw->node_index = node_index; - rw->next_index = - vlib_node_add_next (vnm->vlib_main, node_index, hw->output_node_index); - rw->max_l3_packet_bytes = hw->max_l3_packet_bytes[VLIB_TX]; - - ASSERT (max_rewrite_bytes > 0); - vec_reset_length (rw_tmp); - vec_validate (rw_tmp, max_rewrite_bytes - 1); - - ASSERT (hc->set_rewrite); - n_rw_tmp = - hc->set_rewrite (vnm, sw_if_index, packet_type, dst_address, rw_tmp, - max_rewrite_bytes); - - ASSERT (n_rw_tmp < max_rewrite_bytes); - vnet_rewrite_set_data_internal (rw, max_rewrite_bytes, rw_tmp, n_rw_tmp); + vnet_rewrite_init (vnm, sw_if_index, node_index, + vnet_tx_node_index_for_sw_interface (vnm, sw_if_index), + rw); + + ASSERT (hc->build_rewrite); + rewrite = hc->build_rewrite (vnm, sw_if_index, link_type, dst_address); + + ASSERT (vec_len (rewrite) < max_rewrite_bytes); + vnet_rewrite_set_data_internal (rw, max_rewrite_bytes, rewrite, + vec_len (rewrite)); + vec_free (rewrite); } void @@ -280,6 +293,33 @@ unserialize_vnet_rewrite (serialize_main_t * m, va_list * va) rw->data_bytes); } +u8 * +vnet_build_rewrite_for_sw_interface (vnet_main_t * vnm, + u32 sw_if_index, + vnet_link_t link_type, + const void *dst_address) +{ + vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sw_if_index); + vnet_hw_interface_class_t *hc = + vnet_get_hw_interface_class (vnm, hw->hw_class_index); + + ASSERT (hc->build_rewrite); + return (hc->build_rewrite (vnm, sw_if_index, link_type, dst_address)); +} + + +void +vnet_update_adjacency_for_sw_interface (vnet_main_t * vnm, + u32 sw_if_index, u32 ai) +{ + vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sw_if_index); + vnet_hw_interface_class_t *hc = + vnet_get_hw_interface_class (vnm, hw->hw_class_index); + + ASSERT (hc->update_adjacency); + hc->update_adjacency (vnm, sw_if_index, ai); +} + /* * fd.io coding-style-patch-verification: ON * |