sys_dragonfly.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 { return true }
  7. // A RouteMetrics represents route metrics.
  8. type RouteMetrics struct {
  9. PathMTU int // path maximum transmission unit
  10. }
  11. // SysType implements the SysType method of Sys interface.
  12. func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
  13. // Sys implements the Sys method of Message interface.
  14. func (m *RouteMessage) Sys() []Sys {
  15. return []Sys{
  16. &RouteMetrics{
  17. PathMTU: int(nativeEndian.Uint64(m.raw[m.extOff+8 : m.extOff+16])),
  18. },
  19. }
  20. }
  21. // A InterfaceMetrics represents interface metrics.
  22. type InterfaceMetrics struct {
  23. Type int // interface type
  24. MTU int // maximum transmission unit
  25. }
  26. // SysType implements the SysType method of Sys interface.
  27. func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
  28. // Sys implements the Sys method of Message interface.
  29. func (m *InterfaceMessage) Sys() []Sys {
  30. return []Sys{
  31. &InterfaceMetrics{
  32. Type: int(m.raw[m.extOff]),
  33. MTU: int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])),
  34. },
  35. }
  36. }
  37. func probeRoutingStack() (int, map[int]*wireFormat) {
  38. var p uintptr
  39. rtm := &wireFormat{extOff: 40, bodyOff: sizeofRtMsghdrDragonFlyBSD4}
  40. rtm.parse = rtm.parseRouteMessage
  41. ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrDragonFlyBSD4}
  42. ifm.parse = ifm.parseInterfaceMessage
  43. ifam := &wireFormat{extOff: sizeofIfaMsghdrDragonFlyBSD4, bodyOff: sizeofIfaMsghdrDragonFlyBSD4}
  44. ifam.parse = ifam.parseInterfaceAddrMessage
  45. ifmam := &wireFormat{extOff: sizeofIfmaMsghdrDragonFlyBSD4, bodyOff: sizeofIfmaMsghdrDragonFlyBSD4}
  46. ifmam.parse = ifmam.parseInterfaceMulticastAddrMessage
  47. ifanm := &wireFormat{extOff: sizeofIfAnnouncemsghdrDragonFlyBSD4, bodyOff: sizeofIfAnnouncemsghdrDragonFlyBSD4}
  48. ifanm.parse = ifanm.parseInterfaceAnnounceMessage
  49. return int(unsafe.Sizeof(p)), map[int]*wireFormat{
  50. sysRTM_ADD: rtm,
  51. sysRTM_DELETE: rtm,
  52. sysRTM_CHANGE: rtm,
  53. sysRTM_GET: rtm,
  54. sysRTM_LOSING: rtm,
  55. sysRTM_REDIRECT: rtm,
  56. sysRTM_MISS: rtm,
  57. sysRTM_LOCK: rtm,
  58. sysRTM_RESOLVE: rtm,
  59. sysRTM_NEWADDR: ifam,
  60. sysRTM_DELADDR: ifam,
  61. sysRTM_IFINFO: ifm,
  62. sysRTM_NEWMADDR: ifmam,
  63. sysRTM_DELMADDR: ifmam,
  64. sysRTM_IFANNOUNCE: ifanm,
  65. }
  66. }