1
2
3
4
5 package route
6
7 import (
8 "syscall"
9 "unsafe"
10 )
11
12 func (typ RIBType) parseable() bool { return true }
13
14
15 type RouteMetrics struct {
16 PathMTU int
17 }
18
19
20 func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
21
22
23 func (m *RouteMessage) Sys() []Sys {
24 return []Sys{
25 &RouteMetrics{
26 PathMTU: int(nativeEndian.Uint64(m.raw[m.extOff+8 : m.extOff+16])),
27 },
28 }
29 }
30
31
32 type InterfaceMetrics struct {
33 Type int
34 MTU int
35 }
36
37
38 func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
39
40
41 func (m *InterfaceMessage) Sys() []Sys {
42 return []Sys{
43 &InterfaceMetrics{
44 Type: int(m.raw[m.extOff]),
45 MTU: int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])),
46 },
47 }
48 }
49
50 func probeRoutingStack() (int, map[int]*wireFormat) {
51 var p uintptr
52 rtm := &wireFormat{extOff: 40, bodyOff: sizeofRtMsghdrDragonFlyBSD4}
53 rtm.parse = rtm.parseRouteMessage
54 ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrDragonFlyBSD4}
55 ifm.parse = ifm.parseInterfaceMessage
56 ifam := &wireFormat{extOff: sizeofIfaMsghdrDragonFlyBSD4, bodyOff: sizeofIfaMsghdrDragonFlyBSD4}
57 ifam.parse = ifam.parseInterfaceAddrMessage
58 ifmam := &wireFormat{extOff: sizeofIfmaMsghdrDragonFlyBSD4, bodyOff: sizeofIfmaMsghdrDragonFlyBSD4}
59 ifmam.parse = ifmam.parseInterfaceMulticastAddrMessage
60 ifanm := &wireFormat{extOff: sizeofIfAnnouncemsghdrDragonFlyBSD4, bodyOff: sizeofIfAnnouncemsghdrDragonFlyBSD4}
61 ifanm.parse = ifanm.parseInterfaceAnnounceMessage
62
63 rel, _ := syscall.SysctlUint32("kern.osreldate")
64 if rel >= 500705 {
65
66
67 rtmVersion = 7
68 ifam.bodyOff = sizeofIfaMsghdrDragonFlyBSD58
69 }
70
71 return int(unsafe.Sizeof(p)), map[int]*wireFormat{
72 syscall.RTM_ADD: rtm,
73 syscall.RTM_DELETE: rtm,
74 syscall.RTM_CHANGE: rtm,
75 syscall.RTM_GET: rtm,
76 syscall.RTM_LOSING: rtm,
77 syscall.RTM_REDIRECT: rtm,
78 syscall.RTM_MISS: rtm,
79 syscall.RTM_LOCK: rtm,
80 syscall.RTM_RESOLVE: rtm,
81 syscall.RTM_NEWADDR: ifam,
82 syscall.RTM_DELADDR: ifam,
83 syscall.RTM_IFINFO: ifm,
84 syscall.RTM_NEWMADDR: ifmam,
85 syscall.RTM_DELMADDR: ifmam,
86 syscall.RTM_IFANNOUNCE: ifanm,
87 }
88 }
89
View as plain text