diff options
| author | luwenpeng <[email protected]> | 2023-10-11 18:11:48 +0800 |
|---|---|---|
| committer | luwenpeng <[email protected]> | 2023-10-23 19:27:59 +0800 |
| commit | 49ccb5149facb022cacfd98cb82fd5dd1fce2107 (patch) | |
| tree | fd0dd54b6e316713766e36df6da3546d96acea05 /common/src/utils.cpp | |
| parent | db517610e023b7c986f12c2207382db627ec9d19 (diff) | |
perf: Optimize IPID (Avoid the futex of rand() while ensuring that IPID increases monotonically)
Diffstat (limited to 'common/src/utils.cpp')
| -rw-r--r-- | common/src/utils.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/common/src/utils.cpp b/common/src/utils.cpp index 6b0f0a7..6ba90e3 100644 --- a/common/src/utils.cpp +++ b/common/src/utils.cpp @@ -196,16 +196,16 @@ void build_udp_header(const char *l3_hdr, int l3_hdr_len, struct udp_hdr *udp_hd udp_hdr->uh_sum = CHECKSUM_CARRY(sum); } -void build_ip_header(struct ip *ip_hdr, uint8_t next_protocol, const char *src_addr, const char *dst_addr, uint16_t payload_len) +void build_ip_header(struct ip *ip_hdr, uint8_t next_protocol, uint16_t ipid, const char *src_addr, const char *dst_addr, uint16_t payload_len) { memset(ip_hdr, 0, sizeof(struct ip)); - ip_hdr->ip_hl = 5; /* 20 byte header */ - ip_hdr->ip_v = 4; /* version 4 */ - ip_hdr->ip_tos = 0; /* IP tos */ - ip_hdr->ip_id = htons(random()); /* IP ID */ - ip_hdr->ip_ttl = 80; /* time to live */ - ip_hdr->ip_p = next_protocol; /* transport protocol */ + ip_hdr->ip_hl = 5; /* 20 byte header */ + ip_hdr->ip_v = 4; /* version 4 */ + ip_hdr->ip_tos = 0; /* IP tos */ + ip_hdr->ip_id = htons(ipid); /* IP ID */ + ip_hdr->ip_ttl = 80; /* time to live */ + ip_hdr->ip_p = next_protocol; /* transport protocol */ ip_hdr->ip_src.s_addr = inet_addr(src_addr); ip_hdr->ip_dst.s_addr = inet_addr(dst_addr); ip_hdr->ip_len = htons(sizeof(struct ip) + payload_len); /* total length */ |
