1
2
3
4
5 package route
6
7 import "syscall"
8
9 func (typ RIBType) parseable() bool {
10 switch typ {
11 case syscall.NET_RT_STAT, syscall.NET_RT_TRASH:
12 return false
13 default:
14 return true
15 }
16 }
17
18
19 type RouteMetrics struct {
20 PathMTU int
21 }
22
23
24 func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
25
26
27 func (m *RouteMessage) Sys() []Sys {
28 return []Sys{
29 &RouteMetrics{
30 PathMTU: int(nativeEndian.Uint32(m.raw[m.extOff+4 : m.extOff+8])),
31 },
32 }
33 }
34
35
36 type InterfaceMetrics struct {
37 Type int
38 MTU int
39 }
40
41
42 func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
43
44
45 func (m *InterfaceMessage) Sys() []Sys {
46 return []Sys{
47 &InterfaceMetrics{
48 Type: int(m.raw[m.extOff]),
49 MTU: int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])),
50 },
51 }
52 }
53
54 func probeRoutingStack() (int, map[int]*wireFormat) {
55 rtm := &wireFormat{extOff: 36, bodyOff: sizeofRtMsghdrDarwin15}
56 rtm.parse = rtm.parseRouteMessage
57 rtm2 := &wireFormat{extOff: 36, bodyOff: sizeofRtMsghdr2Darwin15}
58 rtm2.parse = rtm2.parseRouteMessage
59 ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrDarwin15}
60 ifm.parse = ifm.parseInterfaceMessage
61 ifm2 := &wireFormat{extOff: 32, bodyOff: sizeofIfMsghdr2Darwin15}
62 ifm2.parse = ifm2.parseInterfaceMessage
63 ifam := &wireFormat{extOff: sizeofIfaMsghdrDarwin15, bodyOff: sizeofIfaMsghdrDarwin15}
64 ifam.parse = ifam.parseInterfaceAddrMessage
65 ifmam := &wireFormat{extOff: sizeofIfmaMsghdrDarwin15, bodyOff: sizeofIfmaMsghdrDarwin15}
66 ifmam.parse = ifmam.parseInterfaceMulticastAddrMessage
67 ifmam2 := &wireFormat{extOff: sizeofIfmaMsghdr2Darwin15, bodyOff: sizeofIfmaMsghdr2Darwin15}
68 ifmam2.parse = ifmam2.parseInterfaceMulticastAddrMessage
69
70 return 4, map[int]*wireFormat{
71 syscall.RTM_ADD: rtm,
72 syscall.RTM_DELETE: rtm,
73 syscall.RTM_CHANGE: rtm,
74 syscall.RTM_GET: rtm,
75 syscall.RTM_LOSING: rtm,
76 syscall.RTM_REDIRECT: rtm,
77 syscall.RTM_MISS: rtm,
78 syscall.RTM_LOCK: rtm,
79 syscall.RTM_RESOLVE: rtm,
80 syscall.RTM_NEWADDR: ifam,
81 syscall.RTM_DELADDR: ifam,
82 syscall.RTM_IFINFO: ifm,
83 syscall.RTM_NEWMADDR: ifmam,
84 syscall.RTM_DELMADDR: ifmam,
85 syscall.RTM_IFINFO2: ifm2,
86 syscall.RTM_NEWMADDR2: ifmam2,
87 syscall.RTM_GET2: rtm2,
88 }
89 }
90
View as plain text