diff --git a/common/include/kni_cmsg.h b/common/include/kni_cmsg.h index eeab498..c4b37ba 100644 --- a/common/include/kni_cmsg.h +++ b/common/include/kni_cmsg.h @@ -8,7 +8,8 @@ struct kni_cmsg_serialize_header; enum kni_cmsg_errno{ KNI_CMSG_INVALID_FORMAT = -1, KNI_CMSG_BUFF_NOT_ENOUGH = -2, - KNI_CMSG_INVALID_TYPE = -3 + KNI_CMSG_INVALID_TYPE = -3, + KNI_CMSG_TYPE_UNSET = -4, }; enum tfe_cmsg_tlv_type diff --git a/common/src/kni_cmsg.cpp b/common/src/kni_cmsg.cpp index ea4d462..0815c1b 100644 --- a/common/src/kni_cmsg.cpp +++ b/common/src/kni_cmsg.cpp @@ -65,11 +65,15 @@ int kni_cmsg_set(struct kni_cmsg *cmsg, uint16_t type, const unsigned char *valu int kni_cmsg_get(struct kni_cmsg *cmsg, uint16_t type, uint16_t *size, unsigned char **pvalue) { struct kni_cmsg_tlv *tlv = NULL; - if(type >= KNI_CMSG_TLV_NR_MAX || (tlv = cmsg->tlvs[type]) == NULL) + if(type >= KNI_CMSG_TLV_NR_MAX) { *size = 0; return KNI_CMSG_INVALID_TYPE; } + if((tlv = cmsg->tlvs[type]) == NULL){ + *size = 0; + return KNI_CMSG_TYPE_UNSET; + } *size = tlv->length - sizeof(struct kni_cmsg_tlv); *pvalue = tlv->value_as_string; return 0; @@ -153,6 +157,7 @@ int kni_cmsg_deserialize(const unsigned char *data, uint16_t len, struct kni_cms cmsg = ALLOC(struct kni_cmsg, 1); offset = sizeof(struct kni_cmsg_serialize_header); nr_tlvs = ntohs(header->nr_tlvs); + printf("nr_tlvs is %d\n", nr_tlvs); for(int i = 0; i < nr_tlvs; i++) { struct kni_cmsg_tlv *tlv = (struct kni_cmsg_tlv*)(data + offset); @@ -161,6 +166,7 @@ int kni_cmsg_deserialize(const unsigned char *data, uint16_t len, struct kni_cms goto error_out; } uint16_t type = ntohs(tlv->type); + printf("type = %d\n", type); uint16_t length = ntohs(tlv->length); if(length < sizeof(struct kni_cmsg_tlv) || offset + length > len) { diff --git a/conf/kni.conf b/conf/kni.conf index 86e5530..670dffb 100644 --- a/conf/kni.conf +++ b/conf/kni.conf @@ -6,7 +6,7 @@ local_eth = enp8s0 [maat] #readconf_mode: 0 = iris, 1 = json, 2 = redis -readconf_mode = 1 +readconf_mode = 2 tableinfo_path = ./conf/kni/maat_tableinfo.conf maatjson_path = ./conf/kni/maat_test.json redis_ip = 192.168.10.120 @@ -50,4 +50,13 @@ security.protocol = MG [tfe_cmsg_receiver] listen_eth = enp8s0 -listen_port = 8888 \ No newline at end of file +listen_port = 2475 + +[traceid2pme_htable] +mho_screen_print_ctrl = 0 +mho_thread_safe = 1 +mho_mutex_num = 160 +mho_hash_slot_size = 160000 +mho_hash_max_element_num = 640000 +mho_expire_time = 30 +mho_eliminate_type = LRU \ No newline at end of file diff --git a/entry/src/kni_entry.cpp b/entry/src/kni_entry.cpp index 113bf68..5c2fa04 100644 --- a/entry/src/kni_entry.cpp +++ b/entry/src/kni_entry.cpp @@ -53,13 +53,13 @@ struct pme_info{ time_t start_time; uint64_t con_duration; //from tfe, kafka log - int intercept_state; - int pinningst; //defalut 0 + uint64_t intercept_state; + uint64_t pinningst; //defalut 0 uint64_t ssl_server_side_latency; uint64_t ssl_client_side_latency; char ssl_server_side_version[KNI_SYMBOL_MAX]; char ssl_client_side_version[KNI_SYMBOL_MAX]; - int ssl_cert_verify; + uint64_t ssl_cert_verify; char ssl_error[KNI_STRING_MAX]; }; @@ -493,6 +493,7 @@ static char data_opstate(const struct streaminfo *stream, struct pme_info *pmein return APP_STATE_DROPPKT | APP_STATE_GIVEME; case KNI_ACTION_BYPASS: FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_BYP_PKT], 0, FS_OP_ADD, 1); + pmeinfo->tfe_release = 1; return APP_STATE_FAWPKT | APP_STATE_GIVEME; default: break; @@ -641,15 +642,19 @@ extern "C" char kni_tcpall_entry(const struct streaminfo *stream, void** pme, in pktinfo->data = (char*)pktinfo->tcphdr + pktinfo->tcphdr_len; pktinfo->data_len = pktinfo->ip_totlen - pktinfo->iphdr_len - pktinfo->tcphdr_len; int ret; + int key_size; switch(stream->pktstate){ case OP_STATE_PENDING: *pme = pmeinfo = pme_info_new(stream, thread_seq, logger); + key_size = strlen(pmeinfo->stream_trace_id); ret = MESA_htable_add(g_kni_handle->traceid2pme_htable, (const unsigned char *)(pmeinfo->stream_trace_id), - strlen(pmeinfo->stream_trace_id), (const void*)pmeinfo); + key_size, (const void*)pmeinfo); if(ret < 0){ KNI_LOG_ERROR(logger, "MESA_htable: failed at MESA_htable_add," "table is traceid2pme_htable, key is %s", pmeinfo->stream_trace_id); } + KNI_LOG_DEBUG(logger, "MESA_htable: succeed at MESA_htable_add, table is traceid2pme_htable, key is %s, key_size is %d", + key_size, pmeinfo->stream_trace_id); ret = pending_opstate(stream, pmeinfo, pktinfo); break; case OP_STATE_DATA: @@ -759,11 +764,13 @@ static int wrapped_kni_cmsg_get(struct pme_info *pmeinfo, struct kni_cmsg *cmsg, unsigned char *value = NULL; int ret = kni_cmsg_get(cmsg, type, &value_size, &value); if(ret < 0){ - KNI_LOG_ERROR(logger, "Failed at kni_cmsg_get: type is %d, ret is %d", type, ret); + if(ret == KNI_CMSG_INVALID_TYPE){ + KNI_LOG_ERROR(logger, "Failed at kni_cmsg_get: type is %d, ret is %d", type, ret); + } return -1; } if(value_size > value_size_max){ - KNI_LOG_ERROR(logger, "kni_cmsg_get: type is %s, size is %d, which should <= %d", type, value_size, value_size_max); + KNI_LOG_ERROR(logger, "kni_cmsg_get: type is %d, size is %d, which should <= %d", type, value_size, value_size_max); return -1; } switch(type) @@ -812,14 +819,17 @@ static long traceid2pme_htable_search_cb(void *data, const uchar *key, uint size wrapped_kni_cmsg_get(pmeinfo, cmsg, TFE_CMSG_SSL_PINNING_STATE, sizeof(pmeinfo->pinningst), logger); wrapped_kni_cmsg_get(pmeinfo, cmsg, TFE_CMSG_SSL_CERT_VERIFY, sizeof(pmeinfo->ssl_cert_verify), logger); wrapped_kni_cmsg_get(pmeinfo, cmsg, TFE_CMSG_SSL_ERROR, sizeof(pmeinfo->ssl_error), logger); + FREE(&cmsg); pmeinfo->tfe_release = 1; + int key_size = strlen(pmeinfo->stream_trace_id); int ret = MESA_htable_del(g_kni_handle->traceid2pme_htable, (const unsigned char *)pmeinfo->stream_trace_id, - sizeof(pmeinfo->stream_trace_id), NULL); + key_size, NULL); if(ret < 0){ - KNI_LOG_ERROR(logger, "MESA_htable: failed at del, table is %s, key is %s, ret is %d", - "traceid2pme_htable", pmeinfo->stream_trace_id, ret); + KNI_LOG_ERROR(logger, "MESA_htable: failed at del, table is %s, key is %s, key_size is %d, ret is %d", + "traceid2pme_htable", pmeinfo->stream_trace_id, key_size, ret); } } + FREE(&cmsg); return 0; }