Skip to content

Commit db0a762

Browse files
colo-ftjasowang
authored andcommitted
filter-rewriter: skip net_checksum_calculate() while offset = 0
While the offset of packets's sequence for primary side and secondary side is zero, it is unnecessary to call net_checksum_calculate() to recalculate the checksume value of packets. Signed-off-by: zhanghailiang <[email protected]> Signed-off-by: Jason Wang <[email protected]>
1 parent 0e79668 commit db0a762

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

net/filter-rewriter.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ static int handle_primary_tcp_pkt(NetFilterState *nf,
9393
conn->offset -= (ntohl(tcp_pkt->th_ack) - 1);
9494
conn->syn_flag = 0;
9595
}
96-
/* handle packets to the secondary from the primary */
97-
tcp_pkt->th_ack = htonl(ntohl(tcp_pkt->th_ack) + conn->offset);
96+
if (conn->offset) {
97+
/* handle packets to the secondary from the primary */
98+
tcp_pkt->th_ack = htonl(ntohl(tcp_pkt->th_ack) + conn->offset);
9899

99-
net_checksum_calculate((uint8_t *)pkt->data, pkt->size);
100+
net_checksum_calculate((uint8_t *)pkt->data, pkt->size);
101+
}
100102
}
101103

102104
return 0;
@@ -129,10 +131,13 @@ static int handle_secondary_tcp_pkt(NetFilterState *nf,
129131
}
130132

131133
if ((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == TH_ACK) {
132-
/* handle packets to the primary from the secondary*/
133-
tcp_pkt->th_seq = htonl(ntohl(tcp_pkt->th_seq) - conn->offset);
134+
/* Only need to adjust seq while offset is Non-zero */
135+
if (conn->offset) {
136+
/* handle packets to the primary from the secondary*/
137+
tcp_pkt->th_seq = htonl(ntohl(tcp_pkt->th_seq) - conn->offset);
134138

135-
net_checksum_calculate((uint8_t *)pkt->data, pkt->size);
139+
net_checksum_calculate((uint8_t *)pkt->data, pkt->size);
140+
}
136141
}
137142

138143
return 0;

0 commit comments

Comments
 (0)