blob: 02f71d54bbdfa6776826c1df09b96172a6bd1c9f [file] [log] [blame]
Mikio Hara30be4882016-04-23 22:36:41 +09001// 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
5package route
6
7func (typ RIBType) parseable() bool { return true }
8
Mikio Haraab548502017-07-20 06:11:51 +09009// RouteMetrics represents route metrics.
Mikio Hara30be4882016-04-23 22:36:41 +090010type RouteMetrics struct {
11 PathMTU int // path maximum transmission unit
12}
13
14// SysType implements the SysType method of Sys interface.
15func (rmx *RouteMetrics) SysType() SysType { return SysMetrics }
16
17// Sys implements the Sys method of Message interface.
18func (m *RouteMessage) Sys() []Sys {
19 return []Sys{
20 &RouteMetrics{
21 PathMTU: int(nativeEndian.Uint64(m.raw[m.extOff+8 : m.extOff+16])),
22 },
23 }
24}
25
Mikio Haraab548502017-07-20 06:11:51 +090026// RouteMetrics represents route metrics.
Mikio Hara30be4882016-04-23 22:36:41 +090027type InterfaceMetrics struct {
28 Type int // interface type
29 MTU int // maximum transmission unit
30}
31
32// SysType implements the SysType method of Sys interface.
33func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics }
34
35// Sys implements the Sys method of Message interface.
36func (m *InterfaceMessage) Sys() []Sys {
37 return []Sys{
38 &InterfaceMetrics{
39 Type: int(m.raw[m.extOff]),
40 MTU: int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])),
41 },
42 }
43}
44
Mikio Hara41bba8d2017-01-27 23:21:26 +090045func probeRoutingStack() (int, map[int]*wireFormat) {
Mikio Hara30be4882016-04-23 22:36:41 +090046 rtm := &wireFormat{extOff: 40, bodyOff: sizeofRtMsghdrNetBSD7}
Mikio Hara41bba8d2017-01-27 23:21:26 +090047 rtm.parse = rtm.parseRouteMessage
Mikio Hara30be4882016-04-23 22:36:41 +090048 ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrNetBSD7}
Mikio Hara41bba8d2017-01-27 23:21:26 +090049 ifm.parse = ifm.parseInterfaceMessage
Mikio Hara30be4882016-04-23 22:36:41 +090050 ifam := &wireFormat{extOff: sizeofIfaMsghdrNetBSD7, bodyOff: sizeofIfaMsghdrNetBSD7}
Mikio Hara41bba8d2017-01-27 23:21:26 +090051 ifam.parse = ifam.parseInterfaceAddrMessage
Mikio Hara30be4882016-04-23 22:36:41 +090052 ifanm := &wireFormat{extOff: sizeofIfAnnouncemsghdrNetBSD7, bodyOff: sizeofIfAnnouncemsghdrNetBSD7}
Mikio Hara41bba8d2017-01-27 23:21:26 +090053 ifanm.parse = ifanm.parseInterfaceAnnounceMessage
Mikio Hara30be4882016-04-23 22:36:41 +090054 // NetBSD 6 and above kernels require 64-bit aligned access to
55 // routing facilities.
Mikio Hara41bba8d2017-01-27 23:21:26 +090056 return 8, map[int]*wireFormat{
57 sysRTM_ADD: rtm,
58 sysRTM_DELETE: rtm,
59 sysRTM_CHANGE: rtm,
60 sysRTM_GET: rtm,
61 sysRTM_LOSING: rtm,
62 sysRTM_REDIRECT: rtm,
63 sysRTM_MISS: rtm,
64 sysRTM_LOCK: rtm,
65 sysRTM_RESOLVE: rtm,
66 sysRTM_NEWADDR: ifam,
67 sysRTM_DELADDR: ifam,
68 sysRTM_IFANNOUNCE: ifanm,
69 sysRTM_IFINFO: ifm,
Mikio Hara30be4882016-04-23 22:36:41 +090070 }
71}