sys_netbsd.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. // A 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. // A InterfaceMetrics represents interface 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]parseFn) {
  37. rtm := &wireFormat{extOff: 40, bodyOff: sizeofRtMsghdrNetBSD7}
  38. ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrNetBSD7}
  39. ifam := &wireFormat{extOff: sizeofIfaMsghdrNetBSD7, bodyOff: sizeofIfaMsghdrNetBSD7}
  40. ifanm := &wireFormat{extOff: sizeofIfAnnouncemsghdrNetBSD7, bodyOff: sizeofIfAnnouncemsghdrNetBSD7}
  41. // NetBSD 6 and above kernels require 64-bit aligned access to
  42. // routing facilities.
  43. return 8, map[int]parseFn{
  44. sysRTM_ADD: rtm.parseRouteMessage,
  45. sysRTM_DELETE: rtm.parseRouteMessage,
  46. sysRTM_CHANGE: rtm.parseRouteMessage,
  47. sysRTM_GET: rtm.parseRouteMessage,
  48. sysRTM_LOSING: rtm.parseRouteMessage,
  49. sysRTM_REDIRECT: rtm.parseRouteMessage,
  50. sysRTM_MISS: rtm.parseRouteMessage,
  51. sysRTM_LOCK: rtm.parseRouteMessage,
  52. sysRTM_RESOLVE: rtm.parseRouteMessage,
  53. sysRTM_NEWADDR: ifam.parseInterfaceAddrMessage,
  54. sysRTM_DELADDR: ifam.parseInterfaceAddrMessage,
  55. sysRTM_IFANNOUNCE: ifanm.parseInterfaceAnnounceMessage,
  56. sysRTM_IFINFO: ifm.parseInterfaceMessage,
  57. }
  58. }