Merge branch 'feature-tap-mode' into feature-dup-traffic-recognize
This commit is contained in:
@@ -52,6 +52,12 @@ enum stream_error{
|
||||
STREAM_ERROR_TUPLE2STM_ADD_FAIL = -10,
|
||||
};
|
||||
|
||||
enum sendto_tfe_mode{
|
||||
SENDTO_TFE_MODE_TAP = 0,
|
||||
SENDTO_TFE_MODE_NORMAL = 1,
|
||||
};
|
||||
|
||||
SENDTO_TFE_MODE_TAP
|
||||
struct http_project{
|
||||
int host_len;
|
||||
char host[KNI_DOMAIN_MAX];
|
||||
@@ -175,6 +181,8 @@ struct tuple2stream_htable_value{
|
||||
struct kni_handle{
|
||||
int http_project_id;
|
||||
struct kni_marsio_handle *marsio_handle;
|
||||
struct kni_tap_handle *tap_handle;
|
||||
enum sendto_tfe_mode _sendto_tfe_mode;
|
||||
struct kni_maat_handle *maat_handle;
|
||||
struct kni_send_logger *send_logger;
|
||||
MESA_htable_handle traceid2pme_htable;
|
||||
@@ -668,9 +676,10 @@ static char* add_cmsg_to_packet(struct pme_info *pmeinfo, struct pkt_info *pktin
|
||||
*len = offset;
|
||||
return new_pkt;
|
||||
}
|
||||
|
||||
static int send_to_tfe(struct kni_marsio_handle *handle, char *raw_data, uint16_t raw_len, int thread_seq, int tfe_id, addr_type_t addr_type){
|
||||
|
||||
static int send_to_tfe_normal_mode(char *raw_data, uint16_t raw_len, int thread_seq, int tfe_id, addr_type_t addr_type){
|
||||
void *logger = g_kni_handle->local_logger;
|
||||
struct kni_marsio_handle *handle = g_kni_handle->marsio_handle;
|
||||
marsio_buff_t *tx_buffs[BURST_MAX];
|
||||
int index = -1;
|
||||
for(int i = 0; i < handle->tfe_enabled_node_count; i++){
|
||||
@@ -713,6 +722,29 @@ static int send_to_tfe(struct kni_marsio_handle *handle, char *raw_data, uint16_
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int send_to_tfe_tap_mode(char *raw_data, uint16_t raw_len){
|
||||
struct kni_tap_handle *handle = g_kni_handle->tap_handle;
|
||||
int ret = kni_tap_write(handle, raw_data, raw_len);
|
||||
if(ret < 0){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int send_to_tfe(char *raw_data, uint16_t raw_len, int thread_seq, int tfe_id, addr_type_t addr_type){
|
||||
struct kni_marsio_handle *marsio_handle = g_kni_handle->marsio_handle;
|
||||
struct kni_tap_handle *tap_handle = g_kni_handle->tap_handle;
|
||||
int mode = g_kni_handle->_sendto_tfe_mode;
|
||||
int ret;
|
||||
if(mode == SENDTO_TFE_MODE_TAP){
|
||||
ret = send_to_tfe_tap_mode(tap_handle, raw_data, raw_len);
|
||||
}
|
||||
else{
|
||||
ret = send_to_tfe_normal_mode(marsio_handle, raw_data, raw_len, thread_seq, tfe_id, addr_type);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int wrapped_kni_header_parse(const void *a_packet, struct pme_info *pmeinfo, struct pkt_info *pktinfo){
|
||||
void *logger = g_kni_handle->local_logger;
|
||||
if(pmeinfo->addr_type == ADDR_TYPE_IPV6){
|
||||
@@ -982,7 +1014,7 @@ static int first_data_intercept(struct streaminfo *stream, struct pme_info *pmei
|
||||
//action = KNI_ACTION_INTERCEPT, sendto tfe
|
||||
int len = 0;
|
||||
char *buff = add_cmsg_to_packet(pmeinfo, pktinfo, &len);
|
||||
ret = send_to_tfe(g_kni_handle->marsio_handle, buff, len, thread_seq, pmeinfo->tfe_id, pmeinfo->addr_type);
|
||||
ret = send_to_tfe(buff, len, thread_seq, pmeinfo->tfe_id, pmeinfo->addr_type);
|
||||
if(ret < 0){
|
||||
KNI_LOG_DEBUG(logger, "Stream error: failed at send first packet to tfe%d, stream traceid = %s", pmeinfo->tfe_id, pmeinfo->stream_traceid);
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_SENDTO_TFE_FAIL], 0, FS_OP_ADD, 1);
|
||||
@@ -1088,7 +1120,7 @@ static char data_opstate(struct streaminfo *stream, struct pme_info *pmeinfo, co
|
||||
ipv4_hdr = (struct iphdr*)a_packet;
|
||||
len = ntohs(ipv4_hdr->tot_len);
|
||||
}
|
||||
ret = send_to_tfe(g_kni_handle->marsio_handle, (char*)a_packet, len, thread_seq, pmeinfo->tfe_id, pmeinfo->addr_type);
|
||||
ret = send_to_tfe((char*)a_packet, len, thread_seq, pmeinfo->tfe_id, pmeinfo->addr_type);
|
||||
if(ret < 0){
|
||||
KNI_LOG_ERROR(logger, "Failed at send continue packet to tfe%d, stream traceid = %s", pmeinfo->tfe_id, pmeinfo->stream_traceid);
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_SENDTO_TFE_FAIL], 0, FS_OP_ADD, 1);
|
||||
@@ -1410,6 +1442,7 @@ int tuple2stream_htable_search(MESA_htable_handle handle, struct ethhdr *ether_h
|
||||
}
|
||||
//ipv4
|
||||
else{
|
||||
<<<<<<< HEAD
|
||||
ret = kni_ipv4_header_parse(raw_packet, &pktinfo);
|
||||
if(ret < 0){
|
||||
char *errmsg = kni_ipv4_errmsg_get((enum kni_ipv4hdr_parse_error)ret);
|
||||
@@ -1433,6 +1466,32 @@ int tuple2stream_htable_search(MESA_htable_handle handle, struct ethhdr *ether_h
|
||||
dir = MESA_dir_reverse(value->stream->routedir);
|
||||
}
|
||||
ret = sapp_inject_pkt(value->stream, SIO_EXCLUDE_THIS_LAYER_HDR, raw_packet, pktinfo.ip_totlen, dir);
|
||||
=======
|
||||
struct iphdr *raw_packet_iphdr = (struct iphdr*)raw_packet;
|
||||
tot_len = ntohs(raw_packet_iphdr->tot_len);
|
||||
uint16_t iphdr_len = raw_packet_iphdr->ihl * 4;
|
||||
struct tcphdr *raw_packet_tcphdr = (struct tcphdr*)((char*)raw_packet_iphdr + iphdr_len);
|
||||
//replay packet
|
||||
replay_packet = ALLOC(char, tot_len);
|
||||
memcpy(replay_packet, raw_packet, tot_len);
|
||||
struct iphdr *replay_packet_iphdr = (struct iphdr*)replay_packet;
|
||||
struct tcphdr *replay_packet_tcphdr = (struct tcphdr*)((char*)replay_packet_iphdr + iphdr_len);
|
||||
replay_packet_iphdr->saddr = raw_packet_iphdr->daddr;
|
||||
replay_packet_iphdr->daddr = raw_packet_iphdr->saddr;
|
||||
replay_packet_tcphdr->source = raw_packet_tcphdr->dest;
|
||||
replay_packet_tcphdr->dest = raw_packet_tcphdr->source;
|
||||
replay_packet_tcphdr->seq = htonl(ntohl(raw_packet_tcphdr->ack_seq) + value->first_data_len); //seq = ack + first_data_len
|
||||
replay_packet_tcphdr->ack_seq = htonl(ntohl(raw_packet_tcphdr->seq) + 1); //ack = seq + 1
|
||||
replay_packet_tcphdr->window = htons(value->window);
|
||||
replay_packet_iphdr->check = 0;
|
||||
replay_packet_iphdr->check = kni_ip_checksum((void*)replay_packet_iphdr, iphdr_len);
|
||||
replay_packet_tcphdr->check = 0;
|
||||
replay_packet_tcphdr->check = kni_tcp_checksum((void*)replay_packet_tcphdr, tot_len - iphdr_len,
|
||||
replay_packet_iphdr->saddr, replay_packet_iphdr->daddr);
|
||||
}
|
||||
//send to tfe: thread_seq = g_iThreadNum
|
||||
int ret = send_to_tfe(replay_packet, tot_len, g_iThreadNum + thread_seq, tfe_id);
|
||||
>>>>>>> feature-tap-mode
|
||||
if(ret < 0){
|
||||
KNI_LOG_ERROR(logger, "Failed at sapp_inject_pkt, stream addr = %s", key_str);
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_SAPP_INJECT_FAIL], 0, FS_OP_ADD, 1);
|
||||
@@ -1999,6 +2058,8 @@ extern "C" int kni_init(){
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
g_kni_handle->tap_handle = kni_tap_init()
|
||||
|
||||
//init maat
|
||||
g_kni_handle->maat_handle = kni_maat_init(profile, local_logger, g_kni_handle->thread_count);
|
||||
if(g_kni_handle->maat_handle == NULL){
|
||||
|
||||
Reference in New Issue
Block a user