初步完成数据面代码

This commit is contained in:
崔一鸣
2019-05-17 17:04:50 +08:00
parent 5cda54c8d4
commit c0e577d115
84 changed files with 944 additions and 1533 deletions

View File

@@ -1,13 +1,13 @@
//TODO: 日志打印出文件名 + 行号
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <pthread.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <time.h>
#include "MESA/MESA_handle_logger.h"
#include "MESA/MESA_htable.h"
@@ -19,6 +19,11 @@
#define KNI_STRING_MAX 2048
#define KNI_PATH_MAX 256
#define KNI_SYMBOL_MAX 64
#define KNI_DOMAIN_MAX 256
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#define likely(expr) __builtin_expect((expr), 1)
#define unlikely(expr) __builtin_expect((expr), 0)
@@ -35,7 +40,7 @@ do { \
do { \
char location[KNI_PATH_MAX]; \
snprintf(location, KNI_PATH_MAX, "%s: line %d", __FILE__, __LINE__); \
MESA_handle_runtime_log(handler, RLOG_LV_INFO, location, fmt, ##__VA_ARGS__); } while(0)
MESA_handle_runtime_log(handler, RLOG_LV_INFO, location, fmt, ##__VA_ARGS__); } while(0)
#define KNI_LOG_DEBUG(handler, fmt, ...) \
do { \
@@ -43,5 +48,22 @@ do { \
snprintf(location, KNI_PATH_MAX, "%s: line %d", __FILE__, __LINE__); \
MESA_handle_runtime_log(handler, RLOG_LV_DEBUG, location, fmt, ##__VA_ARGS__); } while(0)
//fprintf(stderr, fmt "\n", ##__VA_ARGS__);
MESA_htable_handle KNI_utils_create_htable(const char *profile, const char *section, void *free_data_cb, void *expire_notify_cb, void *logger);
//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);