perf: 使用session_id替换rand(), 避免rand()中futex的开销
This commit is contained in:
@@ -394,7 +394,10 @@ static struct session_ctx *inject_packet_search_session(struct session_table *ta
|
|||||||
* action bypass/block/forward
|
* 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 ethhdr *eth_hdr = (struct ethhdr *)buffer;
|
||||||
struct ip *ip_hdr = (struct ip *)((char *)eth_hdr + sizeof(struct ethhdr));
|
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_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_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)
|
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:
|
case PACKAGE_METHOD_VXLAN_G:
|
||||||
prepend_len = sizeof(struct ethhdr) + sizeof(struct ip) + sizeof(struct udp_hdr) + sizeof(struct g_vxlan);
|
prepend_len = sizeof(struct ethhdr) + sizeof(struct ip) + sizeof(struct udp_hdr) + sizeof(struct g_vxlan);
|
||||||
buffer = marsio_buff_prepend(rx_buff, prepend_len);
|
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;
|
break;
|
||||||
case PACKAGE_METHOD_LAYER2_SWITCH:
|
case PACKAGE_METHOD_LAYER2_SWITCH:
|
||||||
// TODO
|
// TODO
|
||||||
|
|||||||
Reference in New Issue
Block a user