【问题标题】:Some questions about "-set-xmark" in iptables关于 iptables 中“-set-xmark”的一些问题
【发布时间】:2014-03-27 00:56:34
【问题描述】:

我有一个规则如下:

-A PREROUTING -d 10.228.20.15/32 -p tcp -m tcp --dport 80--tcp-flags FIN,SYN,RST,ACK SYN -j MARK --set-xmark 0x70/0xffffffff

man doc解释--set-xmark如下:

将掩码和 XOR 值给出的位清零到 ctmark 中。

英语不是我的母语。任何人都可以帮助解释将设置为 ctmark 的值吗? 归零是什么意思?举个例子不胜感激。

【问题讨论】:

    标签: linux iptables netfilter


    【解决方案1】:

    所以语法是--set-xmark value/mask。得到的操作是:

    ctmark = (ctmark AND NOT mask) XOR value
    

    零对应于(ctmark AND NOT mask):如果mask 中的某个位被设置,那么ctmark 中的对应位将为零(在异或之前)。

    手册页还指出:

    --and-mark bits
        Binary AND the  ctmark  with  bits.  (Mnemonic  for  --set-xmark
        0/invbits, where invbits is the binary negation of bits.)
    
    --or-mark bits
        Binary  OR  the  ctmark  with  bits.  (Mnemonic  for --set-xmark
        bits/bits.)
    
    --xor-mark bits
        Binary XOR the  ctmark  with  bits.  (Mnemonic  for  --set-xmark
        bits/0.)
    

    您可以根据这些定义验证上述操作:

    --and-mark bits == --set-xmark 0/invbits
         ctmark AND bits = (ctmark AND NOT invbits) XOR 0
         -> bits = NOT invbits
         -> anything XOR 0 = anything
         so: ctmark AND bits = ctmark AND NOT NOT bits = ctmark AND bits
    
    --or-mark bits == --set-mark bits/bits
         ctmark OR bits = (ctmark AND NOT bits) XOR bits
         -> should be obvious based on boolean logic
    
    --xor-mark bits == -set-mark bits/0
         ctmark XOR bits = (ctmark AND NOT 0) XOR bits
         -> anything AND NOT 0 = anything
    

    【讨论】:

    • 感谢您的解释。对我理解很有帮助。
    猜你喜欢
    • 2018-08-04
    • 1970-01-01
    • 1970-01-01
    • 2018-05-24
    • 2013-07-07
    • 2013-05-10
    • 2012-03-18
    • 2023-03-09
    • 2021-07-01
    相关资源
    最近更新 更多