raw UDP sendto 返回 EPERM?

46 views
Skip to first unread message

依云

unread,
Jul 20, 2016, 1:06:51 AM7/20/16
to sh...@googlegroups.com
情况是这样子的:由于某原因我写了个 netfilter_queue 程序拦截 DNS 请求,并
且会在特定情况下替代 DNS 服务器返回 DNS 回应。我开了个 raw UDP socket,
发现偶尔 sendto 会返回 EPERM。已经确定目标地址正常,不是广播地址。报文内
容也没什么特殊的。UDP 校验和我填的全零。

可 sendto 为什么要返回 EPERM 呢?这种情况在几百请求每秒的服务器上才会出
现,每天大概也就几十次的样子。另有一个请求量少的机器从来没出现过。

请求的发送方都是内网机器。

--
Best regards,
lilydjwg

Linux Vim Python 我的博客:
http://lilydjwg.is-programmer.com/
--
A: Because it obfuscates the reading.
Q: Why is top posting so bad?

Derek 呆

unread,
Jul 20, 2016, 4:43:18 PM7/20/16
to Shanghai Linux User Group
有很大的機會是 iptables rules 中設了 rate limit
https://groups.google.com/forum/embed/#!topic/comp.protocols.tcp-ip/Qou9Sfgr77E

依云

unread,
Jul 23, 2016, 1:13:35 AM7/23/16
to sh...@googlegroups.com
On Wed, Jul 20, 2016 at 01:43:17PM -0700, Derek 呆 wrote:
> 有很大的機會是 iptables rules 中設了 rate limit
> https://groups.google.com/forum/embed/#!topic/comp.protocols.tcp-ip/Qou9Sfgr77E

谢谢,终于找到和我遇到同样问题的人了!可是还是没明白原因啊。我的
iptables 除了 netfilter_queue 用的那条之外是空的。没试过关掉 iptables。

看起来是发包太快,遇到了某个地方的瓶颈或者限制,所以就出错了。难道是网卡
太忙了?

依云

unread,
Jul 23, 2016, 1:35:13 AM7/23/16
to sh...@googlegroups.com
On Sat, Jul 23, 2016 at 01:12:58PM +0800, 依云 wrote:
> On Wed, Jul 20, 2016 at 01:43:17PM -0700, Derek 呆 wrote:
> > 有很大的機會是 iptables rules 中設了 rate limit
> > https://groups.google.com/forum/embed/#!topic/comp.protocols.tcp-ip/Qou9Sfgr77E
>
> 谢谢,终于找到和我遇到同样问题的人了!可是还是没明白原因啊。我的
> iptables 除了 netfilter_queue 用的那条之外是空的。没试过关掉 iptables。
>
> 看起来是发包太快,遇到了某个地方的瓶颈或者限制,所以就出错了。难道是网卡
> 太忙了?

解决了!我加了条 iptables 规则:

iptables -t raw -I OUTPUT -p udp -m udp --sport 53 -j NOTRACK

然后 EPERM 就没了,发包耗时也少了一半,只需要 10µs 了!
Reply all
Reply to author
Forward
0 new messages