blob: 3d535936b7e102234314e2f06155b69736caba76 (
plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
|
/* Copyright (c) 2014, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/**
* @file
*
* Optional ODP packet helper functions
*/
#ifndef ODPH_PACKET_HELPER_H_
#define ODPH_PACKET_HELPER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <odp.h>
/**
* Helper: Tests if packet is valid
*
* Allows for more thorough checking than "if (pkt == ODP_PACKET_INVALID)"
*
* @param pkt Packet handle
*
* @return 1 if valid, otherwise 0
*/
static inline int odph_packet_is_valid(odp_packet_t pkt)
{
odp_buffer_t buf = odp_packet_to_buffer(pkt);
return odp_buffer_is_valid(buf);
}
/**
* Helper: Allocate and initialize a packet buffer from a packet pool
*
* @param pool_id Pool handle
*
* @note The pool must have been created with 'buf_type=ODP_BUFFER_TYPE_PACKET'
*
* @return Packet handle or ODP_PACKET_INVALID
*/
static inline odp_packet_t odph_packet_alloc(odp_buffer_pool_t pool_id)
{
odp_packet_t pkt;
odp_buffer_t buf;
buf = odp_buffer_alloc(pool_id);
if (odp_unlikely(!odp_buffer_is_valid(buf)))
return ODP_PACKET_INVALID;
pkt = odp_packet_from_buffer(buf);
odp_packet_init(pkt);
return pkt;
}
/**
* Helper: Free a packet buffer back into the packet pool
*
* @param pkt Packet handle
*/
static inline void odph_packet_free(odp_packet_t pkt)
{
odp_buffer_t buf = odp_packet_to_buffer(pkt);
odp_buffer_free(buf);
}
/**
* Helper: Packet buffer maximum data size
*
* @note odp_packet_buf_size(pkt) != odp_packet_get_len(pkt), the former returns
* the max length of the buffer, the latter the size of a received packet.
*
* @param pkt Packet handle
*
* @return Packet buffer maximum data size
*/
static inline size_t odph_packet_buf_size(odp_packet_t pkt)
{
odp_buffer_t buf = odp_packet_to_buffer(pkt);
return odp_buffer_size(buf);
}
#ifdef __cplusplus
}
#endif
#endif
|