Compare commits
3 Commits
b3a72503fb
...
7177d374a7
Author | SHA1 | Date |
---|---|---|
|
7177d374a7 | |
|
c803c0e9e7 | |
|
586337f5ce |
23
rule.go
23
rule.go
|
@ -31,7 +31,6 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// This constant is missing at unix.NFTA_RULE_POSITION_ID.
|
// 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
|
const nfta_rule_position_id = 0xa
|
||||||
|
|
||||||
type ruleOperation uint32
|
type ruleOperation uint32
|
||||||
|
@ -48,6 +47,15 @@ const (
|
||||||
type Rule struct {
|
type Rule struct {
|
||||||
Table *Table
|
Table *Table
|
||||||
Chain *Chain
|
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
|
// 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
|
// during the Flush() in which the rule is committed. Make sure to not access
|
||||||
// this field concurrently with this Flush() to avoid data races.
|
// this field concurrently with this Flush() to avoid data races.
|
||||||
|
@ -56,17 +64,6 @@ type Rule struct {
|
||||||
// AddRule/InsertRule, and only valid before the rule is committed by Flush().
|
// AddRule/InsertRule, and only valid before the rule is committed by Flush().
|
||||||
// The field is set to 0 during 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
|
Exprs []expr.Any
|
||||||
UserData []byte
|
UserData []byte
|
||||||
}
|
}
|
||||||
|
@ -186,7 +183,7 @@ func (cc *Conn) newRule(r *Rule, op ruleOperation) *Rule {
|
||||||
flags = netlink.Request | netlink.Acknowledge | netlink.Replace
|
flags = netlink.Request | netlink.Acknowledge | netlink.Replace
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Position != 0 || (r.Flags&(1<<unix.NFTA_RULE_POSITION)) != 0 {
|
if r.Position != 0 {
|
||||||
msgData = append(msgData, cc.marshalAttr([]netlink.Attribute{
|
msgData = append(msgData, cc.marshalAttr([]netlink.Attribute{
|
||||||
{Type: unix.NFTA_RULE_POSITION, Data: binaryutil.BigEndian.PutUint64(r.Position)},
|
{Type: unix.NFTA_RULE_POSITION, Data: binaryutil.BigEndian.PutUint64(r.Position)},
|
||||||
})...)
|
})...)
|
||||||
|
|
Loading…
Reference in New Issue