From 05ab8cbdd410f32766d184ad87e5f66a2d2426fe Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Thu, 3 Nov 2016 20:16:04 +0100 Subject: vlib: add vlib_buffer_copy function It works with and without DPDK so it allws us to enable lawful-intercept code in vpp_lite images. Change-Id: I08f234cbc652c3ff47a6123a43b9e7f8bdcd5534 Signed-off-by: Damjan Marion --- vnet/Makefile.am | 1 - vnet/vnet/dpdk_replication.h | 116 -------------------------- vnet/vnet/lawful-intercept/lawful_intercept.c | 3 - vnet/vnet/lawful-intercept/lawful_intercept.h | 1 - vnet/vnet/lawful-intercept/node.c | 31 +------ vnet/vnet/sr/sr_replicate.c | 1 - 6 files changed, 1 insertion(+), 152 deletions(-) delete mode 100644 vnet/vnet/dpdk_replication.h (limited to 'vnet') diff --git a/vnet/Makefile.am b/vnet/Makefile.am index f53a61bf..185c08a9 100644 --- a/vnet/Makefile.am +++ b/vnet/Makefile.am @@ -628,7 +628,6 @@ libvnet_la_SOURCES += \ vnet/lawful-intercept/node.c nobase_include_HEADERS += \ - vnet/dpdk_replication.h \ vnet/lawful-intercept/lawful_intercept.h ######################################## diff --git a/vnet/vnet/dpdk_replication.h b/vnet/vnet/dpdk_replication.h deleted file mode 100644 index 24c13361..00000000 --- a/vnet/vnet/dpdk_replication.h +++ /dev/null @@ -1,116 +0,0 @@ -#ifndef __included_dpdk_replication_h__ -#define __included_dpdk_replication_h__ -#include - -/* - * vlib_dpdk_clone_buffer - clone a buffer - * for port mirroring, lawful intercept, etc. - * rte_pktmbuf_clone (...) requires that the forwarding path - * not touch any of the cloned data. The hope is that we'll - * figure out how to relax that restriction. - * - * For the moment, copy packet data. - */ - -static inline vlib_buffer_t * -vlib_dpdk_clone_buffer (vlib_main_t * vm, vlib_buffer_t * b) -{ - u32 new_buffers_needed = 1; - unsigned socket_id = rte_socket_id (); - struct rte_mempool *rmp = vm->buffer_main->pktmbuf_pools[socket_id]; - struct rte_mbuf *rte_mbufs[5]; - vlib_buffer_free_list_t *fl; - vlib_buffer_t *rv; - u8 *copy_src, *copy_dst; - vlib_buffer_t *src_buf, *dst_buf; - - fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX); - - if (PREDICT_FALSE (b->flags & VLIB_BUFFER_NEXT_PRESENT)) - { - vlib_buffer_t *tmp = b; - int i; - - while (tmp->flags & VLIB_BUFFER_NEXT_PRESENT) - { - new_buffers_needed++; - tmp = vlib_get_buffer (vm, tmp->next_buffer); - } - - /* Should never happen... */ - if (PREDICT_FALSE (new_buffers_needed > ARRAY_LEN (rte_mbufs))) - { - clib_warning ("need %d buffers", new_buffers_needed); - return 0; - } - - if (rte_mempool_get_bulk (rmp, (void **) rte_mbufs, - new_buffers_needed) < 0) - return 0; - - src_buf = b; - rv = dst_buf = vlib_buffer_from_rte_mbuf (rte_mbufs[0]); - vlib_buffer_init_for_free_list (dst_buf, fl); - copy_src = b->data + src_buf->current_data; - copy_dst = dst_buf->data + src_buf->current_data; - - for (i = 0; i < new_buffers_needed; i++) - { - clib_memcpy (copy_src, copy_dst, src_buf->current_length); - dst_buf->current_data = src_buf->current_data; - dst_buf->current_length = src_buf->current_length; - dst_buf->flags = src_buf->flags; - - if (i == 0) - { - dst_buf->total_length_not_including_first_buffer = - src_buf->total_length_not_including_first_buffer; - vnet_buffer (dst_buf)->sw_if_index[VLIB_RX] = - vnet_buffer (src_buf)->sw_if_index[VLIB_RX]; - vnet_buffer (dst_buf)->sw_if_index[VLIB_TX] = - vnet_buffer (src_buf)->sw_if_index[VLIB_TX]; - vnet_buffer (dst_buf)->l2 = vnet_buffer (b)->l2; - } - - if (i < new_buffers_needed - 1) - { - src_buf = vlib_get_buffer (vm, src_buf->next_buffer); - dst_buf = vlib_buffer_from_rte_mbuf (rte_mbufs[i + 1]); - vlib_buffer_init_for_free_list (dst_buf, fl); - copy_src = src_buf->data; - copy_dst = dst_buf->data; - } - } - return rv; - } - - if (rte_mempool_get_bulk (rmp, (void **) rte_mbufs, 1) < 0) - return 0; - - rte_pktmbuf_refcnt_update (rte_mbufs[0], 1); - rv = vlib_buffer_from_rte_mbuf (rte_mbufs[0]); - vlib_buffer_init_for_free_list (rv, fl); - - clib_memcpy (rv->data + b->current_data, b->data + b->current_data, - b->current_length); - rv->current_data = b->current_data; - rv->current_length = b->current_length; - vnet_buffer (rv)->sw_if_index[VLIB_RX] = - vnet_buffer (b)->sw_if_index[VLIB_RX]; - vnet_buffer (rv)->sw_if_index[VLIB_TX] = - vnet_buffer (b)->sw_if_index[VLIB_TX]; - vnet_buffer (rv)->l2 = vnet_buffer (b)->l2; - - return (rv); -} - - -#endif /* __included_dpdk_replication_h__ */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/vnet/vnet/lawful-intercept/lawful_intercept.c b/vnet/vnet/lawful-intercept/lawful_intercept.c index 6b2f41f4..ef07a339 100644 --- a/vnet/vnet/lawful-intercept/lawful_intercept.c +++ b/vnet/vnet/lawful-intercept/lawful_intercept.c @@ -13,7 +13,6 @@ * limitations under the License. */ -#if DPDK==1 #include static clib_error_t * @@ -110,6 +109,4 @@ li_init (vlib_main_t * vm) } VLIB_INIT_FUNCTION(li_init); -#else -#endif /* DPDK */ diff --git a/vnet/vnet/lawful-intercept/lawful_intercept.h b/vnet/vnet/lawful-intercept/lawful_intercept.h index 6fe6caf7..89e699f5 100644 --- a/vnet/vnet/lawful-intercept/lawful_intercept.h +++ b/vnet/vnet/lawful-intercept/lawful_intercept.h @@ -18,7 +18,6 @@ #include #include -#include typedef struct { /* LI collector info */ diff --git a/vnet/vnet/lawful-intercept/node.c b/vnet/vnet/lawful-intercept/node.c index 8701c323..ea0cd8ef 100644 --- a/vnet/vnet/lawful-intercept/node.c +++ b/vnet/vnet/lawful-intercept/node.c @@ -17,7 +17,6 @@ #include #include -#if DPDK==1 #include #include @@ -199,7 +198,7 @@ li_hit_node_fn (vlib_main_t * vm, if (PREDICT_TRUE(to_int_next != 0)) { /* Make an intercept copy */ - c0 = vlib_dpdk_clone_buffer (vm, b0); + c0 = vlib_buffer_copy (vm, b0); vlib_buffer_advance(c0, -sizeof(*iu0)); @@ -274,31 +273,3 @@ VLIB_REGISTER_NODE (li_hit_node) = { VLIB_NODE_FUNCTION_MULTIARCH (li_hit_node, li_hit_node_fn) -#else -#include - -static uword -li_hit_node_fn (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) -{ - clib_warning ("LI not implemented (no DPDK)"); - return 0; -} - -VLIB_REGISTER_NODE (li_hit_node) = { - .vector_size = sizeof (u32), - .function = li_hit_node_fn, - .name = "li-hit", -}; - -static clib_error_t * -li_init (vlib_main_t * vm) -{ - return 0; -} - -VLIB_INIT_FUNCTION(li_init); - - -#endif /* DPDK */ diff --git a/vnet/vnet/sr/sr_replicate.c b/vnet/vnet/sr/sr_replicate.c index 9cc7c5a0..9aa57873 100644 --- a/vnet/vnet/sr/sr_replicate.c +++ b/vnet/vnet/sr/sr_replicate.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include -- cgit 1.2.3-korg