Linux发不出分片包的问题分析

今日有个网络攻击模拟需求,要打分片的ip包,程序写好了,在开发机上验证也没问题,然后部署到沙盒环境之后不行,就是发不出来数据包,而不分片的数据包能够正常发送,定位过程如下

1.对比了两台机器/proc/sys/net/ipv4下的ip相关参数的值,都一样,忽略了因为ipfrag相关设置带来的影响。

2. 查看dmesg、/var/log/messages,没有什么异常的日志。

3. 查看netstat -s

Ip:
226610920001 total packets received
957 with invalid addresses
0 forwarded
0 incoming packets discarded
226610067704 incoming packets delivered
588767879431 requests sent out
20609816 outgoing packets dropped
43646 dropped because of missing route
42 fragments dropped after timeout
353567514 reassemblies required
42 packet reassembles failed

其中飘红的这一样,按照50w/s的速率递增,大致知道了是内核丢掉了数据包,猜测的原因是:内核设定了重组数据包,等待发送来的后续数据包,一直没等到。

4. 搞网卡的参数

ethtool -K xgbe0 tso off
ethtool -K xgbe0 gso off
ethtool -K xgbe0 gro off
ethtool -K xgbe0 lrf off

5. 之后数据包能发出来10s不到,数据包又发不出来了。

6. 考虑是内核相关的东西,查看各内核模块发现有nf_defrag_ipv4模块,手工去掉所有相关模块

rmmod  iptable_nat  nf_nat
rmmod nf_conntrack_ipv4 nf_conntrack  nf_defrag_ipv4
rmmod iptable_filter  ip_queue nfnetlink iptable_mangle ip_tables x_tables

7.搞定

总结:解决问题的过程中并没有完全搞清楚各种现象的根本原因以及牵涉到知识的根本,需要继续补充

原文地址:https://www.cnblogs.com/lovemyspring/p/5664509.html