2019-05-09 15:14:01 +08:00
|
|
|
//TODO: 日志打印出文件名 + 行号
|
|
|
|
|
#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>
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <arpa/inet.h>
|
2019-05-17 17:04:50 +08:00
|
|
|
#include <netinet/tcp.h>
|
2019-05-09 15:14:01 +08:00
|
|
|
#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"
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
#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 { \
|
|
|
|
|
char location[KNI_PATH_MAX]; \
|
|
|
|
|
snprintf(location, KNI_PATH_MAX, "%s: line %d", __FILE__, __LINE__); \
|
|
|
|
|
MESA_handle_runtime_log(handler, RLOG_LV_FATAL, location, fmt, ##__VA_ARGS__); } while(0)
|
|
|
|
|
|
|
|
|
|
#define KNI_LOG_INFO(handler, fmt, ...) \
|
|
|
|
|
do { \
|
|
|
|
|
char location[KNI_PATH_MAX]; \
|
|
|
|
|
snprintf(location, KNI_PATH_MAX, "%s: line %d", __FILE__, __LINE__); \
|
2019-05-17 17:04:50 +08:00
|
|
|
MESA_handle_runtime_log(handler, RLOG_LV_INFO, location, fmt, ##__VA_ARGS__); } while(0)
|
2019-05-09 15:14:01 +08:00
|
|
|
|
|
|
|
|
#define KNI_LOG_DEBUG(handler, fmt, ...) \
|
|
|
|
|
do { \
|
|
|
|
|
char location[KNI_PATH_MAX]; \
|
|
|
|
|
snprintf(location, KNI_PATH_MAX, "%s: line %d", __FILE__, __LINE__); \
|
|
|
|
|
MESA_handle_runtime_log(handler, RLOG_LV_DEBUG, location, fmt, ##__VA_ARGS__); } while(0)
|
|
|
|
|
|
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
|
|
|
|
|
//TODO: 网络序
|
|
|
|
|
struct kni_tcpopt_info{
|
|
|
|
|
uint16_t mss;
|
|
|
|
|
uint8_t wscale;
|
|
|
|
|
uint8_t ts;
|
|
|
|
|
uint8_t sack;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
uint16_t kni_udp_checksum(const void *_buf, size_t len, in_addr_t src_addr, in_addr_t dest_addr);
|
|
|
|
|
struct kni_tcpopt_info* kni_get_tcpopt(struct tcphdr* tcphdr,int tcphdr_len);
|
|
|
|
|
|
|
|
|
|
MESA_htable_handle kni_create_htable(const char *profile, const char *section, void *free_data_cb, void *expire_notify_cb, void *logger);
|