sys_darwin.go 2.7 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. func (typ RIBType) parseable() bool {
  6. switch typ {
  7. case sysNET_RT_STAT, sysNET_RT_TRASH:
  8. return false
  9. default:
  10. return true
  11. }
  12. }
  13. // A RouteMetrics represents route metrics.
  14. type RouteMetrics struct {
  15. PathMTU int // path maximum transmission unit
  16. }
  17. // SysType implements the SysType method of Sys interface.
  18. func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
  19. // Sys implements the Sys method of Message interface.
  20. func (m *RouteMessage) Sys() []Sys {
  21. return []Sys{
  22. &RouteMetrics{
  23. PathMTU: int(nativeEndian.Uint32(m.raw[m.extOff+4 : m.extOff+8])),
  24. },
  25. }
  26. }
  27. // A InterfaceMetrics represents interface metrics.
  28. type InterfaceMetrics struct {
  29. Type int // interface type
  30. MTU int // maximum transmission unit
  31. }
  32. // SysType implements the SysType method of Sys interface.
  33. func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
  34. // Sys implements the Sys method of Message interface.
  35. func (m *InterfaceMessage) Sys() []Sys {
  36. return []Sys{
  37. &InterfaceMetrics{
  38. Type: int(m.raw[m.extOff]),
  39. MTU: int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])),
  40. },
  41. }
  42. }
  43. func probeRoutingStack() (int, map[int]parseFn) {
  44. rtm := &wireFormat{extOff: 36, bodyOff: sizeofRtMsghdrDarwin15}
  45. rtm2 := &wireFormat{extOff: 36, bodyOff: sizeofRtMsghdr2Darwin15}
  46. ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrDarwin15}
  47. ifm2 := &wireFormat{extOff: 32, bodyOff: sizeofIfMsghdr2Darwin15}
  48. ifam := &wireFormat{extOff: sizeofIfaMsghdrDarwin15, bodyOff: sizeofIfaMsghdrDarwin15}
  49. ifmam := &wireFormat{extOff: sizeofIfmaMsghdrDarwin15, bodyOff: sizeofIfmaMsghdrDarwin15}
  50. ifmam2 := &wireFormat{extOff: sizeofIfmaMsghdr2Darwin15, bodyOff: sizeofIfmaMsghdr2Darwin15}
  51. // Darwin kernels require 32-bit aligned access to routing facilities.
  52. return 4, map[int]parseFn{
  53. sysRTM_ADD: rtm.parseRouteMessage,
  54. sysRTM_DELETE: rtm.parseRouteMessage,
  55. sysRTM_CHANGE: rtm.parseRouteMessage,
  56. sysRTM_GET: rtm.parseRouteMessage,
  57. sysRTM_LOSING: rtm.parseRouteMessage,
  58. sysRTM_REDIRECT: rtm.parseRouteMessage,
  59. sysRTM_MISS: rtm.parseRouteMessage,
  60. sysRTM_LOCK: rtm.parseRouteMessage,
  61. sysRTM_RESOLVE: rtm.parseRouteMessage,
  62. sysRTM_NEWADDR: ifam.parseInterfaceAddrMessage,
  63. sysRTM_DELADDR: ifam.parseInterfaceAddrMessage,
  64. sysRTM_IFINFO: ifm.parseInterfaceMessage,
  65. sysRTM_NEWMADDR: ifmam.parseInterfaceMulticastAddrMessage,
  66. sysRTM_DELMADDR: ifmam.parseInterfaceMulticastAddrMessage,
  67. sysRTM_IFINFO2: ifm2.parseInterfaceMessage,
  68. sysRTM_NEWMADDR2: ifmam2.parseInterfaceMulticastAddrMessage,
  69. sysRTM_GET2: rtm2.parseRouteMessage,
  70. }
  71. }