github.com/Andyfoo/golang/x/net@v0.0.0-20190901054642-57c1bf301704/route/sys_dragonfly.go (about) 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 5 package route 6 7 import "unsafe" 8 9 func (typ RIBType) parseable() bool { return true } 10 11 // RouteMetrics represents route metrics. 12 type RouteMetrics struct { 13 PathMTU int // path maximum transmission unit 14 } 15 16 // SysType implements the SysType method of Sys interface. 17 func (rmx *RouteMetrics) SysType() SysType { return SysMetrics } 18 19 // Sys implements the Sys method of Message interface. 20 func (m *RouteMessage) Sys() []Sys { 21 return []Sys{ 22 &RouteMetrics{ 23 PathMTU: int(nativeEndian.Uint64(m.raw[m.extOff+8 : m.extOff+16])), 24 }, 25 } 26 } 27 28 // InterfaceMetrics represents interface metrics. 29 type InterfaceMetrics struct { 30 Type int // interface type 31 MTU int // maximum transmission unit 32 } 33 34 // SysType implements the SysType method of Sys interface. 35 func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics } 36 37 // Sys implements the Sys method of Message interface. 38 func (m *InterfaceMessage) Sys() []Sys { 39 return []Sys{ 40 &InterfaceMetrics{ 41 Type: int(m.raw[m.extOff]), 42 MTU: int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])), 43 }, 44 } 45 } 46 47 func probeRoutingStack() (int, map[int]*wireFormat) { 48 var p uintptr 49 rtm := &wireFormat{extOff: 40, bodyOff: sizeofRtMsghdrDragonFlyBSD4} 50 rtm.parse = rtm.parseRouteMessage 51 ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrDragonFlyBSD4} 52 ifm.parse = ifm.parseInterfaceMessage 53 ifam := &wireFormat{extOff: sizeofIfaMsghdrDragonFlyBSD4, bodyOff: sizeofIfaMsghdrDragonFlyBSD4} 54 ifam.parse = ifam.parseInterfaceAddrMessage 55 ifmam := &wireFormat{extOff: sizeofIfmaMsghdrDragonFlyBSD4, bodyOff: sizeofIfmaMsghdrDragonFlyBSD4} 56 ifmam.parse = ifmam.parseInterfaceMulticastAddrMessage 57 ifanm := &wireFormat{extOff: sizeofIfAnnouncemsghdrDragonFlyBSD4, bodyOff: sizeofIfAnnouncemsghdrDragonFlyBSD4} 58 ifanm.parse = ifanm.parseInterfaceAnnounceMessage 59 return int(unsafe.Sizeof(p)), 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_IFANNOUNCE: ifanm, 75 } 76 }