2019-05-09 15:14:01 +08:00
|
|
|
#pragma once
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2019-05-17 17:04:50 +08:00
|
|
|
#include <string.h>
|
2019-05-09 15:14:01 +08:00
|
|
|
#include <assert.h>
|
2019-06-17 20:52:22 +08:00
|
|
|
#include <errno.h>
|
2019-05-09 15:14:01 +08:00
|
|
|
#include <unistd.h>
|
2019-06-17 20:52:22 +08:00
|
|
|
#include <pthread.h>
|
2019-05-09 15:14:01 +08:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include "MESA/MESA_handle_logger.h"
|
|
|
|
|
#include "MESA/MESA_htable.h"
|
|
|
|
|
#include "MESA/MESA_prof_load.h"
|
|
|
|
|
#include "field_stat2.h"
|
|
|
|
|
#include "Maat_rule.h"
|
|
|
|
|
#include "Maat_command.h"
|
2019-05-21 17:14:07 +08:00
|
|
|
#include "mrtunnat.h"
|
2019-05-09 15:14:01 +08:00
|
|
|
|
|
|
|
|
#define KNI_STRING_MAX 2048
|
|
|
|
|
#define KNI_PATH_MAX 256
|
|
|
|
|
#define KNI_SYMBOL_MAX 64
|
2019-05-17 17:04:50 +08:00
|
|
|
#define KNI_DOMAIN_MAX 256
|
2019-06-03 20:19:04 +08:00
|
|
|
|
2019-06-05 11:32:11 +08:00
|
|
|
#ifndef MAX
|
|
|
|
|
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-05-17 17:04:50 +08:00
|
|
|
#ifndef MIN
|
|
|
|
|
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-05-09 15:14:01 +08:00
|
|
|
#define likely(expr) __builtin_expect((expr), 1)
|
|
|
|
|
#define unlikely(expr) __builtin_expect((expr), 0)
|
|
|
|
|
|
|
|
|
|
#define ALLOC(type, number) ((type *)calloc(sizeof(type), number))
|
|
|
|
|
#define FREE(p) {free(*p);*p=NULL;}
|
|
|
|
|
|
|
|
|
|
#define KNI_LOG_ERROR(handler, fmt, ...) \
|
|
|
|
|
do { \
|
2019-06-18 18:29:06 +08:00
|
|
|
MESA_handle_runtime_log(handler, RLOG_LV_FATAL, "kni", fmt, ##__VA_ARGS__); } while(0)
|
2019-05-09 15:14:01 +08:00
|
|
|
|
|
|
|
|
#define KNI_LOG_INFO(handler, fmt, ...) \
|
|
|
|
|
do { \
|
2019-06-18 18:29:06 +08:00
|
|
|
MESA_handle_runtime_log(handler, RLOG_LV_INFO, "kni", fmt, ##__VA_ARGS__); } while(0)
|
2019-05-09 15:14:01 +08:00
|
|
|
|
|
|
|
|
#define KNI_LOG_DEBUG(handler, fmt, ...) \
|
|
|
|
|
do { \
|
2019-06-18 18:29:06 +08:00
|
|
|
MESA_handle_runtime_log(handler, RLOG_LV_DEBUG, "kni", fmt, ##__VA_ARGS__); } while(0)
|
2019-05-09 15:14:01 +08:00
|
|
|
|
2019-05-18 12:41:31 +08:00
|
|
|
|
2019-05-17 17:04:50 +08:00
|
|
|
//default tcp opt
|
|
|
|
|
#define KNI_DEFAULT_WINSCLE 0
|
|
|
|
|
#define KNI_DEFAULT_MSS 1460
|
|
|
|
|
#define KNI_DEFAULT_MTU 1500
|
|
|
|
|
#define KNI_MTU 3000
|
|
|
|
|
struct kni_tcpopt_info{
|
|
|
|
|
uint16_t mss;
|
2019-07-02 18:47:48 +06:00
|
|
|
uint8_t wscale_set;
|
2019-05-17 17:04:50 +08:00
|
|
|
uint8_t wscale;
|
|
|
|
|
uint8_t ts;
|
|
|
|
|
uint8_t sack;
|
|
|
|
|
};
|
|
|
|
|
|
2019-05-18 12:41:31 +08:00
|
|
|
//field_stat
|
2019-06-19 12:23:28 +08:00
|
|
|
#define KNI_FIELD_MAX 64
|
2019-05-18 12:41:31 +08:00
|
|
|
enum kni_field{
|
|
|
|
|
KNI_FIELD_INTCP_STM,
|
2019-06-19 16:15:11 +08:00
|
|
|
KNI_FIELD_BYP_STM,
|
|
|
|
|
KNI_FIELD_POLICY_BYP,
|
|
|
|
|
KNI_FIELD_PME_NEW_FAIL,
|
|
|
|
|
KNI_FIELD_NO_TFE,
|
|
|
|
|
KNI_FIELD_STATE_UNKNOWN,
|
|
|
|
|
KNI_FIELD_STM_ERR,
|
|
|
|
|
KNI_FIELD_NO_SYN,
|
|
|
|
|
KNI_FIELD_SINGLE_DIR,
|
|
|
|
|
KNI_FIELD_PROTO_UNKNOWN,
|
|
|
|
|
KNI_FIELD_NO_SA,
|
|
|
|
|
KNI_FIELD_ACTION_INVALID,
|
|
|
|
|
KNI_FIELD_NO_DATA,
|
|
|
|
|
KNI_FIELD_IPV4HDR_PARSE_FAIL,
|
|
|
|
|
KNI_FIELD_IPV6HDR_PARSE_FAIL,
|
|
|
|
|
KNI_FIELD_KA_ADD_FAIL,
|
|
|
|
|
KNI_FIELD_EXCEED_MTU,
|
|
|
|
|
KNI_FIELD_SENDTO_TFE_FAIL,
|
|
|
|
|
//others
|
|
|
|
|
KNI_FIELD_NULL_PKT,
|
|
|
|
|
KNI_FIELD_IPV4_STM,
|
|
|
|
|
KNI_FIELD_IPV6_STM,
|
2019-05-18 12:41:31 +08:00
|
|
|
KNI_FIELD_SSL_STM,
|
|
|
|
|
KNI_FIELD_HTTP_STM,
|
2019-06-03 20:19:04 +08:00
|
|
|
KNI_FIELD_SENDLOG_SUCC,
|
|
|
|
|
KNI_FIELD_SENDLOG_FAIL,
|
2019-06-19 16:15:11 +08:00
|
|
|
KNI_FIELD_PME_NEW_SUCC,
|
2019-06-08 20:28:21 +08:00
|
|
|
KNI_FIELD_PME_FREE,
|
|
|
|
|
KNI_FIELD_ID2PME_ADD_SUCC,
|
|
|
|
|
KNI_FIELD_ID2PME_ADD_FAIL,
|
|
|
|
|
KNI_FIELD_ID2PME_DEL_SUCC,
|
|
|
|
|
KNI_FIELD_ID2PME_DEL_FAIL,
|
2019-06-14 11:13:15 +08:00
|
|
|
KNI_FIELD_KEEPALIVE_REPLAY_ADD_SUCC,
|
2019-06-19 12:23:28 +08:00
|
|
|
KNI_FIELD_KEEPALIVE_REPLAY_DEL_SUCC,
|
|
|
|
|
KNI_FIELD_KEEPALIVE_REPLAY_DEL_FAIL,
|
2019-08-11 15:18:55 +08:00
|
|
|
KNI_FIELD_KNI_INTCP_BYTES,
|
|
|
|
|
KNI_FIELD_TFE_INTCP_BYTES,
|
|
|
|
|
KNI_FIELD_KNI_INTCP_STM,
|
|
|
|
|
KNI_FIELD_TFE_INTCP_STM,
|
2019-06-18 18:29:06 +08:00
|
|
|
//KNI_FIELD_TFE_STATUS_BASE must be last
|
2019-06-18 17:37:43 +08:00
|
|
|
KNI_FIELD_TFE_STATUS_BASE,
|
2019-05-18 12:41:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct kni_field_stat_handle{
|
|
|
|
|
screen_stat_handle_t handle;
|
|
|
|
|
int fields[KNI_FIELD_MAX];
|
|
|
|
|
};
|
|
|
|
|
|
2019-06-14 11:13:15 +08:00
|
|
|
struct pkt_info{
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum kni_ipv4hdr_parse_error{
|
|
|
|
|
KNI_IPV4HDR_PARSE_ERROR_NULL_PACKET = -1,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum kni_ipv6hdr_parse_error{
|
|
|
|
|
KNI_IPV6HDR_PARSE_ERROR_NULL_PACKET = -1,
|
|
|
|
|
KNI_IPV6HDR_PARSE_ERROR_NO_TCPHDR = -2,
|
|
|
|
|
KNI_IPV6HDR_PARSE_ERROR_INVALID_TYPE = -3,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int kni_stream_addr_trans(const struct layer_addr *addr, addr_type_t addr_type, char *output, int len);
|
2019-05-17 17:04:50 +08:00
|
|
|
uint16_t kni_ip_checksum(const void *buf, size_t hdr_len);
|
|
|
|
|
uint16_t kni_tcp_checksum(const void *_buf, size_t len, in_addr_t src_addr, in_addr_t dest_addr);
|
2019-06-14 11:13:15 +08:00
|
|
|
uint16_t kni_tcp_checksum_v6(const void *_buf, size_t len, struct in6_addr src_addr, struct in6_addr dest_addr);
|
2019-05-17 17:04:50 +08:00
|
|
|
uint16_t kni_udp_checksum(const void *_buf, size_t len, in_addr_t src_addr, in_addr_t dest_addr);
|
2019-06-14 11:13:15 +08:00
|
|
|
struct kni_tcpopt_info* kni_get_tcpopt(struct tcphdr* tcphdr, int tcphdr_len);
|
2019-06-03 20:19:04 +08:00
|
|
|
int kni_ipv4_addr_get_by_eth(const char *ifname, uint32_t *ip);
|
2019-06-14 11:13:15 +08:00
|
|
|
int kni_ipv4_header_parse(const void *a_packet, struct pkt_info *pktinfo);
|
|
|
|
|
int kni_ipv6_header_parse(const void *a_packet, struct pkt_info *pktinfo);
|
|
|
|
|
char* kni_ipv4_errmsg_get(enum kni_ipv4hdr_parse_error _errno);
|
|
|
|
|
char* kni_ipv6_errmsg_get(enum kni_ipv6hdr_parse_error _errno);
|
2019-06-03 20:19:04 +08:00
|
|
|
|
2019-05-17 17:04:50 +08:00
|
|
|
|
|
|
|
|
MESA_htable_handle kni_create_htable(const char *profile, const char *section, void *free_data_cb, void *expire_notify_cb, void *logger);
|