Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/tcpip/network/ipv4/ipv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ func (e *endpoint) writePacketPostRouting(r *stack.Route, pkt *stack.PacketBuffe
}

if nft := stk.NFTables(); nft != nil && stk.IsNFTablesConfigured() {
ipCheck := nft.CheckOutput(pkt, stack.IP)
inetCheck := nft.CheckOutput(pkt, stack.Inet)
ipCheck := nft.CheckPostrouting(pkt, stack.IP)
inetCheck := nft.CheckPostrouting(pkt, stack.Inet)
if !ipCheck || !inetCheck {
// nftables is telling us to drop the packet.
return nil
Expand Down
11 changes: 9 additions & 2 deletions pkg/tcpip/nftables/nft_metaload.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,15 @@ func (op metaLoad) evaluate(regs *registerSet, pkt *stack.PacketBuffer, rule *Ru

// Netfilter (Family) Protocol (8-bit, single byte).
case linux.NFT_META_NFPROTO:
family := rule.chain.GetAddressFamily()
target = []byte{AfProtocol(family)}
switch pkt.NetworkProtocolNumber {
// Cannot rely on chain's address family as it can be inet, and inet can mean either IPv4 or IPv6.
case header.IPv4ProtocolNumber:
target = []byte{linux.NFPROTO_IPV4}
case header.IPv6ProtocolNumber:
target = []byte{linux.NFPROTO_IPV6}
default:
target = []byte{AfProtocol(rule.chain.GetAddressFamily())}
}

// L4 Transport Layer Protocol (8-bit, single byte).
case linux.NFT_META_L4PROTO:
Expand Down
2 changes: 1 addition & 1 deletion pkg/tcpip/nftables/nftables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2854,7 +2854,7 @@ func TestEvaluateMetaLoad(t *testing.T) {
pkt: pkt,
op1: mustCreateMetaLoad(t, linux.NFT_META_NFPROTO, linux.NFT_REG_4),
op2: mustCreateComparison(t, linux.NFT_REG_4, linux.NFT_CMP_EQ,
[]byte{AfProtocol(stack.Inet), 0, 0, 0}),
[]byte{linux.NFPROTO_IPV6, 0, 0, 0}),
},
{ // cmd: add rule ip6 tab ch meta l4proto 0x6
tname: "meta load l4proto test",
Expand Down
Loading