-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtypepolicy.go
56 lines (47 loc) · 1.19 KB
/
typepolicy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package ipset
import (
"github.com/ti-mo/netfilter"
)
type TypePolicy struct {
BasePolicy
TypeName *NullStringBox
Family *UInt8Box
}
func newTypePolicy(name string, family netfilter.ProtoFamily) *TypePolicy {
return &TypePolicy{
BasePolicy: newBasePolicy(),
TypeName: NewNullStringBox(name),
Family: NewUInt8Box(uint8(family)),
}
}
func (p TypePolicy) marshalAttributes() Attributes {
attrs := p.BasePolicy.marshalAttributes()
attrs.append(AttrTypeName, p.TypeName)
attrs.append(AttrFamily, p.Family)
return attrs
}
func (p *TypePolicy) unmarshalAttribute(nfa netfilter.Attribute) {
switch at := AttributeType(nfa.Type); at {
case AttrTypeName:
p.TypeName = unmarshalNullStringBox(nfa)
case AttrFamily:
p.Family = unmarshalUInt8Box(nfa)
default:
p.BasePolicy.unmarshalAttribute(nfa)
}
}
type TypeResponsePolicy struct {
TypePolicy
Revision *UInt8Box
RevisionMin *UInt8Box
}
func (p *TypeResponsePolicy) unmarshalAttribute(nfa netfilter.Attribute) {
switch at := AttributeType(nfa.Type); at {
case AttrRevision:
p.Revision = unmarshalUInt8Box(nfa)
case AttrRevisionMin:
p.RevisionMin = unmarshalUInt8Box(nfa)
default:
p.TypePolicy.unmarshalAttribute(nfa)
}
}