This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
tango-tfe/common/include/tfe_pkt_util.h

59 lines
1.6 KiB
C
Raw Normal View History

#ifndef _TFE_PKT_UTIL_H
#define _TFE_PKT_UTIL_H
#ifdef __cpluscplus
extern "C"
{
#endif
enum addr_type_t {
ADDR_TYPE_IPV4 = 1,
ADDR_TYPE_IPV6 = 2,
};
struct pkt_info {
enum addr_type_t addr_type;
union {
struct iphdr *v4;
struct ip6_hdr *v6;
} iphdr;
uint16_t iphdr_len;
uint16_t ip_totlen;
struct tcphdr *tcphdr;
uint16_t tcphdr_len;
char *data;
uint16_t data_len;
int parse_failed;
};
// always success
void tfe_pkt_parse_ipv4_header(const void *a_packet, struct pkt_info *pktinfo);
// check pktinfo->parse_failed for status
void tfe_pkt_parse_ipv6_header(const void *a_packet, struct pkt_info *pktinfo);
uint16_t tfe_pkt_checksum_ip(const void *buf, size_t hdr_len);
uint16_t tfe_pkt_checksum_tcp_v4(const void *buf, size_t len, in_addr_t src_addr, in_addr_t dest_addr);
uint16_t tfe_pkt_checksum_tcp_v6(const void *buf, size_t len, struct in6_addr src_addr, struct in6_addr dest_addr);
/*
* IP Payload ${data} tcp ${option}
*
*
* 1. tcp options ${optlen}
* 2.${out_opt_buff} ${out_opt_buff_size}
*
*
* 1. tcp ${option} 1 tcp ${option} ${out_opt_buff} ${out_optlen}
* 2. tcp ${option} 0
*/
int tfe_pkt_find_tcp_option(uint8_t option, char *data, unsigned int opts_total_len, uint8_t *out_opt_len, char *out_opt_buff, unsigned int out_opt_buff_size);
#ifdef __cpluscplus
}
#endif
#endif