Compare commits

..

1 Commits

Author SHA1 Message Date
corpix 64d0cc77d7
Merge dd13cb1d03 into 68e1406c13 2025-04-29 16:13:53 -04:00
2 changed files with 2 additions and 40 deletions

View File

@ -110,12 +110,6 @@ const (
CtStateUDPREPLIED
)
const (
// https://git.netfilter.org/libnftnl/tree/src/expr/ct.c?id=116e95aa7b6358c917de8c69f6f173874030b46b#n31
CtDirOriginal = iota
CtDirReply
)
// https://git.netfilter.org/libnftnl/tree/src/obj/ct_timeout.c?id=116e95aa7b6358c917de8c69f6f173874030b46b#n57
var CtStateUDPTimeoutDefaults CtStatePolicyTimeout = map[uint16]uint32{
CtStateUDPUNREPLIED: 30,
@ -128,7 +122,6 @@ type Ct struct {
SourceRegister bool
Key CtKey
Direction uint32
OptDirection bool
}
func (e *Ct) marshal(fam byte) ([]byte, error) {
@ -172,16 +165,10 @@ func (e *Ct) marshalData(fam byte) ([]byte, error) {
exprData = append(exprData, regData...)
switch e.Key {
case CtKeyPKTS, CtKeyBYTES, CtKeyAVGPKT, CtKeyL3PROTOCOL, CtKeyPROTOCOL:
if !e.OptDirection {
break
}
fallthrough
case CtKeySRC, CtKeyDST, CtKeyPROTOSRC, CtKeyPROTODST, CtKeySRCIP, CtKeyDSTIP, CtKeySRCIP6, CtKeyDSTIP6:
regData, err = netlink.MarshalAttributes(
[]netlink.Attribute{
{Type: unix.NFTA_CT_DIRECTION, Data: []byte{uint8(e.Direction)}},
{Type: unix.NFTA_CT_DIRECTION, Data: binaryutil.BigEndian.PutUint32(e.Direction)},
},
)
if err != nil {
@ -199,8 +186,6 @@ func (e *Ct) unmarshal(fam byte, data []byte) error {
return err
}
ad.ByteOrder = binary.BigEndian
var hasDirection bool
for ad.Next() {
switch ad.Type() {
case unix.NFTA_CT_KEY:
@ -208,19 +193,12 @@ func (e *Ct) unmarshal(fam byte, data []byte) error {
case unix.NFTA_CT_DREG:
e.Register = ad.Uint32()
case unix.NFTA_CT_DIRECTION:
e.Direction = uint32(ad.Uint8())
hasDirection = true
e.Direction = ad.Uint32()
case unix.NFTA_CT_SREG:
e.SourceRegister = true
e.Register = ad.Uint32()
}
}
switch e.Key {
case CtKeyPKTS, CtKeyBYTES, CtKeyAVGPKT, CtKeyL3PROTOCOL, CtKeyPROTOCOL:
e.OptDirection = hasDirection
}
return ad.Err()
}

View File

@ -78,22 +78,6 @@ func TestCt(t *testing.T) {
Direction: 1,
},
},
{
name: "Unmarshal Ct packets direction original case",
ct: Ct{
Register: 1,
Key: CtKeyPKTS,
Direction: CtDirOriginal,
OptDirection: true,
},
},
{
name: "Unmarshal Ct bytes without direction case",
ct: Ct{
Register: 1,
Key: CtKeyBYTES,
},
},
}
for _, tt := range tests {