-
Notifications
You must be signed in to change notification settings - Fork 1
/
e_dpdkcpt_malloc.c
85 lines (75 loc) · 2.01 KB
/
e_dpdkcpt_malloc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* SPDX-License-Identifier: Marvell-MIT
* Copyright (c) 2024 Marvell.
*/
#include <stdint.h>
#include <rte_mbuf.h>
#include "e_dpdkcpt.h"
#include "e_dpdkcpt_malloc.h"
void *dpdkcpt_malloc(size_t len, const char *file, int line)
{
struct rte_mbuf *mbuf_ptr = NULL;
void *data_ptr = NULL;
(void)file, (void)line;
mbuf_ptr = rte_pktmbuf_alloc(mbuf_pool);
if (mbuf_ptr == NULL) {
engine_log(ENG_LOG_ERR,
"Failed to create a mbuf\n File : %s Line : %d\n", file,
line);
return NULL;
}
data_ptr = rte_pktmbuf_append(mbuf_ptr, len + E_DPDK_DIGEST_LEN);
if (data_ptr == NULL)
return NULL;
*((uint64_t *)data_ptr - 1) = 0xDEADBEEF;
return data_ptr;
}
void *dpdkcpt_realloc(void *ptr, size_t len, const char *file, int line)
{
struct rte_mbuf *mbuf_ptr = NULL;
uint64_t *data_ptr = NULL;
(void)file, (void)line;
if (ptr == NULL)
return dpdkcpt_malloc(len, file, line);
if (len == 0) {
dpdkcpt_free(ptr, file, line);
return NULL;
}
data_ptr = (uint64_t *)ptr - 1;
if (*data_ptr == 0xDEADBEEF) {
mbuf_ptr =
(struct rte_mbuf *)((char *)ptr - RTE_PKTMBUF_HEADROOM -
sizeof(struct rte_mbuf));
if (mbuf_ptr == NULL) {
engine_log(ENG_LOG_ERR, "Failed to get mbuf pointer\n");
return NULL;
}
if (rte_pktmbuf_append(mbuf_ptr, len) == NULL)
return NULL;
/* get databuf pointer pointing to start of pkt. */
return rte_pktmbuf_mtod(mbuf_ptr, void *);
} else {
data_ptr = realloc(ptr, len);
return data_ptr;
}
}
void dpdkcpt_free(void *ptr, const char *file, int line)
{
struct rte_mbuf *mbuf_ptr = NULL;
uint64_t *data_ptr = NULL;
(void)file, (void)line;
if (ptr != NULL) {
data_ptr = (uint64_t *)ptr - 1;
if (*data_ptr == 0xDEADBEEF) {
mbuf_ptr = (struct rte_mbuf *)((char *)ptr -
RTE_PKTMBUF_HEADROOM -
sizeof(struct rte_mbuf));
/* With the changes for TCP Zero copy, this buffer
* could be part of an mbuf chain, but not the head.
* So changing to segment free.
*/
rte_pktmbuf_free_seg(mbuf_ptr);
} else {
free(ptr);
}
}
}