Merge pull request #65 from Minaru/default_policy_fix
Default policy fix
This commit is contained in:
commit
2e3a74b3f8
18
chain.go
18
chain.go
|
@ -73,6 +73,15 @@ const (
|
||||||
ChainTypeNAT ChainType = "nat"
|
ChainTypeNAT ChainType = "nat"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ChainPolicy defines what this chain default policy will be.
|
||||||
|
type ChainPolicy uint32
|
||||||
|
|
||||||
|
// Possible ChainPolicy values.
|
||||||
|
const (
|
||||||
|
ChainPolicyDrop ChainPolicy = iota
|
||||||
|
ChainPolicyAccept
|
||||||
|
)
|
||||||
|
|
||||||
// A Chain contains Rules. See also
|
// A Chain contains Rules. See also
|
||||||
// https://wiki.nftables.org/wiki-nftables/index.php/Configuring_chains
|
// https://wiki.nftables.org/wiki-nftables/index.php/Configuring_chains
|
||||||
type Chain struct {
|
type Chain struct {
|
||||||
|
@ -81,7 +90,7 @@ type Chain struct {
|
||||||
Hooknum ChainHook
|
Hooknum ChainHook
|
||||||
Priority ChainPriority
|
Priority ChainPriority
|
||||||
Type ChainType
|
Type ChainType
|
||||||
Policy uint32
|
Policy *ChainPolicy
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddChain adds the specified Chain. See also
|
// AddChain adds the specified Chain. See also
|
||||||
|
@ -103,9 +112,9 @@ func (cc *Conn) AddChain(c *Chain) *Chain {
|
||||||
})...)
|
})...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Policy > 0 {
|
if c.Policy != nil {
|
||||||
data = append(data, cc.marshalAttr([]netlink.Attribute{
|
data = append(data, cc.marshalAttr([]netlink.Attribute{
|
||||||
{Type: unix.NFTA_CHAIN_POLICY, Data: binaryutil.BigEndian.PutUint32(uint32(c.Policy))},
|
{Type: unix.NFTA_CHAIN_POLICY, Data: binaryutil.BigEndian.PutUint32(uint32(*c.Policy))},
|
||||||
})...)
|
})...)
|
||||||
}
|
}
|
||||||
if c.Type != "" {
|
if c.Type != "" {
|
||||||
|
@ -200,7 +209,8 @@ func chainFromMsg(msg netlink.Message) (*Chain, error) {
|
||||||
case unix.NFTA_CHAIN_TYPE:
|
case unix.NFTA_CHAIN_TYPE:
|
||||||
c.Type = ChainType(ad.String())
|
c.Type = ChainType(ad.String())
|
||||||
case unix.NFTA_CHAIN_POLICY:
|
case unix.NFTA_CHAIN_POLICY:
|
||||||
c.Policy = uint32(ad.Uint32())
|
policy := ChainPolicy(ad.Uint32())
|
||||||
|
c.Policy = &policy
|
||||||
case unix.NFTA_CHAIN_HOOK:
|
case unix.NFTA_CHAIN_HOOK:
|
||||||
ad.Do(func(b []byte) error {
|
ad.Do(func(b []byte) error {
|
||||||
c.Hooknum, c.Priority, err = hookFromMsg(b)
|
c.Hooknum, c.Priority, err = hookFromMsg(b)
|
||||||
|
|
|
@ -2327,13 +2327,14 @@ func TestSet4(t *testing.T) {
|
||||||
Name: "ipv4table",
|
Name: "ipv4table",
|
||||||
Family: nftables.TableFamilyIPv4,
|
Family: nftables.TableFamilyIPv4,
|
||||||
}
|
}
|
||||||
|
defPol := nftables.ChainPolicyAccept
|
||||||
ch := &nftables.Chain{
|
ch := &nftables.Chain{
|
||||||
Name: "ipv4chain-2",
|
Name: "ipv4chain-2",
|
||||||
Table: tbl,
|
Table: tbl,
|
||||||
Type: nftables.ChainTypeNAT,
|
Type: nftables.ChainTypeNAT,
|
||||||
Priority: nftables.ChainPriorityNATDest,
|
Priority: nftables.ChainPriorityNATDest,
|
||||||
Hooknum: nftables.ChainHookPrerouting,
|
Hooknum: nftables.ChainHookPrerouting,
|
||||||
Policy: 1, // TODO
|
Policy: &defPol,
|
||||||
}
|
}
|
||||||
set := nftables.Set{
|
set := nftables.Set{
|
||||||
Anonymous: false,
|
Anonymous: false,
|
||||||
|
|
Loading…
Reference in New Issue