-
Notifications
You must be signed in to change notification settings - Fork 10
/
rt.go
executable file
·274 lines (259 loc) · 5.53 KB
/
rt.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
// +build linux
package nlgo
const (
IFLA_UNSPEC = iota
IFLA_ADDRESS
IFLA_BROADCAST
IFLA_IFNAME
IFLA_MTU
IFLA_LINK // used with 8021q, for example
IFLA_QDISC
IFLA_STATS
IFLA_COST
IFLA_PRIORITY
IFLA_MASTER
IFLA_WIRELESS
IFLA_PROTINFO
IFLA_TXQLEN
IFLA_MAP
IFLA_WEIGHT
IFLA_OPERSTATE
IFLA_LINKMODE
IFLA_LINKINFO
IFLA_NET_NS_PID
IFLA_IFALIAS
IFLA_NUM_VF
IFLA_VFINFO_LIST
IFLA_STATS64
IFLA_VF_PORTS
IFLA_PORT_SELF
IFLA_AF_SPEC
IFLA_GROUP
IFLA_NET_NS_FD
IFLA_EXT_MASK
IFLA_PROMISCUITY
IFLA_NUM_TX_QUEUES
IFLA_NUM_RX_QUEUES
IFLA_CARRIER
IFLA_PHYS_PORT_ID
IFLA_CARRIER_CHANGES
)
const (
IFLA_INFO_UNSPEC = iota
IFLA_INFO_KIND
IFLA_INFO_DATA
IFLA_INFO_XSTATS
IFLA_INFO_SLAVE_KIND
IFLA_INFO_SLAVE_DATA
)
const (
IFLA_VF_UNSPEC = iota
IFLA_VF_MAC
IFLA_VF_VLAN
IFLA_VF_TX_RATE
IFLA_VF_SPOOFCHK
IFLA_VF_LINK_STATE
IFLA_VF_RATE
)
const (
IFLA_VF_PORT_UNSPEC = iota
IFLA_VF_PORT
)
const (
IFLA_PORT_UNSPEC = iota
IFLA_PORT_VF
IFLA_PORT_PROFILE
IFLA_PORT_VSI_TYPE
IFLA_PORT_INSTANCE_UUID
IFLA_PORT_HOST_UUID
IFLA_PORT_REQUEST
IFLA_PORT_RESPONSE
)
// RtnlLinkStats64 will be the contents for IFLA_STATS64.
type RtnlLinkStats64 struct {
RxPackets uint64
TxPackets uint64
RxBytes uint64
TxBytes uint64
RxErrors uint64
TxErrors uint64
RxDropped uint64
TxDropped uint64
Multicast uint64
Collisions uint64
// detailed rx_errors
RxLengthErrors uint64
RxOverErrors uint64
RxCrcErrors uint64
RxFrameErrors uint64
RxFifoErrors uint64
RxMissedErrors uint64
// detailed tx_errors
TxAbortedErrors uint64
TxCarrierErrors uint64
TxFifoErrors uint64
TxHeartbeatErrors uint64
TxWindowErrors uint64
// cslip etc.
RxCompressed uint64
TxCompressed uint64
}
var portPolicy Policy = MapPolicy{
Prefix: "IFLA_PORT",
Names: IFLA_PORT_itoa,
Rule: map[uint16]Policy{
IFLA_PORT_VF: U32Policy,
IFLA_PORT_PROFILE: BinaryPolicy,
IFLA_PORT_VSI_TYPE: BinaryPolicy,
IFLA_PORT_INSTANCE_UUID: BinaryPolicy,
IFLA_PORT_HOST_UUID: BinaryPolicy,
IFLA_PORT_REQUEST: U8Policy,
IFLA_PORT_RESPONSE: U16Policy,
},
}
var RouteLinkPolicy MapPolicy = MapPolicy{
Prefix: "IFLA",
Names: IFLA_itoa,
Rule: map[uint16]Policy{
IFLA_IFNAME: NulStringPolicy,
IFLA_ADDRESS: BinaryPolicy,
IFLA_BROADCAST: BinaryPolicy,
IFLA_MAP: BinaryPolicy,
IFLA_MTU: U32Policy,
IFLA_LINK: U32Policy,
IFLA_MASTER: U32Policy,
IFLA_CARRIER: U8Policy,
IFLA_TXQLEN: U32Policy,
IFLA_WEIGHT: U32Policy,
IFLA_OPERSTATE: U8Policy,
IFLA_LINKMODE: U8Policy,
IFLA_LINKINFO: MapPolicy{
Prefix: "INFO",
Names: IFLA_INFO_itoa,
Rule: map[uint16]Policy{
IFLA_INFO_KIND: NulStringPolicy,
IFLA_INFO_DATA: BinaryPolicy, // depends on the kind
IFLA_INFO_SLAVE_KIND: BinaryPolicy,
IFLA_INFO_SLAVE_DATA: BinaryPolicy, // depends on the kind
},
},
IFLA_NET_NS_PID: U32Policy,
IFLA_NET_NS_FD: U32Policy,
IFLA_IFALIAS: NulStringPolicy,
IFLA_VFINFO_LIST: ListPolicy{
Nested: MapPolicy{
Prefix: "VF",
Names: IFLA_VF_itoa,
Rule: map[uint16]Policy{
IFLA_VF_MAC: BinaryPolicy,
IFLA_VF_VLAN: BinaryPolicy,
IFLA_VF_TX_RATE: BinaryPolicy,
IFLA_VF_SPOOFCHK: BinaryPolicy,
IFLA_VF_LINK_STATE: BinaryPolicy,
IFLA_VF_RATE: BinaryPolicy,
},
},
},
IFLA_VF_PORTS: ListPolicy{
Nested: MapPolicy{
Prefix: "VF_PORT",
Names: IFLA_VF_PORT_itoa,
Rule: map[uint16]Policy{
IFLA_VF_PORT: portPolicy,
},
},
},
IFLA_PORT_SELF: portPolicy,
IFLA_AF_SPEC: BinaryPolicy, // depends on spec
IFLA_EXT_MASK: U32Policy,
IFLA_PROMISCUITY: U32Policy,
IFLA_NUM_TX_QUEUES: U32Policy,
IFLA_NUM_RX_QUEUES: U32Policy,
IFLA_PHYS_PORT_ID: BinaryPolicy,
IFLA_CARRIER_CHANGES: U32Policy,
IFLA_QDISC: BinaryPolicy,
IFLA_STATS: BinaryPolicy, // struct rtnl_link_stats
IFLA_STATS64: BinaryPolicy, // struct rtnl_link_stats64
IFLA_WIRELESS: BinaryPolicy,
IFLA_PROTINFO: BinaryPolicy, // depends on prot
IFLA_NUM_VF: U32Policy,
IFLA_GROUP: U32Policy,
},
}
const (
RTA_UNSPEC = iota
RTA_DST
RTA_SRC
RTA_IIF
RTA_OIF
RTA_GATEWAY
RTA_PRIORITY
RTA_PREFSRC
RTA_METRICS
RTA_MULTIPATH
RTA_PROTOINFO
RTA_FLOW
RTA_CACHEINFO
RTA_SESSION
RTA_MP_ALGO
RTA_TABLE
RTA_MARK
RTA_MFC_STATS
)
var RoutePolicy MapPolicy = MapPolicy{
Prefix: "RTA",
Names: RTA_itoa,
Rule: map[uint16]Policy{
RTA_DST: BinaryPolicy,
RTA_SRC: BinaryPolicy,
RTA_IIF: U32Policy,
RTA_OIF: U32Policy,
RTA_GATEWAY: BinaryPolicy,
RTA_PRIORITY: U32Policy,
RTA_PREFSRC: BinaryPolicy,
RTA_METRICS: ListPolicy{
Nested: U32Policy,
},
RTA_MULTIPATH: BinaryPolicy,
RTA_FLOW: U32Policy,
RTA_CACHEINFO: BinaryPolicy,
RTA_TABLE: U32Policy,
RTA_MARK: U32Policy,
RTA_MFC_STATS: BinaryPolicy,
},
}
const (
RTEXT_FILTER_VF = 1 << iota
RTEXT_FILTER_BRVLAN
RTEXT_FILTER_BRVLAN_COMPRESSED
RTEXT_FILTER_SKIP_STATS
)
const (
NDA_UNSPEC = iota
NDA_DST
NDA_LLADDR
NDA_CACHEINFO
NDA_PROBES
NDA_VLAN
NDA_PORT
NDA_VNI
NDA_IFINDEX
NDA_MASTER
NDA_LINK_NETNSID
)
var NeighPolicy = MapPolicy{
Prefix: "NDA",
Names: NDA_itoa,
Rule: map[uint16]Policy{
NDA_DST: BinaryPolicy,
NDA_LLADDR: BinaryPolicy,
NDA_CACHEINFO: BinaryPolicy, // nda_cacheinfo
NDA_PROBES: U32Policy,
NDA_VLAN: U16Policy,
NDA_PORT: U16Policy,
NDA_VNI: U32Policy,
NDA_IFINDEX: U32Policy,
NDA_MASTER: U32Policy,
NDA_LINK_NETNSID: U32Policy,
},
}