修复一处内存泄漏, 添加cmsg失败bypass
This commit is contained in:
@@ -600,18 +600,22 @@ static unsigned char* kni_cmsg_serialize_header_new(struct pme_info *pmeinfo, st
|
||||
char src_mac[6];
|
||||
ret = get_rawpkt_opt_from_streaminfo(stream, RAW_PKT_GET_VXLAN_OUTER_GDEV_MAC, src_mac);
|
||||
if(ret < 0){
|
||||
KNI_LOG_ERROR(logger, "Failed at get src mac from rawpkt");
|
||||
KNI_LOG_ERROR(logger, "Failed at get src mac from rawpkt, ret = %d", ret);
|
||||
goto error_out;
|
||||
}
|
||||
KNI_LOG_DEBUG(logger, "Succeed at get src mac from rawpkt, addr = %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
|
||||
src_mac[0], src_mac[1], src_mac[2], src_mac[3], src_mac[4], src_mac[5]);
|
||||
ret = wrapped_kni_cmsg_set(cmsg, TFE_CMSG_SRC_MAC, (const unsigned char*)src_mac, sizeof(src_mac), pmeinfo->stream_traceid);
|
||||
if(ret < 0) goto error_out;
|
||||
//dst mac
|
||||
char dst_mac[6];
|
||||
ret = get_rawpkt_opt_from_streaminfo(stream, RAW_PKT_GET_VXLAN_OUTER_LOCAL_MAC, dst_mac);
|
||||
if(ret < 0){
|
||||
KNI_LOG_ERROR(logger, "Failed at get dst mac from rawpkt");
|
||||
KNI_LOG_ERROR(logger, "Failed at get dst mac from rawpkt, ret = %d", ret);
|
||||
goto error_out;
|
||||
}
|
||||
KNI_LOG_DEBUG(logger, "Succeed at get dst mac from rawpkt, addr = %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
|
||||
dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5]);
|
||||
ret = wrapped_kni_cmsg_set(cmsg, TFE_CMSG_DST_MAC, (const unsigned char*)dst_mac, sizeof(dst_mac), pmeinfo->stream_traceid);
|
||||
if(ret < 0) goto error_out;
|
||||
|
||||
@@ -629,6 +633,9 @@ static unsigned char* kni_cmsg_serialize_header_new(struct pme_info *pmeinfo, st
|
||||
return buff;
|
||||
|
||||
error_out:
|
||||
if(buff != NULL){
|
||||
FREE(&buff);
|
||||
}
|
||||
kni_cmsg_destroy(cmsg);
|
||||
return NULL;
|
||||
}
|
||||
@@ -655,6 +662,7 @@ static char* add_cmsg_to_packet(struct pme_info *pmeinfo, struct streaminfo *str
|
||||
opt->len = 4;
|
||||
opt->offset = htons(pktinfo->data_len);
|
||||
memcpy(new_pkt + offset, (void*)opt, 4);
|
||||
FREE(&opt);
|
||||
offset += 4;
|
||||
memcpy(new_pkt + offset, (void*)((char*)pktinfo->tcphdr + 20), pktinfo->tcphdr_len - 20);
|
||||
offset += pktinfo->tcphdr_len - 20;
|
||||
@@ -664,6 +672,9 @@ static char* add_cmsg_to_packet(struct pme_info *pmeinfo, struct streaminfo *str
|
||||
//kni_cmsg_serialize_header
|
||||
uint16_t header_len = 0;
|
||||
unsigned char* header = kni_cmsg_serialize_header_new(pmeinfo, stream, pktinfo, &header_len);
|
||||
if(header == NULL){
|
||||
goto error_out;
|
||||
}
|
||||
memcpy(new_pkt + offset, (void*)header, header_len);
|
||||
offset += header_len;
|
||||
FREE(&header);
|
||||
@@ -687,6 +698,12 @@ static char* add_cmsg_to_packet(struct pme_info *pmeinfo, struct streaminfo *str
|
||||
}
|
||||
*len = offset;
|
||||
return new_pkt;
|
||||
|
||||
error_out:
|
||||
if(new_pkt != NULL){
|
||||
FREE(&new_pkt);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int add_ether_header(void *dst_data, void *raw_data, uint16_t raw_len, addr_type_t addr_type){
|
||||
@@ -1034,6 +1051,10 @@ 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, stream, pktinfo, &len);
|
||||
if(buff == NULL){
|
||||
KNI_LOG_ERROR(logger, "Failed at add cmsg to packet, stream traceid = %s", pmeinfo->stream_traceid);
|
||||
return APP_STATE_FAWPKT | APP_STATE_DROPME;
|
||||
}
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user