Compare commits
5 Commits
c803c0e9e7
...
7a668d7c79
Author | SHA1 | Date |
---|---|---|
|
7a668d7c79 | |
|
d11ef81b6a | |
|
e2fedeb355 | |
|
a24f918d08 | |
|
3163cd89a9 |
6
go.mod
6
go.mod
|
@ -1,17 +1,17 @@
|
|||
module github.com/google/nftables
|
||||
|
||||
go 1.21
|
||||
go 1.23.0
|
||||
|
||||
require (
|
||||
github.com/google/go-cmp v0.6.0
|
||||
github.com/mdlayher/netlink v1.7.3-0.20250113171957-fbb4dce95f42
|
||||
github.com/vishvananda/netlink v1.3.0
|
||||
github.com/vishvananda/netns v0.0.4
|
||||
golang.org/x/sys v0.28.0
|
||||
golang.org/x/sys v0.31.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/mdlayher/socket v0.5.0 // indirect
|
||||
golang.org/x/net v0.33.0 // indirect
|
||||
golang.org/x/net v0.37.0 // indirect
|
||||
golang.org/x/sync v0.6.0 // indirect
|
||||
)
|
||||
|
|
8
go.sum
8
go.sum
|
@ -8,11 +8,11 @@ github.com/vishvananda/netlink v1.3.0 h1:X7l42GfcV4S6E4vHTsw48qbrV+9PVojNfIhZcwQ
|
|||
github.com/vishvananda/netlink v1.3.0/go.mod h1:i6NetklAujEcC6fK0JPjT8qSwWyO0HLn4UKG+hGqeJs=
|
||||
github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8=
|
||||
github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
|
||||
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
|
||||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
||||
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
|
||||
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
|
||||
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
|
||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
|
||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
|
|
25
rule.go
25
rule.go
|
@ -31,6 +31,7 @@ const (
|
|||
)
|
||||
|
||||
// This constant is missing at unix.NFTA_RULE_POSITION_ID.
|
||||
// TODO: Add the constant in unix and then remove it here.
|
||||
const nfta_rule_position_id = 0xa
|
||||
|
||||
type ruleOperation uint32
|
||||
|
@ -47,15 +48,6 @@ const (
|
|||
type Rule struct {
|
||||
Table *Table
|
||||
Chain *Chain
|
||||
// Position can be set to the Handle of another Rule to insert the new Rule
|
||||
// before (InsertRule) or after (AddRule) the existing rule.
|
||||
Position uint64
|
||||
// Deprecated: The feature for which this field was added never worked.
|
||||
// The field may be removed in a later version.
|
||||
Flags uint32
|
||||
// PositionID can be set to the ID of another Rule, same as Position, for when
|
||||
// the existing rule is not yet committed.
|
||||
PositionID uint32
|
||||
// Handle identifies an existing Rule. For a new Rule, this field is set
|
||||
// during the Flush() in which the rule is committed. Make sure to not access
|
||||
// this field concurrently with this Flush() to avoid data races.
|
||||
|
@ -63,7 +55,18 @@ type Rule struct {
|
|||
// ID is an identifier for a new Rule, which is assigned by
|
||||
// AddRule/InsertRule, and only valid before the rule is committed by Flush().
|
||||
// The field is set to 0 during Flush().
|
||||
ID uint32
|
||||
ID uint32
|
||||
// Position can be set to the Handle of another Rule to insert the new Rule
|
||||
// before (InsertRule) or after (AddRule) the existing rule.
|
||||
Position uint64
|
||||
// PositionID can be set to the ID of another Rule, same as Position, for when
|
||||
// the existing rule is not yet committed.
|
||||
PositionID uint32
|
||||
// The list of possible flags are specified by nftnl_rule_attr, see
|
||||
// https://git.netfilter.org/libnftnl/tree/include/libnftnl/rule.h#n21
|
||||
// Current nftables go implementation supports only
|
||||
// NFTNL_RULE_POSITION flag for setting rule at position 0
|
||||
Flags uint32
|
||||
Exprs []expr.Any
|
||||
UserData []byte
|
||||
}
|
||||
|
@ -183,7 +186,7 @@ func (cc *Conn) newRule(r *Rule, op ruleOperation) *Rule {
|
|||
flags = netlink.Request | netlink.Acknowledge | netlink.Replace
|
||||
}
|
||||
|
||||
if r.Position != 0 {
|
||||
if r.Position != 0 || (r.Flags&(1<<unix.NFTA_RULE_POSITION)) != 0 {
|
||||
msgData = append(msgData, cc.marshalAttr([]netlink.Attribute{
|
||||
{Type: unix.NFTA_RULE_POSITION, Data: binaryutil.BigEndian.PutUint64(r.Position)},
|
||||
})...)
|
||||
|
|
Loading…
Reference in New Issue