Skip to content

Commit a7f6fc8

Browse files
committed
ipvs: Optimize TOA insertion performance using memmove
1 parent 3095daf commit a7f6fc8

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/ipvs/ip_vs_proto_tcp.c

+7-10
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,8 @@ static int tcp_in_add_toa(struct dp_vs_conn *conn, struct rte_mbuf *mbuf,
488488
uint32_t mtu;
489489
struct tcpopt_addr *toa;
490490
uint32_t tcp_opt_len;
491-
uint8_t *p, *q, *tail;
491+
uint8_t *src, *dst, *tail;
492+
size_t move_len;
492493
struct route_entry *rt;
493494
struct route6 *rt6;
494495

@@ -541,15 +542,11 @@ static int tcp_in_add_toa(struct dp_vs_conn *conn, struct rte_mbuf *mbuf,
541542
* now add address option
542543
*/
543544

544-
/* move data down, including existing tcp options
545-
* @p is last data byte,
546-
* @q is new position of last data byte */
547-
p = tail - 1;
548-
q = p + tcp_opt_len;
549-
while (p >= ((uint8_t *)tcph + sizeof(struct tcphdr))) {
550-
*q = *p;
551-
p--, q--;
552-
}
545+
/* move data down, including existing tcp options */
546+
src = (uint8_t *)tcph + sizeof(struct tcphdr);
547+
dst = src + tcp_opt_len;
548+
move_len = tail - src;
549+
memmove(dst, src, move_len);
553550

554551
/* insert toa right after TCP basic header */
555552
toa = (struct tcpopt_addr *)(tcph + 1);

0 commit comments

Comments
 (0)