type filter hook prerouting priority mangle + 10; policy drop;
meta nfproto ipv4 udp sport . udp dport { 68 . 67, 67 . 68 } accept comment "DHCPv4 client/server"
# Reverse path forwarding filter. Check that a route exists back to the source address on the interface which received the packet. If the packet came from the wrong interface, then the packet is likely spoofed.
fib saddr . mark . iif check exists accept
jump rpfilter-allow
meta pkttype host log prefix "Failed rpfilter: " level info
}
chain rpfilter-allow {
# Allow packets on internal interfaces from pods
meta iifname @internal-iface ip saddr @pod-cidr-ipv4 accept
meta iifname @internal-iface ip6 saddr @pod-cidr-ipv6 accept
}
chain input {
type filter hook input priority filter; policy drop;
iifname "lo" accept comment "trusted interfaces"
# Drop invalid connections, accept packets for established or related connections and send packets for new or untracked connections to the input-allow chain
ct state vmap { invalid : drop, established : accept, related : accept, new : jump input-allow, untracked : jump input-allow }
# If the packet is a new connection and reaches this point, then we are going to reject it. So log that rejection.
tcp flags & (fin | syn | rst | ack) == syn log prefix "refused connection: " level info
# Log rejected packets destined for this machine (as opposed to packets being routed or broadcast packets)
meta pkttype host log prefix "refused packet: " level info
# When rejecting packets, send a TCP Reset (RST) instead of simply dropping the packet.
meta l4proto tcp reject with tcp reset
# Reject any packets that make it here.
reject
}
chain input-allow {
# Allow pings.
icmp type echo-request accept comment "allow ping"
icmpv6 type != { nd-redirect, 139 } accept comment "Accept all ICMPv6 messages except redirects and node information queries (type 139). See RFC 4890, section 4.4."
type filter hook forward priority filter; policy drop;
# Drop invalid connections, accept packets for established or related connections and send packets for new or untracked connections to the forward-allow chain
ct state vmap { invalid : drop, established : accept, related : accept, new : jump forward-allow, untracked : jump forward-allow }
log prefix "blocked forwarding packet: " level info
}
chain forward-allow {
icmpv6 type != { router-renumbering, 139 } accept comment "Accept all ICMPv6 messages except renumbering and node information queries (type 139). See RFC 4890, section 4.3."
# When connection tracking (ct) shows the status as destination nat (dnat) then accept the packet.
ct status dnat accept comment "allow port forward"
# Allow packets from pods
ip saddr @pod-cidr-ipv4 accept
ip6 saddr @pod-cidr-ipv6 accept
# Allow node-to-pod
ip saddr @node-cidr-ipv4 ip daddr @pod-cidr-ipv4 accept