diff options
| author | luwenpeng <[email protected]> | 2023-10-10 16:47:56 +0800 |
|---|---|---|
| committer | luwenpeng <[email protected]> | 2023-10-11 15:20:43 +0800 |
| commit | 2d9fecdf0fa18425ec3c57a345960791ace3690a (patch) | |
| tree | 0e8486f3570fbc9d07a9f0b4f461667b934e3d71 | |
| parent | b6d80d130c3d63e4c6add220811883f8fd381265 (diff) | |
perf: 使用session_id替换rand(), 避免rand()中futex的开销v1.0.18-20231011
| -rw-r--r-- | platform/src/packet_io.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/platform/src/packet_io.cpp b/platform/src/packet_io.cpp index 43e2dac..f44150e 100644 --- a/platform/src/packet_io.cpp +++ b/platform/src/packet_io.cpp @@ -394,7 +394,10 @@ static struct session_ctx *inject_packet_search_session(struct session_table *ta * action bypass/block/forward ******************************************************************************/ -static void vxlan_encapsulate(char *buffer, const char *src_mac_str, const char *dst_mac_str, const char *src_ip_str, const char *dst_ip_str, int payload_len, int is_e2i, int is_decrypted, int sf_index) +static void vxlan_encapsulate(char *buffer, + const char *src_mac_str, const char *dst_mac_str, + const char *src_ip_str, const char *dst_ip_str, + int payload_len, int is_e2i, int is_decrypted, int sf_index, uint64_t session_id) { struct ethhdr *eth_hdr = (struct ethhdr *)buffer; struct ip *ip_hdr = (struct ip *)((char *)eth_hdr + sizeof(struct ethhdr)); @@ -408,7 +411,7 @@ static void vxlan_encapsulate(char *buffer, const char *src_mac_str, const char build_ether_header(eth_hdr, ETH_P_IP, src_mac_str, dst_mac_str); build_ip_header(ip_hdr, IPPROTO_UDP, src_ip_str, dst_ip_str, sizeof(struct udp_hdr) + sizeof(struct g_vxlan) + payload_len); - build_udp_header((const char *)&ip_hdr->ip_src, 8, udp_hdr, rand() % (65535 - 49152) + 49152, 4789, sizeof(struct g_vxlan) + payload_len); + build_udp_header((const char *)&ip_hdr->ip_src, 8, udp_hdr, session_id % (65535 - 49152) + 49152, 4789, sizeof(struct g_vxlan) + payload_len); } static int send_packet_to_sf(marsio_buff_t *rx_buff, struct metadata *meta, struct selected_sf *sf, struct thread_ctx *thread_ctx) @@ -433,7 +436,7 @@ static int send_packet_to_sf(marsio_buff_t *rx_buff, struct metadata *meta, stru case PACKAGE_METHOD_VXLAN_G: prepend_len = sizeof(struct ethhdr) + sizeof(struct ip) + sizeof(struct udp_hdr) + sizeof(struct g_vxlan); buffer = marsio_buff_prepend(rx_buff, prepend_len); - vxlan_encapsulate(buffer, src_mac_str, dst_mac_str, src_ip_str, dst_ip_str, payload_len, is_e2i, is_decrypted, sf_index); + vxlan_encapsulate(buffer, src_mac_str, dst_mac_str, src_ip_str, dst_ip_str, payload_len, is_e2i, is_decrypted, sf_index, meta->session_id); break; case PACKAGE_METHOD_LAYER2_SWITCH: // TODO |
