Mikio Hara | 30be488 | 2016-04-23 22:36:41 +0900 | [diff] [blame] | 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. |
| 4 | |
| 5 | package route |
| 6 | |
| 7 | func (typ RIBType) parseable() bool { return true } |
| 8 | |
Mikio Hara | ab54850 | 2017-07-20 06:11:51 +0900 | [diff] [blame] | 9 | // RouteMetrics represents route metrics. |
Mikio Hara | 30be488 | 2016-04-23 22:36:41 +0900 | [diff] [blame] | 10 | type RouteMetrics struct { |
| 11 | PathMTU int // path maximum transmission unit |
| 12 | } |
| 13 | |
| 14 | // SysType implements the SysType method of Sys interface. |
| 15 | func (rmx *RouteMetrics) SysType() SysType { return SysMetrics } |
| 16 | |
| 17 | // Sys implements the Sys method of Message interface. |
| 18 | func (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 Hara | ab54850 | 2017-07-20 06:11:51 +0900 | [diff] [blame] | 26 | // RouteMetrics represents route metrics. |
Mikio Hara | 30be488 | 2016-04-23 22:36:41 +0900 | [diff] [blame] | 27 | type InterfaceMetrics struct { |
| 28 | Type int // interface type |
| 29 | MTU int // maximum transmission unit |
| 30 | } |
| 31 | |
| 32 | // SysType implements the SysType method of Sys interface. |
| 33 | func (imx *InterfaceMetrics) SysType() SysType { return SysMetrics } |
| 34 | |
| 35 | // Sys implements the Sys method of Message interface. |
| 36 | func (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 Hara | 41bba8d | 2017-01-27 23:21:26 +0900 | [diff] [blame] | 45 | func probeRoutingStack() (int, map[int]*wireFormat) { |
Mikio Hara | 30be488 | 2016-04-23 22:36:41 +0900 | [diff] [blame] | 46 | rtm := &wireFormat{extOff: 40, bodyOff: sizeofRtMsghdrNetBSD7} |
Mikio Hara | 41bba8d | 2017-01-27 23:21:26 +0900 | [diff] [blame] | 47 | rtm.parse = rtm.parseRouteMessage |
Mikio Hara | 30be488 | 2016-04-23 22:36:41 +0900 | [diff] [blame] | 48 | ifm := &wireFormat{extOff: 16, bodyOff: sizeofIfMsghdrNetBSD7} |
Mikio Hara | 41bba8d | 2017-01-27 23:21:26 +0900 | [diff] [blame] | 49 | ifm.parse = ifm.parseInterfaceMessage |
Mikio Hara | 30be488 | 2016-04-23 22:36:41 +0900 | [diff] [blame] | 50 | ifam := &wireFormat{extOff: sizeofIfaMsghdrNetBSD7, bodyOff: sizeofIfaMsghdrNetBSD7} |
Mikio Hara | 41bba8d | 2017-01-27 23:21:26 +0900 | [diff] [blame] | 51 | ifam.parse = ifam.parseInterfaceAddrMessage |
Mikio Hara | 30be488 | 2016-04-23 22:36:41 +0900 | [diff] [blame] | 52 | ifanm := &wireFormat{extOff: sizeofIfAnnouncemsghdrNetBSD7, bodyOff: sizeofIfAnnouncemsghdrNetBSD7} |
Mikio Hara | 41bba8d | 2017-01-27 23:21:26 +0900 | [diff] [blame] | 53 | ifanm.parse = ifanm.parseInterfaceAnnounceMessage |
Mikio Hara | 30be488 | 2016-04-23 22:36:41 +0900 | [diff] [blame] | 54 | // NetBSD 6 and above kernels require 64-bit aligned access to |
| 55 | // routing facilities. |
Mikio Hara | 41bba8d | 2017-01-27 23:21:26 +0900 | [diff] [blame] | 56 | 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 Hara | 30be488 | 2016-04-23 22:36:41 +0900 | [diff] [blame] | 70 | } |
| 71 | } |