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.
12 func (typ RIBType) parseable() bool { return true }
14 // RouteMetrics represents route metrics.
15 type RouteMetrics struct {
16 PathMTU int // path maximum transmission unit
19 // SysType implements the SysType method of Sys interface.
20 func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
22 // Sys implements the Sys method of Message interface.
23 func (m *RouteMessage) Sys() []Sys {
27 PathMTU: int(nativeEndian.Uint64(m.raw[m.extOff+8 : m.extOff+16])),
33 PathMTU: int(nativeEndian.Uint32(m.raw[m.extOff+4 : m.extOff+8])),
38 // InterfaceMetrics represents interface metrics.
39 type InterfaceMetrics struct {
40 Type int // interface type
41 MTU int // maximum transmission unit
44 // SysType implements the SysType method of Sys interface.
45 func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
47 // Sys implements the Sys method of Message interface.
48 func (m *InterfaceMessage) Sys() []Sys {
51 Type: int(m.raw[m.extOff]),
52 MTU: int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])),
57 func probeRoutingStack() (int, map[int]*wireFormat) {
59 wordSize := int(unsafe.Sizeof(p))
60 align := int(unsafe.Sizeof(p))
61 // In the case of kern.supported_archs="amd64 i386", we need
62 // to know the underlying kernel's architecture because the
63 // alignment for routing facilities are set at the build time
65 conf, _ := syscall.Sysctl("kern.conftxt")
66 for i, j := 0, 0; j < len(conf); j++ {
72 if len(s) > len("machine") && s[:len("machine")] == "machine" {
73 s = s[len("machine"):]
74 for k := 0; k < len(s); k++ {
75 if s[k] == ' ' || s[k] == '\t' {
86 var rtm, ifm, ifam, ifmam, ifanm *wireFormat
87 if align != wordSize { // 386 emulation on amd64
88 rtm = &wireFormat{extOff: sizeofRtMsghdrFreeBSD10Emu - sizeofRtMetricsFreeBSD10Emu, bodyOff: sizeofRtMsghdrFreeBSD10Emu}
89 ifm = &wireFormat{extOff: 16}
90 ifam = &wireFormat{extOff: sizeofIfaMsghdrFreeBSD10Emu, bodyOff: sizeofIfaMsghdrFreeBSD10Emu}
91 ifmam = &wireFormat{extOff: sizeofIfmaMsghdrFreeBSD10Emu, bodyOff: sizeofIfmaMsghdrFreeBSD10Emu}
92 ifanm = &wireFormat{extOff: sizeofIfAnnouncemsghdrFreeBSD10Emu, bodyOff: sizeofIfAnnouncemsghdrFreeBSD10Emu}
94 rtm = &wireFormat{extOff: sizeofRtMsghdrFreeBSD10 - sizeofRtMetricsFreeBSD10, bodyOff: sizeofRtMsghdrFreeBSD10}
95 ifm = &wireFormat{extOff: 16}
96 ifam = &wireFormat{extOff: sizeofIfaMsghdrFreeBSD10, bodyOff: sizeofIfaMsghdrFreeBSD10}
97 ifmam = &wireFormat{extOff: sizeofIfmaMsghdrFreeBSD10, bodyOff: sizeofIfmaMsghdrFreeBSD10}
98 ifanm = &wireFormat{extOff: sizeofIfAnnouncemsghdrFreeBSD10, bodyOff: sizeofIfAnnouncemsghdrFreeBSD10}
100 rel, _ := syscall.SysctlUint32("kern.osreldate")
103 if align != wordSize { // 386 emulation on amd64
104 ifm.bodyOff = sizeofIfMsghdrFreeBSD7Emu
106 ifm.bodyOff = sizeofIfMsghdrFreeBSD7
108 case 800000 <= rel && rel < 900000:
109 if align != wordSize { // 386 emulation on amd64
110 ifm.bodyOff = sizeofIfMsghdrFreeBSD8Emu
112 ifm.bodyOff = sizeofIfMsghdrFreeBSD8
114 case 900000 <= rel && rel < 1000000:
115 if align != wordSize { // 386 emulation on amd64
116 ifm.bodyOff = sizeofIfMsghdrFreeBSD9Emu
118 ifm.bodyOff = sizeofIfMsghdrFreeBSD9
120 case 1000000 <= rel && rel < 1100000:
121 if align != wordSize { // 386 emulation on amd64
122 ifm.bodyOff = sizeofIfMsghdrFreeBSD10Emu
124 ifm.bodyOff = sizeofIfMsghdrFreeBSD10
127 if align != wordSize { // 386 emulation on amd64
128 ifm.bodyOff = sizeofIfMsghdrFreeBSD11Emu
130 ifm.bodyOff = sizeofIfMsghdrFreeBSD11
133 rtm.parse = rtm.parseRouteMessage
134 ifm.parse = ifm.parseInterfaceMessage
135 ifam.parse = ifam.parseInterfaceAddrMessage
136 ifmam.parse = ifmam.parseInterfaceMulticastAddrMessage
137 ifanm.parse = ifanm.parseInterfaceAnnounceMessage
138 return align, map[int]*wireFormat{
144 sysRTM_REDIRECT: rtm,
148 sysRTM_NEWADDR: ifam,
149 sysRTM_DELADDR: ifam,
151 sysRTM_NEWMADDR: ifmam,
152 sysRTM_DELMADDR: ifmam,
153 sysRTM_IFANNOUNCE: ifanm,