forked from Asphaltt/go-iproute2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathztypes.go
219 lines (193 loc) · 3.53 KB
/
ztypes.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package iproute2
import "math/bits"
// Copying code is to avoid code for different OS platforms.
// copied from syscall
const (
AF_BRIDGE = 0x7
PF_BRIDGE = AF_BRIDGE
)
// copied from golang.org/x/sys/unix
const (
NETLINK_ROUTE = 0x0
RTM_NEWNEIGH = 0x1c
RTM_DELNEIGH = 0x1d
RTM_GETNEIGH = 0x1e
RTNLGRP_NEIGH = 0x3
)
// families for netlink socket
const (
FamilySocketMonitoring = 0x0004
)
// message types for netlink message
const (
MsgTypeSockDiagByFamily = 0x0014
)
// SockDiagAttrType is the type for sock diag's attribute.
type SockDiagAttrType int
// attribute types for sock diag message
const (
InetDiagNone SockDiagAttrType = iota
InetDiagMemInfo
InetDiagInfo
InetDiagVegaInfo
InetDiagCong
InetDiagTOS
InetDiagTclass
InetDiagSkMemInfo
InetDiagShutdown
InetDiagDctcpInfo /* request as INET_DIAG_VEGASINFO */
InetDiagProtocol /* response attribute only */
InetDiagSkV6Only
InetDiagLocals
InetDiagPeers
InetDiagPad
InetDiagMark /* only with CAP_NET_ADMIN */
InetDiagBbrInfo /* request as INET_DIAG_VEGASINFO */
InetDiagClassID /* request as INET_DIAG_TCLASS */
InetDiagMD5Sig
InetDiagUlpInfo
InetDiagSkBpfStorages
InetDiagCgroupID
InetDiagSockOpt
)
// SockStateType is the type for socket's state.
type SockStateType int
// states for socket
const (
Unknown SockStateType = iota
Established
SynSent
SynRecv
FinWait1
FinWait2
TimeWait
Close
CloseWait
LastAck
Listen
Closing
_Max
All SockStateType = 1<<(_Max) - 1
Conn SockStateType = All & ^((1 << Listen) | (1 << Close) | (1 << TimeWait) | (1 << SynRecv))
)
// String gets the description string of the state.
func (s SockStateType) String() string {
switch s {
case Established:
return "ESTAB"
case SynSent:
return "SYN-SENT"
case SynRecv:
return "SYN-RECV"
case FinWait1:
return "FIN-WAIT-1"
case FinWait2:
return "FIN-WAIT-2"
case TimeWait:
return "TIME-WAIT"
case Close:
return "UNCONN"
case CloseWait:
return "CLOSE-WAIT"
case LastAck:
return "LAST-ACK"
case Listen:
return "LISTEN"
case Closing:
return "CLOSING"
default:
return "UNKNOWN"
}
}
type NdAttrType uint16
// types for error message attribute
const (
NdaUnspec NdAttrType = iota
NdaDst
NdaLladdr
NdaCacheInfo
NdaProbes
NdaVlan
NdaPort
NdaVNI
NdaIfindex
NdaMaster
NdaLinkNetNSID
NdaSrcVNI
NdaProtocol
NdaNhID
NdaFdbExtAttrs
)
type NtfFlag uint8
const (
NtfUse NtfFlag = 1 << iota
NtfSelf
NtfMaster
NtfProxy
NtfExtLearned
NtfOffloaded
NtfSticky
NtfRouter
)
func (f NtfFlag) String() string {
if f == 0 {
return ""
}
flags := [...]string{
"use",
"self",
"master",
"proxy",
"extern_learn",
"offload",
"sticky",
"router",
}
index := bits.TrailingZeros8(uint8(f))
return flags[index]
}
type NudState uint16
const (
NudIncomplete NudState = 1 << iota
NudReachable
NudStale
NudDelay
NudProbe
NudFailed
NudNoArp
NudPermanent
NudNone NudState = 0
)
func (s NudState) String() string {
if s == NudNone {
return "none"
}
states := [...]string{
"incomplete",
"reachable",
"stale",
"delay",
"probe",
"failed",
"noarp",
"permanent",
}
index := bits.TrailingZeros16(uint16(s))
return states[index]
}
// copied from src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux.go
// TODO: use ztypes_linux.go instead
const (
IFLA_EXT_MASK = 0x1d
)
/* New extended info filters for IFLA_EXT_MASK */
type RtTextFilterType int
const (
RTEXT_FILTER_VF RtTextFilterType = 1 << iota
RTEXT_FILTER_BRVLAN
RTEXT_FILTER_BRVLAN_COMPRESSED
RTEXT_FILTER_SKIP_STATS
RTEXT_FILTER_MRP
RTEXT_FILTER_CFM_CONFIG
RTEXT_FILTER_CFM_STATUS
)