github.com/vishvananda/netlink@v1.3.0/tcp_linux.go (about) 1 package netlink 2 3 import ( 4 "bytes" 5 "errors" 6 "io" 7 ) 8 9 const ( 10 tcpBBRInfoLen = 20 11 memInfoLen = 16 12 ) 13 14 func checkDeserErr(err error) error { 15 if err == io.EOF { 16 return nil 17 } 18 return err 19 } 20 21 func (t *TCPInfo) deserialize(b []byte) error { 22 var err error 23 rb := bytes.NewBuffer(b) 24 25 t.State, err = rb.ReadByte() 26 if err != nil { 27 return checkDeserErr(err) 28 } 29 30 t.Ca_state, err = rb.ReadByte() 31 if err != nil { 32 return checkDeserErr(err) 33 } 34 35 t.Retransmits, err = rb.ReadByte() 36 if err != nil { 37 return checkDeserErr(err) 38 } 39 40 t.Probes, err = rb.ReadByte() 41 if err != nil { 42 return checkDeserErr(err) 43 } 44 45 t.Backoff, err = rb.ReadByte() 46 if err != nil { 47 return checkDeserErr(err) 48 } 49 t.Options, err = rb.ReadByte() 50 if err != nil { 51 return checkDeserErr(err) 52 } 53 54 scales, err := rb.ReadByte() 55 if err != nil { 56 return checkDeserErr(err) 57 } 58 t.Snd_wscale = scales >> 4 // first 4 bits 59 t.Rcv_wscale = scales & 0xf // last 4 bits 60 61 rateLimAndFastOpen, err := rb.ReadByte() 62 if err != nil { 63 return checkDeserErr(err) 64 } 65 t.Delivery_rate_app_limited = rateLimAndFastOpen >> 7 // get first bit 66 t.Fastopen_client_fail = rateLimAndFastOpen >> 5 & 3 // get next two bits 67 68 next := rb.Next(4) 69 if len(next) == 0 { 70 return nil 71 } 72 t.Rto = native.Uint32(next) 73 74 next = rb.Next(4) 75 if len(next) == 0 { 76 return nil 77 } 78 t.Ato = native.Uint32(next) 79 80 next = rb.Next(4) 81 if len(next) == 0 { 82 return nil 83 } 84 t.Snd_mss = native.Uint32(next) 85 86 next = rb.Next(4) 87 if len(next) == 0 { 88 return nil 89 } 90 t.Rcv_mss = native.Uint32(next) 91 92 next = rb.Next(4) 93 if len(next) == 0 { 94 return nil 95 } 96 t.Unacked = native.Uint32(next) 97 98 next = rb.Next(4) 99 if len(next) == 0 { 100 return nil 101 } 102 t.Sacked = native.Uint32(next) 103 104 next = rb.Next(4) 105 if len(next) == 0 { 106 return nil 107 } 108 t.Lost = native.Uint32(next) 109 110 next = rb.Next(4) 111 if len(next) == 0 { 112 return nil 113 } 114 t.Retrans = native.Uint32(next) 115 116 next = rb.Next(4) 117 if len(next) == 0 { 118 return nil 119 } 120 t.Fackets = native.Uint32(next) 121 122 next = rb.Next(4) 123 if len(next) == 0 { 124 return nil 125 } 126 t.Last_data_sent = native.Uint32(next) 127 128 next = rb.Next(4) 129 if len(next) == 0 { 130 return nil 131 } 132 t.Last_ack_sent = native.Uint32(next) 133 134 next = rb.Next(4) 135 if len(next) == 0 { 136 return nil 137 } 138 t.Last_data_recv = native.Uint32(next) 139 140 next = rb.Next(4) 141 if len(next) == 0 { 142 return nil 143 } 144 t.Last_ack_recv = native.Uint32(next) 145 146 next = rb.Next(4) 147 if len(next) == 0 { 148 return nil 149 } 150 t.Pmtu = native.Uint32(next) 151 152 next = rb.Next(4) 153 if len(next) == 0 { 154 return nil 155 } 156 t.Rcv_ssthresh = native.Uint32(next) 157 158 next = rb.Next(4) 159 if len(next) == 0 { 160 return nil 161 } 162 t.Rtt = native.Uint32(next) 163 164 next = rb.Next(4) 165 if len(next) == 0 { 166 return nil 167 } 168 t.Rttvar = native.Uint32(next) 169 170 next = rb.Next(4) 171 if len(next) == 0 { 172 return nil 173 } 174 t.Snd_ssthresh = native.Uint32(next) 175 176 next = rb.Next(4) 177 if len(next) == 0 { 178 return nil 179 } 180 t.Snd_cwnd = native.Uint32(next) 181 182 next = rb.Next(4) 183 if len(next) == 0 { 184 return nil 185 } 186 t.Advmss = native.Uint32(next) 187 188 next = rb.Next(4) 189 if len(next) == 0 { 190 return nil 191 } 192 t.Reordering = native.Uint32(next) 193 194 next = rb.Next(4) 195 if len(next) == 0 { 196 return nil 197 } 198 t.Rcv_rtt = native.Uint32(next) 199 200 next = rb.Next(4) 201 if len(next) == 0 { 202 return nil 203 } 204 t.Rcv_space = native.Uint32(next) 205 206 next = rb.Next(4) 207 if len(next) == 0 { 208 return nil 209 } 210 t.Total_retrans = native.Uint32(next) 211 212 next = rb.Next(8) 213 if len(next) == 0 { 214 return nil 215 } 216 t.Pacing_rate = native.Uint64(next) 217 218 next = rb.Next(8) 219 if len(next) == 0 { 220 return nil 221 } 222 t.Max_pacing_rate = native.Uint64(next) 223 224 next = rb.Next(8) 225 if len(next) == 0 { 226 return nil 227 } 228 t.Bytes_acked = native.Uint64(next) 229 230 next = rb.Next(8) 231 if len(next) == 0 { 232 return nil 233 } 234 t.Bytes_received = native.Uint64(next) 235 236 next = rb.Next(4) 237 if len(next) == 0 { 238 return nil 239 } 240 t.Segs_out = native.Uint32(next) 241 242 next = rb.Next(4) 243 if len(next) == 0 { 244 return nil 245 } 246 t.Segs_in = native.Uint32(next) 247 next = rb.Next(4) 248 if len(next) == 0 { 249 return nil 250 } 251 t.Notsent_bytes = native.Uint32(next) 252 next = rb.Next(4) 253 if len(next) == 0 { 254 return nil 255 } 256 t.Min_rtt = native.Uint32(next) 257 next = rb.Next(4) 258 if len(next) == 0 { 259 return nil 260 } 261 t.Data_segs_in = native.Uint32(next) 262 next = rb.Next(4) 263 if len(next) == 0 { 264 return nil 265 } 266 t.Data_segs_out = native.Uint32(next) 267 268 next = rb.Next(8) 269 if len(next) == 0 { 270 return nil 271 } 272 t.Delivery_rate = native.Uint64(next) 273 274 next = rb.Next(8) 275 if len(next) == 0 { 276 return nil 277 } 278 t.Busy_time = native.Uint64(next) 279 280 next = rb.Next(8) 281 if len(next) == 0 { 282 return nil 283 } 284 t.Rwnd_limited = native.Uint64(next) 285 286 next = rb.Next(8) 287 if len(next) == 0 { 288 return nil 289 } 290 t.Sndbuf_limited = native.Uint64(next) 291 292 next = rb.Next(4) 293 if len(next) == 0 { 294 return nil 295 } 296 t.Delivered = native.Uint32(next) 297 298 next = rb.Next(4) 299 if len(next) == 0 { 300 return nil 301 } 302 t.Delivered_ce = native.Uint32(next) 303 304 next = rb.Next(8) 305 if len(next) == 0 { 306 return nil 307 } 308 t.Bytes_sent = native.Uint64(next) 309 310 next = rb.Next(8) 311 if len(next) == 0 { 312 return nil 313 } 314 t.Bytes_retrans = native.Uint64(next) 315 316 next = rb.Next(4) 317 if len(next) == 0 { 318 return nil 319 } 320 t.Dsack_dups = native.Uint32(next) 321 322 next = rb.Next(4) 323 if len(next) == 0 { 324 return nil 325 } 326 t.Reord_seen = native.Uint32(next) 327 328 next = rb.Next(4) 329 if len(next) == 0 { 330 return nil 331 } 332 t.Rcv_ooopack = native.Uint32(next) 333 334 next = rb.Next(4) 335 if len(next) == 0 { 336 return nil 337 } 338 t.Snd_wnd = native.Uint32(next) 339 return nil 340 } 341 342 func (t *TCPBBRInfo) deserialize(b []byte) error { 343 if len(b) != tcpBBRInfoLen { 344 return errors.New("Invalid length") 345 } 346 347 rb := bytes.NewBuffer(b) 348 t.BBRBW = native.Uint64(rb.Next(8)) 349 t.BBRMinRTT = native.Uint32(rb.Next(4)) 350 t.BBRPacingGain = native.Uint32(rb.Next(4)) 351 t.BBRCwndGain = native.Uint32(rb.Next(4)) 352 353 return nil 354 } 355 356 func (m *MemInfo) deserialize(b []byte) error { 357 if len(b) != memInfoLen { 358 return errors.New("Invalid length") 359 } 360 361 rb := bytes.NewBuffer(b) 362 m.RMem = native.Uint32(rb.Next(4)) 363 m.WMem = native.Uint32(rb.Next(4)) 364 m.FMem = native.Uint32(rb.Next(4)) 365 m.TMem = native.Uint32(rb.Next(4)) 366 367 return nil 368 }