blob: 13994c1782f429d6ecf87eb227087656ed547114 [file] [log] [blame]
Abhay Kumara2ae5992025-11-10 14:02:24 +00001// Copyright 2023 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// TLSStat struct represents data in /proc/net/tls_stat.
25// See https://docs.kernel.org/networking/tls.html#statistics
26type TLSStat struct {
27 // number of TX sessions currently installed where host handles cryptography
28 TLSCurrTxSw int
29 // number of RX sessions currently installed where host handles cryptography
30 TLSCurrRxSw int
31 // number of TX sessions currently installed where NIC handles cryptography
32 TLSCurrTxDevice int
33 // number of RX sessions currently installed where NIC handles cryptography
34 TLSCurrRxDevice int
35 //number of TX sessions opened with host cryptography
36 TLSTxSw int
37 //number of RX sessions opened with host cryptography
38 TLSRxSw int
39 // number of TX sessions opened with NIC cryptography
40 TLSTxDevice int
41 // number of RX sessions opened with NIC cryptography
42 TLSRxDevice int
43 // record decryption failed (e.g. due to incorrect authentication tag)
44 TLSDecryptError int
45 // number of RX resyncs sent to NICs handling cryptography
46 TLSRxDeviceResync int
47 // number of RX records which had to be re-decrypted due to TLS_RX_EXPECT_NO_PAD mis-prediction. Note that this counter will also increment for non-data records.
48 TLSDecryptRetry int
49 // number of data RX records which had to be re-decrypted due to TLS_RX_EXPECT_NO_PAD mis-prediction.
50 TLSRxNoPadViolation int
51}
52
53// NewTLSStat reads the tls_stat statistics.
54func NewTLSStat() (TLSStat, error) {
55 fs, err := NewFS(DefaultMountPoint)
56 if err != nil {
57 return TLSStat{}, err
58 }
59
60 return fs.NewTLSStat()
61}
62
63// NewTLSStat reads the tls_stat statistics.
64func (fs FS) NewTLSStat() (TLSStat, error) {
65 file, err := os.Open(fs.proc.Path("net/tls_stat"))
66 if err != nil {
67 return TLSStat{}, err
68 }
69 defer file.Close()
70
71 var (
72 tlsstat = TLSStat{}
73 s = bufio.NewScanner(file)
74 )
75
76 for s.Scan() {
77 fields := strings.Fields(s.Text())
78
79 if len(fields) != 2 {
80 return TLSStat{}, fmt.Errorf("%w: %q line %q", ErrFileParse, file.Name(), s.Text())
81 }
82
83 name := fields[0]
84 value, err := strconv.Atoi(fields[1])
85 if err != nil {
86 return TLSStat{}, err
87 }
88
89 switch name {
90 case "TlsCurrTxSw":
91 tlsstat.TLSCurrTxSw = value
92 case "TlsCurrRxSw":
93 tlsstat.TLSCurrRxSw = value
94 case "TlsCurrTxDevice":
95 tlsstat.TLSCurrTxDevice = value
96 case "TlsCurrRxDevice":
97 tlsstat.TLSCurrRxDevice = value
98 case "TlsTxSw":
99 tlsstat.TLSTxSw = value
100 case "TlsRxSw":
101 tlsstat.TLSRxSw = value
102 case "TlsTxDevice":
103 tlsstat.TLSTxDevice = value
104 case "TlsRxDevice":
105 tlsstat.TLSRxDevice = value
106 case "TlsDecryptError":
107 tlsstat.TLSDecryptError = value
108 case "TlsRxDeviceResync":
109 tlsstat.TLSRxDeviceResync = value
110 case "TlsDecryptRetry":
111 tlsstat.TLSDecryptRetry = value
112 case "TlsRxNoPadViolation":
113 tlsstat.TLSRxNoPadViolation = value
114 }
115
116 }
117
118 return tlsstat, s.Err()
119}