sys_netbsd.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. func (typ RIBType) parseable() bool { return true }
  6. // RouteMetrics represents route metrics.
  7. type RouteMetrics struct {
  8. PathMTU int // path maximum transmission unit
  9. }
  10. // SysType implements the SysType method of Sys interface.
  11. func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
  12. // Sys implements the Sys method of Message interface.
  13. func (m *RouteMessage) Sys() []Sys {
  14. return []Sys{
  15. &RouteMetrics{
  16. PathMTU: int(nativeEndian.Uint64(m.raw[m.extOff+8 : m.extOff+16])),
  17. },
  18. }
  19. }
  20. // RouteMetrics represents route metrics.
  21. type InterfaceMetrics struct {
  22. Type int // interface type
  23. MTU int // maximum transmission unit
  24. }
  25. // SysType implements the SysType method of Sys interface.
  26. func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
  27. // Sys implements the Sys method of Message interface.
  28. func (m *InterfaceMessage) Sys() []Sys {
  29. return []Sys{
  30. &InterfaceMetrics{
  31. Type: int(m.raw[m.extOff]),
  32. MTU: int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])),
  33. },
  34. }
  35. }
  36. func probeRoutingStack() (int, map[int]*wireFormat) {
  37. rtm := &wireFormat{extOff: 40, bodyOff: sizeofRtMsghdrNetBSD7}
  38. rtm.parse = rtm.parseRouteMessage
  39. ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrNetBSD7}
  40. ifm.parse = ifm.parseInterfaceMessage
  41. ifam := &wireFormat{extOff: sizeofIfaMsghdrNetBSD7, bodyOff: sizeofIfaMsghdrNetBSD7}
  42. ifam.parse = ifam.parseInterfaceAddrMessage
  43. ifanm := &wireFormat{extOff: sizeofIfAnnouncemsghdrNetBSD7, bodyOff: sizeofIfAnnouncemsghdrNetBSD7}
  44. ifanm.parse = ifanm.parseInterfaceAnnounceMessage
  45. // NetBSD 6 and above kernels require 64-bit aligned access to
  46. // routing facilities.
  47. return 8, map[int]*wireFormat{
  48. sysRTM_ADD: rtm,
  49. sysRTM_DELETE: rtm,
  50. sysRTM_CHANGE: rtm,
  51. sysRTM_GET: rtm,
  52. sysRTM_LOSING: rtm,
  53. sysRTM_REDIRECT: rtm,
  54. sysRTM_MISS: rtm,
  55. sysRTM_LOCK: rtm,
  56. sysRTM_RESOLVE: rtm,
  57. sysRTM_NEWADDR: ifam,
  58. sysRTM_DELADDR: ifam,
  59. sysRTM_IFANNOUNCE: ifanm,
  60. sysRTM_IFINFO: ifm,
  61. }
  62. }