iptables和条件语句。 可能吗?

我尝试了search,但我没有成功,在这种情况下,我很抱歉,我将欣赏redirect。

我想到了这个问题:一个MAC地址为M的计算机通过openwrt路由器(或基于linux的系统)发送数据包,我想试试这个可能性,让M从数据包中立即发出一个包之后必须放弃,然后再接受,然后下降等。

所以如果带有mac的计算机发送20个数据包,只有10个会通过,另外10个会被丢弃。 以一种详细的方式,想要的结果是:接受,放弃,接受,放弃,接受,放弃,接受,放弃等等…

伪代码解释

condition=ACCEPT for each packet { if ( packet_is_sent_from_adapter_with_mac_M ) { if (condition == ACCEPT) { accept_packet condition=DROP } else { drop_packet condition=ACCEPT } } } 

可能吗? 谷歌search后有点似乎iptables不支持任何条件语句或脚本。

如果可能的话,那么一般条件“Y连续接受后连续丢弃X个数据包”呢?

另外1 :一般的问题是“stream量控制”在iptables中是不允许的? 或更好,因为有条件的决定是基于一个状态(伪代码中的条件 ),我们如何在iptables中保存与某个条件有关的状态并做一些检查这个状态?

另外2 :在注释中,build议使用额外的工具(tc)来实现stream量控制(我的意思是说,如果语句,循环等),随意提出组合(也许有一些解释)。 谢谢!

为了您的需要,iptables statistic扩展可能工作。 将模式设置为nthevery2 ,并将其附加到您的DROP规则。 所以也许是这样的

 iptables -A INPUT -m statistic --mode nth --every 2 -m mac --mac-source xx:xx:xx:xx:xx -j DROP 

应该pipe用。

关于统计模块的iptables-extensions手册页说:

 statistic This module matches packets based on some statistic condition. It supports two distinct modes settable with the --mode option. Supported options: --mode mode Set the matching mode of the matching rule, supported modes are random and nth. [!] --probability p Set the probability for a packet to be randomly matched. It only works with the random mode. p must be within 0.0 and 1.0. The supported granularity is in 1/2147483648th increments. [!] --every n Match one packet every nth packet. It works only with the nth mode (see also the --packet option). --packet p Set the initial counter value (0 <= p <= n-1, default 0) for the nth mode.