diff --git a/bpf/bpf_tun_rss_steering.c b/bpf/bpf_tun_rss_steering.c index 36b80e1..c07166a 100644 --- a/bpf/bpf_tun_rss_steering.c +++ b/bpf/bpf_tun_rss_steering.c @@ -328,11 +328,11 @@ static inline void select_rss_queue(struct packet *packet, struct bpf_config *co { packet->src_addr_hash = crc32_hash(&packet->in4_src, 4, 0); packet->dst_addr_hash = crc32_hash(&packet->in4_dst, 4, 0); - packet->last_hash = packet->src_addr_hash ^ packet->dst_addr_hash; + packet->last_hash = packet->src_addr_hash + packet->dst_addr_hash; packet->src_port_hash = crc32_hash(&packet->src_port, 2, packet->last_hash); packet->dst_port_hash = crc32_hash(&packet->dst_port, 2, packet->last_hash); - packet->last_hash = packet->src_port_hash ^ packet->dst_port_hash; + packet->last_hash = packet->src_port_hash + packet->dst_port_hash; packet->select_queue = packet->last_hash % bpf_config_get_queue_num(config); } @@ -340,7 +340,7 @@ static inline void select_rss_queue(struct packet *packet, struct bpf_config *co { packet->src_addr_hash = crc32_hash(&packet->in4_src, 4, 0); packet->dst_addr_hash = crc32_hash(&packet->in4_dst, 4, 0); - packet->last_hash = packet->src_addr_hash ^ packet->dst_addr_hash; + packet->last_hash = packet->src_addr_hash + packet->dst_addr_hash; packet->select_queue = packet->last_hash % bpf_config_get_queue_num(config); } @@ -352,11 +352,11 @@ static inline void select_rss_queue(struct packet *packet, struct bpf_config *co { packet->src_addr_hash = crc32_hash(&packet->in6_src, 16, 0); packet->dst_addr_hash = crc32_hash(&packet->in6_dst, 16, 0); - packet->last_hash = packet->src_addr_hash ^ packet->dst_addr_hash; + packet->last_hash = packet->src_addr_hash + packet->dst_addr_hash; packet->src_port_hash = crc32_hash(&packet->src_port, 2, packet->last_hash); packet->dst_port_hash = crc32_hash(&packet->dst_port, 2, packet->last_hash); - packet->last_hash = packet->src_port_hash ^ packet->dst_port_hash; + packet->last_hash = packet->src_port_hash + packet->dst_port_hash; packet->select_queue = packet->last_hash % bpf_config_get_queue_num(config); } @@ -364,7 +364,7 @@ static inline void select_rss_queue(struct packet *packet, struct bpf_config *co { packet->src_addr_hash = crc32_hash(&packet->in6_src, 16, 0); packet->dst_addr_hash = crc32_hash(&packet->in6_dst, 16, 0); - packet->last_hash = packet->src_addr_hash ^ packet->dst_addr_hash; + packet->last_hash = packet->src_addr_hash + packet->dst_addr_hash; packet->select_queue = packet->last_hash % bpf_config_get_queue_num(config); } diff --git a/common/include/tfe_packet_io.h b/common/include/tfe_packet_io.h index 848d098..76e9be4 100644 --- a/common/include/tfe_packet_io.h +++ b/common/include/tfe_packet_io.h @@ -80,6 +80,7 @@ struct session_ctx struct acceptor_kni_v4 { + int debug; int firewall_sids; int proxy_sids; int sce_sids; diff --git a/common/include/tfe_raw_packet.h b/common/include/tfe_raw_packet.h index f88684c..69818b8 100644 --- a/common/include/tfe_raw_packet.h +++ b/common/include/tfe_raw_packet.h @@ -90,8 +90,10 @@ int raw_packet_parser_get_most_outer_tuple4(struct raw_pkt_parser *handler, stru int raw_packet_parser_get_most_inner_address(struct raw_pkt_parser *handler, struct addr_tuple4 *addr, void *logger); int raw_packet_parser_get_most_outer_address(struct raw_pkt_parser *handler, struct addr_tuple4 *addr, void *logger); -uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum ldbc_method method, int dir_is_internal, void *logger); +uint16_t raw_packet_parser_get_most_inner_ipid(struct raw_pkt_parser *handler); +uint16_t raw_packet_parser_get_most_outer_ipid(struct raw_pkt_parser *handler); +uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum ldbc_method method, int dir_is_internal, void *logger); int raw_traffic_decapsulate(struct raw_pkt_parser *handler, char *raw_data, int raw_len, char **output, int *out_len, int *is_ipv4); diff --git a/common/src/tfe_packet_io.cpp b/common/src/tfe_packet_io.cpp index 10f741f..98dfdf8 100644 --- a/common/src/tfe_packet_io.cpp +++ b/common/src/tfe_packet_io.cpp @@ -1536,6 +1536,22 @@ static int handle_raw_packet_from_nf(struct packet_io *handle, marsio_buff_t *rx if (node == NULL) { throughput_metrics_inc(&packet_io_fs->raw_pkt_rx, 1, raw_len); throughput_metrics_inc(&packet_io_fs->raw_bypass, 1, raw_len); + + if (thread->ref_acceptor_ctx->debug) + { + struct addr_tuple4 inner_addr; + struct raw_pkt_parser raw_parser; + memset(&inner_addr, 0, sizeof(struct addr_tuple4)); + raw_packet_parser_init(&raw_parser, 0, LAYER_TYPE_ALL, 8); + raw_packet_parser_parse(&raw_parser, (const void *)raw_data, raw_len, logger); + raw_packet_parser_get_most_inner_tuple4(&raw_parser, &inner_addr, logger); + uint16_t ipid = raw_packet_parser_get_most_inner_ipid(&raw_parser); + + char *str = addr_tuple4_to_str(&inner_addr); + TFE_LOG_ERROR(logger, "packet from nf %lu: %s (ipid: %u) miss session table", meta.session_id, str, ipid); + free(str); + } + marsio_send_burst(handle->dev_nf_interface.mr_path, thread_seq, &rx_buff, 1); return -1; } @@ -1913,6 +1929,7 @@ int packet_io_polling_nf_interface(struct packet_io *handle, int thread_seq, voi { marsio_buff_t *rx_buff = rx_buffs[j]; int raw_len = marsio_buff_datalen(rx_buff); + char *raw_data = marsio_buff_mtod(rx_buff); if (is_downstream_keepalive_packet(rx_buff)) { @@ -1926,6 +1943,21 @@ int packet_io_polling_nf_interface(struct packet_io *handle, int thread_seq, voi continue; } + if (thread->ref_acceptor_ctx->debug) + { + struct addr_tuple4 inner_addr; + struct raw_pkt_parser raw_parser; + memset(&inner_addr, 0, sizeof(struct addr_tuple4)); + raw_packet_parser_init(&raw_parser, 0, LAYER_TYPE_ALL, 8); + raw_packet_parser_parse(&raw_parser, (const void *)raw_data, raw_len, thread->logger); + raw_packet_parser_get_most_inner_tuple4(&raw_parser, &inner_addr, thread->logger); + uint16_t ipid = raw_packet_parser_get_most_inner_ipid(&raw_parser); + + char *str = addr_tuple4_to_str(&inner_addr); + TFE_LOG_DEBUG(thread->logger, "recv packet %s (ipid: %u)", str, ipid); + free(str); + } + if (marsio_buff_is_ctrlbuf(rx_buff)) { throughput_metrics_inc(&packet_io_fs->raw_pkt_rx, 1, raw_len); @@ -2041,6 +2073,15 @@ void handle_raw_packet_from_tap(const char *data, int len, void *args) struct session_node *node = session_table_search_by_addr(thread->session_table, &inner_addr); if (node == NULL) { throughput_metrics_inc(&packet_io_fs->tap_pkt_rxdrop, 1, len); + + if (thread->ref_acceptor_ctx->debug) + { + char *str = addr_tuple4_to_str(&inner_addr); + uint16_t ipid = raw_packet_parser_get_most_inner_ipid(&raw_parser); + TFE_LOG_ERROR(logger, "packet from tap %s (ipid: %u) miss session table", str, ipid); + free(str); + } + return; } diff --git a/common/src/tfe_raw_packet.cpp b/common/src/tfe_raw_packet.cpp index 9efada2..07c0932 100644 --- a/common/src/tfe_raw_packet.cpp +++ b/common/src/tfe_raw_packet.cpp @@ -168,7 +168,7 @@ int raw_packet_parser_get_most_inner_tuple4(struct raw_pkt_parser *handler, stru // return 0 : success // return -1 : error -int raw_packet_parser_get_most_outer_tuple4(struct raw_pkt_parser *handler, struct addr_tuple4 *addr, void *logger) +int raw_packet_parser_get_most_outer_tuple4(struct raw_pkt_parser *handler, struct addr_tuple4 *addr, void *logger) { const char *l3_layer_data = NULL; const char *l4_layer_data = NULL; @@ -271,6 +271,64 @@ int raw_packet_parser_get_most_outer_address(struct raw_pkt_parser *handler, str return -1; } +uint16_t raw_packet_parser_get_most_inner_ipid(struct raw_pkt_parser *handler) +{ + const char *l3_layer_data = NULL; + struct layer_results *results = &handler->results; + + // search L3 layer in reverse order + for (int8_t i = results->layers_used - 1; i >= 0; i--) + { + const struct layer_result *layer = &results->layers[i]; + enum layer_type type = layer->type; + + if (type & LAYER_TYPE_L3) + { + l3_layer_data = (const char *)handler->ptr_pkt_start + layer->offset; + if (type == LAYER_TYPE_IPV4) + { + const struct ip *ipv4_hdr = (const struct ip *)l3_layer_data; + return ntohs(ipv4_hdr->ip_id); + } + else + { + return 0; + } + } + } + + return 0; +} + +uint16_t raw_packet_parser_get_most_outer_ipid(struct raw_pkt_parser *handler) +{ + const char *l3_layer_data = NULL; + struct layer_results *results = &handler->results; + + // search L3 layer in order + for (int8_t i = 0; i <= results->layers_used - 1; i++) + { + const struct layer_result *layer = &results->layers[i]; + enum layer_type type = layer->type; + + if (type & LAYER_TYPE_L3) + { + l3_layer_data = (const char *)handler->ptr_pkt_start + layer->offset; + if (type == LAYER_TYPE_IPV4) + { + const struct ip *ipv4_hdr = (const struct ip *)l3_layer_data; + return ntohs(ipv4_hdr->ip_id); + } + else + { + return 0; + } + } + } + + return -1; +} + uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum ldbc_method method, int dir_is_internal, void *logger) { uint64_t temp = 0; @@ -392,7 +450,7 @@ uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum l char *inner_addr_str = addr_tuple4_to_str(&inner_addr); char *outer_addr_str = addr_tuple4_to_str(&outer_addr); TFE_LOG_DEBUG(logger, "%s: pkt_trace_id: %lu, outer_addr: %s, inner_addr: %s, is_internal: %d, hash_method: %s, hash_value: %lu", - LOG_TAG_RAWPKT, handler->pkt_trace_id, outer_addr_str, inner_addr_str, dir_is_internal, ldbc_method_to_string(method), hash_value); + LOG_TAG_RAWPKT, handler->pkt_trace_id, outer_addr_str, inner_addr_str, dir_is_internal, ldbc_method_to_string(method), hash_value); free(inner_addr_str); free(outer_addr_str); @@ -889,7 +947,7 @@ static const void *parse_vxlan(struct raw_pkt_parser *handler, const void *data, return data; } - //struct vxlan_hdr *vxlan_hdr = (struct vxlan_hdr *)data; + // struct vxlan_hdr *vxlan_hdr = (struct vxlan_hdr *)data; uint16_t hdr_len = sizeof(struct vxlan_hdr); const void *data_next_layer = (const char *)data + hdr_len; size_t data_next_length = length - hdr_len; diff --git a/conf/tfe/tfe.conf b/conf/tfe/tfe.conf index cac29ad..2e369c0 100644 --- a/conf/tfe/tfe.conf +++ b/conf/tfe/tfe.conf @@ -228,6 +228,7 @@ app_name="proxy_rule_hits" # for enable kni v4 [packet_io] +packet_io_debug=0 packet_io_threads=8 packet_io_cpu_affinity_mask=1-9 diff --git a/conf/tfe/zlog.conf b/conf/tfe/zlog.conf index 5b95a46..eee4efe 100644 --- a/conf/tfe/zlog.conf +++ b/conf/tfe/zlog.conf @@ -2,7 +2,7 @@ [global] -default format = "%d(%c), %V, %F, %U, %m%n" +default format = "%d(%c), %t, %V, %F, %U, %m%n" [levels] diff --git a/platform/src/acceptor_kni_v4.cpp b/platform/src/acceptor_kni_v4.cpp index c1b0055..f054262 100644 --- a/platform/src/acceptor_kni_v4.cpp +++ b/platform/src/acceptor_kni_v4.cpp @@ -85,6 +85,7 @@ struct acceptor_kni_v4 *acceptor_ctx_create(const char *profile, void *logger) MESA_load_profile_int_def(profile, "PACKET_IO", "firewall_sids", (int *)&(ctx->firewall_sids), 1000); MESA_load_profile_int_def(profile, "PACKET_IO", "proxy_sids", (int *)&(ctx->proxy_sids), 1001); MESA_load_profile_int_def(profile, "PACKET_IO", "service_chaining_sids", (int *)&(ctx->sce_sids), 1002); + MESA_load_profile_int_def(profile, "PACKET_IO", "packet_io_debug", (int *)&(ctx->debug), 0); MESA_load_profile_int_def(profile, "PACKET_IO", "packet_io_threads", (int *)&(ctx->nr_worker_threads), 8); MESA_load_profile_uint_range(profile, "PACKET_IO", "packet_io_cpu_affinity_mask", TFE_THREAD_MAX, (unsigned int *)ctx->cpu_affinity_mask); ctx->nr_worker_threads = MIN(ctx->nr_worker_threads, TFE_THREAD_MAX);