废除 tfe-kmod, tfe 直接与 kni 通信

* 新增 enable_kni_v3=1 配置项
	* develop_build_release 分支关闭 ASAN 检测
	* 修正根据 CMSG 恢复 TCP 链接时没有正确填写 TCP 时间戳启用选项的问题
This commit is contained in:
luwenpeng
2021-03-08 17:33:17 +08:00
parent 1c37ae746d
commit 1fe60d2428
21 changed files with 1387 additions and 25 deletions

View File

@@ -25,6 +25,11 @@ enum tfe_cmsg_tlv_type
TFE_CMSG_TCP_RESTORE_TS_CLIENT = 0x8,
TFE_CMSG_TCP_RESTORE_TS_SERVER = 0x9,
TFE_CMSG_TCP_RESTORE_PROTOCOL = 0xa,
TFE_CMSG_TCP_RESTORE_WINDOW_CLIENT = 0xb,
TFE_CMSG_TCP_RESTORE_WINDOW_SERVER = 0xc,
TFE_CMSG_TCP_RESTORE_INFO_PACKET_CUR_DIR = 0xd,
TFE_CMSG_TCP_RESTORE_TS_CLIENT_VAL = 0xe,
TFE_CMSG_TCP_RESTORE_TS_SERVER_VAL = 0xf,
TFE_CMSG_POLICY_ID = 0x10,
TFE_CMSG_STREAM_TRACE_ID = 0x11,

View File

@@ -0,0 +1,59 @@
#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

View File

@@ -0,0 +1,47 @@
#ifndef _TFE_TCP_RESTORE_H
#define _TFE_TCP_RESTORE_H
#ifdef __cpluscplus
extern "C"
{
#endif
enum tcp_restore_pkt_dir
{
PKT_DIR_NOT_SET = 0x0,
PKT_DIR_C2S = 0x1,
PKT_DIR_S2C = 0x2
};
struct tcp_restore_endpoint
{
struct sockaddr_storage addr;
uint32_t seq;
uint32_t ack;
uint32_t ts_val;
uint16_t mss;
uint16_t window;
uint8_t wscale;
bool wscale_perm;
bool timestamp_perm;
bool sack_perm;
};
struct tcp_restore_info
{
enum tcp_restore_pkt_dir cur_dir;
struct tcp_restore_endpoint client;
struct tcp_restore_endpoint server;
char cmsg[2048];
unsigned int cmsg_len;
};
void tfe_tcp_restore_info_dump(const struct tcp_restore_info *info);
int tfe_tcp_restore_fd_create(const struct tcp_restore_endpoint *endpoint, const struct tcp_restore_endpoint *peer);
#ifdef __cpluscplus
}
#endif
#endif

View File

@@ -8,6 +8,7 @@
#include <MESA/MESA_htable.h>
#include <time.h>
#include <dirent.h> //scan_dir
#include <stdbool.h>
#define TFE_STRING_MAX 2048
#define TFE_PATH_MAX 256
@@ -103,9 +104,6 @@ do { if(!(condition)) { TFE_LOG_ERROR(g_default_logger, fmt, ##__VA_ARGS__); abo
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
int addr_sock_to_layer(struct sockaddr * sock_addr, int sockaddrlen, struct layer_addr * layer_addr);
int addr_layer_to_sock(struct layer_addr * layer_addr, struct sockaddr * sock_addr);
char* tfe_strdup(const char* s);
char *tfe_thread_safe_ctime(const time_t *tp, char *buf, int len);
@@ -172,6 +170,4 @@ int tfe_scandir(const char *dir, struct dirent ***namelist,
char *tfe_read_file(const char *filename, size_t *filelen);
const char * tfe_version();
int __wrapper_MESA_htable_set_opt(MESA_htable_handle table, enum MESA_htable_opt opt_type, unsigned value);
int __wrapper_MESA_htable_set_opt(MESA_htable_handle table, enum MESA_htable_opt opt_type, void * val, size_t len);
int tfe_decode_base64url(u_char *dst, u_char *src);