-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathheader.go
104 lines (86 loc) · 3.03 KB
/
header.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) 2017 Pani Networks
// All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package ipset
import "fmt"
// Header is a representation of ipset Set header. Header of a set indicates
// which what additional fields could be used in members of the set and
// how much resources the set is using.
//
// Ipset configuration consists of collection of Sets, every Set has
// a Type, a Header and a collection of Members.
type Header struct {
Family string `xml:" family,omitempty" json:"family,omitempty"`
Range string `xml:" range,omitempty" json:"range,omitempty"`
Hashsize int `xml:" hashsize,omitempty" json:"hashsize,omitempty"`
Maxelem int `xml:" maxelem,omitempty" json:"maxelem,omitempty"`
Memsize int `xml:" memsize,omitempty" json:"memsize,omitempty"`
References int `xml:" references,omitempty" json:"references,omitempty"`
Timeout int `xml:" timeout,omitempty" json:"timeout,omitempty"`
Netmask int `xml:" netmask,omitempty" json:"netmask,omitempty"`
Size int `xml:" size,omitempty" json:"size,omitempty"`
Counters *string `xml:" counters,omitempty" json:"counters,omitempty"`
Comment *string `xml:" comment,omitempty" json:"comment,omitempty"`
SKBInfo *string `xml:" skbinfo,omitempty" json:"skbinfo,omitempty"`
Forceadd *string `xml:" forceadd,omitempty" json:"forceadd,omitempty"`
}
// render is a helper for Set.Render() that produces string representation
// of a header. Since Header isn't affected by rendering format this function
// doesn't take any arguments.
func (h *Header) render() string {
var result string
if h == nil {
return result
}
if h.Family != "" {
result += fmt.Sprintf(" family %s", h.Family)
}
if h.Range != "" {
result += fmt.Sprintf(" range %s", h.Range)
}
if h.Hashsize != 0 {
result += fmt.Sprintf(" hashsize %d", h.Hashsize)
}
if h.Maxelem != 0 {
result += fmt.Sprintf(" maxelem %d", h.Maxelem)
}
if h.References != 0 {
result += fmt.Sprintf(" references %d", h.References)
}
if h.Timeout != 0 {
if h.Timeout < 0 {
h.Timeout = 0
}
result += fmt.Sprintf(" timeout %d", h.Timeout)
}
if h.Netmask != 0 {
result += fmt.Sprintf(" netmask %d", h.Netmask)
}
if h.Size != 0 {
result += fmt.Sprintf(" size %d", h.Size)
}
if h.Counters != nil {
result += fmt.Sprintf(" counters")
}
if h.Comment != nil {
result += fmt.Sprintf(" comment")
}
if h.SKBInfo != nil {
result += fmt.Sprintf(" skbinfo")
}
if h.Forceadd != nil {
result += fmt.Sprintf(" forceadd")
}
return result
}