github.com/Andyfoo/golang/x/net@v0.0.0-20190901054642-57c1bf301704/route/sys_openbsd.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 { 10 switch typ { 11 case sysNET_RT_STATS, sysNET_RT_TABLE: 12 return false 13 default: 14 return true 15 } 16 } 17 18 // RouteMetrics represents route metrics. 19 type RouteMetrics struct { 20 PathMTU int // path maximum transmission unit 21 } 22 23 // SysType implements the SysType method of Sys interface. 24 func (rmx *RouteMetrics) SysType() SysType { return SysMetrics } 25 26 // Sys implements the Sys method of Message interface. 27 func (m *RouteMessage) Sys() []Sys { 28 return []Sys{ 29 &RouteMetrics{ 30 PathMTU: int(nativeEndian.Uint32(m.raw[60:64])), 31 }, 32 } 33 } 34 35 // InterfaceMetrics represents interface metrics. 36 type InterfaceMetrics struct { 37 Type int // interface type 38 MTU int // maximum transmission unit 39 } 40 41 // SysType implements the SysType method of Sys interface. 42 func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics } 43 44 // Sys implements the Sys method of Message interface. 45 func (m *InterfaceMessage) Sys() []Sys { 46 return []Sys{ 47 &InterfaceMetrics{ 48 Type: int(m.raw[24]), 49 MTU: int(nativeEndian.Uint32(m.raw[28:32])), 50 }, 51 } 52 } 53 54 func probeRoutingStack() (int, map[int]*wireFormat) { 55 var p uintptr 56 rtm := &wireFormat{extOff: -1, bodyOff: -1} 57 rtm.parse = rtm.parseRouteMessage 58 ifm := &wireFormat{extOff: -1, bodyOff: -1} 59 ifm.parse = ifm.parseInterfaceMessage 60 ifam := &wireFormat{extOff: -1, bodyOff: -1} 61 ifam.parse = ifam.parseInterfaceAddrMessage 62 ifanm := &wireFormat{extOff: -1, bodyOff: -1} 63 ifanm.parse = ifanm.parseInterfaceAnnounceMessage 64 return int(unsafe.Sizeof(p)), map[int]*wireFormat{ 65 sysRTM_ADD: rtm, 66 sysRTM_DELETE: rtm, 67 sysRTM_CHANGE: rtm, 68 sysRTM_GET: rtm, 69 sysRTM_LOSING: rtm, 70 sysRTM_REDIRECT: rtm, 71 sysRTM_MISS: rtm, 72 sysRTM_LOCK: rtm, 73 sysRTM_RESOLVE: rtm, 74 sysRTM_NEWADDR: ifam, 75 sysRTM_DELADDR: ifam, 76 sysRTM_IFINFO: ifm, 77 sysRTM_IFANNOUNCE: ifanm, 78 sysRTM_DESYNC: rtm, 79 } 80 }