29 #define ODPH_IPV4HDR_LEN 20
30 #define ODPH_IPV4HDR_IHL_MIN 5
31 #define ODPH_IPV4ADDR_LEN 4
40 #define ODPH_IP_TOS_MAX_DSCP 63
41 #define ODPH_IP_TOS_DSCP_MASK 0xFC
42 #define ODPH_IP_TOS_DSCP_SHIFT 2
43 #define ODPH_IP_TOS_MAX_ECN 3
44 #define ODPH_IP_TOS_ECN_MASK 0x03
45 #define ODPH_IP_TOS_ECN_SHIFT 0
50 #define ODPH_IP_ECN_NOT_ECT 0
51 #define ODPH_IP_ECN_ECT1 1
52 #define ODPH_IP_ECN_ECT0 2
53 #define ODPH_IP_ECN_CE 3
56 #define ODPH_IPV4HDR_VER(ver_ihl) (((ver_ihl) & 0xf0) >> 4)
59 #define ODPH_IPV4HDR_IHL(ver_ihl) ((ver_ihl) & 0x0f)
62 #define ODPH_IPV4HDR_DSCP(tos) (((tos) & 0xfc) >> 2)
65 #define ODPH_IPV4HDR_FLAGS_DONT_FRAG(frag_offset) ((frag_offset) & 0x4000)
68 #define ODPH_IPV4HDR_FLAGS_MORE_FRAGS(frag_offset) ((frag_offset) & 0x2000)
71 #define ODPH_IPV4HDR_FRAG_OFFSET(frag_offset) ((frag_offset) & 0x1fff)
74 #define ODPH_IPV4HDR_IS_FRAGMENT(frag_offset) ((frag_offset) & 0x3fff)
77 #define ODPH_IPV4HDR_CSUM_OFFSET 10
95 "ODPH_IPV4HDR_T__SIZE_ERROR");
112 odp_u16sum_t *chksum)
115 const int max_ip_header_len = 15 * 4;
116 uint16_t buf[max_ip_header_len];
119 if (odp_unlikely(nleft <
sizeof(*ip)))
122 memcpy(buf, ip,
sizeof(*ip));
123 res = odp_packet_copy_to_mem(pkt, offset + (uint32_t)
sizeof(*ip),
124 nleft - (uint32_t)
sizeof(*ip),
125 buf +
sizeof(*ip) / 2);
126 if (odp_unlikely(res < 0))
129 *chksum = (odp_u16sum_t)~odp_chksum_ones_comp16(buf, nleft);
146 odp_u16sum_t chksum, cur_chksum;
148 offset = odp_packet_l3_offset(pkt);
149 if (offset == ODP_PACKET_OFFSET_INVALID)
152 res = odp_packet_copy_to_mem(pkt, offset,
sizeof(
odph_ipv4hdr_t), &ip);
153 if (odp_unlikely(res < 0))
159 if (odp_unlikely(res < 0))
162 return (cur_chksum == chksum) ? 1 : 0;
180 offset = odp_packet_l3_offset(pkt);
181 if (offset == ODP_PACKET_OFFSET_INVALID)
184 res = odp_packet_copy_to_mem(pkt, offset,
sizeof(ip), &ip);
185 if (odp_unlikely(res < 0))
189 if (odp_unlikely(res < 0))
192 return odp_packet_copy_from_mem(pkt,
201 #define ODPH_IPV6HDR_LEN 40
204 #define ODPH_IPV6ADDR_LEN 16
213 #define ODPH_IPV6HDR_VERSION_MASK 0xF0000000
214 #define ODPH_IPV6HDR_VERSION_SHIFT 28
215 #define ODPH_IPV6HDR_TC_MASK 0x0FF00000
216 #define ODPH_IPV6HDR_TC_SHIFT 20
217 #define ODPH_IPV6HDR_FLOW_LABEL_MASK 0x000FFFFF
218 #define ODPH_IPV6HDR_FLOW_LABEL_SHIFT 0
221 #define ODPH_IPV6HDR_DSCP(ver_tc_flow) \
222 (uint8_t)((((ver_tc_flow) & 0x0fc00000) >> 22) & 0xff)
238 "ODPH_IPV6HDR_T__SIZE_ERROR");
255 #define ODPH_IPPROTO_HOPOPTS 0x00
256 #define ODPH_IPPROTO_ICMPV4 0x01
257 #define ODPH_IPPROTO_IGMP 0x02
258 #define ODPH_IPPROTO_TCP 0x06
259 #define ODPH_IPPROTO_UDP 0x11
260 #define ODPH_IPPROTO_ROUTE 0x2B
261 #define ODPH_IPPROTO_FRAG 0x2C
262 #define ODPH_IPPROTO_AH 0x33
263 #define ODPH_IPPROTO_ESP 0x32
264 #define ODPH_IPPROTO_ICMPV6 0x3A
265 #define ODPH_IPPROTO_SCTP 0x84
267 #define ODPH_IPPROTO_INVALID 0xFF
static int odph_ipv4_csum(odp_packet_t pkt, uint32_t offset, odph_ipv4hdr_t *ip, odp_u16sum_t *chksum)
Calculate IPv4 header checksum.
#define ODPH_IPV4HDR_IHL(ver_ihl)
static int odph_ipv4_csum_valid(odp_packet_t pkt)
Check if IPv4 checksum is valid.
#define ODPH_IPV6HDR_LEN
IPv6 header length.
#define ODPH_IPV4HDR_LEN
Min length of IP header (no options)
struct ODP_PACKED odph_ipv6hdr_ext_t
IPv6 Header extensions.
#define ODPH_IPV4HDR_CSUM_OFFSET
static int odph_ipv4_csum_update(odp_packet_t pkt)
Calculate and fill in IPv4 checksum.
struct ODP_PACKED odph_ipv6hdr_t
IPv6 header.
struct ODP_PACKED odph_ipv4hdr_t
IPv4 header.
int odph_ipv4_addr_parse(uint32_t *ip_addr, const char *str)
Parse IPv4 address from a string.
odp_u32be_t src_addr
Source address.
uint8_t hop_limit
Hop limit.
odp_u32be_t dst_addr
Destination address.
odp_u16be_t tot_len
Total length.
uint8_t ver_ihl
Version / Header length.
odp_u16sum_t chksum
checksum of icmp header
uint8_t tos
Type of service.
odp_u16be_t frag_offset
Fragmentation offset.
odp_u32be_t ver_tc_flow
Version / Traffic class / Flow label.
uint8_t ext_len
Length of this extension in 8 byte units, not counting first 8 bytes, so 0 = 8 bytes 1 = 16 bytes,...
uint8_t next_hdr
Next header.
uint8_t filler[6]
Fill out first 8 byte segment.
odp_u16be_t payload_len
Payload length.