sys_openbsd.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // 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. // 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]*wireFormat) {
  45. var p uintptr
  46. rtm := &wireFormat{extOff: -1, bodyOff: -1}
  47. rtm.parse = rtm.parseRouteMessage
  48. ifm := &wireFormat{extOff: -1, bodyOff: -1}
  49. ifm.parse = ifm.parseInterfaceMessage
  50. ifam := &wireFormat{extOff: -1, bodyOff: -1}
  51. ifam.parse = ifam.parseInterfaceAddrMessage
  52. ifanm := &wireFormat{extOff: -1, bodyOff: -1}
  53. ifanm.parse = ifanm.parseInterfaceAnnounceMessage
  54. return int(unsafe.Sizeof(p)), map[int]*wireFormat{
  55. sysRTM_ADD: rtm,
  56. sysRTM_DELETE: rtm,
  57. sysRTM_CHANGE: rtm,
  58. sysRTM_GET: rtm,
  59. sysRTM_LOSING: rtm,
  60. sysRTM_REDIRECT: rtm,
  61. sysRTM_MISS: rtm,
  62. sysRTM_LOCK: rtm,
  63. sysRTM_RESOLVE: rtm,
  64. sysRTM_NEWADDR: ifam,
  65. sysRTM_DELADDR: ifam,
  66. sysRTM_IFINFO: ifm,
  67. sysRTM_IFANNOUNCE: ifanm,
  68. sysRTM_DESYNC: rtm,
  69. }
  70. }