diff options
author | Damjan Marion <damarion@cisco.com> | 2016-11-03 20:16:04 +0100 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2016-11-03 22:16:15 +0000 |
commit | 05ab8cbdd410f32766d184ad87e5f66a2d2426fe (patch) | |
tree | e9cf1b65e9efed12e3e1597de55c85901c645604 | |
parent | bcc889cd0892a4dba9a06fc3c0ba49356c7220a4 (diff) |
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 <damarion@cisco.com>
-rw-r--r-- | vlib/vlib/buffer_funcs.h | 72 | ||||
-rw-r--r-- | vnet/Makefile.am | 1 | ||||
-rw-r--r-- | vnet/vnet/dpdk_replication.h | 116 | ||||
-rw-r--r-- | vnet/vnet/lawful-intercept/lawful_intercept.c | 3 | ||||
-rw-r--r-- | vnet/vnet/lawful-intercept/lawful_intercept.h | 1 | ||||
-rw-r--r-- | vnet/vnet/lawful-intercept/node.c | 31 | ||||
-rw-r--r-- | vnet/vnet/sr/sr_replicate.c | 1 |
7 files changed, 73 insertions, 152 deletions
diff --git a/vlib/vlib/buffer_funcs.h b/vlib/vlib/buffer_funcs.h index 497a6bb07a8..29635a3fd96 100644 --- a/vlib/vlib/buffer_funcs.h +++ b/vlib/vlib/buffer_funcs.h @@ -422,6 +422,78 @@ u32 vlib_buffer_add_data (vlib_main_t * vm, u32 free_list_index, u32 buffer_index, void *data, u32 n_data_bytes); +/* duplicate all buffers in chain */ +always_inline vlib_buffer_t * +vlib_buffer_copy (vlib_main_t * vm, vlib_buffer_t * b) +{ + vlib_buffer_t *s, *d, *fd; + uword n_alloc, n_buffers = 1; + u32 *new_buffers = 0; + int i; + + s = b; + while (s->flags & VLIB_BUFFER_NEXT_PRESENT) + { + n_buffers++; + s = vlib_get_buffer (vm, s->next_buffer); + } + + vec_validate (new_buffers, n_buffers - 1); + n_alloc = vlib_buffer_alloc (vm, new_buffers, n_buffers); + ASSERT (n_alloc == n_buffers); + + /* 1st segment */ + s = b; + fd = d = vlib_get_buffer (vm, new_buffers[0]); + clib_memcpy (vlib_buffer_get_current (d), + vlib_buffer_get_current (s), s->current_length); + d->current_data = s->current_data; + d->current_length = s->current_length; + d->flags = s->flags; + d->total_length_not_including_first_buffer = + s->total_length_not_including_first_buffer; + clib_memcpy (d->opaque, s->opaque, sizeof (s->opaque)); +#if DPDK > 0 + struct rte_mbuf *ms, *md; + ms = rte_mbuf_from_vlib_buffer (s); + md = rte_mbuf_from_vlib_buffer (d); + rte_pktmbuf_reset (md); + md->nb_segs = ms->nb_segs; + md->data_len = ms->data_len; + md->pkt_len = ms->pkt_len; + md->data_off = ms->data_off; +#endif + + /* next segments */ + for (i = 1; i < n_buffers; i++) + { + /* previous */ + d->next_buffer = new_buffers[i]; + /* current */ + s = vlib_get_buffer (vm, s->next_buffer); + d = vlib_get_buffer (vm, new_buffers[i]); + d->current_data = s->current_data; + d->current_length = s->current_length; + clib_memcpy (vlib_buffer_get_current (d), + vlib_buffer_get_current (s), s->current_length); + d->flags = s->flags; +#if DPDK > 0 + /* previous */ + md->next = rte_mbuf_from_vlib_buffer (d); + /* current */ + md = rte_mbuf_from_vlib_buffer (d); + ms = rte_mbuf_from_vlib_buffer (s); + rte_pktmbuf_reset (md); + md->data_len = ms->data_len; + md->pkt_len = ms->pkt_len; + md->data_off = ms->data_off; + md->next = 0; +#endif + } + + return fd; +} + /* * vlib_buffer_chain_* functions provide a way to create long buffers. * When DPDK is enabled, the 'hidden' DPDK header is taken care of transparently. diff --git a/vnet/Makefile.am b/vnet/Makefile.am index f53a61bfd44..185c08a9627 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 24c133619e9..00000000000 --- a/vnet/vnet/dpdk_replication.h +++ /dev/null @@ -1,116 +0,0 @@ -#ifndef __included_dpdk_replication_h__ -#define __included_dpdk_replication_h__ -#include <vnet/devices/dpdk/dpdk.h> - -/* - * 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 6b2f41f4795..ef07a339201 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 <vnet/lawful-intercept/lawful_intercept.h> 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 6fe6caf7f45..89e699f51a0 100644 --- a/vnet/vnet/lawful-intercept/lawful_intercept.h +++ b/vnet/vnet/lawful-intercept/lawful_intercept.h @@ -18,7 +18,6 @@ #include <vnet/vnet.h> #include <vnet/ip/ip.h> -#include <vnet/dpdk_replication.h> typedef struct { /* LI collector info */ diff --git a/vnet/vnet/lawful-intercept/node.c b/vnet/vnet/lawful-intercept/node.c index 8701c323358..ea0cd8efcdd 100644 --- a/vnet/vnet/lawful-intercept/node.c +++ b/vnet/vnet/lawful-intercept/node.c @@ -17,7 +17,6 @@ #include <vnet/vnet.h> #include <vppinfra/error.h> -#if DPDK==1 #include <vnet/lawful-intercept/lawful_intercept.h> #include <vppinfra/error.h> @@ -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 <vlib/vlib.h> - -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 9cc7c5a0dde..9aa57873c8c 100644 --- a/vnet/vnet/sr/sr_replicate.c +++ b/vnet/vnet/sr/sr_replicate.c @@ -30,7 +30,6 @@ #include <vnet/pg/pg.h> #include <vnet/sr/sr.h> #include <vnet/devices/dpdk/dpdk.h> -#include <vnet/dpdk_replication.h> #include <vnet/ip/ip.h> #include <vnet/fib/ip6_fib.h> |