From d4525b0c5c09cd92c657cff8015089003c565cbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E4=B8=80=E9=B8=A3?= Date: Wed, 7 Aug 2019 15:42:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E8=AE=A1tap=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/kni_entry.cpp | 27 ++++++++++++++++++++++----- entry/src/tap_mode.cpp | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 entry/src/tap_mode.cpp diff --git a/entry/src/kni_entry.cpp b/entry/src/kni_entry.cpp index 5faafd7..7650d7e 100644 --- a/entry/src/kni_entry.cpp +++ b/entry/src/kni_entry.cpp @@ -667,8 +667,8 @@ 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(struct kni_marsio_handle *handle, 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; marsio_buff_t *tx_buffs[BURST_MAX]; int index = -1; @@ -712,6 +712,23 @@ static int send_to_tfe(struct kni_marsio_handle *handle, char *raw_data, uint16_ return 0; } +static int send_to_tfe(struct tap_mode_handle *handle, char *raw_data, uint16_t raw_len){ + int ret; + ret = tap_mode_write() +} + +static int send_to_tfe(struct kni_marsio_handle *marsio_handle, struct tap_mode_handle *tap_handle, char *raw_data, + uint16_t raw_len, int thread_seq, int tfe_id, addr_type_t addr_type, int 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){ @@ -856,7 +873,7 @@ static int first_data_intercept(const struct streaminfo *stream, struct pme_info //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(g_kni_handle->marsio_handle, g_kni_handle->tap_mode_handle, buff, len, thread_seq, pmeinfo->tfe_id, pmeinfo->addr_type); if(ret < 0){ KNI_LOG_ERROR(logger, "Failed at send first packet to tfe%d, stream traceid is %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); @@ -903,7 +920,7 @@ static char data_opstate(const struct streaminfo *stream, struct pme_info *pmein 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(g_kni_handle->marsio_handle, g_kni_handle->tap_mode_handle, (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 is %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); @@ -1275,7 +1292,7 @@ static long keepalive_replay_search_cb(void *data, const uchar *key, uint size, replay_packet_iphdr->saddr, replay_packet_iphdr->daddr); } //send to tfe: thread_seq = g_iThreadNum - int ret = send_to_tfe(marsio_handle, replay_packet, tot_len, g_iThreadNum + thread_seq, tfe_id, args->addr_type); + int ret = send_to_tfe(marsio_handle, g_kni_handle->tap_mode_handle, replay_packet, tot_len, g_iThreadNum + thread_seq, tfe_id, args->addr_type); if(ret < 0){ KNI_LOG_ERROR(logger, "Failed at send keepalive replay packet to tfe"); FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_SENDTO_TFE_FAIL], 0, FS_OP_ADD, 1); diff --git a/entry/src/tap_mode.cpp b/entry/src/tap_mode.cpp new file mode 100644 index 0000000..52d8f6b --- /dev/null +++ b/entry/src/tap_mode.cpp @@ -0,0 +1,18 @@ + +struct tap_mode_handle{ + int fd; + void *logger; +}; + +struct tap_mode_handle* tap_mode_init(void *logger){ + +} + + +int tap_mode_write(struct tap_mode_handle *handle, char *buff, uint16_t buff_len){ + +} + +int tap_mode_read(struct tap_mode_handle *handle, char *buff, uint16_t buff_len){ + +} \ No newline at end of file