Skip to content

Nftables New Chain implementation #11889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2025
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
1 change: 1 addition & 0 deletions pkg/abi/linux/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ go_library(
"msgqueue.go",
"netdevice.go",
"netfilter.go",
"netfilter_arp.go",
"netfilter_bridge.go",
"netfilter_ipv4.go",
"netfilter_ipv6.go",
Expand Down
7 changes: 7 additions & 0 deletions pkg/abi/linux/netfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ const (
NF_INET_LOCAL_OUT = 3
NF_INET_POST_ROUTING = 4
NF_INET_NUMHOOKS = 5
NF_INET_INGRESS = NF_INET_NUMHOOKS
)

const (
NF_NETDEV_INGRESS = iota
NF_NETDEV_EGRESS
NF_NETDEV_NUMHOOKS
)

// Protocol families (address families). These correspond to values in
Expand Down
24 changes: 24 additions & 0 deletions pkg/abi/linux/netfilter_arp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2025 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package linux

// These constants show the hooks ARP packets can be evaluated at.
// From include/uapi/linux/netfilter_arp.h.
const (
NF_ARP_IN = iota
NF_ARP_OUT
NF_ARP_FORWARD
NF_ARP_NUMHOOKS
)
11 changes: 11 additions & 0 deletions pkg/abi/linux/netfilter_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ package linux

import "math"

// Netfilter Bridge Standard Hook Points, from uapi/linux/netfilter_bridge.h.
const (
NF_BR_PRE_ROUTING = iota
NF_BR_LOCAL_IN
NF_BR_FORWARD
NF_BR_LOCAL_OUT
NF_BR_POST_ROUTING
NF_BR_BROUTING
NF_BR_NUMHOOKS
)

// Netfilter Bridge Standard Hook Priorities, from
// uapi/linux/netfilter_bridge.h.
const (
Expand Down
43 changes: 43 additions & 0 deletions pkg/abi/linux/nf_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package linux

// This file contains constants required to support nf_tables.

const NFT_MAX_HOOKS = NF_INET_NUMHOOKS + 1

// Name length constants for nf_table structures. These correspond to values in
// include/uapi/linux/netfilter/nf_tables.h.
const (
Expand Down Expand Up @@ -136,6 +138,18 @@ const (
NFT_MSG_MAX
)

// NfTableHookAttributes represents the netfilter hook attributes.
// These correspond to values in include/uapi/linux/netfilter/nf_tables.h.
const (
NFTA_HOOK_UNSPEC uint16 = iota
NFTA_HOOK_HOOKNUM
NFTA_HOOK_PRIORITY
NFTA_HOOK_DEV
NFTA_HOOK_DEVS
__NFTA_HOOK_MAX
NFTA_HOOK_MAX = __NFTA_HOOK_MAX - 1
)

// NfTableFlags represents table flags that can be set for a table, namely dormant.
// These correspond to values in include/uapi/linux/netfilter/nf_tables.h.
const (
Expand All @@ -162,6 +176,35 @@ const (
// NFTA_TABLE_MAX is the maximum netfilter table attribute.
const NFTA_TABLE_MAX = __NFTA_TABLE_MAX - 1

// NfTableChainFlags represents chain flags that can be set for a chain.
// These correspond to values in include/uapi/linux/netfilter/nf_tables.h.
const (
NFT_CHAIN_BASE uint32 = (1 << 0)
NFT_CHAIN_HW_OFFLOAD = (1 << 1)
NFT_CHAIN_BINDING = (1 << 2)
NFT_CHAIN_FLAGS = (NFT_CHAIN_BASE | NFT_CHAIN_HW_OFFLOAD | NFT_CHAIN_BINDING)
)

// NfTableChainAttributes represents the netfilter chain attributes.
// These correspond to values in include/uapi/linux/netfilter/nf_tables.h.
const (
NFTA_CHAIN_UNSPEC uint16 = iota
NFTA_CHAIN_TABLE
NFTA_CHAIN_HANDLE
NFTA_CHAIN_NAME
NFTA_CHAIN_HOOK
NFTA_CHAIN_POLICY
NFTA_CHAIN_USE
NFTA_CHAIN_TYPE
NFTA_CHAIN_COUNTERS
NFTA_CHAIN_PAD
NFTA_CHAIN_FLAGS
NFTA_CHAIN_ID
NFTA_CHAIN_USERDATA
__NFTA_CHAIN_MAX
NFTA_CHAIN_MAX = __NFTA_CHAIN_MAX - 1
)

// Nf table relational operators.
// Used by the nft comparison operation to compare values in registers.
// These correspond to enum values in include/uapi/linux/netfilter/nf_tables.h.
Expand Down
1 change: 1 addition & 0 deletions pkg/sentry/socket/netlink/netfilter/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
visibility = ["//pkg/sentry:internal"],
deps = [
"//pkg/abi/linux",
"//pkg/atomicbitops",
"//pkg/context",
"//pkg/log",
"//pkg/marshal/primitive",
Expand Down
Loading
Loading