perf: Optimize IPID (Avoid the futex of rand() while ensuring that IPID increases monotonically)
This commit is contained in:
@@ -397,7 +397,8 @@ static struct session_ctx *inject_packet_search_session(struct session_table *ta
|
||||
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)
|
||||
int payload_len, int is_e2i, int is_decrypted, int sf_index,
|
||||
uint64_t session_id, uint16_t ipid)
|
||||
{
|
||||
struct ethhdr *eth_hdr = (struct ethhdr *)buffer;
|
||||
struct ip *ip_hdr = (struct ip *)((char *)eth_hdr + sizeof(struct ethhdr));
|
||||
@@ -410,12 +411,13 @@ static void vxlan_encapsulate(char *buffer,
|
||||
g_vxlan_set_traffic_type(g_vxlan_hdr, is_decrypted);
|
||||
|
||||
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, ipid, 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, 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)
|
||||
{
|
||||
thread_ctx->tx_packets_to_sf++;
|
||||
struct packet_io *packet_io = thread_ctx->ref_io;
|
||||
int thread_index = thread_ctx->thread_index;
|
||||
|
||||
@@ -436,7 +438,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, meta->session_id);
|
||||
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, thread_ctx->tx_packets_to_sf % 65535);
|
||||
break;
|
||||
case PACKAGE_METHOD_LAYER2_SWITCH:
|
||||
// TODO
|
||||
|
||||
Reference in New Issue
Block a user