修改tcp options中mss值
src/ipvs/ip_vs_proto_tcp.c
因为tcp头部options中不同kind顺序是随机的,所以需要遍历找到kind值是mss 2和length值是4,再修改后面的mss value。
static void tcp_out_adjust_mss(int af, struct tcphdr *tcph)
{
unsigned char *ptr;
int length;
if (unlikely(af != AF_INET && af != AF_INET6)) {
RTE_LOG(DEBUG, IPVS, "adjust mss: unknow af, af : %d.\n",
af);
return ;
}
ptr = (unsigned char *)(tcph + 1);
length = (tcph->doff << 2) - sizeof(struct tcphdr);
while (length > 0) {
int opcode = *ptr++;
int opsize;
switch (opcode) {
case TCP_OPT_EOL:
return;
case TCP_OPT_NOP:
length--;
continue;
default:
opsize = *ptr++;
if (opsize < 2) /* "silly options" */
return;
if (opsize > length)
return; /* partial options */
if ((opcode == TCP_OPT_MSS) && (opsize == TCP_OLEN_MSS)) {
uint16_t in_mss = ntohs(*(__be16 *) ptr);
in_mss -= (af == AF_INET ? TCP_OLEN_IP4_ADDR : TCP_OLEN_IP6_ADDR);
/* set mss, 16bit */
*((uint16_t *) ptr) = htons(in_mss);
/* re-calc csum later */
return;
}
ptr += opsize - 2;
length -= opsize;
break;
}
}
}
标签:af,mss,tcp,dpvs,TCP,opsize,ptr From: https://www.cnblogs.com/WJQ2017/p/18313504