forked from dsheets/go-ipset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
headerpolicy.go
43 lines (37 loc) · 1017 Bytes
/
headerpolicy.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
package ipset
import (
"github.com/ti-mo/netfilter"
)
type HeaderPolicy struct {
NamePolicy
TypeName *NullStringBox
Revision *UInt8Box
Family *UInt8Box
}
func newHeaderPolicy(p NamePolicy, typeName string, revision uint8, family netfilter.ProtoFamily) HeaderPolicy {
return HeaderPolicy{
NamePolicy: p,
TypeName: NewNullStringBox(typeName),
Revision: NewUInt8Box(revision),
Family: NewUInt8Box(uint8(family)),
}
}
func (p HeaderPolicy) marshalAttributes() Attributes {
attrs := p.NamePolicy.marshalAttributes()
attrs.append(AttrTypeName, p.TypeName)
attrs.append(AttrRevision, p.Revision)
attrs.append(AttrFamily, p.Family)
return attrs
}
func (p *HeaderPolicy) unmarshalAttribute(nfa netfilter.Attribute) {
switch at := AttributeType(nfa.Type); at {
case AttrTypeName:
p.TypeName = unmarshalNullStringBox(nfa)
case AttrRevision:
p.Revision = unmarshalUInt8Box(nfa)
case AttrFamily:
p.Family = unmarshalUInt8Box(nfa)
default:
p.NamePolicy.unmarshalAttribute(nfa)
}
}