Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

88 linhas
2.7 KiB

  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. // 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. // 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]*wireFormat) {
  44. rtm := &wireFormat{extOff: 36, bodyOff: sizeofRtMsghdrDarwin15}
  45. rtm.parse = rtm.parseRouteMessage
  46. rtm2 := &wireFormat{extOff: 36, bodyOff: sizeofRtMsghdr2Darwin15}
  47. rtm2.parse = rtm2.parseRouteMessage
  48. ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrDarwin15}
  49. ifm.parse = ifm.parseInterfaceMessage
  50. ifm2 := &wireFormat{extOff: 32, bodyOff: sizeofIfMsghdr2Darwin15}
  51. ifm2.parse = ifm2.parseInterfaceMessage
  52. ifam := &wireFormat{extOff: sizeofIfaMsghdrDarwin15, bodyOff: sizeofIfaMsghdrDarwin15}
  53. ifam.parse = ifam.parseInterfaceAddrMessage
  54. ifmam := &wireFormat{extOff: sizeofIfmaMsghdrDarwin15, bodyOff: sizeofIfmaMsghdrDarwin15}
  55. ifmam.parse = ifmam.parseInterfaceMulticastAddrMessage
  56. ifmam2 := &wireFormat{extOff: sizeofIfmaMsghdr2Darwin15, bodyOff: sizeofIfmaMsghdr2Darwin15}
  57. ifmam2.parse = ifmam2.parseInterfaceMulticastAddrMessage
  58. // Darwin kernels require 32-bit aligned access to routing facilities.
  59. return 4, 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_IFINFO2: ifm2,
  75. sysRTM_NEWMADDR2: ifmam2,
  76. sysRTM_GET2: rtm2,
  77. }
  78. }