Skip to content

[Discovery] How is dnat actually expressed? #162

@thediveo

Description

@thediveo

After starting a test container and exposing a port of it on the host, I'm trying to find the corresponding port forwarding expression(s) in a table/chain/rule dump ... or rather, not finding it. What am I missing either in terms of not properly understanding the low-level nft netlink expressions or maybe missing some decoding in the nftables module?

sudo nft list table nat turns up the following rule in the "DOCKER" chain:

table ip nat {
  chain DOCKER {
    iifname != "docker0" meta l4proto tcp tcp dport 49153 counter packets 0 bytes 0 dnat to 172.17.0.2:12345
  }
}

Now I would have expected to find kind of a dnat expression. However somehow the dnat eludes my eyes, because the while rule pos 35 handles iifname != "docker0" I don't see any signs of either the original port number 49153 nor the rewritten port 12345; additionally, I don't recognize an 172.17.0.2 byte signature, that is 0xac, 0x11, 0x0, 0x2. Am I even on the right track here?

  CHAIN "DOCKER" TYPE "" HOOK "PREROUTING"
    RULE POS 0
      EXPR &expr.Meta{Key:0x6, SourceRegister:false, Register:0x1}
      EXPR &expr.Cmp{Op:0x0, Register:0x1, Data:[]uint8{0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x30, 0x0}}
      EXPR &expr.Counter{Bytes:0x0, Packets:0x0}
      EXPR &expr.Verdict{Kind:-5, Chain:""}
    RULE POS 35
      EXPR &expr.Meta{Key:0x6, SourceRegister:false, Register:0x1}
      EXPR &expr.Cmp{Op:0x1, Register:0x1, Data:[]uint8{0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x30, 0x0}}
      EXPR &expr.Meta{Key:0x10, SourceRegister:false, Register:0x1}
      EXPR &expr.Cmp{Op:0x0, Register:0x1, Data:[]uint8{0x6}}
      EXPR &expr.Counter{Bytes:0x0, Packets:0x0}
    RULE POS 39
      EXPR &expr.Meta{Key:0x6, SourceRegister:false, Register:0x1}
      EXPR &expr.Cmp{Op:0x0, Register:0x1, Data:[]uint8{0x62, 0x72, 0x2d, 0x32, 0x36, 0x37, 0x36, 0x32, 0x39, 0x39, 0x66, 0x31, 0x36, 0x39, 0x38, 0x0}}
      EXPR &expr.Counter{Bytes:0x0, Packets:0x0}
      EXPR &expr.Verdict{Kind:-5, Chain:""}
    RULE POS 40
      EXPR &expr.Meta{Key:0x6, SourceRegister:false, Register:0x1}
      EXPR &expr.Cmp{Op:0x0, Register:0x1, Data:[]uint8{0x62, 0x72, 0x2d, 0x39, 0x38, 0x66, 0x65, 0x31, 0x32, 0x39, 0x66, 0x34, 0x30, 0x64, 0x37, 0x0}}
      EXPR &expr.Counter{Bytes:0x0, Packets:0x0}
      EXPR &expr.Verdict{Kind:-5, Chain:""}
    RULE POS 41
      EXPR &expr.Meta{Key:0x6, SourceRegister:false, Register:0x1}
      EXPR &expr.Cmp{Op:0x0, Register:0x1, Data:[]uint8{0x62, 0x72, 0x2d, 0x61, 0x31, 0x33, 0x34, 0x61, 0x61, 0x65, 0x39, 0x62, 0x35, 0x63, 0x33, 0x0}}
      EXPR &expr.Counter{Bytes:0x0, Packets:0x0}
      EXPR &expr.Verdict{Kind:-5, Chain:""}
    RULE POS 42
      EXPR &expr.Meta{Key:0x6, SourceRegister:false, Register:0x1}
      EXPR &expr.Cmp{Op:0x0, Register:0x1, Data:[]uint8{0x62, 0x72, 0x2d, 0x62, 0x66, 0x36, 0x63, 0x36, 0x63, 0x39, 0x66, 0x66, 0x38, 0x66, 0x62, 0x0}}
      EXPR &expr.Counter{Bytes:0x0, Packets:0x0}
      EXPR &expr.Verdict{Kind:-5, Chain:""}
    RULE POS 44
      EXPR &expr.Meta{Key:0x6, SourceRegister:false, Register:0x1}
      EXPR &expr.Cmp{Op:0x0, Register:0x1, Data:[]uint8{0x62, 0x72, 0x2d, 0x64, 0x64, 0x63, 0x64, 0x64, 0x32, 0x32, 0x39, 0x61, 0x66, 0x37, 0x34, 0x0}}
      EXPR &expr.Counter{Bytes:0x0, Packets:0x0}
      EXPR &expr.Verdict{Kind:-5, Chain:""}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions