sys_openbsd.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2016 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package route
  5. import "unsafe"
  6. func (typ RIBType) parseable() bool {
  7. switch typ {
  8. case sysNET_RT_STATS, sysNET_RT_TABLE:
  9. return false
  10. default:
  11. return true
  12. }
  13. }
  14. // A RouteMetrics represents route metrics.
  15. type RouteMetrics struct {
  16. PathMTU int // path maximum transmission unit
  17. }
  18. // SysType implements the SysType method of Sys interface.
  19. func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
  20. // Sys implements the Sys method of Message interface.
  21. func (m *RouteMessage) Sys() []Sys {
  22. return []Sys{
  23. &RouteMetrics{
  24. PathMTU: int(nativeEndian.Uint32(m.raw[60:64])),
  25. },
  26. }
  27. }
  28. // A InterfaceMetrics represents interface metrics.
  29. type InterfaceMetrics struct {
  30. Type int // interface type
  31. MTU int // maximum transmission unit
  32. }
  33. // SysType implements the SysType method of Sys interface.
  34. func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
  35. // Sys implements the Sys method of Message interface.
  36. func (m *InterfaceMessage) Sys() []Sys {
  37. return []Sys{
  38. &InterfaceMetrics{
  39. Type: int(m.raw[24]),
  40. MTU: int(nativeEndian.Uint32(m.raw[28:32])),
  41. },
  42. }
  43. }
  44. func probeRoutingStack() (int, map[int]parseFn) {
  45. var p uintptr
  46. nooff := &wireFormat{extOff: -1, bodyOff: -1}
  47. return int(unsafe.Sizeof(p)), map[int]parseFn{
  48. sysRTM_ADD: nooff.parseRouteMessage,
  49. sysRTM_DELETE: nooff.parseRouteMessage,
  50. sysRTM_CHANGE: nooff.parseRouteMessage,
  51. sysRTM_GET: nooff.parseRouteMessage,
  52. sysRTM_LOSING: nooff.parseRouteMessage,
  53. sysRTM_REDIRECT: nooff.parseRouteMessage,
  54. sysRTM_MISS: nooff.parseRouteMessage,
  55. sysRTM_LOCK: nooff.parseRouteMessage,
  56. sysRTM_RESOLVE: nooff.parseRouteMessage,
  57. sysRTM_NEWADDR: nooff.parseInterfaceAddrMessage,
  58. sysRTM_DELADDR: nooff.parseInterfaceAddrMessage,
  59. sysRTM_IFINFO: nooff.parseInterfaceMessage,
  60. sysRTM_IFANNOUNCE: nooff.parseInterfaceAnnounceMessage,
  61. }
  62. }