FD.io VPP  v16.06
Vector Packet Processing
dpdk_replication.h
Go to the documentation of this file.
1 #ifndef __included_dpdk_replication_h__
2 #define __included_dpdk_replication_h__
4 
5 /*
6  * vlib_dpdk_clone_buffer - clone a buffer
7  * for port mirroring, lawful intercept, etc.
8  * rte_pktmbuf_clone (...) requires that the forwarding path
9  * not touch any of the cloned data. The hope is that we'll
10  * figure out how to relax that restriction.
11  *
12  * For the moment, copy packet data.
13  */
14 
15 static inline vlib_buffer_t *
17 {
18  u32 new_buffers_needed = 1;
19  unsigned socket_id = rte_socket_id();
20  struct rte_mempool *rmp = vm->buffer_main->pktmbuf_pools[socket_id];
21  struct rte_mbuf *rte_mbufs[5];
23  vlib_buffer_t * rv;
24  u8 * copy_src, * copy_dst;
25  vlib_buffer_t *src_buf, *dst_buf;
26 
28 
30  {
31  vlib_buffer_t *tmp = b;
32  int i;
33 
34  while (tmp->flags & VLIB_BUFFER_NEXT_PRESENT)
35  {
36  new_buffers_needed ++;
37  tmp = vlib_get_buffer (vm, tmp->next_buffer);
38  }
39 
40  /* Should never happen... */
41  if (PREDICT_FALSE(new_buffers_needed > ARRAY_LEN(rte_mbufs)))
42  {
43  clib_warning ("need %d buffers", new_buffers_needed);
44  return 0;
45  }
46 
47  if (rte_mempool_get_bulk (rmp, (void **)rte_mbufs,
48  new_buffers_needed) < 0)
49  return 0;
50 
51  src_buf = b;
52  rv = dst_buf = vlib_buffer_from_rte_mbuf(rte_mbufs[0]);
53  vlib_buffer_init_for_free_list (dst_buf, fl);
54  copy_src = b->data + src_buf->current_data;
55  copy_dst = dst_buf->data + src_buf->current_data;
56 
57  for (i = 0; i < new_buffers_needed; i++)
58  {
59  clib_memcpy (copy_src, copy_dst, src_buf->current_length);
60  dst_buf->current_data = src_buf->current_data;
61  dst_buf->current_length = src_buf->current_length;
62  dst_buf->flags = src_buf->flags;
63 
64  if (i == 0)
65  {
68  vnet_buffer(dst_buf)->sw_if_index[VLIB_RX] =
69  vnet_buffer(src_buf)->sw_if_index[VLIB_RX];
70  vnet_buffer(dst_buf)->sw_if_index[VLIB_TX] =
71  vnet_buffer(src_buf)->sw_if_index[VLIB_TX];
72  vnet_buffer(dst_buf)->l2 = vnet_buffer(b)->l2;
73  }
74 
75  if (i < new_buffers_needed - 1)
76  {
77  src_buf = vlib_get_buffer (vm, src_buf->next_buffer);
78  dst_buf = vlib_buffer_from_rte_mbuf(rte_mbufs[i+1]);
79  vlib_buffer_init_for_free_list (dst_buf, fl);
80  copy_src = src_buf->data;
81  copy_dst = dst_buf->data;
82  }
83  }
84  return rv;
85  }
86 
87  if (rte_mempool_get_bulk (rmp, (void **)rte_mbufs, 1) < 0)
88  return 0;
89 
90  rv = vlib_buffer_from_rte_mbuf(rte_mbufs[0]);
92 
93  clib_memcpy(rv->data + b->current_data, b->data + b->current_data,
94  b->current_length);
95  rv->current_data = b->current_data;
97  vnet_buffer(rv)->sw_if_index[VLIB_RX] =
98  vnet_buffer(b)->sw_if_index[VLIB_RX];
99  vnet_buffer(rv)->sw_if_index[VLIB_TX] =
100  vnet_buffer(b)->sw_if_index[VLIB_TX];
101  vnet_buffer(rv)->l2 = vnet_buffer(b)->l2;
102 
103  return (rv);
104 }
105 
106 
107 #endif /* __included_dpdk_replication_h__ */
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:267
vlib_buffer_main_t * buffer_main
Definition: main.h:103
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:77
#define clib_warning(format, args...)
Definition: error.h:59
always_inline vlib_buffer_free_list_t * vlib_buffer_get_free_list(vlib_main_t *vm, u32 free_list_index)
Definition: buffer_funcs.h:332
#define VLIB_BUFFER_NEXT_PRESENT
Definition: buffer.h:93
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:81
#define PREDICT_FALSE(x)
Definition: clib.h:97
#define clib_memcpy(a, b, c)
Definition: string.h:63
#define ARRAY_LEN(x)
Definition: clib.h:59
#define VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX
Definition: buffer.h:296
unsigned int u32
Definition: types.h:88
#define vnet_buffer(b)
Definition: buffer.h:300
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:112
always_inline void vlib_buffer_init_for_free_list(vlib_buffer_t *_dst, vlib_buffer_free_list_t *fl)
Definition: buffer_funcs.h:591
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
Definition: buffer.h:106
Definition: defs.h:46
unsigned char u8
Definition: types.h:56
static vlib_buffer_t * vlib_dpdk_clone_buffer(vlib_main_t *vm, vlib_buffer_t *b)
u8 data[0]
Packet data.
Definition: buffer.h:150
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:84
always_inline vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:69
Definition: defs.h:45