1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
@@ -305,6 +305,48 @@ } } +/* use NOP option to replace TCP_OLEN_IP4_ADDR and TCP_OLEN_IP6_ADDR opt */ +static void tcp_in_remove_toa(struct tcphdr *tcph, int af) +{ + unsigned char *ptr; + int len, i; + uint32_t tcp_opt_len = af == AF_INET ? TCP_OLEN_IP4_ADDR : TCP_OLEN_IP6_ADDR; + + ptr = (unsigned char *)(tcph + 1); + len = (tcph->doff << 2) - sizeof(struct tcphdr); + + while (len > 0) { + int opcode = *ptr++; + int opsize; + + switch (opcode) { + case TCP_OPT_EOL: + return; + case TCP_OPT_NOP: + len--; + continue; + default: + opsize = *ptr++; + if (opsize < 2) /* silly options */ + return; + if (opsize > len) + return; /* partial options */ + if ((opcode == TCP_OPT_ADDR) && (opsize == tcp_opt_len)) { + for (i = 0; i < tcp_opt_len; i++) { + *(ptr - 2 + i) = TCP_OPT_NOP; + } + /* DON'T RETURN + * keep search other TCP_OPT_ADDR ,and clear them. + * See https://github.com/iqiyi/dpvs/pull/925 for more detail. */ + } + + ptr += opsize - 2; + len -= opsize; + break; + } + } +} + static inline int tcp_in_add_toa(struct dp_vs_conn *conn, struct rte_mbuf *mbuf, struct tcphdr *tcph) { @@ -719,14 +761,25 @@ */ if (th->syn && !th->ack) { tcp_in_remove_ts(th); + tcp_in_init_seq(conn, mbuf, th); - tcp_in_add_toa(conn, mbuf, th); + + /* Only clear when adding TOA fails to reduce invocation frequency and improve performance. + * See https://github.com/iqiyi/dpvs/pull/925 for more detail. */ + if (unlikely(tcp_in_add_toa(conn, mbuf, th) != EDPVS_OK)) { + tcp_in_remove_toa(th, af); + } } /* add toa to first data packet */ if (ntohl(th->ack_seq) == conn->fnat_seq.fdata_seq - && !th->syn && !th->rst /*&& !th->fin*/) - tcp_in_add_toa(conn, mbuf, th); + && !th->syn && !th->rst /*&& !th->fin*/) { + /* Only clear when adding TOA fails to reduce invocation frequency and improve performance. + * See https://github.com/iqiyi/dpvs/pull/925 for more detail. */ + if (unlikely(tcp_in_add_toa(conn, mbuf, th) != EDPVS_OK)) { + tcp_in_remove_toa(th, af); + } + } tcp_in_adjust_seq(conn, th);
|