source: code/trunk/vendor/github.com/prometheus/procfs/net_xfrm.go@ 824

Last change on this file since 824 was 822, checked in by yakumo.izuru, 22 months ago

Prefer immortal.run over runit and rc.d, use vendored modules
for convenience.

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

File size: 4.9 KB
Line 
1// Copyright 2017 Prometheus Team
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14package procfs
15
16import (
17 "bufio"
18 "fmt"
19 "os"
20 "strconv"
21 "strings"
22)
23
24// XfrmStat models the contents of /proc/net/xfrm_stat.
25type XfrmStat struct {
26 // All errors which are not matched by other
27 XfrmInError int
28 // No buffer is left
29 XfrmInBufferError int
30 // Header Error
31 XfrmInHdrError int
32 // No state found
33 // i.e. either inbound SPI, address, or IPSEC protocol at SA is wrong
34 XfrmInNoStates int
35 // Transformation protocol specific error
36 // e.g. SA Key is wrong
37 XfrmInStateProtoError int
38 // Transformation mode specific error
39 XfrmInStateModeError int
40 // Sequence error
41 // e.g. sequence number is out of window
42 XfrmInStateSeqError int
43 // State is expired
44 XfrmInStateExpired int
45 // State has mismatch option
46 // e.g. UDP encapsulation type is mismatched
47 XfrmInStateMismatch int
48 // State is invalid
49 XfrmInStateInvalid int
50 // No matching template for states
51 // e.g. Inbound SAs are correct but SP rule is wrong
52 XfrmInTmplMismatch int
53 // No policy is found for states
54 // e.g. Inbound SAs are correct but no SP is found
55 XfrmInNoPols int
56 // Policy discards
57 XfrmInPolBlock int
58 // Policy error
59 XfrmInPolError int
60 // All errors which are not matched by others
61 XfrmOutError int
62 // Bundle generation error
63 XfrmOutBundleGenError int
64 // Bundle check error
65 XfrmOutBundleCheckError int
66 // No state was found
67 XfrmOutNoStates int
68 // Transformation protocol specific error
69 XfrmOutStateProtoError int
70 // Transportation mode specific error
71 XfrmOutStateModeError int
72 // Sequence error
73 // i.e sequence number overflow
74 XfrmOutStateSeqError int
75 // State is expired
76 XfrmOutStateExpired int
77 // Policy discads
78 XfrmOutPolBlock int
79 // Policy is dead
80 XfrmOutPolDead int
81 // Policy Error
82 XfrmOutPolError int
83 // Forward routing of a packet is not allowed
84 XfrmFwdHdrError int
85 // State is invalid, perhaps expired
86 XfrmOutStateInvalid int
87 // State hasn’t been fully acquired before use
88 XfrmAcquireError int
89}
90
91// NewXfrmStat reads the xfrm_stat statistics.
92func NewXfrmStat() (XfrmStat, error) {
93 fs, err := NewFS(DefaultMountPoint)
94 if err != nil {
95 return XfrmStat{}, err
96 }
97
98 return fs.NewXfrmStat()
99}
100
101// NewXfrmStat reads the xfrm_stat statistics from the 'proc' filesystem.
102func (fs FS) NewXfrmStat() (XfrmStat, error) {
103 file, err := os.Open(fs.proc.Path("net/xfrm_stat"))
104 if err != nil {
105 return XfrmStat{}, err
106 }
107 defer file.Close()
108
109 var (
110 x = XfrmStat{}
111 s = bufio.NewScanner(file)
112 )
113
114 for s.Scan() {
115 fields := strings.Fields(s.Text())
116
117 if len(fields) != 2 {
118 return XfrmStat{}, fmt.Errorf("couldn't parse %q line %q", file.Name(), s.Text())
119 }
120
121 name := fields[0]
122 value, err := strconv.Atoi(fields[1])
123 if err != nil {
124 return XfrmStat{}, err
125 }
126
127 switch name {
128 case "XfrmInError":
129 x.XfrmInError = value
130 case "XfrmInBufferError":
131 x.XfrmInBufferError = value
132 case "XfrmInHdrError":
133 x.XfrmInHdrError = value
134 case "XfrmInNoStates":
135 x.XfrmInNoStates = value
136 case "XfrmInStateProtoError":
137 x.XfrmInStateProtoError = value
138 case "XfrmInStateModeError":
139 x.XfrmInStateModeError = value
140 case "XfrmInStateSeqError":
141 x.XfrmInStateSeqError = value
142 case "XfrmInStateExpired":
143 x.XfrmInStateExpired = value
144 case "XfrmInStateInvalid":
145 x.XfrmInStateInvalid = value
146 case "XfrmInTmplMismatch":
147 x.XfrmInTmplMismatch = value
148 case "XfrmInNoPols":
149 x.XfrmInNoPols = value
150 case "XfrmInPolBlock":
151 x.XfrmInPolBlock = value
152 case "XfrmInPolError":
153 x.XfrmInPolError = value
154 case "XfrmOutError":
155 x.XfrmOutError = value
156 case "XfrmInStateMismatch":
157 x.XfrmInStateMismatch = value
158 case "XfrmOutBundleGenError":
159 x.XfrmOutBundleGenError = value
160 case "XfrmOutBundleCheckError":
161 x.XfrmOutBundleCheckError = value
162 case "XfrmOutNoStates":
163 x.XfrmOutNoStates = value
164 case "XfrmOutStateProtoError":
165 x.XfrmOutStateProtoError = value
166 case "XfrmOutStateModeError":
167 x.XfrmOutStateModeError = value
168 case "XfrmOutStateSeqError":
169 x.XfrmOutStateSeqError = value
170 case "XfrmOutStateExpired":
171 x.XfrmOutStateExpired = value
172 case "XfrmOutPolBlock":
173 x.XfrmOutPolBlock = value
174 case "XfrmOutPolDead":
175 x.XfrmOutPolDead = value
176 case "XfrmOutPolError":
177 x.XfrmOutPolError = value
178 case "XfrmFwdHdrError":
179 x.XfrmFwdHdrError = value
180 case "XfrmOutStateInvalid":
181 x.XfrmOutStateInvalid = value
182 case "XfrmAcquireError":
183 x.XfrmAcquireError = value
184 }
185
186 }
187
188 return x, s.Err()
189}
Note: See TracBrowser for help on using the repository browser.