sys_dragonfly.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 (
  6. "syscall"
  7. "unsafe"
  8. )
  9. func (typ RIBType) parseable() bool { return true }
  10. // RouteMetrics represents route metrics.
  11. type RouteMetrics struct {
  12. PathMTU int // path maximum transmission unit
  13. }
  14. // SysType implements the SysType method of Sys interface.
  15. func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
  16. // Sys implements the Sys method of Message interface.
  17. func (m *RouteMessage) Sys() []Sys {
  18. return []Sys{
  19. &RouteMetrics{
  20. PathMTU: int(nativeEndian.Uint64(m.raw[m.extOff+8 : m.extOff+16])),
  21. },
  22. }
  23. }
  24. // InterfaceMetrics represents interface metrics.
  25. type InterfaceMetrics struct {
  26. Type int // interface type
  27. MTU int // maximum transmission unit
  28. }
  29. // SysType implements the SysType method of Sys interface.
  30. func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
  31. // Sys implements the Sys method of Message interface.
  32. func (m *InterfaceMessage) Sys() []Sys {
  33. return []Sys{
  34. &InterfaceMetrics{
  35. Type: int(m.raw[m.extOff]),
  36. MTU: int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])),
  37. },
  38. }
  39. }
  40. func probeRoutingStack() (int, map[int]*wireFormat) {
  41. var p uintptr
  42. rtm := &wireFormat{extOff: 40, bodyOff: sizeofRtMsghdrDragonFlyBSD4}
  43. rtm.parse = rtm.parseRouteMessage
  44. ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrDragonFlyBSD4}
  45. ifm.parse = ifm.parseInterfaceMessage
  46. ifam := &wireFormat{extOff: sizeofIfaMsghdrDragonFlyBSD4, bodyOff: sizeofIfaMsghdrDragonFlyBSD4}
  47. ifam.parse = ifam.parseInterfaceAddrMessage
  48. ifmam := &wireFormat{extOff: sizeofIfmaMsghdrDragonFlyBSD4, bodyOff: sizeofIfmaMsghdrDragonFlyBSD4}
  49. ifmam.parse = ifmam.parseInterfaceMulticastAddrMessage
  50. ifanm := &wireFormat{extOff: sizeofIfAnnouncemsghdrDragonFlyBSD4, bodyOff: sizeofIfAnnouncemsghdrDragonFlyBSD4}
  51. ifanm.parse = ifanm.parseInterfaceAnnounceMessage
  52. rel, _ := syscall.SysctlUint32("kern.osreldate")
  53. if rel >= 500705 {
  54. // https://github.com/DragonFlyBSD/DragonFlyBSD/commit/43a373152df2d405c9940983e584e6a25e76632d
  55. // but only the size of struct ifa_msghdr actually changed
  56. rtmVersion = 7
  57. ifam.bodyOff = sizeofIfaMsghdrDragonFlyBSD58
  58. }
  59. return int(unsafe.Sizeof(p)), map[int]*wireFormat{
  60. sysRTM_ADD: rtm,
  61. sysRTM_DELETE: rtm,
  62. sysRTM_CHANGE: rtm,
  63. sysRTM_GET: rtm,
  64. sysRTM_LOSING: rtm,
  65. sysRTM_REDIRECT: rtm,
  66. sysRTM_MISS: rtm,
  67. sysRTM_LOCK: rtm,
  68. sysRTM_RESOLVE: rtm,
  69. sysRTM_NEWADDR: ifam,
  70. sysRTM_DELADDR: ifam,
  71. sysRTM_IFINFO: ifm,
  72. sysRTM_NEWMADDR: ifmam,
  73. sysRTM_DELMADDR: ifmam,
  74. sysRTM_IFANNOUNCE: ifanm,
  75. }
  76. }