1
2
3
4
5 package route
6
7 func (typ RIBType) parseable() bool {
8 switch typ {
9 case sysNET_RT_STAT, sysNET_RT_TRASH:
10 return false
11 default:
12 return true
13 }
14 }
15
16
17 type RouteMetrics struct {
18 PathMTU int
19 }
20
21
22 func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
23
24
25 func (m *RouteMessage) Sys() []Sys {
26 return []Sys{
27 &RouteMetrics{
28 PathMTU: int(nativeEndian.Uint32(m.raw[m.extOff+4 : m.extOff+8])),
29 },
30 }
31 }
32
33
34 type InterfaceMetrics struct {
35 Type int
36 MTU int
37 }
38
39
40 func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
41
42
43 func (m *InterfaceMessage) Sys() []Sys {
44 return []Sys{
45 &InterfaceMetrics{
46 Type: int(m.raw[m.extOff]),
47 MTU: int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])),
48 },
49 }
50 }
51
52 func probeRoutingStack() (int, map[int]*wireFormat) {
53 rtm := &wireFormat{extOff: 36, bodyOff: sizeofRtMsghdrDarwin15}
54 rtm.parse = rtm.parseRouteMessage
55 rtm2 := &wireFormat{extOff: 36, bodyOff: sizeofRtMsghdr2Darwin15}
56 rtm2.parse = rtm2.parseRouteMessage
57 ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrDarwin15}
58 ifm.parse = ifm.parseInterfaceMessage
59 ifm2 := &wireFormat{extOff: 32, bodyOff: sizeofIfMsghdr2Darwin15}
60 ifm2.parse = ifm2.parseInterfaceMessage
61 ifam := &wireFormat{extOff: sizeofIfaMsghdrDarwin15, bodyOff: sizeofIfaMsghdrDarwin15}
62 ifam.parse = ifam.parseInterfaceAddrMessage
63 ifmam := &wireFormat{extOff: sizeofIfmaMsghdrDarwin15, bodyOff: sizeofIfmaMsghdrDarwin15}
64 ifmam.parse = ifmam.parseInterfaceMulticastAddrMessage
65 ifmam2 := &wireFormat{extOff: sizeofIfmaMsghdr2Darwin15, bodyOff: sizeofIfmaMsghdr2Darwin15}
66 ifmam2.parse = ifmam2.parseInterfaceMulticastAddrMessage
67
68 return 4, map[int]*wireFormat{
69 sysRTM_ADD: rtm,
70 sysRTM_DELETE: rtm,
71 sysRTM_CHANGE: rtm,
72 sysRTM_GET: rtm,
73 sysRTM_LOSING: rtm,
74 sysRTM_REDIRECT: rtm,
75 sysRTM_MISS: rtm,
76 sysRTM_LOCK: rtm,
77 sysRTM_RESOLVE: rtm,
78 sysRTM_NEWADDR: ifam,
79 sysRTM_DELADDR: ifam,
80 sysRTM_IFINFO: ifm,
81 sysRTM_NEWMADDR: ifmam,
82 sysRTM_DELMADDR: ifmam,
83 sysRTM_IFINFO2: ifm2,
84 sysRTM_NEWMADDR2: ifmam2,
85 sysRTM_GET2: rtm2,
86 }
87 }
88
View as plain text