TC-CT(8)

๐Ÿ“ฆ
version 7.3.0 ยท 2 versions
  • 7.3.0 ยท alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 5.15.0 ยท ubuntu jammy
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

๐Ÿ’– ct action in tc(8) ๐Ÿ’–

okay so this is the manual page for the ct action in tc(8), and it is iconic ๐Ÿ’… ct stands for tc connection tracking action, and it's how you send packets over to netfilter's conntrack module. Let's get into it ๐Ÿซถ

โœจ NAME โœจ

ct - tc connection tracking action

๐ŸŽ€ SYNOPSIS ๐ŸŽ€

tc ... action ct commit [ force ] [ zone ZONE ] [ mark MASKED_MARK ] [
        label MASKED_LABEL ] [ nat NAT_SPEC ]

tc ... action ct [ nat ] [ zone ZONE ]

tc ... action ct clear

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

okay so the ct action is a tc action that sends packets off and lets you interact with the netfilter conntrack module. It's giving main character energy ๐Ÿ‘‘

It can do three things, as shown in the synopsis, in this order:

  • Commit: send the packet to conntrack and commit the connection, while setting a 32bit mark, a 128bit label, and src/dst nat.
  • Lookup: send the packet to conntrack, which marks the packet with the connection's state and its metadata (mark/label), and runs the nat you configured earlier.
  • Clear: wipe the packet's previous connection tracking state. ๐Ÿงน

๐ŸŒธ OPTIONS ๐ŸŒธ

  • zone ZONE โ€” pick the conntrack zone number you want to send the packet to conntrack in. ๐Ÿ“
  • mark MASKED_MARK โ€” set a masked 32bit mark for the connection. This only works with commit. ๐Ÿ’œ
  • label MASKED_LABEL โ€” set a masked 128bit label for the connection. This only works with commit. ๐Ÿท๏ธ
  • nat NAT_SPEC โ€” configure the src/dst nat range for the connection. This only works with commit. The full form is:
NAT_SPEC := {src|dst} addr addr1[-addr2] [port port1[-port2]]
  • src/dst โ€” pick whether you're doing src nat or dst nat ๐Ÿ”ฅ
  • addr1/addr2 โ€” IPv4/IPv6 addresses
  • port1/port2 โ€” port numbers
  • nat โ€” restore any nat you configured before. ๐Ÿ”
  • clear โ€” remove any conntrack state and metadata (mark/label) from the packet. This has to be the only option you specify, no sharing ๐Ÿ™…โ€โ™€๏ธ
  • force โ€” forces the conntrack direction for a connection that was already committed, so the current direction becomes the original direction. Only works with commit. ๐ŸŒˆ

๐Ÿงš EXAMPLES ๐Ÿงš

this one shows a natted firewall in conntrack zone 2, plus conntrack mark usage. obsessed!! ๐Ÿ˜ญ

#Add ingress qdisc on eth0 and eth1 interfaces
$ tc qdisc add dev eth0 ingress
$ tc qdisc add dev eth1 ingress

#Setup filters on eth0, allowing opening new connections in zone 2, and doing src nat + mark for each new connection
$ tc filter add dev eth0 ingress prio 1 chain 0 proto ip flower ip_proto tcp ct_state -trk \
action ct zone 2 pipe action goto chain 2
$ tc filter add dev eth0 ingress prio 1 chain 2 proto ip flower ct_state +trk+new \
action ct zone 2 commit mark 0xbb nat src addr 5.5.5.7 pipe action mirred egress redirect dev eth1
$ tc filter add dev eth0 ingress prio 1 chain 2 proto ip flower ct_zone 2 ct_mark 0xbb ct_state +trk+est \
action ct nat pipe action mirred egress redirect dev eth1

#Setup filters on eth1, allowing only established connections of zone 2 through, and reverse nat (dst nat in this case)
$ tc filter add dev eth1 ingress prio 1 chain 0 proto ip flower ip_proto tcp ct_state -trk \
action ct zone 2 pipe action goto chain 1
$ tc filter add dev eth1 ingress prio 1 chain 1 proto ip flower ct_zone 2 ct_mark 0xbb ct_state +trk+est \
action ct nat pipe action mirred egress redirect dev eth0

๐Ÿ”— SEE ALSO ๐Ÿ”—

tc(8), tc-flower(8) tc-mirred(8)

๐Ÿ’… AUTHORS ๐Ÿ’…

  • Paul Blakey โ€” paulb@mellanox.com
  • Marcelo Ricardo Leitner โ€” marcelo.leitner@gmail.com
  • Yossi Kuperman โ€” yossiku@mellanox.com

bestie, you're officially a tc connection tracking queen now ๐Ÿ‘‘๐Ÿซถ This page came from iproute2, dated 14 May 2020, and it's filed under ct action in tc(8) ๐Ÿฆ‹โœจ ily, go slay the netfilter ๐Ÿ’–

๐Ÿ“ฆ where this page comes from